• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "SkImageRef_GlobalPool.h"
2 #include "SkImageRefPool.h"
3 #include "SkThread.h"
4 
5 extern SkMutex gImageRefMutex;
6 
7 static SkImageRefPool gGlobalImageRefPool;
8 
SkImageRef_GlobalPool(SkStream * stream,SkBitmap::Config config,int sampleSize)9 SkImageRef_GlobalPool::SkImageRef_GlobalPool(SkStream* stream,
10                                              SkBitmap::Config config,
11                                              int sampleSize)
12         : SkImageRef(stream, config, sampleSize) {
13     this->mutex()->acquire();
14     gGlobalImageRefPool.addToHead(this);
15     this->mutex()->release();
16 }
17 
~SkImageRef_GlobalPool()18 SkImageRef_GlobalPool::~SkImageRef_GlobalPool() {
19     this->mutex()->acquire();
20     gGlobalImageRefPool.detach(this);
21     this->mutex()->release();
22 }
23 
onDecode(SkImageDecoder * codec,SkStream * stream,SkBitmap * bitmap,SkBitmap::Config config,SkImageDecoder::Mode mode)24 bool SkImageRef_GlobalPool::onDecode(SkImageDecoder* codec, SkStream* stream,
25                                      SkBitmap* bitmap, SkBitmap::Config config,
26                                      SkImageDecoder::Mode mode) {
27     if (!this->INHERITED::onDecode(codec, stream, bitmap, config, mode)) {
28         return false;
29     }
30     if (mode == SkImageDecoder::kDecodePixels_Mode) {
31         gGlobalImageRefPool.justAddedPixels(this);
32     }
33     return true;
34 }
35 
onUnlockPixels()36 void SkImageRef_GlobalPool::onUnlockPixels() {
37     this->INHERITED::onUnlockPixels();
38 
39     gGlobalImageRefPool.canLosePixels(this);
40 }
41 
SkImageRef_GlobalPool(SkFlattenableReadBuffer & buffer)42 SkImageRef_GlobalPool::SkImageRef_GlobalPool(SkFlattenableReadBuffer& buffer)
43         : INHERITED(buffer) {
44     this->mutex()->acquire();
45     gGlobalImageRefPool.addToHead(this);
46     this->mutex()->release();
47 }
48 
Create(SkFlattenableReadBuffer & buffer)49 SkPixelRef* SkImageRef_GlobalPool::Create(SkFlattenableReadBuffer& buffer) {
50     return SkNEW_ARGS(SkImageRef_GlobalPool, (buffer));
51 }
52 
53 static SkPixelRef::Registrar::Registrar reg("SkImageRef_GlobalPool",
54                                             SkImageRef_GlobalPool::Create);
55 
56 ///////////////////////////////////////////////////////////////////////////////
57 // global imagerefpool wrappers
58 
GetRAMBudget()59 size_t SkImageRef_GlobalPool::GetRAMBudget() {
60     SkAutoMutexAcquire ac(gImageRefMutex);
61     return gGlobalImageRefPool.getRAMBudget();
62 }
63 
SetRAMBudget(size_t size)64 void SkImageRef_GlobalPool::SetRAMBudget(size_t size) {
65     SkAutoMutexAcquire ac(gImageRefMutex);
66     gGlobalImageRefPool.setRAMBudget(size);
67 }
68 
GetRAMUsed()69 size_t SkImageRef_GlobalPool::GetRAMUsed() {
70     SkAutoMutexAcquire ac(gImageRefMutex);
71     return gGlobalImageRefPool.getRAMUsed();
72 }
73 
SetRAMUsed(size_t usage)74 void SkImageRef_GlobalPool::SetRAMUsed(size_t usage) {
75     SkAutoMutexAcquire ac(gImageRefMutex);
76     gGlobalImageRefPool.setRAMUsed(usage);
77 }
78 
DumpPool()79 void SkImageRef_GlobalPool::DumpPool() {
80     SkAutoMutexAcquire ac(gImageRefMutex);
81     gGlobalImageRefPool.dump();
82 }
83 
84