Revert[4] "clean up (partially) colortable api""""
Fixes:
- create temp api for android to pass nullptr
- don't release and access sk_sp<SkData> at the same time in parameters
This reverts commit b14131c1851eea6acbd34cc42a8f860daed36b21.
Bug: skia:
Change-Id: Ic0e4f62520ba9f35455499ed30d306ad19d998a8
Reviewed-on: https://skia-review.googlesource.com/11129
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp
index 70958ca..4578bbb 100644
--- a/tests/BitmapCopyTest.cpp
+++ b/tests/BitmapCopyTest.cpp
@@ -62,11 +62,11 @@
}
}
-static SkColorTable* init_ctable() {
+static sk_sp<SkColorTable> init_ctable() {
static const SkColor colors[] = {
SK_ColorBLACK, SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE
};
- return new SkColorTable(colors, SK_ARRAY_COUNT(colors));
+ return SkColorTable::Make(colors, SK_ARRAY_COUNT(colors));
}
struct Pair {
@@ -194,16 +194,13 @@
static void setup_src_bitmaps(SkBitmap* srcOpaque, SkBitmap* srcPremul,
SkColorType ct) {
- SkColorTable* ctable = nullptr;
+ sk_sp<SkColorTable> ctable;
if (kIndex_8_SkColorType == ct) {
ctable = init_ctable();
}
- srcOpaque->allocPixels(SkImageInfo::Make(W, H, ct, kOpaque_SkAlphaType),
- nullptr, ctable);
- srcPremul->allocPixels(SkImageInfo::Make(W, H, ct, kPremul_SkAlphaType),
- nullptr, ctable);
- SkSafeUnref(ctable);
+ srcOpaque->allocPixels(SkImageInfo::Make(W, H, ct, kOpaque_SkAlphaType), ctable);
+ srcPremul->allocPixels(SkImageInfo::Make(W, H, ct, kPremul_SkAlphaType), ctable);
init_src(*srcOpaque);
init_src(*srcPremul);
}
@@ -378,7 +375,7 @@
// Create bitmap to act as source for copies and subsets.
SkBitmap src, subset;
- SkColorTable* ct = nullptr;
+ sk_sp<SkColorTable> ct;
if (kIndex_8_SkColorType == src.colorType()) {
ct = init_ctable();
}
@@ -394,7 +391,6 @@
kPremul_SkAlphaType))) {
// failure is fine, as we will notice later on
}
- SkSafeUnref(ct);
// Either copy src or extract into 'subset', which is used
// for subsequent calls to copyPixelsTo/From.
diff --git a/tests/BitmapTest.cpp b/tests/BitmapTest.cpp
index 9342d26..76621e6 100644
--- a/tests/BitmapTest.cpp
+++ b/tests/BitmapTest.cpp
@@ -44,7 +44,7 @@
SkBitmap bm;
REPORTER_ASSERT(reporter, !bm.tryAllocPixels(info));
- SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, info.minRowBytes(), nullptr);
+ sk_sp<SkPixelRef> pr = SkMallocPixelRef::MakeAllocate(info, info.minRowBytes(), nullptr);
REPORTER_ASSERT(reporter, !pr);
}
diff --git a/tests/CodecPriv.h b/tests/CodecPriv.h
index 50c205c..cfa794e 100644
--- a/tests/CodecPriv.h
+++ b/tests/CodecPriv.h
@@ -29,7 +29,7 @@
colorCountPtr = &maxColors;
}
- bm->allocPixels(codec->getInfo(), nullptr, colorTable.get());
+ bm->allocPixels(codec->getInfo(), colorTable);
const SkCodec::Result result = codec->getPixels(codec->getInfo(), bm->getPixels(),
bm->rowBytes(), nullptr, colorPtr, colorCountPtr);
return result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput;
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index dd11ff8..f3a393d 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -700,8 +700,7 @@
} else if (SkCodec::kUnimplemented == result) {
// New method should be supported:
SkBitmap bm;
- sk_sp<SkColorTable> colorTable(new SkColorTable(colorStorage, 256));
- bm.allocPixels(info, nullptr, colorTable.get());
+ bm.allocPixels(info, SkColorTable::Make(colorStorage, 256));
result = decoder->startIncrementalDecode(info, bm.getPixels(), bm.rowBytes(), nullptr,
colorStorage, &colorCount);
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
@@ -1108,8 +1107,8 @@
static void check_round_trip(skiatest::Reporter* r, SkCodec* origCodec, const SkImageInfo& info) {
SkBitmap bm1;
SkPMColor colors[256];
- sk_sp<SkColorTable> colorTable1(new SkColorTable(colors, 256));
- bm1.allocPixels(info, nullptr, colorTable1.get());
+ sk_sp<SkColorTable> colorTable1 = SkColorTable::Make(colors, 256);
+ bm1.allocPixels(info, colorTable1);
int numColors;
SkCodec::Result result = origCodec->getPixels(info, bm1.getPixels(), bm1.rowBytes(), nullptr,
const_cast<SkPMColor*>(colorTable1->readColors()),
@@ -1126,8 +1125,8 @@
REPORTER_ASSERT(r, alpha_type_match(info.alphaType(), codec->getInfo().alphaType()));
SkBitmap bm2;
- sk_sp<SkColorTable> colorTable2(new SkColorTable(colors, 256));
- bm2.allocPixels(info, nullptr, colorTable2.get());
+ sk_sp<SkColorTable> colorTable2 = SkColorTable::Make(colors, 256);
+ bm2.allocPixels(info, colorTable2);
result = codec->getPixels(info, bm2.getPixels(), bm2.rowBytes(), nullptr,
const_cast<SkPMColor*>(colorTable2->readColors()), &numColors);
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
diff --git a/tests/GifTest.cpp b/tests/GifTest.cpp
index dae2bc9..0168d89 100644
--- a/tests/GifTest.cpp
+++ b/tests/GifTest.cpp
@@ -256,7 +256,7 @@
options.fColorCount = colorCountPtr;
SkBitmap bm;
- bm.allocPixels(codec->getInfo(), nullptr, colorTable.get());
+ bm.allocPixels(codec->getInfo(), colorTable);
const SkCodec::Result result = codec->getAndroidPixels(codec->getInfo(), bm.getPixels(),
bm.rowBytes(), &options);
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 3a7a192..9916ed3 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -568,10 +568,8 @@
DEF_TEST(ImageFromIndex8Bitmap, r) {
SkPMColor pmColors[1] = {SkPreMultiplyColor(SK_ColorWHITE)};
SkBitmap bm;
- sk_sp<SkColorTable> ctable( new SkColorTable(pmColors, SK_ARRAY_COUNT(pmColors)));
SkImageInfo info = SkImageInfo::Make(1, 1, kIndex_8_SkColorType, kPremul_SkAlphaType);
- bm.allocPixels(info, nullptr, ctable.get());
- SkAutoLockPixels autoLockPixels(bm);
+ bm.allocPixels(info, SkColorTable::Make(pmColors, SK_ARRAY_COUNT(pmColors)));
*bm.getAddr8(0, 0) = 0;
sk_sp<SkImage> img(SkImage::MakeFromBitmap(bm));
REPORTER_ASSERT(r, img != nullptr);
diff --git a/tests/MallocPixelRefTest.cpp b/tests/MallocPixelRefTest.cpp
index b89d121..096e3e6 100644
--- a/tests/MallocPixelRefTest.cpp
+++ b/tests/MallocPixelRefTest.cpp
@@ -25,8 +25,8 @@
REPORTER_ASSERT(reporter, true);
SkImageInfo info = SkImageInfo::MakeN32Premul(10, 13);
{
- sk_sp<SkMallocPixelRef> pr(
- SkMallocPixelRef::NewAllocate(info, info.minRowBytes() - 1, nullptr));
+ sk_sp<SkPixelRef> pr(
+ SkMallocPixelRef::MakeAllocate(info, info.minRowBytes() - 1, nullptr));
// rowbytes too small.
REPORTER_ASSERT(reporter, nullptr == pr.get());
}
@@ -34,8 +34,8 @@
size_t rowBytes = info.minRowBytes() - 1;
size_t size = info.getSafeSize(rowBytes);
sk_sp<SkData> data(SkData::MakeUninitialized(size));
- sk_sp<SkMallocPixelRef> pr(
- SkMallocPixelRef::NewWithData(info, rowBytes, nullptr, data.get()));
+ sk_sp<SkPixelRef> pr(
+ SkMallocPixelRef::MakeWithData(info, rowBytes, nullptr, data));
// rowbytes too small.
REPORTER_ASSERT(reporter, nullptr == pr.get());
}
@@ -43,8 +43,8 @@
size_t rowBytes = info.minRowBytes() + 2;
size_t size = info.getSafeSize(rowBytes) - 1;
sk_sp<SkData> data(SkData::MakeUninitialized(size));
- sk_sp<SkMallocPixelRef> pr(
- SkMallocPixelRef::NewWithData(info, rowBytes, nullptr, data.get()));
+ sk_sp<SkPixelRef> pr(
+ SkMallocPixelRef::MakeWithData(info, rowBytes, nullptr, data));
// data too small.
REPORTER_ASSERT(reporter, nullptr == pr.get());
}
@@ -52,32 +52,32 @@
size_t size = info.getSafeSize(rowBytes) + 9;
{
SkAutoMalloc memory(size);
- sk_sp<SkMallocPixelRef> pr(
- SkMallocPixelRef::NewDirect(info, memory.get(), rowBytes, nullptr));
+ sk_sp<SkPixelRef> pr(
+ SkMallocPixelRef::MakeDirect(info, memory.get(), rowBytes, nullptr));
REPORTER_ASSERT(reporter, pr.get() != nullptr);
REPORTER_ASSERT(reporter, memory.get() == pr->pixels());
}
{
- sk_sp<SkMallocPixelRef> pr(
- SkMallocPixelRef::NewAllocate(info, rowBytes, nullptr));
+ sk_sp<SkPixelRef> pr(
+ SkMallocPixelRef::MakeAllocate(info, rowBytes, nullptr));
REPORTER_ASSERT(reporter, pr.get() != nullptr);
REPORTER_ASSERT(reporter, pr->pixels());
}
{
void* addr = static_cast<void*>(new uint8_t[size]);
- sk_sp<SkMallocPixelRef> pr(
- SkMallocPixelRef::NewWithProc(info, rowBytes, nullptr, addr,
- delete_uint8_proc, nullptr));
+ sk_sp<SkPixelRef> pr(
+ SkMallocPixelRef::MakeWithProc(info, rowBytes, nullptr, addr,
+ delete_uint8_proc, nullptr));
REPORTER_ASSERT(reporter, pr.get() != nullptr);
REPORTER_ASSERT(reporter, addr == pr->pixels());
}
{
int x = 0;
SkAutoMalloc memory(size);
- sk_sp<SkMallocPixelRef> pr(
- SkMallocPixelRef::NewWithProc(info, rowBytes, nullptr,
- memory.get(), set_to_one_proc,
- static_cast<void*>(&x)));
+ sk_sp<SkPixelRef> pr(
+ SkMallocPixelRef::MakeWithProc(info, rowBytes, nullptr,
+ memory.get(), set_to_one_proc,
+ static_cast<void*>(&x)));
REPORTER_ASSERT(reporter, pr.get() != nullptr);
REPORTER_ASSERT(reporter, memory.get() == pr->pixels());
REPORTER_ASSERT(reporter, 0 == x);
@@ -88,10 +88,10 @@
{
int x = 0;
SkAutoMalloc memory(size);
- sk_sp<SkMallocPixelRef> pr(
- SkMallocPixelRef::NewWithProc(SkImageInfo::MakeN32Premul(-1, -1), rowBytes, nullptr,
- memory.get(), set_to_one_proc,
- static_cast<void*>(&x)));
+ sk_sp<SkPixelRef> pr(
+ SkMallocPixelRef::MakeWithProc(SkImageInfo::MakeN32Premul(-1, -1), rowBytes, nullptr,
+ memory.get(), set_to_one_proc,
+ static_cast<void*>(&x)));
REPORTER_ASSERT(reporter, pr.get() == nullptr);
// make sure that set_to_one_proc was called.
REPORTER_ASSERT(reporter, 1 == x);
@@ -99,17 +99,16 @@
{
void* addr = static_cast<void*>(new uint8_t[size]);
REPORTER_ASSERT(reporter, addr != nullptr);
- sk_sp<SkMallocPixelRef> pr(
- SkMallocPixelRef::NewWithProc(info, rowBytes, nullptr, addr,
- delete_uint8_proc, nullptr));
+ sk_sp<SkPixelRef> pr(
+ SkMallocPixelRef::MakeWithProc(info, rowBytes, nullptr, addr,
+ delete_uint8_proc, nullptr));
REPORTER_ASSERT(reporter, addr == pr->pixels());
}
{
sk_sp<SkData> data(SkData::MakeUninitialized(size));
SkData* dataPtr = data.get();
REPORTER_ASSERT(reporter, dataPtr->unique());
- sk_sp<SkMallocPixelRef> pr(
- SkMallocPixelRef::NewWithData(info, rowBytes, nullptr, data.get()));
+ sk_sp<SkPixelRef> pr = SkMallocPixelRef::MakeWithData(info, rowBytes, nullptr, data);
REPORTER_ASSERT(reporter, !(dataPtr->unique()));
data.reset(nullptr);
REPORTER_ASSERT(reporter, dataPtr->unique());
diff --git a/tests/PixelRefTest.cpp b/tests/PixelRefTest.cpp
index 487e519..683e249 100644
--- a/tests/PixelRefTest.cpp
+++ b/tests/PixelRefTest.cpp
@@ -69,7 +69,7 @@
DEF_TEST(PixelRef_GenIDChange, r) {
SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
- sk_sp<SkPixelRef> pixelRef(SkMallocPixelRef::NewAllocate(info, 0, nullptr));
+ sk_sp<SkPixelRef> pixelRef = SkMallocPixelRef::MakeAllocate(info, 0, nullptr);
// Register a listener.
int count = 0;
diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp
index c38e4d6..cace6b1 100644
--- a/tests/WritePixelsTest.cpp
+++ b/tests/WritePixelsTest.cpp
@@ -263,7 +263,7 @@
if (!bm->setInfo(info, rowBytes)) {
return false;
}
- sk_sp<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, rowBytes, nullptr));
+ sk_sp<SkPixelRef> pr = SkMallocPixelRef::MakeAllocate(info, rowBytes, nullptr);
bm->setPixelRef(std::move(pr), 0, 0);
return true;
}