Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Functions
ResourceKey.h File Reference
#include "include/core/SkData.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkAlign.h"
#include "include/private/base/SkAlignedStorage.h"
#include "include/private/base/SkDebug.h"
#include "include/private/base/SkTemplates.h"
#include "include/private/base/SkTo.h"
#include <cstdint>
#include <cstring>
#include <new>
#include <utility>

Go to the source code of this file.

Classes

class  skgpu::ResourceKey
 
class  skgpu::ResourceKey::Builder
 
class  skgpu::ScratchKey
 
class  skgpu::ScratchKey::Builder
 
class  skgpu::UniqueKey
 
class  skgpu::UniqueKey::Builder
 
class  skgpu::UniqueKeyInvalidatedMessage
 
class  skgpu::UniqueKeyInvalidatedMsg_Graphite
 

Namespaces

namespace  skgpu
 

Macros

#define SKGPU_DECLARE_STATIC_UNIQUE_KEY(name)   static SkOnce name##_once
 
#define SKGPU_DEFINE_STATIC_UNIQUE_KEY(name)
 

Functions

uint32_t skgpu::ResourceKeyHash (const uint32_t *data, size_t size)
 
static void skgpu::skgpu_init_static_unique_key_once (SkAlignedSTStorage< 1, UniqueKey > *keyStorage)
 
static bool skgpu::SkShouldPostMessageToBus (const UniqueKeyInvalidatedMessage &msg, uint32_t msgBusUniqueID)
 
static bool skgpu::SkShouldPostMessageToBus (const UniqueKeyInvalidatedMsg_Graphite &msg, uint32_t msgBusUniqueID)
 

Macro Definition Documentation

◆ SKGPU_DECLARE_STATIC_UNIQUE_KEY

#define SKGPU_DECLARE_STATIC_UNIQUE_KEY (   name)    static SkOnce name##_once

It is common to need a frequently reused UniqueKey where the only requirement is that the key is unique. These macros create such a key in a thread safe manner so the key can be truly global and only constructed once. Place outside of function/class definitions.

Definition at line 321 of file ResourceKey.h.

◆ SKGPU_DEFINE_STATIC_UNIQUE_KEY

#define SKGPU_DEFINE_STATIC_UNIQUE_KEY (   name)
Value:
static const skgpu::UniqueKey& name = \
*reinterpret_cast<skgpu::UniqueKey*>(name##_storage.get())
const char * name
Definition fuchsia.cc:50
static void skgpu_init_static_unique_key_once(SkAlignedSTStorage< 1, UniqueKey > *keyStorage)

Place inside function where the key is used.

Definition at line 324 of file ResourceKey.h.

329 {
330 UniqueKey* key = new (keyStorage->get()) UniqueKey;
331 UniqueKey::Builder builder(key, UniqueKey::GenerateDomain(), 0);
332}
333
334// The cache listens for these messages to purge junk resources proactively.
335class UniqueKeyInvalidatedMessage {
336public:
337 UniqueKeyInvalidatedMessage() = default;
338 UniqueKeyInvalidatedMessage(const UniqueKey& key,
339 uint32_t contextUniqueID,
340 bool inThreadSafeCache = false)
341 : fKey(key), fContextID(contextUniqueID), fInThreadSafeCache(inThreadSafeCache) {
342 SkASSERT(SK_InvalidUniqueID != contextUniqueID);
343 }
344
345 UniqueKeyInvalidatedMessage(const UniqueKeyInvalidatedMessage&) = default;
346
347 UniqueKeyInvalidatedMessage& operator=(const UniqueKeyInvalidatedMessage&) = default;
348
349 const UniqueKey& key() const { return fKey; }
350 uint32_t contextID() const { return fContextID; }
351 bool inThreadSafeCache() const { return fInThreadSafeCache; }
352
353private:
354 UniqueKey fKey;
355 uint32_t fContextID = SK_InvalidUniqueID;
356 bool fInThreadSafeCache = false;
357};
358
359static inline bool SkShouldPostMessageToBus(const UniqueKeyInvalidatedMessage& msg,
360 uint32_t msgBusUniqueID) {
361 return msg.contextID() == msgBusUniqueID;
362}
363
364class UniqueKeyInvalidatedMsg_Graphite {
365public:
366 UniqueKeyInvalidatedMsg_Graphite() = default;
367 UniqueKeyInvalidatedMsg_Graphite(const UniqueKey& key, uint32_t recorderID)
368 : fKey(key), fRecorderID(recorderID) {
369 SkASSERT(SK_InvalidUniqueID != fRecorderID);
370 }
371
372 UniqueKeyInvalidatedMsg_Graphite(const UniqueKeyInvalidatedMsg_Graphite&) = default;
373
374 UniqueKeyInvalidatedMsg_Graphite& operator=(const UniqueKeyInvalidatedMsg_Graphite&) = default;
375
376 const UniqueKey& key() const { return fKey; }
377 uint32_t recorderID() const { return fRecorderID; }
378
379private:
380 UniqueKey fKey;
381 uint32_t fRecorderID = SK_InvalidUniqueID;
382};
383
384static inline bool SkShouldPostMessageToBus(const UniqueKeyInvalidatedMsg_Graphite& msg,
385 uint32_t msgBusUniqueID) {
386 return msg.recorderID() == msgBusUniqueID;
387}
388
389} // namespace skgpu
390
391#endif // skgpu_ResourceKey_DEFINED
#define SkASSERT(cond)
Definition SkAssert.h:116
static bool SkShouldPostMessageToBus(const SkResourceCache::PurgeSharedIDMessage &, uint32_t)
static constexpr uint32_t SK_InvalidUniqueID
Definition SkTypes.h:196