Consolidate the scissor enums into one "GrScissorTest" enum
Bug: skia:
Change-Id: If8d40b54860acb5c18d3a9a82cb2a61e3c42025f
Reviewed-on: https://skia-review.googlesource.com/147172
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/gm/clockwise.cpp b/gm/clockwise.cpp
index 7dc3816..7b2dbcc 100644
--- a/gm/clockwise.cpp
+++ b/gm/clockwise.cpp
@@ -122,7 +122,7 @@
if (!vertexBuffer) {
return;
}
- GrPipeline pipeline(flushState->drawOpArgs().fProxy, GrPipeline::ScissorState::kDisabled,
+ GrPipeline pipeline(flushState->drawOpArgs().fProxy, GrScissorTest::kDisabled,
SkBlendMode::kPlus);
GrMesh mesh(GrPrimitiveType::kTriangleStrip);
mesh.setNonIndexedNonInstanced(4);
diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h
index ef6fa54..4b6b709 100644
--- a/include/private/GrTypesPriv.h
+++ b/include/private/GrTypesPriv.h
@@ -202,6 +202,11 @@
kPath_ClipType
};
+enum class GrScissorTest : bool {
+ kDisabled = false,
+ kEnabled = true
+};
+
struct GrMipLevel {
const void* fPixels;
size_t fRowBytes;
diff --git a/samplecode/SampleCCPRGeometry.cpp b/samplecode/SampleCCPRGeometry.cpp
index c33a6bd..f883dbd 100644
--- a/samplecode/SampleCCPRGeometry.cpp
+++ b/samplecode/SampleCCPRGeometry.cpp
@@ -347,8 +347,7 @@
}
}
- GrPipeline pipeline(state->drawOpArgs().fProxy, GrPipeline::ScissorState::kDisabled,
- SkBlendMode::kPlus);
+ GrPipeline pipeline(state->drawOpArgs().fProxy, GrScissorTest::kDisabled, SkBlendMode::kPlus);
if (glGpu) {
glGpu->handleDirtyContext();
diff --git a/src/gpu/GrPipeline.cpp b/src/gpu/GrPipeline.cpp
index 5b59f95..c671922 100644
--- a/src/gpu/GrPipeline.cpp
+++ b/src/gpu/GrPipeline.cpp
@@ -99,7 +99,7 @@
return this->getXferProcessor().xferBarrierType(caps);
}
-GrPipeline::GrPipeline(GrRenderTargetProxy* proxy, ScissorState scissorState, SkBlendMode blendmode)
+GrPipeline::GrPipeline(GrRenderTargetProxy* proxy, GrScissorTest scissorTest, SkBlendMode blendmode)
: fProxy(proxy)
, fWindowRectsState()
, fUserStencilSettings(&GrUserStencilSettings::kUnused)
@@ -108,7 +108,7 @@
, fFragmentProcessors()
, fNumColorProcessors(0) {
SkASSERT(proxy);
- if (scissorState) {
+ if (GrScissorTest::kEnabled == scissorTest) {
fFlags |= kScissorEnabled_Flag;
}
}
diff --git a/src/gpu/GrPipeline.h b/src/gpu/GrPipeline.h
index 1bd7765..5e75c65 100644
--- a/src/gpu/GrPipeline.h
+++ b/src/gpu/GrPipeline.h
@@ -53,11 +53,6 @@
kSnapVerticesToPixelCenters_Flag = 0x2,
};
- enum ScissorState : bool {
- kEnabled = true,
- kDisabled = false
- };
-
struct InitArgs {
uint32_t fFlags = 0;
const GrUserStencilSettings* fUserStencil = &GrUserStencilSettings::kUnused;
@@ -97,10 +92,10 @@
/**
* Creates a simple pipeline with default settings and no processors. The provided blend mode
- * must be "Porter Duff" (<= kLastCoeffMode). If using ScissorState::kEnabled, the caller must
+ * must be "Porter Duff" (<= kLastCoeffMode). If using GrScissorTest::kEnabled, the caller must
* specify a scissor rectangle through the DynamicState struct.
**/
- GrPipeline(GrRenderTargetProxy*, ScissorState, SkBlendMode);
+ GrPipeline(GrRenderTargetProxy*, GrScissorTest, SkBlendMode);
GrPipeline(const InitArgs&, GrProcessorSet&&, GrAppliedClip&&);
@@ -176,8 +171,8 @@
const GrUserStencilSettings* getUserStencil() const { return fUserStencilSettings; }
- ScissorState isScissorEnabled() const {
- return ScissorState(SkToBool(fFlags & kScissorEnabled_Flag));
+ bool isScissorEnabled() const {
+ return SkToBool(fFlags & kScissorEnabled_Flag);
}
const GrWindowRectsState& getWindowRectsState() const { return fWindowRectsState; }
diff --git a/src/gpu/ccpr/GrCCPathParser.cpp b/src/gpu/ccpr/GrCCPathParser.cpp
index 1935385..190f162 100644
--- a/src/gpu/ccpr/GrCCPathParser.cpp
+++ b/src/gpu/ccpr/GrCCPathParser.cpp
@@ -164,11 +164,11 @@
}
}
-void GrCCPathParser::saveParsedPath(ScissorMode scissorMode, const SkIRect& clippedDevIBounds,
+void GrCCPathParser::saveParsedPath(GrScissorTest scissorTest, const SkIRect& clippedDevIBounds,
const SkIVector& devToAtlasOffset) {
SkASSERT(fParsingPath);
- fPathsInfo.emplace_back(scissorMode, devToAtlasOffset);
+ fPathsInfo.emplace_back(scissorTest, devToAtlasOffset);
// Tessellate fans from very large and/or simple paths, in order to reduce overdraw.
int numVerbs = fGeometry.verbs().count() - fCurrPathVerbsIdx - 1;
@@ -250,10 +250,10 @@
fPathsInfo.back().adoptFanTessellation(vertices, count);
}
- fTotalPrimitiveCounts[(int)scissorMode] += fCurrPathPrimitiveCounts;
+ fTotalPrimitiveCounts[(int)scissorTest] += fCurrPathPrimitiveCounts;
- if (ScissorMode::kScissored == scissorMode) {
- fScissorSubBatches.push_back() = {fTotalPrimitiveCounts[(int)ScissorMode::kScissored],
+ if (GrScissorTest::kEnabled == scissorTest) {
+ fScissorSubBatches.push_back() = {fTotalPrimitiveCounts[(int)GrScissorTest::kEnabled],
clippedDevIBounds.makeOffset(devToAtlasOffset.fX,
devToAtlasOffset.fY)};
}
@@ -276,14 +276,14 @@
fMaxMeshesPerDraw = SkTMax(fMaxMeshesPerDraw, maxMeshes);
const auto& lastScissorSubBatch = fScissorSubBatches[lastBatch.fEndScissorSubBatchIdx - 1];
- PrimitiveTallies batchTotalCounts = fTotalPrimitiveCounts[(int)ScissorMode::kNonScissored] -
+ PrimitiveTallies batchTotalCounts = fTotalPrimitiveCounts[(int)GrScissorTest::kDisabled] -
lastBatch.fEndNonScissorIndices;
- batchTotalCounts += fTotalPrimitiveCounts[(int)ScissorMode::kScissored] -
+ batchTotalCounts += fTotalPrimitiveCounts[(int)GrScissorTest::kEnabled] -
lastScissorSubBatch.fEndPrimitiveIndices;
// This will invalidate lastBatch.
fCoverageCountBatches.push_back() = {
- fTotalPrimitiveCounts[(int)ScissorMode::kNonScissored],
+ fTotalPrimitiveCounts[(int)GrScissorTest::kDisabled],
fScissorSubBatches.count(),
batchTotalCounts
};
@@ -350,7 +350,7 @@
bool GrCCPathParser::finalize(GrOnFlushResourceProvider* onFlushRP) {
SkASSERT(!fParsingPath); // Call saveParsedPath() or discardParsedPath().
SkASSERT(fCoverageCountBatches.back().fEndNonScissorIndices == // Call closeCurrentBatch().
- fTotalPrimitiveCounts[(int)ScissorMode::kNonScissored]);
+ fTotalPrimitiveCounts[(int)GrScissorTest::kDisabled]);
SkASSERT(fCoverageCountBatches.back().fEndScissorSubBatchIdx == fScissorSubBatches.count());
// Here we build a single instance buffer to share with every internal batch.
@@ -417,7 +417,7 @@
switch (verb) {
case GrCCGeometry::Verb::kBeginPath:
SkASSERT(currFan.empty());
- currIndices = &instanceIndices[(int)nextPathInfo->scissorMode()];
+ currIndices = &instanceIndices[(int)nextPathInfo->scissorTest()];
devToAtlasOffset = Sk2f(static_cast<float>(nextPathInfo->devToAtlasOffset().fX),
static_cast<float>(nextPathInfo->devToAtlasOffset().fY));
currFanIsTessellated = nextPathInfo->hasFanTessellation();
@@ -530,7 +530,7 @@
const PrimitiveTallies& batchTotalCounts = fCoverageCountBatches[batchID].fTotalPrimitiveCounts;
- GrPipeline pipeline(flushState->drawOpArgs().fProxy, GrPipeline::ScissorState::kEnabled,
+ GrPipeline pipeline(flushState->drawOpArgs().fProxy, GrScissorTest::kEnabled,
SkBlendMode::kPlus);
if (batchTotalCounts.fTriangles) {
@@ -581,7 +581,7 @@
if (int instanceCount = batch.fEndNonScissorIndices.*instanceType -
previousBatch.fEndNonScissorIndices.*instanceType) {
SkASSERT(instanceCount > 0);
- int baseInstance = fBaseInstances[(int)ScissorMode::kNonScissored].*instanceType +
+ int baseInstance = fBaseInstances[(int)GrScissorTest::kDisabled].*instanceType +
previousBatch.fEndNonScissorIndices.*instanceType;
proc.appendMesh(fInstanceBuffer.get(), instanceCount, baseInstance, &fMeshesScratchBuffer);
fScissorRectScratchBuffer.push_back().setXYWH(0, 0, drawBounds.width(),
@@ -591,7 +591,7 @@
SkASSERT(previousBatch.fEndScissorSubBatchIdx > 0);
SkASSERT(batch.fEndScissorSubBatchIdx <= fScissorSubBatches.count());
- int baseScissorInstance = fBaseInstances[(int)ScissorMode::kScissored].*instanceType;
+ int baseScissorInstance = fBaseInstances[(int)GrScissorTest::kEnabled].*instanceType;
for (int i = previousBatch.fEndScissorSubBatchIdx; i < batch.fEndScissorSubBatchIdx; ++i) {
const ScissorSubBatch& previousSubBatch = fScissorSubBatches[i - 1];
const ScissorSubBatch& scissorSubBatch = fScissorSubBatches[i];
diff --git a/src/gpu/ccpr/GrCCPathParser.h b/src/gpu/ccpr/GrCCPathParser.h
index 57b1ce6..9ec2a3c 100644
--- a/src/gpu/ccpr/GrCCPathParser.h
+++ b/src/gpu/ccpr/GrCCPathParser.h
@@ -28,11 +28,6 @@
*/
class GrCCPathParser {
public:
- // Indicates whether a path should enforce a scissor clip when rendering its mask. (Specified
- // as an int because these values get used directly as indices into arrays.)
- enum class ScissorMode : int { kNonScissored = 0, kScissored = 1 };
- static constexpr int kNumScissorModes = 2;
-
struct PathStats {
int fMaxPointsPerPath = 0;
int fNumTotalSkPoints = 0;
@@ -67,7 +62,7 @@
// Commits the currently-parsed path from staging to the current batch, and specifies whether
// the mask should be rendered with a scissor in effect. Accepts an optional post-device-space
// translate for placement in an atlas.
- void saveParsedPath(ScissorMode, const SkIRect& clippedDevIBounds,
+ void saveParsedPath(GrScissorTest, const SkIRect& clippedDevIBounds,
const SkIVector& devToAtlasOffset);
void discardParsedPath();
@@ -83,15 +78,16 @@
void drawCoverageCount(GrOpFlushState*, CoverageCountBatchID, const SkIRect& drawBounds) const;
private:
+ static constexpr int kNumScissorModes = 2;
using PrimitiveTallies = GrCCGeometry::PrimitiveTallies;
// Every kBeginPath verb has a corresponding PathInfo entry.
class PathInfo {
public:
- PathInfo(ScissorMode scissorMode, const SkIVector& devToAtlasOffset)
- : fScissorMode(scissorMode), fDevToAtlasOffset(devToAtlasOffset) {}
+ PathInfo(GrScissorTest scissorTest, const SkIVector& devToAtlasOffset)
+ : fScissorTest(scissorTest), fDevToAtlasOffset(devToAtlasOffset) {}
- ScissorMode scissorMode() const { return fScissorMode; }
+ GrScissorTest scissorTest() const { return fScissorTest; }
const SkIVector& devToAtlasOffset() const { return fDevToAtlasOffset; }
// An empty tessellation fan is also valid; we use negative count to denote not tessellated.
@@ -112,7 +108,7 @@
}
private:
- ScissorMode fScissorMode;
+ GrScissorTest fScissorTest;
SkIVector fDevToAtlasOffset; // Translation from device space to location in atlas.
int fFanTessellationCount = -1;
std::unique_ptr<const GrTessellator::WindingVertex[]> fFanTessellation;
diff --git a/src/gpu/ccpr/GrCCPerFlushResources.cpp b/src/gpu/ccpr/GrCCPerFlushResources.cpp
index 2b246c9..886d679 100644
--- a/src/gpu/ccpr/GrCCPerFlushResources.cpp
+++ b/src/gpu/ccpr/GrCCPerFlushResources.cpp
@@ -69,8 +69,7 @@
auto atlasProxy = fStashedAtlasProxy.get();
dynamicState.fPrimitiveProcessorTextures = &atlasProxy;
- GrPipeline pipeline(flushState->proxy(), GrPipeline::ScissorState::kDisabled,
- SkBlendMode::kSrc);
+ GrPipeline pipeline(flushState->proxy(), GrScissorTest::kDisabled, SkBlendMode::kSrc);
GrCCPathProcessor pathProc(atlasProxy);
pathProc.drawPaths(flushState, pipeline, &dynamicState, *fResources, fBaseInstance,
fEndInstance, this->bounds());
@@ -216,14 +215,13 @@
bool GrCCPerFlushResources::placeParsedPathInAtlas(const SkIRect& clipIBounds,
const SkIRect& pathIBounds,
SkIVector* devToAtlasOffset) {
- using ScissorMode = GrCCPathParser::ScissorMode;
- ScissorMode scissorMode;
+ GrScissorTest scissorTest;
SkIRect clippedPathIBounds;
if (clipIBounds.contains(pathIBounds)) {
clippedPathIBounds = pathIBounds;
- scissorMode = ScissorMode::kNonScissored;
+ scissorTest = GrScissorTest::kDisabled;
} else if (clippedPathIBounds.intersect(clipIBounds, pathIBounds)) {
- scissorMode = ScissorMode::kScissored;
+ scissorTest = GrScissorTest::kEnabled;
} else {
fPathParser.discardParsedPath();
return false;
@@ -237,7 +235,7 @@
CoverageCountBatchID batchID = fPathParser.closeCurrentBatch();
retiredAtlas->setUserBatchID(batchID);
}
- fPathParser.saveParsedPath(scissorMode, clippedPathIBounds, *devToAtlasOffset);
+ fPathParser.saveParsedPath(scissorTest, clippedPathIBounds, *devToAtlasOffset);
return true;
}
diff --git a/tests/GrMeshTest.cpp b/tests/GrMeshTest.cpp
index 1cb2b7c..cc45cd8 100644
--- a/tests/GrMeshTest.cpp
+++ b/tests/GrMeshTest.cpp
@@ -390,7 +390,7 @@
void DrawMeshHelper::drawMesh(const GrMesh& mesh) {
GrRenderTargetProxy* proxy = fState->drawOpArgs().fProxy;
- GrPipeline pipeline(proxy, GrPipeline::ScissorState::kDisabled, SkBlendMode::kSrc);
+ GrPipeline pipeline(proxy, GrScissorTest::kDisabled, SkBlendMode::kSrc);
GrMeshTestProcessor mtp(mesh.isInstanced(), mesh.hasVertexData());
fState->rtCommandBuffer()->draw(mtp, pipeline, nullptr, nullptr, &mesh, 1,
SkRect::MakeIWH(kImageWidth, kImageHeight));
diff --git a/tests/GrPipelineDynamicStateTest.cpp b/tests/GrPipelineDynamicStateTest.cpp
index 622790b..a31b1f8 100644
--- a/tests/GrPipelineDynamicStateTest.cpp
+++ b/tests/GrPipelineDynamicStateTest.cpp
@@ -28,8 +28,6 @@
* scissor rectangles then reads back the result to verify a successful test.
*/
-using ScissorState = GrPipeline::ScissorState;
-
static constexpr int kScreenSize = 6;
static constexpr int kNumMeshes = 4;
static constexpr int kScreenSplitX = kScreenSize/2;
@@ -113,19 +111,19 @@
DEFINE_OP_CLASS_ID
static std::unique_ptr<GrDrawOp> Make(GrContext* context,
- ScissorState scissorState,
+ GrScissorTest scissorTest,
sk_sp<const GrBuffer> vbuff) {
GrOpMemoryPool* pool = context->contextPriv().opMemoryPool();
- return pool->allocate<GrPipelineDynamicStateTestOp>(scissorState, std::move(vbuff));
+ return pool->allocate<GrPipelineDynamicStateTestOp>(scissorTest, std::move(vbuff));
}
private:
friend class GrOpMemoryPool;
- GrPipelineDynamicStateTestOp(ScissorState scissorState, sk_sp<const GrBuffer> vbuff)
+ GrPipelineDynamicStateTestOp(GrScissorTest scissorTest, sk_sp<const GrBuffer> vbuff)
: INHERITED(ClassID())
- , fScissorState(scissorState)
+ , fScissorTest(scissorTest)
, fVertexBuffer(std::move(vbuff)) {
this->setBounds(SkRect::MakeIWH(kScreenSize, kScreenSize),
HasAABloat::kNo, IsZeroArea::kNo);
@@ -139,7 +137,7 @@
void onPrepare(GrOpFlushState*) override {}
void onExecute(GrOpFlushState* state) override {
GrRenderTargetProxy* proxy = state->drawOpArgs().fProxy;
- GrPipeline pipeline(proxy, fScissorState, SkBlendMode::kSrc);
+ GrPipeline pipeline(proxy, fScissorTest, SkBlendMode::kSrc);
SkSTArray<kNumMeshes, GrMesh> meshes;
for (int i = 0; i < kNumMeshes; ++i) {
GrMesh& mesh = meshes.emplace_back(GrPrimitiveType::kTriangleStrip);
@@ -153,7 +151,7 @@
SkRect::MakeIWH(kScreenSize, kScreenSize));
}
- ScissorState fScissorState;
+ GrScissorTest fScissorTest;
const sk_sp<const GrBuffer> fVertexBuffer;
typedef GrDrawOp INHERITED;
@@ -206,17 +204,17 @@
uint32_t resultPx[kScreenSize * kScreenSize];
- for (ScissorState scissorState : {ScissorState::kEnabled, ScissorState::kDisabled}) {
+ for (GrScissorTest scissorTest : {GrScissorTest::kEnabled, GrScissorTest::kDisabled}) {
rtc->clear(nullptr, 0xbaaaaaad, GrRenderTargetContext::CanClearFullscreen::kYes);
rtc->priv().testingOnly_addDrawOp(
- GrPipelineDynamicStateTestOp::Make(context, scissorState, vbuff));
+ GrPipelineDynamicStateTestOp::Make(context, scissorTest, vbuff));
rtc->readPixels(SkImageInfo::Make(kScreenSize, kScreenSize,
kRGBA_8888_SkColorType, kPremul_SkAlphaType),
resultPx, 4 * kScreenSize, 0, 0, 0);
for (int y = 0; y < kScreenSize; ++y) {
for (int x = 0; x < kScreenSize; ++x) {
int expectedColorIdx;
- if (ScissorState::kEnabled == scissorState) {
+ if (GrScissorTest::kEnabled == scissorTest) {
expectedColorIdx = (x < kScreenSplitX ? 0 : 2) + (y < kScreenSplitY ? 0 : 1);
} else {
expectedColorIdx = kNumMeshes - 1;
@@ -225,7 +223,7 @@
uint32_t actual = resultPx[y * kScreenSize + x];
if (expected != actual) {
ERRORF(reporter, "[scissor=%s] pixel (%i,%i): got 0x%x expected 0x%x",
- ScissorState::kEnabled == scissorState ? "enabled" : "disabled", x, y,
+ GrScissorTest::kEnabled == scissorTest ? "enabled" : "disabled", x, y,
actual, expected);
return;
}