Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
SkBitmapCache::Rec Class Reference
Inheritance diagram for SkBitmapCache::Rec:
SkResourceCache::Rec

Public Member Functions

 Rec (const SkBitmapCacheDesc &desc, const SkImageInfo &info, size_t rowBytes, std::unique_ptr< SkDiscardableMemory > dm, void *block)
 
 ~Rec () override
 
const KeygetKey () const override
 
size_t bytesUsed () const override
 
bool canBePurged () override
 
void postAddInstall (void *payload) override
 
const char * getCategory () const override
 
SkDiscardableMemorydiagnostic_only_getDiscardable () const override
 
bool install (SkBitmap *bitmap)
 
- Public Member Functions inherited from SkResourceCache::Rec
 Rec ()
 
virtual ~Rec ()
 
uint32_t getHash () const
 
virtual const KeygetKey () const =0
 
virtual size_t bytesUsed () const =0
 
virtual bool canBePurged ()
 
virtual void postAddInstall (void *)
 
virtual const char * getCategory () const =0
 
virtual SkDiscardableMemorydiagnostic_only_getDiscardable () const
 

Static Public Member Functions

static void ReleaseProc (void *addr, void *ctx)
 
static bool Finder (const SkResourceCache::Rec &baseRec, void *contextBitmap)
 

Additional Inherited Members

- Public Types inherited from SkResourceCache::Rec
typedef SkResourceCache::Key Key
 

Detailed Description

Definition at line 74 of file SkBitmapCache.cpp.

Constructor & Destructor Documentation

◆ Rec()

SkBitmapCache::Rec::Rec ( const SkBitmapCacheDesc desc,
const SkImageInfo info,
size_t  rowBytes,
std::unique_ptr< SkDiscardableMemory dm,
void *  block 
)
inline

Definition at line 76 of file SkBitmapCache.cpp.

78 : fKey(desc)
79 , fDM(std::move(dm))
80 , fMalloc(block)
81 , fInfo(info)
82 , fRowBytes(rowBytes)
83 {
84 SkASSERT(!(fDM && fMalloc)); // can't have both
85
86 // We need an ID to return with the bitmap/pixelref. We can't necessarily use the key/desc
87 // ID - lazy images cache the same ID with multiple keys (in different color types).
88 fPrUniqueID = SkNextID::ImageID();
89 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkASSERT(cond)
Definition: SkAssert.h:116
static uint32_t ImageID()
Definition: SkPixelRef.cpp:19

◆ ~Rec()

SkBitmapCache::Rec::~Rec ( )
inlineoverridevirtual

Reimplemented from SkResourceCache::Rec.

Definition at line 91 of file SkBitmapCache.cpp.

91 {
92 SkASSERT(0 == fExternalCounter);
93 if (fDM && fDiscardableIsLocked) {
94 SkASSERT(fDM->data());
95 fDM->unlock();
96 }
97 sk_free(fMalloc); // may be null
98 }
SK_API void sk_free(void *)

Member Function Documentation

◆ bytesUsed()

size_t SkBitmapCache::Rec::bytesUsed ( ) const
inlineoverridevirtual

Implements SkResourceCache::Rec.

Definition at line 101 of file SkBitmapCache.cpp.

101 {
102 return sizeof(fKey) + fInfo.computeByteSize(fRowBytes);
103 }
size_t computeByteSize(size_t rowBytes) const

◆ canBePurged()

bool SkBitmapCache::Rec::canBePurged ( )
inlineoverridevirtual

Reimplemented from SkResourceCache::Rec.

Definition at line 104 of file SkBitmapCache.cpp.

104 {
105 SkAutoMutexExclusive ama(fMutex);
106 return fExternalCounter == 0;
107 }

◆ diagnostic_only_getDiscardable()

SkDiscardableMemory * SkBitmapCache::Rec::diagnostic_only_getDiscardable ( ) const
inlineoverridevirtual

Reimplemented from SkResourceCache::Rec.

Definition at line 113 of file SkBitmapCache.cpp.

113 {
114 return fDM.get();
115 }

◆ Finder()

static bool SkBitmapCache::Rec::Finder ( const SkResourceCache::Rec baseRec,
void *  contextBitmap 
)
inlinestatic

Definition at line 160 of file SkBitmapCache.cpp.

160 {
161 Rec* rec = const_cast<Rec*>(static_cast<const Rec*>(&baseRec));
162 SkBitmap* result = (SkBitmap*)contextBitmap;
163 return rec->install(result);
164 }
GAsyncResult * result

◆ getCategory()

const char * SkBitmapCache::Rec::getCategory ( ) const
inlineoverridevirtual

Implements SkResourceCache::Rec.

Definition at line 112 of file SkBitmapCache.cpp.

112{ return "bitmap"; }

◆ getKey()

const Key & SkBitmapCache::Rec::getKey ( ) const
inlineoverridevirtual

Implements SkResourceCache::Rec.

Definition at line 100 of file SkBitmapCache.cpp.

100{ return fKey; }

◆ install()

bool SkBitmapCache::Rec::install ( SkBitmap bitmap)
inline

Definition at line 134 of file SkBitmapCache.cpp.

134 {
135 SkAutoMutexExclusive ama(fMutex);
136
137 if (!fDM && !fMalloc) {
138 return false;
139 }
140
141 if (fDM) {
142 if (!fDiscardableIsLocked) {
143 SkASSERT(fExternalCounter == 0);
144 if (!fDM->lock()) {
145 fDM.reset(nullptr);
146 return false;
147 }
148 fDiscardableIsLocked = true;
149 }
150 SkASSERT(fDM->data());
151 }
152
153 bitmap->installPixels(fInfo, fDM ? fDM->data() : fMalloc, fRowBytes, ReleaseProc, this);
154 SkBitmapCache_setImmutableWithID(bitmap->pixelRef(), fPrUniqueID);
155 fExternalCounter++;
156
157 return true;
158 }
void SkBitmapCache_setImmutableWithID(SkPixelRef *pr, uint32_t id)
static void ReleaseProc(void *addr, void *ctx)
Definition: bitmap.py:1

◆ postAddInstall()

void SkBitmapCache::Rec::postAddInstall ( void *  payload)
inlineoverridevirtual

Reimplemented from SkResourceCache::Rec.

Definition at line 108 of file SkBitmapCache.cpp.

108 {
109 SkAssertResult(this->install(static_cast<SkBitmap*>(payload)));
110 }
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
bool install(SkBitmap *bitmap)

◆ ReleaseProc()

static void SkBitmapCache::Rec::ReleaseProc ( void *  addr,
void *  ctx 
)
inlinestatic

Definition at line 117 of file SkBitmapCache.cpp.

117 {
118 Rec* rec = static_cast<Rec*>(ctx);
119 SkAutoMutexExclusive ama(rec->fMutex);
120
121 SkASSERT(rec->fExternalCounter > 0);
122 rec->fExternalCounter -= 1;
123 if (rec->fDM) {
124 SkASSERT(rec->fMalloc == nullptr);
125 if (rec->fExternalCounter == 0) {
126 rec->fDM->unlock();
127 rec->fDiscardableIsLocked = false;
128 }
129 } else {
130 SkASSERT(rec->fMalloc != nullptr);
131 }
132 }

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