2020-12-02 18:37:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 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"
|
2022-04-05 16:56:01 +00:00
|
|
|
|
|
|
|
#include "include/core/SkColorSpace.h"
|
2020-12-02 18:37:16 +00:00
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/private/SkColorData.h"
|
2021-07-21 19:39:51 +00:00
|
|
|
#include "src/core/SkCanvasPriv.h"
|
2021-08-04 17:27:43 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
|
|
|
#include "src/gpu/SurfaceFillContext.h"
|
2022-02-15 21:30:59 +00:00
|
|
|
#include "src/gpu/Swizzle.h"
|
2020-12-02 18:37:16 +00:00
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
namespace skiagm {
|
|
|
|
|
2020-12-02 18:37:16 +00:00
|
|
|
// Size of each clear
|
|
|
|
static constexpr int kSize = 64;
|
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
DEF_SIMPLE_GPU_GM_CAN_FAIL(clear_swizzle, rContext, canvas, errorMsg, 6*kSize, 2*kSize) {
|
|
|
|
if (rContext->abandoned()) {
|
|
|
|
*errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly;
|
|
|
|
return DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
|
2021-07-26 17:23:10 +00:00
|
|
|
auto sfc = SkCanvasPriv::TopDeviceSurfaceFillContext(canvas);
|
|
|
|
if (!sfc) {
|
2021-07-21 19:39:51 +00:00
|
|
|
*errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly;
|
|
|
|
return DrawResult::kSkip;
|
2020-12-02 18:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto make_offscreen = [&](const SkISize dimensions) {
|
2022-02-15 21:30:59 +00:00
|
|
|
skgpu::Swizzle readSwizzle = skgpu::Swizzle::Concat(sfc->readSwizzle(),
|
|
|
|
skgpu::Swizzle{"bgra"});
|
|
|
|
skgpu::Swizzle writeSwizzle = skgpu::Swizzle::Concat(sfc->readSwizzle(),
|
|
|
|
skgpu::Swizzle{"bgra"});
|
2021-08-02 15:14:38 +00:00
|
|
|
return rContext->priv().makeSFC(kPremul_SkAlphaType,
|
|
|
|
sfc->colorInfo().refColorSpace(),
|
|
|
|
dimensions,
|
|
|
|
SkBackingFit::kExact,
|
|
|
|
sfc->asSurfaceProxy()->backendFormat(),
|
|
|
|
/* sample count*/ 1,
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
sfc->asSurfaceProxy()->isProtected(),
|
|
|
|
readSwizzle,
|
|
|
|
writeSwizzle,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
SkBudgeted::kYes);
|
2020-12-02 18:37:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct {
|
|
|
|
SkIRect rect;
|
|
|
|
SkPMColor4f color;
|
|
|
|
} clears[] {
|
|
|
|
{{ 0, 0, kSize, kSize}, {1, 0, 0, 1}},
|
|
|
|
{{kSize, 0, 2*kSize, kSize}, {0, 1, 0, 1}},
|
|
|
|
{{ 0, kSize, kSize, 2*kSize}, {0, 0, 1, 1}},
|
|
|
|
{{kSize, kSize, 2*kSize, 2*kSize}, {1, 0, 1, 1}},
|
|
|
|
};
|
|
|
|
|
|
|
|
// onscreen for reference
|
|
|
|
for (const auto& c : clears) {
|
2021-07-26 17:23:10 +00:00
|
|
|
sfc->clear(c.rect, c.color);
|
2020-12-02 18:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// partial clear offscreen
|
|
|
|
auto offscreen = make_offscreen({2*kSize, 2*kSize});
|
|
|
|
for (const auto& c : clears) {
|
|
|
|
offscreen->clear(c.rect, c.color);
|
|
|
|
}
|
2021-07-26 17:23:10 +00:00
|
|
|
sfc->blitTexture(offscreen->readSurfaceView(),
|
2021-07-21 19:39:51 +00:00
|
|
|
SkIRect::MakeSize({2*kSize, 2*kSize}),
|
|
|
|
SkIPoint{2*kSize, 0});
|
2020-12-02 18:37:16 +00:00
|
|
|
|
|
|
|
// full offscreen clears
|
|
|
|
for (const auto& c : clears) {
|
|
|
|
offscreen = make_offscreen(c.rect.size());
|
|
|
|
offscreen->clear(SkIRect::MakeSize(c.rect.size()), c.color);
|
2021-07-26 17:23:10 +00:00
|
|
|
sfc->blitTexture(offscreen->readSurfaceView(),
|
2021-07-21 19:39:51 +00:00
|
|
|
SkIRect::MakeSize(offscreen->dimensions()),
|
|
|
|
c.rect.topLeft() + SkIPoint{4*kSize, 0});
|
2020-12-02 18:37:16 +00:00
|
|
|
}
|
2021-07-21 19:39:51 +00:00
|
|
|
|
|
|
|
return DrawResult::kOk;
|
2020-12-02 18:37:16 +00:00
|
|
|
}
|
2021-07-21 19:39:51 +00:00
|
|
|
|
|
|
|
} // namespace skiagm
|