Flutter Engine
The Flutter Engine
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
9
10#include <unordered_map>
11#include <vector>
12
13bool operator==(const SkData& a, const SkData& b) {
14 return a.equals(&b);
15}
16
17UrlDataManager::UrlDataManager(SkString rootUrl) : fRootUrl(rootUrl), fDataId(0) {}
18
19SkString 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
39 fCache.foreach([&](UrlData* urlData) {
40 urlData->unref();
41 });
42 fCache.rewind();
43}
44
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
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}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static T * SkRef(T *obj)
Definition: SkRefCnt.h:132
bool operator==(const SkData &a, const SkData &b)
Definition: SkData.h:25
void unref() const
Definition: SkRefCnt.h:72
void set(const SkString &src)
Definition: SkString.h:186
const char * c_str() const
Definition: SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
UrlDataManager(SkString rootUrl)
void indexImages(const std::vector< sk_sp< SkImage > > &)
SkString addData(SkData *, const char *contentType)
int lookupImage(const SkImage *)
T * get() const
Definition: SkRefCnt.h:303
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
static bool b
struct MyStruct a[10]
std::array< MockImage, 3 > images
Definition: mock_vulkan.cc:41
sk_sp< SkData > fData
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63