blob: 42fc8a109362155ceb908b5cac8cc7c82161f2a6 [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
Herb Derbyd3895d82018-09-04 13:27:00 -04008#include "GrBackendSurface.h"
kkinnunen179a8f52015-11-20 13:32:24 -08009#include "GrContext.h"
Robert Phillips2c862492017-01-18 10:08:39 -050010#include "GrContextPriv.h"
Brian Salomon3a2cc2c2018-02-03 00:25:12 +000011#include "GrGpu.h"
Brian Salomonbdecacf2018-02-02 20:32:49 -050012#include "GrGpuResourcePriv.h"
13#include "GrRenderTargetContext.h"
ericrkc4025182016-05-04 12:01:58 -070014#include "GrResourceProvider.h"
Brian Osmanc7ad40f2018-05-31 14:27:17 -040015#include "SkCanvas.h"
16#include "SkData.h"
17#include "SkDevice.h"
Brian Salomonbdecacf2018-02-02 20:32:49 -050018#include "SkGpuDevice.h"
Brian Osmanc7ad40f2018-05-31 14:27:17 -040019#include "SkImage_Base.h"
Brian Salomonbdecacf2018-02-02 20:32:49 -050020#include "SkImage_Gpu.h"
Brian Osmanc7ad40f2018-05-31 14:27:17 -040021#include "SkOverdrawCanvas.h"
22#include "SkPath.h"
23#include "SkRegion.h"
24#include "SkRRect.h"
25#include "SkSurface.h"
Brian Salomonbdecacf2018-02-02 20:32:49 -050026#include "SkSurface_Gpu.h"
Brian Osmanc7ad40f2018-05-31 14:27:17 -040027#include "SkUtils.h"
28#include "Test.h"
junov@chromium.org995beb62013-03-28 13:49:22 +000029
Hal Canary8a001442018-09-19 11:31:27 -040030#include <functional>
31#include <initializer_list>
32#include <vector>
33
Mike Reedd4746982018-02-07 16:05:29 -050034#include "sk_tool_utils.h"
35
bsalomon74f681d2015-06-23 14:38:48 -070036
kkinnunen179a8f52015-11-20 13:32:24 -080037static void release_direct_surface_storage(void* pixels, void* context) {
reed982542d2014-06-27 06:48:14 -070038 SkASSERT(pixels == context);
39 sk_free(pixels);
40}
reede8f30622016-03-23 18:59:25 -070041static sk_sp<SkSurface> create_surface(SkAlphaType at = kPremul_SkAlphaType,
42 SkImageInfo* requestedInfo = nullptr) {
bsalomon74f681d2015-06-23 14:38:48 -070043 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000044 if (requestedInfo) {
45 *requestedInfo = info;
46 }
reede8f30622016-03-23 18:59:25 -070047 return SkSurface::MakeRaster(info);
junov@chromium.org995beb62013-03-28 13:49:22 +000048}
reede8f30622016-03-23 18:59:25 -070049static sk_sp<SkSurface> create_direct_surface(SkAlphaType at = kPremul_SkAlphaType,
50 SkImageInfo* requestedInfo = nullptr) {
kkinnunen179a8f52015-11-20 13:32:24 -080051 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
52 if (requestedInfo) {
53 *requestedInfo = info;
54 }
55 const size_t rowBytes = info.minRowBytes();
Mike Reedf0ffb892017-10-03 14:47:21 -040056 void* storage = sk_malloc_throw(info.computeByteSize(rowBytes));
reede8f30622016-03-23 18:59:25 -070057 return SkSurface::MakeRasterDirectReleaseProc(info, storage, rowBytes,
58 release_direct_surface_storage,
59 storage);
kkinnunen179a8f52015-11-20 13:32:24 -080060}
reede8f30622016-03-23 18:59:25 -070061static sk_sp<SkSurface> create_gpu_surface(GrContext* context, SkAlphaType at = kPremul_SkAlphaType,
62 SkImageInfo* requestedInfo = nullptr) {
kkinnunen179a8f52015-11-20 13:32:24 -080063 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
64 if (requestedInfo) {
65 *requestedInfo = info;
66 }
robertphillips7e922762016-07-26 11:38:17 -070067 return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
kkinnunen179a8f52015-11-20 13:32:24 -080068}
reede8f30622016-03-23 18:59:25 -070069static sk_sp<SkSurface> create_gpu_scratch_surface(GrContext* context,
70 SkAlphaType at = kPremul_SkAlphaType,
71 SkImageInfo* requestedInfo = nullptr) {
kkinnunen179a8f52015-11-20 13:32:24 -080072 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
73 if (requestedInfo) {
74 *requestedInfo = info;
75 }
robertphillips7e922762016-07-26 11:38:17 -070076 return SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info);
kkinnunen179a8f52015-11-20 13:32:24 -080077}
junov@chromium.org995beb62013-03-28 13:49:22 +000078
kkinnunen179a8f52015-11-20 13:32:24 -080079DEF_TEST(SurfaceEmpty, reporter) {
reedb2497c22014-12-31 12:31:43 -080080 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
reede8f30622016-03-23 18:59:25 -070081 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRaster(info));
82 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRasterDirect(info, nullptr, 0));
kkinnunen179a8f52015-11-20 13:32:24 -080083
reedb2497c22014-12-31 12:31:43 -080084}
egdanielab527a52016-06-28 08:07:26 -070085DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, ctxInfo) {
kkinnunen179a8f52015-11-20 13:32:24 -080086 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
87 REPORTER_ASSERT(reporter, nullptr ==
robertphillips7e922762016-07-26 11:38:17 -070088 SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo, info));
kkinnunen179a8f52015-11-20 13:32:24 -080089}
reedb2497c22014-12-31 12:31:43 -080090
Brian Salomonbdecacf2018-02-02 20:32:49 -050091DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsSurface, reporter, ctxInfo) {
92 for (int ct = 0; ct < kLastEnum_SkColorType; ++ct) {
93 static constexpr int kSize = 10;
94
95 SkColorType colorType = static_cast<SkColorType>(ct);
96 auto info = SkImageInfo::Make(kSize, kSize, colorType, kOpaque_SkAlphaType, nullptr);
97 bool can = ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType);
98 auto surf = SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kYes, info, 1,
99 nullptr);
100 REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d",
101 colorType, can, SkToBool(surf));
102
103 auto* gpu = ctxInfo.grContext()->contextPriv().getGpu();
104 GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
Brian Osman2b23c4b2018-06-01 12:25:08 -0400105 nullptr, kSize, kSize, colorType, true, GrMipMapped::kNo);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500106 surf = SkSurface::MakeFromBackendTexture(ctxInfo.grContext(), backendTex,
107 kTopLeft_GrSurfaceOrigin, 0, colorType, nullptr,
108 nullptr);
109 REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d",
110 colorType, can, SkToBool(surf));
111
112 surf = SkSurface::MakeFromBackendTextureAsRenderTarget(ctxInfo.grContext(), backendTex,
113 kTopLeft_GrSurfaceOrigin, 1,
114 colorType, nullptr, nullptr);
115 REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d",
116 colorType, can, SkToBool(surf));
117
118 surf.reset();
119 ctxInfo.grContext()->flush();
120 if (backendTex.isValid()) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500121 gpu->deleteTestingOnlyBackendTexture(backendTex);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500122 }
123
124 static constexpr int kSampleCnt = 2;
125
126 can = ctxInfo.grContext()->maxSurfaceSampleCountForColorType(colorType) >= kSampleCnt;
127 surf = SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kYes, info, kSampleCnt,
128 nullptr);
129 REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d",
130 colorType, can, SkToBool(surf));
131
Brian Osman2b23c4b2018-06-01 12:25:08 -0400132 backendTex = gpu->createTestingOnlyBackendTexture(nullptr, kSize, kSize, colorType, true,
133 GrMipMapped::kNo);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500134 surf = SkSurface::MakeFromBackendTexture(ctxInfo.grContext(), backendTex,
135 kTopLeft_GrSurfaceOrigin, kSampleCnt, colorType,
136 nullptr, nullptr);
137 REPORTER_ASSERT(reporter, can == SkToBool(surf),
138 "colorTypeSupportedAsSurface:%d, surf:%d, ct:%d", can, SkToBool(surf),
139 colorType);
140 // Ensure that the sample count stored on the resulting SkSurface is a valid value.
141 if (surf) {
142 auto* rtc = ((SkSurface_Gpu*)(surf.get()))->getDevice()->accessRenderTargetContext();
143 int storedCnt = rtc->numStencilSamples();
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400144 int allowedCnt = ctxInfo.grContext()->contextPriv().caps()->getSampleCount(
Brian Salomonbdecacf2018-02-02 20:32:49 -0500145 storedCnt, rtc->asSurfaceProxy()->config());
146 REPORTER_ASSERT(reporter, storedCnt == allowedCnt,
147 "Should store an allowed sample count (%d vs %d)", allowedCnt,
148 storedCnt);
149 }
150
151 surf = SkSurface::MakeFromBackendTextureAsRenderTarget(ctxInfo.grContext(), backendTex,
152 kTopLeft_GrSurfaceOrigin, kSampleCnt,
153 colorType, nullptr, nullptr);
154 REPORTER_ASSERT(reporter, can == SkToBool(surf),
155 "colorTypeSupportedAsSurface:%d, surf:%d, ct:%d", can, SkToBool(surf),
156 colorType);
157 if (surf) {
158 auto* rtc = ((SkSurface_Gpu*)(surf.get()))->getDevice()->accessRenderTargetContext();
159 int storedCnt = rtc->numStencilSamples();
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400160 int allowedCnt = ctxInfo.grContext()->contextPriv().caps()->getSampleCount(
Brian Salomonbdecacf2018-02-02 20:32:49 -0500161 storedCnt, rtc->asSurfaceProxy()->config());
162 REPORTER_ASSERT(reporter, storedCnt == allowedCnt,
163 "Should store an allowed sample count (%d vs %d)", allowedCnt,
164 storedCnt);
165 }
166
167 surf.reset();
168 ctxInfo.grContext()->flush();
169 if (backendTex.isValid()) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500170 gpu->deleteTestingOnlyBackendTexture(backendTex);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500171 }
Brian Salomon93348dd2018-08-29 12:56:23 -0400172
173 GrBackendRenderTarget backendRenderTarget = gpu->createTestingOnlyBackendRenderTarget(
174 16, 16, SkColorTypeToGrColorType(colorType));
175 can = ctxInfo.grContext()->colorTypeSupportedAsSurface(colorType);
176 surf = SkSurface::MakeFromBackendRenderTarget(ctxInfo.grContext(), backendRenderTarget,
177 kTopLeft_GrSurfaceOrigin, colorType, nullptr,
178 nullptr);
179 REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d", colorType,
180 can, SkToBool(surf));
181 surf.reset();
182 ctxInfo.grContext()->flush();
183 if (backendRenderTarget.isValid()) {
184 gpu->deleteTestingOnlyBackendRenderTarget(backendRenderTarget);
185 }
Brian Salomonbdecacf2018-02-02 20:32:49 -0500186 }
187}
188
189DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_maxSurfaceSamplesForColorType, reporter, ctxInfo) {
190 for (int ct = 0; ct < kLastEnum_SkColorType; ++ct) {
191 static constexpr int kSize = 10;
192
193 SkColorType colorType = static_cast<SkColorType>(ct);
194 int max = ctxInfo.grContext()->maxSurfaceSampleCountForColorType(colorType);
195 if (!max) {
196 continue;
197 }
198 auto* gpu = ctxInfo.grContext()->contextPriv().getGpu();
199 GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
Brian Osman2b23c4b2018-06-01 12:25:08 -0400200 nullptr, kSize, kSize, colorType, true, GrMipMapped::kNo);
Brian Salomon99501b72018-03-23 11:26:11 -0400201 if (!backendTex.isValid()) {
202 continue;
203 }
204 SkScopeExit freeTex([&backendTex, gpu] {gpu->deleteTestingOnlyBackendTexture(backendTex);});
Brian Salomonbdecacf2018-02-02 20:32:49 -0500205 auto info = SkImageInfo::Make(kSize, kSize, colorType, kOpaque_SkAlphaType, nullptr);
206 auto surf = SkSurface::MakeFromBackendTexture(ctxInfo.grContext(), backendTex,
207 kTopLeft_GrSurfaceOrigin, max,
208 colorType, nullptr, nullptr);
209 REPORTER_ASSERT(reporter, surf);
210 if (!surf) {
211 continue;
212 }
213 int sampleCnt = ((SkSurface_Gpu*)(surf.get()))
214 ->getDevice()
215 ->accessRenderTargetContext()
216 ->numStencilSamples();
217 REPORTER_ASSERT(reporter, sampleCnt == max, "Exected: %d, actual: %d", max, sampleCnt);
218 }
219}
Brian Salomonbdecacf2018-02-02 20:32:49 -0500220
kkinnunen179a8f52015-11-20 13:32:24 -0800221static void test_canvas_peek(skiatest::Reporter* reporter,
reede8f30622016-03-23 18:59:25 -0700222 sk_sp<SkSurface>& surface,
kkinnunen179a8f52015-11-20 13:32:24 -0800223 const SkImageInfo& requestInfo,
224 bool expectPeekSuccess) {
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000225 const SkColor color = SK_ColorRED;
226 const SkPMColor pmcolor = SkPreMultiplyColor(color);
kkinnunen179a8f52015-11-20 13:32:24 -0800227 surface->getCanvas()->clear(color);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000228
reed6ceeebd2016-03-09 14:26:26 -0800229 SkPixmap pmap;
230 bool success = surface->getCanvas()->peekPixels(&pmap);
kkinnunen179a8f52015-11-20 13:32:24 -0800231 REPORTER_ASSERT(reporter, expectPeekSuccess == success);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000232
reed6ceeebd2016-03-09 14:26:26 -0800233 SkPixmap pmap2;
234 const void* addr2 = surface->peekPixels(&pmap2) ? pmap2.addr() : nullptr;
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000235
kkinnunen179a8f52015-11-20 13:32:24 -0800236 if (success) {
reed6ceeebd2016-03-09 14:26:26 -0800237 REPORTER_ASSERT(reporter, requestInfo == pmap.info());
238 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= pmap.rowBytes());
239 REPORTER_ASSERT(reporter, pmcolor == *pmap.addr32());
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000240
reed6ceeebd2016-03-09 14:26:26 -0800241 REPORTER_ASSERT(reporter, pmap.addr() == pmap2.addr());
242 REPORTER_ASSERT(reporter, pmap.info() == pmap2.info());
243 REPORTER_ASSERT(reporter, pmap.rowBytes() == pmap2.rowBytes());
kkinnunen179a8f52015-11-20 13:32:24 -0800244 } else {
245 REPORTER_ASSERT(reporter, nullptr == addr2);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000246 }
247}
kkinnunen179a8f52015-11-20 13:32:24 -0800248DEF_TEST(SurfaceCanvasPeek, reporter) {
249 for (auto& surface_func : { &create_surface, &create_direct_surface }) {
250 SkImageInfo requestInfo;
reede8f30622016-03-23 18:59:25 -0700251 auto surface(surface_func(kPremul_SkAlphaType, &requestInfo));
kkinnunen179a8f52015-11-20 13:32:24 -0800252 test_canvas_peek(reporter, surface, requestInfo, true);
253 }
254}
egdanielab527a52016-06-28 08:07:26 -0700255DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, ctxInfo) {
kkinnunen179a8f52015-11-20 13:32:24 -0800256 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
257 SkImageInfo requestInfo;
bsalomon8b7451a2016-05-11 06:33:06 -0700258 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, &requestInfo));
kkinnunen179a8f52015-11-20 13:32:24 -0800259 test_canvas_peek(reporter, surface, requestInfo, false);
260 }
261}
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000262
reede8f30622016-03-23 18:59:25 -0700263static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp<SkSurface>& surface,
brianosman69c166d2016-08-17 14:01:05 -0700264 SkAlphaType expectedAlphaType) {
kkinnunen179a8f52015-11-20 13:32:24 -0800265 REPORTER_ASSERT(reporter, surface);
266 if (surface) {
reed9ce9d672016-03-17 10:51:11 -0700267 sk_sp<SkImage> image(surface->makeImageSnapshot());
kkinnunen179a8f52015-11-20 13:32:24 -0800268 REPORTER_ASSERT(reporter, image);
269 if (image) {
brianosman69c166d2016-08-17 14:01:05 -0700270 REPORTER_ASSERT(reporter, image->alphaType() == expectedAlphaType);
reed41e010c2015-06-09 12:16:53 -0700271 }
272 }
273}
kkinnunen179a8f52015-11-20 13:32:24 -0800274DEF_TEST(SurfaceSnapshotAlphaType, reporter) {
275 for (auto& surface_func : { &create_surface, &create_direct_surface }) {
brianosman69c166d2016-08-17 14:01:05 -0700276 for (auto& at: { kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType }) {
277 auto surface(surface_func(at, nullptr));
278 test_snapshot_alphatype(reporter, surface, at);
bsalomon74f681d2015-06-23 14:38:48 -0700279 }
280 }
281}
egdanielab527a52016-06-28 08:07:26 -0700282DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, ctxInfo) {
kkinnunen179a8f52015-11-20 13:32:24 -0800283 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
brianosman69c166d2016-08-17 14:01:05 -0700284 // GPU doesn't support creating unpremul surfaces, so only test opaque + premul
285 for (auto& at : { kOpaque_SkAlphaType, kPremul_SkAlphaType }) {
286 auto surface(surface_func(ctxInfo.grContext(), at, nullptr));
287 test_snapshot_alphatype(reporter, surface, at);
kkinnunen179a8f52015-11-20 13:32:24 -0800288 }
289 }
290}
bsalomon74f681d2015-06-23 14:38:48 -0700291
Robert Phillips8caf85f2018-04-05 09:30:38 -0400292static void test_backend_texture_access_copy_on_write(
293 skiatest::Reporter* reporter, SkSurface* surface, SkSurface::BackendHandleAccess access) {
294 GrBackendTexture tex1 = surface->getBackendTexture(access);
reed9ce9d672016-03-17 10:51:11 -0700295 sk_sp<SkImage> snap1(surface->makeImageSnapshot());
fmalitae2639082015-08-06 07:04:51 -0700296
Robert Phillips8caf85f2018-04-05 09:30:38 -0400297 GrBackendTexture tex2 = surface->getBackendTexture(access);
reed9ce9d672016-03-17 10:51:11 -0700298 sk_sp<SkImage> snap2(surface->makeImageSnapshot());
fmalitae2639082015-08-06 07:04:51 -0700299
300 // If the access mode triggers CoW, then the backend objects should reflect it.
Robert Phillips8caf85f2018-04-05 09:30:38 -0400301 REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(tex1, tex2) == (snap1 == snap2));
fmalitae2639082015-08-06 07:04:51 -0700302}
Robert Phillips8caf85f2018-04-05 09:30:38 -0400303
304static void test_backend_rendertarget_access_copy_on_write(
305 skiatest::Reporter* reporter, SkSurface* surface, SkSurface::BackendHandleAccess access) {
306 GrBackendRenderTarget rt1 = surface->getBackendRenderTarget(access);
307 sk_sp<SkImage> snap1(surface->makeImageSnapshot());
308
309 GrBackendRenderTarget rt2 = surface->getBackendRenderTarget(access);
310 sk_sp<SkImage> snap2(surface->makeImageSnapshot());
311
312 // If the access mode triggers CoW, then the backend objects should reflect it.
313 REPORTER_ASSERT(reporter, GrBackendRenderTarget::TestingOnly_Equals(rt1, rt2) ==
314 (snap1 == snap2));
315}
316
317DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendSurfaceAccessCopyOnWrite_Gpu, reporter, ctxInfo) {
kkinnunen179a8f52015-11-20 13:32:24 -0800318 const SkSurface::BackendHandleAccess accessModes[] = {
319 SkSurface::kFlushRead_BackendHandleAccess,
320 SkSurface::kFlushWrite_BackendHandleAccess,
321 SkSurface::kDiscardWrite_BackendHandleAccess,
322 };
Robert Phillips8caf85f2018-04-05 09:30:38 -0400323
kkinnunen179a8f52015-11-20 13:32:24 -0800324 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
Robert Phillips8caf85f2018-04-05 09:30:38 -0400325 for (auto& accessMode : accessModes) {
326 {
bsalomon8b7451a2016-05-11 06:33:06 -0700327 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
Robert Phillips8caf85f2018-04-05 09:30:38 -0400328 test_backend_texture_access_copy_on_write(reporter, surface.get(), accessMode);
329 }
330 {
331 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
332 test_backend_rendertarget_access_copy_on_write(reporter, surface.get(), accessMode);
kkinnunen179a8f52015-11-20 13:32:24 -0800333 }
334 }
335 }
336}
kkinnunen179a8f52015-11-20 13:32:24 -0800337
Robert Phillips8caf85f2018-04-05 09:30:38 -0400338template<typename Type, Type(SkSurface::*func)(SkSurface::BackendHandleAccess)>
339static void test_backend_unique_id(skiatest::Reporter* reporter, SkSurface* surface) {
reed9ce9d672016-03-17 10:51:11 -0700340 sk_sp<SkImage> image0(surface->makeImageSnapshot());
Robert Phillips8caf85f2018-04-05 09:30:38 -0400341
342 Type obj = (surface->*func)(SkSurface::kFlushRead_BackendHandleAccess);
343 REPORTER_ASSERT(reporter, obj.isValid());
reed9ce9d672016-03-17 10:51:11 -0700344 sk_sp<SkImage> image1(surface->makeImageSnapshot());
kkinnunen179a8f52015-11-20 13:32:24 -0800345 // just read access should not affect the snapshot
346 REPORTER_ASSERT(reporter, image0->uniqueID() == image1->uniqueID());
347
Robert Phillips8caf85f2018-04-05 09:30:38 -0400348 obj = (surface->*func)(SkSurface::kFlushWrite_BackendHandleAccess);
349 REPORTER_ASSERT(reporter, obj.isValid());
reed9ce9d672016-03-17 10:51:11 -0700350 sk_sp<SkImage> image2(surface->makeImageSnapshot());
kkinnunen179a8f52015-11-20 13:32:24 -0800351 // expect a new image, since we claimed we would write
352 REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID());
353
Robert Phillips8caf85f2018-04-05 09:30:38 -0400354 obj = (surface->*func)(SkSurface::kDiscardWrite_BackendHandleAccess);
355 REPORTER_ASSERT(reporter, obj.isValid());
reed9ce9d672016-03-17 10:51:11 -0700356 sk_sp<SkImage> image3(surface->makeImageSnapshot());
kkinnunen179a8f52015-11-20 13:32:24 -0800357 // expect a new(er) image, since we claimed we would write
358 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID());
359 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID());
360}
Robert Phillips8caf85f2018-04-05 09:30:38 -0400361
kkinnunen179a8f52015-11-20 13:32:24 -0800362// No CPU test.
bsalomon68d91342016-04-12 09:59:58 -0700363DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter, ctxInfo) {
kkinnunen179a8f52015-11-20 13:32:24 -0800364 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
Robert Phillips8caf85f2018-04-05 09:30:38 -0400365 {
366 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
367 test_backend_unique_id<GrBackendTexture, &SkSurface::getBackendTexture>(reporter,
368 surface.get());
369 }
370 {
371 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
372 test_backend_unique_id<GrBackendRenderTarget, &SkSurface::getBackendRenderTarget>(
373 reporter, surface.get());
kkinnunen179a8f52015-11-20 13:32:24 -0800374 }
375 }
376}
kkinnunen179a8f52015-11-20 13:32:24 -0800377
378// Verify that the right canvas commands trigger a copy on write.
379static void test_copy_on_write(skiatest::Reporter* reporter, SkSurface* surface) {
junov@chromium.org995beb62013-03-28 13:49:22 +0000380 SkCanvas* canvas = surface->getCanvas();
381
382 const SkRect testRect =
383 SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
384 SkIntToScalar(4), SkIntToScalar(5));
junov@chromium.org995beb62013-03-28 13:49:22 +0000385 SkPath testPath;
386 testPath.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
387 SkIntToScalar(2), SkIntToScalar(1)));
388
389 const SkIRect testIRect = SkIRect::MakeXYWH(0, 0, 2, 1);
390
391 SkRegion testRegion;
392 testRegion.setRect(testIRect);
393
394
395 const SkColor testColor = 0x01020304;
396 const SkPaint testPaint;
397 const SkPoint testPoints[3] = {
398 {SkIntToScalar(0), SkIntToScalar(0)},
399 {SkIntToScalar(2), SkIntToScalar(1)},
400 {SkIntToScalar(0), SkIntToScalar(2)}
401 };
402 const size_t testPointCount = 3;
403
404 SkBitmap testBitmap;
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +0000405 testBitmap.allocN32Pixels(10, 10);
robertphillips@google.comd1ce77d2013-10-09 12:51:09 +0000406 testBitmap.eraseColor(0);
junov@chromium.org995beb62013-03-28 13:49:22 +0000407
408 SkRRect testRRect;
409 testRRect.setRectXY(testRect, SK_Scalar1, SK_Scalar1);
410
411 SkString testText("Hello World");
junov@chromium.org995beb62013-03-28 13:49:22 +0000412
413#define EXPECT_COPY_ON_WRITE(command) \
414 { \
reed9ce9d672016-03-17 10:51:11 -0700415 sk_sp<SkImage> imageBefore = surface->makeImageSnapshot(); \
416 sk_sp<SkImage> aur_before(imageBefore); \
junov@chromium.org995beb62013-03-28 13:49:22 +0000417 canvas-> command ; \
reed9ce9d672016-03-17 10:51:11 -0700418 sk_sp<SkImage> imageAfter = surface->makeImageSnapshot(); \
419 sk_sp<SkImage> aur_after(imageAfter); \
junov@chromium.org995beb62013-03-28 13:49:22 +0000420 REPORTER_ASSERT(reporter, imageBefore != imageAfter); \
421 }
422
423 EXPECT_COPY_ON_WRITE(clear(testColor))
424 EXPECT_COPY_ON_WRITE(drawPaint(testPaint))
425 EXPECT_COPY_ON_WRITE(drawPoints(SkCanvas::kPoints_PointMode, testPointCount, testPoints, \
426 testPaint))
427 EXPECT_COPY_ON_WRITE(drawOval(testRect, testPaint))
428 EXPECT_COPY_ON_WRITE(drawRect(testRect, testPaint))
429 EXPECT_COPY_ON_WRITE(drawRRect(testRRect, testPaint))
430 EXPECT_COPY_ON_WRITE(drawPath(testPath, testPaint))
431 EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0))
reede47829b2015-08-06 10:02:53 -0700432 EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, testRect, nullptr))
halcanary96fcdcc2015-08-27 07:41:13 -0700433 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, nullptr))
Hal Canary89a644b2019-01-07 09:36:09 -0500434 EXPECT_COPY_ON_WRITE(drawString(testText, 0, 1, SkFont(), testPaint))
kkinnunen179a8f52015-11-20 13:32:24 -0800435}
436DEF_TEST(SurfaceCopyOnWrite, reporter) {
reede8f30622016-03-23 18:59:25 -0700437 test_copy_on_write(reporter, create_surface().get());
kkinnunen179a8f52015-11-20 13:32:24 -0800438}
egdanielab527a52016-06-28 08:07:26 -0700439DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, ctxInfo) {
kkinnunen179a8f52015-11-20 13:32:24 -0800440 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
bsalomon8b7451a2016-05-11 06:33:06 -0700441 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
reede8f30622016-03-23 18:59:25 -0700442 test_copy_on_write(reporter, surface.get());
fmalitae2639082015-08-06 07:04:51 -0700443 }
junov@chromium.org995beb62013-03-28 13:49:22 +0000444}
445
kkinnunen179a8f52015-11-20 13:32:24 -0800446static void test_writable_after_snapshot_release(skiatest::Reporter* reporter,
447 SkSurface* surface) {
junov@chromium.orgaf058352013-04-03 15:03:26 +0000448 // This test succeeds by not triggering an assertion.
449 // The test verifies that the surface remains writable (usable) after
450 // acquiring and releasing a snapshot without triggering a copy on write.
junov@chromium.orgaf058352013-04-03 15:03:26 +0000451 SkCanvas* canvas = surface->getCanvas();
452 canvas->clear(1);
reed9ce9d672016-03-17 10:51:11 -0700453 surface->makeImageSnapshot(); // Create and destroy SkImage
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000454 canvas->clear(2); // Must not assert internally
junov@chromium.org995beb62013-03-28 13:49:22 +0000455}
kkinnunen179a8f52015-11-20 13:32:24 -0800456DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) {
reede8f30622016-03-23 18:59:25 -0700457 test_writable_after_snapshot_release(reporter, create_surface().get());
kkinnunen179a8f52015-11-20 13:32:24 -0800458}
egdanielab527a52016-06-28 08:07:26 -0700459DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu, reporter, ctxInfo) {
kkinnunen179a8f52015-11-20 13:32:24 -0800460 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
bsalomon8b7451a2016-05-11 06:33:06 -0700461 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
reede8f30622016-03-23 18:59:25 -0700462 test_writable_after_snapshot_release(reporter, surface.get());
kkinnunen179a8f52015-11-20 13:32:24 -0800463 }
464}
junov@chromium.orgda904742013-05-01 22:38:16 +0000465
kkinnunen179a8f52015-11-20 13:32:24 -0800466static void test_crbug263329(skiatest::Reporter* reporter,
467 SkSurface* surface1,
468 SkSurface* surface2) {
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000469 // This is a regression test for crbug.com/263329
470 // Bug was caused by onCopyOnWrite releasing the old surface texture
471 // back to the scratch texture pool even though the texture is used
472 // by and active SkImage_Gpu.
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000473 SkCanvas* canvas1 = surface1->getCanvas();
474 SkCanvas* canvas2 = surface2->getCanvas();
475 canvas1->clear(1);
reed9ce9d672016-03-17 10:51:11 -0700476 sk_sp<SkImage> image1(surface1->makeImageSnapshot());
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000477 // Trigger copy on write, new backing is a scratch texture
478 canvas1->clear(2);
reed9ce9d672016-03-17 10:51:11 -0700479 sk_sp<SkImage> image2(surface1->makeImageSnapshot());
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000480 // Trigger copy on write, old backing should not be returned to scratch
481 // pool because it is held by image2
482 canvas1->clear(3);
483
484 canvas2->clear(4);
reed9ce9d672016-03-17 10:51:11 -0700485 sk_sp<SkImage> image3(surface2->makeImageSnapshot());
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000486 // Trigger copy on write on surface2. The new backing store should not
487 // be recycling a texture that is held by an existing image.
488 canvas2->clear(5);
reed9ce9d672016-03-17 10:51:11 -0700489 sk_sp<SkImage> image4(surface2->makeImageSnapshot());
Robert Phillips87444052017-06-23 14:09:30 -0400490 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image3)->getTexture());
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000491 // The following assertion checks crbug.com/263329
Robert Phillips87444052017-06-23 14:09:30 -0400492 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image2)->getTexture());
493 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image1)->getTexture());
494 REPORTER_ASSERT(reporter, as_IB(image3)->getTexture() != as_IB(image2)->getTexture());
495 REPORTER_ASSERT(reporter, as_IB(image3)->getTexture() != as_IB(image1)->getTexture());
496 REPORTER_ASSERT(reporter, as_IB(image2)->getTexture() != as_IB(image1)->getTexture());
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000497}
egdanielab527a52016-06-28 08:07:26 -0700498DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, ctxInfo) {
kkinnunen179a8f52015-11-20 13:32:24 -0800499 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
bsalomon8b7451a2016-05-11 06:33:06 -0700500 auto surface1(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
501 auto surface2(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
reede8f30622016-03-23 18:59:25 -0700502 test_crbug263329(reporter, surface1.get(), surface2.get());
kkinnunen179a8f52015-11-20 13:32:24 -0800503 }
504}
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000505
kkinnunen179a8f52015-11-20 13:32:24 -0800506DEF_TEST(SurfaceGetTexture, reporter) {
reede8f30622016-03-23 18:59:25 -0700507 auto surface(create_surface());
reed9ce9d672016-03-17 10:51:11 -0700508 sk_sp<SkImage> image(surface->makeImageSnapshot());
Robert Phillips6de99042017-01-31 11:31:39 -0500509 REPORTER_ASSERT(reporter, !as_IB(image)->isTextureBacked());
kkinnunen179a8f52015-11-20 13:32:24 -0800510 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
Robert Phillips6de99042017-01-31 11:31:39 -0500511 REPORTER_ASSERT(reporter, !as_IB(image)->isTextureBacked());
kkinnunen179a8f52015-11-20 13:32:24 -0800512}
egdanielab527a52016-06-28 08:07:26 -0700513DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, ctxInfo) {
kkinnunen179a8f52015-11-20 13:32:24 -0800514 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
bsalomon8b7451a2016-05-11 06:33:06 -0700515 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
reed9ce9d672016-03-17 10:51:11 -0700516 sk_sp<SkImage> image(surface->makeImageSnapshot());
Robert Phillips6de99042017-01-31 11:31:39 -0500517
518 REPORTER_ASSERT(reporter, as_IB(image)->isTextureBacked());
Robert Phillipsc5509952018-04-04 15:54:55 -0400519 GrBackendTexture backendTex = image->getBackendTexture(false);
520 REPORTER_ASSERT(reporter, backendTex.isValid());
kkinnunen179a8f52015-11-20 13:32:24 -0800521 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
Robert Phillips6de99042017-01-31 11:31:39 -0500522 REPORTER_ASSERT(reporter, as_IB(image)->isTextureBacked());
Robert Phillipsc5509952018-04-04 15:54:55 -0400523 GrBackendTexture backendTex2 = image->getBackendTexture(false);
524 REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(backendTex, backendTex2));
junov@chromium.orgda904742013-05-01 22:38:16 +0000525 }
junov@chromium.orgda904742013-05-01 22:38:16 +0000526}
bsalomoneaaaf0b2015-01-23 08:08:04 -0800527
reede8f30622016-03-23 18:59:25 -0700528static SkBudgeted is_budgeted(const sk_sp<SkSurface>& surf) {
529 SkSurface_Gpu* gsurf = (SkSurface_Gpu*)surf.get();
Robert Phillips6de99042017-01-31 11:31:39 -0500530
531 GrRenderTargetProxy* proxy = gsurf->getDevice()->accessRenderTargetContext()
532 ->asRenderTargetProxy();
533 return proxy->isBudgeted();
bsalomoneaaaf0b2015-01-23 08:08:04 -0800534}
535
bsalomon5ec26ae2016-02-25 08:33:02 -0800536static SkBudgeted is_budgeted(SkImage* image) {
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400537 return ((SkImage_Gpu*)image)->peekProxy()->isBudgeted();
bsalomoneaaaf0b2015-01-23 08:08:04 -0800538}
539
reed9ce9d672016-03-17 10:51:11 -0700540static SkBudgeted is_budgeted(const sk_sp<SkImage> image) {
541 return is_budgeted(image.get());
542}
543
egdanielab527a52016-06-28 08:07:26 -0700544DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, ctxInfo) {
bsalomoneaaaf0b2015-01-23 08:08:04 -0800545 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8);
Robert Phillipsac6b1fa2017-03-20 08:38:50 -0400546 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) {
547 auto surface(SkSurface::MakeRenderTarget(ctxInfo.grContext(), budgeted, info));
548 SkASSERT(surface);
549 REPORTER_ASSERT(reporter, budgeted == is_budgeted(surface));
bsalomoneaaaf0b2015-01-23 08:08:04 -0800550
Robert Phillipsac6b1fa2017-03-20 08:38:50 -0400551 sk_sp<SkImage> image(surface->makeImageSnapshot());
bsalomoneaaaf0b2015-01-23 08:08:04 -0800552
Robert Phillipsac6b1fa2017-03-20 08:38:50 -0400553 // Initially the image shares a texture with the surface, and the
554 // the budgets should always match.
555 REPORTER_ASSERT(reporter, budgeted == is_budgeted(surface));
556 REPORTER_ASSERT(reporter, budgeted == is_budgeted(image));
bsalomoneaaaf0b2015-01-23 08:08:04 -0800557
Robert Phillipsac6b1fa2017-03-20 08:38:50 -0400558 // Now trigger copy-on-write
559 surface->getCanvas()->clear(SK_ColorBLUE);
bsalomoneaaaf0b2015-01-23 08:08:04 -0800560
Robert Phillipsac6b1fa2017-03-20 08:38:50 -0400561 // They don't share a texture anymore but the budgets should still match.
562 REPORTER_ASSERT(reporter, budgeted == is_budgeted(surface));
563 REPORTER_ASSERT(reporter, budgeted == is_budgeted(image));
bsalomoneaaaf0b2015-01-23 08:08:04 -0800564 }
565}
junov@chromium.orgda904742013-05-01 22:38:16 +0000566
kkinnunen179a8f52015-11-20 13:32:24 -0800567static void test_no_canvas1(skiatest::Reporter* reporter,
568 SkSurface* surface,
569 SkSurface::ContentChangeMode mode) {
570 // Test passes by not asserting
571 surface->notifyContentWillChange(mode);
kkinnunen179a8f52015-11-20 13:32:24 -0800572}
573static void test_no_canvas2(skiatest::Reporter* reporter,
574 SkSurface* surface,
575 SkSurface::ContentChangeMode mode) {
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000576 // Verifies the robustness of SkSurface for handling use cases where calls
577 // are made before a canvas is created.
reed9ce9d672016-03-17 10:51:11 -0700578 sk_sp<SkImage> image1 = surface->makeImageSnapshot();
579 sk_sp<SkImage> aur_image1(image1);
kkinnunen179a8f52015-11-20 13:32:24 -0800580 surface->notifyContentWillChange(mode);
reed9ce9d672016-03-17 10:51:11 -0700581 sk_sp<SkImage> image2 = surface->makeImageSnapshot();
582 sk_sp<SkImage> aur_image2(image2);
kkinnunen179a8f52015-11-20 13:32:24 -0800583 REPORTER_ASSERT(reporter, image1 != image2);
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000584}
kkinnunen179a8f52015-11-20 13:32:24 -0800585DEF_TEST(SurfaceNoCanvas, reporter) {
586 SkSurface::ContentChangeMode modes[] =
587 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentChangeMode};
588 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) {
589 for (auto& mode : modes) {
reede8f30622016-03-23 18:59:25 -0700590 test_func(reporter, create_surface().get(), mode);
kkinnunen179a8f52015-11-20 13:32:24 -0800591 }
592 }
593}
egdanielab527a52016-06-28 08:07:26 -0700594DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, ctxInfo) {
kkinnunen179a8f52015-11-20 13:32:24 -0800595 SkSurface::ContentChangeMode modes[] =
596 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentChangeMode};
597 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
598 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) {
599 for (auto& mode : modes) {
bsalomon8b7451a2016-05-11 06:33:06 -0700600 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
reede8f30622016-03-23 18:59:25 -0700601 test_func(reporter, surface.get(), mode);
bsalomone904c092014-07-17 10:50:59 -0700602 }
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000603 }
junov@chromium.orgaf058352013-04-03 15:03:26 +0000604 }
junov@chromium.org995beb62013-03-28 13:49:22 +0000605}
reed9cd016e2016-01-30 10:01:06 -0800606
607static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Reporter* reporter) {
reed6ceeebd2016-03-09 14:26:26 -0800608 SkPixmap surfacePM;
609 REPORTER_ASSERT(reporter, surface->peekPixels(&surfacePM));
reed9cd016e2016-01-30 10:01:06 -0800610
reed9ce9d672016-03-17 10:51:11 -0700611 sk_sp<SkImage> image(surface->makeImageSnapshot());
reed6ceeebd2016-03-09 14:26:26 -0800612 SkPixmap pm;
613 REPORTER_ASSERT(reporter, image->peekPixels(&pm));
reed9cd016e2016-01-30 10:01:06 -0800614
reed6ceeebd2016-03-09 14:26:26 -0800615 REPORTER_ASSERT(reporter, surfacePM.rowBytes() == pm.rowBytes());
reed9cd016e2016-01-30 10:01:06 -0800616
617 // trigger a copy-on-write
618 surface->getCanvas()->drawPaint(SkPaint());
reed9ce9d672016-03-17 10:51:11 -0700619 sk_sp<SkImage> image2(surface->makeImageSnapshot());
reed9cd016e2016-01-30 10:01:06 -0800620 REPORTER_ASSERT(reporter, image->uniqueID() != image2->uniqueID());
621
reed6ceeebd2016-03-09 14:26:26 -0800622 SkPixmap pm2;
623 REPORTER_ASSERT(reporter, image2->peekPixels(&pm2));
624 REPORTER_ASSERT(reporter, pm2.rowBytes() == pm.rowBytes());
reed9cd016e2016-01-30 10:01:06 -0800625}
626
627DEF_TEST(surface_rowbytes, reporter) {
628 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
629
reede8f30622016-03-23 18:59:25 -0700630 auto surf0(SkSurface::MakeRaster(info));
631 check_rowbytes_remain_consistent(surf0.get(), reporter);
reed9cd016e2016-01-30 10:01:06 -0800632
633 // specify a larger rowbytes
reede8f30622016-03-23 18:59:25 -0700634 auto surf1(SkSurface::MakeRaster(info, 500, nullptr));
635 check_rowbytes_remain_consistent(surf1.get(), reporter);
reed9cd016e2016-01-30 10:01:06 -0800636
637 // Try some illegal rowByte values
reede8f30622016-03-23 18:59:25 -0700638 auto s = SkSurface::MakeRaster(info, 396, nullptr); // needs to be at least 400
reed9cd016e2016-01-30 10:01:06 -0800639 REPORTER_ASSERT(reporter, nullptr == s);
Mike Reedf0ffb892017-10-03 14:47:21 -0400640 s = SkSurface::MakeRaster(info, std::numeric_limits<size_t>::max(), nullptr);
reed9cd016e2016-01-30 10:01:06 -0800641 REPORTER_ASSERT(reporter, nullptr == s);
642}
bsalomone63ffef2016-02-05 07:17:34 -0800643
fmalita03912f12016-07-06 06:22:06 -0700644DEF_TEST(surface_raster_zeroinitialized, reporter) {
645 sk_sp<SkSurface> s(SkSurface::MakeRasterN32Premul(100, 100));
646 SkPixmap pixmap;
647 REPORTER_ASSERT(reporter, s->peekPixels(&pixmap));
648
649 for (int i = 0; i < pixmap.info().width(); ++i) {
650 for (int j = 0; j < pixmap.info().height(); ++j) {
651 REPORTER_ASSERT(reporter, *pixmap.addr32(i, j) == 0);
652 }
653 }
654}
655
ericrkc4025182016-05-04 12:01:58 -0700656static sk_sp<SkSurface> create_gpu_surface_backend_texture(
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500657 GrContext* context, int sampleCnt, uint32_t color, GrBackendTexture* outTexture) {
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500658 GrGpu* gpu = context->contextPriv().getGpu();
659
Michael Ludwig72ab3462018-12-10 12:43:36 -0500660 // On Pixel and Pixel2XL's with Adreno 530 and 540s, setting width and height to 10s reliably
661 // triggers what appears to be a driver race condition where the 10x10 surface from the
662 // OverdrawSurface_gpu test is reused(?) for this surface created by the SurfacePartialDraw_gpu
663 // test.
664 //
665 // Immediately after creation of this surface, readback shows the correct initial solid color.
666 // However, sometime before content is rendered into the upper half of the surface, the driver
667 // presumably cleans up the OverdrawSurface_gpu's memory which corrupts this color buffer. The
668 // top half of the surface is fine after the partially-covering rectangle is drawn, but the
669 // untouched bottom half contains random pixel values that trigger asserts in the
670 // SurfacePartialDraw_gpu test for no longer matching the initial color. Running the
671 // SurfacePartialDraw_gpu test without the OverdrawSurface_gpu test completes successfully.
672 //
673 // Requesting a much larger backend texture size seems to prevent it from reusing the same
674 // memory and avoids the issue.
675#if defined(SK_BUILD_FOR_SKQP)
ericrkc4025182016-05-04 12:01:58 -0700676 const int kWidth = 10;
677 const int kHeight = 10;
Michael Ludwig72ab3462018-12-10 12:43:36 -0500678#else
679 const int kWidth = 100;
680 const int kHeight = 100;
681#endif
682
Ben Wagner7ecc5962016-11-02 17:07:33 -0400683 std::unique_ptr<uint32_t[]> pixels(new uint32_t[kWidth * kHeight]);
ericrkc4025182016-05-04 12:01:58 -0700684 sk_memset32(pixels.get(), color, kWidth * kHeight);
Greg Daniel7ef28f32017-04-20 16:41:55 +0000685
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500686 *outTexture = gpu->createTestingOnlyBackendTexture(
Robert Phillips646f6372018-09-25 09:31:10 -0400687 pixels.get(), kWidth, kHeight, GrColorType::kRGBA_8888, true, GrMipMapped::kNo);
Greg Daniel7ef28f32017-04-20 16:41:55 +0000688
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500689 if (!outTexture->isValid() || !gpu->isTestingOnlyBackendTexture(*outTexture)) {
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500690 return nullptr;
691 }
Greg Daniel7ef28f32017-04-20 16:41:55 +0000692
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500693 sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(context, *outTexture,
Robert Phillipse44ef102017-07-21 15:37:19 -0400694 kTopLeft_GrSurfaceOrigin, sampleCnt,
Greg Danielfaa095e2017-12-19 13:15:02 -0500695 kRGBA_8888_SkColorType,
Greg Daniel7ef28f32017-04-20 16:41:55 +0000696 nullptr, nullptr);
ericrkc4025182016-05-04 12:01:58 -0700697 if (!surface) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500698 gpu->deleteTestingOnlyBackendTexture(*outTexture);
ericrkc4025182016-05-04 12:01:58 -0700699 return nullptr;
700 }
ericrkc4025182016-05-04 12:01:58 -0700701 return surface;
702}
bsalomone63ffef2016-02-05 07:17:34 -0800703
ericrkc4025182016-05-04 12:01:58 -0700704static sk_sp<SkSurface> create_gpu_surface_backend_texture_as_render_target(
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500705 GrContext* context, int sampleCnt, uint32_t color, GrBackendTexture* outTexture) {
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500706 GrGpu* gpu = context->contextPriv().getGpu();
707
ericrkc4025182016-05-04 12:01:58 -0700708 const int kWidth = 10;
709 const int kHeight = 10;
Ben Wagner7ecc5962016-11-02 17:07:33 -0400710 std::unique_ptr<uint32_t[]> pixels(new uint32_t[kWidth * kHeight]);
ericrkc4025182016-05-04 12:01:58 -0700711 sk_memset32(pixels.get(), color, kWidth * kHeight);
Greg Daniel7ef28f32017-04-20 16:41:55 +0000712
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500713 *outTexture = gpu->createTestingOnlyBackendTexture(
Robert Phillips646f6372018-09-25 09:31:10 -0400714 pixels.get(), kWidth, kHeight, GrColorType::kRGBA_8888, true, GrMipMapped::kNo, 0);
Greg Daniel7ef28f32017-04-20 16:41:55 +0000715
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500716 if (!outTexture->isValid() || !gpu->isTestingOnlyBackendTexture(*outTexture)) {
ericrkc4025182016-05-04 12:01:58 -0700717 return nullptr;
718 }
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500719
720 sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTextureAsRenderTarget(
Greg Danielfaa095e2017-12-19 13:15:02 -0500721 context, *outTexture, kTopLeft_GrSurfaceOrigin, sampleCnt, kRGBA_8888_SkColorType,
722 nullptr, nullptr);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500723
724 if (!surface) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500725 gpu->deleteTestingOnlyBackendTexture(*outTexture);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500726 return nullptr;
727 }
ericrkc4025182016-05-04 12:01:58 -0700728 return surface;
729}
730
731static void test_surface_clear(skiatest::Reporter* reporter, sk_sp<SkSurface> surface,
Robert Phillips2c862492017-01-18 10:08:39 -0500732 std::function<sk_sp<GrSurfaceContext>(SkSurface*)> grSurfaceGetter,
ericrkc4025182016-05-04 12:01:58 -0700733 uint32_t expectedValue) {
bsalomone63ffef2016-02-05 07:17:34 -0800734 if (!surface) {
735 ERRORF(reporter, "Could not create GPU SkSurface.");
736 return;
737 }
738 int w = surface->width();
739 int h = surface->height();
Ben Wagner7ecc5962016-11-02 17:07:33 -0400740 std::unique_ptr<uint32_t[]> pixels(new uint32_t[w * h]);
ericrkc4025182016-05-04 12:01:58 -0700741 sk_memset32(pixels.get(), ~expectedValue, w * h);
bsalomone63ffef2016-02-05 07:17:34 -0800742
Robert Phillips2c862492017-01-18 10:08:39 -0500743 sk_sp<GrSurfaceContext> grSurfaceContext(grSurfaceGetter(surface.get()));
744 if (!grSurfaceContext) {
bsalomone63ffef2016-02-05 07:17:34 -0800745 ERRORF(reporter, "Could access render target of GPU SkSurface.");
746 return;
747 }
bsalomon2fba8092016-02-05 13:47:06 -0800748 surface.reset();
Robert Phillips2c862492017-01-18 10:08:39 -0500749
750 SkImageInfo ii = SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
751 grSurfaceContext->readPixels(ii, pixels.get(), 0, 0, 0);
bsalomone63ffef2016-02-05 07:17:34 -0800752 for (int y = 0; y < h; ++y) {
753 for (int x = 0; x < w; ++x) {
754 uint32_t pixel = pixels.get()[y * w + x];
755 if (pixel != expectedValue) {
756 SkString msg;
757 if (expectedValue) {
758 msg = "SkSurface should have left render target unmodified";
759 } else {
760 msg = "SkSurface should have cleared the render target";
761 }
762 ERRORF(reporter,
763 "%s but read 0x%08x (instead of 0x%08x) at %x,%d", msg.c_str(), pixel,
764 expectedValue, x, y);
765 return;
766 }
767 }
768 }
769}
770
bsalomon758586c2016-04-06 14:02:39 -0700771DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -0700772 GrContext* context = ctxInfo.grContext();
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500773 GrGpu* gpu = context->contextPriv().getGpu();
ericrkc4025182016-05-04 12:01:58 -0700774
Robert Phillips2c862492017-01-18 10:08:39 -0500775 std::function<sk_sp<GrSurfaceContext>(SkSurface*)> grSurfaceContextGetters[] = {
egdanielab527a52016-06-28 08:07:26 -0700776 [] (SkSurface* s){
Robert Phillips2c862492017-01-18 10:08:39 -0500777 return sk_ref_sp(s->getCanvas()->internal_private_accessTopLayerRenderTargetContext());
778 },
779 [] (SkSurface* s){
780 sk_sp<SkImage> i(s->makeImageSnapshot());
781 SkImage_Gpu* gpuImage = (SkImage_Gpu *) as_IB(i);
Robert Phillips6de99042017-01-31 11:31:39 -0500782 sk_sp<GrTextureProxy> proxy = gpuImage->asTextureProxyRef();
Robert Phillips2c862492017-01-18 10:08:39 -0500783 GrContext* context = gpuImage->context();
784 return context->contextPriv().makeWrappedSurfaceContext(std::move(proxy),
785 gpuImage->refColorSpace());
786 }
bsalomone63ffef2016-02-05 07:17:34 -0800787 };
ericrkc4025182016-05-04 12:01:58 -0700788
Robert Phillips2c862492017-01-18 10:08:39 -0500789 for (auto grSurfaceGetter : grSurfaceContextGetters) {
ericrkc4025182016-05-04 12:01:58 -0700790 // Test that non-wrapped RTs are created clear.
bsalomone63ffef2016-02-05 07:17:34 -0800791 for (auto& surface_func : {&create_gpu_surface, &create_gpu_scratch_surface}) {
reede8f30622016-03-23 18:59:25 -0700792 auto surface = surface_func(context, kPremul_SkAlphaType, nullptr);
bsalomone63ffef2016-02-05 07:17:34 -0800793 test_surface_clear(reporter, surface, grSurfaceGetter, 0x0);
794 }
795 // Wrapped RTs are *not* supposed to clear (to allow client to partially update a surface).
ericrkc4025182016-05-04 12:01:58 -0700796 const uint32_t kOrigColor = 0xABABABAB;
797 for (auto& surfaceFunc : {&create_gpu_surface_backend_texture,
798 &create_gpu_surface_backend_texture_as_render_target}) {
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500799 GrBackendTexture backendTex;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500800 auto surface = surfaceFunc(context, 1, kOrigColor, &backendTex);
ericrkc4025182016-05-04 12:01:58 -0700801 test_surface_clear(reporter, surface, grSurfaceGetter, kOrigColor);
802 surface.reset();
Brian Salomon26102cb2018-03-09 09:33:19 -0500803 gpu->deleteTestingOnlyBackendTexture(backendTex);
ericrkc4025182016-05-04 12:01:58 -0700804 }
805 }
806}
bsalomone63ffef2016-02-05 07:17:34 -0800807
ericrkc4025182016-05-04 12:01:58 -0700808static void test_surface_draw_partially(
809 skiatest::Reporter* reporter, sk_sp<SkSurface> surface, uint32_t origColor) {
810 const int kW = surface->width();
811 const int kH = surface->height();
812 SkPaint paint;
813 const SkColor kRectColor = ~origColor | 0xFF000000;
814 paint.setColor(kRectColor);
815 surface->getCanvas()->drawRect(SkRect::MakeWH(SkIntToScalar(kW), SkIntToScalar(kH)/2),
816 paint);
Ben Wagner7ecc5962016-11-02 17:07:33 -0400817 std::unique_ptr<uint32_t[]> pixels(new uint32_t[kW * kH]);
ericrkc4025182016-05-04 12:01:58 -0700818 sk_memset32(pixels.get(), ~origColor, kW * kH);
819 // Read back RGBA to avoid format conversions that may not be supported on all platforms.
820 SkImageInfo readInfo = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
821 SkAssertResult(surface->readPixels(readInfo, pixels.get(), kW * sizeof(uint32_t), 0, 0));
822 bool stop = false;
823 SkPMColor origColorPM = SkPackARGB_as_RGBA((origColor >> 24 & 0xFF),
824 (origColor >> 0 & 0xFF),
825 (origColor >> 8 & 0xFF),
826 (origColor >> 16 & 0xFF));
827 SkPMColor rectColorPM = SkPackARGB_as_RGBA((kRectColor >> 24 & 0xFF),
828 (kRectColor >> 16 & 0xFF),
829 (kRectColor >> 8 & 0xFF),
830 (kRectColor >> 0 & 0xFF));
831 for (int y = 0; y < kH/2 && !stop; ++y) {
832 for (int x = 0; x < kW && !stop; ++x) {
833 REPORTER_ASSERT(reporter, rectColorPM == pixels[x + y * kW]);
834 if (rectColorPM != pixels[x + y * kW]) {
835 stop = true;
836 }
837 }
838 }
839 stop = false;
840 for (int y = kH/2; y < kH && !stop; ++y) {
841 for (int x = 0; x < kW && !stop; ++x) {
842 REPORTER_ASSERT(reporter, origColorPM == pixels[x + y * kW]);
843 if (origColorPM != pixels[x + y * kW]) {
844 stop = true;
845 }
846 }
847 }
848}
bsalomone63ffef2016-02-05 07:17:34 -0800849
egdanielab527a52016-06-28 08:07:26 -0700850DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacePartialDraw_Gpu, reporter, ctxInfo) {
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500851 GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu();
ericrkc4025182016-05-04 12:01:58 -0700852 if (!gpu) {
853 return;
854 }
855 static const uint32_t kOrigColor = 0xFFAABBCC;
bsalomone63ffef2016-02-05 07:17:34 -0800856
ericrkc4025182016-05-04 12:01:58 -0700857 for (auto& surfaceFunc : {&create_gpu_surface_backend_texture,
858 &create_gpu_surface_backend_texture_as_render_target}) {
859 // Validate that we can draw to the canvas and that the original texture color is
860 // preserved in pixels that aren't rendered to via the surface.
861 // This works only for non-multisampled case.
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500862 GrBackendTexture backendTex;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500863 auto surface = surfaceFunc(ctxInfo.grContext(), 1, kOrigColor, &backendTex);
ericrkc4025182016-05-04 12:01:58 -0700864 if (surface) {
865 test_surface_draw_partially(reporter, surface, kOrigColor);
866 surface.reset();
Brian Salomon26102cb2018-03-09 09:33:19 -0500867 gpu->deleteTestingOnlyBackendTexture(backendTex);
ericrkc4025182016-05-04 12:01:58 -0700868 }
869 }
870}
871
872
873DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceAttachStencil_Gpu, reporter, ctxInfo) {
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500874 GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu();
ericrkc4025182016-05-04 12:01:58 -0700875 if (!gpu) {
876 return;
877 }
Eric Karl5c779752017-05-08 12:02:07 -0700878 if (gpu->caps()->avoidStencilBuffers()) {
879 return;
880 }
ericrkc4025182016-05-04 12:01:58 -0700881 static const uint32_t kOrigColor = 0xFFAABBCC;
882
Robert Phillips6be756b2018-01-16 15:07:54 -0500883 auto resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider();
884
ericrkc4025182016-05-04 12:01:58 -0700885 for (auto& surfaceFunc : {&create_gpu_surface_backend_texture,
886 &create_gpu_surface_backend_texture_as_render_target}) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500887 for (int sampleCnt : {1, 4, 8}) {
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500888 GrBackendTexture backendTex;
889 auto surface = surfaceFunc(ctxInfo.grContext(), sampleCnt, kOrigColor, &backendTex);
ericrkc4025182016-05-04 12:01:58 -0700890
Brian Salomonbdecacf2018-02-02 20:32:49 -0500891 if (!surface && sampleCnt > 1) {
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500892 // Certain platforms don't support MSAA, skip these.
893 continue;
ericrkc4025182016-05-04 12:01:58 -0700894 }
895
896 // Validate that we can attach a stencil buffer to an SkSurface created by either of
897 // our surface functions.
Brian Osman11052242016-10-27 14:47:55 -0400898 GrRenderTarget* rt = surface->getCanvas()
899 ->internal_private_accessTopLayerRenderTargetContext()->accessRenderTarget();
Robert Phillips6be756b2018-01-16 15:07:54 -0500900 REPORTER_ASSERT(reporter, resourceProvider->attachStencilAttachment(rt));
Brian Salomon26102cb2018-03-09 09:33:19 -0500901 gpu->deleteTestingOnlyBackendTexture(backendTex);
ericrkc4025182016-05-04 12:01:58 -0700902 }
bsalomone63ffef2016-02-05 07:17:34 -0800903 }
904}
brianosman0e22eb82016-08-30 07:07:59 -0700905
Matt Sarett22886c42016-11-22 11:31:41 -0500906static void test_overdraw_surface(skiatest::Reporter* r, SkSurface* surface) {
Matt Sarette11b6142016-11-28 18:28:07 -0500907 SkOverdrawCanvas canvas(surface->getCanvas());
908 canvas.drawPaint(SkPaint());
Matt Sarett22886c42016-11-22 11:31:41 -0500909 sk_sp<SkImage> image = surface->makeImageSnapshot();
910
911 SkBitmap bitmap;
Cary Clark4f5a79c2018-02-07 15:51:00 -0500912 image->asLegacyBitmap(&bitmap);
Matt Sarett22886c42016-11-22 11:31:41 -0500913 for (int y = 0; y < 10; y++) {
914 for (int x = 0; x < 10; x++) {
915 REPORTER_ASSERT(r, 1 == SkGetPackedA32(*bitmap.getAddr32(x, y)));
916 }
917 }
918}
919
920DEF_TEST(OverdrawSurface_Raster, r) {
921 sk_sp<SkSurface> surface = create_surface();
922 test_overdraw_surface(r, surface.get());
923}
924
Matt Sarett22886c42016-11-22 11:31:41 -0500925DEF_GPUTEST_FOR_RENDERING_CONTEXTS(OverdrawSurface_Gpu, r, ctxInfo) {
926 GrContext* context = ctxInfo.grContext();
927 sk_sp<SkSurface> surface = create_gpu_surface(context);
928 test_overdraw_surface(r, surface.get());
929}
Mike Reed44d04bd2017-06-28 19:57:21 -0400930
931DEF_TEST(Surface_null, r) {
932 REPORTER_ASSERT(r, SkSurface::MakeNull(0, 0) == nullptr);
933
934 const int w = 37;
935 const int h = 1000;
936 auto surf = SkSurface::MakeNull(w, h);
937 auto canvas = surf->getCanvas();
938
939 canvas->drawPaint(SkPaint()); // should not crash, but don't expect anything to draw
940 REPORTER_ASSERT(r, surf->makeImageSnapshot() == nullptr);
941}
Mike Reedd4746982018-02-07 16:05:29 -0500942
943// assert: if a given imageinfo is valid for a surface, then it must be valid for an image
944// (so the snapshot can succeed)
945DEF_TEST(surface_image_unity, reporter) {
946 auto do_test = [reporter](const SkImageInfo& info) {
947 size_t rowBytes = info.minRowBytes();
948 auto surf = SkSurface::MakeRaster(info, rowBytes, nullptr);
949 if (surf) {
950 auto img = surf->makeImageSnapshot();
951 if (!img && false) { // change to true to document the differences
952 SkDebugf("image failed: [%08X %08X] %14s %s\n",
953 info.width(), info.height(),
954 sk_tool_utils::colortype_name(info.colorType()),
955 sk_tool_utils::alphatype_name(info.alphaType()));
956 return;
957 }
958 REPORTER_ASSERT(reporter, img != nullptr);
959
960 char dummyPixel = 0; // just need a valid address (not a valid size)
961 SkPixmap pmap = { info, &dummyPixel, rowBytes };
962 img = SkImage::MakeFromRaster(pmap, nullptr, nullptr);
963 REPORTER_ASSERT(reporter, img != nullptr);
964 }
965 };
966
Mike Kleine978ca22018-10-29 11:29:58 -0400967 const int32_t sizes[] = { -1, 0, 1, 1 << 18 };
Mike Klein30dc8f92018-02-16 10:08:10 -0500968 for (int cti = 0; cti <= kLastEnum_SkColorType; ++cti) {
Mike Reedd4746982018-02-07 16:05:29 -0500969 SkColorType ct = static_cast<SkColorType>(cti);
Mike Klein30dc8f92018-02-16 10:08:10 -0500970 for (int ati = 0; ati <= kLastEnum_SkAlphaType; ++ati) {
Mike Reedd4746982018-02-07 16:05:29 -0500971 SkAlphaType at = static_cast<SkAlphaType>(ati);
972 for (int32_t size : sizes) {
973 do_test(SkImageInfo::Make(1, size, ct, at));
974 do_test(SkImageInfo::Make(size, 1, ct, at));
975 }
976 }
977 }
978}