OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include <functional> | 8 #include <functional> |
9 #include <initializer_list> | 9 #include <initializer_list> |
10 #include "DMGpuSupport.h" | 10 #include "DMGpuSupport.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 static sk_sp<SkImage> create_data_image() { | 104 static sk_sp<SkImage> create_data_image() { |
105 SkImageInfo info; | 105 SkImageInfo info; |
106 sk_sp<SkData> data(create_image_data(&info)); | 106 sk_sp<SkData> data(create_image_data(&info)); |
107 return SkImage::MakeRasterData(info, data, info.minRowBytes()); | 107 return SkImage::MakeRasterData(info, data, info.minRowBytes()); |
108 } | 108 } |
109 #if SK_SUPPORT_GPU // not gpu-specific but currently only used in GPU tests | 109 #if SK_SUPPORT_GPU // not gpu-specific but currently only used in GPU tests |
110 static sk_sp<SkImage> create_picture_image() { | 110 static sk_sp<SkImage> create_picture_image() { |
111 SkPictureRecorder recorder; | 111 SkPictureRecorder recorder; |
112 SkCanvas* canvas = recorder.beginRecording(10, 10); | 112 SkCanvas* canvas = recorder.beginRecording(10, 10); |
113 canvas->clear(SK_ColorCYAN); | 113 canvas->clear(SK_ColorCYAN); |
114 sk_sp<SkPicture> picture(recorder.endRecording()); | 114 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), SkISize
::Make(10, 10), |
115 return SkImage::MakeFromPicture(picture, SkISize::Make(10, 10), nullptr, nul
lptr); | 115 nullptr, nullptr); |
116 }; | 116 }; |
117 #endif | 117 #endif |
118 // Want to ensure that our Release is called when the owning image is destroyed | 118 // Want to ensure that our Release is called when the owning image is destroyed |
119 struct RasterDataHolder { | 119 struct RasterDataHolder { |
120 RasterDataHolder() : fReleaseCount(0) {} | 120 RasterDataHolder() : fReleaseCount(0) {} |
121 SkAutoTUnref<SkData> fData; | 121 SkAutoTUnref<SkData> fData; |
122 int fReleaseCount; | 122 int fReleaseCount; |
123 static void Release(const void* pixels, void* context) { | 123 static void Release(const void* pixels, void* context) { |
124 RasterDataHolder* self = static_cast<RasterDataHolder*>(context); | 124 RasterDataHolder* self = static_cast<RasterDataHolder*>(context); |
125 self->fReleaseCount++; | 125 self->fReleaseCount++; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // Test that image encoding failures do not break picture serialization/deserial
ization. | 225 // Test that image encoding failures do not break picture serialization/deserial
ization. |
226 DEF_TEST(Image_Serialize_Encoding_Failure, reporter) { | 226 DEF_TEST(Image_Serialize_Encoding_Failure, reporter) { |
227 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100)); | 227 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100)); |
228 surface->getCanvas()->clear(SK_ColorGREEN); | 228 surface->getCanvas()->clear(SK_ColorGREEN); |
229 sk_sp<SkImage> image(surface->makeImageSnapshot()); | 229 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
230 REPORTER_ASSERT(reporter, image); | 230 REPORTER_ASSERT(reporter, image); |
231 | 231 |
232 SkPictureRecorder recorder; | 232 SkPictureRecorder recorder; |
233 SkCanvas* canvas = recorder.beginRecording(100, 100); | 233 SkCanvas* canvas = recorder.beginRecording(100, 100); |
234 canvas->drawImage(image, 0, 0); | 234 canvas->drawImage(image, 0, 0); |
235 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 235 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
236 REPORTER_ASSERT(reporter, picture); | 236 REPORTER_ASSERT(reporter, picture); |
237 REPORTER_ASSERT(reporter, picture->approximateOpCount() > 0); | 237 REPORTER_ASSERT(reporter, picture->approximateOpCount() > 0); |
238 | 238 |
239 MockSerializer emptySerializer([]() -> SkData* { return SkData::NewEmpty();
}); | 239 MockSerializer emptySerializer([]() -> SkData* { return SkData::NewEmpty();
}); |
240 MockSerializer nullSerializer([]() -> SkData* { return nullptr; }); | 240 MockSerializer nullSerializer([]() -> SkData* { return nullptr; }); |
241 MockSerializer* serializers[] = { &emptySerializer, &nullSerializer }; | 241 MockSerializer* serializers[] = { &emptySerializer, &nullSerializer }; |
242 | 242 |
243 for (size_t i = 0; i < SK_ARRAY_COUNT(serializers); ++i) { | 243 for (size_t i = 0; i < SK_ARRAY_COUNT(serializers); ++i) { |
244 SkDynamicMemoryWStream wstream; | 244 SkDynamicMemoryWStream wstream; |
245 REPORTER_ASSERT(reporter, !serializers[i]->didEncode()); | 245 REPORTER_ASSERT(reporter, !serializers[i]->didEncode()); |
246 picture->serialize(&wstream, serializers[i]); | 246 picture->serialize(&wstream, serializers[i]); |
247 REPORTER_ASSERT(reporter, serializers[i]->didEncode()); | 247 REPORTER_ASSERT(reporter, serializers[i]->didEncode()); |
248 | 248 |
249 SkAutoTDelete<SkStream> rstream(wstream.detachAsStream()); | 249 SkAutoTDelete<SkStream> rstream(wstream.detachAsStream()); |
250 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rstream
)); | 250 sk_sp<SkPicture> deserialized(SkPicture::MakeFromStream(rstream)); |
251 REPORTER_ASSERT(reporter, deserialized); | 251 REPORTER_ASSERT(reporter, deserialized); |
252 REPORTER_ASSERT(reporter, deserialized->approximateOpCount() > 0); | 252 REPORTER_ASSERT(reporter, deserialized->approximateOpCount() > 0); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 DEF_TEST(Image_NewRasterCopy, reporter) { | 256 DEF_TEST(Image_NewRasterCopy, reporter) { |
257 const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0); | 257 const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0); |
258 const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); | 258 const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); |
259 const SkPMColor blue = SkPackARGB32(0xFF, 0, 0, 0xFF); | 259 const SkPMColor blue = SkPackARGB32(0xFF, 0, 0, 0xFF); |
260 SkPMColor colors[] = { red, green, blue, 0 }; | 260 SkPMColor colors[] = { red, green, blue, 0 }; |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 otherContextInfo.fGrContext, buffer, budgeted)); | 884 otherContextInfo.fGrContext, buffer, budgeted)); |
885 REPORTER_ASSERT(reporter, !newImage2); | 885 REPORTER_ASSERT(reporter, !newImage2); |
886 glContext->makeCurrent(); | 886 glContext->makeCurrent(); |
887 } | 887 } |
888 } | 888 } |
889 sk_free(buffer); | 889 sk_free(buffer); |
890 } | 890 } |
891 } | 891 } |
892 } | 892 } |
893 #endif | 893 #endif |
OLD | NEW |