Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 1 | /* |
| 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 Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 14 | #include "include/core/SkYUVAIndex.h" |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 15 | #include "include/gpu/GrContext.h" |
| 16 | #include "src/core/SkAutoPixmapStorage.h" |
| 17 | #include "src/core/SkConvertPixels.h" |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 18 | #include "src/core/SkScopeExit.h" |
| 19 | #include "src/gpu/GrContextPriv.h" |
| 20 | #include "src/gpu/GrGpu.h" |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 21 | #include "tools/Resources.h" |
| 22 | #include "tools/ToolUtils.h" |
| 23 | |
| 24 | // Draws the image to a surface, does a asyncRescaleAndReadPixels of the image, and then sticks |
| 25 | // the result in a raster image. |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 26 | static sk_sp<SkImage> do_read_and_scale(SkSurface* surface, const SkIRect& srcRect, |
| 27 | const SkImageInfo& ii, SkSurface::RescaleGamma rescaleGamma, |
| 28 | SkFilterQuality quality) { |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 29 | SkBitmap bmp; |
| 30 | bmp.allocPixels(ii); |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 31 | SkPaint paint; |
| 32 | paint.setBlendMode(SkBlendMode::kSrc); |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 33 | struct Context { |
| 34 | SkPixmap fPixmap; |
| 35 | bool fCalled = false; |
Brian Salomon | cd5caa3 | 2019-06-11 17:02:19 -0400 | [diff] [blame] | 36 | bool fSucceeded = false; |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 37 | } context; |
| 38 | SkAssertResult(bmp.peekPixels(&context.fPixmap)); |
| 39 | auto callback = [](void* c, const void* data, size_t rowBytes) { |
| 40 | auto context = reinterpret_cast<Context*>(c); |
| 41 | context->fCalled = true; |
| 42 | if (!data) { |
| 43 | context->fPixmap.reset(); |
| 44 | return; |
| 45 | } |
Brian Salomon | cd5caa3 | 2019-06-11 17:02:19 -0400 | [diff] [blame] | 46 | context->fSucceeded = true; |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 47 | SkRectMemcpy(context->fPixmap.writable_addr(), context->fPixmap.rowBytes(), data, rowBytes, |
| 48 | context->fPixmap.info().minRowBytes(), context->fPixmap.height()); |
| 49 | }; |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 50 | surface->asyncRescaleAndReadPixels(ii, srcRect, rescaleGamma, quality, callback, &context); |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 51 | while (!context.fCalled) { |
| 52 | // Only GPU should actually be asynchronous. |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 53 | SkASSERT(surface->getCanvas()->getGrContext()); |
| 54 | surface->getCanvas()->getGrContext()->checkAsyncWorkCompletion(); |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 55 | } |
Brian Salomon | cd5caa3 | 2019-06-11 17:02:19 -0400 | [diff] [blame] | 56 | return context.fSucceeded ? SkImage::MakeFromBitmap(bmp) : nullptr; |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 57 | } |
| 58 | |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 59 | static sk_sp<SkImage> do_read_and_scale_yuv(SkSurface* surface, SkYUVColorSpace yuvCS, |
| 60 | const SkIRect& srcRect, int dstW, int dstH, |
| 61 | SkSurface::RescaleGamma rescaleGamma, |
| 62 | SkFilterQuality quality, SkScopeExit* cleanup) { |
| 63 | SkASSERT(!(dstW & 0b1) && !(dstH & 0b1)); |
| 64 | std::unique_ptr<uint8_t[]> yData(new uint8_t[dstW * dstH]); |
| 65 | std::unique_ptr<uint8_t[]> uData(new uint8_t[dstW / 2 * dstH / 2]); |
| 66 | std::unique_ptr<uint8_t[]> vData(new uint8_t[dstW / 2 * dstH / 2]); |
| 67 | struct Context { |
| 68 | int fW; |
| 69 | int fH; |
| 70 | uint8_t* fYData; |
| 71 | uint8_t* fUData; |
| 72 | uint8_t* fVData; |
| 73 | bool fCalled = false; |
Brian Salomon | cd5caa3 | 2019-06-11 17:02:19 -0400 | [diff] [blame] | 74 | bool fSucceeded = false; |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 75 | } context{dstW, dstH, yData.get(), uData.get(), vData.get()}; |
| 76 | auto callback = [](void* c, const void* data[2], size_t rowBytes[2]) { |
| 77 | auto context = reinterpret_cast<Context*>(c); |
| 78 | context->fCalled = true; |
| 79 | if (!data) { |
| 80 | return; |
| 81 | } |
Brian Salomon | cd5caa3 | 2019-06-11 17:02:19 -0400 | [diff] [blame] | 82 | context->fSucceeded = true; |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 83 | int w = context->fW; |
| 84 | int h = context->fH; |
| 85 | SkRectMemcpy(context->fYData, w, data[0], rowBytes[0], w, h); |
| 86 | SkRectMemcpy(context->fUData, w / 2, data[1], rowBytes[1], w / 2, h / 2); |
| 87 | SkRectMemcpy(context->fVData, w / 2, data[2], rowBytes[2], w / 2, h / 2); |
| 88 | }; |
| 89 | surface->asyncRescaleAndReadPixelsYUV420(yuvCS, SkColorSpace::MakeSRGB(), srcRect, dstW, dstH, |
| 90 | rescaleGamma, quality, callback, &context); |
| 91 | while (!context.fCalled) { |
| 92 | // Only GPU should actually be asynchronous. |
| 93 | SkASSERT(surface->getCanvas()->getGrContext()); |
| 94 | surface->getCanvas()->getGrContext()->checkAsyncWorkCompletion(); |
| 95 | } |
Brian Salomon | cd5caa3 | 2019-06-11 17:02:19 -0400 | [diff] [blame] | 96 | if (!context.fSucceeded) { |
| 97 | return nullptr; |
| 98 | } |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 99 | auto* gr = surface->getCanvas()->getGrContext(); |
| 100 | GrBackendTexture backendTextures[3]; |
| 101 | GrBackendFormat format = gr->priv().caps()->getBackendFormatFromColorType(kAlpha_8_SkColorType); |
| 102 | backendTextures[0] = gr->priv().getGpu()->createBackendTexture( |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 103 | dstW, dstH, format, GrMipMapped::kNo, GrRenderable::kNo, yData.get(), 0, nullptr, |
| 104 | GrProtected::kNo); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 105 | backendTextures[1] = gr->priv().getGpu()->createBackendTexture( |
| 106 | dstW / 2, dstH / 2, format, GrMipMapped::kNo, GrRenderable::kNo, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 107 | uData.get(), 0, nullptr, GrProtected::kNo); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 108 | backendTextures[2] = gr->priv().getGpu()->createBackendTexture( |
| 109 | dstW / 2, dstH / 2, format, GrMipMapped::kNo, GrRenderable::kNo, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 110 | vData.get(), 0, nullptr, GrProtected::kNo); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 111 | auto config = gr->priv().caps()->getConfigFromBackendFormat(format, kAlpha_8_SkColorType); |
| 112 | SkColorChannel channel; |
| 113 | if (config == kAlpha_8_as_Red_GrPixelConfig) { |
| 114 | channel = SkColorChannel::kR; |
| 115 | } else { |
| 116 | SkASSERT(config == kAlpha_8_as_Alpha_GrPixelConfig); |
| 117 | channel = SkColorChannel::kA; |
| 118 | } |
| 119 | SkYUVAIndex indices[4]{{0, channel}, {1, channel}, {2, channel}, {-1, SkColorChannel::kR}}; |
| 120 | *cleanup = {[gr, backendTextures] { |
| 121 | GrFlushInfo flushInfo; |
| 122 | flushInfo.fFlags = kSyncCpu_GrFlushFlag; |
| 123 | gr->flush(flushInfo); |
| 124 | gr->deleteBackendTexture(backendTextures[0]); |
| 125 | gr->deleteBackendTexture(backendTextures[1]); |
| 126 | gr->deleteBackendTexture(backendTextures[2]); |
| 127 | }}; |
| 128 | |
| 129 | return SkImage::MakeFromYUVATextures(gr, yuvCS, backendTextures, indices, {dstW, dstH}, |
| 130 | kTopLeft_GrSurfaceOrigin, SkColorSpace::MakeSRGB()); |
| 131 | } |
| 132 | |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 133 | // Draws a grid of rescales. The columns are none, low, and high filter quality. The rows are |
| 134 | // rescale in src gamma and rescale in linear gamma. |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 135 | static skiagm::DrawResult do_rescale_grid(SkCanvas* canvas, SkSurface* surface, |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 136 | const SkIRect& srcRect, int newW, int newH, bool doYUV420, |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 137 | SkString* errorMsg, int pad = 0) { |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 138 | if (doYUV420) { |
Brian Salomon | cd5caa3 | 2019-06-11 17:02:19 -0400 | [diff] [blame] | 139 | if (!canvas->getGrContext() || !canvas->getGrContext()->priv().asDirectContext()) { |
| 140 | errorMsg->printf("YUV420 only supported on direct GPU for now."); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 141 | return skiagm::DrawResult::kSkip; |
| 142 | } |
| 143 | } |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 144 | if (canvas->imageInfo().colorType() == kUnknown_SkColorType) { |
| 145 | *errorMsg = "Not supported on recording/vector backends."; |
| 146 | return skiagm::DrawResult::kSkip; |
| 147 | } |
Brian Salomon | a34e0fc | 2019-05-17 19:56:59 +0000 | [diff] [blame] | 148 | const auto ii = canvas->imageInfo().makeWH(newW, newH); |
Brian Salomon | a34e0fc | 2019-05-17 19:56:59 +0000 | [diff] [blame] | 149 | |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 150 | SkYUVColorSpace yuvColorSpace = kRec601_SkYUVColorSpace; |
Brian Salomon | a34e0fc | 2019-05-17 19:56:59 +0000 | [diff] [blame] | 151 | canvas->save(); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 152 | for (auto gamma : {SkSurface::RescaleGamma::kSrc, SkSurface::RescaleGamma::kLinear}) { |
Brian Salomon | a34e0fc | 2019-05-17 19:56:59 +0000 | [diff] [blame] | 153 | canvas->save(); |
| 154 | for (auto quality : {kNone_SkFilterQuality, kLow_SkFilterQuality, kHigh_SkFilterQuality}) { |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 155 | SkScopeExit cleanup; |
| 156 | sk_sp<SkImage> result; |
| 157 | if (doYUV420) { |
| 158 | result = do_read_and_scale_yuv(surface, yuvColorSpace, srcRect, newW, newH, gamma, |
| 159 | quality, &cleanup); |
Brian Salomon | cd5caa3 | 2019-06-11 17:02:19 -0400 | [diff] [blame] | 160 | if (!result) { |
| 161 | errorMsg->printf("YUV420 async call failed. Allowed for now."); |
| 162 | return skiagm::DrawResult::kSkip; |
| 163 | } |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 164 | int nextCS = static_cast<int>(yuvColorSpace + 1) % (kLastEnum_SkYUVColorSpace + 1); |
| 165 | yuvColorSpace = static_cast<SkYUVColorSpace>(nextCS); |
| 166 | } else { |
| 167 | result = do_read_and_scale(surface, srcRect, ii, gamma, quality); |
Brian Salomon | cd5caa3 | 2019-06-11 17:02:19 -0400 | [diff] [blame] | 168 | if (!result) { |
| 169 | errorMsg->printf("async read call failed."); |
| 170 | return skiagm::DrawResult::kFail; |
| 171 | } |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 172 | } |
| 173 | canvas->drawImage(result, 0, 0); |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 174 | canvas->translate(newW + pad, 0); |
Brian Salomon | a34e0fc | 2019-05-17 19:56:59 +0000 | [diff] [blame] | 175 | } |
| 176 | canvas->restore(); |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 177 | canvas->translate(0, newH + pad); |
Brian Salomon | 451b01f | 2019-05-17 12:39:17 -0400 | [diff] [blame] | 178 | } |
Brian Salomon | a34e0fc | 2019-05-17 19:56:59 +0000 | [diff] [blame] | 179 | canvas->restore(); |
| 180 | return skiagm::DrawResult::kOk; |
Brian Salomon | 451b01f | 2019-05-17 12:39:17 -0400 | [diff] [blame] | 181 | } |
| 182 | |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 183 | static skiagm::DrawResult do_rescale_image_grid(SkCanvas* canvas, const char* imageFile, |
| 184 | const SkIRect& srcRect, int newW, int newH, |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 185 | bool doYUV420, SkString* errorMsg) { |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 186 | 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 | } |
| 195 | // Turn the image into a surface in order to call the read and rescale API |
| 196 | auto surfInfo = image->imageInfo().makeWH(image->width(), image->height()); |
| 197 | auto surface = canvas->makeSurface(surfInfo); |
| 198 | if (!surface && surfInfo.colorType() == kBGRA_8888_SkColorType) { |
| 199 | surfInfo = surfInfo.makeColorType(kRGBA_8888_SkColorType); |
| 200 | surface = canvas->makeSurface(surfInfo); |
| 201 | } |
| 202 | if (!surface) { |
| 203 | *errorMsg = "Could not create surface for image."; |
Brian Salomon | 9be911c | 2019-05-20 14:01:21 -0400 | [diff] [blame] | 204 | // When testing abandoned GrContext we expect surface creation to fail. |
| 205 | if (canvas->getGrContext() && canvas->getGrContext()->abandoned()) { |
| 206 | return skiagm::DrawResult::kSkip; |
| 207 | } |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 208 | return skiagm::DrawResult::kFail; |
| 209 | } |
| 210 | SkPaint paint; |
| 211 | paint.setBlendMode(SkBlendMode::kSrc); |
| 212 | surface->getCanvas()->drawImage(image, 0, 0, &paint); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 213 | return do_rescale_grid(canvas, surface.get(), srcRect, newW, newH, doYUV420, errorMsg); |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 214 | } |
| 215 | |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 216 | #define DEF_RESCALE_AND_READ_GM(IMAGE_FILE, TAG, SRC_RECT, W, H) \ |
| 217 | DEF_SIMPLE_GM_CAN_FAIL(async_rescale_and_read_##TAG, canvas, errorMsg, 3 * W, 2 * H) { \ |
| 218 | ToolUtils::draw_checkerboard(canvas, SK_ColorDKGRAY, SK_ColorLTGRAY, 25); \ |
| 219 | return do_rescale_image_grid(canvas, #IMAGE_FILE, SRC_RECT, W, H, false, errorMsg); \ |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 220 | } |
| 221 | |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 222 | #define DEF_RESCALE_AND_READ_YUV_GM(IMAGE_FILE, TAG, SRC_RECT, W, H) \ |
| 223 | DEF_SIMPLE_GM_CAN_FAIL(async_rescale_and_read_yuv420_##TAG, canvas, errorMsg, 3 * W, 2 * H) { \ |
| 224 | ToolUtils::draw_checkerboard(canvas, SK_ColorDKGRAY, SK_ColorLTGRAY, 25); \ |
| 225 | return do_rescale_image_grid(canvas, #IMAGE_FILE, SRC_RECT, W, H, true, errorMsg); \ |
| 226 | } |
| 227 | |
| 228 | DEF_RESCALE_AND_READ_YUV_GM(images/yellow_rose.webp, rose, SkIRect::MakeXYWH(50, 5, 200, 150), |
| 229 | 410, 376) |
| 230 | |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 231 | DEF_RESCALE_AND_READ_GM(images/yellow_rose.webp, rose, SkIRect::MakeXYWH(100, 20, 100, 100), |
| 232 | 410, 410) |
| 233 | |
| 234 | DEF_RESCALE_AND_READ_GM(images/dog.jpg, dog_down, SkIRect::MakeXYWH(0, 10, 180, 150), 45, 45) |
Brian Salomon | c7e9f78 | 2019-05-28 20:39:53 -0400 | [diff] [blame] | 235 | DEF_RESCALE_AND_READ_GM(images/dog.jpg, dog_up, SkIRect::MakeWH(180, 180), 800, 400) |
Brian Salomon | 201700f | 2019-05-17 12:05:44 -0400 | [diff] [blame] | 236 | |
| 237 | DEF_RESCALE_AND_READ_GM(images/text.png, text_down, SkIRect::MakeWH(637, 105), (int)(0.7 * 637), |
| 238 | (int)(0.7 * 105)) |
| 239 | DEF_RESCALE_AND_READ_GM(images/text.png, text_up, SkIRect::MakeWH(637, 105), (int)(1.2 * 637), |
| 240 | (int)(1.2 * 105)) |
| 241 | DEF_RESCALE_AND_READ_GM(images/text.png, text_up_large, SkIRect::MakeXYWH(300, 0, 300, 105), |
| 242 | (int)(2.4 * 300), (int)(2.4 * 105)) |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 243 | |
| 244 | DEF_SIMPLE_GM_CAN_FAIL(async_rescale_and_read_no_bleed, canvas, errorMsg, 60, 60) { |
| 245 | if (canvas->imageInfo().colorType() == kUnknown_SkColorType) { |
| 246 | *errorMsg = "Not supported on recording/vector backends."; |
| 247 | return skiagm::DrawResult::kSkip; |
| 248 | } |
| 249 | |
| 250 | static constexpr int kBorder = 5; |
| 251 | static constexpr int kInner = 5; |
| 252 | const auto srcRect = SkIRect::MakeXYWH(kBorder, kBorder, kInner, kInner); |
| 253 | auto surfaceII = |
| 254 | SkImageInfo::Make(kInner + 2 * kBorder, kInner + 2 * kBorder, kRGBA_8888_SkColorType, |
| 255 | kPremul_SkAlphaType, SkColorSpace::MakeSRGB()); |
| 256 | auto surface = canvas->makeSurface(surfaceII); |
Brian Salomon | af9b7b9 | 2019-05-20 12:19:37 -0400 | [diff] [blame] | 257 | if (!surface) { |
| 258 | *errorMsg = "Could not create surface for image."; |
Brian Salomon | 9be911c | 2019-05-20 14:01:21 -0400 | [diff] [blame] | 259 | // When testing abandoned GrContext we expect surface creation to fail. |
| 260 | if (canvas->getGrContext() && canvas->getGrContext()->abandoned()) { |
| 261 | return skiagm::DrawResult::kSkip; |
| 262 | } |
Brian Salomon | af9b7b9 | 2019-05-20 12:19:37 -0400 | [diff] [blame] | 263 | return skiagm::DrawResult::kFail; |
| 264 | } |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 265 | surface->getCanvas()->clear(SK_ColorRED); |
| 266 | surface->getCanvas()->save(); |
| 267 | surface->getCanvas()->clipRect(SkRect::Make(srcRect), SkClipOp::kIntersect, false); |
| 268 | surface->getCanvas()->clear(SK_ColorBLUE); |
| 269 | surface->getCanvas()->restore(); |
| 270 | static constexpr int kPad = 2; |
| 271 | canvas->translate(kPad, kPad); |
| 272 | skiagm::DrawResult result; |
| 273 | auto downW = static_cast<int>(kInner / 2); |
| 274 | auto downH = static_cast<int>(kInner / 2); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 275 | result = do_rescale_grid(canvas, surface.get(), srcRect, downW, downH, false, errorMsg, kPad); |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 276 | if (result != skiagm::DrawResult::kOk) { |
| 277 | return result; |
| 278 | } |
| 279 | canvas->translate(0, 2 * downH); |
| 280 | auto upW = static_cast<int>(kInner * 3.5); |
| 281 | auto upH = static_cast<int>(kInner * 4.6); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 282 | result = do_rescale_grid(canvas, surface.get(), srcRect, upW, upH, false, errorMsg, kPad); |
Brian Salomon | 286b557 | 2019-05-20 10:25:50 -0400 | [diff] [blame] | 283 | if (result != skiagm::DrawResult::kOk) { |
| 284 | return result; |
| 285 | } |
| 286 | return skiagm::DrawResult::kOk; |
| 287 | } |