Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Friends | List of all members
skgpu::graphite::ProxyCache Class Reference

#include <ProxyCache.h>

Public Types

using BitmapGeneratorContext = const void *
 
using BitmapGeneratorFn = SkBitmap(*)(BitmapGeneratorContext)
 

Public Member Functions

 ProxyCache (uint32_t recorderID)
 
 ~ProxyCache ()
 
sk_sp< TextureProxyfindOrCreateCachedProxy (Recorder *, const SkBitmap &, std::string_view label)
 
sk_sp< TextureProxyfindOrCreateCachedProxy (Recorder *recorder, const UniqueKey &key, BitmapGeneratorContext context, BitmapGeneratorFn fn, std::string_view label={})
 
void purgeAll ()
 

Friends

class ResourceCache
 

Detailed Description

Definition at line 33 of file ProxyCache.h.

Member Typedef Documentation

◆ BitmapGeneratorContext

Definition at line 49 of file ProxyCache.h.

◆ BitmapGeneratorFn

Definition at line 50 of file ProxyCache.h.

Constructor & Destructor Documentation

◆ ProxyCache()

skgpu::graphite::ProxyCache::ProxyCache ( uint32_t  recorderID)

Definition at line 64 of file ProxyCache.cpp.

64 : fInvalidUniqueKeyInbox(recorderID) {
65 SkASSERT(recorderID != SK_InvalidGenID);
66}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static constexpr uint32_t SK_InvalidGenID
Definition: SkTypes.h:192

◆ ~ProxyCache()

skgpu::graphite::ProxyCache::~ProxyCache ( )

Definition at line 68 of file ProxyCache.cpp.

68{}

Member Function Documentation

◆ findOrCreateCachedProxy() [1/2]

sk_sp< TextureProxy > skgpu::graphite::ProxyCache::findOrCreateCachedProxy ( Recorder recorder,
const SkBitmap bitmap,
std::string_view  label 
)

Definition at line 74 of file ProxyCache.cpp.

76 {
77
79 make_bitmap_key(&key, bitmap);
80 return this->findOrCreateCachedProxy(
81 recorder, key, &bitmap,
82 [](const void* context) { return *static_cast<const SkBitmap*>(context); },
83 label);
84}
sk_sp< TextureProxy > findOrCreateCachedProxy(Recorder *, const SkBitmap &, std::string_view label)
Definition: ProxyCache.cpp:74
Definition: bitmap.py:1

◆ findOrCreateCachedProxy() [2/2]

sk_sp< TextureProxy > skgpu::graphite::ProxyCache::findOrCreateCachedProxy ( Recorder recorder,
const UniqueKey key,
BitmapGeneratorContext  context,
BitmapGeneratorFn  fn,
std::string_view  label = {} 
)

Definition at line 86 of file ProxyCache.cpp.

90 {
91 this->processInvalidKeyMsgs();
92
93 if (sk_sp<TextureProxy>* cached = fCache.find(key)) {
94 if (Resource* resource = (*cached)->texture()) {
95 resource->updateAccessTime();
96 }
97 return *cached;
98 }
99
100 SkBitmap bitmap = generator(context);
101 if (bitmap.empty()) {
102 return nullptr;
103 }
104 auto [ view, ct ] = MakeBitmapProxyView(recorder, bitmap, nullptr, Mipmapped::kNo,
105 Budgeted::kYes, label.empty() ? key.tag() : label);
106 if (view) {
107 // Since if the bitmap is held by more than just this function call (e.g. it likely came
108 // from findOrCreateCachedProxy() that takes an existing SkBitmap), it's worth adding a
109 // listener to remove them from the cache automatically when no one holds on to it anymore.
110 const bool addListener = !bitmap.pixelRef()->unique();
111 if (addListener) {
112 auto listener = make_unique_key_invalidation_listener(key, recorder->priv().uniqueID());
113 bitmap.pixelRef()->addGenIDChangeListener(std::move(listener));
114 }
115 fCache.set(key, view.refProxy());
116 }
117 return view.refProxy();
118}
static SkString resource(SkPDFResourceType type, int index)
std::tuple< TextureProxyView, SkColorType > MakeBitmapProxyView(Recorder *recorder, const SkBitmap &bitmap, sk_sp< SkMipmap > mipmapsIn, Mipmapped mipmapped, Budgeted budgeted, std::string_view label)

◆ purgeAll()

void skgpu::graphite::ProxyCache::purgeAll ( )

Definition at line 120 of file ProxyCache.cpp.

120 {
121 fCache.reset();
122}

Friends And Related Function Documentation

◆ ResourceCache

friend class ResourceCache
friend

Definition at line 68 of file ProxyCache.h.


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