| 1 |
/* |
| 2 |
* Copyright 2006 The Android Open Source Project |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "include/core/SkGraphics.h" |
| 9 |
|
| 10 |
#include "src/core/SkBitmapProcState.h" |
| 11 |
#include "src/core/SkBlitMask.h" |
| 12 |
#include "src/core/SkBlitRow.h" |
| 13 |
#include "src/core/SkCpu.h" |
| 14 |
#include "src/core/SkImageFilter_Base.h" |
| 15 |
#include "src/core/SkMemset.h" |
| 16 |
#include "src/core/SkOpts.h" |
| 17 |
#include "src/core/SkResourceCache.h" |
| 18 |
#include "src/core/SkStrikeCache.h" |
| 19 |
#include "src/core/SkSwizzlePriv.h" |
| 20 |
#include "src/core/SkTypefaceCache.h" |
| 21 |
|
| 22 |
void SkGraphics::Init() { |
| 23 |
// SkGraphics::Init() must be thread-safe and idempotent. |
| 24 |
SkCpu::CacheRuntimeFeatures(); |
| 25 |
SkOpts::Init(); |
| 26 |
SkOpts::Init_BitmapProcState(); |
| 27 |
SkOpts::Init_BlitMask(); |
| 28 |
SkOpts::Init_BlitRow(); |
| 29 |
SkOpts::Init_Memset(); |
| 30 |
SkOpts::Init_Swizzler(); |
| 31 |
} |
| 32 |
|
| 33 |
/////////////////////////////////////////////////////////////////////////////// |
| 34 |
|
| 35 |
void SkGraphics::DumpMemoryStatistics(SkTraceMemoryDump* dump) { |
| 36 |
SkResourceCache::DumpMemoryStatistics(dump); |
| 37 |
SkStrikeCache::DumpMemoryStatistics(dump); |
| 38 |
} |
| 39 |
|
| 40 |
void SkGraphics::PurgeAllCaches() { |
| 41 |
SkGraphics::PurgeFontCache(); |
| 42 |
SkGraphics::PurgeResourceCache(); |
| 43 |
SkImageFilter_Base::PurgeCache(); |
| 44 |
} |
| 45 |
|
| 46 |
/////////////////////////////////////////////////////////////////////////////// |
| 47 |
|
| 48 |
size_t SkGraphics::GetFontCacheLimit() { |
| 49 |
return SkStrikeCache::GlobalStrikeCache()->getCacheSizeLimit(); |
| 50 |
} |
| 51 |
|
| 52 |
size_t SkGraphics::SetFontCacheLimit(size_t bytes) { |
| 53 |
return SkStrikeCache::GlobalStrikeCache()->setCacheSizeLimit(bytes); |
| 54 |
} |
| 55 |
|
| 56 |
size_t SkGraphics::GetFontCacheUsed() { |
| 57 |
return SkStrikeCache::GlobalStrikeCache()->getTotalMemoryUsed(); |
| 58 |
} |
| 59 |
|
| 60 |
int SkGraphics::GetFontCacheCountLimit() { |
| 61 |
return SkStrikeCache::GlobalStrikeCache()->getCacheCountLimit(); |
| 62 |
} |
| 63 |
|
| 64 |
int SkGraphics::SetFontCacheCountLimit(int count) { |
| 65 |
return SkStrikeCache::GlobalStrikeCache()->setCacheCountLimit(count); |
| 66 |
} |
| 67 |
|
| 68 |
int SkGraphics::GetFontCacheCountUsed() { |
| 69 |
return SkStrikeCache::GlobalStrikeCache()->getCacheCountUsed(); |
| 70 |
} |
| 71 |
|
| 72 |
void SkGraphics::PurgeFontCache() { |
| 73 |
SkStrikeCache::GlobalStrikeCache()->purgeAll(); |
| 74 |
SkTypefaceCache::PurgeAll(); |
| 75 |
} |
| 76 |
|
| 77 |
void SkGraphics::PurgePinnedFontCache() { |
| 78 |
SkStrikeCache::GlobalStrikeCache()->purgePinned(); |
| 79 |
} |
| 80 |
|
| 81 |
size_t SkGraphics::GetResourceCacheTotalBytesUsed() { return SkResourceCache::GetTotalBytesUsed(); } |
| 82 |
|
| 83 |
size_t SkGraphics::GetResourceCacheTotalByteLimit() { return SkResourceCache::GetTotalByteLimit(); } |
| 84 |
|
| 85 |
size_t SkGraphics::SetResourceCacheTotalByteLimit(size_t newLimit) { |
| 86 |
return SkResourceCache::SetTotalByteLimit(newLimit); |
| 87 |
} |
| 88 |
|
| 89 |
size_t SkGraphics::GetResourceCacheSingleAllocationByteLimit() { |
| 90 |
return SkResourceCache::GetSingleAllocationByteLimit(); |
| 91 |
} |
| 92 |
|
| 93 |
size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) { |
| 94 |
return SkResourceCache::SetSingleAllocationByteLimit(newLimit); |
| 95 |
} |
| 96 |
|
| 97 |
void SkGraphics::PurgeResourceCache() { |
| 98 |
SkImageFilter_Base::PurgeCache(); |
| 99 |
return SkResourceCache::PurgeAll(); |
| 100 |
} |
| 101 |
|
| 102 |
static int gTypefaceCacheCountLimit = 1024; // historical default value |
| 103 |
|
| 104 |
int SkGraphics::GetTypefaceCacheCountLimit() { |
| 105 |
return gTypefaceCacheCountLimit; |
| 106 |
} |
| 107 |
|
| 108 |
int SkGraphics::SetTypefaceCacheCountLimit(int count) { |
| 109 |
const int prev = gTypefaceCacheCountLimit; |
| 110 |
gTypefaceCacheCountLimit = count; |
| 111 |
return prev; |
| 112 |
} |
| 113 |
|
| 114 |
static SkGraphics::OpenTypeSVGDecoderFactory gSVGDecoderFactory = nullptr; |
| 115 |
|
| 116 |
SkGraphics::OpenTypeSVGDecoderFactory |
| 117 |
SkGraphics::SetOpenTypeSVGDecoderFactory(OpenTypeSVGDecoderFactory svgDecoderFactory) { |
| 118 |
OpenTypeSVGDecoderFactory old(gSVGDecoderFactory); |
| 119 |
gSVGDecoderFactory = svgDecoderFactory; |
| 120 |
return old; |
| 121 |
} |
| 122 |
|
| 123 |
SkGraphics::OpenTypeSVGDecoderFactory SkGraphics::GetOpenTypeSVGDecoderFactory() { |
| 124 |
return gSVGDecoderFactory; |
| 125 |
} |