Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkResourceCache::Key Struct Reference

#include <SkResourceCache.h>

Inheritance diagram for SkResourceCache::Key:
TestKey SkFontRequestCache::Request TestKey

Public Member Functions

void init (void *nameSpace, uint64_t sharedID, size_t dataSize)
 
size_t size () const
 
void * getNamespace () const
 
uint64_t getSharedID () const
 
uint32_t hash () const
 
bool operator== (const Key &other) const
 

Detailed Description

Definition at line 33 of file SkResourceCache.h.

Member Function Documentation

◆ getNamespace()

void * SkResourceCache::Key::getNamespace ( ) const
inline

Definition at line 47 of file SkResourceCache.h.

47{ return fNamespace; }

◆ getSharedID()

uint64_t SkResourceCache::Key::getSharedID ( ) const
inline

Definition at line 48 of file SkResourceCache.h.

48{ return ((uint64_t)fSharedID_hi << 32) | fSharedID_lo; }

◆ hash()

uint32_t SkResourceCache::Key::hash ( ) const
inline

Definition at line 51 of file SkResourceCache.h.

51{ return fHash; }

◆ init()

void SkResourceCache::Key::init ( void *  nameSpace,
uint64_t  sharedID,
size_t  dataSize 
)

Key subclasses must call this after their own fields and data are initialized. All fields and data must be tightly packed.

Parameters
nameSpacemust be unique per Key subclass.
sharedID== 0 means ignore this field, does not support group purging.
dataSizeis size of fields and data of the subclass, must be a multiple of 4.

Definition at line 55 of file SkResourceCache.cpp.

55 {
56 SkASSERT(SkAlign4(dataSize) == dataSize);
57
58 // fCount32 and fHash are not hashed
59 static const int kUnhashedLocal32s = 2; // fCache32 + fHash
60 static const int kSharedIDLocal32s = 2; // fSharedID_lo + fSharedID_hi
61 static const int kHashedLocal32s = kSharedIDLocal32s + (sizeof(fNamespace) >> 2);
62 static const int kLocal32s = kUnhashedLocal32s + kHashedLocal32s;
63
64 static_assert(sizeof(Key) == (kLocal32s << 2), "unaccounted_key_locals");
65 static_assert(sizeof(Key) == offsetof(Key, fNamespace) + sizeof(fNamespace),
66 "namespace_field_must_be_last");
67
68 fCount32 = SkToS32(kLocal32s + (dataSize >> 2));
69 fSharedID_lo = (uint32_t)(sharedID & 0xFFFFFFFF);
70 fSharedID_hi = (uint32_t)(sharedID >> 32);
71 fNamespace = nameSpace;
72 // skip unhashed fields when computing the hash
73 fHash = SkChecksum::Hash32(this->as32() + kUnhashedLocal32s,
74 (fCount32 - kUnhashedLocal32s) << 2);
75}
TArray< uint32_t > Key
static constexpr T SkAlign4(T x)
Definition: SkAlign.h:16
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr int32_t SkToS32(S x)
Definition: SkTo.h:25
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)
Definition: SkChecksum.cpp:113

◆ operator==()

bool SkResourceCache::Key::operator== ( const Key other) const
inline

Definition at line 53 of file SkResourceCache.h.

53 {
54 const uint32_t* a = this->as32();
55 const uint32_t* b = other.as32();
56 for (int i = 0; i < fCount32; ++i) { // (This checks fCount == other.fCount first.)
57 if (a[i] != b[i]) {
58 return false;
59 }
60 }
61 return true;
62 }
static bool b
struct MyStruct a[10]

◆ size()

size_t SkResourceCache::Key::size ( ) const
inline

Returns the size of this key.

Definition at line 43 of file SkResourceCache.h.

43 {
44 return fCount32 << 2;
45 }

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