junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 7 | |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 8 | #include <functional> |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 9 | #include "SkCanvas.h" |
reed@google.com | 4f7c615 | 2014-02-06 14:11:56 +0000 | [diff] [blame] | 10 | #include "SkData.h" |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 11 | #include "SkDevice.h" |
bsalomon | 5581236 | 2015-06-10 08:49:28 -0700 | [diff] [blame] | 12 | #include "SkImage_Base.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 13 | #include "SkPath.h" |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 14 | #include "SkRRect.h" |
| 15 | #include "SkSurface.h" |
reed@google.com | 4f7c615 | 2014-02-06 14:11:56 +0000 | [diff] [blame] | 16 | #include "SkUtils.h" |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 17 | #include "Test.h" |
| 18 | |
| 19 | #if SK_SUPPORT_GPU |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 20 | #include "GrContext.h" |
| 21 | #include "GrGpu.h" |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 22 | #endif |
| 23 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 24 | #include <initializer_list> |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 25 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 26 | static void release_direct_surface_storage(void* pixels, void* context) { |
reed | 982542d | 2014-06-27 06:48:14 -0700 | [diff] [blame] | 27 | SkASSERT(pixels == context); |
| 28 | sk_free(pixels); |
| 29 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 30 | static SkSurface* create_surface(SkAlphaType at = kPremul_SkAlphaType, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 31 | SkImageInfo* requestedInfo = nullptr) { |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 32 | const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 33 | if (requestedInfo) { |
| 34 | *requestedInfo = info; |
| 35 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 36 | return SkSurface::NewRaster(info); |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 37 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 38 | static 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 |
| 51 | static 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 | } |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 57 | return SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 58 | } |
| 59 | static 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 | } |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 66 | return SkSurface::NewRenderTarget(context, SkBudgeted::kYes, info, 0, nullptr); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 67 | } |
| 68 | #endif |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 69 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 70 | DEF_TEST(SurfaceEmpty, reporter) { |
reed | b2497c2 | 2014-12-31 12:31:43 -0800 | [diff] [blame] | 71 | const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 72 | REPORTER_ASSERT(reporter, nullptr == SkSurface::NewRaster(info)); |
| 73 | REPORTER_ASSERT(reporter, nullptr == SkSurface::NewRasterDirect(info, nullptr, 0)); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 74 | |
reed | b2497c2 | 2014-12-31 12:31:43 -0800 | [diff] [blame] | 75 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 76 | #if SK_SUPPORT_GPU |
| 77 | DEF_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 == |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 80 | SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr)); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 81 | } |
| 82 | #endif |
reed | b2497c2 | 2014-12-31 12:31:43 -0800 | [diff] [blame] | 83 | |
bsalomon | e4579ad | 2015-04-08 08:38:40 -0700 | [diff] [blame] | 84 | #if SK_SUPPORT_GPU |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 85 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, context) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 86 | GrGpu* gpu = context->getGpu(); |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 87 | if (!gpu) { |
bsalomon | e4579ad | 2015-04-08 08:38:40 -0700 | [diff] [blame] | 88 | return; |
| 89 | } |
bsalomon | 7a61793 | 2015-06-16 08:07:16 -0700 | [diff] [blame] | 90 | |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 91 | // Test the wrapped factory for SkSurface by creating a backend texture and then wrap it in |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 92 | // a SkSurface. |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 93 | 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); |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 98 | GrBackendObject texHandle = gpu->createTestingOnlyBackendTexture(pixels.get(), kW, kH, |
| 99 | kRGBA_8888_GrPixelConfig); |
bsalomon | e4579ad | 2015-04-08 08:38:40 -0700 | [diff] [blame] | 100 | |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 101 | 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; |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 108 | wrappedDesc.fTextureHandle = texHandle; |
bsalomon | e4579ad | 2015-04-08 08:38:40 -0700 | [diff] [blame] | 109 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 110 | SkAutoTUnref<SkSurface> surface( |
| 111 | SkSurface::NewWrappedRenderTarget(context, wrappedDesc, nullptr)); |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 112 | 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; |
bsalomon | 7a61793 | 2015-06-16 08:07:16 -0700 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | } |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 140 | 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 | } |
bsalomon | 7a61793 | 2015-06-16 08:07:16 -0700 | [diff] [blame] | 148 | } |
| 149 | } |
bsalomon | 67d7620 | 2015-11-11 12:40:42 -0800 | [diff] [blame] | 150 | gpu->deleteTestingOnlyBackendTexture(texHandle); |
bsalomon | e4579ad | 2015-04-08 08:38:40 -0700 | [diff] [blame] | 151 | } |
| 152 | #endif |
| 153 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 154 | static void test_canvas_peek(skiatest::Reporter* reporter, |
| 155 | SkSurface* surface, |
| 156 | const SkImageInfo& requestInfo, |
| 157 | bool expectPeekSuccess) { |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 158 | const SkColor color = SK_ColorRED; |
| 159 | const SkPMColor pmcolor = SkPreMultiplyColor(color); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 160 | SkImageInfo info; |
| 161 | size_t rowBytes; |
| 162 | surface->getCanvas()->clear(color); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 163 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 164 | const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes); |
| 165 | bool success = SkToBool(addr); |
| 166 | REPORTER_ASSERT(reporter, expectPeekSuccess == success); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 167 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 168 | SkImageInfo info2; |
| 169 | size_t rb2; |
| 170 | const void* addr2 = surface->peekPixels(&info2, &rb2); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 171 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 172 | 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.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 176 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 177 | 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.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 184 | DEF_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 |
| 192 | DEF_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.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 200 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 201 | // 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. |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 205 | void test_access_pixels(skiatest::Reporter* reporter, SkSurface* surface) { |
| 206 | SkCanvas* canvas = surface->getCanvas(); |
| 207 | canvas->clear(0); |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 208 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 209 | 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 | } |
| 218 | DEF_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 |
| 225 | DEF_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 | |
| 233 | static 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)); |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 244 | DEF_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); |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 253 | #if SK_SUPPORT_GPU |
| 254 | DEF_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 |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 264 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 265 | static GrBackendObject get_surface_backend_texture_handle( |
| 266 | SkSurface* s, SkSurface::BackendHandleAccess a) { |
| 267 | return s->getTextureHandle(a); |
| 268 | } |
| 269 | static 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 | |
| 278 | static void test_backend_handle_access_copy_on_write( |
| 279 | skiatest::Reporter* reporter, SkSurface* surface, SkSurface::BackendHandleAccess mode, |
| 280 | GrBackendObject (*func)(SkSurface*, SkSurface::BackendHandleAccess)) { |
fmalita | e263908 | 2015-08-06 07:04:51 -0700 | [diff] [blame] | 281 | 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 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 290 | DEF_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 |
| 306 | DEF_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 |
fmalita | e263908 | 2015-08-06 07:04:51 -0700 | [diff] [blame] | 325 | |
bsalomon | f47b9a3 | 2016-02-22 11:02:58 -0800 | [diff] [blame] | 326 | static bool same_image(SkImage* a, SkImage* b, |
| 327 | std::function<intptr_t(SkImage*)> getImageBackingStore) { |
| 328 | return getImageBackingStore(a) == getImageBackingStore(b); |
| 329 | } |
| 330 | |
| 331 | static bool same_image_surf(SkImage* a, SkSurface* b, |
| 332 | std::function<intptr_t(SkImage*)> getImageBackingStore, |
| 333 | std::function<intptr_t(SkSurface*)> getSurfaceBackingStore) { |
| 334 | return getImageBackingStore(a) == getSurfaceBackingStore(b); |
| 335 | } |
| 336 | |
| 337 | static void test_unique_image_snap(skiatest::Reporter* reporter, SkSurface* surface, |
| 338 | bool surfaceIsDirect, |
| 339 | std::function<intptr_t(SkImage*)> imageBackingStore, |
| 340 | std::function<intptr_t(SkSurface*)> surfaceBackingStore) { |
| 341 | std::function<intptr_t(SkImage*)> ibs = imageBackingStore; |
| 342 | std::function<intptr_t(SkSurface*)> sbs = surfaceBackingStore; |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 343 | static const SkBudgeted kB = SkBudgeted::kNo; |
bsalomon | f47b9a3 | 2016-02-22 11:02:58 -0800 | [diff] [blame] | 344 | { |
| 345 | SkAutoTUnref<SkImage> image(surface->newImageSnapshot(kB, SkSurface::kYes_ForceUnique)); |
| 346 | REPORTER_ASSERT(reporter, !same_image_surf(image, surface, ibs, sbs)); |
| 347 | REPORTER_ASSERT(reporter, image->unique()); |
| 348 | } |
| 349 | { |
| 350 | SkAutoTUnref<SkImage> image1(surface->newImageSnapshot(kB, SkSurface::kYes_ForceUnique)); |
| 351 | REPORTER_ASSERT(reporter, !same_image_surf(image1, surface, ibs, sbs)); |
| 352 | REPORTER_ASSERT(reporter, image1->unique()); |
| 353 | SkAutoTUnref<SkImage> image2(surface->newImageSnapshot(kB, SkSurface::kYes_ForceUnique)); |
| 354 | REPORTER_ASSERT(reporter, !same_image_surf(image2, surface, ibs, sbs)); |
| 355 | REPORTER_ASSERT(reporter, !same_image(image1, image2, ibs)); |
| 356 | REPORTER_ASSERT(reporter, image2->unique()); |
| 357 | } |
| 358 | { |
| 359 | SkAutoTUnref<SkImage> image1(surface->newImageSnapshot(kB, SkSurface::kNo_ForceUnique)); |
| 360 | SkAutoTUnref<SkImage> image2(surface->newImageSnapshot(kB, SkSurface::kYes_ForceUnique)); |
| 361 | SkAutoTUnref<SkImage> image3(surface->newImageSnapshot(kB, SkSurface::kNo_ForceUnique)); |
| 362 | SkAutoTUnref<SkImage> image4(surface->newImageSnapshot(kB, SkSurface::kYes_ForceUnique)); |
| 363 | // Image 1 and 3 ought to be the same (or we're missing an optimization). |
| 364 | REPORTER_ASSERT(reporter, same_image(image1, image3, ibs)); |
| 365 | // If the surface is not direct then images 1 and 3 should alias the surface's |
| 366 | // store. |
| 367 | REPORTER_ASSERT(reporter, !surfaceIsDirect == same_image_surf(image1, surface, ibs, sbs)); |
| 368 | // Image 2 should not be shared with any other image. |
| 369 | REPORTER_ASSERT(reporter, !same_image(image1, image2, ibs) && |
| 370 | !same_image(image3, image2, ibs) && |
| 371 | !same_image(image4, image2, ibs)); |
| 372 | REPORTER_ASSERT(reporter, image2->unique()); |
| 373 | REPORTER_ASSERT(reporter, !same_image_surf(image2, surface, ibs, sbs)); |
| 374 | // Image 4 should not be shared with any other image. |
| 375 | REPORTER_ASSERT(reporter, !same_image(image1, image4, ibs) && |
| 376 | !same_image(image3, image4, ibs)); |
| 377 | REPORTER_ASSERT(reporter, !same_image_surf(image4, surface, ibs, sbs)); |
| 378 | REPORTER_ASSERT(reporter, image4->unique()); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | DEF_TEST(UniqueImageSnapshot, reporter) { |
| 383 | auto getImageBackingStore = [reporter](SkImage* image) { |
| 384 | SkPixmap pm; |
| 385 | bool success = image->peekPixels(&pm); |
| 386 | REPORTER_ASSERT(reporter, success); |
| 387 | return reinterpret_cast<intptr_t>(pm.addr()); |
| 388 | }; |
| 389 | auto getSufaceBackingStore = [reporter](SkSurface* surface) { |
| 390 | SkImageInfo info; |
| 391 | size_t rowBytes; |
| 392 | const void* pixels = surface->getCanvas()->peekPixels(&info, &rowBytes); |
| 393 | REPORTER_ASSERT(reporter, pixels); |
| 394 | return reinterpret_cast<intptr_t>(pixels); |
| 395 | }; |
| 396 | |
| 397 | SkAutoTUnref<SkSurface> surface(create_surface()); |
| 398 | test_unique_image_snap(reporter, surface, false, getImageBackingStore, getSufaceBackingStore); |
| 399 | surface.reset(create_direct_surface()); |
| 400 | test_unique_image_snap(reporter, surface, true, getImageBackingStore, getSufaceBackingStore); |
| 401 | } |
| 402 | |
| 403 | #if SK_SUPPORT_GPU |
| 404 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, context) { |
| 405 | for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { |
| 406 | SkAutoTUnref<SkSurface> surface(surface_func(context, kOpaque_SkAlphaType, nullptr)); |
| 407 | |
| 408 | auto imageBackingStore = [reporter](SkImage* image) { |
| 409 | GrTexture* texture = as_IB(image)->peekTexture(); |
| 410 | if (!texture) { |
| 411 | ERRORF(reporter, "Not texture backed."); |
| 412 | return static_cast<intptr_t>(0); |
| 413 | } |
| 414 | return static_cast<intptr_t>(texture->getUniqueID()); |
| 415 | }; |
| 416 | |
| 417 | auto surfaceBackingStore = [reporter](SkSurface* surface) { |
| 418 | GrRenderTarget* rt = |
| 419 | surface->getCanvas()->internal_private_accessTopLayerRenderTarget(); |
| 420 | if (!rt) { |
| 421 | ERRORF(reporter, "Not render target backed."); |
| 422 | return static_cast<intptr_t>(0); |
| 423 | } |
| 424 | return static_cast<intptr_t>(rt->getUniqueID()); |
| 425 | }; |
| 426 | |
| 427 | test_unique_image_snap(reporter, surface, false, imageBackingStore, surfaceBackingStore); |
| 428 | |
| 429 | // Test again with a "direct" render target; |
| 430 | GrBackendObject textureObject = context->getGpu()->createTestingOnlyBackendTexture(nullptr, |
| 431 | 10, 10, kRGBA_8888_GrPixelConfig); |
| 432 | GrBackendTextureDesc desc; |
| 433 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 434 | desc.fWidth = 10; |
| 435 | desc.fHeight = 10; |
| 436 | desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 437 | desc.fTextureHandle = textureObject; |
| 438 | GrTexture* texture = context->textureProvider()->wrapBackendTexture(desc); |
| 439 | { |
| 440 | SkAutoTUnref<SkSurface> surface( |
| 441 | SkSurface::NewRenderTargetDirect(texture->asRenderTarget())); |
bsalomon | b2c0133 | 2016-02-26 10:37:26 -0800 | [diff] [blame] | 442 | test_unique_image_snap(reporter, surface, true, imageBackingStore, |
bsalomon | f47b9a3 | 2016-02-22 11:02:58 -0800 | [diff] [blame] | 443 | surfaceBackingStore); |
| 444 | } |
| 445 | texture->unref(); |
| 446 | context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); |
| 447 | } |
| 448 | } |
| 449 | #endif |
| 450 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 451 | #if SK_SUPPORT_GPU |
| 452 | // May we (soon) eliminate the need to keep testing this, by hiding the bloody device! |
| 453 | static uint32_t get_legacy_gen_id(SkSurface* surface) { |
| 454 | SkBaseDevice* device = |
| 455 | surface->getCanvas()->getDevice_just_for_deprecated_compatibility_testing(); |
| 456 | return device->accessBitmap(false).getGenerationID(); |
| 457 | } |
| 458 | /* |
| 459 | * Test legacy behavor of bumping the surface's device's bitmap's genID when we access its |
| 460 | * texture handle for writing. |
| 461 | * |
| 462 | * Note: this needs to be tested separately from checking newImageSnapshot, as calling that |
| 463 | * can also incidentally bump the genID (when a new backing surface is created). |
| 464 | */ |
| 465 | static void test_backend_handle_gen_id( |
| 466 | skiatest::Reporter* reporter, SkSurface* surface, |
| 467 | GrBackendObject (*func)(SkSurface*, SkSurface::BackendHandleAccess)) { |
| 468 | const uint32_t gen0 = get_legacy_gen_id(surface); |
| 469 | func(surface, SkSurface::kFlushRead_BackendHandleAccess); |
| 470 | const uint32_t gen1 = get_legacy_gen_id(surface); |
| 471 | REPORTER_ASSERT(reporter, gen0 == gen1); |
| 472 | |
| 473 | func(surface, SkSurface::kFlushWrite_BackendHandleAccess); |
| 474 | const uint32_t gen2 = get_legacy_gen_id(surface); |
| 475 | REPORTER_ASSERT(reporter, gen0 != gen2); |
| 476 | |
| 477 | func(surface, SkSurface::kDiscardWrite_BackendHandleAccess); |
| 478 | const uint32_t gen3 = get_legacy_gen_id(surface); |
| 479 | REPORTER_ASSERT(reporter, gen0 != gen3); |
| 480 | REPORTER_ASSERT(reporter, gen2 != gen3); |
| 481 | } |
| 482 | static void test_backend_handle_unique_id( |
| 483 | skiatest::Reporter* reporter, SkSurface* surface, |
| 484 | GrBackendObject (*func)(SkSurface*, SkSurface::BackendHandleAccess)) { |
| 485 | SkAutoTUnref<SkImage> image0(surface->newImageSnapshot()); |
| 486 | GrBackendObject obj = func(surface, SkSurface::kFlushRead_BackendHandleAccess); |
| 487 | REPORTER_ASSERT(reporter, obj != 0); |
| 488 | SkAutoTUnref<SkImage> image1(surface->newImageSnapshot()); |
| 489 | // just read access should not affect the snapshot |
| 490 | REPORTER_ASSERT(reporter, image0->uniqueID() == image1->uniqueID()); |
| 491 | |
| 492 | obj = func(surface, SkSurface::kFlushWrite_BackendHandleAccess); |
| 493 | REPORTER_ASSERT(reporter, obj != 0); |
| 494 | SkAutoTUnref<SkImage> image2(surface->newImageSnapshot()); |
| 495 | // expect a new image, since we claimed we would write |
| 496 | REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID()); |
| 497 | |
| 498 | obj = func(surface, SkSurface::kDiscardWrite_BackendHandleAccess); |
| 499 | REPORTER_ASSERT(reporter, obj != 0); |
| 500 | SkAutoTUnref<SkImage> image3(surface->newImageSnapshot()); |
| 501 | // expect a new(er) image, since we claimed we would write |
| 502 | REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID()); |
| 503 | REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID()); |
| 504 | } |
| 505 | // No CPU test. |
| 506 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter, context) { |
| 507 | for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { |
| 508 | for (auto& test_func : { &test_backend_handle_unique_id, &test_backend_handle_gen_id }) { |
| 509 | for (auto& handle_access_func : |
| 510 | { &get_surface_backend_texture_handle, &get_surface_backend_render_target_handle}) { |
| 511 | SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaType, |
| 512 | nullptr)); |
| 513 | test_func(reporter, surface, handle_access_func); |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | #endif |
| 519 | |
| 520 | // Verify that the right canvas commands trigger a copy on write. |
| 521 | static void test_copy_on_write(skiatest::Reporter* reporter, SkSurface* surface) { |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 522 | SkCanvas* canvas = surface->getCanvas(); |
| 523 | |
| 524 | const SkRect testRect = |
| 525 | SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| 526 | SkIntToScalar(4), SkIntToScalar(5)); |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 527 | SkPath testPath; |
| 528 | testPath.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| 529 | SkIntToScalar(2), SkIntToScalar(1))); |
| 530 | |
| 531 | const SkIRect testIRect = SkIRect::MakeXYWH(0, 0, 2, 1); |
| 532 | |
| 533 | SkRegion testRegion; |
| 534 | testRegion.setRect(testIRect); |
| 535 | |
| 536 | |
| 537 | const SkColor testColor = 0x01020304; |
| 538 | const SkPaint testPaint; |
| 539 | const SkPoint testPoints[3] = { |
| 540 | {SkIntToScalar(0), SkIntToScalar(0)}, |
| 541 | {SkIntToScalar(2), SkIntToScalar(1)}, |
| 542 | {SkIntToScalar(0), SkIntToScalar(2)} |
| 543 | }; |
| 544 | const size_t testPointCount = 3; |
| 545 | |
| 546 | SkBitmap testBitmap; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 547 | testBitmap.allocN32Pixels(10, 10); |
robertphillips@google.com | d1ce77d | 2013-10-09 12:51:09 +0000 | [diff] [blame] | 548 | testBitmap.eraseColor(0); |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 549 | |
| 550 | SkRRect testRRect; |
| 551 | testRRect.setRectXY(testRect, SK_Scalar1, SK_Scalar1); |
| 552 | |
| 553 | SkString testText("Hello World"); |
| 554 | const SkPoint testPoints2[] = { |
| 555 | { SkIntToScalar(0), SkIntToScalar(1) }, |
| 556 | { SkIntToScalar(1), SkIntToScalar(1) }, |
| 557 | { SkIntToScalar(2), SkIntToScalar(1) }, |
| 558 | { SkIntToScalar(3), SkIntToScalar(1) }, |
| 559 | { SkIntToScalar(4), SkIntToScalar(1) }, |
| 560 | { SkIntToScalar(5), SkIntToScalar(1) }, |
| 561 | { SkIntToScalar(6), SkIntToScalar(1) }, |
| 562 | { SkIntToScalar(7), SkIntToScalar(1) }, |
| 563 | { SkIntToScalar(8), SkIntToScalar(1) }, |
| 564 | { SkIntToScalar(9), SkIntToScalar(1) }, |
| 565 | { SkIntToScalar(10), SkIntToScalar(1) }, |
| 566 | }; |
| 567 | |
| 568 | #define EXPECT_COPY_ON_WRITE(command) \ |
| 569 | { \ |
junov@chromium.org | 5ee449a | 2013-04-12 20:20:50 +0000 | [diff] [blame] | 570 | SkImage* imageBefore = surface->newImageSnapshot(); \ |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 571 | SkAutoTUnref<SkImage> aur_before(imageBefore); \ |
| 572 | canvas-> command ; \ |
junov@chromium.org | 5ee449a | 2013-04-12 20:20:50 +0000 | [diff] [blame] | 573 | SkImage* imageAfter = surface->newImageSnapshot(); \ |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 574 | SkAutoTUnref<SkImage> aur_after(imageAfter); \ |
| 575 | REPORTER_ASSERT(reporter, imageBefore != imageAfter); \ |
| 576 | } |
| 577 | |
| 578 | EXPECT_COPY_ON_WRITE(clear(testColor)) |
| 579 | EXPECT_COPY_ON_WRITE(drawPaint(testPaint)) |
| 580 | EXPECT_COPY_ON_WRITE(drawPoints(SkCanvas::kPoints_PointMode, testPointCount, testPoints, \ |
| 581 | testPaint)) |
| 582 | EXPECT_COPY_ON_WRITE(drawOval(testRect, testPaint)) |
| 583 | EXPECT_COPY_ON_WRITE(drawRect(testRect, testPaint)) |
| 584 | EXPECT_COPY_ON_WRITE(drawRRect(testRRect, testPaint)) |
| 585 | EXPECT_COPY_ON_WRITE(drawPath(testPath, testPaint)) |
| 586 | EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0)) |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 587 | EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, testRect, nullptr)) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 588 | EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, nullptr)) |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 589 | EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testPaint)) |
| 590 | EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoints2, \ |
| 591 | testPaint)) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 592 | EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testPath, nullptr, \ |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 593 | testPaint)) |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 594 | } |
| 595 | DEF_TEST(SurfaceCopyOnWrite, reporter) { |
| 596 | SkAutoTUnref<SkSurface> surface(create_surface()); |
| 597 | test_copy_on_write(reporter, surface); |
| 598 | } |
| 599 | #if SK_SUPPORT_GPU |
| 600 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, context) { |
| 601 | for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { |
| 602 | SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaType, nullptr)); |
| 603 | test_copy_on_write(reporter, surface); |
fmalita | e263908 | 2015-08-06 07:04:51 -0700 | [diff] [blame] | 604 | } |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 605 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 606 | #endif |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 607 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 608 | static void test_writable_after_snapshot_release(skiatest::Reporter* reporter, |
| 609 | SkSurface* surface) { |
junov@chromium.org | af05835 | 2013-04-03 15:03:26 +0000 | [diff] [blame] | 610 | // This test succeeds by not triggering an assertion. |
| 611 | // The test verifies that the surface remains writable (usable) after |
| 612 | // acquiring and releasing a snapshot without triggering a copy on write. |
junov@chromium.org | af05835 | 2013-04-03 15:03:26 +0000 | [diff] [blame] | 613 | SkCanvas* canvas = surface->getCanvas(); |
| 614 | canvas->clear(1); |
junov@chromium.org | 5ee449a | 2013-04-12 20:20:50 +0000 | [diff] [blame] | 615 | surface->newImageSnapshot()->unref(); // Create and destroy SkImage |
commit-bot@chromium.org | 4d24b74 | 2013-07-25 23:29:40 +0000 | [diff] [blame] | 616 | canvas->clear(2); // Must not assert internally |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 617 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 618 | DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) { |
| 619 | SkAutoTUnref<SkSurface> surface(create_surface()); |
| 620 | test_writable_after_snapshot_release(reporter, surface); |
| 621 | } |
| 622 | #if SK_SUPPORT_GPU |
| 623 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu, reporter, context) { |
| 624 | for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { |
| 625 | SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaType, nullptr)); |
| 626 | test_writable_after_snapshot_release(reporter, surface); |
| 627 | } |
| 628 | } |
| 629 | #endif |
junov@chromium.org | da90474 | 2013-05-01 22:38:16 +0000 | [diff] [blame] | 630 | |
junov@chromium.org | b516a41 | 2013-05-01 22:49:59 +0000 | [diff] [blame] | 631 | #if SK_SUPPORT_GPU |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 632 | static void test_crbug263329(skiatest::Reporter* reporter, |
| 633 | SkSurface* surface1, |
| 634 | SkSurface* surface2) { |
commit-bot@chromium.org | 4d24b74 | 2013-07-25 23:29:40 +0000 | [diff] [blame] | 635 | // This is a regression test for crbug.com/263329 |
| 636 | // Bug was caused by onCopyOnWrite releasing the old surface texture |
| 637 | // back to the scratch texture pool even though the texture is used |
| 638 | // by and active SkImage_Gpu. |
commit-bot@chromium.org | 4d24b74 | 2013-07-25 23:29:40 +0000 | [diff] [blame] | 639 | SkCanvas* canvas1 = surface1->getCanvas(); |
| 640 | SkCanvas* canvas2 = surface2->getCanvas(); |
| 641 | canvas1->clear(1); |
| 642 | SkAutoTUnref<SkImage> image1(surface1->newImageSnapshot()); |
| 643 | // Trigger copy on write, new backing is a scratch texture |
| 644 | canvas1->clear(2); |
| 645 | SkAutoTUnref<SkImage> image2(surface1->newImageSnapshot()); |
| 646 | // Trigger copy on write, old backing should not be returned to scratch |
| 647 | // pool because it is held by image2 |
| 648 | canvas1->clear(3); |
| 649 | |
| 650 | canvas2->clear(4); |
| 651 | SkAutoTUnref<SkImage> image3(surface2->newImageSnapshot()); |
| 652 | // Trigger copy on write on surface2. The new backing store should not |
| 653 | // be recycling a texture that is held by an existing image. |
| 654 | canvas2->clear(5); |
| 655 | SkAutoTUnref<SkImage> image4(surface2->newImageSnapshot()); |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame^] | 656 | REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image3)->peekTexture()); |
commit-bot@chromium.org | 4d24b74 | 2013-07-25 23:29:40 +0000 | [diff] [blame] | 657 | // The following assertion checks crbug.com/263329 |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame^] | 658 | REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image2)->peekTexture()); |
| 659 | REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image1)->peekTexture()); |
| 660 | REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image2)->peekTexture()); |
| 661 | REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image1)->peekTexture()); |
| 662 | REPORTER_ASSERT(reporter, as_IB(image2)->peekTexture() != as_IB(image1)->peekTexture()); |
commit-bot@chromium.org | 4d24b74 | 2013-07-25 23:29:40 +0000 | [diff] [blame] | 663 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 664 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, context) { |
| 665 | for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { |
| 666 | SkAutoTUnref<SkSurface> surface1(surface_func(context, kPremul_SkAlphaType, nullptr)); |
| 667 | SkAutoTUnref<SkSurface> surface2(surface_func(context, kPremul_SkAlphaType, nullptr)); |
| 668 | test_crbug263329(reporter, surface1, surface2); |
| 669 | } |
| 670 | } |
| 671 | #endif |
commit-bot@chromium.org | 4d24b74 | 2013-07-25 23:29:40 +0000 | [diff] [blame] | 672 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 673 | DEF_TEST(SurfaceGetTexture, reporter) { |
| 674 | SkAutoTUnref<SkSurface> surface(create_surface()); |
junov@chromium.org | da90474 | 2013-05-01 22:38:16 +0000 | [diff] [blame] | 675 | SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame^] | 676 | REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 677 | surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame^] | 678 | REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 679 | } |
| 680 | #if SK_SUPPORT_GPU |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame^] | 681 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, context) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 682 | for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { |
| 683 | SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaType, nullptr)); |
| 684 | SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame^] | 685 | GrTexture* texture = as_IB(image)->peekTexture(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 686 | REPORTER_ASSERT(reporter, texture); |
junov@chromium.org | da90474 | 2013-05-01 22:38:16 +0000 | [diff] [blame] | 687 | REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 688 | surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame^] | 689 | REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == texture); |
junov@chromium.org | da90474 | 2013-05-01 22:38:16 +0000 | [diff] [blame] | 690 | } |
junov@chromium.org | da90474 | 2013-05-01 22:38:16 +0000 | [diff] [blame] | 691 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 692 | #endif |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 693 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 694 | #if SK_SUPPORT_GPU |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 695 | #include "GrGpuResourcePriv.h" |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 696 | #include "SkGpuDevice.h" |
| 697 | #include "SkImage_Gpu.h" |
| 698 | #include "SkSurface_Gpu.h" |
| 699 | |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 700 | static SkBudgeted is_budgeted(SkSurface* surf) { |
| 701 | return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->resourcePriv().isBudgeted(); |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 702 | } |
| 703 | |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 704 | static SkBudgeted is_budgeted(SkImage* image) { |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame^] | 705 | return ((SkImage_Gpu*)image)->peekTexture()->resourcePriv().isBudgeted(); |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 706 | } |
| 707 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 708 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, context) { |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 709 | SkImageInfo info = SkImageInfo::MakeN32Premul(8,8); |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 710 | for (auto sbudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { |
| 711 | for (auto ibudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 712 | SkAutoTUnref<SkSurface> |
| 713 | surface(SkSurface::NewRenderTarget(context, sbudgeted, info, 0)); |
| 714 | SkASSERT(surface); |
| 715 | REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); |
| 716 | |
mtklein | 31ff298 | 2015-01-24 11:27:27 -0800 | [diff] [blame] | 717 | SkAutoTUnref<SkImage> image(surface->newImageSnapshot(ibudgeted)); |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 718 | |
| 719 | // Initially the image shares a texture with the surface, and the surface decides |
| 720 | // whether it is budgeted or not. |
| 721 | REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); |
| 722 | REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(image)); |
| 723 | |
| 724 | // Now trigger copy-on-write |
| 725 | surface->getCanvas()->clear(SK_ColorBLUE); |
| 726 | |
| 727 | // They don't share a texture anymore. They should each have made their own budget |
| 728 | // decision. |
| 729 | REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); |
| 730 | REPORTER_ASSERT(reporter, ibudgeted == is_budgeted(image)); |
| 731 | } |
| 732 | } |
| 733 | } |
junov@chromium.org | b516a41 | 2013-05-01 22:49:59 +0000 | [diff] [blame] | 734 | #endif |
junov@chromium.org | da90474 | 2013-05-01 22:38:16 +0000 | [diff] [blame] | 735 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 736 | static void test_no_canvas1(skiatest::Reporter* reporter, |
| 737 | SkSurface* surface, |
| 738 | SkSurface::ContentChangeMode mode) { |
| 739 | // Test passes by not asserting |
| 740 | surface->notifyContentWillChange(mode); |
| 741 | SkDEBUGCODE(surface->validate();) |
| 742 | } |
| 743 | static void test_no_canvas2(skiatest::Reporter* reporter, |
| 744 | SkSurface* surface, |
| 745 | SkSurface::ContentChangeMode mode) { |
junov@chromium.org | acea3ef | 2013-04-16 19:41:09 +0000 | [diff] [blame] | 746 | // Verifies the robustness of SkSurface for handling use cases where calls |
| 747 | // are made before a canvas is created. |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 748 | SkImage* image1 = surface->newImageSnapshot(); |
| 749 | SkAutoTUnref<SkImage> aur_image1(image1); |
| 750 | SkDEBUGCODE(image1->validate();) |
| 751 | SkDEBUGCODE(surface->validate();) |
| 752 | surface->notifyContentWillChange(mode); |
| 753 | SkDEBUGCODE(image1->validate();) |
| 754 | SkDEBUGCODE(surface->validate();) |
| 755 | SkImage* image2 = surface->newImageSnapshot(); |
| 756 | SkAutoTUnref<SkImage> aur_image2(image2); |
| 757 | SkDEBUGCODE(image2->validate();) |
| 758 | SkDEBUGCODE(surface->validate();) |
| 759 | REPORTER_ASSERT(reporter, image1 != image2); |
junov@chromium.org | acea3ef | 2013-04-16 19:41:09 +0000 | [diff] [blame] | 760 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 761 | DEF_TEST(SurfaceNoCanvas, reporter) { |
| 762 | SkSurface::ContentChangeMode modes[] = |
| 763 | { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentChangeMode}; |
| 764 | for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { |
| 765 | for (auto& mode : modes) { |
| 766 | SkAutoTUnref<SkSurface> surface(create_surface()); |
| 767 | test_func(reporter, surface, mode); |
| 768 | } |
| 769 | } |
| 770 | } |
junov@chromium.org | b516a41 | 2013-05-01 22:49:59 +0000 | [diff] [blame] | 771 | #if SK_SUPPORT_GPU |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 772 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, context) { |
| 773 | SkSurface::ContentChangeMode modes[] = |
| 774 | { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentChangeMode}; |
| 775 | for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { |
| 776 | for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { |
| 777 | for (auto& mode : modes) { |
| 778 | SkAutoTUnref<SkSurface> surface( |
| 779 | surface_func(context, kPremul_SkAlphaType, nullptr)); |
| 780 | test_func(reporter, surface, mode); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 781 | } |
robertphillips@google.com | 3bddb38 | 2013-11-12 13:51:03 +0000 | [diff] [blame] | 782 | } |
junov@chromium.org | af05835 | 2013-04-03 15:03:26 +0000 | [diff] [blame] | 783 | } |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 784 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 785 | #endif |
reed | 9cd016e | 2016-01-30 10:01:06 -0800 | [diff] [blame] | 786 | |
| 787 | static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Reporter* reporter) { |
| 788 | SkImageInfo info; |
| 789 | size_t rowBytes; |
| 790 | REPORTER_ASSERT(reporter, surface->peekPixels(&info, &rowBytes)); |
| 791 | |
| 792 | SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 793 | SkImageInfo im_info; |
| 794 | size_t im_rowbytes; |
| 795 | REPORTER_ASSERT(reporter, image->peekPixels(&im_info, &im_rowbytes)); |
| 796 | |
| 797 | REPORTER_ASSERT(reporter, rowBytes == im_rowbytes); |
| 798 | |
| 799 | // trigger a copy-on-write |
| 800 | surface->getCanvas()->drawPaint(SkPaint()); |
| 801 | SkAutoTUnref<SkImage> image2(surface->newImageSnapshot()); |
| 802 | REPORTER_ASSERT(reporter, image->uniqueID() != image2->uniqueID()); |
| 803 | |
| 804 | SkImageInfo im_info2; |
| 805 | size_t im_rowbytes2; |
| 806 | REPORTER_ASSERT(reporter, image2->peekPixels(&im_info2, &im_rowbytes2)); |
| 807 | |
| 808 | REPORTER_ASSERT(reporter, im_rowbytes2 == im_rowbytes); |
| 809 | } |
| 810 | |
| 811 | DEF_TEST(surface_rowbytes, reporter) { |
| 812 | const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
| 813 | |
| 814 | SkAutoTUnref<SkSurface> surf0(SkSurface::NewRaster(info)); |
| 815 | check_rowbytes_remain_consistent(surf0, reporter); |
| 816 | |
| 817 | // specify a larger rowbytes |
| 818 | SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info, 500, nullptr)); |
| 819 | check_rowbytes_remain_consistent(surf1, reporter); |
| 820 | |
| 821 | // Try some illegal rowByte values |
| 822 | SkSurface* s = SkSurface::NewRaster(info, 396, nullptr); // needs to be at least 400 |
| 823 | REPORTER_ASSERT(reporter, nullptr == s); |
| 824 | s = SkSurface::NewRaster(info, 1 << 30, nullptr); // allocation to large |
| 825 | REPORTER_ASSERT(reporter, nullptr == s); |
| 826 | } |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 827 | |
| 828 | #if SK_SUPPORT_GPU |
| 829 | |
bsalomon | 2fba809 | 2016-02-05 13:47:06 -0800 | [diff] [blame] | 830 | void test_surface_clear(skiatest::Reporter* reporter, SkSurface* surfacePtr, |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 831 | std::function<GrSurface*(SkSurface*)> grSurfaceGetter, |
| 832 | uint32_t expectedValue) { |
bsalomon | 2fba809 | 2016-02-05 13:47:06 -0800 | [diff] [blame] | 833 | SkAutoTUnref<SkSurface> surface(surfacePtr); |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 834 | if (!surface) { |
| 835 | ERRORF(reporter, "Could not create GPU SkSurface."); |
| 836 | return; |
| 837 | } |
| 838 | int w = surface->width(); |
| 839 | int h = surface->height(); |
| 840 | SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[w * h]); |
| 841 | memset(pixels.get(), ~expectedValue, sizeof(uint32_t) * w * h); |
| 842 | |
| 843 | SkAutoTUnref<GrSurface> grSurface(SkSafeRef(grSurfaceGetter(surface))); |
| 844 | if (!grSurface) { |
| 845 | ERRORF(reporter, "Could access render target of GPU SkSurface."); |
| 846 | return; |
| 847 | } |
| 848 | SkASSERT(surface->unique()); |
bsalomon | 2fba809 | 2016-02-05 13:47:06 -0800 | [diff] [blame] | 849 | surface.reset(); |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 850 | grSurface->readPixels(0, 0, w, h, kRGBA_8888_GrPixelConfig, pixels.get()); |
| 851 | for (int y = 0; y < h; ++y) { |
| 852 | for (int x = 0; x < w; ++x) { |
| 853 | uint32_t pixel = pixels.get()[y * w + x]; |
| 854 | if (pixel != expectedValue) { |
| 855 | SkString msg; |
| 856 | if (expectedValue) { |
| 857 | msg = "SkSurface should have left render target unmodified"; |
| 858 | } else { |
| 859 | msg = "SkSurface should have cleared the render target"; |
| 860 | } |
| 861 | ERRORF(reporter, |
| 862 | "%s but read 0x%08x (instead of 0x%08x) at %x,%d", msg.c_str(), pixel, |
| 863 | expectedValue, x, y); |
| 864 | return; |
| 865 | } |
| 866 | } |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, context) { |
| 871 | std::function<GrSurface*(SkSurface*)> grSurfaceGetters[] = { |
bsalomon | 2fba809 | 2016-02-05 13:47:06 -0800 | [diff] [blame] | 872 | [] (SkSurface* s){ return s->getCanvas()->internal_private_accessTopLayerRenderTarget(); }, |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 873 | [] (SkSurface* s){ |
| 874 | SkBaseDevice* d = |
| 875 | s->getCanvas()->getDevice_just_for_deprecated_compatibility_testing(); |
| 876 | return d->accessRenderTarget(); }, |
bsalomon | 2fba809 | 2016-02-05 13:47:06 -0800 | [diff] [blame] | 877 | [] (SkSurface* s){ SkAutoTUnref<SkImage> i(s->newImageSnapshot()); |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 878 | return as_IB(i)->peekTexture(); }, |
| 879 | }; |
| 880 | for (auto grSurfaceGetter : grSurfaceGetters) { |
| 881 | for (auto& surface_func : {&create_gpu_surface, &create_gpu_scratch_surface}) { |
bsalomon | 2fba809 | 2016-02-05 13:47:06 -0800 | [diff] [blame] | 882 | SkSurface* surface = surface_func(context, kPremul_SkAlphaType, nullptr); |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 883 | test_surface_clear(reporter, surface, grSurfaceGetter, 0x0); |
| 884 | } |
| 885 | // Wrapped RTs are *not* supposed to clear (to allow client to partially update a surface). |
| 886 | static const int kWidth = 10; |
| 887 | static const int kHeight = 10; |
| 888 | SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[kWidth * kHeight]); |
| 889 | memset(pixels.get(), 0xAB, sizeof(uint32_t) * kWidth * kHeight); |
| 890 | |
| 891 | GrBackendObject textureObject = |
| 892 | context->getGpu()->createTestingOnlyBackendTexture(pixels.get(), kWidth, kHeight, |
| 893 | kRGBA_8888_GrPixelConfig); |
| 894 | |
| 895 | GrBackendTextureDesc desc; |
| 896 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 897 | desc.fWidth = kWidth; |
| 898 | desc.fHeight = kHeight; |
| 899 | desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 900 | desc.fTextureHandle = textureObject; |
| 901 | |
| 902 | SkSurface* surface = SkSurface::NewFromBackendTexture(context, desc, nullptr); |
| 903 | test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB); |
| 904 | context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); |
| 905 | } |
| 906 | } |
| 907 | #endif |