Flutter Engine
The Flutter Engine
third_party
skia
tools
UrlDataManager.h
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
#ifndef SkUrlDataManager_DEFINED
9
#define SkUrlDataManager_DEFINED
10
11
#include "
include/core/SkData.h
"
12
#include "
include/core/SkImage.h
"
13
#include "
include/core/SkString.h
"
14
#include "
src/core/SkChecksum.h
"
15
#include "
src/core/SkTDynamicHash.h
"
16
17
#include <unordered_map>
18
#include <vector>
19
20
/*
21
* A simple class which allows clients to add opaque data types, and returns a url where this data
22
* will be hosted. Its up to the owner of this class to actually serve the data.
23
*/
24
bool
operator==
(
const
SkData
&
a
,
const
SkData
&
b
);
25
26
class
UrlDataManager
{
27
public
:
28
UrlDataManager
(
SkString
rootUrl);
29
~UrlDataManager
() { this->
reset
(); }
30
31
/*
32
* Adds a data blob to the cache with a particular content type. UrlDataManager will hash
33
* the blob data to ensure uniqueness
34
*/
35
SkString
addData
(
SkData
*,
const
char
* contentType);
36
37
struct
UrlData
:
public
SkRefCnt
{
38
SkString
fUrl
;
39
SkString
fContentType
;
40
sk_sp<SkData>
fData
;
41
};
42
43
/*
44
* returns the UrlData object which should be hosted at 'url'
45
*/
46
UrlData
*
getDataFromUrl
(
const
SkString
& url) {
47
return
fUrlLookup.find(url);
48
}
49
void
reset
();
50
51
// Methods used to identify images differently in wasm debugger for mskp animations.
52
// serving is uncessary, as a collection of images with identifiers is already present, we
53
// just want to use it when serializing commands.
54
55
/*
56
* Construct an index from a list of images
57
* (expected to be the list that was loaded from the mskp file)
58
* Use only once.
59
*/
60
void
indexImages
(
const
std::vector<
sk_sp<SkImage>
>&);
61
62
/*
63
* Reports whether this UDM has an initialized image index (effevitely whether we're in wasm)
64
*/
65
bool
hasImageIndex
() {
return
imageMap.size() > 0; }
66
67
/*
68
* Return the file id (index of the image in the originally provided list) of an SkImage
69
*/
70
int
lookupImage
(
const
SkImage
*);
71
72
private
:
73
struct
LookupTrait {
74
// We use the data as a hash, this is not really optimal but is fine until proven otherwise
75
static
const
SkData
& GetKey(
const
UrlData&
data
) {
76
return
*
data
.fData;
77
}
78
79
static
uint32_t
Hash
(
const
SkData
&
key
) {
80
return
SkChecksum::Hash32
(
key
.bytes(),
key
.size());
81
}
82
};
83
84
struct
ReverseLookupTrait {
85
static
const
SkString
& GetKey(
const
UrlData&
data
) {
86
return
data
.fUrl;
87
}
88
89
static
uint32_t
Hash
(
const
SkString
&
key
) {
90
return
SkChecksum::Hash32
(
key
.c_str(), strlen(
key
.c_str()));
91
}
92
};
93
94
95
SkString
fRootUrl;
96
SkTDynamicHash<UrlData, SkData, LookupTrait>
fCache;
97
SkTDynamicHash<UrlData, SkString, ReverseLookupTrait>
fUrlLookup;
98
uint32_t fDataId;
99
std::unordered_map<const SkImage*, int> imageMap;
100
};
101
102
#endif
SkChecksum.h
SkData.h
SkImage.h
SkString.h
SkTDynamicHash.h
operator==
bool operator==(const SkData &a, const SkData &b)
Definition:
UrlDataManager.cpp:13
SkData
Definition:
SkData.h:25
SkImage
Definition:
SkImage.h:272
SkRefCnt
Definition:
SkRefCnt.h:119
SkString
Definition:
SkString.h:118
SkTDynamicHash
Definition:
SkTDynamicHash.h:22
UrlDataManager
Definition:
UrlDataManager.h:26
UrlDataManager::UrlDataManager
UrlDataManager(SkString rootUrl)
Definition:
UrlDataManager.cpp:17
UrlDataManager::indexImages
void indexImages(const std::vector< sk_sp< SkImage > > &)
Definition:
UrlDataManager.cpp:45
UrlDataManager::hasImageIndex
bool hasImageIndex()
Definition:
UrlDataManager.h:65
UrlDataManager::~UrlDataManager
~UrlDataManager()
Definition:
UrlDataManager.h:29
UrlDataManager::addData
SkString addData(SkData *, const char *contentType)
Definition:
UrlDataManager.cpp:19
UrlDataManager::getDataFromUrl
UrlData * getDataFromUrl(const SkString &url)
Definition:
UrlDataManager.h:46
UrlDataManager::lookupImage
int lookupImage(const SkImage *)
Definition:
UrlDataManager.cpp:52
UrlDataManager::reset
void reset()
Definition:
UrlDataManager.cpp:38
sk_sp< SkData >
b
static bool b
Definition:
ffi_native_test_module.c:74
a
struct MyStruct a[10]
key
int key
Definition:
keyboard_key_handler_unittests.cc:114
SkChecksum::Hash32
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)
Definition:
SkChecksum.cpp:113
dart::Hash
static uint32_t Hash(uint32_t key)
Definition:
hashmap_test.cc:65
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