Flutter Engine
The Flutter Engine
Classes | Macros | Functions | Variables
SkResourceCache.cpp File Reference
#include "src/core/SkResourceCache.h"
#include "include/core/SkGraphics.h"
#include "include/core/SkString.h"
#include "include/core/SkTraceMemoryDump.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkAlign.h"
#include "include/private/base/SkDebug.h"
#include "include/private/base/SkMalloc.h"
#include "include/private/base/SkMath.h"
#include "include/private/base/SkMutex.h"
#include "include/private/base/SkTArray.h"
#include "include/private/base/SkTo.h"
#include "src/core/SkCachedData.h"
#include "src/core/SkChecksum.h"
#include "src/core/SkImageFilter_Base.h"
#include "src/core/SkMessageBus.h"
#include "src/core/SkTHash.h"
#include <algorithm>

Go to the source code of this file.

Classes

class  SkResourceCache::Hash
 

Macros

#define SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT   1024
 
#define SK_DEFAULT_IMAGE_CACHE_LIMIT   (32 * 1024 * 1024)
 

Functions

static bool SkShouldPostMessageToBus (const SkResourceCache::PurgeSharedIDMessage &, uint32_t)
 
static void make_size_str (size_t size, SkString *str)
 
static SkMutex & resource_cache_mutex ()
 
static SkResourceCacheget_cache ()
 
static void dump_visitor (const SkResourceCache::Rec &rec, void *)
 
static void sk_trace_dump_visitor (const SkResourceCache::Rec &rec, void *context)
 

Variables

static bool gDumpCacheTransactions
 
static SkResourceCachegResourceCache = nullptr
 

Macro Definition Documentation

◆ SK_DEFAULT_IMAGE_CACHE_LIMIT

#define SK_DEFAULT_IMAGE_CACHE_LIMIT   (32 * 1024 * 1024)

Definition at line 52 of file SkResourceCache.cpp.

◆ SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT

#define SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT   1024

Definition at line 48 of file SkResourceCache.cpp.

Function Documentation

◆ dump_visitor()

static void dump_visitor ( const SkResourceCache::Rec rec,
void *   
)
static

Definition at line 591 of file SkResourceCache.cpp.

591 {
592 SkDebugf("RC: %12s bytes %9zu discardable %p\n",
594}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
virtual const char * getCategory() const =0
virtual SkDiscardableMemory * diagnostic_only_getDiscardable() const
virtual size_t bytesUsed() const =0

◆ get_cache()

static SkResourceCache * get_cache ( )
static

Must hold resource_cache_mutex() when calling.

Definition at line 473 of file SkResourceCache.cpp.

473 {
474 // resource_cache_mutex() is always held when this is called, so we don't need to be fancy in here.
475 resource_cache_mutex().assertHeld();
476 if (nullptr == gResourceCache) {
477#ifdef SK_USE_DISCARDABLE_SCALEDIMAGECACHE
479#else
481#endif
482 }
483 return gResourceCache;
484}
static SkMutex & resource_cache_mutex()
static SkResourceCache * gResourceCache
#define SK_DEFAULT_IMAGE_CACHE_LIMIT
static SkDiscardableMemory * Create(size_t bytes)

◆ make_size_str()

static void make_size_str ( size_t  size,
SkString str 
)
static

Definition at line 145 of file SkResourceCache.cpp.

145 {
146 const char suffix[] = { 'b', 'k', 'm', 'g', 't', 0 };
147 int i = 0;
148 while (suffix[i] && (size > 1024)) {
149 i += 1;
150 size >>= 10;
151 }
152 str->printf("%zu%c", size, suffix[i]);
153}
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ resource_cache_mutex()

static SkMutex & resource_cache_mutex ( )
static

Definition at line 467 of file SkResourceCache.cpp.

467 {
468 static SkMutex& mutex = *(new SkMutex);
469 return mutex;
470}

◆ sk_trace_dump_visitor()

static void sk_trace_dump_visitor ( const SkResourceCache::Rec rec,
void *  context 
)
static

Definition at line 600 of file SkResourceCache.cpp.

600 {
601 SkTraceMemoryDump* dump = static_cast<SkTraceMemoryDump*>(context);
602 SkString dumpName = SkStringPrintf("skia/sk_resource_cache/%s_%p", rec.getCategory(), &rec);
604 if (discardable) {
605 dump->setDiscardableMemoryBacking(dumpName.c_str(), *discardable);
606
607 // The discardable memory size will be calculated by dumper, but we also dump what we think
608 // the size of object in memory is irrespective of whether object is live or dead.
609 dump->dumpNumericValue(dumpName.c_str(), "discardable_size", "bytes", rec.bytesUsed());
610 } else {
611 dump->dumpNumericValue(dumpName.c_str(), "size", "bytes", rec.bytesUsed());
612 dump->setMemoryBacking(dumpName.c_str(), "malloc", nullptr);
613 }
614}
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static void dump(const float m[20], SkYUVColorSpace cs, bool rgb2yuv)
Definition: SkYUVMath.cpp:629
const char * c_str() const
Definition: SkString.h:133

◆ SkShouldPostMessageToBus()

static bool SkShouldPostMessageToBus ( const SkResourceCache::PurgeSharedIDMessage ,
uint32_t   
)
inlinestatic

Definition at line 37 of file SkResourceCache.cpp.

38 {
39 // SkResourceCache is typically used as a singleton and we don't label Inboxes so all messages
40 // go to all inboxes.
41 return true;
42}

Variable Documentation

◆ gDumpCacheTransactions

bool gDumpCacheTransactions
static

Definition at line 155 of file SkResourceCache.cpp.

◆ gResourceCache

SkResourceCache* gResourceCache = nullptr
static

Definition at line 466 of file SkResourceCache.cpp.