diff options
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/SkDataPixelRef.cpp | 25 | ||||
-rw-r--r-- | src/image/SkDataPixelRef.h | 7 | ||||
-rw-r--r-- | src/image/SkImage_Raster.cpp | 6 | ||||
-rw-r--r-- | src/image/SkSurface_Raster.cpp | 16 |
4 files changed, 27 insertions, 27 deletions
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)); } |