2019-05-17 16:05:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
2019-06-11 15:38:16 +00:00
|
|
|
#include "include/core/SkYUVAIndex.h"
|
2019-05-17 16:05:44 +00:00
|
|
|
#include "include/gpu/GrContext.h"
|
2020-07-01 16:55:01 +00:00
|
|
|
#include "include/gpu/GrRecordingContext.h"
|
2019-05-17 16:05:44 +00:00
|
|
|
#include "src/core/SkAutoPixmapStorage.h"
|
|
|
|
#include "src/core/SkConvertPixels.h"
|
2019-06-11 15:38:16 +00:00
|
|
|
#include "src/core/SkScopeExit.h"
|
2019-05-17 16:05:44 +00:00
|
|
|
#include "tools/Resources.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
|
|
|
|
2019-10-03 17:26:54 +00:00
|
|
|
namespace {
|
|
|
|
struct AsyncContext {
|
|
|
|
bool fCalled = false;
|
2020-06-26 17:32:09 +00:00
|
|
|
std::unique_ptr<const SkImage::AsyncReadResult> fResult;
|
2019-10-03 17:26:54 +00:00
|
|
|
};
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
// Making this a lambda in the test functions caused:
|
|
|
|
// "error: cannot compile this forwarded non-trivially copyable parameter yet"
|
|
|
|
// on x86/Win/Clang bot, referring to 'result'.
|
2020-06-26 17:32:09 +00:00
|
|
|
static void async_callback(void* c, std::unique_ptr<const SkImage::AsyncReadResult> result) {
|
2019-10-03 17:26:54 +00:00
|
|
|
auto context = static_cast<AsyncContext*>(c);
|
|
|
|
context->fResult = std::move(result);
|
|
|
|
context->fCalled = true;
|
|
|
|
};
|
|
|
|
|
2019-05-17 16:05:44 +00:00
|
|
|
// Draws the image to a surface, does a asyncRescaleAndReadPixels of the image, and then sticks
|
|
|
|
// the result in a raster image.
|
2020-06-26 17:32:09 +00:00
|
|
|
template <typename Src>
|
|
|
|
static sk_sp<SkImage> do_read_and_scale(Src* src,
|
|
|
|
GrContext* context,
|
|
|
|
const SkIRect& srcRect,
|
|
|
|
const SkImageInfo& ii,
|
|
|
|
SkImage::RescaleGamma rescaleGamma,
|
2019-05-20 14:25:50 +00:00
|
|
|
SkFilterQuality quality) {
|
2020-06-26 17:32:09 +00:00
|
|
|
auto* asyncContext = new AsyncContext();
|
|
|
|
src->asyncRescaleAndReadPixels(ii, srcRect, rescaleGamma, quality, async_callback,
|
|
|
|
asyncContext);
|
|
|
|
if (context) {
|
|
|
|
context->submit();
|
2020-06-02 15:47:26 +00:00
|
|
|
}
|
2020-06-26 17:32:09 +00:00
|
|
|
while (!asyncContext->fCalled) {
|
2019-05-17 16:05:44 +00:00
|
|
|
// Only GPU should actually be asynchronous.
|
2020-06-26 17:32:09 +00:00
|
|
|
SkASSERT(context);
|
|
|
|
context->checkAsyncWorkCompletion();
|
2019-05-17 16:05:44 +00:00
|
|
|
}
|
2020-06-26 17:32:09 +00:00
|
|
|
if (!asyncContext->fResult) {
|
2019-10-03 17:26:54 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2020-06-26 17:32:09 +00:00
|
|
|
SkPixmap pixmap(ii, asyncContext->fResult->data(0), asyncContext->fResult->rowBytes(0));
|
2019-10-03 17:26:54 +00:00
|
|
|
auto releasePixels = [](const void*, void* c) { delete static_cast<AsyncContext*>(c); };
|
2020-06-26 17:32:09 +00:00
|
|
|
return SkImage::MakeFromRaster(pixmap, releasePixels, asyncContext);
|
2019-05-17 16:05:44 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
template <typename Src>
|
|
|
|
static sk_sp<SkImage> do_read_and_scale_yuv(Src* src,
|
|
|
|
GrContext* context,
|
|
|
|
SkYUVColorSpace yuvCS,
|
|
|
|
const SkIRect& srcRect,
|
|
|
|
SkISize size,
|
|
|
|
SkImage::RescaleGamma rescaleGamma,
|
|
|
|
SkFilterQuality quality,
|
|
|
|
SkScopeExit* cleanup) {
|
2019-10-03 17:26:54 +00:00
|
|
|
SkASSERT(!(size.width() & 0b1) && !(size.height() & 0b1));
|
2019-08-14 16:33:29 +00:00
|
|
|
|
2019-10-03 17:26:54 +00:00
|
|
|
SkISize uvSize = {size.width()/2, size.height()/2};
|
|
|
|
SkImageInfo yII = SkImageInfo::Make(size, kGray_8_SkColorType, kPremul_SkAlphaType);
|
|
|
|
SkImageInfo uvII = SkImageInfo::Make(uvSize, kGray_8_SkColorType, kPremul_SkAlphaType);
|
2019-08-14 16:33:29 +00:00
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
AsyncContext asyncContext;
|
|
|
|
src->asyncRescaleAndReadPixelsYUV420(yuvCS, SkColorSpace::MakeSRGB(), srcRect, size,
|
|
|
|
rescaleGamma, quality, async_callback, &asyncContext);
|
|
|
|
if (context) {
|
|
|
|
context->submit();
|
2020-06-02 15:47:26 +00:00
|
|
|
}
|
2020-06-26 17:32:09 +00:00
|
|
|
while (!asyncContext.fCalled) {
|
2019-06-11 15:38:16 +00:00
|
|
|
// Only GPU should actually be asynchronous.
|
2020-06-26 17:32:09 +00:00
|
|
|
SkASSERT(context);
|
|
|
|
context->checkAsyncWorkCompletion();
|
2019-06-11 15:38:16 +00:00
|
|
|
}
|
2020-06-26 17:32:09 +00:00
|
|
|
if (!asyncContext.fResult) {
|
2019-06-11 21:02:19 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2019-06-11 15:38:16 +00:00
|
|
|
GrBackendTexture backendTextures[3];
|
2019-07-30 16:49:10 +00:00
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
SkPixmap yPM(yII, asyncContext.fResult->data(0), asyncContext.fResult->rowBytes(0));
|
|
|
|
SkPixmap uPM(uvII, asyncContext.fResult->data(1), asyncContext.fResult->rowBytes(1));
|
|
|
|
SkPixmap vPM(uvII, asyncContext.fResult->data(2), asyncContext.fResult->rowBytes(2));
|
2019-10-03 17:26:54 +00:00
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
backendTextures[0] = context->createBackendTexture(yPM, GrRenderable::kNo, GrProtected::kNo);
|
|
|
|
backendTextures[1] = context->createBackendTexture(uPM, GrRenderable::kNo, GrProtected::kNo);
|
|
|
|
backendTextures[2] = context->createBackendTexture(vPM, GrRenderable::kNo, GrProtected::kNo);
|
2019-10-03 17:26:54 +00:00
|
|
|
|
2019-08-14 16:33:29 +00:00
|
|
|
SkYUVAIndex indices[4] = {
|
|
|
|
{ 0, SkColorChannel::kR},
|
|
|
|
{ 1, SkColorChannel::kR},
|
|
|
|
{ 2, SkColorChannel::kR},
|
|
|
|
{-1, SkColorChannel::kR}
|
|
|
|
};
|
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
*cleanup = {[context, backendTextures] {
|
2020-06-30 17:42:46 +00:00
|
|
|
context->flush();
|
2020-06-26 17:32:09 +00:00
|
|
|
context->submit(true);
|
|
|
|
context->deleteBackendTexture(backendTextures[0]);
|
|
|
|
context->deleteBackendTexture(backendTextures[1]);
|
|
|
|
context->deleteBackendTexture(backendTextures[2]);
|
2019-06-11 15:38:16 +00:00
|
|
|
}};
|
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
return SkImage::MakeFromYUVATextures(context, yuvCS, backendTextures, indices, size,
|
2019-06-11 15:38:16 +00:00
|
|
|
kTopLeft_GrSurfaceOrigin, SkColorSpace::MakeSRGB());
|
|
|
|
}
|
|
|
|
|
2019-05-17 16:05:44 +00:00
|
|
|
// Draws a grid of rescales. The columns are none, low, and high filter quality. The rows are
|
|
|
|
// rescale in src gamma and rescale in linear gamma.
|
2020-06-26 17:32:09 +00:00
|
|
|
template <typename Src>
|
|
|
|
static skiagm::DrawResult do_rescale_grid(SkCanvas* canvas,
|
|
|
|
Src* src,
|
|
|
|
GrContext* context,
|
|
|
|
const SkIRect& srcRect,
|
|
|
|
SkISize newSize,
|
|
|
|
bool doYUV420,
|
|
|
|
SkString* errorMsg,
|
|
|
|
int pad = 0) {
|
2019-06-11 15:38:16 +00:00
|
|
|
if (doYUV420) {
|
2020-07-01 15:11:18 +00:00
|
|
|
if (!canvas->recordingContext() || !canvas->recordingContext()->asDirectContext()) {
|
2019-06-11 21:02:19 +00:00
|
|
|
errorMsg->printf("YUV420 only supported on direct GPU for now.");
|
2019-06-11 15:38:16 +00:00
|
|
|
return skiagm::DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
}
|
2019-05-17 16:05:44 +00:00
|
|
|
if (canvas->imageInfo().colorType() == kUnknown_SkColorType) {
|
|
|
|
*errorMsg = "Not supported on recording/vector backends.";
|
|
|
|
return skiagm::DrawResult::kSkip;
|
|
|
|
}
|
2019-10-03 17:26:54 +00:00
|
|
|
const auto ii = canvas->imageInfo().makeDimensions(newSize);
|
2019-05-17 16:05:44 +00:00
|
|
|
|
2019-06-11 15:38:16 +00:00
|
|
|
SkYUVColorSpace yuvColorSpace = kRec601_SkYUVColorSpace;
|
2019-05-17 16:05:44 +00:00
|
|
|
canvas->save();
|
2020-06-26 17:32:09 +00:00
|
|
|
for (auto gamma : {SkImage::RescaleGamma::kSrc, SkImage::RescaleGamma::kLinear}) {
|
2019-05-17 16:05:44 +00:00
|
|
|
canvas->save();
|
|
|
|
for (auto quality : {kNone_SkFilterQuality, kLow_SkFilterQuality, kHigh_SkFilterQuality}) {
|
2019-06-11 15:38:16 +00:00
|
|
|
SkScopeExit cleanup;
|
|
|
|
sk_sp<SkImage> result;
|
|
|
|
if (doYUV420) {
|
2020-06-26 17:32:09 +00:00
|
|
|
result = do_read_and_scale_yuv(src, context, yuvColorSpace, srcRect, newSize, gamma,
|
2019-06-11 15:38:16 +00:00
|
|
|
quality, &cleanup);
|
2019-06-11 21:02:19 +00:00
|
|
|
if (!result) {
|
|
|
|
errorMsg->printf("YUV420 async call failed. Allowed for now.");
|
|
|
|
return skiagm::DrawResult::kSkip;
|
|
|
|
}
|
2019-06-11 15:38:16 +00:00
|
|
|
int nextCS = static_cast<int>(yuvColorSpace + 1) % (kLastEnum_SkYUVColorSpace + 1);
|
|
|
|
yuvColorSpace = static_cast<SkYUVColorSpace>(nextCS);
|
|
|
|
} else {
|
2020-06-26 17:32:09 +00:00
|
|
|
result = do_read_and_scale(src, context, srcRect, ii, gamma, quality);
|
2019-06-11 21:02:19 +00:00
|
|
|
if (!result) {
|
|
|
|
errorMsg->printf("async read call failed.");
|
|
|
|
return skiagm::DrawResult::kFail;
|
|
|
|
}
|
2019-06-11 15:38:16 +00:00
|
|
|
}
|
|
|
|
canvas->drawImage(result, 0, 0);
|
2019-10-03 17:26:54 +00:00
|
|
|
canvas->translate(newSize.width() + pad, 0);
|
2019-05-17 16:05:44 +00:00
|
|
|
}
|
|
|
|
canvas->restore();
|
2019-10-03 17:26:54 +00:00
|
|
|
canvas->translate(0, newSize.height() + pad);
|
2019-05-17 16:05:44 +00:00
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
return skiagm::DrawResult::kOk;
|
|
|
|
}
|
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
static skiagm::DrawResult do_rescale_image_grid(SkCanvas* canvas,
|
|
|
|
const char* imageFile,
|
|
|
|
const SkIRect& srcRect,
|
|
|
|
SkISize newSize,
|
|
|
|
bool doSurface,
|
|
|
|
bool doYUV420,
|
|
|
|
SkString* errorMsg) {
|
2019-05-20 14:25:50 +00:00
|
|
|
auto image = GetResourceAsImage(imageFile);
|
|
|
|
if (!image) {
|
|
|
|
errorMsg->printf("Could not load image file %s.", imageFile);
|
|
|
|
return skiagm::DrawResult::kFail;
|
|
|
|
}
|
|
|
|
if (canvas->imageInfo().colorType() == kUnknown_SkColorType) {
|
|
|
|
*errorMsg = "Not supported on recording/vector backends.";
|
|
|
|
return skiagm::DrawResult::kSkip;
|
|
|
|
}
|
2020-06-26 17:32:09 +00:00
|
|
|
if (doSurface) {
|
|
|
|
// Turn the image into a surface in order to call the read and rescale API
|
|
|
|
auto surfInfo = image->imageInfo().makeDimensions(image->dimensions());
|
|
|
|
auto surface = canvas->makeSurface(surfInfo);
|
|
|
|
if (!surface && surfInfo.colorType() == kBGRA_8888_SkColorType) {
|
|
|
|
surfInfo = surfInfo.makeColorType(kRGBA_8888_SkColorType);
|
|
|
|
surface = canvas->makeSurface(surfInfo);
|
|
|
|
}
|
|
|
|
if (!surface) {
|
|
|
|
*errorMsg = "Could not create surface for image.";
|
|
|
|
// When testing abandoned GrContext we expect surface creation to fail.
|
2020-06-30 19:30:12 +00:00
|
|
|
if (canvas->recordingContext() && canvas->recordingContext()->abandoned()) {
|
2020-06-26 17:32:09 +00:00
|
|
|
return skiagm::DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
return skiagm::DrawResult::kFail;
|
|
|
|
}
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setBlendMode(SkBlendMode::kSrc);
|
|
|
|
surface->getCanvas()->drawImage(image, 0, 0, &paint);
|
|
|
|
return do_rescale_grid(canvas, surface.get(), canvas->getGrContext(), srcRect, newSize,
|
|
|
|
doYUV420, errorMsg);
|
|
|
|
} else if (auto ctx = canvas->getGrContext()) {
|
|
|
|
image = image->makeTextureImage(ctx);
|
|
|
|
if (!image) {
|
|
|
|
*errorMsg = "Could not create image.";
|
|
|
|
// When testing abandoned GrContext we expect surface creation to fail.
|
2020-06-30 19:30:12 +00:00
|
|
|
if (canvas->recordingContext() && canvas->recordingContext()->abandoned()) {
|
2020-06-26 17:32:09 +00:00
|
|
|
return skiagm::DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
return skiagm::DrawResult::kFail;
|
2020-06-26 13:09:15 +00:00
|
|
|
}
|
2019-05-20 14:25:50 +00:00
|
|
|
}
|
2020-06-26 17:32:09 +00:00
|
|
|
return do_rescale_grid(canvas, image.get(), canvas->getGrContext(), srcRect, newSize, doYUV420,
|
|
|
|
errorMsg);
|
2019-05-20 14:25:50 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
#define DEF_RESCALE_AND_READ_SURF_GM(IMAGE_FILE, TAG, SRC_RECT, W, H) \
|
|
|
|
DEF_SIMPLE_GM_CAN_FAIL(async_rescale_and_read_##TAG, canvas, errorMsg, 3 * W, 2 * H) { \
|
|
|
|
ToolUtils::draw_checkerboard(canvas, SK_ColorDKGRAY, SK_ColorLTGRAY, 25); \
|
|
|
|
return do_rescale_image_grid(canvas, #IMAGE_FILE, SRC_RECT, {W, H}, true, false, \
|
|
|
|
errorMsg); \
|
2019-05-17 16:05:44 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
#define DEF_RESCALE_AND_READ_YUV_SURF_GM(IMAGE_FILE, TAG, SRC_RECT, W, H) \
|
|
|
|
DEF_SIMPLE_GM_CAN_FAIL(async_rescale_and_read_yuv420_##TAG, canvas, errorMsg, 3 * W, 2 * H) { \
|
|
|
|
ToolUtils::draw_checkerboard(canvas, SK_ColorDKGRAY, SK_ColorLTGRAY, 25); \
|
|
|
|
return do_rescale_image_grid(canvas, #IMAGE_FILE, SRC_RECT, {W, H}, true, true, errorMsg); \
|
2019-06-11 15:38:16 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
#define DEF_RESCALE_AND_READ_IMG_GM(IMAGE_FILE, TAG, SRC_RECT, W, H) \
|
|
|
|
DEF_SIMPLE_GM_CAN_FAIL(async_rescale_and_read_##TAG, canvas, errorMsg, 3 * W, 2 * H) { \
|
|
|
|
ToolUtils::draw_checkerboard(canvas, SK_ColorDKGRAY, SK_ColorLTGRAY, 25); \
|
|
|
|
return do_rescale_image_grid(canvas, #IMAGE_FILE, SRC_RECT, {W, H}, false, false, \
|
|
|
|
errorMsg); \
|
|
|
|
}
|
2019-06-11 15:38:16 +00:00
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
#define DEF_RESCALE_AND_READ_YUV_IMG_GM(IMAGE_FILE, TAG, SRC_RECT, W, H) \
|
|
|
|
DEF_SIMPLE_GM_CAN_FAIL(async_rescale_and_read_yuv420_##TAG, canvas, errorMsg, 3 * W, 2 * H) { \
|
|
|
|
ToolUtils::draw_checkerboard(canvas, SK_ColorDKGRAY, SK_ColorLTGRAY, 25); \
|
|
|
|
return do_rescale_image_grid(canvas, #IMAGE_FILE, SRC_RECT, {W, H}, true, true, errorMsg); \
|
|
|
|
}
|
2019-05-17 16:05:44 +00:00
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
DEF_RESCALE_AND_READ_YUV_SURF_GM(
|
|
|
|
images/yellow_rose.webp, rose, SkIRect::MakeXYWH(50, 5, 200, 150), 410, 376)
|
2019-05-17 16:05:44 +00:00
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
DEF_RESCALE_AND_READ_YUV_IMG_GM(
|
|
|
|
images/yellow_rose.webp, rose_down, SkIRect::MakeXYWH(50, 5, 200, 150), 106, 60)
|
|
|
|
|
|
|
|
DEF_RESCALE_AND_READ_SURF_GM(
|
|
|
|
images/yellow_rose.webp, rose, SkIRect::MakeXYWH(100, 20, 100, 100), 410, 410)
|
|
|
|
|
|
|
|
DEF_RESCALE_AND_READ_SURF_GM(images/dog.jpg, dog_down, SkIRect::MakeXYWH(0, 10, 180, 150), 45, 45)
|
|
|
|
DEF_RESCALE_AND_READ_IMG_GM(images/dog.jpg, dog_up, SkIRect::MakeWH(180, 180), 800, 400)
|
|
|
|
|
|
|
|
DEF_RESCALE_AND_READ_IMG_GM(
|
|
|
|
images/text.png, text_down, SkIRect::MakeWH(637, 105), (int)(0.7 * 637), (int)(0.7 * 105))
|
|
|
|
DEF_RESCALE_AND_READ_SURF_GM(
|
|
|
|
images/text.png, text_up, SkIRect::MakeWH(637, 105), (int)(1.2 * 637), (int)(1.2 * 105))
|
|
|
|
DEF_RESCALE_AND_READ_IMG_GM(images/text.png,
|
|
|
|
text_up_large,
|
|
|
|
SkIRect::MakeXYWH(300, 0, 300, 105),
|
|
|
|
(int)(2.4 * 300),
|
|
|
|
(int)(2.4 * 105))
|
2019-05-20 14:25:50 +00:00
|
|
|
|
2020-01-27 20:41:40 +00:00
|
|
|
// Exercises non-scaling YUV420. Reads from the original canvas's surface in order to
|
|
|
|
// exercise case where source surface is not a texture (in glbert config).
|
|
|
|
DEF_SIMPLE_GM_CAN_FAIL(async_yuv_no_scale, canvas, errorMsg, 400, 300) {
|
|
|
|
auto surface = canvas->getSurface();
|
|
|
|
if (!surface) {
|
|
|
|
*errorMsg = "Not supported on recording/vector backends.";
|
|
|
|
return skiagm::DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto image = GetResourceAsImage("images/yellow_rose.webp");
|
|
|
|
if (!image) {
|
|
|
|
return skiagm::DrawResult::kFail;
|
|
|
|
}
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->drawImage(image.get(), 0, 0);
|
|
|
|
|
|
|
|
SkScopeExit scopeExit;
|
|
|
|
auto yuvImage = do_read_and_scale_yuv(
|
2020-06-26 17:32:09 +00:00
|
|
|
surface, surface->getContext(), kRec601_SkYUVColorSpace, SkIRect::MakeWH(400, 300),
|
|
|
|
{400, 300}, SkImage::RescaleGamma::kSrc, kNone_SkFilterQuality, &scopeExit);
|
2020-01-27 20:41:40 +00:00
|
|
|
|
|
|
|
canvas->clear(SK_ColorWHITE);
|
|
|
|
canvas->drawImage(yuvImage.get(), 0, 0);
|
|
|
|
|
|
|
|
return skiagm::DrawResult::kOk;
|
|
|
|
}
|
|
|
|
|
2019-05-20 14:25:50 +00:00
|
|
|
DEF_SIMPLE_GM_CAN_FAIL(async_rescale_and_read_no_bleed, canvas, errorMsg, 60, 60) {
|
|
|
|
if (canvas->imageInfo().colorType() == kUnknown_SkColorType) {
|
|
|
|
*errorMsg = "Not supported on recording/vector backends.";
|
|
|
|
return skiagm::DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr int kBorder = 5;
|
|
|
|
static constexpr int kInner = 5;
|
|
|
|
const auto srcRect = SkIRect::MakeXYWH(kBorder, kBorder, kInner, kInner);
|
|
|
|
auto surfaceII =
|
|
|
|
SkImageInfo::Make(kInner + 2 * kBorder, kInner + 2 * kBorder, kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
|
|
|
|
auto surface = canvas->makeSurface(surfaceII);
|
2019-05-20 16:19:37 +00:00
|
|
|
if (!surface) {
|
|
|
|
*errorMsg = "Could not create surface for image.";
|
2019-05-20 18:01:21 +00:00
|
|
|
// When testing abandoned GrContext we expect surface creation to fail.
|
|
|
|
if (canvas->getGrContext() && canvas->getGrContext()->abandoned()) {
|
|
|
|
return skiagm::DrawResult::kSkip;
|
|
|
|
}
|
2019-05-20 16:19:37 +00:00
|
|
|
return skiagm::DrawResult::kFail;
|
|
|
|
}
|
2019-05-20 14:25:50 +00:00
|
|
|
surface->getCanvas()->clear(SK_ColorRED);
|
|
|
|
surface->getCanvas()->save();
|
|
|
|
surface->getCanvas()->clipRect(SkRect::Make(srcRect), SkClipOp::kIntersect, false);
|
|
|
|
surface->getCanvas()->clear(SK_ColorBLUE);
|
|
|
|
surface->getCanvas()->restore();
|
|
|
|
static constexpr int kPad = 2;
|
|
|
|
canvas->translate(kPad, kPad);
|
|
|
|
skiagm::DrawResult result;
|
2019-10-03 17:26:54 +00:00
|
|
|
SkISize downSize = {static_cast<int>(kInner/2), static_cast<int>(kInner / 2)};
|
2020-06-26 17:32:09 +00:00
|
|
|
GrContext* context = canvas->getGrContext();
|
|
|
|
result = do_rescale_grid(canvas, surface.get(), context, srcRect, downSize, false, errorMsg,
|
|
|
|
kPad);
|
|
|
|
|
2019-05-20 14:25:50 +00:00
|
|
|
if (result != skiagm::DrawResult::kOk) {
|
|
|
|
return result;
|
|
|
|
}
|
2020-01-27 18:16:22 +00:00
|
|
|
canvas->translate(0, 4 * downSize.height());
|
2019-10-03 17:26:54 +00:00
|
|
|
SkISize upSize = {static_cast<int>(kInner * 3.5), static_cast<int>(kInner * 4.6)};
|
2020-06-26 17:32:09 +00:00
|
|
|
result =
|
|
|
|
do_rescale_grid(canvas, surface.get(), context, srcRect, upSize, false, errorMsg, kPad);
|
2019-05-20 14:25:50 +00:00
|
|
|
if (result != skiagm::DrawResult::kOk) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return skiagm::DrawResult::kOk;
|
|
|
|
}
|