skia2/gm/clear_swizzle.cpp
Kevin Lubick 8499e372ce [includes] Remove more includes of SkColorSpace
While I was fixing up Chrome's uses, I found some failures
there that I did not see in Skia, and tracked them down
to a few other places where we include SkColorSpace
and it is not strictly necessary

 - SkCustomMesh.h
 - GrColorInfo.h
 - GrColorSpaceXform.h
 - SkColorSpaceXformSteps.h

For these files (and their .cpp files), I added enforcement
of include-what-you-use, and then fixed the myriad of places
which were depending on these transitive includes.

One change to help Chrome is the manual overloads of
SkImage::MakeFromAdoptedTexture instead of using default
parameters. This makes it so callers of that function
do not need to include SkColorSpace if they were going
to pass nullptr for it anyway.

Bug: skia:13052
Change-Id: I16bf8ed5e258225d887f562f2c189623b1ca9c23
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/527056
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
2022-04-06 21:58:24 +00:00

92 lines
3.2 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/SkColorSpace.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/private/SkColorData.h"
#include "src/core/SkCanvasPriv.h"
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/SurfaceFillContext.h"
#include "src/gpu/Swizzle.h"
namespace skiagm {
// Size of each clear
static constexpr int kSize = 64;
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;
}
auto sfc = SkCanvasPriv::TopDeviceSurfaceFillContext(canvas);
if (!sfc) {
*errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly;
return DrawResult::kSkip;
}
auto make_offscreen = [&](const SkISize dimensions) {
skgpu::Swizzle readSwizzle = skgpu::Swizzle::Concat(sfc->readSwizzle(),
skgpu::Swizzle{"bgra"});
skgpu::Swizzle writeSwizzle = skgpu::Swizzle::Concat(sfc->readSwizzle(),
skgpu::Swizzle{"bgra"});
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);
};
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) {
sfc->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);
}
sfc->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);
sfc->blitTexture(offscreen->readSurfaceView(),
SkIRect::MakeSize(offscreen->dimensions()),
c.rect.topLeft() + SkIPoint{4*kSize, 0});
}
return DrawResult::kOk;
}
} // namespace skiagm