diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-01-03 16:32:45 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-01-03 16:32:45 +0000 |
commit | 27f890219b09e4774da75e6a11ec82849eadae5a (patch) | |
tree | c3b4cf408291039b44e7b4fb5e5c0ea77a0bf04b /src/core | |
parent | f1ce05288a8fee6e691c3dff5db9dcd47818060f (diff) |
Reason for revert: SkImageRef_ashmem doesn't compile
R=halcanary@google.com, scroggo@google.com
TBR=halcanary@google.com, scroggo@google.com
NOTREECHECKS=true
NOTRY=true
BUG=
Author: reed@google.com
Review URL: https://codereview.chromium.org/119753009
git-svn-id: http://skia.googlecode.com/svn/trunk@12884 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkBitmapDevice.cpp | 35 | ||||
-rw-r--r-- | src/core/SkMallocPixelRef.cpp | 16 | ||||
-rw-r--r-- | src/core/SkPixelRef.cpp | 79 | ||||
-rw-r--r-- | src/core/SkScaledImageCache.cpp | 23 |
4 files changed, 60 insertions, 93 deletions
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index 368c807511..1668618cf7 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -24,30 +24,31 @@ SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& , fBitmap(bitmap) { } -void SkBitmapDevice::init(SkBitmap::Config config, int width, int height, bool isOpaque) { +SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque) { fBitmap.setConfig(config, width, height, 0, isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); - - if (SkBitmap::kNo_Config != config) { - if (!fBitmap.allocPixels()) { - // indicate failure by zeroing our bitmap - fBitmap.setConfig(config, 0, 0, 0, isOpaque ? - kOpaque_SkAlphaType : kPremul_SkAlphaType); - } else if (!isOpaque) { - fBitmap.eraseColor(SK_ColorTRANSPARENT); - } + if (!fBitmap.allocPixels()) { + fBitmap.setConfig(config, 0, 0, 0, isOpaque ? + kOpaque_SkAlphaType : kPremul_SkAlphaType); + } + if (!isOpaque) { + fBitmap.eraseColor(SK_ColorTRANSPARENT); } -} - -SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque) { - this->init(config, width, height, isOpaque); } SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque, const SkDeviceProperties& deviceProperties) - : SkBaseDevice(deviceProperties) -{ - this->init(config, width, height, isOpaque); + : SkBaseDevice(deviceProperties) { + + fBitmap.setConfig(config, width, height, 0, isOpaque ? + kOpaque_SkAlphaType : kPremul_SkAlphaType); + if (!fBitmap.allocPixels()) { + fBitmap.setConfig(config, 0, 0, 0, isOpaque ? + kOpaque_SkAlphaType : kPremul_SkAlphaType); + } + if (!isOpaque) { + fBitmap.eraseColor(SK_ColorTRANSPARENT); + } } SkBitmapDevice::~SkBitmapDevice() { diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp index c86d33bf18..c3e605c358 100644 --- a/src/core/SkMallocPixelRef.cpp +++ b/src/core/SkMallocPixelRef.cpp @@ -152,7 +152,7 @@ SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage, fRB = rowBytes; SkSafeRef(ctable); - this->setPreLocked(fStorage, fRB, fCTable); + this->setPreLocked(fStorage, fCTable); } SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage, @@ -174,8 +174,8 @@ SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage, fCTable = ctable; fRB = rowBytes; SkSafeRef(ctable); - - this->setPreLocked(fStorage, fRB, fCTable); + + this->setPreLocked(fStorage, fCTable); } @@ -186,11 +186,9 @@ SkMallocPixelRef::~SkMallocPixelRef() { } } -bool SkMallocPixelRef::onNewLockPixels(LockRec* rec) { - rec->fPixels = fStorage; - rec->fRowBytes = fRB; - rec->fColorTable = fCTable; - return true; +void* SkMallocPixelRef::onLockPixels(SkColorTable** ctable) { + *ctable = fCTable; + return fStorage; } void SkMallocPixelRef::onUnlockPixels() { @@ -236,5 +234,5 @@ SkMallocPixelRef::SkMallocPixelRef(SkFlattenableReadBuffer& buffer) fCTable = NULL; } - this->setPreLocked(fStorage, fRB, fCTable); + this->setPreLocked(fStorage, fCTable); } diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp index 7ec5929669..fedbb5ac7d 100644 --- a/src/core/SkPixelRef.cpp +++ b/src/core/SkPixelRef.cpp @@ -82,19 +82,20 @@ void SkPixelRef::setMutex(SkBaseMutex* mutex) { // just need a > 0 value, so pick a funny one to aid in debugging #define SKPIXELREF_PRELOCKED_LOCKCOUNT 123456789 -SkPixelRef::SkPixelRef(const SkImageInfo& info) : fInfo(info) { - this->setMutex(NULL); - fRec.zero(); +SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) : fInfo(info) { + this->setMutex(mutex); + fPixels = NULL; + fColorTable = NULL; // we do not track ownership of this fLockCount = 0; this->needsNewGenID(); fIsImmutable = false; fPreLocked = false; } - -SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) : fInfo(info) { - this->setMutex(mutex); - fRec.zero(); +SkPixelRef::SkPixelRef(const SkImageInfo& info) : fInfo(info) { + this->setMutex(NULL); + fPixels = NULL; + fColorTable = NULL; // we do not track ownership of this fLockCount = 0; this->needsNewGenID(); fIsImmutable = false; @@ -112,7 +113,8 @@ SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex) , fInfo(read_info(buffer)) { this->setMutex(mutex); - fRec.zero(); + fPixels = NULL; + fColorTable = NULL; // we do not track ownership of this fLockCount = 0; fIsImmutable = buffer.readBool(); fGenerationID = buffer.readUInt(); @@ -136,13 +138,12 @@ void SkPixelRef::cloneGenID(const SkPixelRef& that) { that.fUniqueGenerationID = false; } -void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctable) { +void SkPixelRef::setPreLocked(void* pixels, SkColorTable* ctable) { #ifndef SK_IGNORE_PIXELREF_SETPRELOCKED // only call me in your constructor, otherwise fLockCount tracking can get // out of sync. - fRec.fPixels = pixels; - fRec.fColorTable = ctable; - fRec.fRowBytes = rowBytes; + fPixels = pixels; + fColorTable = ctable; fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT; fPreLocked = true; #endif @@ -165,30 +166,20 @@ void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { } } -bool SkPixelRef::lockPixels(LockRec* rec) { +void SkPixelRef::lockPixels() { SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); - + if (!fPreLocked) { SkAutoMutexAcquire ac(*fMutex); - - if (1 == ++fLockCount) { - SkASSERT(fRec.isZero()); - LockRec rec; - if (!this->onNewLockPixels(&rec)) { - return false; + if (1 == ++fLockCount) { + fPixels = this->onLockPixels(&fColorTable); + // If onLockPixels failed, it will return NULL + if (NULL == fPixels) { + fColorTable = NULL; } - SkASSERT(!rec.isZero()); // else why did onNewLock return true? - fRec = rec; } } - *rec = fRec; - return true; -} - -bool SkPixelRef::lockPixels() { - LockRec rec; - return this->lockPixels(&rec); } void SkPixelRef::unlockPixels() { @@ -200,11 +191,12 @@ void SkPixelRef::unlockPixels() { SkASSERT(fLockCount > 0); if (0 == --fLockCount) { // don't call onUnlockPixels unless onLockPixels succeeded - if (fRec.fPixels) { + if (fPixels) { this->onUnlockPixels(); - fRec.zero(); + fPixels = NULL; + fColorTable = NULL; } else { - SkASSERT(fRec.isZero()); + SkASSERT(NULL == fColorTable); } } } @@ -286,29 +278,6 @@ size_t SkPixelRef::getAllocatedSizeInBytes() const { /////////////////////////////////////////////////////////////////////////////// -#ifdef SK_SUPPORT_LEGACY_ONLOCKPIXELS - -void* SkPixelRef::onLockPixels(SkColorTable** ctable) { - return NULL; -} - -bool SkPixelRef::onNewLockPixels(LockRec* rec) { - SkColorTable* ctable; - void* pixels = this->onLockPixels(&ctable); - if (!pixels) { - return false; - } - - rec->fPixels = pixels; - rec->fColorTable = ctable; - rec->fRowBytes = 0; // callers don't currently need this (thank goodness) - return true; -} - -#endif - -/////////////////////////////////////////////////////////////////////////////// - #ifdef SK_BUILD_FOR_ANDROID void SkPixelRef::globalRef(void* data) { this->ref(); diff --git a/src/core/SkScaledImageCache.cpp b/src/core/SkScaledImageCache.cpp index 5a772a7cd5..45a5684638 100644 --- a/src/core/SkScaledImageCache.cpp +++ b/src/core/SkScaledImageCache.cpp @@ -199,11 +199,13 @@ public: SK_DECLARE_UNFLATTENABLE_OBJECT() protected: - virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE; + virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; virtual void onUnlockPixels() SK_OVERRIDE; virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE; private: + SkImageInfo fInfo; // remove when SkPixelRef gets this in baseclass + SkDiscardableMemory* fDM; size_t fRB; bool fFirstTime; @@ -218,6 +220,8 @@ SkOneShotDiscardablePixelRef::SkOneShotDiscardablePixelRef(const SkImageInfo& in , fDM(dm) , fRB(rowBytes) { + fInfo = info; // remove this redundant field when SkPixelRef has info + SkASSERT(dm->data()); fFirstTime = true; } @@ -226,31 +230,26 @@ SkOneShotDiscardablePixelRef::~SkOneShotDiscardablePixelRef() { SkDELETE(fDM); } -bool SkOneShotDiscardablePixelRef::onNewLockPixels(LockRec* rec) { +void* SkOneShotDiscardablePixelRef::onLockPixels(SkColorTable** ctable) { if (fFirstTime) { // we're already locked SkASSERT(fDM->data()); fFirstTime = false; - goto SUCCESS; + return fDM->data(); } // A previous call to onUnlock may have deleted our DM, so check for that if (NULL == fDM) { - return false; + return NULL; } if (!fDM->lock()) { // since it failed, we delete it now, to free-up the resource delete fDM; fDM = NULL; - return false; + return NULL; } - -SUCCESS: - rec->fPixels = fDM->data(); - rec->fColorTable = NULL; - rec->fRowBytes = fRB; - return true; + return fDM->data(); } void SkOneShotDiscardablePixelRef::onUnlockPixels() { @@ -259,7 +258,7 @@ void SkOneShotDiscardablePixelRef::onUnlockPixels() { } size_t SkOneShotDiscardablePixelRef::getAllocatedSizeInBytes() const { - return this->info().getSafeSize(fRB); + return fInfo.fHeight * fRB; } class SkScaledImageCacheDiscardableAllocator : public SkBitmap::Allocator { |