Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
UrlDataManager Class Reference

#include <UrlDataManager.h>

Classes

struct  UrlData
 

Public Member Functions

 UrlDataManager (SkString rootUrl)
 
 ~UrlDataManager ()
 
SkString addData (SkData *, const char *contentType)
 
UrlDatagetDataFromUrl (const SkString &url)
 
void reset ()
 
void indexImages (const std::vector< sk_sp< SkImage > > &)
 
bool hasImageIndex ()
 
int lookupImage (const SkImage *)
 

Detailed Description

Definition at line 26 of file UrlDataManager.h.

Constructor & Destructor Documentation

◆ UrlDataManager()

UrlDataManager::UrlDataManager ( SkString  rootUrl)

Definition at line 17 of file UrlDataManager.cpp.

17: fRootUrl(rootUrl), fDataId(0) {}

◆ ~UrlDataManager()

UrlDataManager::~UrlDataManager ( )
inline

Definition at line 29 of file UrlDataManager.h.

29{ this->reset(); }

Member Function Documentation

◆ addData()

SkString UrlDataManager::addData ( SkData data,
const char *  contentType 
)

Definition at line 19 of file UrlDataManager.cpp.

19 {
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}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static T * SkRef(T *obj)
Definition: SkRefCnt.h:132
const char * c_str() const
Definition: SkString.h:133
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ getDataFromUrl()

UrlData * UrlDataManager::getDataFromUrl ( const SkString url)
inline

Definition at line 46 of file UrlDataManager.h.

46 {
47 return fUrlLookup.find(url);
48 }

◆ hasImageIndex()

bool UrlDataManager::hasImageIndex ( )
inline

Definition at line 65 of file UrlDataManager.h.

65{ return imageMap.size() > 0; }

◆ indexImages()

void UrlDataManager::indexImages ( const std::vector< sk_sp< SkImage > > &  images)

Definition at line 45 of file UrlDataManager.cpp.

45 {
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}
std::array< MockImage, 3 > images
Definition: mock_vulkan.cc:41

◆ lookupImage()

int UrlDataManager::lookupImage ( const SkImage im)

Definition at line 52 of file UrlDataManager.cpp.

52 {
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}

◆ reset()

void UrlDataManager::reset ( )

Definition at line 38 of file UrlDataManager.cpp.

38 {
39 fCache.foreach([&](UrlData* urlData) {
40 urlData->unref();
41 });
42 fCache.rewind();
43}

The documentation for this class was generated from the following files: