Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Unified Diff: src/core/SkMallocPixelRef.cpp

Issue 68973005: Expand pixelref to return SkImageInfo and rowbytes (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkMallocPixelRef.cpp
diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp
index f229e9de34d0fa8dbdd29304dd0ac0f7a78e5611..2ca56f10ac2ed567b301cbf942226cae9f13b1f6 100644
--- a/src/core/SkMallocPixelRef.cpp
+++ b/src/core/SkMallocPixelRef.cpp
@@ -9,19 +9,21 @@
#include "SkBitmap.h"
#include "SkFlattenableBuffers.h"
-SkMallocPixelRef::SkMallocPixelRef(void* storage, size_t size,
- SkColorTable* ctable, bool ownPixels) {
+SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage,
+ size_t rowBytes, SkColorTable* ctable, bool ownPixels) {
+ size_t size = info.fHeight * rowBytes;
if (NULL == storage) {
SkASSERT(ownPixels);
storage = sk_malloc_throw(size);
}
fStorage = storage;
- fSize = size;
+ fInfo = info;
+ fRB = rowBytes;
fCTable = ctable;
SkSafeRef(ctable);
fOwnPixels = ownPixels;
- this->setPreLocked(fStorage, fCTable);
+ this->setPreLocked(fStorage, rowBytes, fCTable);
}
SkMallocPixelRef::~SkMallocPixelRef() {
@@ -31,7 +33,10 @@ SkMallocPixelRef::~SkMallocPixelRef() {
}
}
-void* SkMallocPixelRef::onLockPixels(SkColorTable** ct) {
+void* SkMallocPixelRef::onLockPixels(SkImageInfo* info, size_t* rowBytes,
+ SkColorTable** ct) {
+ *info = fInfo;
+ *rowBytes = fRB;
*ct = fCTable;
return fStorage;
}
@@ -43,7 +48,16 @@ void SkMallocPixelRef::onUnlockPixels() {
void SkMallocPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
- buffer.writeByteArray(fStorage, fSize);
+ buffer.write32(fInfo.fWidth);
scroggo 2013/11/19 18:17:09 SkImageInfo::writeToMemory?
reed1 2013/11/20 20:56:56 removed (for now at least. only one caller)
+ buffer.write32(fInfo.fHeight);
scroggo 2013/11/19 18:17:09 This will require a change to the picture format.
reed1 2013/11/20 20:56:56 indeed. I'll update the picvers code next.
+ buffer.write32(fInfo.fAlphaType);
+ buffer.write32(fInfo.fColorType);
+
+ // 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->computeSize();
+ buffer.write32(fRB);
+ buffer.writeByteArray(fStorage, size);
buffer.writeBool(fCTable != NULL);
if (fCTable) {
fCTable->writeToBuffer(buffer);
@@ -52,9 +66,15 @@ void SkMallocPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
SkMallocPixelRef::SkMallocPixelRef(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer, NULL) {
- fSize = buffer.getArrayCount();
- fStorage = sk_malloc_throw(fSize);
- buffer.readByteArray(fStorage, fSize);
+ fInfo.fWidth = buffer.read32();
scroggo 2013/11/19 18:17:09 readFromMemory?
reed1 2013/11/20 20:56:56 removed api
+ fInfo.fHeight = buffer.read32();
+ fInfo.fAlphaType = (SkAlphaType)buffer.read32();
+ fInfo.fColorType = (SkColorType)buffer.read32();
+
+ fRB = buffer.read32();
+ size_t size = this->computeSize();
+ fStorage = sk_malloc_throw(size);
+ buffer.readByteArray(fStorage, size);
if (buffer.readBool()) {
fCTable = SkNEW_ARGS(SkColorTable, (buffer));
} else {
@@ -62,5 +82,5 @@ SkMallocPixelRef::SkMallocPixelRef(SkFlattenableReadBuffer& buffer)
}
fOwnPixels = true;
- this->setPreLocked(fStorage, fCTable);
+ this->setPreLocked(fStorage, fRB, fCTable);
}

Powered by Google App Engine
This is Rietveld 408576698