blob: 50d443d8a6f828f396a1992bc7e6559d3d0d19f2 [file] [log] [blame]
junov@chromium.org995beb62013-03-28 13:49:22 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +00007
bsalomone63ffef2016-02-05 07:17:34 -08008#include <functional>
junov@chromium.org995beb62013-03-28 13:49:22 +00009#include "SkCanvas.h"
reed@google.com4f7c6152014-02-06 14:11:56 +000010#include "SkData.h"
reed41e010c2015-06-09 12:16:53 -070011#include "SkDevice.h"
bsalomon55812362015-06-10 08:49:28 -070012#include "SkImage_Base.h"
bungemand3ebb482015-08-05 13:57:49 -070013#include "SkPath.h"
junov@chromium.org995beb62013-03-28 13:49:22 +000014#include "SkRRect.h"
15#include "SkSurface.h"
reed@google.com4f7c6152014-02-06 14:11:56 +000016#include "SkUtils.h"
junov@chromium.org995beb62013-03-28 13:49:22 +000017#include "Test.h"
18
19#if SK_SUPPORT_GPU
kkinnunen179a8f52015-11-20 13:32:24 -080020#include "GrContext.h"
21#include "GrGpu.h"
junov@chromium.org995beb62013-03-28 13:49:22 +000022#endif
23
kkinnunen179a8f52015-11-20 13:32:24 -080024#include <initializer_list>
bsalomon74f681d2015-06-23 14:38:48 -070025
kkinnunen179a8f52015-11-20 13:32:24 -080026static void release_direct_surface_storage(void* pixels, void* context) {
reed982542d2014-06-27 06:48:14 -070027 SkASSERT(pixels == context);
28 sk_free(pixels);
29}
kkinnunen179a8f52015-11-20 13:32:24 -080030static SkSurface* create_surface(SkAlphaType at = kPremul_SkAlphaType,
halcanary96fcdcc2015-08-27 07:41:13 -070031 SkImageInfo* requestedInfo = nullptr) {
bsalomon74f681d2015-06-23 14:38:48 -070032 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000033 if (requestedInfo) {
34 *requestedInfo = info;
35 }
kkinnunen179a8f52015-11-20 13:32:24 -080036 return SkSurface::NewRaster(info);
junov@chromium.org995beb62013-03-28 13:49:22 +000037}
kkinnunen179a8f52015-11-20 13:32:24 -080038static SkSurface* create_direct_surface(SkAlphaType at = kPremul_SkAlphaType,
39 SkImageInfo* requestedInfo = nullptr) {
40 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
41 if (requestedInfo) {
42 *requestedInfo = info;
43 }
44 const size_t rowBytes = info.minRowBytes();
45 void* storage = sk_malloc_throw(info.getSafeSize(rowBytes));
46 return SkSurface::NewRasterDirectReleaseProc(info, storage, rowBytes,
47 release_direct_surface_storage,
48 storage);
49}
50#if SK_SUPPORT_GPU
51static SkSurface* create_gpu_surface(GrContext* context, SkAlphaType at = kPremul_SkAlphaType,
52 SkImageInfo* requestedInfo = nullptr) {
53 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
54 if (requestedInfo) {
55 *requestedInfo = info;
56 }
57 return SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0, nullptr);
58}
59static SkSurface* create_gpu_scratch_surface(GrContext* context,
60 SkAlphaType at = kPremul_SkAlphaType,
61 SkImageInfo* requestedInfo = nullptr) {
62 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
63 if (requestedInfo) {
64 *requestedInfo = info;
65 }
66 return SkSurface::NewRenderTarget(context, SkSurface::kYes_Budgeted, info, 0, nullptr);
67}
68#endif
junov@chromium.org995beb62013-03-28 13:49:22 +000069
kkinnunen179a8f52015-11-20 13:32:24 -080070DEF_TEST(SurfaceEmpty, reporter) {
reedb2497c22014-12-31 12:31:43 -080071 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
halcanary96fcdcc2015-08-27 07:41:13 -070072 REPORTER_ASSERT(reporter, nullptr == SkSurface::NewRaster(info));
73 REPORTER_ASSERT(reporter, nullptr == SkSurface::NewRasterDirect(info, nullptr, 0));
kkinnunen179a8f52015-11-20 13:32:24 -080074
reedb2497c22014-12-31 12:31:43 -080075}
kkinnunen179a8f52015-11-20 13:32:24 -080076#if SK_SUPPORT_GPU
77DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, context) {
78 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
79 REPORTER_ASSERT(reporter, nullptr ==
80 SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0, nullptr));
81}
82#endif
reedb2497c22014-12-31 12:31:43 -080083
bsalomone4579ad2015-04-08 08:38:40 -070084#if SK_SUPPORT_GPU
kkinnunen179a8f52015-11-20 13:32:24 -080085DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, context) {
bsalomone63ffef2016-02-05 07:17:34 -080086 GrGpu* gpu = context->getGpu();
jvanverth672bb7f2015-07-13 07:19:57 -070087 if (!gpu) {
bsalomone4579ad2015-04-08 08:38:40 -070088 return;
89 }
bsalomon7a617932015-06-16 08:07:16 -070090
jvanverth672bb7f2015-07-13 07:19:57 -070091 // Test the wrapped factory for SkSurface by creating a backend texture and then wrap it in
joshualitt81793412015-07-08 12:54:04 -070092 // a SkSurface.
joshualitt81793412015-07-08 12:54:04 -070093 static const int kW = 100;
94 static const int kH = 100;
95 static const uint32_t kOrigColor = 0xFFAABBCC;
96 SkAutoTArray<uint32_t> pixels(kW * kH);
97 sk_memset32(pixels.get(), kOrigColor, kW * kH);
bsalomon091f60c2015-11-10 11:54:56 -080098 GrBackendObject texHandle = gpu->createTestingOnlyBackendTexture(pixels.get(), kW, kH,
99 kRGBA_8888_GrPixelConfig);
bsalomone4579ad2015-04-08 08:38:40 -0700100
joshualitt81793412015-07-08 12:54:04 -0700101 GrBackendTextureDesc wrappedDesc;
102 wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig;
103 wrappedDesc.fWidth = kW;
104 wrappedDesc.fHeight = kH;
105 wrappedDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
106 wrappedDesc.fSampleCnt = 0;
107 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
bsalomon091f60c2015-11-10 11:54:56 -0800108 wrappedDesc.fTextureHandle = texHandle;
bsalomone4579ad2015-04-08 08:38:40 -0700109
kkinnunen179a8f52015-11-20 13:32:24 -0800110 SkAutoTUnref<SkSurface> surface(
111 SkSurface::NewWrappedRenderTarget(context, wrappedDesc, nullptr));
joshualitt81793412015-07-08 12:54:04 -0700112 REPORTER_ASSERT(reporter, surface);
113 if (surface) {
114 // Validate that we can draw to the canvas and that the original texture color is preserved
115 // in pixels that aren't rendered to via the surface.
116 SkPaint paint;
117 static const SkColor kRectColor = ~kOrigColor | 0xFF000000;
118 paint.setColor(kRectColor);
119 surface->getCanvas()->drawRect(SkRect::MakeWH(SkIntToScalar(kW), SkIntToScalar(kH)/2),
120 paint);
121 SkImageInfo readInfo = SkImageInfo::MakeN32Premul(kW, kH);
122 surface->readPixels(readInfo, pixels.get(), kW * sizeof(uint32_t), 0, 0);
123 bool stop = false;
124 SkPMColor origColorPM = SkPackARGB32((kOrigColor >> 24 & 0xFF),
125 (kOrigColor >> 0 & 0xFF),
126 (kOrigColor >> 8 & 0xFF),
127 (kOrigColor >> 16 & 0xFF));
128 SkPMColor rectColorPM = SkPackARGB32((kRectColor >> 24 & 0xFF),
129 (kRectColor >> 16 & 0xFF),
130 (kRectColor >> 8 & 0xFF),
131 (kRectColor >> 0 & 0xFF));
132 for (int y = 0; y < kH/2 && !stop; ++y) {
133 for (int x = 0; x < kW && !stop; ++x) {
134 REPORTER_ASSERT(reporter, rectColorPM == pixels[x + y * kW]);
135 if (rectColorPM != pixels[x + y * kW]) {
136 stop = true;
bsalomon7a617932015-06-16 08:07:16 -0700137 }
138 }
139 }
joshualitt81793412015-07-08 12:54:04 -0700140 stop = false;
141 for (int y = kH/2; y < kH && !stop; ++y) {
142 for (int x = 0; x < kW && !stop; ++x) {
143 REPORTER_ASSERT(reporter, origColorPM == pixels[x + y * kW]);
144 if (origColorPM != pixels[x + y * kW]) {
145 stop = true;
146 }
147 }
bsalomon7a617932015-06-16 08:07:16 -0700148 }
149 }
bsalomon67d76202015-11-11 12:40:42 -0800150 gpu->deleteTestingOnlyBackendTexture(texHandle);
bsalomone4579ad2015-04-08 08:38:40 -0700151}
152#endif
153
kkinnunen179a8f52015-11-20 13:32:24 -0800154static void test_canvas_peek(skiatest::Reporter* reporter,
155 SkSurface* surface,
156 const SkImageInfo& requestInfo,
157 bool expectPeekSuccess) {
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000158 const SkColor color = SK_ColorRED;
159 const SkPMColor pmcolor = SkPreMultiplyColor(color);
kkinnunen179a8f52015-11-20 13:32:24 -0800160 SkImageInfo info;
161 size_t rowBytes;
162 surface->getCanvas()->clear(color);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000163
kkinnunen179a8f52015-11-20 13:32:24 -0800164 const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes);
165 bool success = SkToBool(addr);
166 REPORTER_ASSERT(reporter, expectPeekSuccess == success);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000167
kkinnunen179a8f52015-11-20 13:32:24 -0800168 SkImageInfo info2;
169 size_t rb2;
170 const void* addr2 = surface->peekPixels(&info2, &rb2);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000171
kkinnunen179a8f52015-11-20 13:32:24 -0800172 if (success) {
173 REPORTER_ASSERT(reporter, requestInfo == info);
174 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= rowBytes);
175 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000176
kkinnunen179a8f52015-11-20 13:32:24 -0800177 REPORTER_ASSERT(reporter, addr2 == addr);
178 REPORTER_ASSERT(reporter, info2 == info);
179 REPORTER_ASSERT(reporter, rb2 == rowBytes);
180 } else {
181 REPORTER_ASSERT(reporter, nullptr == addr2);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000182 }
183}
kkinnunen179a8f52015-11-20 13:32:24 -0800184DEF_TEST(SurfaceCanvasPeek, reporter) {
185 for (auto& surface_func : { &create_surface, &create_direct_surface }) {
186 SkImageInfo requestInfo;
187 SkAutoTUnref<SkSurface> surface(surface_func(kPremul_SkAlphaType, &requestInfo));
188 test_canvas_peek(reporter, surface, requestInfo, true);
189 }
190}
191#if SK_SUPPORT_GPU
192DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, context) {
193 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
194 SkImageInfo requestInfo;
195 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaType, &requestInfo));
196 test_canvas_peek(reporter, surface, requestInfo, false);
197 }
198}
199#endif
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000200
reed41e010c2015-06-09 12:16:53 -0700201// For compatibility with clients that still call accessBitmap(), we need to ensure that we bump
202// the bitmap's genID when we draw to it, else they won't know it has new values. When they are
203// exclusively using surface/image, and we can hide accessBitmap from device, we can remove this
204// test.
kkinnunen179a8f52015-11-20 13:32:24 -0800205void test_access_pixels(skiatest::Reporter* reporter, SkSurface* surface) {
206 SkCanvas* canvas = surface->getCanvas();
207 canvas->clear(0);
reed41e010c2015-06-09 12:16:53 -0700208
kkinnunen179a8f52015-11-20 13:32:24 -0800209 SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compatibility_testing();
210 SkBitmap bm = device->accessBitmap(false);
211 uint32_t genID0 = bm.getGenerationID();
212 // Now we draw something, which needs to "dirty" the genID (sorta like copy-on-write)
213 canvas->drawColor(SK_ColorBLUE);
214 // Now check that we get a different genID
215 uint32_t genID1 = bm.getGenerationID();
216 REPORTER_ASSERT(reporter, genID0 != genID1);
217}
218DEF_TEST(SurfaceAccessPixels, reporter) {
219 for (auto& surface_func : { &create_surface, &create_direct_surface }) {
220 SkAutoTUnref<SkSurface> surface(surface_func(kPremul_SkAlphaType, nullptr));
221 test_access_pixels(reporter, surface);
222 }
223}
224#if SK_SUPPORT_GPU
225DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceAccessPixels_Gpu, reporter, context) {
226 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
227 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaType, nullptr));
228 test_access_pixels(reporter, surface);
229 }
230}
231#endif
232
233static void test_snapshot_alphatype(skiatest::Reporter* reporter, SkSurface* surface,
234 bool expectOpaque) {
235 REPORTER_ASSERT(reporter, surface);
236 if (surface) {
237 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
238 REPORTER_ASSERT(reporter, image);
239 if (image) {
240 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(expectOpaque));
reed41e010c2015-06-09 12:16:53 -0700241 }
242 }
243}
kkinnunen179a8f52015-11-20 13:32:24 -0800244DEF_TEST(SurfaceSnapshotAlphaType, reporter) {
245 for (auto& surface_func : { &create_surface, &create_direct_surface }) {
246 for (auto& isOpaque : { true, false }) {
247 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
248 SkAutoTUnref<SkSurface> surface(surface_func(alphaType, nullptr));
249 test_snapshot_alphatype(reporter, surface, isOpaque);
bsalomon74f681d2015-06-23 14:38:48 -0700250 }
251 }
252}
kkinnunen179a8f52015-11-20 13:32:24 -0800253#if SK_SUPPORT_GPU
254DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, context) {
255 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
256 for (auto& isOpaque : { true, false }) {
257 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
258 SkAutoTUnref<SkSurface> surface(surface_func(context, alphaType, nullptr));
259 test_snapshot_alphatype(reporter, surface, isOpaque);
260 }
261 }
262}
263#endif
bsalomon74f681d2015-06-23 14:38:48 -0700264
kkinnunen179a8f52015-11-20 13:32:24 -0800265static GrBackendObject get_surface_backend_texture_handle(
266 SkSurface* s, SkSurface::BackendHandleAccess a) {
267 return s->getTextureHandle(a);
268}
269static GrBackendObject get_surface_backend_render_target_handle(
270 SkSurface* s, SkSurface::BackendHandleAccess a) {
271 GrBackendObject result;
272 if (!s->getRenderTargetHandle(&result, a)) {
273 return 0;
274 }
275 return result;
276}
277
278static void test_backend_handle_access_copy_on_write(
279 skiatest::Reporter* reporter, SkSurface* surface, SkSurface::BackendHandleAccess mode,
280 GrBackendObject (*func)(SkSurface*, SkSurface::BackendHandleAccess)) {
fmalitae2639082015-08-06 07:04:51 -0700281 GrBackendObject obj1 = func(surface, mode);
282 SkAutoTUnref<SkImage> snap1(surface->newImageSnapshot());
283
284 GrBackendObject obj2 = func(surface, mode);
285 SkAutoTUnref<SkImage> snap2(surface->newImageSnapshot());
286
287 // If the access mode triggers CoW, then the backend objects should reflect it.
288 REPORTER_ASSERT(reporter, (obj1 == obj2) == (snap1 == snap2));
289}
kkinnunen179a8f52015-11-20 13:32:24 -0800290DEF_TEST(SurfaceBackendHandleAccessCopyOnWrite, reporter) {
291 const SkSurface::BackendHandleAccess accessModes[] = {
292 SkSurface::kFlushRead_BackendHandleAccess,
293 SkSurface::kFlushWrite_BackendHandleAccess,
294 SkSurface::kDiscardWrite_BackendHandleAccess,
295 };
296 for (auto& handle_access_func :
297 { &get_surface_backend_texture_handle, &get_surface_backend_render_target_handle }) {
298 for (auto& accessMode : accessModes) {
299 SkAutoTUnref<SkSurface> surface(create_surface());
300 test_backend_handle_access_copy_on_write(reporter, surface, accessMode,
301 handle_access_func);
302 }
303 }
304}
305#if SK_SUPPORT_GPU
306DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessCopyOnWrite_Gpu, reporter, context) {
307 const SkSurface::BackendHandleAccess accessModes[] = {
308 SkSurface::kFlushRead_BackendHandleAccess,
309 SkSurface::kFlushWrite_BackendHandleAccess,
310 SkSurface::kDiscardWrite_BackendHandleAccess,
311 };
312 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
313 for (auto& handle_access_func :
314 { &get_surface_backend_texture_handle, &get_surface_backend_render_target_handle }) {
315 for (auto& accessMode : accessModes) {
316 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaType,
317 nullptr));
318 test_backend_handle_access_copy_on_write(reporter, surface, accessMode,
319 handle_access_func);
320 }
321 }
322 }
323}
324#endif
fmalitae2639082015-08-06 07:04:51 -0700325
kkinnunen179a8f52015-11-20 13:32:24 -0800326#if SK_SUPPORT_GPU
327// May we (soon) eliminate the need to keep testing this, by hiding the bloody device!
328static uint32_t get_legacy_gen_id(SkSurface* surface) {
329 SkBaseDevice* device =
330 surface->getCanvas()->getDevice_just_for_deprecated_compatibility_testing();
331 return device->accessBitmap(false).getGenerationID();
332}
333/*
334 * Test legacy behavor of bumping the surface's device's bitmap's genID when we access its
335 * texture handle for writing.
336 *
337 * Note: this needs to be tested separately from checking newImageSnapshot, as calling that
338 * can also incidentally bump the genID (when a new backing surface is created).
339 */
340static void test_backend_handle_gen_id(
341 skiatest::Reporter* reporter, SkSurface* surface,
342 GrBackendObject (*func)(SkSurface*, SkSurface::BackendHandleAccess)) {
343 const uint32_t gen0 = get_legacy_gen_id(surface);
344 func(surface, SkSurface::kFlushRead_BackendHandleAccess);
345 const uint32_t gen1 = get_legacy_gen_id(surface);
346 REPORTER_ASSERT(reporter, gen0 == gen1);
347
348 func(surface, SkSurface::kFlushWrite_BackendHandleAccess);
349 const uint32_t gen2 = get_legacy_gen_id(surface);
350 REPORTER_ASSERT(reporter, gen0 != gen2);
351
352 func(surface, SkSurface::kDiscardWrite_BackendHandleAccess);
353 const uint32_t gen3 = get_legacy_gen_id(surface);
354 REPORTER_ASSERT(reporter, gen0 != gen3);
355 REPORTER_ASSERT(reporter, gen2 != gen3);
356}
357static void test_backend_handle_unique_id(
358 skiatest::Reporter* reporter, SkSurface* surface,
359 GrBackendObject (*func)(SkSurface*, SkSurface::BackendHandleAccess)) {
360 SkAutoTUnref<SkImage> image0(surface->newImageSnapshot());
361 GrBackendObject obj = func(surface, SkSurface::kFlushRead_BackendHandleAccess);
362 REPORTER_ASSERT(reporter, obj != 0);
363 SkAutoTUnref<SkImage> image1(surface->newImageSnapshot());
364 // just read access should not affect the snapshot
365 REPORTER_ASSERT(reporter, image0->uniqueID() == image1->uniqueID());
366
367 obj = func(surface, SkSurface::kFlushWrite_BackendHandleAccess);
368 REPORTER_ASSERT(reporter, obj != 0);
369 SkAutoTUnref<SkImage> image2(surface->newImageSnapshot());
370 // expect a new image, since we claimed we would write
371 REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID());
372
373 obj = func(surface, SkSurface::kDiscardWrite_BackendHandleAccess);
374 REPORTER_ASSERT(reporter, obj != 0);
375 SkAutoTUnref<SkImage> image3(surface->newImageSnapshot());
376 // expect a new(er) image, since we claimed we would write
377 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID());
378 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID());
379}
380// No CPU test.
381DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter, context) {
382 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
383 for (auto& test_func : { &test_backend_handle_unique_id, &test_backend_handle_gen_id }) {
384 for (auto& handle_access_func :
385 { &get_surface_backend_texture_handle, &get_surface_backend_render_target_handle}) {
386 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaType,
387 nullptr));
388 test_func(reporter, surface, handle_access_func);
389 }
390 }
391 }
392}
393#endif
394
395// Verify that the right canvas commands trigger a copy on write.
396static void test_copy_on_write(skiatest::Reporter* reporter, SkSurface* surface) {
junov@chromium.org995beb62013-03-28 13:49:22 +0000397 SkCanvas* canvas = surface->getCanvas();
398
399 const SkRect testRect =
400 SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
401 SkIntToScalar(4), SkIntToScalar(5));
junov@chromium.org995beb62013-03-28 13:49:22 +0000402 SkPath testPath;
403 testPath.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
404 SkIntToScalar(2), SkIntToScalar(1)));
405
406 const SkIRect testIRect = SkIRect::MakeXYWH(0, 0, 2, 1);
407
408 SkRegion testRegion;
409 testRegion.setRect(testIRect);
410
411
412 const SkColor testColor = 0x01020304;
413 const SkPaint testPaint;
414 const SkPoint testPoints[3] = {
415 {SkIntToScalar(0), SkIntToScalar(0)},
416 {SkIntToScalar(2), SkIntToScalar(1)},
417 {SkIntToScalar(0), SkIntToScalar(2)}
418 };
419 const size_t testPointCount = 3;
420
421 SkBitmap testBitmap;
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +0000422 testBitmap.allocN32Pixels(10, 10);
robertphillips@google.comd1ce77d2013-10-09 12:51:09 +0000423 testBitmap.eraseColor(0);
junov@chromium.org995beb62013-03-28 13:49:22 +0000424
425 SkRRect testRRect;
426 testRRect.setRectXY(testRect, SK_Scalar1, SK_Scalar1);
427
428 SkString testText("Hello World");
429 const SkPoint testPoints2[] = {
430 { SkIntToScalar(0), SkIntToScalar(1) },
431 { SkIntToScalar(1), SkIntToScalar(1) },
432 { SkIntToScalar(2), SkIntToScalar(1) },
433 { SkIntToScalar(3), SkIntToScalar(1) },
434 { SkIntToScalar(4), SkIntToScalar(1) },
435 { SkIntToScalar(5), SkIntToScalar(1) },
436 { SkIntToScalar(6), SkIntToScalar(1) },
437 { SkIntToScalar(7), SkIntToScalar(1) },
438 { SkIntToScalar(8), SkIntToScalar(1) },
439 { SkIntToScalar(9), SkIntToScalar(1) },
440 { SkIntToScalar(10), SkIntToScalar(1) },
441 };
442
443#define EXPECT_COPY_ON_WRITE(command) \
444 { \
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000445 SkImage* imageBefore = surface->newImageSnapshot(); \
junov@chromium.org995beb62013-03-28 13:49:22 +0000446 SkAutoTUnref<SkImage> aur_before(imageBefore); \
447 canvas-> command ; \
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000448 SkImage* imageAfter = surface->newImageSnapshot(); \
junov@chromium.org995beb62013-03-28 13:49:22 +0000449 SkAutoTUnref<SkImage> aur_after(imageAfter); \
450 REPORTER_ASSERT(reporter, imageBefore != imageAfter); \
451 }
452
453 EXPECT_COPY_ON_WRITE(clear(testColor))
454 EXPECT_COPY_ON_WRITE(drawPaint(testPaint))
455 EXPECT_COPY_ON_WRITE(drawPoints(SkCanvas::kPoints_PointMode, testPointCount, testPoints, \
456 testPaint))
457 EXPECT_COPY_ON_WRITE(drawOval(testRect, testPaint))
458 EXPECT_COPY_ON_WRITE(drawRect(testRect, testPaint))
459 EXPECT_COPY_ON_WRITE(drawRRect(testRRect, testPaint))
460 EXPECT_COPY_ON_WRITE(drawPath(testPath, testPaint))
461 EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0))
reede47829b2015-08-06 10:02:53 -0700462 EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, testRect, nullptr))
halcanary96fcdcc2015-08-27 07:41:13 -0700463 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, nullptr))
junov@chromium.org995beb62013-03-28 13:49:22 +0000464 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testPaint))
465 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoints2, \
466 testPaint))
halcanary96fcdcc2015-08-27 07:41:13 -0700467 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testPath, nullptr, \
junov@chromium.org995beb62013-03-28 13:49:22 +0000468 testPaint))
kkinnunen179a8f52015-11-20 13:32:24 -0800469}
470DEF_TEST(SurfaceCopyOnWrite, reporter) {
471 SkAutoTUnref<SkSurface> surface(create_surface());
472 test_copy_on_write(reporter, surface);
473}
474#if SK_SUPPORT_GPU
475DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, context) {
476 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
477 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaType, nullptr));
478 test_copy_on_write(reporter, surface);
fmalitae2639082015-08-06 07:04:51 -0700479 }
junov@chromium.org995beb62013-03-28 13:49:22 +0000480}
kkinnunen179a8f52015-11-20 13:32:24 -0800481#endif
junov@chromium.org995beb62013-03-28 13:49:22 +0000482
kkinnunen179a8f52015-11-20 13:32:24 -0800483static void test_writable_after_snapshot_release(skiatest::Reporter* reporter,
484 SkSurface* surface) {
junov@chromium.orgaf058352013-04-03 15:03:26 +0000485 // This test succeeds by not triggering an assertion.
486 // The test verifies that the surface remains writable (usable) after
487 // acquiring and releasing a snapshot without triggering a copy on write.
junov@chromium.orgaf058352013-04-03 15:03:26 +0000488 SkCanvas* canvas = surface->getCanvas();
489 canvas->clear(1);
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000490 surface->newImageSnapshot()->unref(); // Create and destroy SkImage
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000491 canvas->clear(2); // Must not assert internally
junov@chromium.org995beb62013-03-28 13:49:22 +0000492}
kkinnunen179a8f52015-11-20 13:32:24 -0800493DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) {
494 SkAutoTUnref<SkSurface> surface(create_surface());
495 test_writable_after_snapshot_release(reporter, surface);
496}
497#if SK_SUPPORT_GPU
498DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu, reporter, context) {
499 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
500 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaType, nullptr));
501 test_writable_after_snapshot_release(reporter, surface);
502 }
503}
504#endif
junov@chromium.orgda904742013-05-01 22:38:16 +0000505
junov@chromium.orgb516a412013-05-01 22:49:59 +0000506#if SK_SUPPORT_GPU
kkinnunen179a8f52015-11-20 13:32:24 -0800507static void test_crbug263329(skiatest::Reporter* reporter,
508 SkSurface* surface1,
509 SkSurface* surface2) {
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000510 // This is a regression test for crbug.com/263329
511 // Bug was caused by onCopyOnWrite releasing the old surface texture
512 // back to the scratch texture pool even though the texture is used
513 // by and active SkImage_Gpu.
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000514 SkCanvas* canvas1 = surface1->getCanvas();
515 SkCanvas* canvas2 = surface2->getCanvas();
516 canvas1->clear(1);
517 SkAutoTUnref<SkImage> image1(surface1->newImageSnapshot());
518 // Trigger copy on write, new backing is a scratch texture
519 canvas1->clear(2);
520 SkAutoTUnref<SkImage> image2(surface1->newImageSnapshot());
521 // Trigger copy on write, old backing should not be returned to scratch
522 // pool because it is held by image2
523 canvas1->clear(3);
524
525 canvas2->clear(4);
526 SkAutoTUnref<SkImage> image3(surface2->newImageSnapshot());
527 // Trigger copy on write on surface2. The new backing store should not
528 // be recycling a texture that is held by an existing image.
529 canvas2->clear(5);
530 SkAutoTUnref<SkImage> image4(surface2->newImageSnapshot());
bsalomon55812362015-06-10 08:49:28 -0700531 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image3)->getTexture());
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000532 // The following assertion checks crbug.com/263329
bsalomon55812362015-06-10 08:49:28 -0700533 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image2)->getTexture());
534 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image1)->getTexture());
535 REPORTER_ASSERT(reporter, as_IB(image3)->getTexture() != as_IB(image2)->getTexture());
536 REPORTER_ASSERT(reporter, as_IB(image3)->getTexture() != as_IB(image1)->getTexture());
537 REPORTER_ASSERT(reporter, as_IB(image2)->getTexture() != as_IB(image1)->getTexture());
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000538}
kkinnunen179a8f52015-11-20 13:32:24 -0800539DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, context) {
540 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
541 SkAutoTUnref<SkSurface> surface1(surface_func(context, kPremul_SkAlphaType, nullptr));
542 SkAutoTUnref<SkSurface> surface2(surface_func(context, kPremul_SkAlphaType, nullptr));
543 test_crbug263329(reporter, surface1, surface2);
544 }
545}
546#endif
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000547
kkinnunen179a8f52015-11-20 13:32:24 -0800548DEF_TEST(SurfaceGetTexture, reporter) {
549 SkAutoTUnref<SkSurface> surface(create_surface());
junov@chromium.orgda904742013-05-01 22:38:16 +0000550 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
kkinnunen179a8f52015-11-20 13:32:24 -0800551 REPORTER_ASSERT(reporter, as_IB(image)->getTexture() == nullptr);
552 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
553 REPORTER_ASSERT(reporter, as_IB(image)->getTexture() == nullptr);
554}
555#if SK_SUPPORT_GPU
556DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceGetTexture_Gpu, reporter, context) {
557 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
558 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaType, nullptr));
559 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
560 GrTexture* texture = as_IB(image)->getTexture();
bsalomon49f085d2014-09-05 13:34:00 -0700561 REPORTER_ASSERT(reporter, texture);
junov@chromium.orgda904742013-05-01 22:38:16 +0000562 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle());
kkinnunen179a8f52015-11-20 13:32:24 -0800563 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
564 REPORTER_ASSERT(reporter, as_IB(image)->getTexture() == texture);
junov@chromium.orgda904742013-05-01 22:38:16 +0000565 }
junov@chromium.orgda904742013-05-01 22:38:16 +0000566}
kkinnunen179a8f52015-11-20 13:32:24 -0800567#endif
bsalomoneaaaf0b2015-01-23 08:08:04 -0800568
kkinnunen179a8f52015-11-20 13:32:24 -0800569#if SK_SUPPORT_GPU
bsalomon3582d3e2015-02-13 14:20:05 -0800570#include "GrGpuResourcePriv.h"
bsalomoneaaaf0b2015-01-23 08:08:04 -0800571#include "SkGpuDevice.h"
572#include "SkImage_Gpu.h"
573#include "SkSurface_Gpu.h"
574
kkinnunen179a8f52015-11-20 13:32:24 -0800575static SkSurface::Budgeted is_budgeted(SkSurface* surf) {
bsalomon3582d3e2015-02-13 14:20:05 -0800576 return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->resourcePriv().isBudgeted() ?
bsalomoneaaaf0b2015-01-23 08:08:04 -0800577 SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
578}
579
kkinnunen179a8f52015-11-20 13:32:24 -0800580static SkSurface::Budgeted is_budgeted(SkImage* image) {
bsalomon3582d3e2015-02-13 14:20:05 -0800581 return ((SkImage_Gpu*)image)->getTexture()->resourcePriv().isBudgeted() ?
bsalomoneaaaf0b2015-01-23 08:08:04 -0800582 SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
583}
584
kkinnunen179a8f52015-11-20 13:32:24 -0800585DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, context) {
bsalomoneaaaf0b2015-01-23 08:08:04 -0800586 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8);
587 for (int i = 0; i < 2; ++i) {
588 SkSurface::Budgeted sbudgeted = i ? SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
589 for (int j = 0; j < 2; ++j) {
590 SkSurface::Budgeted ibudgeted = j ? SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
591 SkAutoTUnref<SkSurface>
592 surface(SkSurface::NewRenderTarget(context, sbudgeted, info, 0));
593 SkASSERT(surface);
594 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface));
595
mtklein31ff2982015-01-24 11:27:27 -0800596 SkAutoTUnref<SkImage> image(surface->newImageSnapshot(ibudgeted));
bsalomoneaaaf0b2015-01-23 08:08:04 -0800597
598 // Initially the image shares a texture with the surface, and the surface decides
599 // whether it is budgeted or not.
600 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface));
601 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(image));
602
603 // Now trigger copy-on-write
604 surface->getCanvas()->clear(SK_ColorBLUE);
605
606 // They don't share a texture anymore. They should each have made their own budget
607 // decision.
608 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface));
609 REPORTER_ASSERT(reporter, ibudgeted == is_budgeted(image));
610 }
611 }
612}
junov@chromium.orgb516a412013-05-01 22:49:59 +0000613#endif
junov@chromium.orgda904742013-05-01 22:38:16 +0000614
kkinnunen179a8f52015-11-20 13:32:24 -0800615static void test_no_canvas1(skiatest::Reporter* reporter,
616 SkSurface* surface,
617 SkSurface::ContentChangeMode mode) {
618 // Test passes by not asserting
619 surface->notifyContentWillChange(mode);
620 SkDEBUGCODE(surface->validate();)
621}
622static void test_no_canvas2(skiatest::Reporter* reporter,
623 SkSurface* surface,
624 SkSurface::ContentChangeMode mode) {
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000625 // Verifies the robustness of SkSurface for handling use cases where calls
626 // are made before a canvas is created.
kkinnunen179a8f52015-11-20 13:32:24 -0800627 SkImage* image1 = surface->newImageSnapshot();
628 SkAutoTUnref<SkImage> aur_image1(image1);
629 SkDEBUGCODE(image1->validate();)
630 SkDEBUGCODE(surface->validate();)
631 surface->notifyContentWillChange(mode);
632 SkDEBUGCODE(image1->validate();)
633 SkDEBUGCODE(surface->validate();)
634 SkImage* image2 = surface->newImageSnapshot();
635 SkAutoTUnref<SkImage> aur_image2(image2);
636 SkDEBUGCODE(image2->validate();)
637 SkDEBUGCODE(surface->validate();)
638 REPORTER_ASSERT(reporter, image1 != image2);
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000639}
kkinnunen179a8f52015-11-20 13:32:24 -0800640DEF_TEST(SurfaceNoCanvas, reporter) {
641 SkSurface::ContentChangeMode modes[] =
642 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentChangeMode};
643 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) {
644 for (auto& mode : modes) {
645 SkAutoTUnref<SkSurface> surface(create_surface());
646 test_func(reporter, surface, mode);
647 }
648 }
649}
junov@chromium.orgb516a412013-05-01 22:49:59 +0000650#if SK_SUPPORT_GPU
kkinnunen179a8f52015-11-20 13:32:24 -0800651DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, context) {
652 SkSurface::ContentChangeMode modes[] =
653 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentChangeMode};
654 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
655 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) {
656 for (auto& mode : modes) {
657 SkAutoTUnref<SkSurface> surface(
658 surface_func(context, kPremul_SkAlphaType, nullptr));
659 test_func(reporter, surface, mode);
bsalomone904c092014-07-17 10:50:59 -0700660 }
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000661 }
junov@chromium.orgaf058352013-04-03 15:03:26 +0000662 }
junov@chromium.org995beb62013-03-28 13:49:22 +0000663}
kkinnunen179a8f52015-11-20 13:32:24 -0800664#endif
reed9cd016e2016-01-30 10:01:06 -0800665
666static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Reporter* reporter) {
667 SkImageInfo info;
668 size_t rowBytes;
669 REPORTER_ASSERT(reporter, surface->peekPixels(&info, &rowBytes));
670
671 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
672 SkImageInfo im_info;
673 size_t im_rowbytes;
674 REPORTER_ASSERT(reporter, image->peekPixels(&im_info, &im_rowbytes));
675
676 REPORTER_ASSERT(reporter, rowBytes == im_rowbytes);
677
678 // trigger a copy-on-write
679 surface->getCanvas()->drawPaint(SkPaint());
680 SkAutoTUnref<SkImage> image2(surface->newImageSnapshot());
681 REPORTER_ASSERT(reporter, image->uniqueID() != image2->uniqueID());
682
683 SkImageInfo im_info2;
684 size_t im_rowbytes2;
685 REPORTER_ASSERT(reporter, image2->peekPixels(&im_info2, &im_rowbytes2));
686
687 REPORTER_ASSERT(reporter, im_rowbytes2 == im_rowbytes);
688}
689
690DEF_TEST(surface_rowbytes, reporter) {
691 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
692
693 SkAutoTUnref<SkSurface> surf0(SkSurface::NewRaster(info));
694 check_rowbytes_remain_consistent(surf0, reporter);
695
696 // specify a larger rowbytes
697 SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info, 500, nullptr));
698 check_rowbytes_remain_consistent(surf1, reporter);
699
700 // Try some illegal rowByte values
701 SkSurface* s = SkSurface::NewRaster(info, 396, nullptr); // needs to be at least 400
702 REPORTER_ASSERT(reporter, nullptr == s);
703 s = SkSurface::NewRaster(info, 1 << 30, nullptr); // allocation to large
704 REPORTER_ASSERT(reporter, nullptr == s);
705}
bsalomone63ffef2016-02-05 07:17:34 -0800706
707#if SK_SUPPORT_GPU
708
709void test_surface_clear(skiatest::Reporter* reporter, SkSurface* surface,
710 std::function<GrSurface*(SkSurface*)> grSurfaceGetter,
711 uint32_t expectedValue) {
712 if (!surface) {
713 ERRORF(reporter, "Could not create GPU SkSurface.");
714 return;
715 }
716 int w = surface->width();
717 int h = surface->height();
718 SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[w * h]);
719 memset(pixels.get(), ~expectedValue, sizeof(uint32_t) * w * h);
720
721 SkAutoTUnref<GrSurface> grSurface(SkSafeRef(grSurfaceGetter(surface)));
722 if (!grSurface) {
723 ERRORF(reporter, "Could access render target of GPU SkSurface.");
724 return;
725 }
726 SkASSERT(surface->unique());
727 surface->unref();
728 grSurface->readPixels(0, 0, w, h, kRGBA_8888_GrPixelConfig, pixels.get());
729 for (int y = 0; y < h; ++y) {
730 for (int x = 0; x < w; ++x) {
731 uint32_t pixel = pixels.get()[y * w + x];
732 if (pixel != expectedValue) {
733 SkString msg;
734 if (expectedValue) {
735 msg = "SkSurface should have left render target unmodified";
736 } else {
737 msg = "SkSurface should have cleared the render target";
738 }
739 ERRORF(reporter,
740 "%s but read 0x%08x (instead of 0x%08x) at %x,%d", msg.c_str(), pixel,
741 expectedValue, x, y);
742 return;
743 }
744 }
745 }
746}
747
748DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, context) {
749 std::function<GrSurface*(SkSurface*)> grSurfaceGetters[] = {
750 [] (SkSurface* s){ return s->getCanvas()->internal_private_accessTopLayerRenderTarget();},
751 [] (SkSurface* s){
752 SkBaseDevice* d =
753 s->getCanvas()->getDevice_just_for_deprecated_compatibility_testing();
754 return d->accessRenderTarget(); },
755 [] (SkSurface* s){ SkImage* i = s->newImageSnapshot();
756 return i->getTexture(); },
757 [] (SkSurface* s){ SkImage* i = s->newImageSnapshot();
758 return as_IB(i)->peekTexture(); },
759 };
760 for (auto grSurfaceGetter : grSurfaceGetters) {
761 for (auto& surface_func : {&create_gpu_surface, &create_gpu_scratch_surface}) {
762 SkSurface* surface(surface_func(context, kPremul_SkAlphaType, nullptr));
763 test_surface_clear(reporter, surface, grSurfaceGetter, 0x0);
764 }
765 // Wrapped RTs are *not* supposed to clear (to allow client to partially update a surface).
766 static const int kWidth = 10;
767 static const int kHeight = 10;
768 SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[kWidth * kHeight]);
769 memset(pixels.get(), 0xAB, sizeof(uint32_t) * kWidth * kHeight);
770
771 GrBackendObject textureObject =
772 context->getGpu()->createTestingOnlyBackendTexture(pixels.get(), kWidth, kHeight,
773 kRGBA_8888_GrPixelConfig);
774
775 GrBackendTextureDesc desc;
776 desc.fConfig = kRGBA_8888_GrPixelConfig;
777 desc.fWidth = kWidth;
778 desc.fHeight = kHeight;
779 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
780 desc.fTextureHandle = textureObject;
781
782 SkSurface* surface = SkSurface::NewFromBackendTexture(context, desc, nullptr);
783 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB);
784 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject);
785 }
786}
787#endif