Remove offset to SkMallocPixelRef::NewWithData - use SkData::NewSubset instead.
R=scroggo@google.com, mtklein@google.com, reed@google.com Author: halcanary@google.com Review URL: https://codereview.chromium.org/243483002 git-svn-id: http://skia.googlecode.com/svn/trunk@14289 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
855e88edfa
commit
2c4e75cc3c
@ -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);
|
||||
|
@ -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; }
|
||||
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user