aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkMallocPixelRef.cpp
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-04-01 17:21:42 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-01 17:21:52 +0000
commitb14131c1851eea6acbd34cc42a8f860daed36b21 (patch)
tree39e74b29ec1a34ff63fc347ba9b616186f435ff6 /src/core/SkMallocPixelRef.cpp
parent9920b10f5292838f00600f676c4578cd11705e60 (diff)
Revert "Revert[2] "clean up (partially) colortable api"""
This reverts commit 9920b10f5292838f00600f676c4578cd11705e60. Reason for revert: trying to get details on w2k failure https://chromium-swarm.appspot.com/task?id=354345d34ba3b310&refresh=10 Caught exception 3221225477 EXCEPTION_ACCESS_VIOLATION, was running: unit test HugeBlurImageFilter unit test FontNames unit test Codec_PngRoundTrip unit test ClampRange unit test FontHost unit test ColorMatrixFilter f16 image scaled_codec_premul abnormal.wbmp 565 image brd_android_codec_divisor_0.167 interlaced3.png_0.167 unit test Codec_png unit test ImageFilterBlurLargeImage unit test FontObj unit test DrawText unit test GrShape 565 image brd_android_codec_divisor_0.333 interlaced2.png_0.333 unit test PathOpsOpCubicsThreaded unit test PathOpsOpLoopsThreaded unit test FontMgr unit test ColorToHSVRoundTrip unit test Image_Serialize_Encoding_Failure Likely culprit: unit test Image_Serialize_Encoding_Failure step returned non-zero exit code: -1073741819 Original change's description: > Revert[2] "clean up (partially) colortable api"" > > This reverts commit 1d1165ca6575e082b892c5460492c411618783ad. > > Bug: skia: > Change-Id: Idbc0634ae3cec2e79f592d252de8751b077e6408 > Reviewed-on: https://skia-review.googlesource.com/11024 > Reviewed-by: Mike Reed <reed@google.com> > Commit-Queue: Mike Reed <reed@google.com> > TBR=reed@google.com,reviews@skia.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Change-Id: Ia4e73434b083224baa36092c69526c2f59bb16aa Reviewed-on: https://skia-review.googlesource.com/11025 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/core/SkMallocPixelRef.cpp')
-rw-r--r--src/core/SkMallocPixelRef.cpp126
1 files changed, 67 insertions, 59 deletions
diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp
index 7197aebae5..0d758fcb3d 100644
--- a/src/core/SkMallocPixelRef.cpp
+++ b/src/core/SkMallocPixelRef.cpp
@@ -37,23 +37,22 @@ static bool is_valid(const SkImageInfo& info, SkColorTable* ctable) {
return true;
}
-sk_sp<SkPixelRef> SkMallocPixelRef::MakeDirect(const SkImageInfo& info,
- void* addr,
- size_t rowBytes,
- sk_sp<SkColorTable> ctable) {
- if (!is_valid(info, ctable.get())) {
+SkMallocPixelRef* SkMallocPixelRef::NewDirect(const SkImageInfo& info,
+ void* addr,
+ size_t rowBytes,
+ SkColorTable* ctable) {
+ if (!is_valid(info, ctable)) {
return nullptr;
}
- return sk_sp<SkPixelRef>(new SkMallocPixelRef(info, addr, rowBytes, std::move(ctable),
- nullptr, nullptr));
+ return new SkMallocPixelRef(info, addr, rowBytes, ctable, nullptr, nullptr);
}
- sk_sp<SkPixelRef> SkMallocPixelRef::MakeUsing(void*(*alloc)(size_t),
- const SkImageInfo& info,
- size_t requestedRowBytes,
- sk_sp<SkColorTable> ctable) {
- if (!is_valid(info, ctable.get())) {
+ SkMallocPixelRef* SkMallocPixelRef::NewUsing(void*(*alloc)(size_t),
+ const SkImageInfo& info,
+ size_t requestedRowBytes,
+ SkColorTable* ctable) {
+ if (!is_valid(info, ctable)) {
return nullptr;
}
@@ -85,59 +84,62 @@ sk_sp<SkPixelRef> SkMallocPixelRef::MakeDirect(const SkImageInfo& info,
return nullptr;
}
- return sk_sp<SkPixelRef>(new SkMallocPixelRef(info, addr, rowBytes, std::move(ctable),
- sk_free_releaseproc, nullptr));
+ return new SkMallocPixelRef(info, addr, rowBytes, ctable, sk_free_releaseproc, nullptr);
}
-sk_sp<SkPixelRef> SkMallocPixelRef::MakeAllocate(const SkImageInfo& info,
+SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info,
size_t rowBytes,
- sk_sp<SkColorTable> ctable) {
+ SkColorTable* ctable) {
auto sk_malloc_nothrow = [](size_t size) { return sk_malloc_flags(size, 0); };
- return MakeUsing(sk_malloc_nothrow, info, rowBytes, std::move(ctable));
+ return NewUsing(sk_malloc_nothrow, info, rowBytes, ctable);
}
-sk_sp<SkPixelRef> SkMallocPixelRef::MakeZeroed(const SkImageInfo& info,
- size_t rowBytes,
- sk_sp<SkColorTable> ctable) {
- return MakeUsing(sk_calloc, info, rowBytes, std::move(ctable));
+SkMallocPixelRef* SkMallocPixelRef::NewZeroed(const SkImageInfo& info,
+ size_t rowBytes,
+ SkColorTable* ctable) {
+ return NewUsing(sk_calloc, info, rowBytes, ctable);
}
-static void sk_data_releaseproc(void*, void* dataPtr) {
- (static_cast<SkData*>(dataPtr))->unref();
-}
-
-sk_sp<SkPixelRef> SkMallocPixelRef::MakeWithProc(const SkImageInfo& info,
- size_t rowBytes,
- sk_sp<SkColorTable> ctable,
- void* addr,
- SkMallocPixelRef::ReleaseProc proc,
- void* context) {
- if (!is_valid(info, ctable.get())) {
+SkMallocPixelRef* SkMallocPixelRef::NewWithProc(const SkImageInfo& info,
+ size_t rowBytes,
+ SkColorTable* ctable,
+ void* addr,
+ SkMallocPixelRef::ReleaseProc proc,
+ void* context) {
+ if (!is_valid(info, ctable)) {
if (proc) {
proc(addr, context);
}
return nullptr;
}
- return sk_sp<SkPixelRef>(new SkMallocPixelRef(info, addr, rowBytes, std::move(ctable),
- proc, context));
+ return new SkMallocPixelRef(info, addr, rowBytes, ctable, proc, context);
}
-sk_sp<SkPixelRef> SkMallocPixelRef::MakeWithData(const SkImageInfo& info,
+static void sk_data_releaseproc(void*, void* dataPtr) {
+ (static_cast<SkData*>(dataPtr))->unref();
+}
+
+SkMallocPixelRef* SkMallocPixelRef::NewWithData(const SkImageInfo& info,
size_t rowBytes,
- sk_sp<SkColorTable> ctable,
- sk_sp<SkData> data) {
+ SkColorTable* ctable,
+ SkData* data) {
SkASSERT(data != nullptr);
- if (!is_valid(info, ctable.get())) {
+ if (!is_valid(info, ctable)) {
return nullptr;
}
if ((rowBytes < info.minRowBytes())
|| (data->size() < info.getSafeSize(rowBytes))) {
return nullptr;
}
- SkPixelRef* pr = new SkMallocPixelRef(info, const_cast<void*>(data->data()), rowBytes,
- std::move(ctable), sk_data_releaseproc, data.release());
- pr->setImmutable(); // since we were created with (immutable) data
- return sk_sp<SkPixelRef>(pr);
+ data->ref();
+ SkMallocPixelRef* pr =
+ new SkMallocPixelRef(info, const_cast<void*>(data->data()), rowBytes, ctable,
+ sk_data_releaseproc, static_cast<void*>(data));
+ SkASSERT(pr != nullptr);
+ // We rely on the immutability of the pixels to make the
+ // const_cast okay.
+ pr->setImmutable();
+ return pr;
}
///////////////////////////////////////////////////////////////////////////////
@@ -146,47 +148,50 @@ SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage,
size_t rowBytes, SkColorTable* ctable,
bool ownsPixels)
: INHERITED(info)
- , fCTable(sk_ref_sp(ctable))
, fReleaseProc(ownsPixels ? sk_free_releaseproc : nullptr)
, fReleaseProcContext(nullptr) {
// This constructor is now DEPRICATED.
- SkASSERT(is_valid(info, fCTable.get()));
+ SkASSERT(is_valid(info, ctable));
SkASSERT(rowBytes >= info.minRowBytes());
if (kIndex_8_SkColorType != info.colorType()) {
- fCTable = nullptr;
+ ctable = nullptr;
}
fStorage = storage;
+ fCTable = ctable;
fRB = rowBytes;
+ SkSafeRef(ctable);
- this->setPreLocked(fStorage, rowBytes, fCTable.get());
+ this->setPreLocked(fStorage, rowBytes, fCTable);
}
SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage,
- size_t rowBytes, sk_sp<SkColorTable> ctable,
+ size_t rowBytes, SkColorTable* ctable,
SkMallocPixelRef::ReleaseProc proc,
void* context)
: INHERITED(info)
, fReleaseProc(proc)
, fReleaseProcContext(context)
{
- SkASSERT(is_valid(info, ctable.get()));
+ SkASSERT(is_valid(info, ctable));
SkASSERT(rowBytes >= info.minRowBytes());
if (kIndex_8_SkColorType != info.colorType()) {
- ctable.reset(nullptr);
+ ctable = nullptr;
}
fStorage = storage;
- fCTable = std::move(ctable);
+ fCTable = ctable;
fRB = rowBytes;
+ SkSafeRef(ctable);
- this->setPreLocked(fStorage, rowBytes, fCTable.get());
+ this->setPreLocked(fStorage, rowBytes, fCTable);
}
SkMallocPixelRef::~SkMallocPixelRef() {
+ SkSafeUnref(fCTable);
if (fReleaseProc != nullptr) {
fReleaseProc(fStorage, fReleaseProcContext);
}
@@ -195,7 +200,7 @@ SkMallocPixelRef::~SkMallocPixelRef() {
bool SkMallocPixelRef::onNewLockPixels(LockRec* rec) {
rec->fPixels = fStorage;
rec->fRowBytes = fRB;
- rec->fColorTable = fCTable.get();
+ rec->fColorTable = fCTable;
return true;
}
@@ -207,11 +212,14 @@ size_t SkMallocPixelRef::getAllocatedSizeInBytes() const {
return this->info().getSafeSize(fRB);
}
-#ifdef SK_SUPPORT_LEGACY_PIXELREFFACTORY
-SkMallocPixelRef* SkMallocPixelRef::NewWithData(const SkImageInfo& info,
- size_t rowBytes,
- SkColorTable* ctable,
- SkData* data) {
- return (SkMallocPixelRef*)MakeWithData(info, rowBytes, sk_ref_sp(ctable), sk_ref_sp(data)).release();
+///////////////////////////////////////////////////////////////////////////////
+
+SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, size_t rowBytes,
+ SkColorTable* ctable) {
+ return SkMallocPixelRef::NewAllocate(info, rowBytes, ctable);
+}
+
+SkPixelRef* SkMallocPixelRef::ZeroedPRFactory::create(const SkImageInfo& info, size_t rowBytes,
+ SkColorTable* ctable) {
+ return SkMallocPixelRef::NewZeroed(info, rowBytes, ctable);
}
-#endif