diff options
author | Mike Reed <reed@google.com> | 2017-03-31 09:20:50 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-31 15:39:31 +0000 |
commit | 2e491a6a113c5e16a3b7bede5fa6f588deeb928d (patch) | |
tree | e8540e14d4ca1dd12ca3b2df5d9ef0b6f48b3a7f /tests | |
parent | f3333c89bf05fc602d9bf8e1e24547668c660383 (diff) |
clean up (partially) colortable api
Needs this to land: https://codereview.chromium.org/2789853002/
Bug: skia:
Change-Id: I38d916a546b7fa64d000d973e695ddda24a589e7
Reviewed-on: https://skia-review.googlesource.com/10600
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/BitmapCopyTest.cpp | 16 | ||||
-rw-r--r-- | tests/BitmapTest.cpp | 2 | ||||
-rw-r--r-- | tests/CodecPriv.h | 2 | ||||
-rw-r--r-- | tests/CodecTest.cpp | 11 | ||||
-rw-r--r-- | tests/GifTest.cpp | 2 | ||||
-rw-r--r-- | tests/ImageTest.cpp | 4 | ||||
-rw-r--r-- | tests/MallocPixelRefTest.cpp | 51 | ||||
-rw-r--r-- | tests/PixelRefTest.cpp | 2 | ||||
-rw-r--r-- | tests/WritePixelsTest.cpp | 2 |
9 files changed, 42 insertions, 50 deletions
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp index 70958cae55..4578bbb7d7 100644 --- a/tests/BitmapCopyTest.cpp +++ b/tests/BitmapCopyTest.cpp @@ -62,11 +62,11 @@ static void init_src(const SkBitmap& bitmap) { } } -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 const int H = 33; 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 @@ DEF_TEST(BitmapCopy, reporter) { // 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 @@ DEF_TEST(BitmapCopy, reporter) { 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 9342d261c2..76621e6b38 100644 --- a/tests/BitmapTest.cpp +++ b/tests/BitmapTest.cpp @@ -44,7 +44,7 @@ static void test_bigalloc(skiatest::Reporter* reporter) { 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 50c205c16a..cfa794ed68 100644 --- a/tests/CodecPriv.h +++ b/tests/CodecPriv.h @@ -29,7 +29,7 @@ inline bool decode_memory(const void* mem, size_t size, SkBitmap* bm) { 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 dd11ff84fd..f3a393d7ac 100644 --- a/tests/CodecTest.cpp +++ b/tests/CodecTest.cpp @@ -700,8 +700,7 @@ static void test_invalid_parameters(skiatest::Reporter* r, const char path[]) { } 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 bool alpha_type_match(SkAlphaType origAlphaType, SkAlphaType codecAlphaTy 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 @@ static void check_round_trip(skiatest::Reporter* r, SkCodec* origCodec, const Sk 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 dae2bc9329..0168d89d83 100644 --- a/tests/GifTest.cpp +++ b/tests/GifTest.cpp @@ -256,7 +256,7 @@ DEF_TEST(Gif_Sampled, r) { 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 ba49000d9a..492985c18f 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -568,10 +568,8 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_drawAbandonedGpuImage, reporter, c 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 b89d121579..096e3e69ee 100644 --- a/tests/MallocPixelRefTest.cpp +++ b/tests/MallocPixelRefTest.cpp @@ -25,8 +25,8 @@ DEF_TEST(MallocPixelRef, reporter) { 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 @@ DEF_TEST(MallocPixelRef, reporter) { 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 @@ DEF_TEST(MallocPixelRef, reporter) { 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 @@ DEF_TEST(MallocPixelRef, reporter) { 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 @@ DEF_TEST(MallocPixelRef, reporter) { { 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 @@ DEF_TEST(MallocPixelRef, reporter) { { 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 487e5195f3..683e249626 100644 --- a/tests/PixelRefTest.cpp +++ b/tests/PixelRefTest.cpp @@ -69,7 +69,7 @@ private: 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 c38e4d665d..cace6b196e 100644 --- a/tests/WritePixelsTest.cpp +++ b/tests/WritePixelsTest.cpp @@ -263,7 +263,7 @@ static bool alloc_row_bytes(SkBitmap* bm, const SkImageInfo& info, size_t rowByt 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; } |