aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/BitmapBench.cpp4
-rw-r--r--bench/RepeatTileBench.cpp4
-rw-r--r--dm/DMSrcSink.cpp4
-rw-r--r--fuzz/fuzz.cpp3
-rw-r--r--gm/all_bitmap_configs.cpp3
-rw-r--r--gm/bitmapfilters.cpp5
-rw-r--r--gm/encode-srgb.cpp3
-rw-r--r--gm/image_pict.cpp3
-rw-r--r--gm/tinybitmap.cpp4
-rw-r--r--gn/android_framework_defines.gni1
-rw-r--r--include/core/SkBitmap.h19
-rw-r--r--include/core/SkColorTable.h6
-rw-r--r--include/core/SkMallocPixelRef.h83
-rw-r--r--public.bzl1
-rw-r--r--samplecode/SampleBlur.cpp6
-rw-r--r--samplecode/SampleDitherBitmap.cpp5
-rw-r--r--samplecode/SampleFilter.cpp4
-rw-r--r--samplecode/SampleTinyBitmap.cpp4
-rw-r--r--src/core/SkBitmap.cpp35
-rw-r--r--src/core/SkBitmapDevice.cpp5
-rw-r--r--src/core/SkColorTable.cpp22
-rw-r--r--src/core/SkImageCacherator.cpp2
-rw-r--r--src/core/SkMallocPixelRef.cpp128
-rw-r--r--src/core/SkSpecialSurface.cpp4
-rw-r--r--src/effects/gradients/SkGradientShader.cpp10
-rw-r--r--src/effects/gradients/SkGradientShaderPriv.h5
-rw-r--r--src/image/SkSurface_Raster.cpp2
-rw-r--r--tests/BitmapCopyTest.cpp16
-rw-r--r--tests/BitmapTest.cpp2
-rw-r--r--tests/CodecPriv.h2
-rw-r--r--tests/CodecTest.cpp11
-rw-r--r--tests/GifTest.cpp2
-rw-r--r--tests/ImageTest.cpp4
-rw-r--r--tests/MallocPixelRefTest.cpp51
-rw-r--r--tests/PixelRefTest.cpp2
-rw-r--r--tests/WritePixelsTest.cpp2
-rw-r--r--tools/Resources.cpp5
37 files changed, 224 insertions, 248 deletions
diff --git a/bench/BitmapBench.cpp b/bench/BitmapBench.cpp
index 8e881a665b..fdf17e90b1 100644
--- a/bench/BitmapBench.cpp
+++ b/bench/BitmapBench.cpp
@@ -44,10 +44,8 @@ static void convertToIndex666(const SkBitmap& src, SkBitmap* dst, SkAlphaType aT
}
}
}
- SkColorTable* ctable = new SkColorTable(storage, 216);
dst->allocPixels(SkImageInfo::Make(src.width(), src.height(), kIndex_8_SkColorType, aType),
- nullptr, ctable);
- ctable->unref();
+ SkColorTable::Make(storage, 216));
SkAutoLockPixels alps(src);
SkAutoLockPixels alpd(*dst);
diff --git a/bench/RepeatTileBench.cpp b/bench/RepeatTileBench.cpp
index 33e91780d9..df58a14d10 100644
--- a/bench/RepeatTileBench.cpp
+++ b/bench/RepeatTileBench.cpp
@@ -62,11 +62,9 @@ static void convert_to_index666(const SkBitmap& src, SkBitmap* dst) {
}
}
}
- SkColorTable* ctable = new SkColorTable(storage, 216);
dst->allocPixels(SkImageInfo::Make(src.width(), src.height(),
kIndex_8_SkColorType, kOpaque_SkAlphaType),
- nullptr, ctable);
- ctable->unref();
+ SkColorTable::Make(storage, 216));
SkAutoLockPixels alps(src);
SkAutoLockPixels alpd(*dst);
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index eb9ba41d96..f505bb7476 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -1445,11 +1445,9 @@ Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) con
SkAlphaType alphaType = kPremul_SkAlphaType;
(void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType);
- SkMallocPixelRef::ZeroedPRFactory factory;
dst->allocPixels(SkImageInfo::Make(size.width(), size.height(),
fColorType, alphaType, fColorSpace),
- &factory,
- nullptr/*colortable*/);
+ nullptr/*colortable*/, SkBitmap::kZeroPixels_AllocFlag);
SkCanvas canvas(*dst);
return src.draw(&canvas);
}
diff --git a/fuzz/fuzz.cpp b/fuzz/fuzz.cpp
index 8374f9518b..8e2a73376f 100644
--- a/fuzz/fuzz.cpp
+++ b/fuzz/fuzz.cpp
@@ -224,11 +224,10 @@ static void fuzz_img(sk_sp<SkData> bytes, uint8_t scale, uint8_t mode) {
}
SkBitmap bitmap;
- SkMallocPixelRef::ZeroedPRFactory zeroFactory;
SkCodec::Options options;
options.fZeroInitialized = SkCodec::kYes_ZeroInitialized;
- if (!bitmap.tryAllocPixels(decodeInfo, &zeroFactory, colorTable.get())) {
+ if (!bitmap.tryAllocPixels(decodeInfo, colorTable, SkBitmap::kZeroPixels_AllocFlag)) {
SkDebugf("[terminated] Could not allocate memory. Image might be too large (%d x %d)",
decodeInfo.width(), decodeInfo.height());
return;
diff --git a/gm/all_bitmap_configs.cpp b/gm/all_bitmap_configs.cpp
index ea7b73483b..60aec88ddf 100644
--- a/gm/all_bitmap_configs.cpp
+++ b/gm/all_bitmap_configs.cpp
@@ -124,10 +124,9 @@ static SkBitmap indexed_bitmap() {
pmColors[i] = premultiply_color(colors[i]);
}
SkBitmap bm;
- sk_sp<SkColorTable> ctable(new SkColorTable(pmColors, SK_ARRAY_COUNT(pmColors)));
SkImageInfo info = SkImageInfo::Make(SCALE, SCALE, kIndex_8_SkColorType,
kPremul_SkAlphaType);
- bm.allocPixels(info, nullptr, ctable.get());
+ bm.allocPixels(info, SkColorTable::Make(pmColors, SK_ARRAY_COUNT(pmColors)));
SkAutoLockPixels autoLockPixels1(n32bitmap);
SkAutoLockPixels autoLockPixels2(bm);
for (int y = 0; y < SCALE; ++y) {
diff --git a/gm/bitmapfilters.cpp b/gm/bitmapfilters.cpp
index 2cded98236..22e5d0943f 100644
--- a/gm/bitmapfilters.cpp
+++ b/gm/bitmapfilters.cpp
@@ -17,12 +17,9 @@ static void make_bm(SkBitmap* bm) {
for (size_t i = 0; i < SK_ARRAY_COUNT(colors); ++i) {
colorsPM[i] = SkPreMultiplyColor(colors[i]);
}
- SkColorTable* ctable = new SkColorTable(colorsPM, 4);
-
bm->allocPixels(SkImageInfo::Make(2, 2, kIndex_8_SkColorType,
kPremul_SkAlphaType),
- nullptr, ctable);
- ctable->unref();
+ SkColorTable::Make(colorsPM, 4));
*bm->getAddr8(0, 0) = 0;
*bm->getAddr8(1, 0) = 1;
diff --git a/gm/encode-srgb.cpp b/gm/encode-srgb.cpp
index f62d48ae2c..894b0ef8d5 100644
--- a/gm/encode-srgb.cpp
+++ b/gm/encode-srgb.cpp
@@ -67,10 +67,9 @@ static void make_index8(SkBitmap* bitmap, SkAlphaType alphaType, sk_sp<SkColorSp
pmColors[i] = toPMColor(colors[i]);
}
- sk_sp<SkColorTable> colorTable(new SkColorTable(pmColors, SK_ARRAY_COUNT(pmColors)));
SkImageInfo info = SkImageInfo::Make(imageWidth, imageHeight, kIndex_8_SkColorType,
alphaType, colorSpace);
- bitmap->allocPixels(info, nullptr, colorTable.get());
+ bitmap->allocPixels(info, SkColorTable::Make(pmColors, SK_ARRAY_COUNT(pmColors)));
for (int y = 0; y < imageHeight; y++) {
for (int x = 0; x < imageWidth; x++) {
*bitmap->getAddr8(x, y) = (x / div_round_up(imageWidth, 2)) +
diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp
index 792173ce66..f23b89e728 100644
--- a/gm/image_pict.cpp
+++ b/gm/image_pict.cpp
@@ -199,8 +199,7 @@ static std::unique_ptr<SkImageGenerator> make_ctable_generator(GrContext*, sk_sp
SkImageInfo info = SkImageInfo::Make(100, 100, kIndex_8_SkColorType, kPremul_SkAlphaType);
SkBitmap bm2;
- sk_sp<SkColorTable> ct(new SkColorTable(colors, count));
- bm2.allocPixels(info, nullptr, ct.get());
+ bm2.allocPixels(info, SkColorTable::Make(colors, count));
for (int y = 0; y < info.height(); ++y) {
for (int x = 0; x < info.width(); ++x) {
*bm2.getAddr8(x, y) = find_closest(*bm.getAddr32(x, y), colors, count);
diff --git a/gm/tinybitmap.cpp b/gm/tinybitmap.cpp
index 0f0f1374ea..1640cb23d1 100644
--- a/gm/tinybitmap.cpp
+++ b/gm/tinybitmap.cpp
@@ -15,13 +15,11 @@ namespace skiagm {
static SkBitmap make_bitmap() {
const SkPMColor c[] = { SkPackARGB32(0x80, 0x80, 0, 0) };
- SkColorTable* ctable = new SkColorTable(c, SK_ARRAY_COUNT(c));
SkBitmap bm;
bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType,
kPremul_SkAlphaType),
- nullptr, ctable);
- ctable->unref();
+ SkColorTable::Make(c, SK_ARRAY_COUNT(c)));
bm.lockPixels();
*bm.getAddr8(0, 0) = 0;
diff --git a/gn/android_framework_defines.gni b/gn/android_framework_defines.gni
index 364ea39fd5..df2e56265f 100644
--- a/gn/android_framework_defines.gni
+++ b/gn/android_framework_defines.gni
@@ -17,4 +17,5 @@ android_framework_defines = [
"SK_SUPPORT_LEGACY_EMBOSSMASKFILTER",
"SK_SUPPORT_LEGACY_CANVAS_HELPERS",
"SK_SUPPORT_LEGACY_CANVAS_VERTICES",
+ "SK_SUPPORT_LEGACY_PIXELREFFACTORY",
]
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index fd25a23cdd..1a2daf0845 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -238,20 +238,29 @@ public:
bool setInfo(const SkImageInfo&, size_t rowBytes = 0);
+ enum AllocFlags {
+ kZeroPixels_AllocFlag = 1 << 0,
+ };
/**
* Allocate the bitmap's pixels to match the requested image info. If the Factory
* is non-null, call it to allcoate the pixelref. If the ImageInfo requires
- * a colortable, then ColorTable must be non-null, and will be ref'd.
+ * a colortable, then ColorTable must be non-null.
+ *
* On failure, the bitmap will be set to empty and return false.
*/
- bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*);
-
- void allocPixels(const SkImageInfo& info, SkPixelRefFactory* factory, SkColorTable* ctable) {
- if (!this->tryAllocPixels(info, factory, ctable)) {
+ bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info, sk_sp<SkColorTable> ctable,
+ uint32_t flags = 0);
+ void allocPixels(const SkImageInfo& info, sk_sp<SkColorTable> ctable, uint32_t flags = 0) {
+ if (!this->tryAllocPixels(info, std::move(ctable), flags)) {
sk_throw();
}
}
+ // TEMPORARY -- remove after updating Android BitmapTests.cpp:35
+ void allocPixels(const SkImageInfo& info, std::nullptr_t, SkColorTable* ctable) {
+ this->allocPixels(info, sk_ref_sp(ctable));
+ }
+
/**
* Allocate the bitmap's pixels to match the requested image info and
* rowBytes. If the request cannot be met (e.g. the info is invalid or
diff --git a/include/core/SkColorTable.h b/include/core/SkColorTable.h
index 07dfd675b2..40919d3bac 100644
--- a/include/core/SkColorTable.h
+++ b/include/core/SkColorTable.h
@@ -24,10 +24,12 @@
*/
class SK_API SkColorTable : public SkRefCnt {
public:
+ static sk_sp<SkColorTable> Make(const SkPMColor colors[], int count);
+
/** Copy up to 256 colors into a new SkColorTable.
*/
SkColorTable(const SkPMColor colors[], int count);
- virtual ~SkColorTable();
+ ~SkColorTable() override;
/** Returns the number of colors in the table.
*/
@@ -52,7 +54,7 @@ public:
void writeToBuffer(SkWriteBuffer&) const;
// may return null
- static SkColorTable* Create(SkReadBuffer&);
+ static sk_sp<SkColorTable> Create(SkReadBuffer&);
private:
enum AllocatedWithMalloc {
diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h
index bb07fa2dab..2e4c4e69eb 100644
--- a/include/core/SkMallocPixelRef.h
+++ b/include/core/SkMallocPixelRef.h
@@ -22,12 +22,10 @@ public:
* lifetime of the pixel storage buffer, as this pixelref will not try
* to delete it.
*
- * The pixelref will ref() the colortable (if not NULL).
- *
* Returns NULL on failure.
*/
- static SkMallocPixelRef* NewDirect(const SkImageInfo&, void* addr,
- size_t rowBytes, SkColorTable*);
+ static sk_sp<SkPixelRef> MakeDirect(const SkImageInfo&, void* addr,
+ size_t rowBytes, sk_sp<SkColorTable>);
/**
* Return a new SkMallocPixelRef, automatically allocating storage for the
@@ -39,22 +37,18 @@ public:
*
* Returns NULL on failure.
*/
- static SkMallocPixelRef* NewAllocate(const SkImageInfo& info,
- size_t rowBytes, SkColorTable*);
+ static sk_sp<SkPixelRef> MakeAllocate(const SkImageInfo&, size_t rowBytes, sk_sp<SkColorTable>);
/**
- * Identical to NewAllocate, except all pixel bytes are zeroed.
+ * Identical to MakeAllocate, except all pixel bytes are zeroed.
*/
- static SkMallocPixelRef* NewZeroed(const SkImageInfo& info,
- size_t rowBytes, SkColorTable*);
+ static sk_sp<SkPixelRef> MakeZeroed(const SkImageInfo&, size_t rowBytes, sk_sp<SkColorTable>);
/**
* Return a new SkMallocPixelRef with the provided pixel storage,
* rowBytes, and optional colortable. On destruction, ReleaseProc
* will be called.
*
- * This pixelref will ref() the specified colortable (if not NULL).
- *
* If ReleaseProc is NULL, the pixels will never be released. This
* can be useful if the pixels were stack allocated. However, such an
* SkMallocPixelRef must not live beyond its pixels (e.g. by copying
@@ -63,10 +57,10 @@ public:
* Returns NULL on failure.
*/
typedef void (*ReleaseProc)(void* addr, void* context);
- static SkMallocPixelRef* NewWithProc(const SkImageInfo& info,
- size_t rowBytes, SkColorTable*,
- void* addr, ReleaseProc proc,
- void* context);
+ static sk_sp<SkPixelRef> MakeWithProc(const SkImageInfo& info,
+ size_t rowBytes, sk_sp<SkColorTable>,
+ void* addr, ReleaseProc proc,
+ void* context);
/**
* Return a new SkMallocPixelRef that will use the provided
@@ -74,27 +68,38 @@ public:
* The SkData will be ref()ed and on destruction of the PielRef,
* the SkData will be unref()ed.
*
- * This pixelref will ref() the specified colortable (if not NULL).
- *
* Returns NULL on failure.
*/
+ static sk_sp<SkPixelRef> MakeWithData(const SkImageInfo& info,
+ size_t rowBytes,
+ sk_sp<SkColorTable>,
+ sk_sp<SkData> data);
+
+#ifdef SK_SUPPORT_LEGACY_PIXELREFFACTORY
+ static SkMallocPixelRef* NewDirect(const SkImageInfo& info, void* addr,
+ size_t rowBytes, SkColorTable* ctable) {
+ return (SkMallocPixelRef*)MakeDirect(info, addr, rowBytes, sk_ref_sp(ctable)).release();
+ }
+ static SkMallocPixelRef* NewAllocate(const SkImageInfo& info, size_t rb, SkColorTable* ct) {
+ return (SkMallocPixelRef*)MakeAllocate(info, rb, sk_ref_sp(ct)).release();
+ }
+ static SkMallocPixelRef* NewZeroed(const SkImageInfo& info, size_t rowBytes, SkColorTable* ct) {
+ return (SkMallocPixelRef*)MakeZeroed(info, rowBytes, sk_ref_sp(ct)).release();
+ }
+ static SkMallocPixelRef* NewWithProc(const SkImageInfo& info,
+ size_t rowBytes, SkColorTable* ctable,
+ void* addr, ReleaseProc proc,
+ void* ctx) {
+ return (SkMallocPixelRef*)MakeWithProc(info, rowBytes, sk_ref_sp(ctable), addr, proc, ctx).release();
+ }
static SkMallocPixelRef* NewWithData(const SkImageInfo& info,
size_t rowBytes,
SkColorTable* ctable,
SkData* data);
+#endif
void* getAddr() const { return fStorage; }
- class PRFactory : public SkPixelRefFactory {
- public:
- SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable*) override;
- };
-
- class ZeroedPRFactory : public SkPixelRefFactory {
- public:
- SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable*) override;
- };
-
protected:
// The ownPixels version of this constructor is deprecated.
SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
@@ -107,18 +112,18 @@ protected:
private:
// Uses alloc to implement NewAllocate or NewZeroed.
- static SkMallocPixelRef* NewUsing(void*(*alloc)(size_t),
- const SkImageInfo&,
- size_t rowBytes,
- SkColorTable*);
-
- void* fStorage;
- SkColorTable* fCTable;
- size_t fRB;
- ReleaseProc fReleaseProc;
- void* fReleaseProcContext;
-
- SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
+ static sk_sp<SkPixelRef> MakeUsing(void*(*alloc)(size_t),
+ const SkImageInfo&,
+ size_t rowBytes,
+ sk_sp<SkColorTable>);
+
+ void* fStorage;
+ sk_sp<SkColorTable> fCTable;
+ size_t fRB;
+ ReleaseProc fReleaseProc;
+ void* fReleaseProcContext;
+
+ SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, sk_sp<SkColorTable>,
ReleaseProc proc, void* context);
typedef SkPixelRef INHERITED;
diff --git a/public.bzl b/public.bzl
index 4373738738..ca9509119d 100644
--- a/public.bzl
+++ b/public.bzl
@@ -657,6 +657,7 @@ DEFINES_ALL = [
# Temporarily Disable analytic AA for Google3
"SK_NO_ANALYTIC_AA",
"SK_SUPPORT_LEGACY_BITMAP_SETPIXELREF",
+ "SK_SUPPORT_LEGACY_PIXELREFFACTORY",
]
################################################################################
diff --git a/samplecode/SampleBlur.cpp b/samplecode/SampleBlur.cpp
index 7e6a32562d..c43dc9bd43 100644
--- a/samplecode/SampleBlur.cpp
+++ b/samplecode/SampleBlur.cpp
@@ -4,6 +4,7 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
#include "SampleCode.h"
#include "SkBlurMask.h"
#include "SkBlurMaskFilter.h"
@@ -20,12 +21,9 @@ static SkBitmap make_bitmap() {
}
SkBitmap bm;
- SkColorTable* ctable = new SkColorTable(c, 256);
-
bm.allocPixels(SkImageInfo::Make(256, 256, kIndex_8_SkColorType,
kPremul_SkAlphaType),
- nullptr, ctable);
- ctable->unref();
+ SkColorTable::Make(c, 256));
bm.lockPixels();
const float cx = bm.width() * 0.5f;
diff --git a/samplecode/SampleDitherBitmap.cpp b/samplecode/SampleDitherBitmap.cpp
index 676d4c3530..bdd3071c0b 100644
--- a/samplecode/SampleDitherBitmap.cpp
+++ b/samplecode/SampleDitherBitmap.cpp
@@ -56,12 +56,9 @@ static SkBitmap make_bitmap() {
for (int i = 0; i < 256; i++) {
c[i] = SkPackARGB32(0xFF, i, 0, 0);
}
- SkColorTable* ctable = new SkColorTable(c, 256);
-
SkBitmap bm;
bm.allocPixels(SkImageInfo::Make(256, 32, kIndex_8_SkColorType, kPremul_SkAlphaType),
- nullptr, ctable);
- ctable->unref();
+ SkColorTable::Make(c, 256));
bm.lockPixels();
for (int y = 0; y < bm.height(); y++) {
diff --git a/samplecode/SampleFilter.cpp b/samplecode/SampleFilter.cpp
index 66de8f317f..d12f804d19 100644
--- a/samplecode/SampleFilter.cpp
+++ b/samplecode/SampleFilter.cpp
@@ -26,11 +26,9 @@ static void make_bm(SkBitmap* bm) {
SkPreMultiplyColor(SK_ColorRED), SkPreMultiplyColor(SK_ColorGREEN),
SkPreMultiplyColor(SK_ColorBLUE), SkPreMultiplyColor(SK_ColorWHITE)
};
- SkColorTable* ctable = new SkColorTable(colors, 4);
bm->allocPixels(SkImageInfo::Make(2, 2, kIndex_8_SkColorType,
kOpaque_SkAlphaType),
- nullptr, ctable);
- ctable->unref();
+ SkColorTable::Make(colors, 4));
*bm->getAddr8(0, 0) = 0;
*bm->getAddr8(1, 0) = 1;
diff --git a/samplecode/SampleTinyBitmap.cpp b/samplecode/SampleTinyBitmap.cpp
index 4fb508b898..6b01d11d5a 100644
--- a/samplecode/SampleTinyBitmap.cpp
+++ b/samplecode/SampleTinyBitmap.cpp
@@ -19,13 +19,11 @@ static SkBitmap make_bitmap() {
for (int i = 0; i < N; i++) {
c[i] = SkPackARGB32(0x80, 0x80, 0, 0);
}
- SkColorTable* ctable = new SkColorTable(c, N);
SkBitmap bm;
bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType,
kPremul_SkAlphaType),
- nullptr, ctable);
- ctable->unref();
+ SkColorTable::Make(c, N));
bm.lockPixels();
for (int y = 0; y < bm.height(); y++) {
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 0a999cee42..df3b24ed11 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -300,8 +300,7 @@ void SkBitmap::setPixels(void* p, SkColorTable* ctable) {
return;
}
- sk_sp<SkPixelRef> pr(SkMallocPixelRef::NewDirect(fInfo, p, fRowBytes, ctable));
- this->setPixelRef(std::move(pr), 0, 0);
+ this->setPixelRef(SkMallocPixelRef::MakeDirect(fInfo, p, fRowBytes, sk_ref_sp(ctable)), 0, 0);
if (!fPixelRef) {
return;
}
@@ -334,9 +333,7 @@ bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, size_t rowBytes)
// setInfo may have computed a valid rowbytes if 0 were passed in
rowBytes = this->rowBytes();
- SkMallocPixelRef::PRFactory defaultFactory;
-
- sk_sp<SkPixelRef> pr(defaultFactory.create(correctedInfo, rowBytes, nullptr));
+ sk_sp<SkPixelRef> pr = SkMallocPixelRef::MakeAllocate(correctedInfo, rowBytes, nullptr);
if (!pr) {
return reset_return_false(this);
}
@@ -350,8 +347,8 @@ bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, size_t rowBytes)
return true;
}
-bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactory* factory,
- SkColorTable* ctable) {
+bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, sk_sp<SkColorTable> ctable,
+ uint32_t allocFlags) {
if (kIndex_8_SkColorType == requestedInfo.colorType() && nullptr == ctable) {
return reset_return_false(this);
}
@@ -362,18 +359,14 @@ bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactor
// setInfo may have corrected info (e.g. 565 is always opaque).
const SkImageInfo& correctedInfo = this->info();
- SkMallocPixelRef::PRFactory defaultFactory;
- if (nullptr == factory) {
- factory = &defaultFactory;
- }
-
- sk_sp<SkPixelRef> pr(factory->create(correctedInfo, correctedInfo.minRowBytes(), ctable));
+ sk_sp<SkPixelRef> pr = (allocFlags & kZeroPixels_AllocFlag) ?
+ SkMallocPixelRef::MakeZeroed(correctedInfo, correctedInfo.minRowBytes(), ctable) :
+ SkMallocPixelRef::MakeAllocate(correctedInfo, correctedInfo.minRowBytes(), ctable);
if (!pr) {
return reset_return_false(this);
}
this->setPixelRef(std::move(pr), 0, 0);
- // TODO: lockPixels could/should return bool or void*/nullptr
this->lockPixels();
if (nullptr == this->getPixels()) {
return reset_return_false(this);
@@ -403,8 +396,8 @@ bool SkBitmap::installPixels(const SkImageInfo& requestedInfo, void* pixels, siz
// setInfo may have corrected info (e.g. 565 is always opaque).
const SkImageInfo& correctedInfo = this->info();
- sk_sp<SkPixelRef> pr(SkMallocPixelRef::NewWithProc(correctedInfo, rb, ct, pixels, releaseProc,
- context));
+ sk_sp<SkPixelRef> pr = SkMallocPixelRef::MakeWithProc(correctedInfo, rb, sk_ref_sp(ct),
+ pixels, releaseProc, context);
if (!pr) {
this->reset();
return false;
@@ -473,7 +466,7 @@ bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst,
return false;
}
- sk_sp<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, dst->rowBytes(), ctable));
+ sk_sp<SkPixelRef> pr = SkMallocPixelRef::MakeAllocate(info, dst->rowBytes(), sk_ref_sp(ctable));
if (!pr) {
return false;
}
@@ -1014,7 +1007,7 @@ bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) {
sk_sp<SkColorTable> ctable;
if (buffer->readBool()) {
- ctable.reset(SkColorTable::Create(*buffer));
+ ctable = SkColorTable::Create(*buffer);
if (!ctable) {
return false;
}
@@ -1038,9 +1031,9 @@ bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) {
}
}
- sk_sp<SkPixelRef> pr(SkMallocPixelRef::NewWithData(info, info.minRowBytes(),
- ctable.get(), data.get()));
- if (!pr.get()) {
+ sk_sp<SkPixelRef> pr = SkMallocPixelRef::MakeWithData(info, info.minRowBytes(),
+ std::move(ctable), std::move(data));
+ if (!pr) {
return false;
}
bitmap->setInfo(pr->info());
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 3be63ba66b..95ea45c29d 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -121,9 +121,8 @@ SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo,
}
} else {
// This bitmap has transparency, so we'll zero the pixels (to transparent).
- // We use a ZeroedPRFactory as a faster alloc-then-eraseColor(SK_ColorTRANSPARENT).
- SkMallocPixelRef::ZeroedPRFactory factory;
- if (!bitmap.tryAllocPixels(info, &factory, nullptr/*color table*/)) {
+ // We use the flag as a faster alloc-then-eraseColor(SK_ColorTRANSPARENT).
+ if (!bitmap.tryAllocPixels(info, nullptr/*colortable*/, SkBitmap::kZeroPixels_AllocFlag)) {
return nullptr;
}
}
diff --git a/src/core/SkColorTable.cpp b/src/core/SkColorTable.cpp
index 97103463db..928f5158d4 100644
--- a/src/core/SkColorTable.cpp
+++ b/src/core/SkColorTable.cpp
@@ -23,11 +23,7 @@ void SkColorTable::init(const SkPMColor colors[], int count) {
SkColorTable::SkColorTable(const SkPMColor colors[], int count) {
SkASSERT(0 == count || colors);
- if (count < 0) {
- count = 0;
- } else if (count > 256) {
- count = 256;
- }
+ SkASSERT(count >= 0 && count <= 256);
this->init(colors, count);
}
@@ -56,6 +52,16 @@ const uint16_t* SkColorTable::read16BitCache() const {
return f16BitCache;
}
+sk_sp<SkColorTable> SkColorTable::Make(const SkPMColor colors[], int count) {
+ if (count < 0 || count > 256) {
+ return nullptr;
+ }
+ if (count && !colors) {
+ return nullptr;
+ }
+ return sk_make_sp<SkColorTable>(colors, count);
+}
+
///////////////////////////////////////////////////////////////////////////////
#if 0
@@ -85,14 +91,14 @@ void SkColorTable::writeToBuffer(SkWriteBuffer& buffer) const {
buffer.writeColorArray(fColors, fCount);
}
-SkColorTable* SkColorTable::Create(SkReadBuffer& buffer) {
+sk_sp<SkColorTable> SkColorTable::Create(SkReadBuffer& buffer) {
if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) {
/*fAlphaType = */buffer.readUInt();
}
const int count = buffer.getArrayCount();
if (0 == count) {
- return new SkColorTable(nullptr, 0);
+ return sk_sp<SkColorTable>(new SkColorTable(nullptr, 0));
}
if (count < 0 || count > 256) {
@@ -106,5 +112,5 @@ SkColorTable* SkColorTable::Create(SkReadBuffer& buffer) {
return nullptr;
}
- return new SkColorTable(colors.release(), count, kAllocatedWithMalloc);
+ return sk_sp<SkColorTable>(new SkColorTable(colors.release(), count, kAllocatedWithMalloc));
}
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp
index 1a37f3b217..98a813ffd9 100644
--- a/src/core/SkImageCacherator.cpp
+++ b/src/core/SkImageCacherator.cpp
@@ -157,7 +157,7 @@ bool SkImageCacherator::generateBitmap(SkBitmap* bitmap, const SkImageInfo& deco
allocator)) {
return false;
}
- if (!bitmap->tryAllocPixels(decodeInfo, nullptr, full.getColorTable())) {
+ if (!bitmap->tryAllocPixels(decodeInfo, sk_ref_sp(full.getColorTable()))) {
return false;
}
return full.readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(),
diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp
index 0d758fcb3d..e42a15db21 100644
--- a/src/core/SkMallocPixelRef.cpp
+++ b/src/core/SkMallocPixelRef.cpp
@@ -37,22 +37,23 @@ static bool is_valid(const SkImageInfo& info, SkColorTable* ctable) {
return true;
}
-SkMallocPixelRef* SkMallocPixelRef::NewDirect(const SkImageInfo& info,
- void* addr,
- size_t rowBytes,
- SkColorTable* ctable) {
- if (!is_valid(info, ctable)) {
+sk_sp<SkPixelRef> SkMallocPixelRef::MakeDirect(const SkImageInfo& info,
+ void* addr,
+ size_t rowBytes,
+ sk_sp<SkColorTable> ctable) {
+ if (!is_valid(info, ctable.get())) {
return nullptr;
}
- return new SkMallocPixelRef(info, addr, rowBytes, ctable, nullptr, nullptr);
+ return sk_sp<SkPixelRef>(new SkMallocPixelRef(info, addr, rowBytes, std::move(ctable),
+ nullptr, nullptr));
}
- SkMallocPixelRef* SkMallocPixelRef::NewUsing(void*(*alloc)(size_t),
- const SkImageInfo& info,
- size_t requestedRowBytes,
- SkColorTable* ctable) {
- if (!is_valid(info, ctable)) {
+ 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())) {
return nullptr;
}
@@ -84,62 +85,61 @@ SkMallocPixelRef* SkMallocPixelRef::NewDirect(const SkImageInfo& info,
return nullptr;
}
- return new SkMallocPixelRef(info, addr, rowBytes, ctable, sk_free_releaseproc, nullptr);
+ return sk_sp<SkPixelRef>(new SkMallocPixelRef(info, addr, rowBytes, std::move(ctable),
+ sk_free_releaseproc, nullptr));
}
-SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info,
+sk_sp<SkPixelRef> SkMallocPixelRef::MakeAllocate(const SkImageInfo& info,
size_t rowBytes,
- SkColorTable* ctable) {
+ sk_sp<SkColorTable> ctable) {
auto sk_malloc_nothrow = [](size_t size) { return sk_malloc_flags(size, 0); };
- return NewUsing(sk_malloc_nothrow, info, rowBytes, ctable);
+ return MakeUsing(sk_malloc_nothrow, info, rowBytes, std::move(ctable));
}
-SkMallocPixelRef* SkMallocPixelRef::NewZeroed(const SkImageInfo& info,
- size_t rowBytes,
- SkColorTable* ctable) {
- return NewUsing(sk_calloc, 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::NewWithProc(const SkImageInfo& info,
- size_t rowBytes,
- SkColorTable* ctable,
- void* addr,
- SkMallocPixelRef::ReleaseProc proc,
- void* context) {
- if (!is_valid(info, 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())) {
if (proc) {
proc(addr, context);
}
return nullptr;
}
- return new SkMallocPixelRef(info, addr, rowBytes, ctable, proc, context);
+ return sk_sp<SkPixelRef>(new SkMallocPixelRef(info, addr, rowBytes, std::move(ctable),
+ proc, context));
}
-static void sk_data_releaseproc(void*, void* dataPtr) {
- (static_cast<SkData*>(dataPtr))->unref();
-}
-
-SkMallocPixelRef* SkMallocPixelRef::NewWithData(const SkImageInfo& info,
+sk_sp<SkPixelRef> SkMallocPixelRef::MakeWithData(const SkImageInfo& info,
size_t rowBytes,
- SkColorTable* ctable,
- SkData* data) {
+ sk_sp<SkColorTable> ctable,
+ sk_sp<SkData> data) {
SkASSERT(data != nullptr);
- if (!is_valid(info, ctable)) {
+ if (!is_valid(info, ctable.get())) {
return nullptr;
}
if ((rowBytes < info.minRowBytes())
|| (data->size() < info.getSafeSize(rowBytes))) {
return nullptr;
}
- 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;
+ // must get this address before we call release
+ void* pixels = const_cast<void*>(data->data());
+ SkPixelRef* pr = new SkMallocPixelRef(info, pixels, rowBytes, std::move(ctable),
+ sk_data_releaseproc, data.release());
+ pr->setImmutable(); // since we were created with (immutable) data
+ return sk_sp<SkPixelRef>(pr);
}
///////////////////////////////////////////////////////////////////////////////
@@ -148,50 +148,47 @@ 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, ctable));
+ SkASSERT(is_valid(info, fCTable.get()));
SkASSERT(rowBytes >= info.minRowBytes());
if (kIndex_8_SkColorType != info.colorType()) {
- ctable = nullptr;
+ fCTable = nullptr;
}
fStorage = storage;
- fCTable = ctable;
fRB = rowBytes;
- SkSafeRef(ctable);
- this->setPreLocked(fStorage, rowBytes, fCTable);
+ this->setPreLocked(fStorage, rowBytes, fCTable.get());
}
SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage,
- size_t rowBytes, SkColorTable* ctable,
+ size_t rowBytes, sk_sp<SkColorTable> ctable,
SkMallocPixelRef::ReleaseProc proc,
void* context)
: INHERITED(info)
, fReleaseProc(proc)
, fReleaseProcContext(context)
{
- SkASSERT(is_valid(info, ctable));
+ SkASSERT(is_valid(info, ctable.get()));
SkASSERT(rowBytes >= info.minRowBytes());
if (kIndex_8_SkColorType != info.colorType()) {
- ctable = nullptr;
+ ctable.reset(nullptr);
}
fStorage = storage;
- fCTable = ctable;
+ fCTable = std::move(ctable);
fRB = rowBytes;
- SkSafeRef(ctable);
- this->setPreLocked(fStorage, rowBytes, fCTable);
+ this->setPreLocked(fStorage, rowBytes, fCTable.get());
}
SkMallocPixelRef::~SkMallocPixelRef() {
- SkSafeUnref(fCTable);
if (fReleaseProc != nullptr) {
fReleaseProc(fStorage, fReleaseProcContext);
}
@@ -200,7 +197,7 @@ SkMallocPixelRef::~SkMallocPixelRef() {
bool SkMallocPixelRef::onNewLockPixels(LockRec* rec) {
rec->fPixels = fStorage;
rec->fRowBytes = fRB;
- rec->fColorTable = fCTable;
+ rec->fColorTable = fCTable.get();
return true;
}
@@ -212,14 +209,11 @@ size_t SkMallocPixelRef::getAllocatedSizeInBytes() const {
return this->info().getSafeSize(fRB);
}
-///////////////////////////////////////////////////////////////////////////////
-
-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);
+#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();
}
+#endif
diff --git a/src/core/SkSpecialSurface.cpp b/src/core/SkSpecialSurface.cpp
index 1f396a7ac2..40afb57cec 100644
--- a/src/core/SkSpecialSurface.cpp
+++ b/src/core/SkSpecialSurface.cpp
@@ -98,8 +98,8 @@ sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromBitmap(const SkIRect& subset,
sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRaster(const SkImageInfo& info,
const SkSurfaceProps* props) {
- sk_sp<SkPixelRef> pr(SkMallocPixelRef::NewZeroed(info, 0, nullptr));
- if (nullptr == pr.get()) {
+ sk_sp<SkPixelRef> pr = SkMallocPixelRef::MakeZeroed(info, 0, nullptr);
+ if (!pr) {
return nullptr;
}
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index 0840d7c55e..be60dee15e 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -10,6 +10,7 @@
#include "SkGradientShaderPriv.h"
#include "SkHalf.h"
#include "SkLinearGradient.h"
+#include "SkMallocPixelRef.h"
#include "SkRadialGradient.h"
#include "SkTwoPointConicalGradient.h"
#include "SkSweepGradient.h"
@@ -410,12 +411,9 @@ SkGradientShaderBase::GradientShaderCache::GradientShaderCache(
{
// Only initialize the cache in getCache32.
fCache32 = nullptr;
- fCache32PixelRef = nullptr;
}
-SkGradientShaderBase::GradientShaderCache::~GradientShaderCache() {
- SkSafeUnref(fCache32PixelRef);
-}
+SkGradientShaderBase::GradientShaderCache::~GradientShaderCache() {}
/*
* r,g,b used to be SkFixed, but on gcc (4.2.1 mac and 4.6.3 goobuntu) in
@@ -584,8 +582,8 @@ void SkGradientShaderBase::GradientShaderCache::initCache32(GradientShaderCache*
const SkImageInfo info = SkImageInfo::MakeN32Premul(kCache32Count, kNumberOfDitherRows);
SkASSERT(nullptr == cache->fCache32PixelRef);
- cache->fCache32PixelRef = SkMallocPixelRef::NewAllocate(info, 0, nullptr);
- cache->fCache32 = (SkPMColor*)cache->fCache32PixelRef->getAddr();
+ cache->fCache32PixelRef = SkMallocPixelRef::MakeAllocate(info, 0, nullptr);
+ cache->fCache32 = (SkPMColor*)cache->fCache32PixelRef->pixels();
if (cache->fShader.fColorCount == 2) {
Build32bitCache(cache->fCache32, cache->fShader.fOrigColors[0],
cache->fShader.fOrigColors[1], kCache32Count, cache->fCacheAlpha,
diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h
index f64b4396c2..ec75bdc05a 100644
--- a/src/effects/gradients/SkGradientShaderPriv.h
+++ b/src/effects/gradients/SkGradientShaderPriv.h
@@ -16,7 +16,6 @@
#include "SkClampRange.h"
#include "SkColorPriv.h"
#include "SkColorSpace.h"
-#include "SkMallocPixelRef.h"
#include "SkOnce.h"
#include "SkReadBuffer.h"
#include "SkShader.h"
@@ -129,7 +128,7 @@ public:
const SkPMColor* getCache32();
- SkMallocPixelRef* getCache32PixelRef() const { return fCache32PixelRef; }
+ SkPixelRef* getCache32PixelRef() const { return fCache32PixelRef.get(); }
unsigned getAlpha() const { return fCacheAlpha; }
bool getDither() const { return fCacheDither; }
@@ -138,7 +137,7 @@ public:
// Working pointer. If it's nullptr, we need to recompute the cache values.
SkPMColor* fCache32;
- SkMallocPixelRef* fCache32PixelRef;
+ sk_sp<SkPixelRef> fCache32PixelRef;
const unsigned fCacheAlpha; // The alpha value we used when we computed the cache.
// Larger than 8bits so we can store uninitialized
// value.
diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp
index 4fae0f03c0..92f5301061 100644
--- a/src/image/SkSurface_Raster.cpp
+++ b/src/image/SkSurface_Raster.cpp
@@ -209,7 +209,7 @@ sk_sp<SkSurface> SkSurface::MakeRaster(const SkImageInfo& info, size_t rowBytes,
return nullptr;
}
- sk_sp<SkPixelRef> pr(SkMallocPixelRef::NewZeroed(info, rowBytes, nullptr));
+ sk_sp<SkPixelRef> pr = SkMallocPixelRef::MakeZeroed(info, rowBytes, nullptr);
if (!pr) {
return nullptr;
}
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 3a7a192839..9916ed3e08 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;
}
diff --git a/tools/Resources.cpp b/tools/Resources.cpp
index d7f90189a6..224bf3f66e 100644
--- a/tools/Resources.cpp
+++ b/tools/Resources.cpp
@@ -34,9 +34,10 @@ bool GetResourceAsBitmap(const char* resource, SkBitmap* dst) {
return false;
}
SkPMColor ctStorage[256];
- sk_sp<SkColorTable> ctable(new SkColorTable(ctStorage, 256));
+ auto ctable = SkColorTable::Make(ctStorage, 256);
int count = ctable->count();
- return dst->tryAllocPixels(gen->getInfo(), nullptr, ctable.get()) &&
+ // ICK -- gotta clean up this pattern of writing to the ctable
+ return dst->tryAllocPixels(gen->getInfo(), ctable) &&
gen->getPixels(gen->getInfo().makeColorSpace(nullptr), dst->getPixels(), dst->rowBytes(),
const_cast<SkPMColor*>(ctable->readColors()), &count);
}