blob: 87dc56122239533cdb505d16fd236e35ca60e48a [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");
412 const SkPoint testPoints2[] = {
413 { SkIntToScalar(0), SkIntToScalar(1) },
414 { SkIntToScalar(1), SkIntToScalar(1) },
415 { SkIntToScalar(2), SkIntToScalar(1) },
416 { SkIntToScalar(3), SkIntToScalar(1) },
417 { SkIntToScalar(4), SkIntToScalar(1) },
418 { SkIntToScalar(5), SkIntToScalar(1) },
419 { SkIntToScalar(6), SkIntToScalar(1) },
420 { SkIntToScalar(7), SkIntToScalar(1) },
421 { SkIntToScalar(8), SkIntToScalar(1) },
422 { SkIntToScalar(9), SkIntToScalar(1) },
423 { SkIntToScalar(10), SkIntToScalar(1) },
424 };
425
426#define EXPECT_COPY_ON_WRITE(command) \
427 { \
reed9ce9d672016-03-17 10:51:11 -0700428 sk_sp<SkImage> imageBefore = surface->makeImageSnapshot(); \
429 sk_sp<SkImage> aur_before(imageBefore); \
junov@chromium.org995beb62013-03-28 13:49:22 +0000430 canvas-> command ; \
reed9ce9d672016-03-17 10:51:11 -0700431 sk_sp<SkImage> imageAfter = surface->makeImageSnapshot(); \
432 sk_sp<SkImage> aur_after(imageAfter); \
junov@chromium.org995beb62013-03-28 13:49:22 +0000433 REPORTER_ASSERT(reporter, imageBefore != imageAfter); \
434 }
435
436 EXPECT_COPY_ON_WRITE(clear(testColor))
437 EXPECT_COPY_ON_WRITE(drawPaint(testPaint))
438 EXPECT_COPY_ON_WRITE(drawPoints(SkCanvas::kPoints_PointMode, testPointCount, testPoints, \
439 testPaint))
440 EXPECT_COPY_ON_WRITE(drawOval(testRect, testPaint))
441 EXPECT_COPY_ON_WRITE(drawRect(testRect, testPaint))
442 EXPECT_COPY_ON_WRITE(drawRRect(testRRect, testPaint))
443 EXPECT_COPY_ON_WRITE(drawPath(testPath, testPaint))
444 EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0))
reede47829b2015-08-06 10:02:53 -0700445 EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, testRect, nullptr))
halcanary96fcdcc2015-08-27 07:41:13 -0700446 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, nullptr))
Cary Clark2a475ea2017-04-28 15:35:12 -0400447 EXPECT_COPY_ON_WRITE(drawString(testText, 0, 1, testPaint))
junov@chromium.org995beb62013-03-28 13:49:22 +0000448 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoints2, \
449 testPaint))
kkinnunen179a8f52015-11-20 13:32:24 -0800450}
451DEF_TEST(SurfaceCopyOnWrite, reporter) {
reede8f30622016-03-23 18:59:25 -0700452 test_copy_on_write(reporter, create_surface().get());
kkinnunen179a8f52015-11-20 13:32:24 -0800453}
egdanielab527a52016-06-28 08:07:26 -0700454DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, ctxInfo) {
kkinnunen179a8f52015-11-20 13:32:24 -0800455 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
bsalomon8b7451a2016-05-11 06:33:06 -0700456 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
reede8f30622016-03-23 18:59:25 -0700457 test_copy_on_write(reporter, surface.get());
fmalitae2639082015-08-06 07:04:51 -0700458 }
junov@chromium.org995beb62013-03-28 13:49:22 +0000459}
460
kkinnunen179a8f52015-11-20 13:32:24 -0800461static void test_writable_after_snapshot_release(skiatest::Reporter* reporter,
462 SkSurface* surface) {
junov@chromium.orgaf058352013-04-03 15:03:26 +0000463 // This test succeeds by not triggering an assertion.
464 // The test verifies that the surface remains writable (usable) after
465 // acquiring and releasing a snapshot without triggering a copy on write.
junov@chromium.orgaf058352013-04-03 15:03:26 +0000466 SkCanvas* canvas = surface->getCanvas();
467 canvas->clear(1);
reed9ce9d672016-03-17 10:51:11 -0700468 surface->makeImageSnapshot(); // Create and destroy SkImage
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000469 canvas->clear(2); // Must not assert internally
junov@chromium.org995beb62013-03-28 13:49:22 +0000470}
kkinnunen179a8f52015-11-20 13:32:24 -0800471DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) {
reede8f30622016-03-23 18:59:25 -0700472 test_writable_after_snapshot_release(reporter, create_surface().get());
kkinnunen179a8f52015-11-20 13:32:24 -0800473}
egdanielab527a52016-06-28 08:07:26 -0700474DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu, reporter, ctxInfo) {
kkinnunen179a8f52015-11-20 13:32:24 -0800475 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
bsalomon8b7451a2016-05-11 06:33:06 -0700476 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
reede8f30622016-03-23 18:59:25 -0700477 test_writable_after_snapshot_release(reporter, surface.get());
kkinnunen179a8f52015-11-20 13:32:24 -0800478 }
479}
junov@chromium.orgda904742013-05-01 22:38:16 +0000480
kkinnunen179a8f52015-11-20 13:32:24 -0800481static void test_crbug263329(skiatest::Reporter* reporter,
482 SkSurface* surface1,
483 SkSurface* surface2) {
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000484 // This is a regression test for crbug.com/263329
485 // Bug was caused by onCopyOnWrite releasing the old surface texture
486 // back to the scratch texture pool even though the texture is used
487 // by and active SkImage_Gpu.
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000488 SkCanvas* canvas1 = surface1->getCanvas();
489 SkCanvas* canvas2 = surface2->getCanvas();
490 canvas1->clear(1);
reed9ce9d672016-03-17 10:51:11 -0700491 sk_sp<SkImage> image1(surface1->makeImageSnapshot());
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000492 // Trigger copy on write, new backing is a scratch texture
493 canvas1->clear(2);
reed9ce9d672016-03-17 10:51:11 -0700494 sk_sp<SkImage> image2(surface1->makeImageSnapshot());
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000495 // Trigger copy on write, old backing should not be returned to scratch
496 // pool because it is held by image2
497 canvas1->clear(3);
498
499 canvas2->clear(4);
reed9ce9d672016-03-17 10:51:11 -0700500 sk_sp<SkImage> image3(surface2->makeImageSnapshot());
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000501 // Trigger copy on write on surface2. The new backing store should not
502 // be recycling a texture that is held by an existing image.
503 canvas2->clear(5);
reed9ce9d672016-03-17 10:51:11 -0700504 sk_sp<SkImage> image4(surface2->makeImageSnapshot());
Robert Phillips87444052017-06-23 14:09:30 -0400505 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image3)->getTexture());
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000506 // The following assertion checks crbug.com/263329
Robert Phillips87444052017-06-23 14:09:30 -0400507 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image2)->getTexture());
508 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image1)->getTexture());
509 REPORTER_ASSERT(reporter, as_IB(image3)->getTexture() != as_IB(image2)->getTexture());
510 REPORTER_ASSERT(reporter, as_IB(image3)->getTexture() != as_IB(image1)->getTexture());
511 REPORTER_ASSERT(reporter, as_IB(image2)->getTexture() != as_IB(image1)->getTexture());
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000512}
egdanielab527a52016-06-28 08:07:26 -0700513DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_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 surface1(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
516 auto surface2(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
reede8f30622016-03-23 18:59:25 -0700517 test_crbug263329(reporter, surface1.get(), surface2.get());
kkinnunen179a8f52015-11-20 13:32:24 -0800518 }
519}
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000520
kkinnunen179a8f52015-11-20 13:32:24 -0800521DEF_TEST(SurfaceGetTexture, reporter) {
reede8f30622016-03-23 18:59:25 -0700522 auto surface(create_surface());
reed9ce9d672016-03-17 10:51:11 -0700523 sk_sp<SkImage> image(surface->makeImageSnapshot());
Robert Phillips6de99042017-01-31 11:31:39 -0500524 REPORTER_ASSERT(reporter, !as_IB(image)->isTextureBacked());
kkinnunen179a8f52015-11-20 13:32:24 -0800525 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
Robert Phillips6de99042017-01-31 11:31:39 -0500526 REPORTER_ASSERT(reporter, !as_IB(image)->isTextureBacked());
kkinnunen179a8f52015-11-20 13:32:24 -0800527}
egdanielab527a52016-06-28 08:07:26 -0700528DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, ctxInfo) {
kkinnunen179a8f52015-11-20 13:32:24 -0800529 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
bsalomon8b7451a2016-05-11 06:33:06 -0700530 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
reed9ce9d672016-03-17 10:51:11 -0700531 sk_sp<SkImage> image(surface->makeImageSnapshot());
Robert Phillips6de99042017-01-31 11:31:39 -0500532
533 REPORTER_ASSERT(reporter, as_IB(image)->isTextureBacked());
Robert Phillipsc5509952018-04-04 15:54:55 -0400534 GrBackendTexture backendTex = image->getBackendTexture(false);
535 REPORTER_ASSERT(reporter, backendTex.isValid());
kkinnunen179a8f52015-11-20 13:32:24 -0800536 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
Robert Phillips6de99042017-01-31 11:31:39 -0500537 REPORTER_ASSERT(reporter, as_IB(image)->isTextureBacked());
Robert Phillipsc5509952018-04-04 15:54:55 -0400538 GrBackendTexture backendTex2 = image->getBackendTexture(false);
539 REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(backendTex, backendTex2));
junov@chromium.orgda904742013-05-01 22:38:16 +0000540 }
junov@chromium.orgda904742013-05-01 22:38:16 +0000541}
bsalomoneaaaf0b2015-01-23 08:08:04 -0800542
reede8f30622016-03-23 18:59:25 -0700543static SkBudgeted is_budgeted(const sk_sp<SkSurface>& surf) {
544 SkSurface_Gpu* gsurf = (SkSurface_Gpu*)surf.get();
Robert Phillips6de99042017-01-31 11:31:39 -0500545
546 GrRenderTargetProxy* proxy = gsurf->getDevice()->accessRenderTargetContext()
547 ->asRenderTargetProxy();
548 return proxy->isBudgeted();
bsalomoneaaaf0b2015-01-23 08:08:04 -0800549}
550
bsalomon5ec26ae2016-02-25 08:33:02 -0800551static SkBudgeted is_budgeted(SkImage* image) {
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400552 return ((SkImage_Gpu*)image)->peekProxy()->isBudgeted();
bsalomoneaaaf0b2015-01-23 08:08:04 -0800553}
554
reed9ce9d672016-03-17 10:51:11 -0700555static SkBudgeted is_budgeted(const sk_sp<SkImage> image) {
556 return is_budgeted(image.get());
557}
558
egdanielab527a52016-06-28 08:07:26 -0700559DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, ctxInfo) {
bsalomoneaaaf0b2015-01-23 08:08:04 -0800560 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8);
Robert Phillipsac6b1fa2017-03-20 08:38:50 -0400561 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) {
562 auto surface(SkSurface::MakeRenderTarget(ctxInfo.grContext(), budgeted, info));
563 SkASSERT(surface);
564 REPORTER_ASSERT(reporter, budgeted == is_budgeted(surface));
bsalomoneaaaf0b2015-01-23 08:08:04 -0800565
Robert Phillipsac6b1fa2017-03-20 08:38:50 -0400566 sk_sp<SkImage> image(surface->makeImageSnapshot());
bsalomoneaaaf0b2015-01-23 08:08:04 -0800567
Robert Phillipsac6b1fa2017-03-20 08:38:50 -0400568 // Initially the image shares a texture with the surface, and the
569 // the budgets should always match.
570 REPORTER_ASSERT(reporter, budgeted == is_budgeted(surface));
571 REPORTER_ASSERT(reporter, budgeted == is_budgeted(image));
bsalomoneaaaf0b2015-01-23 08:08:04 -0800572
Robert Phillipsac6b1fa2017-03-20 08:38:50 -0400573 // Now trigger copy-on-write
574 surface->getCanvas()->clear(SK_ColorBLUE);
bsalomoneaaaf0b2015-01-23 08:08:04 -0800575
Robert Phillipsac6b1fa2017-03-20 08:38:50 -0400576 // They don't share a texture anymore but the budgets should still match.
577 REPORTER_ASSERT(reporter, budgeted == is_budgeted(surface));
578 REPORTER_ASSERT(reporter, budgeted == is_budgeted(image));
bsalomoneaaaf0b2015-01-23 08:08:04 -0800579 }
580}
junov@chromium.orgda904742013-05-01 22:38:16 +0000581
kkinnunen179a8f52015-11-20 13:32:24 -0800582static void test_no_canvas1(skiatest::Reporter* reporter,
583 SkSurface* surface,
584 SkSurface::ContentChangeMode mode) {
585 // Test passes by not asserting
586 surface->notifyContentWillChange(mode);
kkinnunen179a8f52015-11-20 13:32:24 -0800587}
588static void test_no_canvas2(skiatest::Reporter* reporter,
589 SkSurface* surface,
590 SkSurface::ContentChangeMode mode) {
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000591 // Verifies the robustness of SkSurface for handling use cases where calls
592 // are made before a canvas is created.
reed9ce9d672016-03-17 10:51:11 -0700593 sk_sp<SkImage> image1 = surface->makeImageSnapshot();
594 sk_sp<SkImage> aur_image1(image1);
kkinnunen179a8f52015-11-20 13:32:24 -0800595 surface->notifyContentWillChange(mode);
reed9ce9d672016-03-17 10:51:11 -0700596 sk_sp<SkImage> image2 = surface->makeImageSnapshot();
597 sk_sp<SkImage> aur_image2(image2);
kkinnunen179a8f52015-11-20 13:32:24 -0800598 REPORTER_ASSERT(reporter, image1 != image2);
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000599}
kkinnunen179a8f52015-11-20 13:32:24 -0800600DEF_TEST(SurfaceNoCanvas, reporter) {
601 SkSurface::ContentChangeMode modes[] =
602 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentChangeMode};
603 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) {
604 for (auto& mode : modes) {
reede8f30622016-03-23 18:59:25 -0700605 test_func(reporter, create_surface().get(), mode);
kkinnunen179a8f52015-11-20 13:32:24 -0800606 }
607 }
608}
egdanielab527a52016-06-28 08:07:26 -0700609DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, ctxInfo) {
kkinnunen179a8f52015-11-20 13:32:24 -0800610 SkSurface::ContentChangeMode modes[] =
611 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentChangeMode};
612 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
613 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) {
614 for (auto& mode : modes) {
bsalomon8b7451a2016-05-11 06:33:06 -0700615 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
reede8f30622016-03-23 18:59:25 -0700616 test_func(reporter, surface.get(), mode);
bsalomone904c092014-07-17 10:50:59 -0700617 }
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000618 }
junov@chromium.orgaf058352013-04-03 15:03:26 +0000619 }
junov@chromium.org995beb62013-03-28 13:49:22 +0000620}
reed9cd016e2016-01-30 10:01:06 -0800621
622static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Reporter* reporter) {
reed6ceeebd2016-03-09 14:26:26 -0800623 SkPixmap surfacePM;
624 REPORTER_ASSERT(reporter, surface->peekPixels(&surfacePM));
reed9cd016e2016-01-30 10:01:06 -0800625
reed9ce9d672016-03-17 10:51:11 -0700626 sk_sp<SkImage> image(surface->makeImageSnapshot());
reed6ceeebd2016-03-09 14:26:26 -0800627 SkPixmap pm;
628 REPORTER_ASSERT(reporter, image->peekPixels(&pm));
reed9cd016e2016-01-30 10:01:06 -0800629
reed6ceeebd2016-03-09 14:26:26 -0800630 REPORTER_ASSERT(reporter, surfacePM.rowBytes() == pm.rowBytes());
reed9cd016e2016-01-30 10:01:06 -0800631
632 // trigger a copy-on-write
633 surface->getCanvas()->drawPaint(SkPaint());
reed9ce9d672016-03-17 10:51:11 -0700634 sk_sp<SkImage> image2(surface->makeImageSnapshot());
reed9cd016e2016-01-30 10:01:06 -0800635 REPORTER_ASSERT(reporter, image->uniqueID() != image2->uniqueID());
636
reed6ceeebd2016-03-09 14:26:26 -0800637 SkPixmap pm2;
638 REPORTER_ASSERT(reporter, image2->peekPixels(&pm2));
639 REPORTER_ASSERT(reporter, pm2.rowBytes() == pm.rowBytes());
reed9cd016e2016-01-30 10:01:06 -0800640}
641
642DEF_TEST(surface_rowbytes, reporter) {
643 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
644
reede8f30622016-03-23 18:59:25 -0700645 auto surf0(SkSurface::MakeRaster(info));
646 check_rowbytes_remain_consistent(surf0.get(), reporter);
reed9cd016e2016-01-30 10:01:06 -0800647
648 // specify a larger rowbytes
reede8f30622016-03-23 18:59:25 -0700649 auto surf1(SkSurface::MakeRaster(info, 500, nullptr));
650 check_rowbytes_remain_consistent(surf1.get(), reporter);
reed9cd016e2016-01-30 10:01:06 -0800651
652 // Try some illegal rowByte values
reede8f30622016-03-23 18:59:25 -0700653 auto s = SkSurface::MakeRaster(info, 396, nullptr); // needs to be at least 400
reed9cd016e2016-01-30 10:01:06 -0800654 REPORTER_ASSERT(reporter, nullptr == s);
Mike Reedf0ffb892017-10-03 14:47:21 -0400655 s = SkSurface::MakeRaster(info, std::numeric_limits<size_t>::max(), nullptr);
reed9cd016e2016-01-30 10:01:06 -0800656 REPORTER_ASSERT(reporter, nullptr == s);
657}
bsalomone63ffef2016-02-05 07:17:34 -0800658
fmalita03912f12016-07-06 06:22:06 -0700659DEF_TEST(surface_raster_zeroinitialized, reporter) {
660 sk_sp<SkSurface> s(SkSurface::MakeRasterN32Premul(100, 100));
661 SkPixmap pixmap;
662 REPORTER_ASSERT(reporter, s->peekPixels(&pixmap));
663
664 for (int i = 0; i < pixmap.info().width(); ++i) {
665 for (int j = 0; j < pixmap.info().height(); ++j) {
666 REPORTER_ASSERT(reporter, *pixmap.addr32(i, j) == 0);
667 }
668 }
669}
670
ericrkc4025182016-05-04 12:01:58 -0700671static sk_sp<SkSurface> create_gpu_surface_backend_texture(
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500672 GrContext* context, int sampleCnt, uint32_t color, GrBackendTexture* outTexture) {
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500673 GrGpu* gpu = context->contextPriv().getGpu();
674
ericrkc4025182016-05-04 12:01:58 -0700675 const int kWidth = 10;
676 const int kHeight = 10;
Ben Wagner7ecc5962016-11-02 17:07:33 -0400677 std::unique_ptr<uint32_t[]> pixels(new uint32_t[kWidth * kHeight]);
ericrkc4025182016-05-04 12:01:58 -0700678 sk_memset32(pixels.get(), color, kWidth * kHeight);
Greg Daniel7ef28f32017-04-20 16:41:55 +0000679
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500680 *outTexture = gpu->createTestingOnlyBackendTexture(
Robert Phillips646f6372018-09-25 09:31:10 -0400681 pixels.get(), kWidth, kHeight, GrColorType::kRGBA_8888, true, GrMipMapped::kNo);
Greg Daniel7ef28f32017-04-20 16:41:55 +0000682
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500683 if (!outTexture->isValid() || !gpu->isTestingOnlyBackendTexture(*outTexture)) {
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500684 return nullptr;
685 }
Greg Daniel7ef28f32017-04-20 16:41:55 +0000686
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500687 sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(context, *outTexture,
Robert Phillipse44ef102017-07-21 15:37:19 -0400688 kTopLeft_GrSurfaceOrigin, sampleCnt,
Greg Danielfaa095e2017-12-19 13:15:02 -0500689 kRGBA_8888_SkColorType,
Greg Daniel7ef28f32017-04-20 16:41:55 +0000690 nullptr, nullptr);
ericrkc4025182016-05-04 12:01:58 -0700691 if (!surface) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500692 gpu->deleteTestingOnlyBackendTexture(*outTexture);
ericrkc4025182016-05-04 12:01:58 -0700693 return nullptr;
694 }
ericrkc4025182016-05-04 12:01:58 -0700695 return surface;
696}
bsalomone63ffef2016-02-05 07:17:34 -0800697
ericrkc4025182016-05-04 12:01:58 -0700698static sk_sp<SkSurface> create_gpu_surface_backend_texture_as_render_target(
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500699 GrContext* context, int sampleCnt, uint32_t color, GrBackendTexture* outTexture) {
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500700 GrGpu* gpu = context->contextPriv().getGpu();
701
ericrkc4025182016-05-04 12:01:58 -0700702 const int kWidth = 10;
703 const int kHeight = 10;
Ben Wagner7ecc5962016-11-02 17:07:33 -0400704 std::unique_ptr<uint32_t[]> pixels(new uint32_t[kWidth * kHeight]);
ericrkc4025182016-05-04 12:01:58 -0700705 sk_memset32(pixels.get(), color, kWidth * kHeight);
Greg Daniel7ef28f32017-04-20 16:41:55 +0000706
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500707 *outTexture = gpu->createTestingOnlyBackendTexture(
Robert Phillips646f6372018-09-25 09:31:10 -0400708 pixels.get(), kWidth, kHeight, GrColorType::kRGBA_8888, true, GrMipMapped::kNo, 0);
Greg Daniel7ef28f32017-04-20 16:41:55 +0000709
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500710 if (!outTexture->isValid() || !gpu->isTestingOnlyBackendTexture(*outTexture)) {
ericrkc4025182016-05-04 12:01:58 -0700711 return nullptr;
712 }
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500713
714 sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTextureAsRenderTarget(
Greg Danielfaa095e2017-12-19 13:15:02 -0500715 context, *outTexture, kTopLeft_GrSurfaceOrigin, sampleCnt, kRGBA_8888_SkColorType,
716 nullptr, nullptr);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500717
718 if (!surface) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500719 gpu->deleteTestingOnlyBackendTexture(*outTexture);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500720 return nullptr;
721 }
ericrkc4025182016-05-04 12:01:58 -0700722 return surface;
723}
724
725static void test_surface_clear(skiatest::Reporter* reporter, sk_sp<SkSurface> surface,
Robert Phillips2c862492017-01-18 10:08:39 -0500726 std::function<sk_sp<GrSurfaceContext>(SkSurface*)> grSurfaceGetter,
ericrkc4025182016-05-04 12:01:58 -0700727 uint32_t expectedValue) {
bsalomone63ffef2016-02-05 07:17:34 -0800728 if (!surface) {
729 ERRORF(reporter, "Could not create GPU SkSurface.");
730 return;
731 }
732 int w = surface->width();
733 int h = surface->height();
Ben Wagner7ecc5962016-11-02 17:07:33 -0400734 std::unique_ptr<uint32_t[]> pixels(new uint32_t[w * h]);
ericrkc4025182016-05-04 12:01:58 -0700735 sk_memset32(pixels.get(), ~expectedValue, w * h);
bsalomone63ffef2016-02-05 07:17:34 -0800736
Robert Phillips2c862492017-01-18 10:08:39 -0500737 sk_sp<GrSurfaceContext> grSurfaceContext(grSurfaceGetter(surface.get()));
738 if (!grSurfaceContext) {
bsalomone63ffef2016-02-05 07:17:34 -0800739 ERRORF(reporter, "Could access render target of GPU SkSurface.");
740 return;
741 }
bsalomon2fba8092016-02-05 13:47:06 -0800742 surface.reset();
Robert Phillips2c862492017-01-18 10:08:39 -0500743
744 SkImageInfo ii = SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
745 grSurfaceContext->readPixels(ii, pixels.get(), 0, 0, 0);
bsalomone63ffef2016-02-05 07:17:34 -0800746 for (int y = 0; y < h; ++y) {
747 for (int x = 0; x < w; ++x) {
748 uint32_t pixel = pixels.get()[y * w + x];
749 if (pixel != expectedValue) {
750 SkString msg;
751 if (expectedValue) {
752 msg = "SkSurface should have left render target unmodified";
753 } else {
754 msg = "SkSurface should have cleared the render target";
755 }
756 ERRORF(reporter,
757 "%s but read 0x%08x (instead of 0x%08x) at %x,%d", msg.c_str(), pixel,
758 expectedValue, x, y);
759 return;
760 }
761 }
762 }
763}
764
bsalomon758586c2016-04-06 14:02:39 -0700765DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -0700766 GrContext* context = ctxInfo.grContext();
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500767 GrGpu* gpu = context->contextPriv().getGpu();
ericrkc4025182016-05-04 12:01:58 -0700768
Robert Phillips2c862492017-01-18 10:08:39 -0500769 std::function<sk_sp<GrSurfaceContext>(SkSurface*)> grSurfaceContextGetters[] = {
egdanielab527a52016-06-28 08:07:26 -0700770 [] (SkSurface* s){
Robert Phillips2c862492017-01-18 10:08:39 -0500771 return sk_ref_sp(s->getCanvas()->internal_private_accessTopLayerRenderTargetContext());
772 },
773 [] (SkSurface* s){
774 sk_sp<SkImage> i(s->makeImageSnapshot());
775 SkImage_Gpu* gpuImage = (SkImage_Gpu *) as_IB(i);
Robert Phillips6de99042017-01-31 11:31:39 -0500776 sk_sp<GrTextureProxy> proxy = gpuImage->asTextureProxyRef();
Robert Phillips2c862492017-01-18 10:08:39 -0500777 GrContext* context = gpuImage->context();
778 return context->contextPriv().makeWrappedSurfaceContext(std::move(proxy),
779 gpuImage->refColorSpace());
780 }
bsalomone63ffef2016-02-05 07:17:34 -0800781 };
ericrkc4025182016-05-04 12:01:58 -0700782
Robert Phillips2c862492017-01-18 10:08:39 -0500783 for (auto grSurfaceGetter : grSurfaceContextGetters) {
ericrkc4025182016-05-04 12:01:58 -0700784 // Test that non-wrapped RTs are created clear.
bsalomone63ffef2016-02-05 07:17:34 -0800785 for (auto& surface_func : {&create_gpu_surface, &create_gpu_scratch_surface}) {
reede8f30622016-03-23 18:59:25 -0700786 auto surface = surface_func(context, kPremul_SkAlphaType, nullptr);
bsalomone63ffef2016-02-05 07:17:34 -0800787 test_surface_clear(reporter, surface, grSurfaceGetter, 0x0);
788 }
789 // Wrapped RTs are *not* supposed to clear (to allow client to partially update a surface).
ericrkc4025182016-05-04 12:01:58 -0700790 const uint32_t kOrigColor = 0xABABABAB;
791 for (auto& surfaceFunc : {&create_gpu_surface_backend_texture,
792 &create_gpu_surface_backend_texture_as_render_target}) {
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500793 GrBackendTexture backendTex;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500794 auto surface = surfaceFunc(context, 1, kOrigColor, &backendTex);
ericrkc4025182016-05-04 12:01:58 -0700795 test_surface_clear(reporter, surface, grSurfaceGetter, kOrigColor);
796 surface.reset();
Brian Salomon26102cb2018-03-09 09:33:19 -0500797 gpu->deleteTestingOnlyBackendTexture(backendTex);
ericrkc4025182016-05-04 12:01:58 -0700798 }
799 }
800}
bsalomone63ffef2016-02-05 07:17:34 -0800801
ericrkc4025182016-05-04 12:01:58 -0700802static void test_surface_draw_partially(
803 skiatest::Reporter* reporter, sk_sp<SkSurface> surface, uint32_t origColor) {
804 const int kW = surface->width();
805 const int kH = surface->height();
806 SkPaint paint;
807 const SkColor kRectColor = ~origColor | 0xFF000000;
808 paint.setColor(kRectColor);
809 surface->getCanvas()->drawRect(SkRect::MakeWH(SkIntToScalar(kW), SkIntToScalar(kH)/2),
810 paint);
Ben Wagner7ecc5962016-11-02 17:07:33 -0400811 std::unique_ptr<uint32_t[]> pixels(new uint32_t[kW * kH]);
ericrkc4025182016-05-04 12:01:58 -0700812 sk_memset32(pixels.get(), ~origColor, kW * kH);
813 // Read back RGBA to avoid format conversions that may not be supported on all platforms.
814 SkImageInfo readInfo = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
815 SkAssertResult(surface->readPixels(readInfo, pixels.get(), kW * sizeof(uint32_t), 0, 0));
816 bool stop = false;
817 SkPMColor origColorPM = SkPackARGB_as_RGBA((origColor >> 24 & 0xFF),
818 (origColor >> 0 & 0xFF),
819 (origColor >> 8 & 0xFF),
820 (origColor >> 16 & 0xFF));
821 SkPMColor rectColorPM = SkPackARGB_as_RGBA((kRectColor >> 24 & 0xFF),
822 (kRectColor >> 16 & 0xFF),
823 (kRectColor >> 8 & 0xFF),
824 (kRectColor >> 0 & 0xFF));
825 for (int y = 0; y < kH/2 && !stop; ++y) {
826 for (int x = 0; x < kW && !stop; ++x) {
827 REPORTER_ASSERT(reporter, rectColorPM == pixels[x + y * kW]);
828 if (rectColorPM != pixels[x + y * kW]) {
829 stop = true;
830 }
831 }
832 }
833 stop = false;
834 for (int y = kH/2; y < kH && !stop; ++y) {
835 for (int x = 0; x < kW && !stop; ++x) {
836 REPORTER_ASSERT(reporter, origColorPM == pixels[x + y * kW]);
837 if (origColorPM != pixels[x + y * kW]) {
838 stop = true;
839 }
840 }
841 }
842}
bsalomone63ffef2016-02-05 07:17:34 -0800843
egdanielab527a52016-06-28 08:07:26 -0700844DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacePartialDraw_Gpu, reporter, ctxInfo) {
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500845 GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu();
ericrkc4025182016-05-04 12:01:58 -0700846 if (!gpu) {
847 return;
848 }
849 static const uint32_t kOrigColor = 0xFFAABBCC;
bsalomone63ffef2016-02-05 07:17:34 -0800850
ericrkc4025182016-05-04 12:01:58 -0700851 for (auto& surfaceFunc : {&create_gpu_surface_backend_texture,
852 &create_gpu_surface_backend_texture_as_render_target}) {
853 // Validate that we can draw to the canvas and that the original texture color is
854 // preserved in pixels that aren't rendered to via the surface.
855 // This works only for non-multisampled case.
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500856 GrBackendTexture backendTex;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500857 auto surface = surfaceFunc(ctxInfo.grContext(), 1, kOrigColor, &backendTex);
ericrkc4025182016-05-04 12:01:58 -0700858 if (surface) {
859 test_surface_draw_partially(reporter, surface, kOrigColor);
860 surface.reset();
Brian Salomon26102cb2018-03-09 09:33:19 -0500861 gpu->deleteTestingOnlyBackendTexture(backendTex);
ericrkc4025182016-05-04 12:01:58 -0700862 }
863 }
864}
865
866
867DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceAttachStencil_Gpu, reporter, ctxInfo) {
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500868 GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu();
ericrkc4025182016-05-04 12:01:58 -0700869 if (!gpu) {
870 return;
871 }
Eric Karl5c779752017-05-08 12:02:07 -0700872 if (gpu->caps()->avoidStencilBuffers()) {
873 return;
874 }
ericrkc4025182016-05-04 12:01:58 -0700875 static const uint32_t kOrigColor = 0xFFAABBCC;
876
Robert Phillips6be756b2018-01-16 15:07:54 -0500877 auto resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider();
878
ericrkc4025182016-05-04 12:01:58 -0700879 for (auto& surfaceFunc : {&create_gpu_surface_backend_texture,
880 &create_gpu_surface_backend_texture_as_render_target}) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500881 for (int sampleCnt : {1, 4, 8}) {
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500882 GrBackendTexture backendTex;
883 auto surface = surfaceFunc(ctxInfo.grContext(), sampleCnt, kOrigColor, &backendTex);
ericrkc4025182016-05-04 12:01:58 -0700884
Brian Salomonbdecacf2018-02-02 20:32:49 -0500885 if (!surface && sampleCnt > 1) {
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500886 // Certain platforms don't support MSAA, skip these.
887 continue;
ericrkc4025182016-05-04 12:01:58 -0700888 }
889
890 // Validate that we can attach a stencil buffer to an SkSurface created by either of
891 // our surface functions.
Brian Osman11052242016-10-27 14:47:55 -0400892 GrRenderTarget* rt = surface->getCanvas()
893 ->internal_private_accessTopLayerRenderTargetContext()->accessRenderTarget();
Robert Phillips6be756b2018-01-16 15:07:54 -0500894 REPORTER_ASSERT(reporter, resourceProvider->attachStencilAttachment(rt));
Brian Salomon26102cb2018-03-09 09:33:19 -0500895 gpu->deleteTestingOnlyBackendTexture(backendTex);
ericrkc4025182016-05-04 12:01:58 -0700896 }
bsalomone63ffef2016-02-05 07:17:34 -0800897 }
898}
brianosman0e22eb82016-08-30 07:07:59 -0700899
Matt Sarett22886c42016-11-22 11:31:41 -0500900static void test_overdraw_surface(skiatest::Reporter* r, SkSurface* surface) {
Matt Sarette11b6142016-11-28 18:28:07 -0500901 SkOverdrawCanvas canvas(surface->getCanvas());
902 canvas.drawPaint(SkPaint());
Matt Sarett22886c42016-11-22 11:31:41 -0500903 sk_sp<SkImage> image = surface->makeImageSnapshot();
904
905 SkBitmap bitmap;
Cary Clark4f5a79c2018-02-07 15:51:00 -0500906 image->asLegacyBitmap(&bitmap);
Matt Sarett22886c42016-11-22 11:31:41 -0500907 for (int y = 0; y < 10; y++) {
908 for (int x = 0; x < 10; x++) {
909 REPORTER_ASSERT(r, 1 == SkGetPackedA32(*bitmap.getAddr32(x, y)));
910 }
911 }
912}
913
914DEF_TEST(OverdrawSurface_Raster, r) {
915 sk_sp<SkSurface> surface = create_surface();
916 test_overdraw_surface(r, surface.get());
917}
918
Matt Sarett22886c42016-11-22 11:31:41 -0500919DEF_GPUTEST_FOR_RENDERING_CONTEXTS(OverdrawSurface_Gpu, r, ctxInfo) {
920 GrContext* context = ctxInfo.grContext();
921 sk_sp<SkSurface> surface = create_gpu_surface(context);
922 test_overdraw_surface(r, surface.get());
923}
Mike Reed44d04bd2017-06-28 19:57:21 -0400924
925DEF_TEST(Surface_null, r) {
926 REPORTER_ASSERT(r, SkSurface::MakeNull(0, 0) == nullptr);
927
928 const int w = 37;
929 const int h = 1000;
930 auto surf = SkSurface::MakeNull(w, h);
931 auto canvas = surf->getCanvas();
932
933 canvas->drawPaint(SkPaint()); // should not crash, but don't expect anything to draw
934 REPORTER_ASSERT(r, surf->makeImageSnapshot() == nullptr);
935}
Mike Reedd4746982018-02-07 16:05:29 -0500936
937// assert: if a given imageinfo is valid for a surface, then it must be valid for an image
938// (so the snapshot can succeed)
939DEF_TEST(surface_image_unity, reporter) {
940 auto do_test = [reporter](const SkImageInfo& info) {
941 size_t rowBytes = info.minRowBytes();
942 auto surf = SkSurface::MakeRaster(info, rowBytes, nullptr);
943 if (surf) {
944 auto img = surf->makeImageSnapshot();
945 if (!img && false) { // change to true to document the differences
946 SkDebugf("image failed: [%08X %08X] %14s %s\n",
947 info.width(), info.height(),
948 sk_tool_utils::colortype_name(info.colorType()),
949 sk_tool_utils::alphatype_name(info.alphaType()));
950 return;
951 }
952 REPORTER_ASSERT(reporter, img != nullptr);
953
954 char dummyPixel = 0; // just need a valid address (not a valid size)
955 SkPixmap pmap = { info, &dummyPixel, rowBytes };
956 img = SkImage::MakeFromRaster(pmap, nullptr, nullptr);
957 REPORTER_ASSERT(reporter, img != nullptr);
958 }
959 };
960
Mike Kleine978ca22018-10-29 11:29:58 -0400961 const int32_t sizes[] = { -1, 0, 1, 1 << 18 };
Mike Klein30dc8f92018-02-16 10:08:10 -0500962 for (int cti = 0; cti <= kLastEnum_SkColorType; ++cti) {
Mike Reedd4746982018-02-07 16:05:29 -0500963 SkColorType ct = static_cast<SkColorType>(cti);
Mike Klein30dc8f92018-02-16 10:08:10 -0500964 for (int ati = 0; ati <= kLastEnum_SkAlphaType; ++ati) {
Mike Reedd4746982018-02-07 16:05:29 -0500965 SkAlphaType at = static_cast<SkAlphaType>(ati);
966 for (int32_t size : sizes) {
967 do_test(SkImageInfo::Make(1, size, ct, at));
968 do_test(SkImageInfo::Make(size, 1, ct, at));
969 }
970 }
971 }
972}