'../src/images/SkImageRef.cpp',
'../src/images/SkImageRefPool.cpp',
'../src/images/SkImageRefPool.h',
+ '../src/images/SkImageRef_ashmem.h',
+ '../src/images/SkImageRef_ashmem.cpp',
'../src/images/SkImageRef_GlobalPool.cpp',
'../src/images/SkImages.cpp',
'../src/images/SkJpegUtility.cpp',
# end libpng stuff
}],
[ 'skia_os == "android"', {
- 'sources!': [
+ 'include_dirs': [
+ '../src/utils',
],
'dependencies': [
'android_deps.gyp:gif',
'defines': [
'SK_ENABLE_LIBPNG',
],
+ },{ #else if skia_os != android
+ 'sources!': [
+ '../src/images/SkImageRef_ashmem.h',
+ '../src/images/SkImageRef_ashmem.cpp',
+ ],
}],
[ 'skia_os == "ios"', {
'include_dirs': [
'../src/ports/SkFontHost_FreeType.cpp',
'../src/ports/SkFontHost_FreeType_common.cpp',
'../src/ports/FontHostConfiguration_android.cpp',
- '../src/ports/SkImageRef_ashmem.cpp',
],
'dependencies': [
'freetype.gyp:freetype',
// Performance tweak to avoid those calls (esp. in multi-thread use case).
void setPreLocked(void* pixels, SkColorTable* ctable);
- /**
- * If a subclass passed a particular mutex to the base constructor, it can
- * override that to go back to the default mutex by calling this. However,
- * this should only be called from within the subclass' constructor.
- */
- void useDefaultMutex() { this->setMutex(NULL); }
-
private:
SkBaseMutex* fMutex; // must remain in scope for the life of this object
@param config The preferred config of the decoded bitmap.
@param sampleSize Requested sampleSize for decoding. Defaults to 1.
*/
- SkImageRef(SkStream*, SkBitmap::Config config, int sampleSize = 1);
+ SkImageRef(SkStream*, SkBitmap::Config config, int sampleSize = 1, SkBaseMutex* mutex = NULL);
virtual ~SkImageRef();
/** this value is passed onto the decoder. Default is true
virtual void* onLockPixels(SkColorTable**);
// override this in your subclass to clean up when we're unlocking pixels
- virtual void onUnlockPixels();
+ virtual void onUnlockPixels() {}
- SkImageRef(SkFlattenableReadBuffer&);
+ SkImageRef(SkFlattenableReadBuffer&, SkBaseMutex* mutex = NULL);
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
SkBitmap fBitmap;
//#define DUMP_IMAGEREF_LIFECYCLE
-// can't be static, as SkImageRef_Pool needs to see it
-SK_DECLARE_GLOBAL_MUTEX(gImageRefMutex);
///////////////////////////////////////////////////////////////////////////////
SkImageRef::SkImageRef(SkStream* stream, SkBitmap::Config config,
- int sampleSize)
- : SkPixelRef(&gImageRefMutex), fErrorInDecoding(false) {
+ int sampleSize, SkBaseMutex* mutex)
+ : SkPixelRef(mutex), fErrorInDecoding(false) {
SkASSERT(stream);
stream->ref();
fStream = stream;
}
SkImageRef::~SkImageRef() {
- SkASSERT(&gImageRefMutex == this->mutex());
#ifdef DUMP_IMAGEREF_LIFECYCLE
SkDebugf("delete ImageRef %p [%d] data=%d\n",
}
bool SkImageRef::getInfo(SkBitmap* bitmap) {
- SkAutoMutexAcquire ac(gImageRefMutex);
+ SkAutoMutexAcquire ac(this->mutex());
if (!this->prepareBitmap(SkImageDecoder::kDecodeBounds_Mode)) {
return false;
}
bool SkImageRef::prepareBitmap(SkImageDecoder::Mode mode) {
- SkASSERT(&gImageRefMutex == this->mutex());
if (fErrorInDecoding) {
return false;
}
void* SkImageRef::onLockPixels(SkColorTable** ct) {
- SkASSERT(&gImageRefMutex == this->mutex());
-
if (NULL == fBitmap.getPixels()) {
(void)this->prepareBitmap(SkImageDecoder::kDecodePixels_Mode);
}
return fBitmap.getPixels();
}
-void SkImageRef::onUnlockPixels() {
- // we're already have the mutex locked
- SkASSERT(&gImageRefMutex == this->mutex());
-}
-
size_t SkImageRef::ramUsed() const {
size_t size = 0;
///////////////////////////////////////////////////////////////////////////////
-SkImageRef::SkImageRef(SkFlattenableReadBuffer& buffer)
- : INHERITED(buffer, &gImageRefMutex), fErrorInDecoding(false) {
+SkImageRef::SkImageRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex)
+ : INHERITED(buffer, mutex), fErrorInDecoding(false) {
fConfig = (SkBitmap::Config)buffer.readUInt();
fSampleSize = buffer.readInt();
fDoDither = buffer.readBool();
#include "SkImageRefPool.h"
#include "SkThread.h"
-extern SkBaseMutex gImageRefMutex;
+SK_DECLARE_STATIC_MUTEX(gGlobalPoolMutex);
/*
* This returns the lazily-allocated global pool. It must be called
SkImageRef_GlobalPool::SkImageRef_GlobalPool(SkStream* stream,
SkBitmap::Config config,
int sampleSize)
- : SkImageRef(stream, config, sampleSize) {
- this->mutex()->acquire();
+ : SkImageRef(stream, config, sampleSize, &gGlobalPoolMutex) {
+ SkASSERT(&gGlobalPoolMutex == this->mutex());
+ SkAutoMutexAcquire ac(gGlobalPoolMutex);
GetGlobalPool()->addToHead(this);
- this->mutex()->release();
}
SkImageRef_GlobalPool::~SkImageRef_GlobalPool() {
- this->mutex()->acquire();
+ SkASSERT(&gGlobalPoolMutex == this->mutex());
+ SkAutoMutexAcquire ac(gGlobalPoolMutex);
GetGlobalPool()->detach(this);
- this->mutex()->release();
}
/* By design, onUnlockPixels() already is inside the mutex-lock,
}
SkImageRef_GlobalPool::SkImageRef_GlobalPool(SkFlattenableReadBuffer& buffer)
- : INHERITED(buffer) {
- this->mutex()->acquire();
+ : INHERITED(buffer, &gGlobalPoolMutex) {
+ SkASSERT(&gGlobalPoolMutex == this->mutex());
+ SkAutoMutexAcquire ac(gGlobalPoolMutex);
GetGlobalPool()->addToHead(this);
- this->mutex()->release();
}
///////////////////////////////////////////////////////////////////////////////
// global imagerefpool wrappers
size_t SkImageRef_GlobalPool::GetRAMBudget() {
- SkAutoMutexAcquire ac(gImageRefMutex);
+ SkAutoMutexAcquire ac(gGlobalPoolMutex);
return GetGlobalPool()->getRAMBudget();
}
void SkImageRef_GlobalPool::SetRAMBudget(size_t size) {
- SkAutoMutexAcquire ac(gImageRefMutex);
+ SkAutoMutexAcquire ac(gGlobalPoolMutex);
GetGlobalPool()->setRAMBudget(size);
}
size_t SkImageRef_GlobalPool::GetRAMUsed() {
- SkAutoMutexAcquire ac(gImageRefMutex);
+ SkAutoMutexAcquire ac(gGlobalPoolMutex);
return GetGlobalPool()->getRAMUsed();
}
void SkImageRef_GlobalPool::SetRAMUsed(size_t usage) {
- SkAutoMutexAcquire ac(gImageRefMutex);
+ SkAutoMutexAcquire ac(gGlobalPoolMutex);
GetGlobalPool()->setRAMUsed(usage);
}
void SkImageRef_GlobalPool::DumpPool() {
- SkAutoMutexAcquire ac(gImageRefMutex);
+ SkAutoMutexAcquire ac(gGlobalPoolMutex);
GetGlobalPool()->dump();
}
fRec.fPinned = false;
fCT = NULL;
-
- this->useDefaultMutex(); // we don't need/want the shared imageref mutex
}
SkImageRef_ashmem::~SkImageRef_ashmem() {
setURI(uri);
sk_free(uri);
}
- this->useDefaultMutex(); // we don't need/want the shared imageref mutex
}
#include "SkImageRef_GlobalPool.h"
#include "SkImages.h"
+#ifdef SK_BUILD_FOR_ANDROID
+#include "SkImageRef_ashmem.h"
+#endif
+
void SkImages::InitializeFlattenables() {
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkImageRef_GlobalPool)
+#ifdef SK_BUILD_FOR_ANDROID
+ SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkImageRef_ashmem)
+#endif
}
#include "SkTypes.h"
#include "SkBitmapProcShader.h"
-#include "SkImageRef_ashmem.h"
#include "SkMallocPixelRef.h"
#include "SkPathEffect.h"
#include "SkPixelRef.h"