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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 for (int y = 0; y < heightA; ++y) { | 53 for (int y = 0; y < heightA; ++y) { |
54 REPORTER_ASSERT(reporter, !memcmp(pmapA.addr32(0, y), pmapB.addr32(0, y)
, widthBytes)); | 54 REPORTER_ASSERT(reporter, !memcmp(pmapA.addr32(0, y), pmapB.addr32(0, y)
, widthBytes)); |
55 } | 55 } |
56 } | 56 } |
57 static void draw_image_test_pattern(SkCanvas* canvas) { | 57 static void draw_image_test_pattern(SkCanvas* canvas) { |
58 canvas->clear(SK_ColorWHITE); | 58 canvas->clear(SK_ColorWHITE); |
59 SkPaint paint; | 59 SkPaint paint; |
60 paint.setColor(SK_ColorBLACK); | 60 paint.setColor(SK_ColorBLACK); |
61 canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint); | 61 canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint); |
62 } | 62 } |
63 static SkImage* create_image() { | 63 static sk_sp<SkImage> create_image() { |
64 const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); | 64 const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); |
65 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | 65 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
66 draw_image_test_pattern(surface->getCanvas()); | 66 draw_image_test_pattern(surface->getCanvas()); |
67 return surface->newImageSnapshot(); | 67 return surface->makeImageSnapshot(); |
68 } | 68 } |
69 static SkImage* create_image_565() { | 69 static sk_sp<SkImage> create_image_565() { |
70 const SkImageInfo info = SkImageInfo::Make(20, 20, kRGB_565_SkColorType, kOp
aque_SkAlphaType); | 70 const SkImageInfo info = SkImageInfo::Make(20, 20, kRGB_565_SkColorType, kOp
aque_SkAlphaType); |
71 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | 71 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
72 draw_image_test_pattern(surface->getCanvas()); | 72 draw_image_test_pattern(surface->getCanvas()); |
73 return surface->newImageSnapshot(); | 73 return surface->makeImageSnapshot(); |
74 } | 74 } |
75 static SkImage* create_image_ct() { | 75 static sk_sp<SkImage> create_image_ct() { |
76 SkPMColor colors[] = { | 76 SkPMColor colors[] = { |
77 SkPreMultiplyARGB(0xFF, 0xFF, 0xFF, 0x00), | 77 SkPreMultiplyARGB(0xFF, 0xFF, 0xFF, 0x00), |
78 SkPreMultiplyARGB(0x80, 0x00, 0xA0, 0xFF), | 78 SkPreMultiplyARGB(0x80, 0x00, 0xA0, 0xFF), |
79 SkPreMultiplyARGB(0xFF, 0xBB, 0x00, 0xBB) | 79 SkPreMultiplyARGB(0xFF, 0xBB, 0x00, 0xBB) |
80 }; | 80 }; |
81 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, SK_ARRAY_COUN
T(colors))); | 81 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, SK_ARRAY_COUN
T(colors))); |
82 uint8_t data[] = { | 82 uint8_t data[] = { |
83 0, 0, 0, 0, 0, | 83 0, 0, 0, 0, 0, |
84 0, 1, 1, 1, 0, | 84 0, 1, 1, 1, 0, |
85 0, 1, 2, 1, 0, | 85 0, 1, 2, 1, 0, |
86 0, 1, 1, 1, 0, | 86 0, 1, 1, 1, 0, |
87 0, 0, 0, 0, 0 | 87 0, 0, 0, 0, 0 |
88 }; | 88 }; |
89 SkImageInfo info = SkImageInfo::Make(5, 5, kIndex_8_SkColorType, kPremul_SkA
lphaType); | 89 SkImageInfo info = SkImageInfo::Make(5, 5, kIndex_8_SkColorType, kPremul_SkA
lphaType); |
90 return SkImage::NewRasterCopy(info, data, 5, colorTable); | 90 return SkImage::MakeRasterCopy(SkPixmap(info, data, 5, colorTable)); |
91 } | 91 } |
92 static SkData* create_image_data(SkImageInfo* info) { | 92 static SkData* create_image_data(SkImageInfo* info) { |
93 *info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); | 93 *info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); |
94 const size_t rowBytes = info->minRowBytes(); | 94 const size_t rowBytes = info->minRowBytes(); |
95 SkAutoTUnref<SkData> data(SkData::NewUninitialized(rowBytes * info->height()
)); | 95 SkAutoTUnref<SkData> data(SkData::NewUninitialized(rowBytes * info->height()
)); |
96 { | 96 { |
97 SkBitmap bm; | 97 SkBitmap bm; |
98 bm.installPixels(*info, data->writable_data(), rowBytes); | 98 bm.installPixels(*info, data->writable_data(), rowBytes); |
99 SkCanvas canvas(bm); | 99 SkCanvas canvas(bm); |
100 draw_image_test_pattern(&canvas); | 100 draw_image_test_pattern(&canvas); |
101 } | 101 } |
102 return data.release(); | 102 return data.release(); |
103 } | 103 } |
104 static SkImage* create_data_image() { | 104 static sk_sp<SkImage> create_data_image() { |
105 SkImageInfo info; | 105 SkImageInfo info; |
106 SkAutoTUnref<SkData> data(create_image_data(&info)); | 106 sk_sp<SkData> data(create_image_data(&info)); |
107 return SkImage::NewRasterData(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 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 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 114 sk_sp<SkPicture> picture(recorder.endRecording()); |
115 return SkImage::NewFromPicture(picture, SkISize::Make(10, 10), nullptr, null
ptr); | 115 return SkImage::MakeFromPicture(picture, SkISize::Make(10, 10), nullptr, nul
lptr); |
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++; |
126 self->fData.reset(); | 126 self->fData.reset(); |
127 } | 127 } |
128 }; | 128 }; |
129 static SkImage* create_rasterproc_image(RasterDataHolder* dataHolder) { | 129 static sk_sp<SkImage> create_rasterproc_image(RasterDataHolder* dataHolder) { |
130 SkASSERT(dataHolder); | 130 SkASSERT(dataHolder); |
131 SkImageInfo info; | 131 SkImageInfo info; |
132 SkAutoTUnref<SkData> data(create_image_data(&info)); | 132 SkAutoTUnref<SkData> data(create_image_data(&info)); |
133 dataHolder->fData.reset(SkRef(data.get())); | 133 dataHolder->fData.reset(SkRef(data.get())); |
134 return SkImage::NewFromRaster(info, data->data(), info.minRowBytes(), | 134 return SkImage::MakeFromRaster(SkPixmap(info, data->data(), info.minRowBytes
()), |
135 RasterDataHolder::Release, dataHolder); | 135 RasterDataHolder::Release, dataHolder); |
136 } | 136 } |
137 static SkImage* create_codec_image() { | 137 static sk_sp<SkImage> create_codec_image() { |
138 SkImageInfo info; | 138 SkImageInfo info; |
139 SkAutoTUnref<SkData> data(create_image_data(&info)); | 139 SkAutoTUnref<SkData> data(create_image_data(&info)); |
140 SkBitmap bitmap; | 140 SkBitmap bitmap; |
141 bitmap.installPixels(info, data->writable_data(), info.minRowBytes()); | 141 bitmap.installPixels(info, data->writable_data(), info.minRowBytes()); |
142 SkAutoTUnref<SkData> src( | 142 sk_sp<SkData> src( |
143 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 100)); | 143 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 100)); |
144 return SkImage::NewFromEncoded(src); | 144 return SkImage::MakeFromEncoded(src); |
145 } | 145 } |
146 #if SK_SUPPORT_GPU | 146 #if SK_SUPPORT_GPU |
147 static SkImage* create_gpu_image(GrContext* context) { | 147 static sk_sp<SkImage> create_gpu_image(GrContext* context) { |
148 const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); | 148 const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); |
149 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, SkBudget
ed::kNo, | 149 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, SkBudget
ed::kNo, |
150 info)); | 150 info)); |
151 draw_image_test_pattern(surface->getCanvas()); | 151 draw_image_test_pattern(surface->getCanvas()); |
152 return surface->newImageSnapshot(); | 152 return surface->makeImageSnapshot(); |
153 } | 153 } |
154 #endif | 154 #endif |
155 | 155 |
156 static void test_encode(skiatest::Reporter* reporter, SkImage* image) { | 156 static void test_encode(skiatest::Reporter* reporter, SkImage* image) { |
157 const SkIRect ir = SkIRect::MakeXYWH(5, 5, 10, 10); | 157 const SkIRect ir = SkIRect::MakeXYWH(5, 5, 10, 10); |
158 SkAutoTUnref<SkData> origEncoded(image->encode()); | 158 sk_sp<SkData> origEncoded(image->encode()); |
159 REPORTER_ASSERT(reporter, origEncoded); | 159 REPORTER_ASSERT(reporter, origEncoded); |
160 REPORTER_ASSERT(reporter, origEncoded->size() > 0); | 160 REPORTER_ASSERT(reporter, origEncoded->size() > 0); |
161 | 161 |
162 SkAutoTUnref<SkImage> decoded(SkImage::NewFromEncoded(origEncoded)); | 162 sk_sp<SkImage> decoded(SkImage::MakeFromEncoded(origEncoded)); |
163 REPORTER_ASSERT(reporter, decoded); | 163 REPORTER_ASSERT(reporter, decoded); |
164 assert_equal(reporter, image, nullptr, decoded); | 164 assert_equal(reporter, image, nullptr, decoded.get()); |
165 | 165 |
166 // Now see if we can instantiate an image from a subset of the surface/origE
ncoded | 166 // Now see if we can instantiate an image from a subset of the surface/origE
ncoded |
167 | 167 |
168 decoded.reset(SkImage::NewFromEncoded(origEncoded, &ir)); | 168 decoded = SkImage::MakeFromEncoded(origEncoded, &ir); |
169 REPORTER_ASSERT(reporter, decoded); | 169 REPORTER_ASSERT(reporter, decoded); |
170 assert_equal(reporter, image, &ir, decoded); | 170 assert_equal(reporter, image, &ir, decoded.get()); |
171 } | 171 } |
172 | 172 |
173 DEF_TEST(ImageEncode, reporter) { | 173 DEF_TEST(ImageEncode, reporter) { |
174 SkAutoTUnref<SkImage> image(create_image()); | 174 test_encode(reporter, create_image().get()); |
175 test_encode(reporter, image); | |
176 } | 175 } |
177 | 176 |
178 #if SK_SUPPORT_GPU | 177 #if SK_SUPPORT_GPU |
179 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageEncode_Gpu, reporter, context) { | 178 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageEncode_Gpu, reporter, context) { |
180 SkAutoTUnref<SkImage> image(create_gpu_image(context)); | 179 test_encode(reporter, create_gpu_image(context).get()); |
181 test_encode(reporter, image); | |
182 } | 180 } |
183 #endif | 181 #endif |
184 | 182 |
185 namespace { | 183 namespace { |
186 | 184 |
187 const char* kSerializedData = "serialized"; | 185 const char* kSerializedData = "serialized"; |
188 | 186 |
189 class MockSerializer : public SkPixelSerializer { | 187 class MockSerializer : public SkPixelSerializer { |
190 public: | 188 public: |
191 MockSerializer(SkData* (*func)()) : fFunc(func), fDidEncode(false) { } | 189 MockSerializer(SkData* (*func)()) : fFunc(func), fDidEncode(false) { } |
(...skipping 15 matching lines...) Expand all Loading... |
207 bool fDidEncode; | 205 bool fDidEncode; |
208 | 206 |
209 typedef SkPixelSerializer INHERITED; | 207 typedef SkPixelSerializer INHERITED; |
210 }; | 208 }; |
211 | 209 |
212 } // anonymous namespace | 210 } // anonymous namespace |
213 | 211 |
214 // Test that SkImage encoding observes custom pixel serializers. | 212 // Test that SkImage encoding observes custom pixel serializers. |
215 DEF_TEST(Image_Encode_Serializer, reporter) { | 213 DEF_TEST(Image_Encode_Serializer, reporter) { |
216 MockSerializer serializer([]() -> SkData* { return SkData::NewWithCString(kS
erializedData); }); | 214 MockSerializer serializer([]() -> SkData* { return SkData::NewWithCString(kS
erializedData); }); |
217 SkAutoTUnref<SkImage> image(create_image()); | 215 sk_sp<SkImage> image(create_image()); |
218 SkAutoTUnref<SkData> encoded(image->encode(&serializer)); | 216 SkAutoTUnref<SkData> encoded(image->encode(&serializer)); |
219 SkAutoTUnref<SkData> reference(SkData::NewWithCString(kSerializedData)); | 217 SkAutoTUnref<SkData> reference(SkData::NewWithCString(kSerializedData)); |
220 | 218 |
221 REPORTER_ASSERT(reporter, serializer.didEncode()); | 219 REPORTER_ASSERT(reporter, serializer.didEncode()); |
222 REPORTER_ASSERT(reporter, encoded); | 220 REPORTER_ASSERT(reporter, encoded); |
223 REPORTER_ASSERT(reporter, encoded->size() > 0); | 221 REPORTER_ASSERT(reporter, encoded->size() > 0); |
224 REPORTER_ASSERT(reporter, encoded->equals(reference)); | 222 REPORTER_ASSERT(reporter, encoded->equals(reference)); |
225 } | 223 } |
226 | 224 |
227 // 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. |
228 DEF_TEST(Image_Serialize_Encoding_Failure, reporter) { | 226 DEF_TEST(Image_Serialize_Encoding_Failure, reporter) { |
229 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100)); | 227 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100)); |
230 surface->getCanvas()->clear(SK_ColorGREEN); | 228 surface->getCanvas()->clear(SK_ColorGREEN); |
231 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | 229 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
232 REPORTER_ASSERT(reporter, image); | 230 REPORTER_ASSERT(reporter, image); |
233 | 231 |
234 SkPictureRecorder recorder; | 232 SkPictureRecorder recorder; |
235 SkCanvas* canvas = recorder.beginRecording(100, 100); | 233 SkCanvas* canvas = recorder.beginRecording(100, 100); |
236 canvas->drawImage(image, 0, 0); | 234 canvas->drawImage(image, 0, 0); |
237 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 235 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
238 REPORTER_ASSERT(reporter, picture); | 236 REPORTER_ASSERT(reporter, picture); |
239 REPORTER_ASSERT(reporter, picture->approximateOpCount() > 0); | 237 REPORTER_ASSERT(reporter, picture->approximateOpCount() > 0); |
240 | 238 |
241 MockSerializer emptySerializer([]() -> SkData* { return SkData::NewEmpty();
}); | 239 MockSerializer emptySerializer([]() -> SkData* { return SkData::NewEmpty();
}); |
(...skipping 18 matching lines...) Expand all Loading... |
260 const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); | 258 const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); |
261 const SkPMColor blue = SkPackARGB32(0xFF, 0, 0, 0xFF); | 259 const SkPMColor blue = SkPackARGB32(0xFF, 0, 0, 0xFF); |
262 SkPMColor colors[] = { red, green, blue, 0 }; | 260 SkPMColor colors[] = { red, green, blue, 0 }; |
263 SkAutoTUnref<SkColorTable> ctable(new SkColorTable(colors, SK_ARRAY_COUNT(co
lors))); | 261 SkAutoTUnref<SkColorTable> ctable(new SkColorTable(colors, SK_ARRAY_COUNT(co
lors))); |
264 // The colortable made a copy, so we can trash the original colors | 262 // The colortable made a copy, so we can trash the original colors |
265 memset(colors, 0xFF, sizeof(colors)); | 263 memset(colors, 0xFF, sizeof(colors)); |
266 | 264 |
267 const SkImageInfo srcInfo = SkImageInfo::Make(2, 2, kIndex_8_SkColorType, kP
remul_SkAlphaType); | 265 const SkImageInfo srcInfo = SkImageInfo::Make(2, 2, kIndex_8_SkColorType, kP
remul_SkAlphaType); |
268 const size_t srcRowBytes = 2 * sizeof(uint8_t); | 266 const size_t srcRowBytes = 2 * sizeof(uint8_t); |
269 uint8_t indices[] = { 0, 1, 2, 3 }; | 267 uint8_t indices[] = { 0, 1, 2, 3 }; |
270 SkAutoTUnref<SkImage> image(SkImage::NewRasterCopy(srcInfo, indices, srcRowB
ytes, ctable)); | 268 sk_sp<SkImage> image(SkImage::MakeRasterCopy(SkPixmap(srcInfo, indices, srcR
owBytes, ctable))); |
271 // The image made a copy, so we can trash the original indices | 269 // The image made a copy, so we can trash the original indices |
272 memset(indices, 0xFF, sizeof(indices)); | 270 memset(indices, 0xFF, sizeof(indices)); |
273 | 271 |
274 const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2); | 272 const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2); |
275 const size_t dstRowBytes = 2 * sizeof(SkPMColor); | 273 const size_t dstRowBytes = 2 * sizeof(SkPMColor); |
276 SkPMColor pixels[4]; | 274 SkPMColor pixels[4]; |
277 memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect | 275 memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect |
278 image->readPixels(dstInfo, pixels, dstRowBytes, 0, 0); | 276 image->readPixels(dstInfo, pixels, dstRowBytes, 0, 0); |
279 REPORTER_ASSERT(reporter, red == pixels[0]); | 277 REPORTER_ASSERT(reporter, red == pixels[0]); |
280 REPORTER_ASSERT(reporter, green == pixels[1]); | 278 REPORTER_ASSERT(reporter, green == pixels[1]); |
281 REPORTER_ASSERT(reporter, blue == pixels[2]); | 279 REPORTER_ASSERT(reporter, blue == pixels[2]); |
282 REPORTER_ASSERT(reporter, 0 == pixels[3]); | 280 REPORTER_ASSERT(reporter, 0 == pixels[3]); |
283 } | 281 } |
284 | 282 |
285 // Test that a draw that only partially covers the drawing surface isn't | 283 // Test that a draw that only partially covers the drawing surface isn't |
286 // interpreted as covering the entire drawing surface (i.e., exercise one of the | 284 // interpreted as covering the entire drawing surface (i.e., exercise one of the |
287 // conditions of SkCanvas::wouldOverwriteEntireSurface()). | 285 // conditions of SkCanvas::wouldOverwriteEntireSurface()). |
288 DEF_TEST(Image_RetainSnapshot, reporter) { | 286 DEF_TEST(Image_RetainSnapshot, reporter) { |
289 const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0); | 287 const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0); |
290 const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); | 288 const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); |
291 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); | 289 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); |
292 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | 290 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
293 surface->getCanvas()->clear(0xFF00FF00); | 291 surface->getCanvas()->clear(0xFF00FF00); |
294 | 292 |
295 SkPMColor pixels[4]; | 293 SkPMColor pixels[4]; |
296 memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect | 294 memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect |
297 const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2); | 295 const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2); |
298 const size_t dstRowBytes = 2 * sizeof(SkPMColor); | 296 const size_t dstRowBytes = 2 * sizeof(SkPMColor); |
299 | 297 |
300 SkAutoTUnref<SkImage> image1(surface->newImageSnapshot()); | 298 sk_sp<SkImage> image1(surface->makeImageSnapshot()); |
301 REPORTER_ASSERT(reporter, image1->readPixels(dstInfo, pixels, dstRowBytes, 0
, 0)); | 299 REPORTER_ASSERT(reporter, image1->readPixels(dstInfo, pixels, dstRowBytes, 0
, 0)); |
302 for (size_t i = 0; i < SK_ARRAY_COUNT(pixels); ++i) { | 300 for (size_t i = 0; i < SK_ARRAY_COUNT(pixels); ++i) { |
303 REPORTER_ASSERT(reporter, pixels[i] == green); | 301 REPORTER_ASSERT(reporter, pixels[i] == green); |
304 } | 302 } |
305 | 303 |
306 SkPaint paint; | 304 SkPaint paint; |
307 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 305 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
308 paint.setColor(SK_ColorRED); | 306 paint.setColor(SK_ColorRED); |
309 | 307 |
310 surface->getCanvas()->drawRect(SkRect::MakeXYWH(1, 1, 1, 1), paint); | 308 surface->getCanvas()->drawRect(SkRect::MakeXYWH(1, 1, 1, 1), paint); |
311 | 309 |
312 SkAutoTUnref<SkImage> image2(surface->newImageSnapshot()); | 310 sk_sp<SkImage> image2(surface->makeImageSnapshot()); |
313 REPORTER_ASSERT(reporter, image2->readPixels(dstInfo, pixels, dstRowBytes, 0
, 0)); | 311 REPORTER_ASSERT(reporter, image2->readPixels(dstInfo, pixels, dstRowBytes, 0
, 0)); |
314 REPORTER_ASSERT(reporter, pixels[0] == green); | 312 REPORTER_ASSERT(reporter, pixels[0] == green); |
315 REPORTER_ASSERT(reporter, pixels[1] == green); | 313 REPORTER_ASSERT(reporter, pixels[1] == green); |
316 REPORTER_ASSERT(reporter, pixels[2] == green); | 314 REPORTER_ASSERT(reporter, pixels[2] == green); |
317 REPORTER_ASSERT(reporter, pixels[3] == red); | 315 REPORTER_ASSERT(reporter, pixels[3] == red); |
318 } | 316 } |
319 | 317 |
320 ////////////////////////////////////////////////////////////////////////////////
///////////////// | 318 ////////////////////////////////////////////////////////////////////////////////
///////////////// |
321 | 319 |
322 static void make_bitmap_mutable(SkBitmap* bm) { | 320 static void make_bitmap_mutable(SkBitmap* bm) { |
(...skipping 13 matching lines...) Expand all Loading... |
336 bool fExpectLazy; | 334 bool fExpectLazy; |
337 } rec[] = { | 335 } rec[] = { |
338 { make_bitmap_mutable, true, false, false }, | 336 { make_bitmap_mutable, true, false, false }, |
339 { make_bitmap_immutable, true, true, false }, | 337 { make_bitmap_immutable, true, true, false }, |
340 }; | 338 }; |
341 | 339 |
342 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { | 340 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { |
343 SkBitmap bm; | 341 SkBitmap bm; |
344 rec[i].fMakeProc(&bm); | 342 rec[i].fMakeProc(&bm); |
345 | 343 |
346 SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bm)); | 344 sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm)); |
347 SkPixmap pmap; | 345 SkPixmap pmap; |
348 | 346 |
349 const bool sharedID = (image->uniqueID() == bm.getGenerationID()); | 347 const bool sharedID = (image->uniqueID() == bm.getGenerationID()); |
350 REPORTER_ASSERT(reporter, sharedID == rec[i].fExpectSharedID); | 348 REPORTER_ASSERT(reporter, sharedID == rec[i].fExpectSharedID); |
351 | 349 |
352 const bool peekSuccess = image->peekPixels(&pmap); | 350 const bool peekSuccess = image->peekPixels(&pmap); |
353 REPORTER_ASSERT(reporter, peekSuccess == rec[i].fExpectPeekSuccess); | 351 REPORTER_ASSERT(reporter, peekSuccess == rec[i].fExpectPeekSuccess); |
354 | 352 |
355 const bool lazy = image->isLazyGenerated(); | 353 const bool lazy = image->isLazyGenerated(); |
356 REPORTER_ASSERT(reporter, lazy == rec[i].fExpectLazy); | 354 REPORTER_ASSERT(reporter, lazy == rec[i].fExpectLazy); |
357 } | 355 } |
358 } | 356 } |
359 | 357 |
360 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 358 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
361 #if SK_SUPPORT_GPU | 359 #if SK_SUPPORT_GPU |
362 | 360 |
363 #include "SkBitmapCache.h" | 361 #include "SkBitmapCache.h" |
364 | 362 |
365 /* | 363 /* |
366 * This tests the caching (and preemptive purge) of the raster equivalent of a
gpu-image. | 364 * This tests the caching (and preemptive purge) of the raster equivalent of a
gpu-image. |
367 * We cache it for performance when drawing into a raster surface. | 365 * We cache it for performance when drawing into a raster surface. |
368 * | 366 * |
369 * A cleaner test would know if each drawImage call triggered a read-back from
the gpu, | 367 * A cleaner test would know if each drawImage call triggered a read-back from
the gpu, |
370 * but we don't have that facility (at the moment) so we use a little internal
knowledge | 368 * but we don't have that facility (at the moment) so we use a little internal
knowledge |
371 * of *how* the raster version is cached, and look for that. | 369 * of *how* the raster version is cached, and look for that. |
372 */ | 370 */ |
373 DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_Gpu2Cpu, reporter, context) { | 371 DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_Gpu2Cpu, reporter, context) { |
374 SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); | 372 SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); |
375 SkAutoTUnref<SkImage> image(create_gpu_image(context)); | 373 sk_sp<SkImage> image(create_gpu_image(context)); |
376 const uint32_t uniqueID = image->uniqueID(); | 374 const uint32_t uniqueID = image->uniqueID(); |
377 | 375 |
378 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | 376 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
379 | 377 |
380 // now we can test drawing a gpu-backed image into a cpu-backed surface | 378 // now we can test drawing a gpu-backed image into a cpu-backed surface |
381 | 379 |
382 { | 380 { |
383 SkBitmap cachedBitmap; | 381 SkBitmap cachedBitmap; |
384 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap))
; | 382 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap))
; |
385 } | 383 } |
(...skipping 18 matching lines...) Expand all Loading... |
404 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap))
; | 402 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap))
; |
405 } | 403 } |
406 } | 404 } |
407 | 405 |
408 DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_newTextureImage, reporter, context, glCon
text) { | 406 DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_newTextureImage, reporter, context, glCon
text) { |
409 GrContextFactory otherFactory; | 407 GrContextFactory otherFactory; |
410 GrContextFactory::ContextInfo otherContextInfo = | 408 GrContextFactory::ContextInfo otherContextInfo = |
411 otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType); | 409 otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType); |
412 glContext->makeCurrent(); | 410 glContext->makeCurrent(); |
413 | 411 |
414 std::function<SkImage*()> imageFactories[] = { | 412 std::function<sk_sp<SkImage>()> imageFactories[] = { |
415 create_image, | 413 create_image, |
416 create_codec_image, | 414 create_codec_image, |
417 create_data_image, | 415 create_data_image, |
418 // Create an image from a picture. | 416 // Create an image from a picture. |
419 create_picture_image, | 417 create_picture_image, |
420 // Create a texture image. | 418 // Create a texture image. |
421 [context] { return create_gpu_image(context); }, | 419 [context] { return create_gpu_image(context); }, |
422 // Create a texture image in a another GrContext. | 420 // Create a texture image in a another GrContext. |
423 [glContext, otherContextInfo] { | 421 [glContext, otherContextInfo] { |
424 otherContextInfo.fGLContext->makeCurrent(); | 422 otherContextInfo.fGLContext->makeCurrent(); |
425 SkImage* otherContextImage = create_gpu_image(otherContextInfo.fGrCo
ntext); | 423 sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo
.fGrContext); |
426 glContext->makeCurrent(); | 424 glContext->makeCurrent(); |
427 return otherContextImage; | 425 return otherContextImage; |
428 } | 426 } |
429 }; | 427 }; |
430 | 428 |
431 for (auto factory : imageFactories) { | 429 for (auto factory : imageFactories) { |
432 SkAutoTUnref<SkImage> image(factory()); | 430 sk_sp<SkImage> image(factory()); |
433 if (!image) { | 431 if (!image) { |
434 ERRORF(reporter, "Error creating image."); | 432 ERRORF(reporter, "Error creating image."); |
435 continue; | 433 continue; |
436 } | 434 } |
437 GrTexture* origTexture = as_IB(image)->peekTexture(); | 435 GrTexture* origTexture = as_IB(image)->peekTexture(); |
438 | 436 |
439 SkAutoTUnref<SkImage> texImage(image->newTextureImage(context)); | 437 sk_sp<SkImage> texImage(image->makeTextureImage(context)); |
440 if (!texImage) { | 438 if (!texImage) { |
441 // We execpt to fail if image comes from a different GrContext. | 439 // We execpt to fail if image comes from a different GrContext. |
442 if (!origTexture || origTexture->getContext() == context) { | 440 if (!origTexture || origTexture->getContext() == context) { |
443 ERRORF(reporter, "newTextureImage failed."); | 441 ERRORF(reporter, "newTextureImage failed."); |
444 } | 442 } |
445 continue; | 443 continue; |
446 } | 444 } |
447 GrTexture* copyTexture = as_IB(texImage)->peekTexture(); | 445 GrTexture* copyTexture = as_IB(texImage)->peekTexture(); |
448 if (!copyTexture) { | 446 if (!copyTexture) { |
449 ERRORF(reporter, "newTextureImage returned non-texture image."); | 447 ERRORF(reporter, "newTextureImage returned non-texture image."); |
(...skipping 18 matching lines...) Expand all Loading... |
468 DEF_TEST(ImageFromIndex8Bitmap, r) { | 466 DEF_TEST(ImageFromIndex8Bitmap, r) { |
469 SkPMColor pmColors[1] = {SkPreMultiplyColor(SK_ColorWHITE)}; | 467 SkPMColor pmColors[1] = {SkPreMultiplyColor(SK_ColorWHITE)}; |
470 SkBitmap bm; | 468 SkBitmap bm; |
471 SkAutoTUnref<SkColorTable> ctable( | 469 SkAutoTUnref<SkColorTable> ctable( |
472 new SkColorTable(pmColors, SK_ARRAY_COUNT(pmColors))); | 470 new SkColorTable(pmColors, SK_ARRAY_COUNT(pmColors))); |
473 SkImageInfo info = | 471 SkImageInfo info = |
474 SkImageInfo::Make(1, 1, kIndex_8_SkColorType, kPremul_SkAlphaType); | 472 SkImageInfo::Make(1, 1, kIndex_8_SkColorType, kPremul_SkAlphaType); |
475 bm.allocPixels(info, nullptr, ctable); | 473 bm.allocPixels(info, nullptr, ctable); |
476 SkAutoLockPixels autoLockPixels(bm); | 474 SkAutoLockPixels autoLockPixels(bm); |
477 *bm.getAddr8(0, 0) = 0; | 475 *bm.getAddr8(0, 0) = 0; |
478 SkAutoTUnref<SkImage> img(SkImage::NewFromBitmap(bm)); | 476 sk_sp<SkImage> img(SkImage::MakeFromBitmap(bm)); |
479 REPORTER_ASSERT(r, img.get() != nullptr); | 477 REPORTER_ASSERT(r, img != nullptr); |
480 } | 478 } |
481 | 479 |
482 class EmptyGenerator : public SkImageGenerator { | 480 class EmptyGenerator : public SkImageGenerator { |
483 public: | 481 public: |
484 EmptyGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(0, 0)) {} | 482 EmptyGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(0, 0)) {} |
485 }; | 483 }; |
486 | 484 |
487 DEF_TEST(ImageEmpty, reporter) { | 485 DEF_TEST(ImageEmpty, reporter) { |
488 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); | 486 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); |
489 REPORTER_ASSERT(reporter, nullptr == SkImage::NewRasterCopy(info, nullptr, 0
)); | 487 SkPixmap pmap(info, nullptr, 0); |
490 REPORTER_ASSERT(reporter, nullptr == SkImage::NewRasterData(info, nullptr, 0
)); | 488 REPORTER_ASSERT(reporter, nullptr == SkImage::MakeRasterCopy(pmap)); |
491 REPORTER_ASSERT(reporter, nullptr == SkImage::NewFromRaster(info, nullptr, 0
, nullptr, nullptr)); | 489 REPORTER_ASSERT(reporter, nullptr == SkImage::MakeRasterData(info, nullptr,
0)); |
492 REPORTER_ASSERT(reporter, nullptr == SkImage::NewFromGenerator(new EmptyGene
rator)); | 490 REPORTER_ASSERT(reporter, nullptr == SkImage::MakeFromRaster(pmap, nullptr,
nullptr)); |
| 491 REPORTER_ASSERT(reporter, nullptr == SkImage::MakeFromGenerator(new EmptyGen
erator)); |
493 } | 492 } |
494 | 493 |
495 DEF_TEST(ImageDataRef, reporter) { | 494 DEF_TEST(ImageDataRef, reporter) { |
496 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); | 495 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
497 size_t rowBytes = info.minRowBytes(); | 496 size_t rowBytes = info.minRowBytes(); |
498 size_t size = info.getSafeSize(rowBytes); | 497 size_t size = info.getSafeSize(rowBytes); |
499 SkData* data = SkData::NewUninitialized(size); | 498 sk_sp<SkData> data = SkData::MakeUninitialized(size); |
500 REPORTER_ASSERT(reporter, data->unique()); | 499 REPORTER_ASSERT(reporter, data->unique()); |
501 SkImage* image = SkImage::NewRasterData(info, data, rowBytes); | 500 sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, rowBytes); |
502 REPORTER_ASSERT(reporter, !data->unique()); | 501 REPORTER_ASSERT(reporter, !data->unique()); |
503 image->unref(); | 502 image.reset(); |
504 REPORTER_ASSERT(reporter, data->unique()); | 503 REPORTER_ASSERT(reporter, data->unique()); |
505 data->unref(); | |
506 } | 504 } |
507 | 505 |
508 static bool has_pixels(const SkPMColor pixels[], int count, SkPMColor expected)
{ | 506 static bool has_pixels(const SkPMColor pixels[], int count, SkPMColor expected)
{ |
509 for (int i = 0; i < count; ++i) { | 507 for (int i = 0; i < count; ++i) { |
510 if (pixels[i] != expected) { | 508 if (pixels[i] != expected) { |
511 return false; | 509 return false; |
512 } | 510 } |
513 } | 511 } |
514 return true; | 512 return true; |
515 } | 513 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h - 1, notExpected)); | 550 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h - 1, notExpected)); |
553 | 551 |
554 // partial bottom-right should succeed | 552 // partial bottom-right should succeed |
555 sk_memset32(pixels, notExpected, w*h); | 553 sk_memset32(pixels, notExpected, w*h); |
556 REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes, | 554 REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes, |
557 image->width() - 1, image->heigh
t() - 1)); | 555 image->width() - 1, image->heigh
t() - 1)); |
558 REPORTER_ASSERT(reporter, pixels[0] == expected); | 556 REPORTER_ASSERT(reporter, pixels[0] == expected); |
559 REPORTER_ASSERT(reporter, has_pixels(&pixels[1], w*h - 1, notExpected)); | 557 REPORTER_ASSERT(reporter, has_pixels(&pixels[1], w*h - 1, notExpected)); |
560 } | 558 } |
561 DEF_TEST(ImageReadPixels, reporter) { | 559 DEF_TEST(ImageReadPixels, reporter) { |
562 SkAutoTUnref<SkImage> image(create_image()); | 560 sk_sp<SkImage> image(create_image()); |
563 test_read_pixels(reporter, image); | 561 test_read_pixels(reporter, image.get()); |
564 | 562 |
565 image.reset(create_data_image()); | 563 image = create_data_image(); |
566 test_read_pixels(reporter, image); | 564 test_read_pixels(reporter, image.get()); |
567 | 565 |
568 RasterDataHolder dataHolder; | 566 RasterDataHolder dataHolder; |
569 image.reset(create_rasterproc_image(&dataHolder)); | 567 image = create_rasterproc_image(&dataHolder); |
570 test_read_pixels(reporter, image); | 568 test_read_pixels(reporter, image.get()); |
571 image.reset(); | 569 image.reset(); |
572 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount); | 570 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount); |
573 | 571 |
574 image.reset(create_codec_image()); | 572 image = create_codec_image(); |
575 test_read_pixels(reporter, image); | 573 test_read_pixels(reporter, image.get()); |
576 } | 574 } |
577 #if SK_SUPPORT_GPU | 575 #if SK_SUPPORT_GPU |
578 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageReadPixels_Gpu, reporter, context) { | 576 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageReadPixels_Gpu, reporter, context) { |
579 SkAutoTUnref<SkImage> image(create_gpu_image(context)); | 577 test_read_pixels(reporter, create_gpu_image(context).get()); |
580 test_read_pixels(reporter, image); | |
581 } | 578 } |
582 #endif | 579 #endif |
583 | 580 |
584 static void check_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* ima
ge, | 581 static void check_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* ima
ge, |
585 const SkBitmap& bitmap, SkImage::LegacyBitmapMod
e mode) { | 582 const SkBitmap& bitmap, SkImage::LegacyBitmapMod
e mode) { |
586 REPORTER_ASSERT(reporter, image->width() == bitmap.width()); | 583 REPORTER_ASSERT(reporter, image->width() == bitmap.width()); |
587 REPORTER_ASSERT(reporter, image->height() == bitmap.height()); | 584 REPORTER_ASSERT(reporter, image->height() == bitmap.height()); |
588 REPORTER_ASSERT(reporter, image->isOpaque() == bitmap.isOpaque()); | 585 REPORTER_ASSERT(reporter, image->isOpaque() == bitmap.isOpaque()); |
589 | 586 |
590 if (SkImage::kRO_LegacyBitmapMode == mode) { | 587 if (SkImage::kRO_LegacyBitmapMode == mode) { |
(...skipping 11 matching lines...) Expand all Loading... |
602 | 599 |
603 static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* imag
e, SkImage::LegacyBitmapMode mode) { | 600 static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* imag
e, SkImage::LegacyBitmapMode mode) { |
604 SkBitmap bitmap; | 601 SkBitmap bitmap; |
605 REPORTER_ASSERT(reporter, image->asLegacyBitmap(&bitmap, mode)); | 602 REPORTER_ASSERT(reporter, image->asLegacyBitmap(&bitmap, mode)); |
606 check_legacy_bitmap(reporter, image, bitmap, mode); | 603 check_legacy_bitmap(reporter, image, bitmap, mode); |
607 | 604 |
608 // Test subsetting to exercise the rowBytes logic. | 605 // Test subsetting to exercise the rowBytes logic. |
609 SkBitmap tmp; | 606 SkBitmap tmp; |
610 REPORTER_ASSERT(reporter, bitmap.extractSubset(&tmp, SkIRect::MakeWH(image->
width() / 2, | 607 REPORTER_ASSERT(reporter, bitmap.extractSubset(&tmp, SkIRect::MakeWH(image->
width() / 2, |
611 image->
height() / 2))); | 608 image->
height() / 2))); |
612 SkAutoTUnref<SkImage> subsetImage(SkImage::NewFromBitmap(tmp)); | 609 sk_sp<SkImage> subsetImage(SkImage::MakeFromBitmap(tmp)); |
613 REPORTER_ASSERT(reporter, subsetImage); | 610 REPORTER_ASSERT(reporter, subsetImage.get()); |
614 | 611 |
615 SkBitmap subsetBitmap; | 612 SkBitmap subsetBitmap; |
616 REPORTER_ASSERT(reporter, subsetImage->asLegacyBitmap(&subsetBitmap, mode)); | 613 REPORTER_ASSERT(reporter, subsetImage->asLegacyBitmap(&subsetBitmap, mode)); |
617 check_legacy_bitmap(reporter, subsetImage, subsetBitmap, mode); | 614 check_legacy_bitmap(reporter, subsetImage.get(), subsetBitmap, mode); |
618 } | 615 } |
619 DEF_TEST(ImageLegacyBitmap, reporter) { | 616 DEF_TEST(ImageLegacyBitmap, reporter) { |
620 const SkImage::LegacyBitmapMode modes[] = { | 617 const SkImage::LegacyBitmapMode modes[] = { |
621 SkImage::kRO_LegacyBitmapMode, | 618 SkImage::kRO_LegacyBitmapMode, |
622 SkImage::kRW_LegacyBitmapMode, | 619 SkImage::kRW_LegacyBitmapMode, |
623 }; | 620 }; |
624 for (auto& mode : modes) { | 621 for (auto& mode : modes) { |
625 SkAutoTUnref<SkImage> image(create_image()); | 622 sk_sp<SkImage> image(create_image()); |
626 test_legacy_bitmap(reporter, image, mode); | 623 test_legacy_bitmap(reporter, image.get(), mode); |
627 | 624 |
628 image.reset(create_data_image()); | 625 image = create_data_image(); |
629 test_legacy_bitmap(reporter, image, mode); | 626 test_legacy_bitmap(reporter, image.get(), mode); |
630 | 627 |
631 RasterDataHolder dataHolder; | 628 RasterDataHolder dataHolder; |
632 image.reset(create_rasterproc_image(&dataHolder)); | 629 image = create_rasterproc_image(&dataHolder); |
633 test_legacy_bitmap(reporter, image, mode); | 630 test_legacy_bitmap(reporter, image.get(), mode); |
634 image.reset(); | 631 image.reset(); |
635 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount); | 632 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount); |
636 | 633 |
637 image.reset(create_codec_image()); | 634 image = create_codec_image(); |
638 test_legacy_bitmap(reporter, image, mode); | 635 test_legacy_bitmap(reporter, image.get(), mode); |
639 } | 636 } |
640 } | 637 } |
641 #if SK_SUPPORT_GPU | 638 #if SK_SUPPORT_GPU |
642 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageLegacyBitmap_Gpu, reporter, context) { | 639 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageLegacyBitmap_Gpu, reporter, context) { |
643 const SkImage::LegacyBitmapMode modes[] = { | 640 const SkImage::LegacyBitmapMode modes[] = { |
644 SkImage::kRO_LegacyBitmapMode, | 641 SkImage::kRO_LegacyBitmapMode, |
645 SkImage::kRW_LegacyBitmapMode, | 642 SkImage::kRW_LegacyBitmapMode, |
646 }; | 643 }; |
647 for (auto& mode : modes) { | 644 for (auto& mode : modes) { |
648 SkAutoTUnref<SkImage> image(create_gpu_image(context)); | 645 sk_sp<SkImage> image(create_gpu_image(context)); |
649 test_legacy_bitmap(reporter, image, mode); | 646 test_legacy_bitmap(reporter, image.get(), mode); |
650 } | 647 } |
651 } | 648 } |
652 #endif | 649 #endif |
653 | 650 |
654 static void test_peek(skiatest::Reporter* reporter, SkImage* image, bool expectP
eekSuccess) { | 651 static void test_peek(skiatest::Reporter* reporter, SkImage* image, bool expectP
eekSuccess) { |
655 SkPixmap pm; | 652 SkPixmap pm; |
656 bool success = image->peekPixels(&pm); | 653 bool success = image->peekPixels(&pm); |
657 REPORTER_ASSERT(reporter, expectPeekSuccess == success); | 654 REPORTER_ASSERT(reporter, expectPeekSuccess == success); |
658 if (success) { | 655 if (success) { |
659 const SkImageInfo& info = pm.info(); | 656 const SkImageInfo& info = pm.info(); |
660 REPORTER_ASSERT(reporter, 20 == info.width()); | 657 REPORTER_ASSERT(reporter, 20 == info.width()); |
661 REPORTER_ASSERT(reporter, 20 == info.height()); | 658 REPORTER_ASSERT(reporter, 20 == info.height()); |
662 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); | 659 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); |
663 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || | 660 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || |
664 kOpaque_SkAlphaType == info.alphaType()); | 661 kOpaque_SkAlphaType == info.alphaType()); |
665 REPORTER_ASSERT(reporter, info.minRowBytes() <= pm.rowBytes()); | 662 REPORTER_ASSERT(reporter, info.minRowBytes() <= pm.rowBytes()); |
666 REPORTER_ASSERT(reporter, SkPreMultiplyColor(SK_ColorWHITE) == *pm.addr3
2(0, 0)); | 663 REPORTER_ASSERT(reporter, SkPreMultiplyColor(SK_ColorWHITE) == *pm.addr3
2(0, 0)); |
667 } | 664 } |
668 } | 665 } |
669 DEF_TEST(ImagePeek, reporter) { | 666 DEF_TEST(ImagePeek, reporter) { |
670 SkAutoTUnref<SkImage> image(create_image()); | 667 sk_sp<SkImage> image(create_image()); |
671 test_peek(reporter, image, true); | 668 test_peek(reporter, image.get(), true); |
672 | 669 |
673 image.reset(create_data_image()); | 670 image = create_data_image(); |
674 test_peek(reporter, image, true); | 671 test_peek(reporter, image.get(), true); |
675 | 672 |
676 RasterDataHolder dataHolder; | 673 RasterDataHolder dataHolder; |
677 image.reset(create_rasterproc_image(&dataHolder)); | 674 image = create_rasterproc_image(&dataHolder); |
678 test_peek(reporter, image, true); | 675 test_peek(reporter, image.get(), true); |
679 image.reset(); | 676 image.reset(); |
680 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount); | 677 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount); |
681 | 678 |
682 image.reset(create_codec_image()); | 679 image = create_codec_image(); |
683 test_peek(reporter, image, false); | 680 test_peek(reporter, image.get(), false); |
684 } | 681 } |
685 #if SK_SUPPORT_GPU | 682 #if SK_SUPPORT_GPU |
686 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImagePeek_Gpu, reporter, context) { | 683 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImagePeek_Gpu, reporter, context) { |
687 SkAutoTUnref<SkImage> image(create_gpu_image(context)); | 684 sk_sp<SkImage> image(create_gpu_image(context)); |
688 test_peek(reporter, image, false); | 685 test_peek(reporter, image.get(), false); |
689 } | 686 } |
690 #endif | 687 #endif |
691 | 688 |
692 #if SK_SUPPORT_GPU | 689 #if SK_SUPPORT_GPU |
693 struct TextureReleaseChecker { | 690 struct TextureReleaseChecker { |
694 TextureReleaseChecker() : fReleaseCount(0) {} | 691 TextureReleaseChecker() : fReleaseCount(0) {} |
695 int fReleaseCount; | 692 int fReleaseCount; |
696 static void Release(void* self) { | 693 static void Release(void* self) { |
697 static_cast<TextureReleaseChecker*>(self)->fReleaseCount++; | 694 static_cast<TextureReleaseChecker*>(self)->fReleaseCount++; |
698 } | 695 } |
(...skipping 25 matching lines...) Expand all Loading... |
724 } | 721 } |
725 | 722 |
726 GrBackendTextureDesc backendDesc; | 723 GrBackendTextureDesc backendDesc; |
727 backendDesc.fConfig = kSkia8888_GrPixelConfig; | 724 backendDesc.fConfig = kSkia8888_GrPixelConfig; |
728 backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag; | 725 backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag; |
729 backendDesc.fWidth = w; | 726 backendDesc.fWidth = w; |
730 backendDesc.fHeight = h; | 727 backendDesc.fHeight = h; |
731 backendDesc.fSampleCnt = 0; | 728 backendDesc.fSampleCnt = 0; |
732 backendDesc.fTextureHandle = tex->getTextureHandle(); | 729 backendDesc.fTextureHandle = tex->getTextureHandle(); |
733 TextureReleaseChecker releaseChecker; | 730 TextureReleaseChecker releaseChecker; |
734 SkAutoTUnref<SkImage> refImg( | 731 sk_sp<SkImage> refImg( |
735 SkImage::NewFromTexture(context, backendDesc, kPremul_SkAlphaType, | 732 SkImage::MakeFromTexture(context, backendDesc, kPremul_SkAlphaType, |
736 TextureReleaseChecker::Release, &releaseChecker)
); | 733 TextureReleaseChecker::Release, &releaseChecker
)); |
737 SkAutoTUnref<SkImage> cpyImg(SkImage::NewFromTextureCopy(context, backendDes
c, | 734 sk_sp<SkImage> cpyImg(SkImage::MakeFromTextureCopy(context, backendDesc, kPr
emul_SkAlphaType)); |
738 kPremul_SkAlphaType
)); | |
739 | 735 |
740 check_image_color(reporter, refImg, expected0); | 736 check_image_color(reporter, refImg.get(), expected0); |
741 check_image_color(reporter, cpyImg, expected0); | 737 check_image_color(reporter, cpyImg.get(), expected0); |
742 | 738 |
743 // Now lets jam new colors into our "external" texture, and see if the image
s notice | 739 // Now lets jam new colors into our "external" texture, and see if the image
s notice |
744 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE); | 740 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE); |
745 sk_memset32(storage, expected1, w * h); | 741 sk_memset32(storage, expected1, w * h); |
746 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF
lushWrites_PixelOp); | 742 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF
lushWrites_PixelOp); |
747 | 743 |
748 // The cpy'd one should still see the old color | 744 // The cpy'd one should still see the old color |
749 #if 0 | 745 #if 0 |
750 // There is no guarantee that refImg sees the new color. We are free to have
made a copy. Our | 746 // There is no guarantee that refImg sees the new color. We are free to have
made a copy. Our |
751 // write pixels call violated the contract with refImg and refImg is now und
efined. | 747 // write pixels call violated the contract with refImg and refImg is now und
efined. |
752 check_image_color(reporter, refImg, expected1); | 748 check_image_color(reporter, refImg, expected1); |
753 #endif | 749 #endif |
754 check_image_color(reporter, cpyImg, expected0); | 750 check_image_color(reporter, cpyImg.get(), expected0); |
755 | 751 |
756 // Now exercise the release proc | 752 // Now exercise the release proc |
757 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); | 753 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); |
758 refImg.reset(nullptr); // force a release of the image | 754 refImg.reset(nullptr); // force a release of the image |
759 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); | 755 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); |
760 } | 756 } |
761 | 757 |
762 static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, co
nst SkImage* b) { | 758 static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, co
nst SkImage* b) { |
763 if (a->width() != b->width() || a->height() != b->height()) { | 759 if (a->width() != b->width() || a->height() != b->height()) { |
764 ERRORF(reporter, "Images must have the same size"); | 760 ERRORF(reporter, "Images must have the same size"); |
(...skipping 30 matching lines...) Expand all Loading... |
795 return; | 791 return; |
796 } | 792 } |
797 } | 793 } |
798 } | 794 } |
799 } | 795 } |
800 | 796 |
801 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(NewTextureFromPixmap, reporter, context) { | 797 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(NewTextureFromPixmap, reporter, context) { |
802 for (auto create : {&create_image, | 798 for (auto create : {&create_image, |
803 &create_image_565, | 799 &create_image_565, |
804 &create_image_ct}) { | 800 &create_image_ct}) { |
805 SkAutoTUnref<SkImage> image((*create)()); | 801 sk_sp<SkImage> image((*create)()); |
806 if (!image) { | 802 if (!image) { |
807 ERRORF(reporter, "Could not create image"); | 803 ERRORF(reporter, "Could not create image"); |
808 return; | 804 return; |
809 } | 805 } |
810 | 806 |
811 SkPixmap pixmap; | 807 SkPixmap pixmap; |
812 if (!image->peekPixels(&pixmap)) { | 808 if (!image->peekPixels(&pixmap)) { |
813 ERRORF(reporter, "peek failed"); | 809 ERRORF(reporter, "peek failed"); |
814 } else { | 810 } else { |
815 SkAutoTUnref<SkImage> texImage(SkImage::NewTextureFromPixmap(context
, pixmap, | 811 sk_sp<SkImage> texImage(SkImage::MakeTextureFromPixmap(context, pixm
ap, |
816 SkBudge
ted::kNo)); | 812 SkBudgeted::k
No)); |
817 if (!texImage) { | 813 if (!texImage) { |
818 ERRORF(reporter, "NewTextureFromPixmap failed."); | 814 ERRORF(reporter, "NewTextureFromPixmap failed."); |
819 } else { | 815 } else { |
820 check_images_same(reporter, image, texImage); | 816 check_images_same(reporter, image.get(), texImage.get()); |
821 } | 817 } |
822 } | 818 } |
823 } | 819 } |
824 } | 820 } |
825 | 821 |
826 DEF_GPUTEST_FOR_NATIVE_CONTEXT(DeferredTextureImage, reporter, context, glContex
t) { | 822 DEF_GPUTEST_FOR_NATIVE_CONTEXT(DeferredTextureImage, reporter, context, glContex
t) { |
827 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); | 823 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); |
828 | 824 |
829 GrContextFactory otherFactory; | 825 GrContextFactory otherFactory; |
830 GrContextFactory::ContextInfo otherContextInfo = | 826 GrContextFactory::ContextInfo otherContextInfo = |
831 otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType); | 827 otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType); |
832 | 828 |
833 glContext->makeCurrent(); | 829 glContext->makeCurrent(); |
834 REPORTER_ASSERT(reporter, proxy); | 830 REPORTER_ASSERT(reporter, proxy); |
835 struct { | 831 struct { |
836 std::function<SkImage *()> fImageFactory; | 832 std::function<sk_sp<SkImage> ()> fImageFactory; |
837 bool fExpectation; | 833 bool fExpectation; |
838 } testCases[] = { | 834 } testCases[] = { |
839 { create_image, true }, | 835 { create_image, true }, |
840 { create_codec_image, true }, | 836 { create_codec_image, true }, |
841 { create_data_image, true }, | 837 { create_data_image, true }, |
842 { create_picture_image, false }, | 838 { create_picture_image, false }, |
843 { [context] { return create_gpu_image(context); }, false }, | 839 { [context] { return create_gpu_image(context); }, false }, |
844 // Create a texture image in a another GrContext. | 840 // Create a texture image in a another GrContext. |
845 { [glContext, otherContextInfo] { | 841 { [glContext, otherContextInfo] { |
846 otherContextInfo.fGLContext->makeCurrent(); | 842 otherContextInfo.fGLContext->makeCurrent(); |
847 SkImage *otherContextImage = create_gpu_image(otherContextInfo.fGrCo
ntext); | 843 sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo
.fGrContext); |
848 glContext->makeCurrent(); | 844 glContext->makeCurrent(); |
849 return otherContextImage; | 845 return otherContextImage; |
850 }, false }, | 846 }, false }, |
851 }; | 847 }; |
852 | 848 |
853 | 849 |
854 for (auto testCase : testCases) { | 850 for (auto testCase : testCases) { |
855 SkAutoTUnref<SkImage> image(testCase.fImageFactory()); | 851 sk_sp<SkImage> image(testCase.fImageFactory()); |
856 | 852 |
857 // This isn't currently used in the implementation, just set any old val
ues. | 853 // This isn't currently used in the implementation, just set any old val
ues. |
858 SkImage::DeferredTextureImageUsageParams params; | 854 SkImage::DeferredTextureImageUsageParams params; |
859 params.fQuality = kLow_SkFilterQuality; | 855 params.fQuality = kLow_SkFilterQuality; |
860 params.fMatrix = SkMatrix::I(); | 856 params.fMatrix = SkMatrix::I(); |
861 | 857 |
862 size_t size = image->getDeferredTextureImageData(*proxy, ¶ms, 1, nul
lptr); | 858 size_t size = image->getDeferredTextureImageData(*proxy, ¶ms, 1, nul
lptr); |
863 | 859 |
864 static const char *const kFS[] = { "fail", "succeed" }; | 860 static const char *const kFS[] = { "fail", "succeed" }; |
865 if (SkToBool(size) != testCase.fExpectation) { | 861 if (SkToBool(size) != testCase.fExpectation) { |
866 ERRORF(reporter, "This image was expected to %s but did not.", | 862 ERRORF(reporter, "This image was expected to %s but did not.", |
867 kFS[testCase.fExpectation]); | 863 kFS[testCase.fExpectation]); |
868 } | 864 } |
869 if (size) { | 865 if (size) { |
870 void* buffer = sk_malloc_throw(size); | 866 void* buffer = sk_malloc_throw(size); |
871 void* misaligned = reinterpret_cast<void*>(reinterpret_cast<intptr_t
>(buffer) + 3); | 867 void* misaligned = reinterpret_cast<void*>(reinterpret_cast<intptr_t
>(buffer) + 3); |
872 if (image->getDeferredTextureImageData(*proxy, ¶ms, 1, misaligne
d)) { | 868 if (image->getDeferredTextureImageData(*proxy, ¶ms, 1, misaligne
d)) { |
873 ERRORF(reporter, "Should fail when buffer is misaligned."); | 869 ERRORF(reporter, "Should fail when buffer is misaligned."); |
874 } | 870 } |
875 if (!image->getDeferredTextureImageData(*proxy, ¶ms, 1, buffer))
{ | 871 if (!image->getDeferredTextureImageData(*proxy, ¶ms, 1, buffer))
{ |
876 ERRORF(reporter, "deferred image size succeeded but creation fai
led."); | 872 ERRORF(reporter, "deferred image size succeeded but creation fai
led."); |
877 } else { | 873 } else { |
878 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { | 874 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { |
879 SkAutoTUnref<SkImage> newImage( | 875 sk_sp<SkImage> newImage( |
880 SkImage::NewFromDeferredTextureImageData(context, buffer
, budgeted)); | 876 SkImage::MakeFromDeferredTextureImageData(context, buffe
r, budgeted)); |
881 REPORTER_ASSERT(reporter, newImage != nullptr); | 877 REPORTER_ASSERT(reporter, newImage != nullptr); |
882 if (newImage) { | 878 if (newImage) { |
883 check_images_same(reporter, image, newImage); | 879 check_images_same(reporter, image.get(), newImage.get())
; |
884 } | 880 } |
885 // The other context should not be able to create images fro
m texture data | 881 // The other context should not be able to create images fro
m texture data |
886 // created by the original context. | 882 // created by the original context. |
887 SkAutoTUnref<SkImage> newImage2(SkImage::NewFromDeferredText
ureImageData( | 883 sk_sp<SkImage> newImage2(SkImage::MakeFromDeferredTextureIma
geData( |
888 otherContextInfo.fGrContext, buffer, budgeted)); | 884 otherContextInfo.fGrContext, buffer, budgeted)); |
889 REPORTER_ASSERT(reporter, !newImage2); | 885 REPORTER_ASSERT(reporter, !newImage2); |
890 glContext->makeCurrent(); | 886 glContext->makeCurrent(); |
891 } | 887 } |
892 } | 888 } |
893 sk_free(buffer); | 889 sk_free(buffer); |
894 } | 890 } |
895 } | 891 } |
896 } | 892 } |
897 #endif | 893 #endif |
OLD | NEW |