diff options
-rw-r--r-- | dm/DMWriteTask.cpp | 5 | ||||
-rw-r--r-- | include/core/SkMallocPixelRef.h | 6 | ||||
-rw-r--r-- | src/core/SkMallocPixelRef.cpp | 10 | ||||
-rw-r--r-- | tests/MallocPixelRefTest.cpp | 5 |
4 files changed, 11 insertions, 15 deletions
diff --git a/dm/DMWriteTask.cpp b/dm/DMWriteTask.cpp index 890a4bb052..f7fa014ea4 100644 --- a/dm/DMWriteTask.cpp +++ b/dm/DMWriteTask.cpp @@ -84,8 +84,11 @@ struct PngAndRaw { } const size_t offset = data->size() - bitmapBytes; + SkAutoTUnref<SkData> subset( + SkData::NewSubset(data, offset, bitmapBytes)); SkAutoTUnref<SkPixelRef> pixels( - SkMallocPixelRef::NewWithData(info, rowBytes, NULL/*ctable*/, data, offset)); + SkMallocPixelRef::NewWithData( + info, rowBytes, NULL/*ctable*/, subset)); SkASSERT(pixels); bitmap->setConfig(info, rowBytes); diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h index f6a57b3dea..ce353080c9 100644 --- a/include/core/SkMallocPixelRef.h +++ b/include/core/SkMallocPixelRef.h @@ -64,9 +64,6 @@ public: * The SkData will be ref()ed and on destruction of the PielRef, * the SkData will be unref()ed. * - * @param offset (in bytes) into the provided SkData that the - * first pixel is located at. - * * This pixelref will ref() the specified colortable (if not NULL). * * Returns NULL on failure. @@ -74,8 +71,7 @@ public: static SkMallocPixelRef* NewWithData(const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable, - SkData* data, - size_t offset = 0); + SkData* data); void* getAddr() const { return fStorage; } diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp index aa7c4f745c..12cb05bd72 100644 --- a/src/core/SkMallocPixelRef.cpp +++ b/src/core/SkMallocPixelRef.cpp @@ -49,6 +49,7 @@ SkMallocPixelRef* SkMallocPixelRef::NewDirect(const SkImageInfo& info, (info, addr, rowBytes, ctable, NULL, NULL)); } + SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info, size_t requestedRowBytes, SkColorTable* ctable) { @@ -108,22 +109,19 @@ static void sk_data_releaseproc(void*, void* dataPtr) { SkMallocPixelRef* SkMallocPixelRef::NewWithData(const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable, - SkData* data, - size_t offset) { + SkData* data) { SkASSERT(data != NULL); - SkASSERT(offset <= data->size()); if (!is_valid(info, ctable)) { return NULL; } if ((rowBytes < info.minRowBytes()) - || ((data->size() - offset) < info.getSafeSize(rowBytes))) { + || (data->size() < info.getSafeSize(rowBytes))) { return NULL; } data->ref(); - const void* ptr = static_cast<const void*>(data->bytes() + offset); SkMallocPixelRef* pr = SkNEW_ARGS(SkMallocPixelRef, - (info, const_cast<void*>(ptr), rowBytes, ctable, + (info, const_cast<void*>(data->data()), rowBytes, ctable, sk_data_releaseproc, static_cast<void*>(data))); SkASSERT(pr != NULL); // We rely on the immutability of the pixels to make the diff --git a/tests/MallocPixelRefTest.cpp b/tests/MallocPixelRefTest.cpp index 5c28ac89cb..cf5e054220 100644 --- a/tests/MallocPixelRefTest.cpp +++ b/tests/MallocPixelRefTest.cpp @@ -104,11 +104,10 @@ DEF_TEST(MallocPixelRef, reporter) { SkData* dataPtr = data.get(); REPORTER_ASSERT(reporter, dataPtr->unique()); SkAutoTUnref<SkMallocPixelRef> pr( - SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data.get(), 4)); + SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data.get())); REPORTER_ASSERT(reporter, !(dataPtr->unique())); data.reset(NULL); REPORTER_ASSERT(reporter, dataPtr->unique()); - REPORTER_ASSERT(reporter, - static_cast<const void*>(dataPtr->bytes() + 4) == pr->pixels()); + REPORTER_ASSERT(reporter, dataPtr->data() == pr->pixels()); } } |