Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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"
14#include "src/core/SkChecksum.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 */
24bool operator==(const SkData& a, const SkData& b);
25
27public:
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
42
43 /*
44 * returns the UrlData object which should be hosted at 'url'
45 */
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
72private:
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;
98 uint32_t fDataId;
99 std::unordered_map<const SkImage*, int> imageMap;
100};
101
102#endif
bool operator==(const SkData &a, const SkData &b)
void indexImages(const std::vector< sk_sp< SkImage > > &)
SkString addData(SkData *, const char *contentType)
UrlData * getDataFromUrl(const SkString &url)
int lookupImage(const SkImage *)
static bool b
struct MyStruct a[10]
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41