diff options
-rw-r--r-- | gn/gpu.gni | 20 | ||||
-rw-r--r-- | src/gpu/GrBatchTest.cpp | 8 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetContext.cpp | 46 | ||||
-rw-r--r-- | src/gpu/batches/GrDrawAtlasOp.cpp (renamed from src/gpu/batches/GrDrawAtlasBatch.cpp) | 85 | ||||
-rw-r--r-- | src/gpu/batches/GrDrawAtlasOp.h (renamed from src/gpu/batches/GrDrawAtlasBatch.h) | 33 | ||||
-rw-r--r-- | src/gpu/batches/GrDrawPathBatch.h | 3 | ||||
-rw-r--r-- | src/gpu/batches/GrDrawVerticesOp.cpp (renamed from src/gpu/batches/GrDrawVerticesBatch.cpp) | 83 | ||||
-rw-r--r-- | src/gpu/batches/GrDrawVerticesOp.h (renamed from src/gpu/batches/GrDrawVerticesBatch.h) | 46 | ||||
-rw-r--r-- | src/gpu/batches/GrLatticeOp.cpp (renamed from src/gpu/batches/GrNinePatch.cpp) | 47 | ||||
-rw-r--r-- | src/gpu/batches/GrLatticeOp.h | 24 | ||||
-rw-r--r-- | src/gpu/batches/GrNinePatch.h | 26 | ||||
-rw-r--r-- | src/gpu/batches/GrRegionOp.cpp (renamed from src/gpu/batches/GrRegionBatch.cpp) | 46 | ||||
-rw-r--r-- | src/gpu/batches/GrRegionOp.h (renamed from src/gpu/batches/GrRegionBatch.h) | 13 | ||||
-rwxr-xr-x | src/gpu/batches/GrShadowRRectBatch.h | 26 | ||||
-rwxr-xr-x | src/gpu/batches/GrShadowRRectOp.cpp (renamed from src/gpu/batches/GrShadowRRectBatch.cpp) | 406 | ||||
-rwxr-xr-x | src/gpu/batches/GrShadowRRectOp.h | 27 |
16 files changed, 464 insertions, 475 deletions
diff --git a/gn/gpu.gni b/gn/gpu.gni index 12005fb9dc..d514c3d9f3 100644 --- a/gn/gpu.gni +++ b/gn/gpu.gni @@ -252,14 +252,14 @@ skia_gpu_sources = [ "$_src/gpu/batches/GrDefaultPathRenderer.cpp", "$_src/gpu/batches/GrDefaultPathRenderer.h", "$_src/gpu/batches/GrDiscardOp.h", - "$_src/gpu/batches/GrDrawAtlasBatch.cpp", - "$_src/gpu/batches/GrDrawAtlasBatch.h", + "$_src/gpu/batches/GrDrawAtlasOp.cpp", + "$_src/gpu/batches/GrDrawAtlasOp.h", "$_src/gpu/batches/GrDrawOp.cpp", "$_src/gpu/batches/GrDrawOp.h", "$_src/gpu/batches/GrDrawPathBatch.cpp", "$_src/gpu/batches/GrDrawPathBatch.h", - "$_src/gpu/batches/GrDrawVerticesBatch.cpp", - "$_src/gpu/batches/GrDrawVerticesBatch.h", + "$_src/gpu/batches/GrDrawVerticesOp.cpp", + "$_src/gpu/batches/GrDrawVerticesOp.h", "$_src/gpu/batches/GrMSAAPathRenderer.cpp", "$_src/gpu/batches/GrMSAAPathRenderer.h", "$_src/gpu/batches/GrNonAAFillRectOp.h", @@ -267,8 +267,8 @@ skia_gpu_sources = [ "$_src/gpu/batches/GrNonAAFillRectPerspectiveOp.cpp", "$_src/gpu/batches/GrNonAAStrokeRectOp.cpp", "$_src/gpu/batches/GrNonAAStrokeRectOp.h", - "$_src/gpu/batches/GrNinePatch.cpp", - "$_src/gpu/batches/GrNinePatch.h", + "$_src/gpu/batches/GrLatticeOp.cpp", + "$_src/gpu/batches/GrLatticeOp.h", "$_src/gpu/batches/GrOp.cpp", "$_src/gpu/batches/GrOp.h", "$_src/gpu/batches/GrOvalOpFactory.cpp", @@ -277,10 +277,10 @@ skia_gpu_sources = [ "$_src/gpu/batches/GrPLSPathRenderer.h", "$_src/gpu/batches/GrRectOpFactory.h", "$_src/gpu/batches/GrRectOpFactory.cpp", - "$_src/gpu/batches/GrRegionBatch.cpp", - "$_src/gpu/batches/GrRegionBatch.h", - "$_src/gpu/batches/GrShadowRRectBatch.cpp", - "$_src/gpu/batches/GrShadowRRectBatch.h", + "$_src/gpu/batches/GrRegionOp.cpp", + "$_src/gpu/batches/GrRegionOp.h", + "$_src/gpu/batches/GrShadowRRectOp.cpp", + "$_src/gpu/batches/GrShadowRRectOp.h", "$_src/gpu/batches/GrStencilAndCoverPathRenderer.cpp", "$_src/gpu/batches/GrStencilAndCoverPathRenderer.h", "$_src/gpu/batches/GrStencilPathBatch.h", diff --git a/src/gpu/GrBatchTest.cpp b/src/gpu/GrBatchTest.cpp index c09c12c531..8b9227c7aa 100644 --- a/src/gpu/GrBatchTest.cpp +++ b/src/gpu/GrBatchTest.cpp @@ -23,12 +23,12 @@ DRAW_BATCH_TEST_EXTERN(DefaultPathBatch); DRAW_BATCH_TEST_EXTERN(CircleOp); DRAW_BATCH_TEST_EXTERN(DIEllipseOp); DRAW_BATCH_TEST_EXTERN(EllipseOp); -DRAW_BATCH_TEST_EXTERN(GrDrawAtlasBatch); +DRAW_BATCH_TEST_EXTERN(GrDrawAtlasOp); DRAW_BATCH_TEST_EXTERN(NonAAStrokeRectOp); DRAW_BATCH_TEST_EXTERN(RRectOp); DRAW_BATCH_TEST_EXTERN(TesselatingPathBatch); DRAW_BATCH_TEST_EXTERN(TextBlobBatch); -DRAW_BATCH_TEST_EXTERN(VerticesBatch); +DRAW_BATCH_TEST_EXTERN(VerticesOp); static BatchTestFunc gTestBatches[] = { DRAW_BATCH_TEST_ENTRY(AAConvexPathBatch), @@ -43,12 +43,12 @@ static BatchTestFunc gTestBatches[] = { DRAW_BATCH_TEST_ENTRY(CircleOp), DRAW_BATCH_TEST_ENTRY(DIEllipseOp), DRAW_BATCH_TEST_ENTRY(EllipseOp), - DRAW_BATCH_TEST_ENTRY(GrDrawAtlasBatch), + DRAW_BATCH_TEST_ENTRY(GrDrawAtlasOp), DRAW_BATCH_TEST_ENTRY(NonAAStrokeRectOp), DRAW_BATCH_TEST_ENTRY(RRectOp), DRAW_BATCH_TEST_ENTRY(TesselatingPathBatch), DRAW_BATCH_TEST_ENTRY(TextBlobBatch), - DRAW_BATCH_TEST_ENTRY(VerticesBatch) + DRAW_BATCH_TEST_ENTRY(VerticesOp) }; GrDrawOp* GrRandomDrawBatch(SkRandom* random, GrContext* context) { diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index adf9ab1c3e..1ba66acac6 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -20,14 +20,14 @@ #include "SkSurfacePriv.h" #include "batches/GrClearOp.h" -#include "batches/GrDrawAtlasBatch.h" -#include "batches/GrDrawVerticesBatch.h" -#include "batches/GrNinePatch.h" // TODO Factory +#include "batches/GrDrawAtlasOp.h" +#include "batches/GrDrawVerticesOp.h" +#include "batches/GrLatticeOp.h" #include "batches/GrOp.h" #include "batches/GrOvalOpFactory.h" #include "batches/GrRectOpFactory.h" -#include "batches/GrRegionBatch.h" -#include "batches/GrShadowRRectBatch.h" +#include "batches/GrRegionOp.h" +#include "batches/GrShadowRRectOp.h" #include "effects/GrRRectEffect.h" @@ -276,13 +276,12 @@ void GrRenderTargetContextPriv::absClear(const SkIRect* clearRect, const GrColor // This path doesn't handle coalescing of full screen clears b.c. it // has to clear the entire render target - not just the content area. // It could be done but will take more finagling. - sk_sp<GrOp> batch(GrClearOp::Make(rtRect, color, - fRenderTargetContext->accessRenderTarget(), - !clearRect)); - if (!batch) { + sk_sp<GrOp> op(GrClearOp::Make(rtRect, color, fRenderTargetContext->accessRenderTarget(), + !clearRect)); + if (!op) { return; } - fRenderTargetContext->getOpList()->addOp(std::move(batch)); + fRenderTargetContext->getOpList()->addOp(std::move(op)); } } @@ -845,9 +844,9 @@ void GrRenderTargetContext::drawVertices(const GrClip& clip, viewMatrix.mapRect(&bounds); - sk_sp<GrDrawOp> op(new GrDrawVerticesBatch(paint.getColor(), primitiveType, viewMatrix, - positions, vertexCount, indices, indexCount, colors, - texCoords, bounds)); + sk_sp<GrDrawOp> op = + GrDrawVerticesOp::Make(paint.getColor(), primitiveType, viewMatrix, positions, + vertexCount, indices, indexCount, colors, texCoords, bounds); GrPipelineBuilder pipelineBuilder(paint, GrAAType::kNone); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, std::move(op)); @@ -869,9 +868,8 @@ void GrRenderTargetContext::drawAtlas(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - sk_sp<GrDrawOp> op(new GrDrawAtlasBatch(paint.getColor(), viewMatrix, spriteCount, xform, - texRect, colors)); - + sk_sp<GrDrawOp> op = + GrDrawAtlasOp::Make(paint.getColor(), viewMatrix, spriteCount, xform, texRect, colors); GrPipelineBuilder pipelineBuilder(paint, GrAAType::kNone); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, std::move(op)); } @@ -968,12 +966,8 @@ void GrRenderTargetContext::drawShadowRRect(const GrClip& clip, // TODO: add instancing support? const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); - sk_sp<GrDrawOp> op(CreateShadowRRectBatch(paint.getColor(), - viewMatrix, - rrect, - blurRadius, - stroke, - shaderCaps)); + sk_sp<GrDrawOp> op = GrShadowRRectOp::Make(paint.getColor(), viewMatrix, rrect, blurRadius, + stroke, shaderCaps); if (op) { GrPipelineBuilder pipelineBuilder(paint, GrAAType::kNone); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, std::move(op)); @@ -1103,7 +1097,7 @@ void GrRenderTargetContext::drawRegion(const GrClip& clip, GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawRegion"); if (GrAA::kYes == aa) { - // GrRegionBatch performs no antialiasing but is much faster, so here we check the matrix + // GrRegionOp performs no antialiasing but is much faster, so here we check the matrix // to see whether aa is really required. if (!SkToBool(viewMatrix.getType() & ~(SkMatrix::kTranslate_Mask)) && is_int(viewMatrix.getTranslateX()) && @@ -1118,7 +1112,7 @@ void GrRenderTargetContext::drawRegion(const GrClip& clip, return this->drawPath(clip, paint, aa, viewMatrix, path, style); } - sk_sp<GrDrawOp> op(GrRegionBatch::Create(paint.getColor(), viewMatrix, region)); + sk_sp<GrDrawOp> op = GrRegionOp::Make(paint.getColor(), viewMatrix, region); GrPipelineBuilder pipelineBuilder(paint, GrAAType::kNone); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, std::move(op)); } @@ -1220,8 +1214,8 @@ void GrRenderTargetContext::drawImageLattice(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - sk_sp<GrDrawOp> op(GrNinePatch::CreateNonAA(paint.getColor(), viewMatrix, imageWidth, - imageHeight, std::move(iter), dst)); + sk_sp<GrDrawOp> op = GrLatticeOp::MakeNonAA(paint.getColor(), viewMatrix, imageWidth, + imageHeight, std::move(iter), dst); GrPipelineBuilder pipelineBuilder(paint, GrAAType::kNone); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, std::move(op)); diff --git a/src/gpu/batches/GrDrawAtlasBatch.cpp b/src/gpu/batches/GrDrawAtlasOp.cpp index f94dc97435..3dafbda732 100644 --- a/src/gpu/batches/GrDrawAtlasBatch.cpp +++ b/src/gpu/batches/GrDrawAtlasOp.cpp @@ -5,24 +5,24 @@ * found in the LICENSE file. */ -#include "GrDrawAtlasBatch.h" +#include "GrDrawAtlasOp.h" #include "GrBatchTest.h" #include "GrOpFlushState.h" #include "SkGr.h" #include "SkRSXform.h" #include "SkRandom.h" -void GrDrawAtlasBatch::initBatchTracker(const GrXPOverridesForBatch& overrides) { +void GrDrawAtlasOp::initBatchTracker(const GrXPOverridesForBatch& overrides) { SkASSERT(fGeoData.count() == 1); // Handle any color overrides if (!overrides.readsColor()) { fGeoData[0].fColor = GrColor_ILLEGAL; } if (overrides.getOverrideColorIfSet(&fGeoData[0].fColor) && fHasColors) { - size_t vertexStride = sizeof(SkPoint) + sizeof(SkPoint) + - (this->hasColors() ? sizeof(GrColor) : 0); + size_t vertexStride = + sizeof(SkPoint) + sizeof(SkPoint) + (this->hasColors() ? sizeof(GrColor) : 0); uint8_t* currVertex = fGeoData[0].fVerts.begin(); - for (int i = 0; i < 4*fQuadCount; ++i) { + for (int i = 0; i < 4 * fQuadCount; ++i) { *(reinterpret_cast<GrColor*>(currVertex + sizeof(SkPoint))) = fGeoData[0].fColor; currVertex += vertexStride; } @@ -32,7 +32,7 @@ void GrDrawAtlasBatch::initBatchTracker(const GrXPOverridesForBatch& overrides) fColorIgnored = !overrides.readsColor(); fColor = fGeoData[0].fColor; // We'd like to assert this, but we can't because of GLPrograms test - //SkASSERT(init.readsLocalCoords()); + // SkASSERT(init.readsLocalCoords()); fCoverageIgnored = !overrides.readsCoverage(); } @@ -51,17 +51,15 @@ static sk_sp<GrGeometryProcessor> set_vertex_attributes(bool hasColors, return GrDefaultGeoProcFactory::Make(gpColor, coverage, localCoords, viewMatrix); } -void GrDrawAtlasBatch::onPrepareDraws(Target* target) const { +void GrDrawAtlasOp::onPrepareDraws(Target* target) const { // Setup geometry processor - sk_sp<GrGeometryProcessor> gp(set_vertex_attributes(this->hasColors(), - this->color(), - this->viewMatrix(), - this->coverageIgnored())); + sk_sp<GrGeometryProcessor> gp(set_vertex_attributes( + this->hasColors(), this->color(), this->viewMatrix(), this->coverageIgnored())); int instanceCount = fGeoData.count(); size_t vertexStride = gp->getVertexStride(); - SkASSERT(vertexStride == sizeof(SkPoint) + sizeof(SkPoint) - + (this->hasColors() ? sizeof(GrColor) : 0)); + SkASSERT(vertexStride == + sizeof(SkPoint) + sizeof(SkPoint) + (this->hasColors() ? sizeof(GrColor) : 0)); QuadHelper helper; int numQuads = this->quadCount(); @@ -82,9 +80,8 @@ void GrDrawAtlasBatch::onPrepareDraws(Target* target) const { helper.recordDraw(target, gp.get()); } -GrDrawAtlasBatch::GrDrawAtlasBatch(GrColor color, const SkMatrix& viewMatrix, int spriteCount, - const SkRSXform* xforms, const SkRect* rects, - const SkColor* colors) +GrDrawAtlasOp::GrDrawAtlasOp(GrColor color, const SkMatrix& viewMatrix, int spriteCount, + const SkRSXform* xforms, const SkRect* rects, const SkColor* colors) : INHERITED(ClassID()) { SkASSERT(xforms); SkASSERT(rects); @@ -96,7 +93,7 @@ GrDrawAtlasBatch::GrDrawAtlasBatch(GrColor color, const SkMatrix& viewMatrix, in // Figure out stride and offsets // Order within the vertex is: position [color] texCoord size_t texOffset = sizeof(SkPoint); - size_t vertexStride = 2*sizeof(SkPoint); + size_t vertexStride = 2 * sizeof(SkPoint); fHasColors = SkToBool(colors); if (colors) { texOffset += sizeof(GrColor); @@ -105,7 +102,7 @@ GrDrawAtlasBatch::GrDrawAtlasBatch(GrColor color, const SkMatrix& viewMatrix, in // Compute buffer size and alloc buffer fQuadCount = spriteCount; - int allocSize = static_cast<int>(4*vertexStride*spriteCount); + int allocSize = static_cast<int>(4 * vertexStride * spriteCount); installedGeo.fVerts.reset(allocSize); uint8_t* currVertex = installedGeo.fVerts.begin(); @@ -127,34 +124,36 @@ GrDrawAtlasBatch::GrDrawAtlasBatch(GrColor color, const SkMatrix& viewMatrix, in } GrColor grColor = SkColorToPremulGrColor(color); - *(reinterpret_cast<GrColor*>(currVertex+sizeof(SkPoint))) = grColor; - *(reinterpret_cast<GrColor*>(currVertex+vertexStride+sizeof(SkPoint))) = grColor; - *(reinterpret_cast<GrColor*>(currVertex+2*vertexStride+sizeof(SkPoint))) = grColor; - *(reinterpret_cast<GrColor*>(currVertex+3*vertexStride+sizeof(SkPoint))) = grColor; + *(reinterpret_cast<GrColor*>(currVertex + sizeof(SkPoint))) = grColor; + *(reinterpret_cast<GrColor*>(currVertex + vertexStride + sizeof(SkPoint))) = grColor; + *(reinterpret_cast<GrColor*>(currVertex + 2 * vertexStride + sizeof(SkPoint))) = + grColor; + *(reinterpret_cast<GrColor*>(currVertex + 3 * vertexStride + sizeof(SkPoint))) = + grColor; } // Copy position and uv to verts *(reinterpret_cast<SkPoint*>(currVertex)) = quad[0]; - *(reinterpret_cast<SkPoint*>(currVertex+texOffset)) = SkPoint::Make(currRect.fLeft, - currRect.fTop); + *(reinterpret_cast<SkPoint*>(currVertex + texOffset)) = + SkPoint::Make(currRect.fLeft, currRect.fTop); bounds.growToInclude(quad[0].fX, quad[0].fY); currVertex += vertexStride; *(reinterpret_cast<SkPoint*>(currVertex)) = quad[1]; - *(reinterpret_cast<SkPoint*>(currVertex+texOffset)) = SkPoint::Make(currRect.fRight, - currRect.fTop); + *(reinterpret_cast<SkPoint*>(currVertex + texOffset)) = + SkPoint::Make(currRect.fRight, currRect.fTop); bounds.growToInclude(quad[1].fX, quad[1].fY); currVertex += vertexStride; *(reinterpret_cast<SkPoint*>(currVertex)) = quad[2]; - *(reinterpret_cast<SkPoint*>(currVertex+texOffset)) = SkPoint::Make(currRect.fRight, - currRect.fBottom); + *(reinterpret_cast<SkPoint*>(currVertex + texOffset)) = + SkPoint::Make(currRect.fRight, currRect.fBottom); bounds.growToInclude(quad[2].fX, quad[2].fY); currVertex += vertexStride; *(reinterpret_cast<SkPoint*>(currVertex)) = quad[3]; - *(reinterpret_cast<SkPoint*>(currVertex+texOffset)) = SkPoint::Make(currRect.fLeft, - currRect.fBottom); + *(reinterpret_cast<SkPoint*>(currVertex + texOffset)) = + SkPoint::Make(currRect.fLeft, currRect.fBottom); bounds.growToInclude(quad[3].fX, quad[3].fY); currVertex += vertexStride; } @@ -162,15 +161,15 @@ GrDrawAtlasBatch::GrDrawAtlasBatch(GrColor color, const SkMatrix& viewMatrix, in this->setTransformedBounds(bounds, viewMatrix, HasAABloat::kNo, IsZeroArea::kNo); } -bool GrDrawAtlasBatch::onCombineIfPossible(GrOp* t, const GrCaps& caps) { - GrDrawAtlasBatch* that = t->cast<GrDrawAtlasBatch>(); +bool GrDrawAtlasOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { + GrDrawAtlasOp* that = t->cast<GrDrawAtlasOp>(); if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), that->bounds(), caps)) { return false; } - // We currently use a uniform viewmatrix for this batch + // We currently use a uniform viewmatrix for this op. if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { return false; } @@ -224,10 +223,9 @@ static SkRect random_texRect(SkRandom* random) { return texRect; } -static void randomize_params(uint32_t count, SkRandom* random, - SkTArray<SkRSXform>* xforms, - SkTArray<SkRect>* texRects, - SkTArray<GrColor>* colors, bool hasColors) { +static void randomize_params(uint32_t count, SkRandom* random, SkTArray<SkRSXform>* xforms, + SkTArray<SkRect>* texRects, SkTArray<GrColor>* colors, + bool hasColors) { for (uint32_t v = 0; v < count; v++) { xforms->push_back(random_xform(random)); texRects->push_back(random_texRect(random)); @@ -237,7 +235,7 @@ static void randomize_params(uint32_t count, SkRandom* random, } } -DRAW_BATCH_TEST_DEFINE(GrDrawAtlasBatch) { +DRAW_BATCH_TEST_DEFINE(GrDrawAtlasOp) { uint32_t spriteCount = random->nextRangeU(1, 100); SkTArray<SkRSXform> xforms(spriteCount); @@ -246,17 +244,14 @@ DRAW_BATCH_TEST_DEFINE(GrDrawAtlasBatch) { bool hasColors = random->nextBool(); - randomize_params(spriteCount, - random, - &xforms, - &texRects, - &colors, hasColors); + randomize_params(spriteCount, random, &xforms, &texRects, &colors, hasColors); SkMatrix viewMatrix = GrTest::TestMatrix(random); GrColor color = GrRandomColor(random); - return new GrDrawAtlasBatch(color, viewMatrix, spriteCount, xforms.begin(), texRects.begin(), - hasColors ? colors.begin() : nullptr); + return GrDrawAtlasOp::Make(color, viewMatrix, spriteCount, xforms.begin(), texRects.begin(), + hasColors ? colors.begin() : nullptr) + .release(); } #endif diff --git a/src/gpu/batches/GrDrawAtlasBatch.h b/src/gpu/batches/GrDrawAtlasOp.h index 8601a05396..9913ec2906 100644 --- a/src/gpu/batches/GrDrawAtlasBatch.h +++ b/src/gpu/batches/GrDrawAtlasOp.h @@ -5,21 +5,25 @@ * found in the LICENSE file. */ -#ifndef GrDrawAtlasBatch_DEFINED -#define GrDrawAtlasBatch_DEFINED +#ifndef GrDrawAtlasOp_DEFINED +#define GrDrawAtlasOp_DEFINED #include "GrColor.h" #include "GrDefaultGeoProcFactory.h" #include "GrMeshDrawOp.h" -class GrDrawAtlasBatch final : public GrMeshDrawOp { +class GrDrawAtlasOp final : public GrMeshDrawOp { public: DEFINE_OP_CLASS_ID - GrDrawAtlasBatch(GrColor color, const SkMatrix& viewMatrix, int spriteCount, - const SkRSXform* xforms, const SkRect* rects, const SkColor* colors); + static sk_sp<GrDrawOp> Make(GrColor color, const SkMatrix& viewMatrix, int spriteCount, + const SkRSXform* xforms, const SkRect* rects, + const SkColor* colors) { + return sk_sp<GrDrawOp>( + new GrDrawAtlasOp(color, viewMatrix, spriteCount, xforms, rects, colors)); + } - const char* name() const override { return "DrawAtlasBatch"; } + const char* name() const override { return "DrawAtlasOp"; } SkString dumpInfo() const override { SkString string; @@ -34,7 +38,7 @@ public: void computePipelineOptimizations(GrInitInvariantOutput* color, GrInitInvariantOutput* coverage, GrBatchToXPOverrides* overrides) const override { - // When this is called on a batch, there is only one geometry bundle + // When this is called there is only one atlas draw. if (this->hasColors()) { color->setUnknownFourComponents(); } else { @@ -44,6 +48,9 @@ public: } private: + GrDrawAtlasOp(GrColor color, const SkMatrix& viewMatrix, int spriteCount, + const SkRSXform* xforms, const SkRect* rects, const SkColor* colors); + void onPrepareDraws(Target*) const override; void initBatchTracker(const GrXPOverridesForBatch&) override; @@ -58,18 +65,18 @@ private: bool onCombineIfPossible(GrOp* t, const GrCaps&) override; struct Geometry { - GrColor fColor; + GrColor fColor; SkTArray<uint8_t, true> fVerts; }; SkSTArray<1, Geometry, true> fGeoData; SkMatrix fViewMatrix; - GrColor fColor; - int fQuadCount; - bool fColorIgnored; - bool fCoverageIgnored; - bool fHasColors; + GrColor fColor; + int fQuadCount; + bool fColorIgnored; + bool fCoverageIgnored; + bool fHasColors; typedef GrMeshDrawOp INHERITED; }; diff --git a/src/gpu/batches/GrDrawPathBatch.h b/src/gpu/batches/GrDrawPathBatch.h index c6bb55eaee..b110295674 100644 --- a/src/gpu/batches/GrDrawPathBatch.h +++ b/src/gpu/batches/GrDrawPathBatch.h @@ -75,8 +75,7 @@ public: private: GrDrawPathBatch(const SkMatrix& viewMatrix, GrColor color, const GrPath* path) - : INHERITED(ClassID(), viewMatrix, color, path->getFillType()) - , fPath(path) { + : GrDrawPathBatchBase(ClassID(), viewMatrix, color, path->getFillType()), fPath(path) { this->setTransformedBounds(path->getBounds(), viewMatrix, HasAABloat::kNo, IsZeroArea::kNo); } diff --git a/src/gpu/batches/GrDrawVerticesBatch.cpp b/src/gpu/batches/GrDrawVerticesOp.cpp index 3cc69cb964..37be6d0d17 100644 --- a/src/gpu/batches/GrDrawVerticesBatch.cpp +++ b/src/gpu/batches/GrDrawVerticesOp.cpp @@ -5,7 +5,7 @@ * found in the LICENSE file. */ -#include "GrDrawVerticesBatch.h" +#include "GrDrawVerticesOp.h" #include "GrDefaultGeoProcFactory.h" #include "GrInvariantOutput.h" @@ -21,23 +21,22 @@ static sk_sp<GrGeometryProcessor> set_vertex_attributes(bool hasLocalCoords, *colorOffset = -1; Coverage coverage(coverageIgnored ? Coverage::kNone_Type : Coverage::kSolid_Type); - LocalCoords localCoords(hasLocalCoords ? LocalCoords::kHasExplicit_Type : - LocalCoords::kUsePosition_Type); + LocalCoords localCoords(hasLocalCoords ? LocalCoords::kHasExplicit_Type + : LocalCoords::kUsePosition_Type); *colorOffset = sizeof(SkPoint); if (hasLocalCoords) { *texOffset = sizeof(SkPoint) + sizeof(GrColor); } - return GrDefaultGeoProcFactory::Make(Color(Color::kAttribute_Type), - coverage, localCoords, viewMatrix); + return GrDefaultGeoProcFactory::Make(Color(Color::kAttribute_Type), coverage, localCoords, + viewMatrix); } -GrDrawVerticesBatch::GrDrawVerticesBatch(GrColor color, GrPrimitiveType primitiveType, - const SkMatrix& viewMatrix, - const SkPoint* positions, int vertexCount, - const uint16_t* indices, int indexCount, - const GrColor* colors, const SkPoint* localCoords, - const SkRect& bounds) - : INHERITED(ClassID()) { +GrDrawVerticesOp::GrDrawVerticesOp(GrColor color, GrPrimitiveType primitiveType, + const SkMatrix& viewMatrix, const SkPoint* positions, + int vertexCount, const uint16_t* indices, int indexCount, + const GrColor* colors, const SkPoint* localCoords, + const SkRect& bounds) + : INHERITED(ClassID()) { SkASSERT(positions); fViewMatrix = viewMatrix; @@ -72,10 +71,10 @@ GrDrawVerticesBatch::GrDrawVerticesBatch(GrColor color, GrPrimitiveType primitiv this->setBounds(bounds, HasAABloat::kNo, zeroArea); } -void GrDrawVerticesBatch::computePipelineOptimizations(GrInitInvariantOutput* color, - GrInitInvariantOutput* coverage, - GrBatchToXPOverrides* overrides) const { - // When this is called on a batch, there is only one mesh +void GrDrawVerticesOp::computePipelineOptimizations(GrInitInvariantOutput* color, + GrInitInvariantOutput* coverage, + GrBatchToXPOverrides* overrides) const { + // When this is called there is only one mesh. if (fVariableColor) { color->setUnknownFourComponents(); } else { @@ -84,7 +83,7 @@ void GrDrawVerticesBatch::computePipelineOptimizations(GrInitInvariantOutput* co coverage->setKnownSingleComponent(0xff); } -void GrDrawVerticesBatch::initBatchTracker(const GrXPOverridesForBatch& overrides) { +void GrDrawVerticesOp::initBatchTracker(const GrXPOverridesForBatch& overrides) { SkASSERT(fMeshes.count() == 1); GrColor overrideColor; if (overrides.getOverrideColorIfSet(&overrideColor)) { @@ -98,15 +97,15 @@ void GrDrawVerticesBatch::initBatchTracker(const GrXPOverridesForBatch& override } } -void GrDrawVerticesBatch::onPrepareDraws(Target* target) const { +void GrDrawVerticesOp::onPrepareDraws(Target* target) const { bool hasLocalCoords = !fMeshes[0].fLocalCoords.isEmpty(); int colorOffset = -1, texOffset = -1; sk_sp<GrGeometryProcessor> gp(set_vertex_attributes(hasLocalCoords, &colorOffset, &texOffset, fViewMatrix, fCoverageIgnored)); size_t vertexStride = gp->getVertexStride(); - SkASSERT(vertexStride == sizeof(SkPoint) + (hasLocalCoords ? sizeof(SkPoint) : 0) - + sizeof(GrColor)); + SkASSERT(vertexStride == + sizeof(SkPoint) + (hasLocalCoords ? sizeof(SkPoint) : 0) + sizeof(GrColor)); int instanceCount = fMeshes.count(); @@ -162,8 +161,8 @@ void GrDrawVerticesBatch::onPrepareDraws(Target* target) const { GrMesh mesh; if (indices) { - mesh.initIndexed(this->primitiveType(), vertexBuffer, indexBuffer, firstVertex, - firstIndex, fVertexCount, fIndexCount); + mesh.initIndexed(this->primitiveType(), vertexBuffer, indexBuffer, firstVertex, firstIndex, + fVertexCount, fIndexCount); } else { mesh.init(this->primitiveType(), vertexBuffer, firstVertex, fVertexCount); @@ -171,8 +170,8 @@ void GrDrawVerticesBatch::onPrepareDraws(Target* target) const { target->draw(gp.get(), mesh); } -bool GrDrawVerticesBatch::onCombineIfPossible(GrOp* t, const GrCaps& caps) { - GrDrawVerticesBatch* that = t->cast<GrDrawVerticesBatch>(); +bool GrDrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { + GrDrawVerticesOp* that = t->cast<GrDrawVerticesOp>(); if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), that->bounds(), caps)) { @@ -183,7 +182,7 @@ bool GrDrawVerticesBatch::onCombineIfPossible(GrOp* t, const GrCaps& caps) { return false; } - // We currently use a uniform viewmatrix for this batch + // We currently use a uniform viewmatrix for this op. if (!fViewMatrix.cheapEqualTo(that->fViewMatrix)) { return false; } @@ -256,11 +255,10 @@ static SkPoint random_point(SkRandom* random, SkScalar min, SkScalar max) { } static void randomize_params(size_t count, size_t maxVertex, SkScalar min, SkScalar max, - SkRandom* random, - SkTArray<SkPoint>* positions, + SkRandom* random, SkTArray<SkPoint>* positions, SkTArray<SkPoint>* texCoords, bool hasTexCoords, - SkTArray<GrColor>* colors, bool hasColors, - SkTArray<uint16_t>* indices, bool hasIndices) { + SkTArray<GrColor>* colors, bool hasColors, SkTArray<uint16_t>* indices, + bool hasIndices) { for (uint32_t v = 0; v < count; v++) { positions->push_back(random_point(random, min, max)); if (hasTexCoords) { @@ -276,7 +274,7 @@ static void randomize_params(size_t count, size_t maxVertex, SkScalar min, SkSca } } -DRAW_BATCH_TEST_DEFINE(VerticesBatch) { +DRAW_BATCH_TEST_DEFINE(VerticesOp) { GrPrimitiveType type = GrPrimitiveType(random->nextULessThan(kLast_GrPrimitiveType + 1)); uint32_t primitiveCount = random->nextRangeU(1, 100); @@ -294,33 +292,28 @@ DRAW_BATCH_TEST_DEFINE(VerticesBatch) { static const SkScalar kMinVertExtent = -100.f; static const SkScalar kMaxVertExtent = 100.f; - randomize_params(seed_vertices(type), vertexCount, kMinVertExtent, kMaxVertExtent, - random, - &positions, - &texCoords, hasTexCoords, - &colors, hasColors, - &indices, hasIndices); + randomize_params(seed_vertices(type), vertexCount, kMinVertExtent, kMaxVertExtent, random, + &positions, &texCoords, hasTexCoords, &colors, hasColors, &indices, + hasIndices); for (uint32_t i = 1; i < primitiveCount; i++) { randomize_params(primitive_vertices(type), vertexCount, kMinVertExtent, kMaxVertExtent, - random, - &positions, - &texCoords, hasTexCoords, - &colors, hasColors, - &indices, hasIndices); + random, &positions, &texCoords, hasTexCoords, &colors, hasColors, &indices, + hasIndices); } SkMatrix viewMatrix = GrTest::TestMatrix(random); SkRect bounds; - SkDEBUGCODE(bool result = ) bounds.setBoundsCheck(positions.begin(), vertexCount); + SkDEBUGCODE(bool result =) bounds.setBoundsCheck(positions.begin(), vertexCount); SkASSERT(result); viewMatrix.mapRect(&bounds); GrColor color = GrRandomColor(random); - return new GrDrawVerticesBatch(color, type, viewMatrix, positions.begin(), vertexCount, - indices.begin(), hasIndices ? vertexCount : 0, - colors.begin(), texCoords.begin(), bounds); + return GrDrawVerticesOp::Make(color, type, viewMatrix, positions.begin(), vertexCount, + indices.begin(), hasIndices ? vertexCount : 0, colors.begin(), + texCoords.begin(), bounds) + .release(); } #endif diff --git a/src/gpu/batches/GrDrawVerticesBatch.h b/src/gpu/batches/GrDrawVerticesOp.h index 4f1bedea75..7cbf24f951 100644 --- a/src/gpu/batches/GrDrawVerticesBatch.h +++ b/src/gpu/batches/GrDrawVerticesOp.h @@ -5,8 +5,8 @@ * found in the LICENSE file. */ -#ifndef GrDrawVerticesBatch_DEFINED -#define GrDrawVerticesBatch_DEFINED +#ifndef GrDrawVerticesOp_DEFINED +#define GrDrawVerticesOp_DEFINED #include "GrColor.h" #include "GrMeshDrawOp.h" @@ -18,23 +18,26 @@ class GrOpFlushState; struct GrInitInvariantOutput; -class GrDrawVerticesBatch final : public GrMeshDrawOp { +class GrDrawVerticesOp final : public GrMeshDrawOp { public: DEFINE_OP_CLASS_ID + static sk_sp<GrDrawOp> Make(GrColor color, GrPrimitiveType primitiveType, + const SkMatrix& viewMatrix, const SkPoint* positions, + int vertexCount, const uint16_t* indices, int indexCount, + const GrColor* colors, const SkPoint* localCoords, + const SkRect& bounds) { + return sk_sp<GrDrawOp>(new GrDrawVerticesOp(color, primitiveType, viewMatrix, positions, + vertexCount, indices, indexCount, colors, + localCoords, bounds)); + } - GrDrawVerticesBatch(GrColor color, GrPrimitiveType primitiveType, - const SkMatrix& viewMatrix, - const SkPoint* positions, int vertexCount, - const uint16_t* indices, int indexCount, - const GrColor* colors, const SkPoint* localCoords, const SkRect& bounds); - - const char* name() const override { return "DrawVerticesBatch"; } + const char* name() const override { return "DrawVerticesOp"; } SkString dumpInfo() const override { SkString string; - string.appendf("PrimType: %d, VarColor: %d, VCount: %d, ICount: %d\n", - fPrimitiveType, fVariableColor, fVertexCount, fIndexCount); + string.appendf("PrimType: %d, VarColor: %d, VCount: %d, ICount: %d\n", fPrimitiveType, + fVariableColor, fVertexCount, fIndexCount); string.append(DumpPipelineInfo(*this->pipeline())); string.append(INHERITED::dumpInfo()); return string; @@ -45,6 +48,11 @@ public: GrBatchToXPOverrides* overrides) const override; private: + GrDrawVerticesOp(GrColor color, GrPrimitiveType primitiveType, const SkMatrix& viewMatrix, + const SkPoint* positions, int vertexCount, const uint16_t* indices, + int indexCount, const GrColor* colors, const SkPoint* localCoords, + const SkRect& bounds); + void onPrepareDraws(Target*) const override; void initBatchTracker(const GrXPOverridesForBatch&) override; @@ -58,19 +66,19 @@ private: bool onCombineIfPossible(GrOp* t, const GrCaps&) override; struct Mesh { - GrColor fColor; // Only used if there are no per-vertex colors + GrColor fColor; // Only used if there are no per-vertex colors SkTDArray<SkPoint> fPositions; SkTDArray<uint16_t> fIndices; SkTDArray<GrColor> fColors; SkTDArray<SkPoint> fLocalCoords; }; - GrPrimitiveType fPrimitiveType; - SkMatrix fViewMatrix; - bool fVariableColor; - int fVertexCount; - int fIndexCount; - bool fCoverageIgnored; // comes from initBatchTracker. + GrPrimitiveType fPrimitiveType; + SkMatrix fViewMatrix; + bool fVariableColor; + int fVertexCount; + int fIndexCount; + bool fCoverageIgnored; // comes from initBatchTracker. SkSTArray<1, Mesh, true> fMeshes; diff --git a/src/gpu/batches/GrNinePatch.cpp b/src/gpu/batches/GrLatticeOp.cpp index ada74031db..119032209d 100644 --- a/src/gpu/batches/GrNinePatch.cpp +++ b/src/gpu/batches/GrLatticeOp.cpp @@ -5,7 +5,7 @@ * found in the LICENSE file. */ -#include "GrNinePatch.h" +#include "GrLatticeOp.h" #include "GrDefaultGeoProcFactory.h" #include "GrMeshDrawOp.h" @@ -23,16 +23,16 @@ static sk_sp<GrGeometryProcessor> create_gp(bool readsCoverage) { return GrDefaultGeoProcFactory::Make(color, coverage, localCoords, SkMatrix::I()); } -class GrNonAANinePatchBatch final : public GrMeshDrawOp { +class NonAALatticeOp final : public GrMeshDrawOp { public: DEFINE_OP_CLASS_ID static const int kVertsPerRect = 4; static const int kIndicesPerRect = 6; - GrNonAANinePatchBatch(GrColor color, const SkMatrix& viewMatrix, int imageWidth, - int imageHeight, std::unique_ptr<SkLatticeIter> iter, const SkRect &dst) - : INHERITED(ClassID()) { + NonAALatticeOp(GrColor color, const SkMatrix& viewMatrix, int imageWidth, int imageHeight, + std::unique_ptr<SkLatticeIter> iter, const SkRect& dst) + : INHERITED(ClassID()) { Patch& patch = fPatches.push_back(); patch.fViewMatrix = viewMatrix; patch.fColor = color; @@ -46,16 +46,14 @@ public: this->setTransformedBounds(patch.fDst, viewMatrix, HasAABloat::kNo, IsZeroArea::kNo); } - const char* name() const override { return "NonAANinePatchBatch"; } + const char* name() const override { return "NonAALatticeOp"; } SkString dumpInfo() const override { SkString str; for (int i = 0; i < fPatches.count(); ++i) { - str.appendf("%d: Color: 0x%08x Dst [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", - i, - fPatches[i].fColor, - fPatches[i].fDst.fLeft, fPatches[i].fDst.fTop, + str.appendf("%d: Color: 0x%08x Dst [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", i, + fPatches[i].fColor, fPatches[i].fDst.fLeft, fPatches[i].fDst.fTop, fPatches[i].fDst.fRight, fPatches[i].fDst.fBottom); } @@ -89,8 +87,7 @@ private: sk_sp<const GrBuffer> indexBuffer(target->resourceProvider()->refQuadIndexBuffer()); InstancedHelper helper; void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexStride, - indexBuffer.get(), kVertsPerRect, - kIndicesPerRect, numRects); + indexBuffer.get(), kVertsPerRect, kIndicesPerRect, numRects); if (!vertices || !indexBuffer) { SkDebugf("Could not allocate vertices\n"); return; @@ -111,8 +108,8 @@ private: intptr_t patchVerts = verts; while (patch.fIter->next(&srcR, &dstR)) { SkPoint* positions = reinterpret_cast<SkPoint*>(verts); - positions->setRectFan(dstR.fLeft, dstR.fTop, - dstR.fRight, dstR.fBottom, vertexStride); + positions->setRectFan(dstR.fLeft, dstR.fTop, dstR.fRight, dstR.fBottom, + vertexStride); // Setup local coords static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor); @@ -123,7 +120,7 @@ private: GrColor* vertColor = reinterpret_cast<GrColor*>(verts + kColorOffset); for (int j = 0; j < 4; ++j) { *vertColor = patch.fColor; - vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); + vertColor = (GrColor*)((intptr_t)vertColor + vertexStride); } verts += kVertsPerRect * vertexStride; } @@ -131,8 +128,8 @@ private: // If we didn't handle it above, apply the matrix here. if (!isScaleTranslate) { SkPoint* positions = reinterpret_cast<SkPoint*>(patchVerts); - patch.fViewMatrix.mapPointsWithStride(positions, vertexStride, - kVertsPerRect * patch.fIter->numRectsToDraw()); + patch.fViewMatrix.mapPointsWithStride( + positions, vertexStride, kVertsPerRect * patch.fIter->numRectsToDraw()); } } helper.recordDraw(target, gp.get()); @@ -144,7 +141,7 @@ private: } bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { - GrNonAANinePatchBatch* that = t->cast<GrNonAANinePatchBatch>(); + NonAALatticeOp* that = t->cast<NonAALatticeOp>(); if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), that->bounds(), caps)) { return false; @@ -153,8 +150,8 @@ private: SkASSERT(this->fImageWidth == that->fImageWidth && this->fImageHeight == that->fImageHeight); - // In the event of two batches, one who can tweak, one who cannot, we just fall back to - // not tweaking + // In the event of two ops, one who can tweak, one who cannot, we just fall back to not + // tweaking. if (fOverrides.canTweakAlphaForCoverage() && !that->fOverrides.canTweakAlphaForCoverage()) { fOverrides = that->fOverrides; } @@ -179,10 +176,10 @@ private: typedef GrMeshDrawOp INHERITED; }; -namespace GrNinePatch { -GrDrawOp* CreateNonAA(GrColor color, const SkMatrix& viewMatrix, int imageWidth, int imageHeight, - std::unique_ptr<SkLatticeIter> iter, const SkRect& dst) { - return new GrNonAANinePatchBatch(color, viewMatrix, imageWidth, imageHeight, std::move(iter), - dst); +namespace GrLatticeOp { +sk_sp<GrDrawOp> MakeNonAA(GrColor color, const SkMatrix& viewMatrix, int imageWidth, + int imageHeight, std::unique_ptr<SkLatticeIter> iter, const SkRect& dst) { + return sk_sp<GrDrawOp>( + new NonAALatticeOp(color, viewMatrix, imageWidth, imageHeight, std::move(iter), dst)); } }; diff --git a/src/gpu/batches/GrLatticeOp.h b/src/gpu/batches/GrLatticeOp.h new file mode 100644 index 0000000000..2908461a29 --- /dev/null +++ b/src/gpu/batches/GrLatticeOp.h @@ -0,0 +1,24 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GLatticeOp_DEFINED +#define GLatticeOp_DEFINED + +#include "GrColor.h" +#include "SkRefCnt.h" + +class GrDrawOp; +class SkLatticeIter; +class SkMatrix; +struct SkRect; + +namespace GrLatticeOp { +sk_sp<GrDrawOp> MakeNonAA(GrColor color, const SkMatrix& viewMatrix, int imageWidth, + int imageHeight, std::unique_ptr<SkLatticeIter> iter, const SkRect& dst); +}; + +#endif diff --git a/src/gpu/batches/GrNinePatch.h b/src/gpu/batches/GrNinePatch.h deleted file mode 100644 index 94551e811a..0000000000 --- a/src/gpu/batches/GrNinePatch.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrNinePatch_DEFINED -#define GrNinePatch_DEFINED - -#include "GrColor.h" -#include "SkCanvas.h" - -class GrDrawOp; -class SkBitmap; -class SkLatticeIter; -class SkMatrix; -struct SkIRect; -struct SkRect; - -namespace GrNinePatch { -GrDrawOp* CreateNonAA(GrColor color, const SkMatrix& viewMatrix, int imageWidth, int imageHeight, - std::unique_ptr<SkLatticeIter> iter, const SkRect& dst); -}; - -#endif diff --git a/src/gpu/batches/GrRegionBatch.cpp b/src/gpu/batches/GrRegionOp.cpp index 4b5fd38bd4..e98bbf0261 100644 --- a/src/gpu/batches/GrRegionBatch.cpp +++ b/src/gpu/batches/GrRegionOp.cpp @@ -5,7 +5,7 @@ * found in the LICENSE file. */ -#include "GrRegionBatch.h" +#include "GrRegionOp.h" #include "GrDefaultGeoProcFactory.h" #include "GrMeshDrawOp.h" @@ -27,22 +27,22 @@ static sk_sp<GrGeometryProcessor> make_gp(bool readsCoverage, const SkMatrix& vi } static void tesselate_region(intptr_t vertices, - size_t vertexStride, - GrColor color, - const SkRegion& region) { + size_t vertexStride, + GrColor color, + const SkRegion& region) { SkRegion::Iterator iter(region); intptr_t verts = vertices; while (!iter.done()) { SkRect rect = SkRect::Make(iter.rect()); - SkPoint* position = (SkPoint*) verts; + SkPoint* position = (SkPoint*)verts; position->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vertexStride); static const int kColorOffset = sizeof(SkPoint); GrColor* vertColor = reinterpret_cast<GrColor*>(verts + kColorOffset); for (int i = 0; i < kVertsPerInstance; i++) { *vertColor = color; - vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); + vertColor = (GrColor*)((intptr_t)vertColor + vertexStride); } verts += vertexStride * kVertsPerInstance; @@ -50,14 +50,12 @@ static void tesselate_region(intptr_t vertices, } } -class RegionBatch final : public GrMeshDrawOp { +class RegionOp final : public GrMeshDrawOp { public: DEFINE_OP_CLASS_ID - RegionBatch(GrColor color, const SkMatrix& viewMatrix, const SkRegion& region) - : INHERITED(ClassID()) - , fViewMatrix(viewMatrix) - { + RegionOp(GrColor color, const SkMatrix& viewMatrix, const SkRegion& region) + : INHERITED(ClassID()), fViewMatrix(viewMatrix) { RegionInfo& info = fRegions.push_back(); info.fColor = color; info.fRegion = region; @@ -66,15 +64,15 @@ public: this->setTransformedBounds(bounds, viewMatrix, HasAABloat::kNo, IsZeroArea::kNo); } - const char* name() const override { return "GrRegionBatch"; } + const char* name() const override { return "GrRegionOp"; } SkString dumpInfo() const override { SkString str; str.appendf("# batched: %d\n", fRegions.count()); for (int i = 0; i < fRegions.count(); ++i) { const RegionInfo& info = fRegions[i]; - str.appendf("%d: Color: 0x%08x, Region with %d rects\n", - i, info.fColor, info.fRegion.computeRegionComplexity()); + str.appendf("%d: Color: 0x%08x, Region with %d rects\n", i, info.fColor, + info.fRegion.computeRegionComplexity()); } str.append(DumpPipelineInfo(*this->pipeline())); str.append(INHERITED::dumpInfo()); @@ -84,7 +82,7 @@ public: void computePipelineOptimizations(GrInitInvariantOutput* color, GrInitInvariantOutput* coverage, GrBatchToXPOverrides* overrides) const override { - // When this is called on a batch, there is only one region. + // When this is called there is only one region. color->setKnownFourComponents(fRegions[0].fColor); coverage->setKnownSingleComponent(0xff); } @@ -95,7 +93,6 @@ public: } private: - void onPrepareDraws(Target* target) const override { sk_sp<GrGeometryProcessor> gp = make_gp(fOverrides.readsCoverage(), fViewMatrix); if (!gp) { @@ -113,9 +110,9 @@ private: size_t vertexStride = gp->getVertexStride(); sk_sp<const GrBuffer> indexBuffer(target->resourceProvider()->refQuadIndexBuffer()); InstancedHelper helper; - void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexStride, - indexBuffer.get(), kVertsPerInstance, kIndicesPerInstance, - numRects); + void* vertices = + helper.init(target, kTriangles_GrPrimitiveType, vertexStride, indexBuffer.get(), + kVertsPerInstance, kIndicesPerInstance, numRects); if (!vertices || !indexBuffer) { SkDebugf("Could not allocate vertices\n"); return; @@ -131,7 +128,7 @@ private: } bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { - RegionBatch* that = t->cast<RegionBatch>(); + RegionOp* that = t->cast<RegionOp>(); if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), that->bounds(), caps)) { return false; @@ -158,10 +155,9 @@ private: typedef GrMeshDrawOp INHERITED; }; -namespace GrRegionBatch { +namespace GrRegionOp { -GrDrawOp* Create(GrColor color, const SkMatrix& viewMatrix, const SkRegion& region) { - return new RegionBatch(color, viewMatrix, region); +sk_sp<GrDrawOp> Make(GrColor color, const SkMatrix& viewMatrix, const SkRegion& region) { + return sk_sp<GrDrawOp>(new RegionOp(color, viewMatrix, region)); +} } - -}; diff --git a/src/gpu/batches/GrRegionBatch.h b/src/gpu/batches/GrRegionOp.h index b7417e519d..24230604ba 100644 --- a/src/gpu/batches/GrRegionBatch.h +++ b/src/gpu/batches/GrRegionOp.h @@ -5,19 +5,18 @@ * found in the LICENSE file. */ -#ifndef GrRegionBatch_DEFINED -#define GrRegionBatch_DEFINED +#ifndef GrRegionOp_DEFINED +#define GrRegionOp_DEFINED #include "GrColor.h" +#include "SkRefCnt.h" class GrDrawOp; class SkMatrix; class SkRegion; -namespace GrRegionBatch { - -GrDrawOp* Create(GrColor color, const SkMatrix& viewMatrix, const SkRegion& region); - -}; +namespace GrRegionOp { +sk_sp<GrDrawOp> Make(GrColor color, const SkMatrix& viewMatrix, const SkRegion& region); +} #endif diff --git a/src/gpu/batches/GrShadowRRectBatch.h b/src/gpu/batches/GrShadowRRectBatch.h deleted file mode 100755 index 3727e05198..0000000000 --- a/src/gpu/batches/GrShadowRRectBatch.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrShadowRRectBatch_DEFINED -#define GrShadowRRectBatch_DEFINED - -#include "GrColor.h" - -class GrDrawOp; -class GrShaderCaps; -class SkMatrix; -class SkRRect; -class SkStrokeRec; - -GrDrawOp* CreateShadowRRectBatch(GrColor, - const SkMatrix& viewMatrix, - const SkRRect& rrect, - const SkScalar blurRadius, - const SkStrokeRec& stroke, - const GrShaderCaps* shaderCaps); - -#endif diff --git a/src/gpu/batches/GrShadowRRectBatch.cpp b/src/gpu/batches/GrShadowRRectOp.cpp index 35a3da7fdb..e099edb000 100755 --- a/src/gpu/batches/GrShadowRRectBatch.cpp +++ b/src/gpu/batches/GrShadowRRectOp.cpp @@ -5,7 +5,7 @@ * found in the LICENSE file. */ -#include "GrShadowRRectBatch.h" +#include "GrShadowRRectOp.h" #include "GrBatchTest.h" #include "GrOpFlushState.h" @@ -20,24 +20,28 @@ // In the case of a normal fill, we draw geometry for the circle as an octagon. static const uint16_t gFillCircleIndices[] = { - // enter the octagon - 0, 1, 8, 1, 2, 8, - 2, 3, 8, 3, 4, 8, - 4, 5, 8, 5, 6, 8, - 6, 7, 8, 7, 0, 8, + // enter the octagon + // clang-format off + 0, 1, 8, 1, 2, 8, + 2, 3, 8, 3, 4, 8, + 4, 5, 8, 5, 6, 8, + 6, 7, 8, 7, 0, 8, + // clang-format on }; // For stroked circles, we use two nested octagons. static const uint16_t gStrokeCircleIndices[] = { - // enter the octagon - 0, 1, 9, 0, 9, 8, - 1, 2, 10, 1, 10, 9, - 2, 3, 11, 2, 11, 10, - 3, 4, 12, 3, 12, 11, - 4, 5, 13, 4, 13, 12, - 5, 6, 14, 5, 14, 13, - 6, 7, 15, 6, 15, 14, - 7, 0, 8, 7, 8, 15, + // enter the octagon + // clang-format off + 0, 1, 9, 0, 9, 8, + 1, 2, 10, 1, 10, 9, + 2, 3, 11, 2, 11, 10, + 3, 4, 12, 3, 12, 11, + 4, 5, 13, 4, 13, 12, + 5, 6, 14, 5, 14, 13, + 6, 7, 15, 6, 15, 14, + 7, 0, 8, 7, 8, 15, + // clang-format on }; static const int kIndicesPerFillCircle = SK_ARRAY_COUNT(gFillCircleIndices); @@ -59,12 +63,12 @@ static const uint16_t* circle_type_to_indices(bool stroked) { /////////////////////////////////////////////////////////////////////////////// -class ShadowCircleBatch : public GrMeshDrawOp { +class ShadowCircleOp final : public GrMeshDrawOp { public: DEFINE_OP_CLASS_ID - static GrDrawOp* Create(GrColor color, const SkMatrix& viewMatrix, SkPoint center, - SkScalar radius, SkScalar blurRadius, const GrStyle& style) { + static sk_sp<GrDrawOp> Make(GrColor color, const SkMatrix& viewMatrix, SkPoint center, + SkScalar radius, SkScalar blurRadius, const GrStyle& style) { SkASSERT(viewMatrix.isSimilarity()); const SkStrokeRec& stroke = style.strokeRec(); if (style.hasPathEffect()) { @@ -76,8 +80,8 @@ public: radius = viewMatrix.mapRadius(radius); SkScalar strokeWidth = viewMatrix.mapRadius(stroke.getWidth()); - bool isStrokeOnly = SkStrokeRec::kStroke_Style == recStyle || - SkStrokeRec::kHairline_Style == recStyle; + bool isStrokeOnly = + SkStrokeRec::kStroke_Style == recStyle || SkStrokeRec::kHairline_Style == recStyle; bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == recStyle; SkScalar innerRadius = -SK_ScalarHalf; @@ -104,44 +108,37 @@ public: outerRadius += SK_ScalarHalf; innerRadius -= SK_ScalarHalf; bool stroked = isStrokeOnly && innerRadius > 0.0f; - ShadowCircleBatch* batch = new ShadowCircleBatch(); - batch->fViewMatrixIfUsingLocalCoords = viewMatrix; + sk_sp<ShadowCircleOp> op(new ShadowCircleOp()); + op->fViewMatrixIfUsingLocalCoords = viewMatrix; SkRect devBounds = SkRect::MakeLTRB(center.fX - outerRadius, center.fY - outerRadius, center.fX + outerRadius, center.fY + outerRadius); - batch->fGeoData.emplace_back(Geometry{ - color, - outerRadius, - innerRadius, - blurRadius, - devBounds, - stroked - }); + op->fGeoData.emplace_back( + Geometry{color, outerRadius, innerRadius, blurRadius, devBounds, stroked}); // Use the original radius and stroke radius for the bounds so that it does not include the // AA bloat. radius += halfWidth; - batch->setBounds({ center.fX - radius, center.fY - radius, - center.fX + radius, center.fY + radius }, - HasAABloat::kNo, IsZeroArea::kNo); - batch->fVertCount = circle_type_to_vert_count(stroked); - batch->fIndexCount = circle_type_to_index_count(stroked); - return batch; + op->setBounds( + {center.fX - radius, center.fY - radius, center.fX + radius, center.fY + radius}, + HasAABloat::kNo, IsZeroArea::kNo); + op->fVertCount = circle_type_to_vert_count(stroked); + op->fIndexCount = circle_type_to_index_count(stroked); + return std::move(op); } - const char* name() const override { return "ShadowCircleBatch"; } + const char* name() const override { return "ShadowCircleOp"; } SkString dumpInfo() const override { SkString string; for (int i = 0; i < fGeoData.count(); ++i) { - string.appendf("Color: 0x%08x Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f], " - "OuterRad: %.2f, InnerRad: %.2f, BlurRad: %.2f\n", - fGeoData[i].fColor, - fGeoData[i].fDevBounds.fLeft, fGeoData[i].fDevBounds.fTop, - fGeoData[i].fDevBounds.fRight, fGeoData[i].fDevBounds.fBottom, - fGeoData[i].fOuterRadius, fGeoData[i].fInnerRadius, - fGeoData[i].fBlurRadius); + string.appendf( + "Color: 0x%08x Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f], " + "OuterRad: %.2f, InnerRad: %.2f, BlurRad: %.2f\n", + fGeoData[i].fColor, fGeoData[i].fDevBounds.fLeft, fGeoData[i].fDevBounds.fTop, + fGeoData[i].fDevBounds.fRight, fGeoData[i].fDevBounds.fBottom, + fGeoData[i].fOuterRadius, fGeoData[i].fInnerRadius, fGeoData[i].fBlurRadius); } string.append(DumpPipelineInfo(*this->pipeline())); string.append(INHERITED::dumpInfo()); @@ -157,7 +154,7 @@ public: } private: - ShadowCircleBatch() : INHERITED(ClassID()) {} + ShadowCircleOp() : INHERITED(ClassID()) {} void initBatchTracker(const GrXPOverridesForBatch& overrides) override { // Handle any overrides that affect our GP. overrides.getOverrideColorIfSet(&fGeoData[0].fColor); @@ -176,9 +173,9 @@ private: sk_sp<GrGeometryProcessor> gp(GrRRectShadowGeoProc::Make(localMatrix)); struct CircleVertex { - SkPoint fPos; - GrColor fColor; - SkPoint fOffset; + SkPoint fPos; + GrColor fColor; + SkPoint fOffset; SkScalar fOuterRadius; SkScalar fBlurRadius; }; @@ -189,8 +186,8 @@ private: const GrBuffer* vertexBuffer; int firstVertex; - char* vertices = (char*)target->makeVertexSpace(vertexStride, fVertCount, - &vertexBuffer, &firstVertex); + char* vertices = (char*)target->makeVertexSpace(vertexStride, fVertCount, &vertexBuffer, + &firstVertex); if (!vertices) { SkDebugf("Could not allocate vertices\n"); return; @@ -227,52 +224,52 @@ private: innerRadius = innerRadius / outerRadius; SkPoint center = SkPoint::Make(bounds.centerX(), bounds.centerY()); - SkScalar halfWidth = 0.5f*bounds.width(); + SkScalar halfWidth = 0.5f * bounds.width(); SkScalar octOffset = 0.41421356237f; // sqrt(2) - 1 - ov0->fPos = center + SkPoint::Make(-octOffset*halfWidth, -halfWidth); + ov0->fPos = center + SkPoint::Make(-octOffset * halfWidth, -halfWidth); ov0->fColor = color; ov0->fOffset = SkPoint::Make(-octOffset, -1); ov0->fOuterRadius = outerRadius; ov0->fBlurRadius = blurRadius; - ov1->fPos = center + SkPoint::Make(octOffset*halfWidth, -halfWidth); + ov1->fPos = center + SkPoint::Make(octOffset * halfWidth, -halfWidth); ov1->fColor = color; ov1->fOffset = SkPoint::Make(octOffset, -1); ov1->fOuterRadius = outerRadius; ov1->fBlurRadius = blurRadius; - ov2->fPos = center + SkPoint::Make(halfWidth, -octOffset*halfWidth); + ov2->fPos = center + SkPoint::Make(halfWidth, -octOffset * halfWidth); ov2->fColor = color; ov2->fOffset = SkPoint::Make(1, -octOffset); ov2->fOuterRadius = outerRadius; ov2->fBlurRadius = blurRadius; - ov3->fPos = center + SkPoint::Make(halfWidth, octOffset*halfWidth); + ov3->fPos = center + SkPoint::Make(halfWidth, octOffset * halfWidth); ov3->fColor = color; ov3->fOffset = SkPoint::Make(1, octOffset); ov3->fOuterRadius = outerRadius; ov3->fBlurRadius = blurRadius; - ov4->fPos = center + SkPoint::Make(octOffset*halfWidth, halfWidth); + ov4->fPos = center + SkPoint::Make(octOffset * halfWidth, halfWidth); ov4->fColor = color; ov4->fOffset = SkPoint::Make(octOffset, 1); ov4->fOuterRadius = outerRadius; ov4->fBlurRadius = blurRadius; - ov5->fPos = center + SkPoint::Make(-octOffset*halfWidth, halfWidth); + ov5->fPos = center + SkPoint::Make(-octOffset * halfWidth, halfWidth); ov5->fColor = color; ov5->fOffset = SkPoint::Make(-octOffset, 1); ov5->fOuterRadius = outerRadius; ov5->fBlurRadius = blurRadius; - ov6->fPos = center + SkPoint::Make(-halfWidth, octOffset*halfWidth); + ov6->fPos = center + SkPoint::Make(-halfWidth, octOffset * halfWidth); ov6->fColor = color; ov6->fOffset = SkPoint::Make(-1, octOffset); ov6->fOuterRadius = outerRadius; ov6->fBlurRadius = blurRadius; - ov7->fPos = center + SkPoint::Make(-halfWidth, -octOffset*halfWidth); + ov7->fPos = center + SkPoint::Make(-halfWidth, -octOffset * halfWidth); ov7->fColor = color; ov7->fOffset = SkPoint::Make(-1, -octOffset); ov7->fOuterRadius = outerRadius; @@ -294,51 +291,51 @@ private: SkScalar s = 0.382683432f; SkScalar r = geom.fInnerRadius; - iv0->fPos = center + SkPoint::Make(-s*r, -c*r); + iv0->fPos = center + SkPoint::Make(-s * r, -c * r); iv0->fColor = color; - iv0->fOffset = SkPoint::Make(-s*innerRadius, -c*innerRadius); + iv0->fOffset = SkPoint::Make(-s * innerRadius, -c * innerRadius); iv0->fOuterRadius = outerRadius; iv0->fBlurRadius = blurRadius; - iv1->fPos = center + SkPoint::Make(s*r, -c*r); + iv1->fPos = center + SkPoint::Make(s * r, -c * r); iv1->fColor = color; - iv1->fOffset = SkPoint::Make(s*innerRadius, -c*innerRadius); + iv1->fOffset = SkPoint::Make(s * innerRadius, -c * innerRadius); iv1->fOuterRadius = outerRadius; iv1->fBlurRadius = blurRadius; - iv2->fPos = center + SkPoint::Make(c*r, -s*r); + iv2->fPos = center + SkPoint::Make(c * r, -s * r); iv2->fColor = color; - iv2->fOffset = SkPoint::Make(c*innerRadius, -s*innerRadius); + iv2->fOffset = SkPoint::Make(c * innerRadius, -s * innerRadius); iv2->fOuterRadius = outerRadius; iv2->fBlurRadius = blurRadius; - iv3->fPos = center + SkPoint::Make(c*r, s*r); + iv3->fPos = center + SkPoint::Make(c * r, s * r); iv3->fColor = color; - iv3->fOffset = SkPoint::Make(c*innerRadius, s*innerRadius); + iv3->fOffset = SkPoint::Make(c * innerRadius, s * innerRadius); iv3->fOuterRadius = outerRadius; iv3->fBlurRadius = blurRadius; - iv4->fPos = center + SkPoint::Make(s*r, c*r); + iv4->fPos = center + SkPoint::Make(s * r, c * r); iv4->fColor = color; - iv4->fOffset = SkPoint::Make(s*innerRadius, c*innerRadius); + iv4->fOffset = SkPoint::Make(s * innerRadius, c * innerRadius); iv4->fOuterRadius = outerRadius; iv4->fBlurRadius = blurRadius; - iv5->fPos = center + SkPoint::Make(-s*r, c*r); + iv5->fPos = center + SkPoint::Make(-s * r, c * r); iv5->fColor = color; - iv5->fOffset = SkPoint::Make(-s*innerRadius, c*innerRadius); + iv5->fOffset = SkPoint::Make(-s * innerRadius, c * innerRadius); iv5->fOuterRadius = outerRadius; iv5->fBlurRadius = blurRadius; - iv6->fPos = center + SkPoint::Make(-c*r, s*r); + iv6->fPos = center + SkPoint::Make(-c * r, s * r); iv6->fColor = color; - iv6->fOffset = SkPoint::Make(-c*innerRadius, s*innerRadius); + iv6->fOffset = SkPoint::Make(-c * innerRadius, s * innerRadius); iv6->fOuterRadius = outerRadius; iv6->fBlurRadius = blurRadius; - iv7->fPos = center + SkPoint::Make(-c*r, -s*r); + iv7->fPos = center + SkPoint::Make(-c * r, -s * r); iv7->fColor = color; - iv7->fOffset = SkPoint::Make(-c*innerRadius, -s*innerRadius); + iv7->fOffset = SkPoint::Make(-c * innerRadius, -s * innerRadius); iv7->fOuterRadius = outerRadius; iv7->fBlurRadius = blurRadius; } else { @@ -358,7 +355,7 @@ private: } currStartVertex += circle_type_to_vert_count(geom.fStroked); - vertices += circle_type_to_vert_count(geom.fStroked)*vertexStride; + vertices += circle_type_to_vert_count(geom.fStroked) * vertexStride; } GrMesh mesh; @@ -368,7 +365,7 @@ private: } bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { - ShadowCircleBatch* that = t->cast<ShadowCircleBatch>(); + ShadowCircleOp* that = t->cast<ShadowCircleOp>(); if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), that->bounds(), caps)) { return false; @@ -386,18 +383,18 @@ private: } struct Geometry { - GrColor fColor; + GrColor fColor; SkScalar fOuterRadius; SkScalar fInnerRadius; SkScalar fBlurRadius; - SkRect fDevBounds; - bool fStroked; + SkRect fDevBounds; + bool fStroked; }; SkSTArray<1, Geometry, true> fGeoData; - SkMatrix fViewMatrixIfUsingLocalCoords; - int fVertCount; - int fIndexCount; + SkMatrix fViewMatrixIfUsingLocalCoords; + int fVertCount; + int fIndexCount; typedef GrMeshDrawOp INHERITED; }; @@ -430,24 +427,26 @@ private: // (either a point or a horizontal or vertical line). static const uint16_t gOverstrokeRRectIndices[] = { - // corners - 0, 1, 5, 0, 5, 4, - 2, 3, 7, 2, 7, 6, - 8, 9, 13, 8, 13, 12, - 10, 11, 15, 10, 15, 14, - - // edges - 1, 2, 6, 1, 6, 5, - 4, 5, 9, 4, 9, 8, - 6, 7, 11, 6, 11, 10, - 9, 10, 14, 9, 14, 13, - - // overstroke quads - // we place this at the end so that we can skip these indices when rendering as stroked - 16, 17, 19, 16, 19, 18, - 19, 17, 23, 19, 23, 21, - 21, 23, 22, 21, 22, 20, - 22, 16, 18, 22, 18, 20, + // clang-format off + // corners + 0, 1, 5, 0, 5, 4, + 2, 3, 7, 2, 7, 6, + 8, 9, 13, 8, 13, 12, + 10, 11, 15, 10, 15, 14, + + // edges + 1, 2, 6, 1, 6, 5, + 4, 5, 9, 4, 9, 8, + 6, 7, 11, 6, 11, 10, + 9, 10, 14, 9, 14, 13, + + // overstroke quads + // we place this at the end so that we can skip these indices when rendering as stroked + 16, 17, 19, 16, 19, 18, + 19, 17, 23, 19, 23, 21, + 21, 23, 22, 21, 22, 20, + 22, 16, 18, 22, 18, 20, + // clang-format on }; // standard stroke indices start at the same place, but will skip the overstroke "ring" static const uint16_t* gStrokeRRectIndices = gOverstrokeRRectIndices; @@ -466,33 +465,42 @@ enum RRectType { }; static int rrect_type_to_vert_count(RRectType type) { - static const int kTypeToVertCount[] = { - kVertsPerOverstrokeRRect, - kVertsPerStrokeRRect, - kVertsPerOverstrokeRRect, - }; - - return kTypeToVertCount[type]; + switch (type) { + case kFill_RRectType: + return kVertsPerOverstrokeRRect; + case kStroke_RRectType: + return kVertsPerStrokeRRect; + case kOverstroke_RRectType: + return kVertsPerOverstrokeRRect; + } + SkFAIL("Invalid type"); + return 0; } static int rrect_type_to_index_count(RRectType type) { - static const int kTypeToIndexCount[] = { - kIndicesPerOverstrokeRRect, - kIndicesPerStrokeRRect, - kIndicesPerOverstrokeRRect, - }; - - return kTypeToIndexCount[type]; + switch (type) { + case kFill_RRectType: + return kIndicesPerOverstrokeRRect; + case kStroke_RRectType: + return kIndicesPerStrokeRRect; + case kOverstroke_RRectType: + return kIndicesPerOverstrokeRRect; + } + SkFAIL("Invalid type"); + return 0; } static const uint16_t* rrect_type_to_indices(RRectType type) { - static const uint16_t* kTypeToIndices[] = { - gOverstrokeRRectIndices, - gStrokeRRectIndices, - gOverstrokeRRectIndices, - }; - - return kTypeToIndices[type]; + switch (type) { + case kFill_RRectType: + return gOverstrokeRRectIndices; + case kStroke_RRectType: + return gStrokeRRectIndices; + case kOverstroke_RRectType: + return gOverstrokeRRectIndices; + } + SkFAIL("Invalid type"); + return nullptr; } // For distance computations in the interior of filled rrects we: @@ -504,17 +512,15 @@ static const uint16_t* rrect_type_to_indices(RRectType type) { // each vertex is also given the normalized x & y distance from the interior rect's edge // the GP takes the min of those depths +1 to get the normalized distance to the outer edge -class ShadowCircularRRectBatch final : public GrMeshDrawOp { +class ShadowCircularRRectOp final : public GrMeshDrawOp { public: DEFINE_OP_CLASS_ID // A devStrokeWidth <= 0 indicates a fill only. If devStrokeWidth > 0 then strokeOnly indicates // whether the rrect is only stroked or stroked and filled. - ShadowCircularRRectBatch(GrColor color, const SkMatrix& viewMatrix, - const SkRect& devRect, float devRadius, float blurRadius, - float devStrokeWidth, bool strokeOnly) - : INHERITED(ClassID()) - , fViewMatrixIfUsingLocalCoords(viewMatrix) { + ShadowCircularRRectOp(GrColor color, const SkMatrix& viewMatrix, const SkRect& devRect, + float devRadius, float blurRadius, float devStrokeWidth, bool strokeOnly) + : INHERITED(ClassID()), fViewMatrixIfUsingLocalCoords(viewMatrix) { SkRect bounds = devRect; SkASSERT(!(devStrokeWidth <= 0 && strokeOnly)); SkScalar innerRadius = 0.0f; @@ -533,8 +539,7 @@ public: devStrokeWidth += 0.25f; // If stroke is greater than width or height, this is still a fill // Otherwise we compute stroke params - if (devStrokeWidth <= devRect.width() && - devStrokeWidth <= devRect.height()) { + if (devStrokeWidth <= devRect.width() && devStrokeWidth <= devRect.height()) { innerRadius = devRadius - halfWidth; type = (innerRadius >= 0) ? kStroke_RRectType : kOverstroke_RRectType; } @@ -562,18 +567,17 @@ public: fIndexCount = rrect_type_to_index_count(type); } - const char* name() const override { return "ShadowCircularRRectBatch"; } + const char* name() const override { return "ShadowCircularRRectOp"; } SkString dumpInfo() const override { SkString string; for (int i = 0; i < fGeoData.count(); ++i) { - string.appendf("Color: 0x%08x Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]," - "OuterRad: %.2f, InnerRad: %.2f, BlurRad: %.2f\n", - fGeoData[i].fColor, - fGeoData[i].fDevBounds.fLeft, fGeoData[i].fDevBounds.fTop, - fGeoData[i].fDevBounds.fRight, fGeoData[i].fDevBounds.fBottom, - fGeoData[i].fOuterRadius, fGeoData[i].fInnerRadius, - fGeoData[i].fBlurRadius); + string.appendf( + "Color: 0x%08x Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]," + "OuterRad: %.2f, InnerRad: %.2f, BlurRad: %.2f\n", + fGeoData[i].fColor, fGeoData[i].fDevBounds.fLeft, fGeoData[i].fDevBounds.fTop, + fGeoData[i].fDevBounds.fRight, fGeoData[i].fDevBounds.fBottom, + fGeoData[i].fOuterRadius, fGeoData[i].fInnerRadius, fGeoData[i].fBlurRadius); } string.append(DumpPipelineInfo(*this->pipeline())); string.append(INHERITED::dumpInfo()); @@ -598,16 +602,16 @@ private: } struct CircleVertex { - SkPoint fPos; - GrColor fColor; - SkPoint fOffset; + SkPoint fPos; + GrColor fColor; + SkPoint fOffset; SkScalar fOuterRadius; SkScalar fBlurRadius; }; - static void FillInOverstrokeVerts(CircleVertex** verts, const SkRect& bounds, - SkScalar smInset, SkScalar bigInset, SkScalar xOffset, - SkScalar outerRadius, GrColor color, SkScalar blurRadius) { + static void FillInOverstrokeVerts(CircleVertex** verts, const SkRect& bounds, SkScalar smInset, + SkScalar bigInset, SkScalar xOffset, SkScalar outerRadius, + GrColor color, SkScalar blurRadius) { SkASSERT(smInset < bigInset); // TL @@ -712,14 +716,10 @@ private: const SkRect& bounds = args.fDevBounds; - SkScalar yCoords[4] = { - bounds.fTop, - bounds.fTop + outerRadius, - bounds.fBottom - outerRadius, - bounds.fBottom - }; + SkScalar yCoords[4] = {bounds.fTop, bounds.fTop + outerRadius, + bounds.fBottom - outerRadius, bounds.fBottom}; - SkScalar yOuterRadii[4] = { -1, 0, 0, 1 }; + SkScalar yOuterRadii[4] = {-1, 0, 0, 1}; // The inner radius in the vertex data must be specified in normalized space. // For fills, specifying -1/outerRadius guarantees an alpha of 1.0 at the inner radius. SkScalar blurRadius = args.fBlurRadius; @@ -768,8 +768,8 @@ private: // geometry to the outer edge SkScalar maxOffset = -args.fInnerRadius / overstrokeOuterRadius; - FillInOverstrokeVerts(&verts, bounds, outerRadius, overstrokeOuterRadius, - maxOffset, overstrokeOuterRadius, color, blurRadius); + FillInOverstrokeVerts(&verts, bounds, outerRadius, overstrokeOuterRadius, maxOffset, + overstrokeOuterRadius, color, blurRadius); } if (kFill_RRectType == args.fType) { @@ -777,8 +777,8 @@ private: SkScalar xOffset = 1.0f - outerRadius / halfMinDim; - FillInOverstrokeVerts(&verts, bounds, outerRadius, halfMinDim, - xOffset, halfMinDim, color, blurRadius); + FillInOverstrokeVerts(&verts, bounds, outerRadius, halfMinDim, xOffset, halfMinDim, + color, blurRadius); } const uint16_t* primIndices = rrect_type_to_indices(args.fType); @@ -797,7 +797,7 @@ private: } bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { - ShadowCircularRRectBatch* that = t->cast<ShadowCircularRRectBatch>(); + ShadowCircularRRectOp* that = t->cast<ShadowCircularRRectOp>(); if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), that->bounds(), caps)) { return false; @@ -815,7 +815,7 @@ private: } struct Geometry { - GrColor fColor; + GrColor fColor; SkScalar fOuterRadius; SkScalar fInnerRadius; SkScalar fBlurRadius; @@ -824,34 +824,34 @@ private: }; SkSTArray<1, Geometry, true> fGeoData; - SkMatrix fViewMatrixIfUsingLocalCoords; - int fVertCount; - int fIndexCount; + SkMatrix fViewMatrixIfUsingLocalCoords; + int fVertCount; + int fIndexCount; typedef GrMeshDrawOp INHERITED; }; /////////////////////////////////////////////////////////////////////////////// -static GrDrawOp* create_shadow_circle_batch(GrColor color, - const SkMatrix& viewMatrix, - const SkRect& oval, - SkScalar blurRadius, - const SkStrokeRec& stroke, - const GrShaderCaps* shaderCaps) { +sk_sp<GrDrawOp> make_shadow_circle_batch(GrColor color, + const SkMatrix& viewMatrix, + const SkRect& oval, + SkScalar blurRadius, + const SkStrokeRec& stroke, + const GrShaderCaps* shaderCaps) { // we can only draw circles SkScalar width = oval.width(); SkASSERT(SkScalarNearlyEqual(width, oval.height()) && viewMatrix.isSimilarity()); - SkPoint center = { oval.centerX(), oval.centerY() }; - return ShadowCircleBatch::Create(color, viewMatrix, center, width / 2.f, - blurRadius, GrStyle(stroke, nullptr)); + SkPoint center = {oval.centerX(), oval.centerY()}; + return ShadowCircleOp::Make(color, viewMatrix, center, width / 2.f, blurRadius, + GrStyle(stroke, nullptr)); } -static GrDrawOp* create_shadow_rrect_batch(GrColor color, - const SkMatrix& viewMatrix, - const SkRRect& rrect, - SkScalar blurRadius, - const SkStrokeRec& stroke) { +static sk_sp<GrDrawOp> make_shadow_rrect_batch(GrColor color, + const SkMatrix& viewMatrix, + const SkRRect& rrect, + SkScalar blurRadius, + const SkStrokeRec& stroke) { SkASSERT(viewMatrix.rectStaysRect()); SkASSERT(rrect.isSimple()); SkASSERT(!rrect.isOval()); @@ -872,21 +872,21 @@ static GrDrawOp* create_shadow_rrect_batch(GrColor color, SkStrokeRec::Style style = stroke.getStyle(); // Do (potentially) anisotropic mapping of stroke. Use -1s to indicate fill-only draws. - SkVector scaledStroke = { -1, -1 }; + SkVector scaledStroke = {-1, -1}; SkScalar strokeWidth = stroke.getWidth(); - bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || - SkStrokeRec::kHairline_Style == style; + bool isStrokeOnly = + SkStrokeRec::kStroke_Style == style || SkStrokeRec::kHairline_Style == style; bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style; if (hasStroke) { if (SkStrokeRec::kHairline_Style == style) { scaledStroke.set(1, 1); } else { - scaledStroke.fX = SkScalarAbs(strokeWidth*(viewMatrix[SkMatrix::kMScaleX] + - viewMatrix[SkMatrix::kMSkewY])); - scaledStroke.fY = SkScalarAbs(strokeWidth*(viewMatrix[SkMatrix::kMSkewX] + - viewMatrix[SkMatrix::kMScaleY])); + scaledStroke.fX = SkScalarAbs( + strokeWidth * (viewMatrix[SkMatrix::kMScaleX] + viewMatrix[SkMatrix::kMSkewY])); + scaledStroke.fY = SkScalarAbs( + strokeWidth * (viewMatrix[SkMatrix::kMSkewX] + viewMatrix[SkMatrix::kMScaleY])); } // we don't handle anisotropic strokes @@ -904,33 +904,34 @@ static GrDrawOp* create_shadow_rrect_batch(GrColor color, return nullptr; } - return new ShadowCircularRRectBatch(color, viewMatrix, bounds, xRadius, - blurRadius, scaledStroke.fX, isStrokeOnly); + return sk_sp<GrDrawOp>(new ShadowCircularRRectOp(color, viewMatrix, bounds, xRadius, blurRadius, + scaledStroke.fX, isStrokeOnly)); } -GrDrawOp* CreateShadowRRectBatch(GrColor color, - const SkMatrix& viewMatrix, - const SkRRect& rrect, - const SkScalar blurRadius, - const SkStrokeRec& stroke, - const GrShaderCaps* shaderCaps) { +namespace GrShadowRRectOp { +sk_sp<GrDrawOp> Make(GrColor color, + const SkMatrix& viewMatrix, + const SkRRect& rrect, + const SkScalar blurRadius, + const SkStrokeRec& stroke, + const GrShaderCaps* shaderCaps) { if (rrect.isOval()) { - return create_shadow_circle_batch(color, viewMatrix, rrect.getBounds(), - blurRadius, stroke, shaderCaps); + return make_shadow_circle_batch(color, viewMatrix, rrect.getBounds(), blurRadius, stroke, + shaderCaps); } if (!viewMatrix.rectStaysRect() || !rrect.isSimple()) { return nullptr; } - return create_shadow_rrect_batch(color, viewMatrix, rrect, blurRadius, stroke); + return make_shadow_rrect_batch(color, viewMatrix, rrect, blurRadius, stroke); +} } - /////////////////////////////////////////////////////////////////////////////// #ifdef GR_TEST_UTILS -DRAW_BATCH_TEST_DEFINE(ShadowCircleBatch) { +DRAW_BATCH_TEST_DEFINE(ShadowCircleOp) { do { SkScalar rotate = random->nextSScalar1() * 360.f; SkScalar translateX = random->nextSScalar1() * 1000.f; @@ -942,25 +943,26 @@ DRAW_BATCH_TEST_DEFINE(ShadowCircleBatch) { viewMatrix.postScale(scale, scale); GrColor color = GrRandomColor(random); SkRect circle = GrTest::TestSquare(random); - SkPoint center = { circle.centerX(), circle.centerY() }; + SkPoint center = {circle.centerX(), circle.centerY()}; SkScalar radius = circle.width() / 2.f; SkStrokeRec stroke = GrTest::TestStrokeRec(random); SkScalar blurRadius = random->nextSScalar1() * 72.f; - GrDrawOp* batch = ShadowCircleBatch::Create(color, viewMatrix, center, radius, - blurRadius, GrStyle(stroke, nullptr)); - if (batch) { - return batch; + sk_sp<GrDrawOp> op = ShadowCircleOp::Make(color, viewMatrix, center, radius, blurRadius, + GrStyle(stroke, nullptr)); + if (op) { + return op.release(); } } while (true); } -DRAW_BATCH_TEST_DEFINE(ShadowRRectBatch) { +DRAW_BATCH_TEST_DEFINE(ShadowRRectOp) { SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); GrColor color = GrRandomColor(random); const SkRRect& rrect = GrTest::TestRRectSimple(random); SkScalar blurRadius = random->nextSScalar1() * 72.f; - return create_shadow_rrect_batch(color, viewMatrix, rrect, - blurRadius, GrTest::TestStrokeRec(random)); + return make_shadow_rrect_batch(color, viewMatrix, rrect, blurRadius, + GrTest::TestStrokeRec(random)) + .release(); } #endif diff --git a/src/gpu/batches/GrShadowRRectOp.h b/src/gpu/batches/GrShadowRRectOp.h new file mode 100755 index 0000000000..3508cb8fab --- /dev/null +++ b/src/gpu/batches/GrShadowRRectOp.h @@ -0,0 +1,27 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrShadowRRectOp_DEFINED +#define GrShadowRRectOp_DEFINED + +#include "GrColor.h" +#include "SkRefCnt.h" + +class GrDrawOp; +class GrShaderCaps; +class SkMatrix; +class SkRRect; +class SkStrokeRec; + +namespace GrShadowRRectOp { + +sk_sp<GrDrawOp> Make(GrColor, const SkMatrix& viewMatrix, const SkRRect& rrect, + const SkScalar blurRadius, const SkStrokeRec& stroke, + const GrShaderCaps* shaderCaps); +} + +#endif |