blob: c75f81cec1c3500d07c977cbb658b88ec44cf6a7 [file] [log] [blame]
Brian Salomon201700f2019-05-17 12:05:44 -04001/*
2 * Copyright 2019 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
9#include "include/core/SkCanvas.h"
10#include "include/core/SkColor.h"
11#include "include/core/SkPaint.h"
12#include "include/core/SkRect.h"
13#include "include/core/SkSurface.h"
Brian Salomon024bd002019-06-11 11:38:16 -040014#include "include/core/SkYUVAIndex.h"
Robert Phillips2a4acf32020-07-06 15:50:15 -040015#include "include/gpu/GrDirectContext.h"
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040016#include "include/gpu/GrRecordingContext.h"
Brian Salomon201700f2019-05-17 12:05:44 -040017#include "src/core/SkAutoPixmapStorage.h"
18#include "src/core/SkConvertPixels.h"
Brian Salomon024bd002019-06-11 11:38:16 -040019#include "src/core/SkScopeExit.h"
Brian Salomon201700f2019-05-17 12:05:44 -040020#include "tools/Resources.h"
21#include "tools/ToolUtils.h"
22
Brian Salomon9241a6d2019-10-03 13:26:54 -040023namespace {
24struct AsyncContext {
25 bool fCalled = false;
Brian Salomon63a0a752020-06-26 13:32:09 -040026 std::unique_ptr<const SkImage::AsyncReadResult> fResult;
Brian Salomon9241a6d2019-10-03 13:26:54 -040027};
28} // anonymous namespace
29
30// Making this a lambda in the test functions caused:
31// "error: cannot compile this forwarded non-trivially copyable parameter yet"
32// on x86/Win/Clang bot, referring to 'result'.
Brian Salomon63a0a752020-06-26 13:32:09 -040033static void async_callback(void* c, std::unique_ptr<const SkImage::AsyncReadResult> result) {
Brian Salomon9241a6d2019-10-03 13:26:54 -040034 auto context = static_cast<AsyncContext*>(c);
35 context->fResult = std::move(result);
36 context->fCalled = true;
37};
38
Brian Salomon201700f2019-05-17 12:05:44 -040039// Draws the image to a surface, does a asyncRescaleAndReadPixels of the image, and then sticks
40// the result in a raster image.
Brian Salomon63a0a752020-06-26 13:32:09 -040041template <typename Src>
42static sk_sp<SkImage> do_read_and_scale(Src* src,
Robert Phillipsd436b782020-07-10 11:49:06 -040043 GrDirectContext* direct,
Brian Salomon63a0a752020-06-26 13:32:09 -040044 const SkIRect& srcRect,
45 const SkImageInfo& ii,
46 SkImage::RescaleGamma rescaleGamma,
Brian Salomon286b5572019-05-20 10:25:50 -040047 SkFilterQuality quality) {
Brian Salomon63a0a752020-06-26 13:32:09 -040048 auto* asyncContext = new AsyncContext();
49 src->asyncRescaleAndReadPixels(ii, srcRect, rescaleGamma, quality, async_callback,
50 asyncContext);
Robert Phillipsd436b782020-07-10 11:49:06 -040051 if (direct) {
52 direct->submit();
Brian Salomon39278022020-06-02 11:47:26 -040053 }
Brian Salomon63a0a752020-06-26 13:32:09 -040054 while (!asyncContext->fCalled) {
Brian Salomon9c219782019-10-02 22:51:08 +000055 // Only GPU should actually be asynchronous.
Robert Phillipsd436b782020-07-10 11:49:06 -040056 SkASSERT(direct);
57 direct->checkAsyncWorkCompletion();
Brian Salomon9c219782019-10-02 22:51:08 +000058 }
Brian Salomon63a0a752020-06-26 13:32:09 -040059 if (!asyncContext->fResult) {
Brian Salomon9241a6d2019-10-03 13:26:54 -040060 return nullptr;
61 }
Brian Salomon63a0a752020-06-26 13:32:09 -040062 SkPixmap pixmap(ii, asyncContext->fResult->data(0), asyncContext->fResult->rowBytes(0));
Brian Salomon9241a6d2019-10-03 13:26:54 -040063 auto releasePixels = [](const void*, void* c) { delete static_cast<AsyncContext*>(c); };
Brian Salomon63a0a752020-06-26 13:32:09 -040064 return SkImage::MakeFromRaster(pixmap, releasePixels, asyncContext);
Ravi Mistrycb550102019-10-03 09:06:25 +000065}
66
Brian Salomon63a0a752020-06-26 13:32:09 -040067template <typename Src>
68static sk_sp<SkImage> do_read_and_scale_yuv(Src* src,
Robert Phillipsd436b782020-07-10 11:49:06 -040069 GrDirectContext* direct,
Brian Salomon63a0a752020-06-26 13:32:09 -040070 SkYUVColorSpace yuvCS,
71 const SkIRect& srcRect,
72 SkISize size,
73 SkImage::RescaleGamma rescaleGamma,
74 SkFilterQuality quality,
75 SkScopeExit* cleanup) {
Brian Salomon9241a6d2019-10-03 13:26:54 -040076 SkASSERT(!(size.width() & 0b1) && !(size.height() & 0b1));
Ravi Mistrycb550102019-10-03 09:06:25 +000077
Brian Salomon9241a6d2019-10-03 13:26:54 -040078 SkISize uvSize = {size.width()/2, size.height()/2};
79 SkImageInfo yII = SkImageInfo::Make(size, kGray_8_SkColorType, kPremul_SkAlphaType);
80 SkImageInfo uvII = SkImageInfo::Make(uvSize, kGray_8_SkColorType, kPremul_SkAlphaType);
Ravi Mistrycb550102019-10-03 09:06:25 +000081
Brian Salomon63a0a752020-06-26 13:32:09 -040082 AsyncContext asyncContext;
83 src->asyncRescaleAndReadPixelsYUV420(yuvCS, SkColorSpace::MakeSRGB(), srcRect, size,
84 rescaleGamma, quality, async_callback, &asyncContext);
Robert Phillipsd436b782020-07-10 11:49:06 -040085 if (direct) {
86 direct->submit();
Brian Salomon39278022020-06-02 11:47:26 -040087 }
Brian Salomon63a0a752020-06-26 13:32:09 -040088 while (!asyncContext.fCalled) {
Ravi Mistrycb550102019-10-03 09:06:25 +000089 // Only GPU should actually be asynchronous.
Robert Phillipsd436b782020-07-10 11:49:06 -040090 SkASSERT(direct);
91 direct->checkAsyncWorkCompletion();
Ravi Mistrycb550102019-10-03 09:06:25 +000092 }
Brian Salomon63a0a752020-06-26 13:32:09 -040093 if (!asyncContext.fResult) {
Brian Salomoncd5caa32019-06-11 17:02:19 -040094 return nullptr;
95 }
Brian Salomon024bd002019-06-11 11:38:16 -040096 GrBackendTexture backendTextures[3];
Robert Phillips0a15cc62019-07-30 12:49:10 -040097
Brian Salomon63a0a752020-06-26 13:32:09 -040098 SkPixmap yPM(yII, asyncContext.fResult->data(0), asyncContext.fResult->rowBytes(0));
99 SkPixmap uPM(uvII, asyncContext.fResult->data(1), asyncContext.fResult->rowBytes(1));
100 SkPixmap vPM(uvII, asyncContext.fResult->data(2), asyncContext.fResult->rowBytes(2));
Brian Salomon9241a6d2019-10-03 13:26:54 -0400101
Robert Phillipsd436b782020-07-10 11:49:06 -0400102 backendTextures[0] = direct->createBackendTexture(yPM, GrRenderable::kNo, GrProtected::kNo);
103 backendTextures[1] = direct->createBackendTexture(uPM, GrRenderable::kNo, GrProtected::kNo);
104 backendTextures[2] = direct->createBackendTexture(vPM, GrRenderable::kNo, GrProtected::kNo);
Brian Salomon9241a6d2019-10-03 13:26:54 -0400105
Robert Phillips2e1142c2019-08-14 12:33:29 -0400106 SkYUVAIndex indices[4] = {
107 { 0, SkColorChannel::kR},
108 { 1, SkColorChannel::kR},
109 { 2, SkColorChannel::kR},
110 {-1, SkColorChannel::kR}
111 };
112
Robert Phillipsd436b782020-07-10 11:49:06 -0400113 *cleanup = {[direct, backendTextures] {
114 direct->flush();
115 direct->submit(true);
116 direct->deleteBackendTexture(backendTextures[0]);
117 direct->deleteBackendTexture(backendTextures[1]);
118 direct->deleteBackendTexture(backendTextures[2]);
Brian Salomon024bd002019-06-11 11:38:16 -0400119 }};
120
Robert Phillipsd436b782020-07-10 11:49:06 -0400121 return SkImage::MakeFromYUVATextures(direct, yuvCS, backendTextures, indices, size,
Brian Salomon024bd002019-06-11 11:38:16 -0400122 kTopLeft_GrSurfaceOrigin, SkColorSpace::MakeSRGB());
123}
124
Brian Salomon201700f2019-05-17 12:05:44 -0400125// Draws a grid of rescales. The columns are none, low, and high filter quality. The rows are
126// rescale in src gamma and rescale in linear gamma.
Brian Salomon63a0a752020-06-26 13:32:09 -0400127template <typename Src>
128static skiagm::DrawResult do_rescale_grid(SkCanvas* canvas,
129 Src* src,
Robert Phillipsd436b782020-07-10 11:49:06 -0400130 GrDirectContext* direct,
Brian Salomon63a0a752020-06-26 13:32:09 -0400131 const SkIRect& srcRect,
132 SkISize newSize,
133 bool doYUV420,
134 SkString* errorMsg,
135 int pad = 0) {
Robert Phillipsd436b782020-07-10 11:49:06 -0400136 if (doYUV420 && !direct) {
Adlai Hollere3ad5272020-07-07 10:27:55 -0400137 errorMsg->printf("YUV420 only supported on direct GPU for now.");
138 return skiagm::DrawResult::kSkip;
Brian Salomon024bd002019-06-11 11:38:16 -0400139 }
Brian Salomon201700f2019-05-17 12:05:44 -0400140 if (canvas->imageInfo().colorType() == kUnknown_SkColorType) {
141 *errorMsg = "Not supported on recording/vector backends.";
142 return skiagm::DrawResult::kSkip;
143 }
Brian Salomon9241a6d2019-10-03 13:26:54 -0400144 const auto ii = canvas->imageInfo().makeDimensions(newSize);
Brian Salomona34e0fc2019-05-17 19:56:59 +0000145
Brian Salomon024bd002019-06-11 11:38:16 -0400146 SkYUVColorSpace yuvColorSpace = kRec601_SkYUVColorSpace;
Brian Salomona34e0fc2019-05-17 19:56:59 +0000147 canvas->save();
Brian Salomon63a0a752020-06-26 13:32:09 -0400148 for (auto gamma : {SkImage::RescaleGamma::kSrc, SkImage::RescaleGamma::kLinear}) {
Brian Salomona34e0fc2019-05-17 19:56:59 +0000149 canvas->save();
150 for (auto quality : {kNone_SkFilterQuality, kLow_SkFilterQuality, kHigh_SkFilterQuality}) {
Brian Salomon024bd002019-06-11 11:38:16 -0400151 SkScopeExit cleanup;
152 sk_sp<SkImage> result;
153 if (doYUV420) {
Robert Phillipsd436b782020-07-10 11:49:06 -0400154 result = do_read_and_scale_yuv(src, direct, yuvColorSpace, srcRect, newSize, gamma,
Brian Salomon024bd002019-06-11 11:38:16 -0400155 quality, &cleanup);
Brian Salomoncd5caa32019-06-11 17:02:19 -0400156 if (!result) {
157 errorMsg->printf("YUV420 async call failed. Allowed for now.");
158 return skiagm::DrawResult::kSkip;
159 }
Brian Salomon024bd002019-06-11 11:38:16 -0400160 int nextCS = static_cast<int>(yuvColorSpace + 1) % (kLastEnum_SkYUVColorSpace + 1);
161 yuvColorSpace = static_cast<SkYUVColorSpace>(nextCS);
162 } else {
Robert Phillipsd436b782020-07-10 11:49:06 -0400163 result = do_read_and_scale(src, direct, srcRect, ii, gamma, quality);
Brian Salomoncd5caa32019-06-11 17:02:19 -0400164 if (!result) {
165 errorMsg->printf("async read call failed.");
166 return skiagm::DrawResult::kFail;
167 }
Brian Salomon024bd002019-06-11 11:38:16 -0400168 }
169 canvas->drawImage(result, 0, 0);
Brian Salomon9241a6d2019-10-03 13:26:54 -0400170 canvas->translate(newSize.width() + pad, 0);
Brian Salomona34e0fc2019-05-17 19:56:59 +0000171 }
172 canvas->restore();
Brian Salomon9241a6d2019-10-03 13:26:54 -0400173 canvas->translate(0, newSize.height() + pad);
Brian Salomon451b01f2019-05-17 12:39:17 -0400174 }
Brian Salomona34e0fc2019-05-17 19:56:59 +0000175 canvas->restore();
176 return skiagm::DrawResult::kOk;
Brian Salomon451b01f2019-05-17 12:39:17 -0400177}
178
Brian Salomon63a0a752020-06-26 13:32:09 -0400179static skiagm::DrawResult do_rescale_image_grid(SkCanvas* canvas,
180 const char* imageFile,
181 const SkIRect& srcRect,
182 SkISize newSize,
183 bool doSurface,
184 bool doYUV420,
185 SkString* errorMsg) {
Brian Salomon286b5572019-05-20 10:25:50 -0400186 auto image = GetResourceAsImage(imageFile);
187 if (!image) {
188 errorMsg->printf("Could not load image file %s.", imageFile);
189 return skiagm::DrawResult::kFail;
190 }
191 if (canvas->imageInfo().colorType() == kUnknown_SkColorType) {
192 *errorMsg = "Not supported on recording/vector backends.";
193 return skiagm::DrawResult::kSkip;
194 }
Robert Phillipsd436b782020-07-10 11:49:06 -0400195 auto direct = GrAsDirectContext(canvas->recordingContext());
196
Brian Salomon63a0a752020-06-26 13:32:09 -0400197 if (doSurface) {
198 // Turn the image into a surface in order to call the read and rescale API
199 auto surfInfo = image->imageInfo().makeDimensions(image->dimensions());
200 auto surface = canvas->makeSurface(surfInfo);
201 if (!surface && surfInfo.colorType() == kBGRA_8888_SkColorType) {
202 surfInfo = surfInfo.makeColorType(kRGBA_8888_SkColorType);
203 surface = canvas->makeSurface(surfInfo);
Brian Salomon1caf3782020-06-26 17:06:31 +0000204 }
Brian Salomon63a0a752020-06-26 13:32:09 -0400205 if (!surface) {
206 *errorMsg = "Could not create surface for image.";
207 // When testing abandoned GrContext we expect surface creation to fail.
Robert Phillips9eb00022020-06-30 15:30:12 -0400208 if (canvas->recordingContext() && canvas->recordingContext()->abandoned()) {
Brian Salomon63a0a752020-06-26 13:32:09 -0400209 return skiagm::DrawResult::kSkip;
210 }
211 return skiagm::DrawResult::kFail;
212 }
213 SkPaint paint;
214 paint.setBlendMode(SkBlendMode::kSrc);
215 surface->getCanvas()->drawImage(image, 0, 0, &paint);
Robert Phillipsd436b782020-07-10 11:49:06 -0400216 return do_rescale_grid(canvas, surface.get(), direct, srcRect, newSize,
Brian Salomon63a0a752020-06-26 13:32:09 -0400217 doYUV420, errorMsg);
Robert Phillipsd436b782020-07-10 11:49:06 -0400218 } else if (direct) {
219 image = image->makeTextureImage(direct);
Brian Salomon63a0a752020-06-26 13:32:09 -0400220 if (!image) {
221 *errorMsg = "Could not create image.";
222 // When testing abandoned GrContext we expect surface creation to fail.
Robert Phillips9eb00022020-06-30 15:30:12 -0400223 if (canvas->recordingContext() && canvas->recordingContext()->abandoned()) {
Brian Salomon63a0a752020-06-26 13:32:09 -0400224 return skiagm::DrawResult::kSkip;
225 }
226 return skiagm::DrawResult::kFail;
227 }
Brian Salomon1caf3782020-06-26 17:06:31 +0000228 }
Robert Phillipsd436b782020-07-10 11:49:06 -0400229 return do_rescale_grid(canvas, image.get(), direct, srcRect, newSize, doYUV420,
Brian Salomon63a0a752020-06-26 13:32:09 -0400230 errorMsg);
Brian Salomon286b5572019-05-20 10:25:50 -0400231}
232
Brian Salomon63a0a752020-06-26 13:32:09 -0400233#define DEF_RESCALE_AND_READ_SURF_GM(IMAGE_FILE, TAG, SRC_RECT, W, H) \
234 DEF_SIMPLE_GM_CAN_FAIL(async_rescale_and_read_##TAG, canvas, errorMsg, 3 * W, 2 * H) { \
235 ToolUtils::draw_checkerboard(canvas, SK_ColorDKGRAY, SK_ColorLTGRAY, 25); \
236 return do_rescale_image_grid(canvas, #IMAGE_FILE, SRC_RECT, {W, H}, true, false, \
237 errorMsg); \
Brian Salomon201700f2019-05-17 12:05:44 -0400238 }
239
Brian Salomon63a0a752020-06-26 13:32:09 -0400240#define DEF_RESCALE_AND_READ_YUV_SURF_GM(IMAGE_FILE, TAG, SRC_RECT, W, H) \
241 DEF_SIMPLE_GM_CAN_FAIL(async_rescale_and_read_yuv420_##TAG, canvas, errorMsg, 3 * W, 2 * H) { \
242 ToolUtils::draw_checkerboard(canvas, SK_ColorDKGRAY, SK_ColorLTGRAY, 25); \
243 return do_rescale_image_grid(canvas, #IMAGE_FILE, SRC_RECT, {W, H}, true, true, errorMsg); \
Brian Salomon024bd002019-06-11 11:38:16 -0400244 }
245
Brian Salomon63a0a752020-06-26 13:32:09 -0400246#define DEF_RESCALE_AND_READ_IMG_GM(IMAGE_FILE, TAG, SRC_RECT, W, H) \
247 DEF_SIMPLE_GM_CAN_FAIL(async_rescale_and_read_##TAG, canvas, errorMsg, 3 * W, 2 * H) { \
248 ToolUtils::draw_checkerboard(canvas, SK_ColorDKGRAY, SK_ColorLTGRAY, 25); \
249 return do_rescale_image_grid(canvas, #IMAGE_FILE, SRC_RECT, {W, H}, false, false, \
250 errorMsg); \
251 }
Brian Salomon024bd002019-06-11 11:38:16 -0400252
Brian Salomon63a0a752020-06-26 13:32:09 -0400253#define DEF_RESCALE_AND_READ_YUV_IMG_GM(IMAGE_FILE, TAG, SRC_RECT, W, H) \
254 DEF_SIMPLE_GM_CAN_FAIL(async_rescale_and_read_yuv420_##TAG, canvas, errorMsg, 3 * W, 2 * H) { \
255 ToolUtils::draw_checkerboard(canvas, SK_ColorDKGRAY, SK_ColorLTGRAY, 25); \
256 return do_rescale_image_grid(canvas, #IMAGE_FILE, SRC_RECT, {W, H}, true, true, errorMsg); \
257 }
Brian Salomon201700f2019-05-17 12:05:44 -0400258
Brian Salomon63a0a752020-06-26 13:32:09 -0400259DEF_RESCALE_AND_READ_YUV_SURF_GM(
260 images/yellow_rose.webp, rose, SkIRect::MakeXYWH(50, 5, 200, 150), 410, 376)
Brian Salomon201700f2019-05-17 12:05:44 -0400261
Brian Salomon63a0a752020-06-26 13:32:09 -0400262DEF_RESCALE_AND_READ_YUV_IMG_GM(
263 images/yellow_rose.webp, rose_down, SkIRect::MakeXYWH(50, 5, 200, 150), 106, 60)
264
265DEF_RESCALE_AND_READ_SURF_GM(
266 images/yellow_rose.webp, rose, SkIRect::MakeXYWH(100, 20, 100, 100), 410, 410)
267
268DEF_RESCALE_AND_READ_SURF_GM(images/dog.jpg, dog_down, SkIRect::MakeXYWH(0, 10, 180, 150), 45, 45)
269DEF_RESCALE_AND_READ_IMG_GM(images/dog.jpg, dog_up, SkIRect::MakeWH(180, 180), 800, 400)
270
271DEF_RESCALE_AND_READ_IMG_GM(
272 images/text.png, text_down, SkIRect::MakeWH(637, 105), (int)(0.7 * 637), (int)(0.7 * 105))
273DEF_RESCALE_AND_READ_SURF_GM(
274 images/text.png, text_up, SkIRect::MakeWH(637, 105), (int)(1.2 * 637), (int)(1.2 * 105))
275DEF_RESCALE_AND_READ_IMG_GM(images/text.png,
276 text_up_large,
277 SkIRect::MakeXYWH(300, 0, 300, 105),
278 (int)(2.4 * 300),
279 (int)(2.4 * 105))
Brian Salomon286b5572019-05-20 10:25:50 -0400280
Brian Salomona7e5c7c2020-01-27 15:41:40 -0500281// Exercises non-scaling YUV420. Reads from the original canvas's surface in order to
282// exercise case where source surface is not a texture (in glbert config).
283DEF_SIMPLE_GM_CAN_FAIL(async_yuv_no_scale, canvas, errorMsg, 400, 300) {
284 auto surface = canvas->getSurface();
285 if (!surface) {
286 *errorMsg = "Not supported on recording/vector backends.";
287 return skiagm::DrawResult::kSkip;
288 }
289
290 auto image = GetResourceAsImage("images/yellow_rose.webp");
291 if (!image) {
292 return skiagm::DrawResult::kFail;
293 }
294 SkPaint paint;
295 canvas->drawImage(image.get(), 0, 0);
296
Robert Phillipsd436b782020-07-10 11:49:06 -0400297 auto direct = GrAsDirectContext(surface->recordingContext());
Robert Phillips2a4acf32020-07-06 15:50:15 -0400298
Brian Salomona7e5c7c2020-01-27 15:41:40 -0500299 SkScopeExit scopeExit;
300 auto yuvImage = do_read_and_scale_yuv(
Robert Phillips2a4acf32020-07-06 15:50:15 -0400301 surface, direct, kRec601_SkYUVColorSpace, SkIRect::MakeWH(400, 300),
Brian Salomon63a0a752020-06-26 13:32:09 -0400302 {400, 300}, SkImage::RescaleGamma::kSrc, kNone_SkFilterQuality, &scopeExit);
Brian Salomona7e5c7c2020-01-27 15:41:40 -0500303
304 canvas->clear(SK_ColorWHITE);
305 canvas->drawImage(yuvImage.get(), 0, 0);
306
307 return skiagm::DrawResult::kOk;
308}
309
Brian Salomon286b5572019-05-20 10:25:50 -0400310DEF_SIMPLE_GM_CAN_FAIL(async_rescale_and_read_no_bleed, canvas, errorMsg, 60, 60) {
311 if (canvas->imageInfo().colorType() == kUnknown_SkColorType) {
312 *errorMsg = "Not supported on recording/vector backends.";
313 return skiagm::DrawResult::kSkip;
314 }
315
316 static constexpr int kBorder = 5;
317 static constexpr int kInner = 5;
318 const auto srcRect = SkIRect::MakeXYWH(kBorder, kBorder, kInner, kInner);
319 auto surfaceII =
320 SkImageInfo::Make(kInner + 2 * kBorder, kInner + 2 * kBorder, kRGBA_8888_SkColorType,
321 kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
322 auto surface = canvas->makeSurface(surfaceII);
Brian Salomonaf9b7b92019-05-20 12:19:37 -0400323 if (!surface) {
324 *errorMsg = "Could not create surface for image.";
Brian Salomon9be911c2019-05-20 14:01:21 -0400325 // When testing abandoned GrContext we expect surface creation to fail.
Robert Phillipsd436b782020-07-10 11:49:06 -0400326 if (canvas->recordingContext() && canvas->recordingContext()->abandoned()) {
Brian Salomon9be911c2019-05-20 14:01:21 -0400327 return skiagm::DrawResult::kSkip;
328 }
Brian Salomonaf9b7b92019-05-20 12:19:37 -0400329 return skiagm::DrawResult::kFail;
330 }
Brian Salomon286b5572019-05-20 10:25:50 -0400331 surface->getCanvas()->clear(SK_ColorRED);
332 surface->getCanvas()->save();
333 surface->getCanvas()->clipRect(SkRect::Make(srcRect), SkClipOp::kIntersect, false);
334 surface->getCanvas()->clear(SK_ColorBLUE);
335 surface->getCanvas()->restore();
336 static constexpr int kPad = 2;
337 canvas->translate(kPad, kPad);
338 skiagm::DrawResult result;
Brian Salomon9241a6d2019-10-03 13:26:54 -0400339 SkISize downSize = {static_cast<int>(kInner/2), static_cast<int>(kInner / 2)};
Robert Phillipsd436b782020-07-10 11:49:06 -0400340 auto direct = GrAsDirectContext(canvas->recordingContext());
341 result = do_rescale_grid(canvas, surface.get(), direct, srcRect, downSize, false, errorMsg,
Brian Salomon63a0a752020-06-26 13:32:09 -0400342 kPad);
343
Brian Salomon286b5572019-05-20 10:25:50 -0400344 if (result != skiagm::DrawResult::kOk) {
345 return result;
346 }
Mike Kleinf68213f2020-01-27 12:16:22 -0600347 canvas->translate(0, 4 * downSize.height());
Brian Salomon9241a6d2019-10-03 13:26:54 -0400348 SkISize upSize = {static_cast<int>(kInner * 3.5), static_cast<int>(kInner * 4.6)};
Robert Phillipsd436b782020-07-10 11:49:06 -0400349 result = do_rescale_grid(canvas, surface.get(), direct, srcRect, upSize, false, errorMsg, kPad);
Brian Salomon286b5572019-05-20 10:25:50 -0400350 if (result != skiagm::DrawResult::kOk) {
351 return result;
352 }
353 return skiagm::DrawResult::kOk;
354}