skia2/gm/clear_swizzle.cpp
John Stiles 0fbc6a3bcb Fix up names from RenderTargetContext to SurfaceDrawContext.
RenderTargetContext was renamed several months ago; this CL just fixes
up a few related names which hadn't yet updated yet.

Change-Id: I59a6ea92fc5d309a9b45a83e3aca6e49cb8d662e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/415745
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
2021-06-04 19:37:14 +00:00

74 lines
2.7 KiB
C++

/*
* 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"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/private/SkColorData.h"
#include "src/gpu/GrSurfaceDrawContext.h"
#include "src/gpu/GrSwizzle.h"
// Size of each clear
static constexpr int kSize = 64;
DEF_SIMPLE_GPU_GM(clear_swizzle, ctx, sdCtx, canvas, 6*kSize, 2*kSize) {
if (ctx->abandoned()) {
return;
}
auto make_offscreen = [&](const SkISize dimensions) {
GrSwizzle readSwizzle = GrSwizzle::Concat(sdCtx->readSwizzle(), GrSwizzle{"bgra"});
GrSwizzle writeSwizzle = GrSwizzle::Concat(sdCtx->readSwizzle(), GrSwizzle{"bgra"});
return GrSurfaceFillContext::Make(ctx,
kPremul_SkAlphaType,
sdCtx->colorInfo().refColorSpace(),
dimensions,
SkBackingFit::kExact,
sdCtx->asSurfaceProxy()->backendFormat(),
/* sample count*/ 1,
GrMipmapped::kNo,
sdCtx->asSurfaceProxy()->isProtected(),
readSwizzle,
writeSwizzle,
kTopLeft_GrSurfaceOrigin,
SkBudgeted::kYes);
};
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) {
sdCtx->clear(c.rect, c.color);
}
// partial clear offscreen
auto offscreen = make_offscreen({2*kSize, 2*kSize});
for (const auto& c : clears) {
offscreen->clear(c.rect, c.color);
}
sdCtx->blitTexture(offscreen->readSurfaceView(),
SkIRect::MakeSize({2*kSize, 2*kSize}),
SkIPoint{2*kSize, 0});
// full offscreen clears
for (const auto& c : clears) {
offscreen = make_offscreen(c.rect.size());
offscreen->clear(SkIRect::MakeSize(c.rect.size()), c.color);
sdCtx->blitTexture(offscreen->readSurfaceView(),
SkIRect::MakeSize(offscreen->dimensions()),
c.rect.topLeft() + SkIPoint{4*kSize, 0});
}
}