Flutter Engine
The Flutter Engine
third_party
skia
tools
UrlDataManager.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2016 Google Inc.
3
*
4
* Use of this source code is governed by a BSD-style license that can be
5
* found in the LICENSE file.
6
*/
7
8
#include "
tools/UrlDataManager.h
"
9
10
#include <unordered_map>
11
#include <vector>
12
13
bool
operator==
(
const
SkData
&
a
,
const
SkData
&
b
) {
14
return
a
.equals(&
b
);
15
}
16
17
UrlDataManager::UrlDataManager
(
SkString
rootUrl) : fRootUrl(rootUrl), fDataId(0) {}
18
19
SkString
UrlDataManager::addData
(
SkData
*
data
,
const
char
* contentType) {
20
UrlData
* urlData = fCache.find(*
data
);
21
if
(fCache.find(*
data
)) {
22
SkASSERT
(
data
->equals(urlData->
fData
.
get
()));
23
return
urlData->
fUrl
;
24
}
25
26
urlData =
new
UrlData
;
27
urlData->
fData
.
reset
(
SkRef
(
data
));
28
urlData->
fContentType
.
set
(contentType);
29
urlData->
fUrl
.
appendf
(
"%s/%u"
, fRootUrl.
c_str
(), fDataId++);
30
31
fCache.add(urlData);
32
33
SkASSERT
(!fUrlLookup.find(urlData->
fUrl
));
34
fUrlLookup.add(urlData);
35
return
urlData->
fUrl
;
36
}
37
38
void
UrlDataManager::reset
() {
39
fCache.foreach([&](
UrlData
* urlData) {
40
urlData->
unref
();
41
});
42
fCache.rewind();
43
}
44
45
void
UrlDataManager::indexImages
(
const
std::vector<
sk_sp<SkImage>
>&
images
) {
46
SkASSERT
(imageMap.empty());
// this method meant only for initialization once.
47
for
(
size_t
i
= 0;
i
<
images
.size(); ++
i
) {
48
imageMap.insert({
images
[
i
].get(),
i
});
49
}
50
}
51
52
int
UrlDataManager::lookupImage
(
const
SkImage
* im) {
53
auto
search = imageMap.find(im);
54
if
(search != imageMap.end()) {
55
return
search->second;
56
}
else
{
57
// -1 signals the pointer to this image wasn't in the original list.
58
// Maybe it was synthesized after file load? If so, you shouldn't be looking it up here.
59
return
-1;
60
}
61
}
SkASSERT
#define SkASSERT(cond)
Definition:
SkAssert.h:116
SkRef
static T * SkRef(T *obj)
Definition:
SkRefCnt.h:132
operator==
bool operator==(const SkData &a, const SkData &b)
Definition:
UrlDataManager.cpp:13
UrlDataManager.h
SkData
Definition:
SkData.h:25
SkImage
Definition:
SkImage.h:272
SkRefCntBase::unref
void unref() const
Definition:
SkRefCnt.h:72
SkString
Definition:
SkString.h:118
SkString::set
void set(const SkString &src)
Definition:
SkString.h:186
SkString::c_str
const char * c_str() const
Definition:
SkString.h:133
SkString::appendf
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition:
SkString.cpp:550
UrlDataManager::UrlDataManager
UrlDataManager(SkString rootUrl)
Definition:
UrlDataManager.cpp:17
UrlDataManager::indexImages
void indexImages(const std::vector< sk_sp< SkImage > > &)
Definition:
UrlDataManager.cpp:45
UrlDataManager::addData
SkString addData(SkData *, const char *contentType)
Definition:
UrlDataManager.cpp:19
UrlDataManager::lookupImage
int lookupImage(const SkImage *)
Definition:
UrlDataManager.cpp:52
UrlDataManager::reset
void reset()
Definition:
UrlDataManager.cpp:38
sk_sp< SkImage >
sk_sp::get
T * get() const
Definition:
SkRefCnt.h:303
sk_sp::reset
void reset(T *ptr=nullptr)
Definition:
SkRefCnt.h:310
b
static bool b
Definition:
ffi_native_test_module.c:74
a
struct MyStruct a[10]
i
int i
Definition:
fl_socket_accessible.cc:18
images
std::array< MockImage, 3 > images
Definition:
mock_vulkan.cc:41
UrlDataManager::UrlData
Definition:
UrlDataManager.h:37
UrlDataManager::UrlData::fUrl
SkString fUrl
Definition:
UrlDataManager.h:38
UrlDataManager::UrlData::fContentType
SkString fContentType
Definition:
UrlDataManager.h:39
UrlDataManager::UrlData::fData
sk_sp< SkData > fData
Definition:
UrlDataManager.h:40
data
std::shared_ptr< const fml::Mapping > data
Definition:
texture_gles.cc:63
Generated on Sun Jun 23 2024 21:56:51 for Flutter Engine by
1.9.4