Skip to content

Commit

Permalink
Make result of GrOp::combineIfPossible be an enum.
Browse files Browse the repository at this point in the history
This is to prepare for a third value that requests that ops be linked
together so that the first op may do the work for multiple linked ops
without actually merging the GrOp objects.

Change-Id: Ib6e012a89be5edd054aee69d8475bea612331852
Reviewed-on: https://skia-review.googlesource.com/145522
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: Brian Salomon <bsalomon@google.com>
  • Loading branch information
bsalomon authored and Skia Commit-Bot committed Aug 6, 2018
1 parent 986f64c commit 641ac7d
Show file tree
Hide file tree
Showing 46 changed files with 166 additions and 189 deletions.
2 changes: 0 additions & 2 deletions bench/VertexColorSpaceBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ class Op : public GrMeshDrawOp {
private:
friend class ::GrOpMemoryPool;

bool onCombineIfPossible(GrOp*, const GrCaps&) override { return false; }

void onPrepareDraws(Target* target) override {
sk_sp<GrGeometryProcessor> gp(new GP(fMode, fColorSpaceXform));

Expand Down
2 changes: 0 additions & 2 deletions gm/beziereffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class BezierTestOp : public GrMeshDrawOp {
GrColor color() const { return fColor; }

private:
bool onCombineIfPossible(GrOp* op, const GrCaps& caps) override { return false; }

SkRect fRect;
GrColor fColor;
sk_sp<const GrGeometryProcessor> fGeometryProcessor;
Expand Down
1 change: 0 additions & 1 deletion gm/clockwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ class ClockwiseTestOp : public GrDrawOp {
RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) override {
return RequiresDstTexture::kNo;
}
bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override { return false; }
void onPrepare(GrOpFlushState*) override {}
void onExecute(GrOpFlushState* flushState) override {
SkPoint vertices[4] = {
Expand Down
2 changes: 0 additions & 2 deletions gm/convexpolyeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ class PolyBoundsOp : public GrMeshDrawOp {
helper.recordDraw(target, std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState);
}

bool onCombineIfPossible(GrOp* op, const GrCaps& caps) override { return false; }

GrColor fColor;
GrProcessorSet fProcessors;
SkRect fRect;
Expand Down
1 change: 0 additions & 1 deletion samplecode/SampleCCPRGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class CCPRGeometryView::DrawCoverageCountOp : public GrDrawOp {
RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) override {
return RequiresDstTexture::kNo;
}
bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override { return false; }
void onPrepare(GrOpFlushState*) override {}
void onExecute(GrOpFlushState*) override;

Expand Down
2 changes: 1 addition & 1 deletion src/atlastext/SkAtlasTextTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void SkInternalAtlasTextTarget::addDrawOp(const GrClip& clip, std::unique_ptr<Gr
int n = SkTMin(kMaxBatchLookBack, fOps.count());
for (int i = 0; i < n; ++i) {
GrAtlasTextOp* other = fOps.fromBack(i).get();
if (other->combineIfPossible(op.get(), caps)) {
if (other->combineIfPossible(op.get(), caps) == GrOp::CombineResult::kMerged) {
fOpMemoryPool->release(std::move(op));
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/GrRenderTargetOpList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ bool GrRenderTargetOpList::combineIfPossible(const RecordedOp& a, GrOp* b,
} else if (a.fDstProxy.proxy()) {
return false;
}
return a.fOp->combineIfPossible(b, caps);
return a.fOp->combineIfPossible(b, caps) == GrOp::CombineResult::kMerged;
}

uint32_t GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op,
Expand Down
6 changes: 3 additions & 3 deletions src/gpu/ccpr/GrCCDrawPathsOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ GrDrawOp::RequiresDstTexture GrCCDrawPathsOp::finalize(const GrCaps& caps,
return RequiresDstTexture(analysis.requiresDstTexture());
}

bool GrCCDrawPathsOp::onCombineIfPossible(GrOp* op, const GrCaps&) {
GrOp::CombineResult GrCCDrawPathsOp::onCombineIfPossible(GrOp* op, const GrCaps&) {
GrCCDrawPathsOp* that = op->cast<GrCCDrawPathsOp>();
SkASSERT(fOwningPerOpListPaths);
SkASSERT(fNumDraws);
Expand All @@ -126,15 +126,15 @@ bool GrCCDrawPathsOp::onCombineIfPossible(GrOp* op, const GrCaps&) {

if (fProcessors != that->fProcessors ||
fViewMatrixIfUsingLocalCoords != that->fViewMatrixIfUsingLocalCoords) {
return false;
return CombineResult::kCannotCombine;
}

fDraws.append(std::move(that->fDraws), &fOwningPerOpListPaths->fAllocator);
this->joinBounds(*that);

SkDEBUGCODE(fNumDraws += that->fNumDraws);
SkDEBUGCODE(that->fNumDraws = 0);
return true;
return CombineResult::kMerged;
}

void GrCCDrawPathsOp::wasRecorded(GrCCPerOpListPaths* owningPerOpListPaths) {
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/ccpr/GrCCDrawPathsOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GrCCDrawPathsOp : public GrDrawOp {
const char* name() const override { return "GrCCDrawPathsOp"; }
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) override;
bool onCombineIfPossible(GrOp*, const GrCaps&) override;
CombineResult onCombineIfPossible(GrOp*, const GrCaps&) override;
void visitProxies(const VisitProxyFunc& fn) const override { fProcessors.visitProxies(fn); }
void onPrepare(GrOpFlushState*) override {}

Expand Down
4 changes: 2 additions & 2 deletions src/gpu/ccpr/GrCCPerFlushResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class AtlasOp : public GrDrawOp {
RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) override {
return RequiresDstTexture::kNo;
}
bool onCombineIfPossible(GrOp* other, const GrCaps&) override {
CombineResult onCombineIfPossible(GrOp* other, const GrCaps&) override {
SK_ABORT("Only expected one Op per CCPR atlas.");
return true;
return CombineResult::kMerged;
}
void onPrepare(GrOpFlushState*) override {}

Expand Down
10 changes: 5 additions & 5 deletions src/gpu/ops/GrAAConvexPathRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,23 +943,23 @@ class AAConvexPathOp final : public GrMeshDrawOp {
}
}

bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
AAConvexPathOp* that = t->cast<AAConvexPathOp>();
if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
return false;
return CombineResult::kCannotCombine;
}
if (fHelper.usesLocalCoords() &&
!fPaths[0].fViewMatrix.cheapEqualTo(that->fPaths[0].fViewMatrix)) {
return false;
return CombineResult::kCannotCombine;
}

if (fLinesOnly != that->fLinesOnly) {
return false;
return CombineResult::kCannotCombine;
}

fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
this->joinBounds(*that);
return true;
return CombineResult::kMerged;
}

struct PathData {
Expand Down
6 changes: 3 additions & 3 deletions src/gpu/ops/GrAAFillRectOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,16 @@ class AAFillRectOp final : public GrMeshDrawOp {
helper.recordDraw(target, std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState);
}

bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
AAFillRectOp* that = t->cast<AAFillRectOp>();
if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
return false;
return CombineResult::kCannotCombine;
}

fRectData.push_back_n(that->fRectData.count(), that->fRectData.begin());
fRectCnt += that->fRectCnt;
this->joinBounds(*that);
return true;
return CombineResult::kMerged;
}

struct RectInfo {
Expand Down
16 changes: 8 additions & 8 deletions src/gpu/ops/GrAAHairLinePathRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,41 +835,41 @@ class AAHairlineOp final : public GrMeshDrawOp {
typedef SkTArray<int, true> IntArray;
typedef SkTArray<float, true> FloatArray;

bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
AAHairlineOp* that = t->cast<AAHairlineOp>();

if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
return false;
return CombineResult::kCannotCombine;
}

if (this->viewMatrix().hasPerspective() != that->viewMatrix().hasPerspective()) {
return false;
return CombineResult::kCannotCombine;
}

// We go to identity if we don't have perspective
if (this->viewMatrix().hasPerspective() &&
!this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
return false;
return CombineResult::kCannotCombine;
}

// TODO we can actually combine hairlines if they are the same color in a kind of bulk
// method but we haven't implemented this yet
// TODO investigate going to vertex color and coverage?
if (this->coverage() != that->coverage()) {
return false;
return CombineResult::kCannotCombine;
}

if (this->color() != that->color()) {
return false;
return CombineResult::kCannotCombine;
}

if (fHelper.usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
return false;
return CombineResult::kCannotCombine;
}

fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
this->joinBounds(*that);
return true;
return CombineResult::kMerged;
}

GrColor color() const { return fColor; }
Expand Down
6 changes: 3 additions & 3 deletions src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,15 @@ class AAFlatteningConvexPathOp final : public GrMeshDrawOp {
sk_free(indices);
}

bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
AAFlatteningConvexPathOp* that = t->cast<AAFlatteningConvexPathOp>();
if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
return false;
return CombineResult::kCannotCombine;
}

fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
this->joinBounds(*that);
return true;
return CombineResult::kMerged;
}

const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; }
Expand Down
12 changes: 6 additions & 6 deletions src/gpu/ops/GrAAStrokeRectOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class AAStrokeRectOp final : public GrMeshDrawOp {
const SkMatrix& viewMatrix() const { return fViewMatrix; }
bool miterStroke() const { return fMiterStroke; }

bool onCombineIfPossible(GrOp* t, const GrCaps&) override;
CombineResult onCombineIfPossible(GrOp* t, const GrCaps&) override;

void generateAAStrokeRectGeometry(void* vertices,
size_t offset,
Expand Down Expand Up @@ -405,27 +405,27 @@ sk_sp<const GrBuffer> AAStrokeRectOp::GetIndexBuffer(GrResourceProvider* resourc
}
}

bool AAStrokeRectOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
GrOp::CombineResult AAStrokeRectOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
AAStrokeRectOp* that = t->cast<AAStrokeRectOp>();

if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
return false;
return CombineResult::kCannotCombine;
}

// TODO combine across miterstroke changes
if (this->miterStroke() != that->miterStroke()) {
return false;
return CombineResult::kCannotCombine;
}

// We apply the viewmatrix to the rect points on the cpu. However, if the pipeline uses
// local coords then we won't be able to combine. TODO: Upload local coords as an attribute.
if (fHelper.usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
return false;
return CombineResult::kCannotCombine;
}

fRects.push_back_n(that->fRects.count(), that->fRects.begin());
this->joinBounds(*that);
return true;
return CombineResult::kMerged;
}

static void setup_scale(int* scale, SkScalar inset) {
Expand Down
25 changes: 12 additions & 13 deletions src/gpu/ops/GrAtlasTextOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,57 +437,56 @@ void GrAtlasTextOp::flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) co
flushInfo->fGlyphsToFlush = 0;
}

bool GrAtlasTextOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
GrOp::CombineResult GrAtlasTextOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
GrAtlasTextOp* that = t->cast<GrAtlasTextOp>();
if (fProcessors != that->fProcessors) {
return false;
return CombineResult::kCannotCombine;
}

if (!fCanCombineOnTouchOrOverlap && GrRectsTouchOrOverlap(this->bounds(), that->bounds())) {
return false;
return CombineResult::kCannotCombine;
}

if (fMaskType != that->fMaskType) {
return false;
return CombineResult::kCannotCombine;
}

const SkMatrix& thisFirstMatrix = fGeoData[0].fViewMatrix;
const SkMatrix& thatFirstMatrix = that->fGeoData[0].fViewMatrix;

if (this->usesLocalCoords() && !thisFirstMatrix.cheapEqualTo(thatFirstMatrix)) {
return false;
return CombineResult::kCannotCombine;
}

if (fNeedsGlyphTransform != that->fNeedsGlyphTransform) {
return false;
return CombineResult::kCannotCombine;
}

if (fNeedsGlyphTransform &&
(thisFirstMatrix.hasPerspective() != thatFirstMatrix.hasPerspective())) {
return false;
return CombineResult::kCannotCombine;
}

if (this->usesDistanceFields()) {
if (fDFGPFlags != that->fDFGPFlags) {
return false;
return CombineResult::kCannotCombine;
}

if (fLuminanceColor != that->fLuminanceColor) {
return false;
return CombineResult::kCannotCombine;
}
} else {
if (kColorBitmapMask_MaskType == fMaskType && this->color() != that->color()) {
return false;
return CombineResult::kCannotCombine;
}

}

// Keep the batch vertex buffer size below 32K so we don't have to create a special one
// We use the largest possible vertex size for this
static const int kVertexSize = sizeof(SkPoint) + sizeof(SkColor) + 2 * sizeof(uint16_t);
static const int kMaxGlyphs = 32768 / (kVerticesPerGlyph * kVertexSize);
if (this->fNumGlyphs + that->fNumGlyphs > kMaxGlyphs) {
return false;
return CombineResult::kCannotCombine;
}

fNumGlyphs += that->numGlyphs();
Expand Down Expand Up @@ -517,7 +516,7 @@ bool GrAtlasTextOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
fGeoCount = newGeoCount;

this->joinBounds(*that);
return true;
return CombineResult::kMerged;
}

// TODO trying to figure out why lcd is so whack
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/ops/GrAtlasTextOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class GrAtlasTextOp final : public GrMeshDrawOp {
bool usesLocalCoords() const { return fUsesLocalCoords; }
int numGlyphs() const { return fNumGlyphs; }

bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override;
CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override;

sk_sp<GrGeometryProcessor> setupDfProcessor(const sk_sp<GrTextureProxy>* proxies,
unsigned int numActiveProxies) const;
Expand Down
10 changes: 5 additions & 5 deletions src/gpu/ops/GrClearOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ class GrClearOp final : public GrOp {
this->setBounds(SkRect::Make(rect), HasAABloat::kNo, IsZeroArea::kNo);
}

bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
// This could be much more complicated. Currently we look at cases where the new clear
// contains the old clear, or when the new clear is a subset of the old clear and is the
// same color.
GrClearOp* cb = t->cast<GrClearOp>();
if (fClip.windowRectsState() != cb->fClip.windowRectsState()) {
return false;
return CombineResult::kCannotCombine;
}
if (cb->contains(this)) {
fClip = cb->fClip;
this->replaceBounds(*t);
fColor = cb->fColor;
return true;
return CombineResult::kMerged;
} else if (cb->fColor == fColor && this->contains(cb)) {
return true;
return CombineResult::kMerged;
}
return false;
return CombineResult::kCannotCombine;
}

bool contains(const GrClearOp* that) const {
Expand Down
2 changes: 0 additions & 2 deletions src/gpu/ops/GrClearStencilClipOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class GrClearStencilClipOp final : public GrOp {
this->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo);
}

bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { return false; }

void onPrepare(GrOpFlushState*) override {}

void onExecute(GrOpFlushState* state) override;
Expand Down
Loading

0 comments on commit 641ac7d

Please sign in to comment.