aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-06 18:51:08 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-06 18:51:08 +0000
commit5b132b28da61e89cdcb84e95f30a58f8184739fc (patch)
treee0a12eb2be846b7f2135f58de677284a3fcc6fad /src
parent3e89524e747b513986abfeeea00b6fac79593f26 (diff)
Revert "PixelRef now returns (nearly) everything that is currently in SkBitmap. The goal is to refactor bitmap later to remove redundancy, and more interestingly, remove the chance for a disconnect between the actual (pixelref) rowbytes and config, and the one claimed by the bitmap."
This reverts commit 154e08b2f5904ef533da694e3510befcb9a3f3e2. revert due to warnings Review URL: https://codereview.chromium.org/108513003 git-svn-id: http://skia.googlecode.com/svn/trunk@12538 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/core/SkBitmap.cpp93
-rw-r--r--src/core/SkBitmapDevice.cpp35
-rw-r--r--src/core/SkImageFilterUtils.cpp16
-rw-r--r--src/core/SkMallocPixelRef.cpp131
-rw-r--r--src/core/SkMaskFilter.cpp8
-rw-r--r--src/core/SkPixelRef.cpp75
-rw-r--r--src/effects/gradients/SkGradientShader.cpp14
-rw-r--r--src/gpu/GrSurface.cpp10
-rw-r--r--src/gpu/SkGpuDevice.cpp28
-rw-r--r--src/gpu/SkGr.cpp30
-rw-r--r--src/gpu/SkGrPixelRef.cpp32
-rw-r--r--src/image/SkDataPixelRef.cpp25
-rw-r--r--src/image/SkDataPixelRef.h7
-rw-r--r--src/image/SkImage_Raster.cpp6
-rw-r--r--src/image/SkSurface_Raster.cpp16
-rw-r--r--src/images/SkImageRef.cpp31
-rw-r--r--src/images/SkImageRef_GlobalPool.cpp6
-rw-r--r--src/lazy/SkCachingPixelRef.cpp34
-rw-r--r--src/lazy/SkCachingPixelRef.h4
-rw-r--r--src/lazy/SkDiscardablePixelRef.cpp38
-rw-r--r--src/lazy/SkDiscardablePixelRef.h9
21 files changed, 175 insertions, 473 deletions
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 900a3abcd0..d2a308b03a 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -361,47 +361,6 @@ void SkBitmap::updatePixelsFromRef() const {
}
}
-static bool config_to_colorType(SkBitmap::Config config, SkColorType* ctOut) {
- SkColorType ct;
- switch (config) {
- case SkBitmap::kNo_Config:
- return false;
- case SkBitmap::kA8_Config:
- ct = kAlpha_8_SkColorType;
- break;
- case SkBitmap::kIndex8_Config:
- ct = kIndex8_SkColorType;
- break;
- case SkBitmap::kRGB_565_Config:
- ct = kRGB_565_SkColorType;
- break;
- case SkBitmap::kARGB_4444_Config:
- ct = kARGB_4444_SkColorType;
- break;
- case SkBitmap::kARGB_8888_Config:
- ct = kPMColor_SkColorType;
- break;
- }
- if (ctOut) {
- *ctOut = ct;
- }
- return true;
-}
-
-bool SkBitmap::asImageInfo(SkImageInfo* info) const {
- SkColorType ct;
- if (!config_to_colorType(this->config(), &ct)) {
- return false;
- }
- if (info) {
- info->fWidth = fWidth;
- info->fHeight = fHeight;
- info->fAlphaType = this->alphaType();
- info->fColorType = ct;
- }
- return true;
-}
-
SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, size_t offset) {
// do this first, we that we never have a non-zero offset with a null ref
if (NULL == pr) {
@@ -452,20 +411,10 @@ void SkBitmap::setPixels(void* p, SkColorTable* ctable) {
return;
}
- SkImageInfo info;
- if (!this->asImageInfo(&info)) {
- this->setPixelRef(NULL, 0);
- return;
- }
-
- SkPixelRef* pr = SkMallocPixelRef::NewDirect(info, p, fRowBytes, ctable);
- if (NULL == pr) {
- this->setPixelRef(NULL, 0);
- return;
- }
-
- this->setPixelRef(pr)->unref();
+ Sk64 size = this->getSize64();
+ SkASSERT(!size.isNeg() && size.is32());
+ this->setPixelRef(new SkMallocPixelRef(p, size.get32(), ctable, false))->unref();
// since we're already allocated, we lockPixels right away
this->lockPixels();
SkDEBUGCODE(this->validate();)
@@ -530,19 +479,17 @@ GrTexture* SkBitmap::getTexture() const {
*/
bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst,
SkColorTable* ctable) {
- SkImageInfo info;
- if (!dst->asImageInfo(&info)) {
-// SkDebugf("unsupported config for info %d\n", dst->config());
+ Sk64 size = dst->getSize64();
+ if (size.isNeg() || !size.is32()) {
return false;
}
-
- SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, dst->rowBytes(),
- ctable);
- if (NULL == pr) {
+
+ void* addr = sk_malloc_flags(size.get32(), 0); // returns NULL on failure
+ if (NULL == addr) {
return false;
}
- dst->setPixelRef(pr, 0)->unref();
+ dst->setPixelRef(new SkMallocPixelRef(addr, size.get32(), ctable))->unref();
// since we're already allocated, we lockPixels right away
dst->lockPixels();
return true;
@@ -1649,28 +1596,6 @@ SkBitmap::RLEPixels::~RLEPixels() {
///////////////////////////////////////////////////////////////////////////////
-void SkImageInfo::unflatten(SkFlattenableReadBuffer& buffer) {
- fWidth = buffer.read32();
- fHeight = buffer.read32();
-
- uint32_t packed = buffer.read32();
- SkASSERT(0 == (packed >> 16));
- fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF);
- fColorType = (SkColorType)((packed >> 0) & 0xFF);
-}
-
-void SkImageInfo::flatten(SkFlattenableWriteBuffer& buffer) const {
- buffer.write32(fWidth);
- buffer.write32(fHeight);
-
- SkASSERT(0 == (fAlphaType & ~0xFF));
- SkASSERT(0 == (fColorType & ~0xFF));
- uint32_t packed = (fAlphaType << 8) | fColorType;
- buffer.write32(packed);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
#ifdef SK_DEBUG
void SkBitmap::validate() const {
SkASSERT(fConfig < kConfigCount);
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/SkImageFilterUtils.cpp b/src/core/SkImageFilterUtils.cpp
index e535d934f8..8385fb446a 100644
--- a/src/core/SkImageFilterUtils.cpp
+++ b/src/core/SkImageFilterUtils.cpp
@@ -15,14 +15,8 @@
#include "SkGr.h"
bool SkImageFilterUtils::WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result) {
- SkImageInfo info;
- info.fWidth = width;
- info.fHeight = height;
- info.fColorType = kPMColor_SkColorType;
- info.fAlphaType = kPremul_SkAlphaType;
-
- result->setConfig(info);
- result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref();
+ result->setConfig(SkBitmap::kARGB_8888_Config, width, height);
+ result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (texture)))->unref();
return true;
}
@@ -42,12 +36,8 @@ bool SkImageFilterUtils::GetInputResultGPU(SkImageFilter* filter, SkImageFilter:
} else {
if (filter->filterImage(proxy, src, ctm, result, offset)) {
if (!result->getTexture()) {
- SkImageInfo info;
- if (!result->asImageInfo(&info)) {
- return false;
- }
GrTexture* resultTex = GrLockAndRefCachedBitmapTexture(context, *result, NULL);
- result->setPixelRef(new SkGrPixelRef(info, resultTex))->unref();
+ result->setPixelRef(new SkGrPixelRef(resultTex))->unref();
GrUnlockAndUnrefCachedBitmapTexture(resultTex);
}
return true;
diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp
index 4ba6e049d8..f229e9de34 100644
--- a/src/core/SkMallocPixelRef.cpp
+++ b/src/core/SkMallocPixelRef.cpp
@@ -1,105 +1,27 @@
+
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
#include "SkMallocPixelRef.h"
#include "SkBitmap.h"
#include "SkFlattenableBuffers.h"
-static bool check_info(const SkImageInfo& info, SkColorTable* ctable) {
- if (info.fWidth < 0 ||
- info.fHeight < 0 ||
- (unsigned)info.fColorType > (unsigned)kLastEnum_SkColorType ||
- (unsigned)info.fAlphaType > (unsigned)kLastEnum_SkAlphaType)
- {
- return false;
- }
-
- // these seem like good checks, but currently we have (at least) tests
- // that expect the pixelref to succeed even when there is a mismatch
- // with colortables. fix?
-#if 0
- if (kIndex8_SkColorType == info.fColorType && NULL == ctable) {
- return false;
- }
- if (kIndex8_SkColorType != info.fColorType && NULL != ctable) {
- return false;
- }
-#endif
- return true;
-}
-
-SkMallocPixelRef* SkMallocPixelRef::NewDirect(const SkImageInfo& info,
- void* addr,
- size_t rowBytes,
- SkColorTable* ctable) {
- if (!check_info(info, ctable)) {
- return NULL;
- }
- return SkNEW_ARGS(SkMallocPixelRef, (info, addr, rowBytes, ctable, false));
-}
-
-SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info,
- size_t requestedRowBytes,
- SkColorTable* ctable) {
- if (!check_info(info, ctable)) {
- return NULL;
- }
-
- int32_t minRB = info.minRowBytes();
- if (minRB < 0) {
- return NULL; // allocation will be too large
- }
- if (requestedRowBytes > 0 && (int32_t)requestedRowBytes < minRB) {
- return NULL; // cannot meet requested rowbytes
- }
-
- int32_t rowBytes;
- if (requestedRowBytes) {
- rowBytes = requestedRowBytes;
- } else {
- rowBytes = minRB;
+SkMallocPixelRef::SkMallocPixelRef(void* storage, size_t size,
+ SkColorTable* ctable, bool ownPixels) {
+ if (NULL == storage) {
+ SkASSERT(ownPixels);
+ storage = sk_malloc_throw(size);
}
-
- Sk64 bigSize;
- bigSize.setMul(info.fHeight, rowBytes);
- if (!bigSize.is32()) {
- return NULL;
- }
-
- size_t size = bigSize.get32();
- void* addr = sk_malloc_flags(size, 0);
- if (NULL == addr) {
- return NULL;
- }
-
- return SkNEW_ARGS(SkMallocPixelRef, (info, addr, rowBytes, ctable, true));
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage,
- size_t rowBytes, SkColorTable* ctable,
- bool ownsPixels)
- : SkPixelRef(info)
- , fOwnPixels(ownsPixels)
-{
- SkASSERT(check_info(info, ctable));
- SkASSERT(rowBytes >= info.minRowBytes());
-
- if (kIndex8_SkColorType != info.fColorType) {
- ctable = NULL;
- }
-
fStorage = storage;
+ fSize = size;
fCTable = ctable;
- fRB = rowBytes;
SkSafeRef(ctable);
-
- this->setPreLocked(fStorage, fRB, fCTable);
+ fOwnPixels = ownPixels;
+
+ this->setPreLocked(fStorage, fCTable);
}
SkMallocPixelRef::~SkMallocPixelRef() {
@@ -109,30 +31,19 @@ SkMallocPixelRef::~SkMallocPixelRef() {
}
}
-bool SkMallocPixelRef::onNewLockPixels(LockRec* rec) {
- rec->fPixels = fStorage;
- rec->fRowBytes = fRB;
- rec->fColorTable = fCTable;
- return true;
+void* SkMallocPixelRef::onLockPixels(SkColorTable** ct) {
+ *ct = fCTable;
+ return fStorage;
}
void SkMallocPixelRef::onUnlockPixels() {
// nothing to do
}
-size_t SkMallocPixelRef::getAllocatedSizeInBytes() const {
- return this->info().getSafeSize(fRB);
-}
-
void SkMallocPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
- buffer.write32(fRB);
-
- // TODO: replace this bulk write with a chunky one that can trim off any
- // trailing bytes on each scanline (in case rowbytes > width*size)
- size_t size = this->info().getSafeSize(fRB);
- buffer.writeByteArray(fStorage, size);
+ buffer.writeByteArray(fStorage, fSize);
buffer.writeBool(fCTable != NULL);
if (fCTable) {
fCTable->writeToBuffer(buffer);
@@ -140,18 +51,16 @@ void SkMallocPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
}
SkMallocPixelRef::SkMallocPixelRef(SkFlattenableReadBuffer& buffer)
- : INHERITED(buffer, NULL)
- , fOwnPixels(true)
-{
- fRB = buffer.read32();
- size_t size = this->info().getSafeSize(fRB);
- fStorage = sk_malloc_throw(size);
- buffer.readByteArray(fStorage, size);
+ : INHERITED(buffer, NULL) {
+ fSize = buffer.getArrayCount();
+ fStorage = sk_malloc_throw(fSize);
+ buffer.readByteArray(fStorage, fSize);
if (buffer.readBool()) {
fCTable = SkNEW_ARGS(SkColorTable, (buffer));
} else {
fCTable = NULL;
}
+ fOwnPixels = true;
- this->setPreLocked(fStorage, fRB, fCTable);
+ this->setPreLocked(fStorage, fCTable);
}
diff --git a/src/core/SkMaskFilter.cpp b/src/core/SkMaskFilter.cpp
index adfed41098..f062f135fd 100644
--- a/src/core/SkMaskFilter.cpp
+++ b/src/core/SkMaskFilter.cpp
@@ -349,14 +349,10 @@ bool SkMaskFilter::filterMaskGPU(GrContext* context,
if (!result) {
return false;
}
- SkAutoUnref aur(dst);
- SkImageInfo info;
resultBM->setConfig(srcBM.config(), dst->width(), dst->height());
- if (resultBM->asImageInfo(&info)) {
- return false;
- }
- resultBM->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, dst)))->unref();
+ resultBM->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (dst)))->unref();
+ dst->unref();
return true;
}
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp
index 60b5cfb26c..1afc3360a2 100644
--- a/src/core/SkPixelRef.cpp
+++ b/src/core/SkPixelRef.cpp
@@ -82,20 +82,10 @@ 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) {
- this->setMutex(NULL);
- fInfo = info;
- fRec.zero();
- fLockCount = 0;
- this->needsNewGenID();
- fIsImmutable = false;
- fPreLocked = false;
-}
-
-SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) {
+SkPixelRef::SkPixelRef(SkBaseMutex* mutex) {
this->setMutex(mutex);
- fInfo = info;
- fRec.zero();
+ fPixels = NULL;
+ fColorTable = NULL; // we do not track ownership of this
fLockCount = 0;
this->needsNewGenID();
fIsImmutable = false;
@@ -105,9 +95,8 @@ SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) {
SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex)
: INHERITED(buffer) {
this->setMutex(mutex);
-
- fInfo.unflatten(buffer);
- fRec.zero();
+ fPixels = NULL;
+ fColorTable = NULL; // we do not track ownership of this
fLockCount = 0;
fIsImmutable = buffer.readBool();
fGenerationID = buffer.readUInt();
@@ -131,13 +120,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
@@ -145,8 +133,6 @@ void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctabl
void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
-
- fInfo.flatten(buffer);
buffer.writeBool(fIsImmutable);
// We write the gen ID into the picture for within-process recording. This
// is safe since the same genID will never refer to two different sets of
@@ -161,27 +147,16 @@ 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) {
- LockRec rec;
- if (!this->onNewLockPixels(&rec)) {
- return false;
- }
- fRec = rec;
+ fPixels = this->onLockPixels(&fColorTable);
}
}
- *rec = fRec;
- return true;
-}
-
-bool SkPixelRef::lockPixels() {
- LockRec rec;
- return this->lockPixels(&rec);
}
void SkPixelRef::unlockPixels() {
@@ -193,7 +168,8 @@ void SkPixelRef::unlockPixels() {
SkASSERT(fLockCount > 0);
if (0 == --fLockCount) {
this->onUnlockPixels();
- fRec.zero();
+ fPixels = NULL;
+ fColorTable = NULL;
}
}
}
@@ -274,29 +250,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/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index 5d200d18d3..2776199346 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -513,14 +513,13 @@ const uint16_t* SkGradientShaderBase::getCache16() const {
const SkPMColor* SkGradientShaderBase::getCache32() const {
if (fCache32 == NULL) {
- SkImageInfo info;
- info.fWidth = kCache32Count;
- info.fHeight = 4; // for our 4 dither rows
- info.fAlphaType = kPremul_SkAlphaType;
- info.fColorType = kPMColor_SkColorType;
+ // double the count for dither entries
+ const int entryCount = kCache32Count * 4;
+ const size_t allocSize = sizeof(SkPMColor) * entryCount;
if (NULL == fCache32PixelRef) {
- fCache32PixelRef = SkMallocPixelRef::NewAllocate(info, 0, NULL);
+ fCache32PixelRef = SkNEW_ARGS(SkMallocPixelRef,
+ (NULL, allocSize, NULL));
}
fCache32 = (SkPMColor*)fCache32PixelRef->getAddr();
if (fColorCount == 2) {
@@ -542,7 +541,8 @@ const SkPMColor* SkGradientShaderBase::getCache32() const {
}
if (fMapper) {
- SkMallocPixelRef* newPR = SkMallocPixelRef::NewAllocate(info, 0, NULL);
+ SkMallocPixelRef* newPR = SkNEW_ARGS(SkMallocPixelRef,
+ (NULL, allocSize, NULL));
SkPMColor* linear = fCache32; // just computed linear data
SkPMColor* mapped = (SkPMColor*)newPR->getAddr(); // storage for mapped data
SkUnitMapper* map = fMapper;
diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp
index 1fcc4ff18b..fed95f232f 100644
--- a/src/gpu/GrSurface.cpp
+++ b/src/gpu/GrSurface.cpp
@@ -8,19 +8,9 @@
#include "GrSurface.h"
#include "SkBitmap.h"
-#include "SkGr.h"
#include "SkImageEncoder.h"
#include <stdio.h>
-void GrSurface::asImageInfo(SkImageInfo* info) const {
- if (!GrPixelConfig2ColorType(this->config(), &info->fColorType)) {
- sk_throw();
- }
- info->fWidth = this->width();
- info->fHeight = this->height();
- info->fAlphaType = kPremul_SkAlphaType;
-}
-
bool GrSurface::savePixels(const char* filename) {
SkBitmap bm;
bm.setConfig(SkBitmap::kARGB_8888_Config, this->width(), this->height());
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index e4c153783b..07a946ef94 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -200,10 +200,7 @@ void SkGpuDevice::initFromRenderTarget(GrContext* context,
if (NULL == surface) {
surface = fRenderTarget;
}
-
- SkImageInfo info;
- surface->asImageInfo(&info);
- SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface, cached));
+ SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (surface, cached));
this->setPixelRef(pr, 0)->unref();
}
@@ -213,8 +210,8 @@ SkGpuDevice::SkGpuDevice(GrContext* context,
int width,
int height,
int sampleCount)
- : SkBitmapDevice(config, width, height, false /*isOpaque*/)
-{
+ : SkBitmapDevice(config, width, height, false /*isOpaque*/) {
+
fDrawProcs = NULL;
fContext = context;
@@ -234,14 +231,6 @@ SkGpuDevice::SkGpuDevice(GrContext* context,
desc.fConfig = SkBitmapConfig2GrPixelConfig(config);
desc.fSampleCnt = sampleCount;
- SkImageInfo info;
- if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) {
- sk_throw();
- }
- info.fWidth = width;
- info.fHeight = height;
- info.fAlphaType = kPremul_SkAlphaType;
-
SkAutoTUnref<GrTexture> texture(fContext->createUncachedTexture(desc, NULL, 0));
if (NULL != texture) {
@@ -251,7 +240,7 @@ SkGpuDevice::SkGpuDevice(GrContext* context,
SkASSERT(NULL != fRenderTarget);
// wrap the bitmap with a pixelref to expose our texture
- SkGrPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, texture));
+ SkGrPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (texture));
this->setPixelRef(pr, 0)->unref();
} else {
GrPrintf("--- failed to create gpu-offscreen [%d %d]\n",
@@ -837,12 +826,11 @@ bool create_mask_GPU(GrContext* context,
}
SkBitmap wrap_texture(GrTexture* texture) {
- SkImageInfo info;
- texture->asImageInfo(&info);
-
SkBitmap result;
- result.setConfig(info);
- result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref();
+ bool dummy;
+ SkBitmap::Config config = grConfig2skConfig(texture->config(), &dummy);
+ result.setConfig(config, texture->width(), texture->height());
+ result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (texture)))->unref();
return result;
}
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index b55256e78e..c7ae0c8f36 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -258,33 +258,3 @@ GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config config) {
return kUnknown_GrPixelConfig;
}
}
-
-bool GrPixelConfig2ColorType(GrPixelConfig config, SkColorType* ctOut) {
- SkColorType ct;
- switch (config) {
- case kAlpha_8_GrPixelConfig:
- ct = kAlpha_8_SkColorType;
- break;
- case kIndex_8_GrPixelConfig:
- ct = kIndex8_SkColorType;
- break;
- case kRGB_565_GrPixelConfig:
- ct = kRGB_565_SkColorType;
- break;
- case kRGBA_4444_GrPixelConfig:
- ct = kARGB_4444_SkColorType;
- break;
- case kRGBA_8888_GrPixelConfig:
- ct = kRGBA_8888_SkColorType;
- break;
- case kBGRA_8888_GrPixelConfig:
- ct = kBGRA_8888_SkColorType;
- break;
- default:
- return false;
- }
- if (ctOut) {
- *ctOut = ct;
- }
- return true;
-}
diff --git a/src/gpu/SkGrPixelRef.cpp b/src/gpu/SkGrPixelRef.cpp
index 882995e088..dc5d7558f0 100644
--- a/src/gpu/SkGrPixelRef.cpp
+++ b/src/gpu/SkGrPixelRef.cpp
@@ -18,14 +18,16 @@
// to avoid deadlock with the default one provided by SkPixelRef.
SK_DECLARE_STATIC_MUTEX(gROLockPixelsPixelRefMutex);
-SkROLockPixelsPixelRef::SkROLockPixelsPixelRef(const SkImageInfo& info)
- : INHERITED(info, &gROLockPixelsPixelRefMutex) {
+SkROLockPixelsPixelRef::SkROLockPixelsPixelRef() : INHERITED(&gROLockPixelsPixelRefMutex) {
}
SkROLockPixelsPixelRef::~SkROLockPixelsPixelRef() {
}
-bool SkROLockPixelsPixelRef::onNewLockPixels(LockRec* rec) {
+void* SkROLockPixelsPixelRef::onLockPixels(SkColorTable** ctable) {
+ if (ctable) {
+ *ctable = NULL;
+ }
fBitmap.reset();
// SkDebugf("---------- calling readpixels in support of lockpixels\n");
if (!this->onReadPixels(&fBitmap, NULL)) {
@@ -33,14 +35,7 @@ bool SkROLockPixelsPixelRef::onNewLockPixels(LockRec* rec) {
return NULL;
}
fBitmap.lockPixels();
- if (NULL == fBitmap.getPixels()) {
- return false;
- }
-
- rec->fPixels = fBitmap.getPixels();
- rec->fColorTable = NULL;
- rec->fRowBytes = fBitmap.rowBytes();
- return true;
+ return fBitmap.getPixels();
}
void SkROLockPixelsPixelRef::onUnlockPixels() {
@@ -81,14 +76,6 @@ static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, SkBitmap::Config
desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
desc.fConfig = SkBitmapConfig2GrPixelConfig(dstConfig);
- SkImageInfo info;
- if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) {
- return NULL;
- }
- info.fWidth = desc.fWidth;
- info.fHeight = desc.fHeight;
- info.fAlphaType = kPremul_SkAlphaType;
-
GrTexture* dst = context->createUncachedTexture(desc, NULL, 0);
if (NULL == dst) {
return NULL;
@@ -106,17 +93,14 @@ static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, SkBitmap::Config
dst->releaseRenderTarget();
#endif
- SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst));
+ SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (dst));
SkSafeUnref(dst);
return pixelRef;
}
///////////////////////////////////////////////////////////////////////////////
-SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface,
- bool transferCacheLock)
- : INHERITED(info)
-{
+SkGrPixelRef::SkGrPixelRef(GrSurface* surface, bool transferCacheLock) {
// TODO: figure out if this is responsible for Chrome canvas errors
#if 0
// The GrTexture has a ref to the GrRenderTarget but not vice versa.
diff --git a/src/image/SkDataPixelRef.cpp b/src/image/SkDataPixelRef.cpp
index 875f933b9c..7897bf9315 100644
--- a/src/image/SkDataPixelRef.cpp
+++ b/src/image/SkDataPixelRef.cpp
@@ -9,25 +9,18 @@
#include "SkData.h"
#include "SkFlattenableBuffers.h"
-SkDataPixelRef::SkDataPixelRef(const SkImageInfo& info,
- SkData* data, size_t rowBytes)
- : INHERITED(info)
- , fData(data)
- , fRB(rowBytes)
-{
+SkDataPixelRef::SkDataPixelRef(SkData* data) : fData(data) {
fData->ref();
- this->setPreLocked(const_cast<void*>(fData->data()), rowBytes, NULL);
+ this->setPreLocked(const_cast<void*>(fData->data()), NULL);
}
SkDataPixelRef::~SkDataPixelRef() {
fData->unref();
}
-bool SkDataPixelRef::onNewLockPixels(LockRec* rec) {
- rec->fPixels = const_cast<void*>(fData->data());
- rec->fColorTable = NULL;
- rec->fRowBytes = fRB;
- return true;
+void* SkDataPixelRef::onLockPixels(SkColorTable** ct) {
+ *ct = NULL;
+ return const_cast<void*>(fData->data());
}
void SkDataPixelRef::onUnlockPixels() {
@@ -40,15 +33,11 @@ size_t SkDataPixelRef::getAllocatedSizeInBytes() const {
void SkDataPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
-
buffer.writeDataAsByteArray(fData);
- buffer.write32(fRB);
}
SkDataPixelRef::SkDataPixelRef(SkFlattenableReadBuffer& buffer)
- : INHERITED(buffer, NULL)
-{
+ : INHERITED(buffer, NULL) {
fData = buffer.readByteArrayAsData();
- fRB = buffer.read32();
- this->setPreLocked(const_cast<void*>(fData->data()), fRB, NULL);
+ this->setPreLocked(const_cast<void*>(fData->data()), NULL);
}
diff --git a/src/image/SkDataPixelRef.h b/src/image/SkDataPixelRef.h
index c2e52cd9e1..50c885714b 100644
--- a/src/image/SkDataPixelRef.h
+++ b/src/image/SkDataPixelRef.h
@@ -14,13 +14,13 @@ class SkData;
class SkDataPixelRef : public SkPixelRef {
public:
- SkDataPixelRef(const SkImageInfo&, SkData* data, size_t rowBytes);
+ SkDataPixelRef(SkData* data);
virtual ~SkDataPixelRef();
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDataPixelRef)
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;
@@ -28,8 +28,7 @@ protected:
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
private:
- SkData* fData;
- size_t fRB;
+ SkData* fData;
typedef SkPixelRef INHERITED;
};
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index 93de5ea3ab..a872ae36e5 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -84,8 +84,10 @@ SkImage* SkImage_Raster::NewEmpty() {
SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes)
: INHERITED(info.fWidth, info.fHeight) {
- fBitmap.setConfig(info, rowBytes);
- fBitmap.setPixelRef(SkNEW_ARGS(SkDataPixelRef, (info, data, rowBytes)))->unref();
+ SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
+
+ fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes, info.fAlphaType);
+ fBitmap.setPixelRef(SkNEW_ARGS(SkDataPixelRef, (data)))->unref();
fBitmap.setImmutable();
}
diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp
index 61ade6f46c..27db504df6 100644
--- a/src/image/SkSurface_Raster.cpp
+++ b/src/image/SkSurface_Raster.cpp
@@ -155,9 +155,19 @@ SkSurface* SkSurface::NewRaster(const SkImageInfo& info) {
return NULL;
}
- SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL));
- if (NULL == pr.get()) {
+ static const size_t kMaxTotalSize = SK_MaxS32;
+ size_t rowBytes = SkImageMinRowBytes(info);
+ uint64_t size64 = (uint64_t)info.fHeight * rowBytes;
+ if (size64 > kMaxTotalSize) {
+ return NULL;
+ }
+
+ size_t size = (size_t)size64;
+ void* pixels = sk_malloc_throw(size);
+ if (NULL == pixels) {
return NULL;
}
- return SkNEW_ARGS(SkSurface_Raster, (info, pr, info.minRowBytes()));
+
+ SkAutoTUnref<SkPixelRef> pr(SkNEW_ARGS(SkMallocPixelRef, (pixels, size, NULL, true)));
+ return SkNEW_ARGS(SkSurface_Raster, (info, pr, rowBytes));
}
diff --git a/src/images/SkImageRef.cpp b/src/images/SkImageRef.cpp
index 99782c45c0..1a8284bdd4 100644
--- a/src/images/SkImageRef.cpp
+++ b/src/images/SkImageRef.cpp
@@ -15,14 +15,16 @@
//#define DUMP_IMAGEREF_LIFECYCLE
+
///////////////////////////////////////////////////////////////////////////////
-SkImageRef::SkImageRef(const SkImageInfo& info, SkStreamRewindable* stream,
+SkImageRef::SkImageRef(SkStreamRewindable* stream, SkBitmap::Config config,
int sampleSize, SkBaseMutex* mutex)
- : INHERITED(info, mutex), fErrorInDecoding(false) {
+ : SkPixelRef(mutex), fErrorInDecoding(false) {
SkASSERT(stream);
stream->ref();
fStream = stream;
+ fConfig = config;
fSampleSize = sampleSize;
fDoDither = true;
fPrev = fNext = NULL;
@@ -38,7 +40,7 @@ SkImageRef::~SkImageRef() {
#ifdef DUMP_IMAGEREF_LIFECYCLE
SkDebugf("delete ImageRef %p [%d] data=%d\n",
- this, this->info().fColorType, (int)fStream->getLength());
+ this, fConfig, (int)fStream->getLength());
#endif
fStream->unref();
@@ -90,6 +92,14 @@ bool SkImageRef::prepareBitmap(SkImageDecoder::Mode mode) {
return false;
}
+ /* As soon as we really know our config, we record it, so that on
+ subsequent calls to the codec, we are sure we will always get the same
+ result.
+ */
+ if (SkBitmap::kNo_Config != fBitmap.config()) {
+ fConfig = fBitmap.config();
+ }
+
if (NULL != fBitmap.getPixels() ||
(SkBitmap::kNo_Config != fBitmap.config() &&
SkImageDecoder::kDecodeBounds_Mode == mode)) {
@@ -115,7 +125,7 @@ bool SkImageRef::prepareBitmap(SkImageDecoder::Mode mode) {
codec->setSampleSize(fSampleSize);
codec->setDitherImage(fDoDither);
- if (this->onDecode(codec, fStream, &fBitmap, fBitmap.config(), mode)) {
+ if (this->onDecode(codec, fStream, &fBitmap, fConfig, mode)) {
return true;
}
}
@@ -133,18 +143,15 @@ bool SkImageRef::prepareBitmap(SkImageDecoder::Mode mode) {
return false;
}
-bool SkImageRef::onNewLockPixels(LockRec* rec) {
+void* SkImageRef::onLockPixels(SkColorTable** ct) {
if (NULL == fBitmap.getPixels()) {
(void)this->prepareBitmap(SkImageDecoder::kDecodePixels_Mode);
}
- if (NULL == fBitmap.getPixels()) {
- return false;
+ if (ct) {
+ *ct = fBitmap.getColorTable();
}
- rec->fPixels = fBitmap.getPixels();
- rec->fColorTable = NULL;
- rec->fRowBytes = fBitmap.rowBytes();
- return true;
+ return fBitmap.getPixels();
}
size_t SkImageRef::ramUsed() const {
@@ -163,6 +170,7 @@ size_t SkImageRef::ramUsed() const {
SkImageRef::SkImageRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex)
: INHERITED(buffer, mutex), fErrorInDecoding(false) {
+ fConfig = (SkBitmap::Config)buffer.readUInt();
fSampleSize = buffer.readInt();
fDoDither = buffer.readBool();
@@ -177,6 +185,7 @@ SkImageRef::SkImageRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex)
void SkImageRef::flatten(SkFlattenableWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
+ buffer.writeUInt(fConfig);
buffer.writeInt(fSampleSize);
buffer.writeBool(fDoDither);
// FIXME: Consider moving this logic should go into writeStream itself.
diff --git a/src/images/SkImageRef_GlobalPool.cpp b/src/images/SkImageRef_GlobalPool.cpp
index f91cebabbf..352dd42d9f 100644
--- a/src/images/SkImageRef_GlobalPool.cpp
+++ b/src/images/SkImageRef_GlobalPool.cpp
@@ -24,10 +24,10 @@ static SkImageRefPool* GetGlobalPool() {
return gPool;
}
-SkImageRef_GlobalPool::SkImageRef_GlobalPool(const SkImageInfo& info,
- SkStreamRewindable* stream,
+SkImageRef_GlobalPool::SkImageRef_GlobalPool(SkStreamRewindable* stream,
+ SkBitmap::Config config,
int sampleSize)
- : SkImageRef(info, stream, sampleSize, &gGlobalPoolMutex) {
+ : SkImageRef(stream, config, sampleSize, &gGlobalPoolMutex) {
SkASSERT(&gGlobalPoolMutex == this->mutex());
SkAutoMutexAcquire ac(gGlobalPoolMutex);
GetGlobalPool()->addToHead(this);
diff --git a/src/lazy/SkCachingPixelRef.cpp b/src/lazy/SkCachingPixelRef.cpp
index fba9845563..667a94931b 100644
--- a/src/lazy/SkCachingPixelRef.cpp
+++ b/src/lazy/SkCachingPixelRef.cpp
@@ -8,6 +8,7 @@
#include "SkCachingPixelRef.h"
#include "SkScaledImageCache.h"
+
bool SkCachingPixelRef::Install(SkImageGenerator* generator,
SkBitmap* dst) {
SkImageInfo info;
@@ -30,10 +31,10 @@ bool SkCachingPixelRef::Install(SkImageGenerator* generator,
SkCachingPixelRef::SkCachingPixelRef(SkImageGenerator* generator,
const SkImageInfo& info,
size_t rowBytes)
- : INHERITED(info)
- , fImageGenerator(generator)
+ : fImageGenerator(generator)
, fErrorInDecoding(false)
, fScaledCacheId(NULL)
+ , fInfo(info)
, fRowBytes(rowBytes) {
SkASSERT(fImageGenerator != NULL);
}
@@ -43,32 +44,31 @@ SkCachingPixelRef::~SkCachingPixelRef() {
// Assert always unlock before unref.
}
-bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) {
+void* SkCachingPixelRef::onLockPixels(SkColorTable** colorTable) {
+ (void)colorTable;
if (fErrorInDecoding) {
- return false; // don't try again.
+ return NULL; // don't try again.
}
-
- const SkImageInfo& info = this->info();
SkBitmap bitmap;
SkASSERT(NULL == fScaledCacheId);
fScaledCacheId = SkScaledImageCache::FindAndLock(this->getGenerationID(),
- info.fWidth,
- info.fHeight,
+ fInfo.fWidth,
+ fInfo.fHeight,
&bitmap);
if (NULL == fScaledCacheId) {
// Cache has been purged, must re-decode.
- if ((!bitmap.setConfig(info, fRowBytes)) || !bitmap.allocPixels()) {
+ if ((!bitmap.setConfig(fInfo, fRowBytes)) || !bitmap.allocPixels()) {
fErrorInDecoding = true;
- return false;
+ return NULL;
}
SkAutoLockPixels autoLockPixels(bitmap);
- if (!fImageGenerator->getPixels(info, bitmap.getPixels(), fRowBytes)) {
+ if (!fImageGenerator->getPixels(fInfo, bitmap.getPixels(), fRowBytes)) {
fErrorInDecoding = true;
- return false;
+ return NULL;
}
fScaledCacheId = SkScaledImageCache::AddAndLock(this->getGenerationID(),
- info.fWidth,
- info.fHeight,
+ fInfo.fWidth,
+ fInfo.fHeight,
bitmap);
SkASSERT(fScaledCacheId != NULL);
}
@@ -78,7 +78,6 @@ bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) {
SkAutoLockPixels autoLockPixels(bitmap);
void* pixels = bitmap.getPixels();
SkASSERT(pixels != NULL);
-
// At this point, the autoLockPixels will unlockPixels()
// to remove bitmap's lock on the pixels. We will then
// destroy bitmap. The *only* guarantee that this pointer
@@ -87,10 +86,7 @@ bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) {
// bitmap (SkScaledImageCache::Rec.fBitmap) that holds a
// reference to the concrete PixelRef while this record is
// locked.
- rec->fPixels = pixels;
- rec->fColorTable = NULL;
- rec->fRowBytes = bitmap.rowBytes();
- return true;
+ return pixels;
}
void SkCachingPixelRef::onUnlockPixels() {
diff --git a/src/lazy/SkCachingPixelRef.h b/src/lazy/SkCachingPixelRef.h
index 75710d8bde..4a0387ddf8 100644
--- a/src/lazy/SkCachingPixelRef.h
+++ b/src/lazy/SkCachingPixelRef.h
@@ -40,7 +40,7 @@ public:
protected:
virtual ~SkCachingPixelRef();
- virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
+ virtual void* onLockPixels(SkColorTable** colorTable) SK_OVERRIDE;
virtual void onUnlockPixels() SK_OVERRIDE;
virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; }
@@ -58,12 +58,12 @@ private:
SkImageGenerator* const fImageGenerator;
bool fErrorInDecoding;
void* fScaledCacheId;
+ const SkImageInfo fInfo;
const size_t fRowBytes;
SkCachingPixelRef(SkImageGenerator* imageGenerator,
const SkImageInfo& info,
size_t rowBytes);
-
typedef SkPixelRef INHERITED;
};
diff --git a/src/lazy/SkDiscardablePixelRef.cpp b/src/lazy/SkDiscardablePixelRef.cpp
index e9e2d8a3ee..e614db37e9 100644
--- a/src/lazy/SkDiscardablePixelRef.cpp
+++ b/src/lazy/SkDiscardablePixelRef.cpp
@@ -10,15 +10,17 @@
SkDiscardablePixelRef::SkDiscardablePixelRef(SkImageGenerator* generator,
const SkImageInfo& info,
+ size_t size,
size_t rowBytes,
SkDiscardableMemory::Factory* fact)
- : INHERITED(info)
- , fGenerator(generator)
+ : fGenerator(generator)
, fDMFactory(fact)
+ , fInfo(info)
+ , fSize(size)
, fRowBytes(rowBytes)
- , fDiscardableMemory(NULL)
-{
+ , fDiscardableMemory(NULL) {
SkASSERT(fGenerator != NULL);
+ SkASSERT(fSize > 0);
SkASSERT(fRowBytes > 0);
// The SkImageGenerator contract requires fGenerator to always
// decode the same image on each call to getPixels().
@@ -32,39 +34,28 @@ SkDiscardablePixelRef::~SkDiscardablePixelRef() {
SkDELETE(fGenerator);
}
-bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) {
+void* SkDiscardablePixelRef::onLockPixels(SkColorTable**) {
if (fDiscardableMemory != NULL) {
if (fDiscardableMemory->lock()) {
- rec->fPixels = fDiscardableMemory->data();
- rec->fColorTable = NULL;
- rec->fRowBytes = fRowBytes;
- return true;
+ return fDiscardableMemory->data();
}
SkDELETE(fDiscardableMemory);
fDiscardableMemory = NULL;
}
-
- const size_t size = this->info().getSafeSize(fRowBytes);
if (fDMFactory != NULL) {
- fDiscardableMemory = fDMFactory->create(size);
+ fDiscardableMemory = fDMFactory->create(fSize);
} else {
- fDiscardableMemory = SkDiscardableMemory::Create(size);
+ fDiscardableMemory = SkDiscardableMemory::Create(fSize);
}
if (NULL == fDiscardableMemory) {
- return false; // Memory allocation failed.
+ return NULL; // Memory allocation failed.
}
-
void* pixels = fDiscardableMemory->data();
- if (!fGenerator->getPixels(this->info(), pixels, fRowBytes)) {
- return false; // TODO(halcanary) Find out correct thing to do.
+ if (!fGenerator->getPixels(fInfo, pixels, fRowBytes)) {
+ return NULL; // TODO(halcanary) Find out correct thing to do.
}
-
- rec->fPixels = pixels;
- rec->fColorTable = NULL;
- rec->fRowBytes = fRowBytes;
- return true;
+ return pixels;
}
-
void SkDiscardablePixelRef::onUnlockPixels() {
if (fDiscardableMemory != NULL) {
fDiscardableMemory->unlock();
@@ -85,6 +76,7 @@ bool SkDiscardablePixelRef::Install(SkImageGenerator* generator,
}
SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef,
(generator, info,
+ dst->getSize(),
dst->rowBytes(),
factory)));
dst->setPixelRef(ref);
diff --git a/src/lazy/SkDiscardablePixelRef.h b/src/lazy/SkDiscardablePixelRef.h
index 313660efc5..78dcd66791 100644
--- a/src/lazy/SkDiscardablePixelRef.h
+++ b/src/lazy/SkDiscardablePixelRef.h
@@ -50,8 +50,7 @@ public:
protected:
~SkDiscardablePixelRef();
-
- virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
+ virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE;
virtual void onUnlockPixels() SK_OVERRIDE;
virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; }
@@ -62,6 +61,8 @@ protected:
private:
SkImageGenerator* const fGenerator;
SkDiscardableMemory::Factory* const fDMFactory;
+ const SkImageInfo fInfo;
+ const size_t fSize; // size of memory to be allocated
const size_t fRowBytes;
// These const members should not change over the life of the
// PixelRef, since the SkBitmap doesn't expect them to change.
@@ -71,10 +72,8 @@ private:
/* Takes ownership of SkImageGenerator. */
SkDiscardablePixelRef(SkImageGenerator* generator,
const SkImageInfo& info,
+ size_t size,
size_t rowBytes,
SkDiscardableMemory::Factory* factory);
-
- typedef SkPixelRef INHERITED;
};
-
#endif // SkDiscardablePixelRef_DEFINED