Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
GrThreadSafeCache Class Reference

#include <GrThreadSafeCache.h>

Classes

class  Trampoline
 
class  VertexData
 

Public Types

typedef bool(* IsNewerBetter) (SkData *incumbent, SkData *challenger)
 

Public Member Functions

 GrThreadSafeCache ()
 
 ~GrThreadSafeCache ()
 
void dropAllRefs () SK_EXCLUDES(fSpinLock)
 
void dropUniqueRefs (GrResourceCache *resourceCache) SK_EXCLUDES(fSpinLock)
 
void dropUniqueRefsOlderThan (skgpu::StdSteadyClock::time_point purgeTime) SK_EXCLUDES(fSpinLock)
 
GrSurfaceProxyView add (const skgpu::UniqueKey &, const GrSurfaceProxyView &) SK_EXCLUDES(fSpinLock)
 
std::tuple< GrSurfaceProxyView, sk_sp< SkData > > addWithData (const skgpu::UniqueKey &, const GrSurfaceProxyView &) SK_EXCLUDES(fSpinLock)
 
GrSurfaceProxyView findOrAdd (const skgpu::UniqueKey &, const GrSurfaceProxyView &) SK_EXCLUDES(fSpinLock)
 
std::tuple< GrSurfaceProxyView, sk_sp< SkData > > findOrAddWithData (const skgpu::UniqueKey &, const GrSurfaceProxyView &) SK_EXCLUDES(fSpinLock)
 
std::tuple< sk_sp< VertexData >, sk_sp< SkData > > findVertsWithData (const skgpu::UniqueKey &) SK_EXCLUDES(fSpinLock)
 
std::tuple< sk_sp< VertexData >, sk_sp< SkData > > addVertsWithData (const skgpu::UniqueKey &, sk_sp< VertexData >, IsNewerBetter) SK_EXCLUDES(fSpinLock)
 
void remove (const skgpu::UniqueKey &) SK_EXCLUDES(fSpinLock)
 

Static Public Member Functions

static sk_sp< VertexDataMakeVertexData (const void *vertices, int vertexCount, size_t vertexSize)
 
static sk_sp< VertexDataMakeVertexData (sk_sp< GrGpuBuffer > buffer, int vertexCount, size_t vertexSize)
 
static std::tuple< GrSurfaceProxyView, sk_sp< Trampoline > > CreateLazyView (GrDirectContext *, GrColorType, SkISize dimensions, GrSurfaceOrigin, SkBackingFit)
 

Public Attributes

SkDEBUGCODE(bool has(const skgpu::UniqueKey &) SK_EXCLUDES(fSpinLock);) GrSurfaceProxyView find(const skgpu std::tuple< GrSurfaceProxyView, sk_sp< SkData > > findWithData (const skgpu::UniqueKey &) SK_EXCLUDES(fSpinLock)
 

Detailed Description

Definition at line 66 of file GrThreadSafeCache.h.

Member Typedef Documentation

◆ IsNewerBetter

typedef bool(* GrThreadSafeCache::IsNewerBetter) (SkData *incumbent, SkData *challenger)

Definition at line 170 of file GrThreadSafeCache.h.

Constructor & Destructor Documentation

◆ GrThreadSafeCache()

GrThreadSafeCache::GrThreadSafeCache ( )

Definition at line 24 of file GrThreadSafeCache.cpp.

25 : fFreeEntryList(nullptr) {
26}

◆ ~GrThreadSafeCache()

GrThreadSafeCache::~GrThreadSafeCache ( )

Definition at line 28 of file GrThreadSafeCache.cpp.

28 {
29 this->dropAllRefs();
30}
void dropAllRefs() SK_EXCLUDES(fSpinLock)

Member Function Documentation

◆ add()

GrSurfaceProxyView GrThreadSafeCache::add ( const skgpu::UniqueKey key,
const GrSurfaceProxyView view 
)

Definition at line 212 of file GrThreadSafeCache.cpp.

213 {
214 SkAutoSpinlock lock{fSpinLock};
215
216 GrSurfaceProxyView newView;
217 std::tie(newView, std::ignore) = this->internalAdd(key, view);
218 return newView;
219}

◆ addVertsWithData()

std::tuple< sk_sp< GrThreadSafeCache::VertexData >, sk_sp< SkData > > GrThreadSafeCache::addVertsWithData ( const skgpu::UniqueKey key,
sk_sp< VertexData vertData,
IsNewerBetter  isNewerBetter 
)

Definition at line 304 of file GrThreadSafeCache.cpp.

307 {
308 SkAutoSpinlock lock{fSpinLock};
309
310 return this->internalAddVerts(key, std::move(vertData), isNewerBetter);
311}

◆ addWithData()

std::tuple< GrSurfaceProxyView, sk_sp< SkData > > GrThreadSafeCache::addWithData ( const skgpu::UniqueKey key,
const GrSurfaceProxyView view 
)

Definition at line 221 of file GrThreadSafeCache.cpp.

223 {
224 SkAutoSpinlock lock{fSpinLock};
225
226 return this->internalAdd(key, view);
227}

◆ CreateLazyView()

std::tuple< GrSurfaceProxyView, sk_sp< GrThreadSafeCache::Trampoline > > GrThreadSafeCache::CreateLazyView ( GrDirectContext dContext,
GrColorType  origCT,
SkISize  dimensions,
GrSurfaceOrigin  origin,
SkBackingFit  fit 
)
static

Definition at line 325 of file GrThreadSafeCache.cpp.

329 {
330 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
331 const GrCaps* caps = dContext->priv().caps();
332
333 constexpr int kSampleCnt = 1;
334 auto [newCT, format] = caps->getFallbackColorTypeAndFormat(origCT, kSampleCnt);
335
336 if (newCT == GrColorType::kUnknown) {
337 return {GrSurfaceProxyView(nullptr), nullptr};
338 }
339
340 sk_sp<Trampoline> trampoline(new Trampoline);
341
343
345 [trampoline](
346 GrResourceProvider* resourceProvider,
348 if (!resourceProvider || !trampoline->fProxy ||
349 !trampoline->fProxy->isInstantiated()) {
350 return GrSurfaceProxy::LazyCallbackResult(nullptr, true);
351 }
352
353 SkASSERT(!trampoline->fProxy->peekTexture()->getUniqueKey().isValid());
355 sk_ref_sp(trampoline->fProxy->peekTexture()));
356 },
357 format,
358 dimensions,
359 kSampleCnt,
361 &texInfo,
363 fit,
366 /* wrapsVkSecondaryCB */ false,
368
369 // TODO: It seems like this 'newCT' usage should be 'origCT' but this is
370 // what skgpu::ganesh::SurfaceDrawContext::MakeWithFallback does
371 skgpu::Swizzle swizzle = dContext->priv().caps()->getReadSwizzle(format, newCT);
372
373 return {{std::move(proxy), origin, swizzle}, std::move(trampoline)};
374}
#define SkASSERT(cond)
Definition: SkAssert.h:116
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
const GrCaps * caps() const
Definition: GrCaps.h:57
std::tuple< GrColorType, GrBackendFormat > getFallbackColorTypeAndFormat(GrColorType, int sampleCount) const
Definition: GrCaps.cpp:499
skgpu::Swizzle getReadSwizzle(const GrBackendFormat &format, GrColorType colorType) const
Definition: GrCaps.cpp:443
GrDirectContextPriv priv()
sk_sp< GrRenderTargetProxy > createLazyRenderTargetProxy(LazyInstantiateCallback &&, const GrBackendFormat &, SkISize dimensions, int renderTargetSampleCnt, GrInternalSurfaceFlags, const TextureInfo *, GrMipmapStatus, SkBackingFit, skgpu::Budgeted, GrProtected, bool wrapsVkSecondaryCB, UseAllocator useAllocator)
GrProxyProvider * proxyProvider()
uint32_t uint32_t * format

◆ dropAllRefs()

void GrThreadSafeCache::dropAllRefs ( )

Definition at line 46 of file GrThreadSafeCache.cpp.

46 {
47 SkAutoSpinlock lock{fSpinLock};
48
49 fUniquelyKeyedEntryMap.reset();
50 while (auto tmp = fUniquelyKeyedEntryList.head()) {
51 fUniquelyKeyedEntryList.remove(tmp);
52 this->recycleEntry(tmp);
53 }
54 // TODO: should we empty out the fFreeEntryList and reset fEntryAllocator?
55}

◆ dropUniqueRefs()

void GrThreadSafeCache::dropUniqueRefs ( GrResourceCache resourceCache)

Definition at line 59 of file GrThreadSafeCache.cpp.

59 {
60 SkAutoSpinlock lock{fSpinLock};
61
62 // Iterate from LRU to MRU
63 Entry* cur = fUniquelyKeyedEntryList.tail();
64 Entry* prev = cur ? cur->fPrev : nullptr;
65
66 while (cur) {
67 if (resourceCache && !resourceCache->overBudget()) {
68 return;
69 }
70
71 if (cur->uniquelyHeld()) {
72 fUniquelyKeyedEntryMap.remove(cur->key());
73 fUniquelyKeyedEntryList.remove(cur);
74 this->recycleEntry(cur);
75 }
76
77 cur = prev;
78 prev = cur ? cur->fPrev : nullptr;
79 }
80}
static float prev(float f)
bool overBudget() const

◆ dropUniqueRefsOlderThan()

void GrThreadSafeCache::dropUniqueRefsOlderThan ( skgpu::StdSteadyClock::time_point  purgeTime)

Definition at line 82 of file GrThreadSafeCache.cpp.

82 {
83 SkAutoSpinlock lock{fSpinLock};
84
85 // Iterate from LRU to MRU
86 Entry* cur = fUniquelyKeyedEntryList.tail();
87 Entry* prev = cur ? cur->fPrev : nullptr;
88
89 while (cur) {
90 if (cur->fLastAccess >= purgeTime) {
91 // This entry and all the remaining ones in the list will be newer than 'purgeTime'
92 return;
93 }
94
95 if (cur->uniquelyHeld()) {
96 fUniquelyKeyedEntryMap.remove(cur->key());
97 fUniquelyKeyedEntryList.remove(cur);
98 this->recycleEntry(cur);
99 }
100
101 cur = prev;
102 prev = cur ? cur->fPrev : nullptr;
103 }
104}

◆ findOrAdd()

GrSurfaceProxyView GrThreadSafeCache::findOrAdd ( const skgpu::UniqueKey key,
const GrSurfaceProxyView v 
)

Definition at line 229 of file GrThreadSafeCache.cpp.

230 {
231 SkAutoSpinlock lock{fSpinLock};
232
234 std::tie(view, std::ignore) = this->internalFind(key);
235 if (view) {
236 return view;
237 }
238
239 std::tie(view, std::ignore) = this->internalAdd(key, v);
240 return view;
241}

◆ findOrAddWithData()

std::tuple< GrSurfaceProxyView, sk_sp< SkData > > GrThreadSafeCache::findOrAddWithData ( const skgpu::UniqueKey key,
const GrSurfaceProxyView v 
)

Definition at line 243 of file GrThreadSafeCache.cpp.

245 {
246 SkAutoSpinlock lock{fSpinLock};
247
248 auto [view, data] = this->internalFind(key);
249 if (view) {
250 return { std::move(view), std::move(data) };
251 }
252
253 return this->internalAdd(key, v);
254}
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ findVertsWithData()

std::tuple< sk_sp< GrThreadSafeCache::VertexData >, sk_sp< SkData > > GrThreadSafeCache::findVertsWithData ( const skgpu::UniqueKey key)

Definition at line 280 of file GrThreadSafeCache.cpp.

280 {
281 SkAutoSpinlock lock{fSpinLock};
282
283 return this->internalFindVerts(key);
284}

◆ MakeVertexData() [1/2]

sk_sp< GrThreadSafeCache::VertexData > GrThreadSafeCache::MakeVertexData ( const void *  vertices,
int  vertexCount,
size_t  vertexSize 
)
static

Definition at line 256 of file GrThreadSafeCache.cpp.

258 {
259 return sk_sp<VertexData>(new VertexData(vertices, vertexCount, vertexSize));
260}

◆ MakeVertexData() [2/2]

sk_sp< GrThreadSafeCache::VertexData > GrThreadSafeCache::MakeVertexData ( sk_sp< GrGpuBuffer buffer,
int  vertexCount,
size_t  vertexSize 
)
static

Definition at line 262 of file GrThreadSafeCache.cpp.

264 {
265 return sk_sp<VertexData>(new VertexData(std::move(buffer), vertexCount, vertexSize));
266}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ remove()

void GrThreadSafeCache::remove ( const skgpu::UniqueKey key)

Definition at line 313 of file GrThreadSafeCache.cpp.

313 {
314 SkAutoSpinlock lock{fSpinLock};
315
316 Entry* tmp = fUniquelyKeyedEntryMap.find(key);
317 if (tmp) {
318 fUniquelyKeyedEntryMap.remove(key);
319 fUniquelyKeyedEntryList.remove(tmp);
320 this->recycleEntry(tmp);
321 }
322}

Member Data Documentation

◆ findWithData

std::tuple< GrSurfaceProxyView, sk_sp< SkData > > GrThreadSafeCache::findWithData

Definition at line 90 of file GrThreadSafeCache.h.


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