aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gyp/images.gyp10
-rw-r--r--gyp/ports.gyp1
-rw-r--r--include/core/SkPixelRef.h7
-rw-r--r--include/images/SkImageRef.h6
-rw-r--r--src/images/SkImageRef.cpp21
-rw-r--r--src/images/SkImageRef_GlobalPool.cpp28
-rw-r--r--src/images/SkImageRef_ashmem.cpp (renamed from src/ports/SkImageRef_ashmem.cpp)3
-rw-r--r--src/images/SkImageRef_ashmem.h (renamed from src/ports/SkImageRef_ashmem.h)0
-rw-r--r--src/images/SkImages.cpp7
-rw-r--r--src/ports/SkGlobalInitialization_default.cpp1
10 files changed, 38 insertions, 46 deletions
diff --git a/gyp/images.gyp b/gyp/images.gyp
index 1bfd2d30b9..8c4690e574 100644
--- a/gyp/images.gyp
+++ b/gyp/images.gyp
@@ -44,6 +44,8 @@
'../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',
@@ -109,7 +111,8 @@
# end libpng stuff
}],
[ 'skia_os == "android"', {
- 'sources!': [
+ 'include_dirs': [
+ '../src/utils',
],
'dependencies': [
'android_deps.gyp:gif',
@@ -118,6 +121,11 @@
'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': [
diff --git a/gyp/ports.gyp b/gyp/ports.gyp
index 0b298d13c9..219bf3edc6 100644
--- a/gyp/ports.gyp
+++ b/gyp/ports.gyp
@@ -161,7 +161,6 @@
'../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',
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
index 618cc711c9..89ce69ae5b 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -216,13 +216,6 @@ protected:
// 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
diff --git a/include/images/SkImageRef.h b/include/images/SkImageRef.h
index dcc4c0e240..bca4305b5b 100644
--- a/include/images/SkImageRef.h
+++ b/include/images/SkImageRef.h
@@ -34,7 +34,7 @@ public:
@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
@@ -73,9 +73,9 @@ protected:
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;
diff --git a/src/images/SkImageRef.cpp b/src/images/SkImageRef.cpp
index 3ed62fb98b..299166c31c 100644
--- a/src/images/SkImageRef.cpp
+++ b/src/images/SkImageRef.cpp
@@ -15,14 +15,12 @@
//#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;
@@ -39,7 +37,6 @@ SkImageRef::SkImageRef(SkStream* stream, SkBitmap::Config config,
}
SkImageRef::~SkImageRef() {
- SkASSERT(&gImageRefMutex == this->mutex());
#ifdef DUMP_IMAGEREF_LIFECYCLE
SkDebugf("delete ImageRef %p [%d] data=%d\n",
@@ -51,7 +48,7 @@ SkImageRef::~SkImageRef() {
}
bool SkImageRef::getInfo(SkBitmap* bitmap) {
- SkAutoMutexAcquire ac(gImageRefMutex);
+ SkAutoMutexAcquire ac(this->mutex());
if (!this->prepareBitmap(SkImageDecoder::kDecodeBounds_Mode)) {
return false;
@@ -89,7 +86,6 @@ bool SkImageRef::onDecode(SkImageDecoder* codec, SkStream* stream,
}
bool SkImageRef::prepareBitmap(SkImageDecoder::Mode mode) {
- SkASSERT(&gImageRefMutex == this->mutex());
if (fErrorInDecoding) {
return false;
@@ -144,8 +140,6 @@ bool SkImageRef::prepareBitmap(SkImageDecoder::Mode mode) {
}
void* SkImageRef::onLockPixels(SkColorTable** ct) {
- SkASSERT(&gImageRefMutex == this->mutex());
-
if (NULL == fBitmap.getPixels()) {
(void)this->prepareBitmap(SkImageDecoder::kDecodePixels_Mode);
}
@@ -156,11 +150,6 @@ void* SkImageRef::onLockPixels(SkColorTable** ct) {
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;
@@ -175,8 +164,8 @@ size_t SkImageRef::ramUsed() const {
///////////////////////////////////////////////////////////////////////////////
-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();
diff --git a/src/images/SkImageRef_GlobalPool.cpp b/src/images/SkImageRef_GlobalPool.cpp
index e62816aa30..6af8653217 100644
--- a/src/images/SkImageRef_GlobalPool.cpp
+++ b/src/images/SkImageRef_GlobalPool.cpp
@@ -9,7 +9,7 @@
#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
@@ -27,16 +27,16 @@ static SkImageRefPool* GetGlobalPool() {
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,
@@ -65,36 +65,36 @@ void SkImageRef_GlobalPool::onUnlockPixels() {
}
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();
}
diff --git a/src/ports/SkImageRef_ashmem.cpp b/src/images/SkImageRef_ashmem.cpp
index f8a9bb9f90..dc60465124 100644
--- a/src/ports/SkImageRef_ashmem.cpp
+++ b/src/images/SkImageRef_ashmem.cpp
@@ -42,8 +42,6 @@ SkImageRef_ashmem::SkImageRef_ashmem(SkStream* stream,
fRec.fPinned = false;
fCT = NULL;
-
- this->useDefaultMutex(); // we don't need/want the shared imageref mutex
}
SkImageRef_ashmem::~SkImageRef_ashmem() {
@@ -230,5 +228,4 @@ SkImageRef_ashmem::SkImageRef_ashmem(SkFlattenableReadBuffer& buffer)
setURI(uri);
sk_free(uri);
}
- this->useDefaultMutex(); // we don't need/want the shared imageref mutex
}
diff --git a/src/ports/SkImageRef_ashmem.h b/src/images/SkImageRef_ashmem.h
index f98507aabc..f98507aabc 100644
--- a/src/ports/SkImageRef_ashmem.h
+++ b/src/images/SkImageRef_ashmem.h
diff --git a/src/images/SkImages.cpp b/src/images/SkImages.cpp
index 0bcc33fa51..5b6bf6b7ce 100644
--- a/src/images/SkImages.cpp
+++ b/src/images/SkImages.cpp
@@ -9,6 +9,13 @@
#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
}
diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp
index 824895a5e4..26a61ca394 100644
--- a/src/ports/SkGlobalInitialization_default.cpp
+++ b/src/ports/SkGlobalInitialization_default.cpp
@@ -8,7 +8,6 @@
#include "SkTypes.h"
#include "SkBitmapProcShader.h"
-#include "SkImageRef_ashmem.h"
#include "SkMallocPixelRef.h"
#include "SkPathEffect.h"
#include "SkPixelRef.h"