Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Unified Diff: tests/ImageTest.cpp

Issue 2206633004: Move off SK_SUPPORT_LEGACY_DATA_FACTORIES. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Gotta catch 'em all. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/ImageTest.cpp
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 72dc9432e39981df1fd394fd576a433cc0b75d6c..4f77fbdf1e99b950e49ca0fea813393abe3a5a3e 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -73,22 +73,22 @@ static sk_sp<SkImage> create_image() {
draw_image_test_pattern(surface->getCanvas());
return surface->makeImageSnapshot();
}
-static SkData* create_image_data(SkImageInfo* info) {
+static sk_sp<SkData> create_image_data(SkImageInfo* info) {
*info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType);
const size_t rowBytes = info->minRowBytes();
- SkAutoTUnref<SkData> data(SkData::NewUninitialized(rowBytes * info->height()));
+ sk_sp<SkData> data(SkData::MakeUninitialized(rowBytes * info->height()));
{
SkBitmap bm;
bm.installPixels(*info, data->writable_data(), rowBytes);
SkCanvas canvas(bm);
draw_image_test_pattern(&canvas);
}
- return data.release();
+ return data;
}
static sk_sp<SkImage> create_data_image() {
SkImageInfo info;
sk_sp<SkData> data(create_image_data(&info));
- return SkImage::MakeRasterData(info, data, info.minRowBytes());
+ return SkImage::MakeRasterData(info, std::move(data), info.minRowBytes());
}
#if SK_SUPPORT_GPU // not gpu-specific but currently only used in GPU tests
static sk_sp<SkImage> create_image_565() {
@@ -134,7 +134,7 @@ static sk_sp<SkImage> create_picture_image() {
// Want to ensure that our Release is called when the owning image is destroyed
struct RasterDataHolder {
RasterDataHolder() : fReleaseCount(0) {}
- SkAutoTUnref<SkData> fData;
+ sk_sp<SkData> fData;
int fReleaseCount;
static void Release(const void* pixels, void* context) {
RasterDataHolder* self = static_cast<RasterDataHolder*>(context);
@@ -145,19 +145,17 @@ struct RasterDataHolder {
static sk_sp<SkImage> create_rasterproc_image(RasterDataHolder* dataHolder) {
SkASSERT(dataHolder);
SkImageInfo info;
- SkAutoTUnref<SkData> data(create_image_data(&info));
- dataHolder->fData.reset(SkRef(data.get()));
- return SkImage::MakeFromRaster(SkPixmap(info, data->data(), info.minRowBytes()),
+ dataHolder->fData = create_image_data(&info);
+ return SkImage::MakeFromRaster(SkPixmap(info, dataHolder->fData->data(), info.minRowBytes()),
RasterDataHolder::Release, dataHolder);
}
static sk_sp<SkImage> create_codec_image() {
SkImageInfo info;
- SkAutoTUnref<SkData> data(create_image_data(&info));
+ sk_sp<SkData> data(create_image_data(&info));
SkBitmap bitmap;
bitmap.installPixels(info, data->writable_data(), info.minRowBytes());
- sk_sp<SkData> src(
- SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 100));
- return SkImage::MakeFromEncoded(src);
+ sk_sp<SkData> src(SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 100));
+ return SkImage::MakeFromEncoded(std::move(src));
}
#if SK_SUPPORT_GPU
static sk_sp<SkImage> create_gpu_image(GrContext* context) {
@@ -231,7 +229,7 @@ const char* kSerializedData = "serialized";
class MockSerializer : public SkPixelSerializer {
public:
- MockSerializer(SkData* (*func)()) : fFunc(func), fDidEncode(false) { }
+ MockSerializer(sk_sp<SkData> (*func)()) : fFunc(func), fDidEncode(false) { }
bool didEncode() const { return fDidEncode; }
@@ -242,11 +240,11 @@ protected:
SkData* onEncode(const SkPixmap&) override {
fDidEncode = true;
- return fFunc();
+ return fFunc().release();
}
private:
- SkData* (*fFunc)();
+ sk_sp<SkData> (*fFunc)();
bool fDidEncode;
typedef SkPixelSerializer INHERITED;
@@ -256,15 +254,17 @@ private:
// Test that SkImage encoding observes custom pixel serializers.
DEF_TEST(Image_Encode_Serializer, reporter) {
- MockSerializer serializer([]() -> SkData* { return SkData::NewWithCString(kSerializedData); });
+ MockSerializer serializer([]() -> sk_sp<SkData> {
+ return SkData::MakeWithCString(kSerializedData);
+ });
sk_sp<SkImage> image(create_image());
- SkAutoTUnref<SkData> encoded(image->encode(&serializer));
- SkAutoTUnref<SkData> reference(SkData::NewWithCString(kSerializedData));
+ sk_sp<SkData> encoded(image->encode(&serializer));
+ sk_sp<SkData> reference(SkData::MakeWithCString(kSerializedData));
REPORTER_ASSERT(reporter, serializer.didEncode());
REPORTER_ASSERT(reporter, encoded);
REPORTER_ASSERT(reporter, encoded->size() > 0);
- REPORTER_ASSERT(reporter, encoded->equals(reference));
+ REPORTER_ASSERT(reporter, encoded->equals(reference.get()));
}
// Test that image encoding failures do not break picture serialization/deserialization.
@@ -281,8 +281,8 @@ DEF_TEST(Image_Serialize_Encoding_Failure, reporter) {
REPORTER_ASSERT(reporter, picture);
REPORTER_ASSERT(reporter, picture->approximateOpCount() > 0);
- MockSerializer emptySerializer([]() -> SkData* { return SkData::NewEmpty(); });
- MockSerializer nullSerializer([]() -> SkData* { return nullptr; });
+ MockSerializer emptySerializer([]() -> sk_sp<SkData> { return SkData::MakeEmpty(); });
+ MockSerializer nullSerializer([]() -> sk_sp<SkData> { return nullptr; });
MockSerializer* serializers[] = { &emptySerializer, &nullSerializer };
for (size_t i = 0; i < SK_ARRAY_COUNT(serializers); ++i) {

Powered by Google App Engine
This is Rietveld 408576698