GPU clear values: just 4 floats

We previously represented these as SkPMColor4f. However, upcoming
changes will add limited support for clearing/drawing to unpremul
dst. Just store the clear values as four floats without assigned
interpretation.

Also, noticed a bug by code inspection: we weren't accounting for
write view swizzle in GrRTC. Fixed and added gm to test.

Bug: skia:11019
Change-Id: I1bce1f6c97a156c0377ebad1b166eb641362b67a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/340098
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2020-12-02 13:37:16 -05:00 committed by Skia Commit-Bot
parent 4be95c541c
commit 07bc9a27f5
28 changed files with 228 additions and 92 deletions

73
gm/clear_swizzle.cpp Normal file
View File

@ -0,0 +1,73 @@
/*
* 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/GrRenderTargetContext.h"
#include "src/gpu/GrSwizzle.h"
// Size of each clear
static constexpr int kSize = 64;
DEF_SIMPLE_GPU_GM(clear_swizzle, ctx, rtCtx, canvas, 6*kSize, 2*kSize) {
if (ctx->abandoned()) {
return;
}
auto make_offscreen = [&](const SkISize dimensions) {
GrSwizzle readSwizzle = GrSwizzle::Concat(rtCtx->readSwizzle(), GrSwizzle{"garb"});
GrSwizzle writeSwizzle = GrSwizzle::Concat(rtCtx->readSwizzle(), GrSwizzle{"brag"});
return GrRenderTargetContext::Make(ctx,
rtCtx->colorInfo().refColorSpace(),
SkBackingFit::kExact,
dimensions,
rtCtx->asSurfaceProxy()->backendFormat(),
/* sample count*/ 1,
GrMipmapped::kNo,
rtCtx->asSurfaceProxy()->isProtected(),
readSwizzle,
writeSwizzle,
kTopLeft_GrSurfaceOrigin,
SkBudgeted::kYes,
/* surface props */ nullptr);
};
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) {
rtCtx->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);
}
rtCtx->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);
rtCtx->blitTexture(offscreen->readSurfaceView(),
SkIRect::MakeSize(offscreen->dimensions()),
c.rect.topLeft() + SkIPoint{4*kSize, 0});
}
}

View File

@ -75,6 +75,7 @@ gm_sources = [
"$_gm/circles.cpp",
"$_gm/circulararcs.cpp",
"$_gm/circularclips.cpp",
"$_gm/clear_swizzle.cpp",
"$_gm/clip_error.cpp",
"$_gm/clip_sierpinski_region.cpp",
"$_gm/clip_strokerect.cpp",

View File

@ -12,6 +12,8 @@
#include "include/core/SkScalar.h"
#include "include/core/SkTypes.h"
#include <array>
/** \file SkColor.h
Types, consts, functions, and macros for colors.
@ -308,6 +310,9 @@ struct SkRGBA4f {
*/
float* vec() { return &fR; }
/** As a std::array<float, 4> */
std::array<float, 4> array() const { return {fR, fG, fB, fA}; }
/** Returns one component. Asserts if index is out of range and SK_DEBUG is defined.
@param index one of: 0 (fR), 1 (fG), 2 (fB), 3 (fA)

View File

@ -35,7 +35,7 @@ void GrOpsRenderPass::end() {
this->resetActiveBuffers();
}
void GrOpsRenderPass::clear(const GrScissorState& scissor, const SkPMColor4f& color) {
void GrOpsRenderPass::clear(const GrScissorState& scissor, std::array<float, 4> color) {
SkASSERT(fRenderTarget);
// A clear at this level will always be a true clear, so make sure clears were not supposed to
// be redirected to draws instead

View File

@ -33,9 +33,9 @@ public:
virtual ~GrOpsRenderPass() {}
struct LoadAndStoreInfo {
GrLoadOp fLoadOp;
GrStoreOp fStoreOp;
SkPMColor4f fClearColor;
GrLoadOp fLoadOp;
GrStoreOp fStoreOp;
std::array<float, 4> fClearColor;
};
// Load-time clears of the stencil buffer are always to 0 so we don't store
@ -124,7 +124,7 @@ public:
* is restricted to 'scissor'. Must check caps.performPartialClearsAsDraws() before using an
* enabled scissor test; must check caps.performColorClearsAsDraws() before using this at all.
*/
void clear(const GrScissorState& scissor, const SkPMColor4f&);
void clear(const GrScissorState& scissor, std::array<float, 4> color);
/**
* Same as clear() but modifies the stencil; check caps.performStencilClearsAsDraws() and
@ -195,7 +195,7 @@ private:
virtual void onDrawIndexedIndirect(const GrBuffer*, size_t offset, int drawCount) {
SK_ABORT("Not implemented."); // Only called if caps.nativeDrawIndirectSupport().
}
virtual void onClear(const GrScissorState&, const SkPMColor4f&) = 0;
virtual void onClear(const GrScissorState&, std::array<float, 4> color) = 0;
virtual void onClearStencilClip(const GrScissorState&, bool insideStencilMask) = 0;
virtual void onExecuteDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>) {}

View File

@ -509,7 +509,7 @@ static GrOpsRenderPass* create_render_pass(GrGpu* gpu,
GrSurfaceOrigin origin,
const SkIRect& bounds,
GrLoadOp colorLoadOp,
const SkPMColor4f& loadClearColor,
const std::array<float, 4>& loadClearColor,
GrLoadOp stencilLoadOp,
GrStoreOp stencilStoreOp,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
@ -653,7 +653,7 @@ bool GrOpsTask::onExecute(GrOpFlushState* flushState) {
return true;
}
void GrOpsTask::setColorLoadOp(GrLoadOp op, const SkPMColor4f& color) {
void GrOpsTask::setColorLoadOp(GrLoadOp op, std::array<float, 4> color) {
fColorLoadOp = op;
fLoadClearColor = color;
if (GrLoadOp::kClear == fColorLoadOp) {
@ -701,7 +701,11 @@ void GrOpsTask::dump(bool printDependencies) const {
SkDebugf("kLoad\n");
break;
case GrLoadOp::kClear:
SkDebugf("kClear (0x%x)\n", fLoadClearColor.toBytes_RGBA());
SkDebugf("kClear {%g, %g, %g, %g}\n",
fLoadClearColor[0],
fLoadClearColor[1],
fLoadClearColor[2],
fLoadClearColor[3]);
break;
case GrLoadOp::kDiscard:
SkDebugf("kDiscard\n");

View File

@ -13,7 +13,6 @@
#include "include/core/SkStrokeRec.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/private/SkColorData.h"
#include "include/private/SkTArray.h"
#include "include/private/SkTDArray.h"
#include "src/core/SkArenaAlloc.h"
@ -126,12 +125,7 @@ private:
void setMustPreserveStencil() { fMustPreserveStencil = true; }
// Must only be called if native color buffer clearing is enabled.
void setColorLoadOp(GrLoadOp op, const SkPMColor4f& color);
// Sets the clear color to transparent black
void setColorLoadOp(GrLoadOp op) {
static const SkPMColor4f kDefaultClearColor = {0.f, 0.f, 0.f, 0.f};
this->setColorLoadOp(op, kDefaultClearColor);
}
void setColorLoadOp(GrLoadOp op, std::array<float, 4> color = {0, 0, 0, 0});
enum class CanDiscardPreviousOps : bool {
kYes = true,
@ -255,7 +249,7 @@ private:
GrAuditTrail* fAuditTrail;
GrLoadOp fColorLoadOp = GrLoadOp::kLoad;
SkPMColor4f fLoadClearColor = SK_PMColor4fTRANSPARENT;
std::array<float, 4> fLoadClearColor = {0, 0, 0, 0};
StencilContent fInitialStencilContent = StencilContent::kDontCare;
bool fMustPreserveStencil = false;

View File

@ -107,18 +107,20 @@ std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::Make(
writeSwizzle = context->priv().caps()->getWriteSwizzle(format, colorType);
}
GrSurfaceProxyView readView(proxy, origin, readSwizzle);
GrSurfaceProxyView readView ( proxy, origin, readSwizzle);
GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
return std::make_unique<GrRenderTargetContext>(context, std::move(readView),
std::move(writeView), colorType,
std::move(colorSpace), surfaceProps,
return std::make_unique<GrRenderTargetContext>(context,
std::move(readView),
std::move(writeView),
colorType,
std::move(colorSpace),
surfaceProps,
flushTimeOpsTask);
}
std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::Make(
GrRecordingContext* context,
GrColorType colorType,
sk_sp<SkColorSpace> colorSpace,
SkBackingFit fit,
SkISize dimensions,
@ -126,6 +128,8 @@ std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::Make(
int sampleCnt,
GrMipmapped mipMapped,
GrProtected isProtected,
GrSwizzle readSwizzle,
GrSwizzle writeSwizzle,
GrSurfaceOrigin origin,
SkBudgeted budgeted,
const SkSurfaceProps* surfaceProps) {
@ -138,17 +142,27 @@ std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::Make(
}
sk_sp<GrTextureProxy> proxy = context->priv().proxyProvider()->createProxy(
format, dimensions, GrRenderable::kYes, sampleCnt, mipMapped, fit, budgeted,
format,
dimensions,
GrRenderable::kYes,
sampleCnt,
mipMapped,
fit,
budgeted,
isProtected);
if (!proxy) {
return nullptr;
}
auto rtc = GrRenderTargetContext::Make(context, colorType, std::move(colorSpace),
std::move(proxy), origin, surfaceProps);
if (!rtc) {
return nullptr;
}
GrSurfaceProxyView readView ( proxy, origin, readSwizzle);
GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
auto rtc = std::make_unique<GrRenderTargetContext>(context,
std::move(readView),
std::move(writeView),
GrColorType::kUnknown,
std::move(colorSpace),
surfaceProps);
rtc->discard();
return rtc;
}
@ -169,9 +183,24 @@ std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::Make(
if (!format.isValid()) {
return nullptr;
}
sk_sp<GrTextureProxy> proxy = context->priv().proxyProvider()->createProxy(
format,
dimensions,
GrRenderable::kYes,
sampleCnt,
mipMapped,
fit,
budgeted,
isProtected);
if (!proxy) {
return nullptr;
}
return GrRenderTargetContext::Make(context, colorType, std::move(colorSpace), fit, dimensions,
format, sampleCnt, mipMapped, isProtected, origin, budgeted,
return GrRenderTargetContext::Make(context,
colorType,
std::move(colorSpace),
std::move(proxy),
origin,
surfaceProps);
}
@ -554,8 +583,9 @@ void GrRenderTargetContext::internalClear(const SkIRect* scissor,
GrOpsTask* opsTask = this->getOpsTask();
if (opsTask->resetForFullscreenClear(this->canDiscardPreviousOpsOnFullClear()) &&
!this->caps()->performColorClearsAsDraws()) {
SkPMColor4f clearColor = this->writeSurfaceView().swizzle().applyTo(color);
// The op list was emptied and native clears are allowed, so just use the load op
opsTask->setColorLoadOp(GrLoadOp::kClear, color);
opsTask->setColorLoadOp(GrLoadOp::kClear, clearColor.array());
return;
} else {
// Will use an op for the clear, reset the load op to discard since the op will
@ -575,7 +605,8 @@ void GrRenderTargetContext::internalClear(const SkIRect* scissor,
GrFillRectOp::MakeNonAARect(fContext, std::move(paint), SkMatrix::I(),
SkRect::Make(scissorState.rect())));
} else {
this->addOp(GrClearOp::MakeColor(fContext, scissorState, color));
SkPMColor4f clearColor = this->writeSurfaceView().swizzle().applyTo(color);
this->addOp(GrClearOp::MakeColor(fContext, scissorState, clearColor.array()));
}
}

View File

@ -60,24 +60,15 @@ class SkVertices;
*/
class GrRenderTargetContext : public GrSurfaceContext {
public:
static std::unique_ptr<GrRenderTargetContext> Make(
GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, sk_sp<GrSurfaceProxy>,
GrSurfaceOrigin, const SkSurfaceProps*, bool flushTimeOpsTask = false);
static std::unique_ptr<GrRenderTargetContext> Make(GrRecordingContext*,
GrColorType,
sk_sp<SkColorSpace>,
SkBackingFit,
SkISize dimensions,
const GrBackendFormat&,
int sampleCnt,
GrMipmapped,
GrProtected,
sk_sp<GrSurfaceProxy>,
GrSurfaceOrigin,
SkBudgeted,
const SkSurfaceProps*);
const SkSurfaceProps*,
bool flushTimeOpsTask = false);
// Same as above but will use the default GrBackendFormat for the given GrColorType
/* Uses the default texture format for the color type */
static std::unique_ptr<GrRenderTargetContext> Make(
GrRecordingContext*,
GrColorType,
@ -91,6 +82,24 @@ public:
SkBudgeted = SkBudgeted::kYes,
const SkSurfaceProps* = nullptr);
/**
* Takes custom swizzles rather than determining swizzles from color type and format.
* It will have color type kUnknown.
*/
static std::unique_ptr<GrRenderTargetContext> Make(GrRecordingContext*,
sk_sp<SkColorSpace>,
SkBackingFit,
SkISize dimensions,
const GrBackendFormat&,
int sampleCnt,
GrMipmapped,
GrProtected,
GrSwizzle readSwizzle,
GrSwizzle writeSwizzle,
GrSurfaceOrigin,
SkBudgeted,
const SkSurfaceProps*);
static std::tuple<GrColorType, GrBackendFormat> GetFallbackColorTypeAndFormat(GrImageContext*,
GrColorType,
int sampleCnt);

View File

@ -9,8 +9,7 @@
#define GrRenderTask_DEFINED
#include "include/core/SkRefCnt.h"
#include "include/private/SkColorData.h"
#include "include/private/SkTDArray.h"
#include "include/private/SkTArray.h"
#include "src/gpu/GrSurfaceProxyView.h"
#include "src/gpu/GrTextureProxy.h"
#include "src/gpu/GrTextureResolveManager.h"

View File

@ -284,10 +284,20 @@ sk_sp<GrSurfaceProxy> GrSurfaceProxy::Copy(GrRecordingContext* context,
}
}
if (src->asTextureProxy()) {
auto dstContext = GrRenderTargetContext::Make(
context, GrColorType::kUnknown, nullptr, fit, {width, height}, format, 1, mipMapped,
src->isProtected(), origin, budgeted, nullptr);
GrSurfaceProxyView view(sk_ref_sp(src), origin, GrSwizzle("rgba"));
auto dstContext = GrRenderTargetContext::Make(context,
nullptr,
fit,
{width, height},
format,
/* sample count*/ 1,
mipMapped,
src->isProtected(),
GrSwizzle::RGBA(),
GrSwizzle::RGBA(),
origin,
budgeted,
/*surface props*/ nullptr);
GrSurfaceProxyView view(sk_ref_sp(src), origin, GrSwizzle::RGBA());
if (dstContext && dstContext->blitTexture(std::move(view), srcRect, dstPoint)) {
return dstContext->asSurfaceProxyRef();
}

View File

@ -391,7 +391,7 @@ void GrD3DDirectCommandList::executeIndirect(const sk_sp<GrD3DCommandSignature>
}
void GrD3DDirectCommandList::clearRenderTargetView(const GrD3DRenderTarget* renderTarget,
const SkPMColor4f& color,
std::array<float, 4> color,
const D3D12_RECT* rect) {
this->addingWork();
this->addResource(renderTarget->resource());
@ -400,8 +400,8 @@ void GrD3DDirectCommandList::clearRenderTargetView(const GrD3DRenderTarget* rend
this->addResource(msaaTextureResource->resource());
}
unsigned int numRects = rect ? 1 : 0;
fCommandList->ClearRenderTargetView(renderTarget->colorRenderTargetView(),
color.vec(), numRects, rect);
fCommandList->ClearRenderTargetView(renderTarget->colorRenderTargetView(), color.data(),
numRects, rect);
}
void GrD3DDirectCommandList::clearDepthStencilView(const GrD3DAttachment* stencil,

View File

@ -10,7 +10,6 @@
#include "include/gpu/GrTypes.h"
#include "include/gpu/d3d/GrD3DTypes.h"
#include "include/private/SkColorData.h"
#include "src/gpu/GrManagedResource.h"
#include "src/gpu/GrRingBuffer.h"
#include "src/gpu/d3d/GrD3DRootSignature.h"
@ -172,7 +171,8 @@ public:
void executeIndirect(const sk_sp<GrD3DCommandSignature> commandSig, unsigned int maxCommandCnt,
const GrD3DBuffer* argumentBuffer, size_t argumentBufferOffset);
void clearRenderTargetView(const GrD3DRenderTarget* renderTarget, const SkPMColor4f& color,
void clearRenderTargetView(const GrD3DRenderTarget* renderTarget,
std::array<float, 4> color,
const D3D12_RECT* rect);
void clearDepthStencilView(const GrD3DAttachment*,
uint8_t stencilClearValue,

View File

@ -314,7 +314,7 @@ static D3D12_RECT scissor_to_d3d_clear_rect(const GrScissorState& scissor,
return clearRect;
}
void GrD3DOpsRenderPass::onClear(const GrScissorState& scissor, const SkPMColor4f& color) {
void GrD3DOpsRenderPass::onClear(const GrScissorState& scissor, std::array<float, 4> color) {
D3D12_RECT clearRect = scissor_to_d3d_clear_rect(scissor, fRenderTarget, fOrigin);
auto d3dRT = static_cast<GrD3DRenderTarget*>(fRenderTarget);
SkASSERT(d3dRT->grD3DResourceState()->getResourceState() == D3D12_RESOURCE_STATE_RENDER_TARGET);

View File

@ -56,7 +56,7 @@ private:
void onDrawIndirect(const GrBuffer*, size_t offset, int drawCount) override;
void onDrawIndexedIndirect(const GrBuffer*, size_t offset, int drawCount) override;
void onClear(const GrScissorState& scissor, const SkPMColor4f& color) override;
void onClear(const GrScissorState& scissor, std::array<float, 4> color) override;
void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override;
@ -68,7 +68,7 @@ private:
SkIRect fCurrentPipelineBounds;
GrLoadOp fColorLoadOp;
SkPMColor4f fClearColor;
std::array<float, 4> fClearColor;
GrLoadOp fStencilLoadOp;
using INHERITED = GrOpsRenderPass;

View File

@ -59,7 +59,7 @@ wgpu::RenderPassEncoder GrDawnOpsRenderPass::beginRenderPass(wgpu::LoadOp colorO
}
auto stencilAttachment = static_cast<GrDawnAttachment*>(fRenderTarget->getStencilAttachment());
const float *c = fColorInfo.fClearColor.vec();
const float* c = fColorInfo.fClearColor.data();
wgpu::RenderPassColorAttachmentDescriptor colorAttachment;
colorAttachment.attachment = static_cast<GrDawnRenderTarget*>(fRenderTarget)->textureView();
@ -103,7 +103,7 @@ void GrDawnOpsRenderPass::onClearStencilClip(const GrScissorState& scissor,
fPassEncoder = beginRenderPass(wgpu::LoadOp::Load, wgpu::LoadOp::Clear);
}
void GrDawnOpsRenderPass::onClear(const GrScissorState& scissor, const SkPMColor4f& color) {
void GrDawnOpsRenderPass::onClear(const GrScissorState& scissor, std::array<float, 4> color) {
SkASSERT(!scissor.enabled());
fPassEncoder.EndPass();
fPassEncoder = beginRenderPass(wgpu::LoadOp::Clear, wgpu::LoadOp::Load);

View File

@ -51,7 +51,7 @@ private:
void onDrawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, int baseInstance,
int baseVertex) override;
void onClear(const GrScissorState& scissor, const SkPMColor4f& color) override;
void onClear(const GrScissorState& scissor, std::array<float, 4> color) override;
void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override;

View File

@ -1339,7 +1339,7 @@ sk_sp<GrTexture> GrGLGpu::onCreateTexture(SkISize dimensions,
this->flushScissorTest(GrScissorTest::kDisabled);
this->disableWindowRectangles();
this->flushColorWrite(true);
this->flushClearColor(SK_PMColor4fTRANSPARENT);
this->flushClearColor({0, 0, 0, 0});
for (int i = 0; i < mipLevelCount; ++i) {
if (levelClearMask & (1U << i)) {
this->bindSurfaceFBOForPixelOps(tex.get(), i, GR_GL_FRAMEBUFFER,
@ -1889,8 +1889,10 @@ GrGLenum GrGLGpu::bindBuffer(GrGpuBufferType type, const GrBuffer* buffer) {
return bufferState->fGLTarget;
}
void GrGLGpu::clear(const GrScissorState& scissor, const SkPMColor4f& color,
GrRenderTarget* target, GrSurfaceOrigin origin) {
void GrGLGpu::clear(const GrScissorState& scissor,
std::array<float, 4> color,
GrRenderTarget* target,
GrSurfaceOrigin origin) {
// parent class should never let us get here with no RT
SkASSERT(target);
SkASSERT(!this->caps()->performColorClearsAsDraws());
@ -2719,8 +2721,8 @@ void GrGLGpu::flushColorWrite(bool writeColor) {
}
}
void GrGLGpu::flushClearColor(const SkPMColor4f& color) {
GrGLfloat r = color.fR, g = color.fG, b = color.fB, a = color.fA;
void GrGLGpu::flushClearColor(std::array<float, 4> color) {
GrGLfloat r = color[0], g = color[1], b = color[2], a = color[3];
if (this->glCaps().clearToBoundaryValuesIsBroken() &&
(1 == r || 0 == r) && (1 == g || 0 == g) && (1 == b || 0 == b) && (1 == a || 0 == a)) {
static const GrGLfloat safeAlpha1 = nextafter(1.f, 2.f);

View File

@ -108,7 +108,7 @@ public:
// The GrGLOpsRenderPass does not buffer up draws before submitting them to the gpu.
// Thus this is the implementation of the clear call for the corresponding passthrough function
// on GrGLOpsRenderPass.
void clear(const GrScissorState&, const SkPMColor4f&, GrRenderTarget*, GrSurfaceOrigin);
void clear(const GrScissorState&, std::array<float, 4> color, GrRenderTarget*, GrSurfaceOrigin);
// The GrGLOpsRenderPass does not buffer up draws before submitting them to the gpu.
// Thus this is the implementation of the clearStencil call for the corresponding passthrough
@ -397,7 +397,7 @@ private:
void flushPatchVertexCount(uint8_t count);
void flushColorWrite(bool writeColor);
void flushClearColor(const SkPMColor4f&);
void flushClearColor(std::array<float, 4>);
// flushes the scissor. see the note on flushBoundTextureAndParams about
// flushing the scissor after that function is called.

View File

@ -383,7 +383,7 @@ void GrGLOpsRenderPass::multiDrawElementsANGLEOrWebGL(const GrBuffer* drawIndire
}
}
void GrGLOpsRenderPass::onClear(const GrScissorState& scissor, const SkPMColor4f& color) {
void GrGLOpsRenderPass::onClear(const GrScissorState& scissor, std::array<float, 4> color) {
fGpu->clear(scissor, color, fRenderTarget, fOrigin);
}

View File

@ -73,7 +73,7 @@ private:
int drawCount) override;
void multiDrawElementsANGLEOrWebGL(const GrBuffer* drawIndirectBuffer, size_t offset,
int drawCount);
void onClear(const GrScissorState& scissor, const SkPMColor4f& color) override;
void onClear(const GrScissorState& scissor, std::array<float, 4> color) override;
void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override;
GrGLGpu* fGpu;

View File

@ -45,7 +45,7 @@ private:
void onDrawIndexedInstanced(int, int, int, int, int) override { this->dummyDraw(); }
void onDrawIndirect(const GrBuffer*, size_t, int) override { this->dummyDraw(); }
void onDrawIndexedIndirect(const GrBuffer*, size_t, int) override { this->dummyDraw(); }
void onClear(const GrScissorState& scissor, const SkPMColor4f&) override {
void onClear(const GrScissorState& scissor, std::array<float, 4>) override {
this->markRenderTargetDirty();
}
void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override {}

View File

@ -49,7 +49,7 @@ private:
void onDrawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, int baseInstance,
int baseVertex) override;
void onClear(const GrScissorState& scissor, const SkPMColor4f& color) override;
void onClear(const GrScissorState& scissor, std::array<float, 4> color) override;
void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override;

View File

@ -123,7 +123,7 @@ bool GrMtlOpsRenderPass::onBindTextures(const GrPrimitiveProcessor& primProc,
return true;
}
void GrMtlOpsRenderPass::onClear(const GrScissorState& scissor, const SkPMColor4f& color) {
void GrMtlOpsRenderPass::onClear(const GrScissorState& scissor, std::array<float, 4> color) {
// Partial clears are not supported
SkASSERT(!scissor.enabled());
@ -212,7 +212,7 @@ void GrMtlOpsRenderPass::setupRenderPass(
static_cast<GrMtlRenderTarget*>(fRenderTarget)->mtlColorTexture();
renderPassDesc.colorAttachments[0].slice = 0;
renderPassDesc.colorAttachments[0].level = 0;
const SkPMColor4f& clearColor = colorInfo.fClearColor;
const std::array<float, 4>& clearColor = colorInfo.fClearColor;
renderPassDesc.colorAttachments[0].clearColor =
MTLClearColorMake(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
renderPassDesc.colorAttachments[0].loadAction =

View File

@ -20,18 +20,24 @@ static bool contains_scissor(const GrScissorState& a, const GrScissorState& b) {
GrOp::Owner GrClearOp::MakeColor(GrRecordingContext* context,
const GrScissorState& scissor,
const SkPMColor4f& color) {
std::array<float, 4> color) {
return GrOp::Make<GrClearOp>(context, Buffer::kColor, scissor, color, false);
}
GrOp::Owner GrClearOp::MakeStencilClip(GrRecordingContext* context,
const GrScissorState& scissor,
bool insideMask) {
return GrOp::Make<GrClearOp>(context, Buffer::kStencilClip, scissor, SkPMColor4f(), insideMask);
return GrOp::Make<GrClearOp>(context,
Buffer::kStencilClip,
scissor,
std::array<float, 4>(),
insideMask);
}
GrClearOp::GrClearOp(Buffer buffer, const GrScissorState& scissor,
const SkPMColor4f& color, bool insideMask)
GrClearOp::GrClearOp(Buffer buffer,
const GrScissorState& scissor,
std::array<float, 4> color,
bool insideMask)
: INHERITED(ClassID())
, fScissor(scissor)
, fColor(color)

View File

@ -22,7 +22,7 @@ public:
// A fullscreen or scissored clear, depending on the clip and proxy dimensions
static GrOp::Owner MakeColor(GrRecordingContext* context,
const GrScissorState& scissor,
const SkPMColor4f& color);
std::array<float, 4> color);
static GrOp::Owner MakeStencilClip(GrRecordingContext* context,
const GrScissorState& scissor,
@ -41,7 +41,10 @@ private:
};
GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Buffer);
GrClearOp(Buffer buffer, const GrScissorState& scissor, const SkPMColor4f& color, bool stencil);
GrClearOp(Buffer buffer,
const GrScissorState& scissor,
std::array<float, 4> color,
bool stencil);
CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override;
@ -61,15 +64,15 @@ private:
} else {
string.append("disabled");
}
string.appendf("], Color: 0x%08x\n", fColor.toBytes_RGBA());
string.appendf("], Color: {%g, %g, %g, %g}\n", fColor[0], fColor[1], fColor[2], fColor[3]);
return string;
}
#endif
GrScissorState fScissor;
SkPMColor4f fColor;
bool fStencilInsideMask;
Buffer fBuffer;
GrScissorState fScissor;
std::array<float, 4> fColor;
bool fStencilInsideMask;
Buffer fBuffer;
using INHERITED = GrOp;
};

View File

@ -63,9 +63,8 @@ GrVkOpsRenderPass::GrVkOpsRenderPass(GrVkGpu* gpu) : fGpu(gpu) {}
bool GrVkOpsRenderPass::init(const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo,
const SkPMColor4f& clearColor,
std::array<float, 4> clearColor,
bool withStencil) {
VkAttachmentLoadOp loadOp;
VkAttachmentStoreOp storeOp;
get_vk_load_store_ops(colorInfo.fLoadOp, colorInfo.fStoreOp,
@ -352,13 +351,13 @@ void GrVkOpsRenderPass::onClearStencilClip(const GrScissorState& scissor, bool i
fCurrentCBIsEmpty = false;
}
void GrVkOpsRenderPass::onClear(const GrScissorState& scissor, const SkPMColor4f& color) {
void GrVkOpsRenderPass::onClear(const GrScissorState& scissor, std::array<float, 4> color) {
if (!fCurrentRenderPass) {
SkASSERT(fGpu->isDeviceLost());
return;
}
VkClearColorValue vkColor = {{color.fR, color.fG, color.fB, color.fA}};
VkClearColorValue vkColor = {{color[0], color[1], color[2], color[3]}};
// If we end up in a situation where we are calling clear without a scissior then in general it
// means we missed an opportunity higher up the stack to set the load op to be a clear. However,

View File

@ -52,7 +52,7 @@ public:
private:
bool init(const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkPMColor4f& clearColor,
std::array<float, 4> clearColor,
bool withStencil);
// Called instead of init when we are drawing to a render target that already wraps a secondary
@ -88,7 +88,7 @@ private:
void onDrawIndexedIndirect(const GrBuffer* drawIndirectBuffer, size_t offset,
int drawCount) override;
void onClear(const GrScissorState& scissor, const SkPMColor4f& color) override;
void onClear(const GrScissorState& scissor, std::array<float, 4> color) override;
void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override;