diff --git a/gm/beziereffects.cpp b/gm/beziereffects.cpp index 578a597ce5..0ddcc52b95 100644 --- a/gm/beziereffects.cpp +++ b/gm/beziereffects.cpp @@ -12,12 +12,9 @@ #if SK_SUPPORT_GPU -#include "GrBatchTarget.h" -#include "GrBufferAllocPool.h" #include "GrContext.h" #include "GrPathUtils.h" #include "GrTest.h" -#include "GrTestBatch.h" #include "SkColorPriv.h" #include "SkDevice.h" #include "SkGeometry.h" @@ -29,86 +26,6 @@ static inline SkScalar eval_line(const SkPoint& p, const SkScalar lineEq[3], SkS } namespace skiagm { - -class BezierCubicOrConicTestBatch : public GrTestBatch { -public: - struct Geometry : public GrTestBatch::Geometry { - SkRect fBounds; - }; - - const char* name() const SK_OVERRIDE { return "BezierCubicOrConicTestBatch"; } - - static GrBatch* Create(const GrGeometryProcessor* gp, const Geometry& geo, - const SkScalar klmEqs[9], SkScalar sign) { - return SkNEW_ARGS(BezierCubicOrConicTestBatch, (gp, geo, klmEqs, sign)); - } - -private: - BezierCubicOrConicTestBatch(const GrGeometryProcessor* gp, const Geometry& geo, - const SkScalar klmEqs[9], SkScalar sign) - : INHERITED(gp) { - for (int i = 0; i < 9; i++) { - fKlmEqs[i] = klmEqs[i]; - } - - fGeometry = geo; - fSign = sign; - } - - struct Vertex { - SkPoint fPosition; - float fKLM[4]; // The last value is ignored. The effect expects a vec4f. - }; - - Geometry* geoData(int index) SK_OVERRIDE { - SkASSERT(0 == index); - return &fGeometry; - } - - void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) SK_OVERRIDE { - size_t vertexStride = this->geometryProcessor()->getVertexStride(); - - const GrVertexBuffer* vertexBuffer; - int firstVertex; - - void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, - kVertsPerCubic, - &vertexBuffer, - &firstVertex); - - SkASSERT(vertexStride == sizeof(Vertex)); - Vertex* verts = reinterpret_cast(vertices); - - verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds.fTop, - fGeometry.fBounds.fRight, fGeometry.fBounds.fBottom, - sizeof(Vertex)); - for (int v = 0; v < 4; ++v) { - verts[v].fKLM[0] = eval_line(verts[v].fPosition, fKlmEqs + 0, fSign); - verts[v].fKLM[1] = eval_line(verts[v].fPosition, fKlmEqs + 3, fSign); - verts[v].fKLM[2] = eval_line(verts[v].fPosition, fKlmEqs + 6, 1.f); - } - - GrDrawTarget::DrawInfo drawInfo; - drawInfo.setPrimitiveType(kTriangleFan_GrPrimitiveType); - drawInfo.setVertexBuffer(vertexBuffer); - drawInfo.setStartVertex(firstVertex); - drawInfo.setVertexCount(kVertsPerCubic); - drawInfo.setStartIndex(0); - drawInfo.setIndexCount(kIndicesPerCubic); - drawInfo.setIndexBuffer(batchTarget->quadIndexBuffer()); - batchTarget->draw(drawInfo); - } - - Geometry fGeometry; - SkScalar fKlmEqs[9]; - SkScalar fSign; - - static const int kVertsPerCubic = 4; - static const int kIndicesPerCubic = 6; - - typedef GrTestBatch INHERITED; -}; - /** * This GM directly exercises effects that draw Bezier curves in the GPU backend. */ @@ -127,6 +44,7 @@ protected: return SkISize::Make(800, 800); } + void onDraw(SkCanvas* canvas) SK_OVERRIDE { GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget(); if (NULL == rt) { @@ -229,16 +147,25 @@ protected: SkASSERT(tt.target()); GrPipelineBuilder pipelineBuilder; + + GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVertexStride(), 0); + SkASSERT(gp->getVertexStride() == sizeof(Vertex)); + Vertex* verts = reinterpret_cast(geo.vertices()); + + verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, + bounds.fRight, bounds.fBottom, + sizeof(Vertex)); + for (int v = 0; v < 4; ++v) { + verts[v].fKLM[0] = eval_line(verts[v].fPosition, klmEqs + 0, klmSigns[c]); + verts[v].fKLM[1] = eval_line(verts[v].fPosition, klmEqs + 3, klmSigns[c]); + verts[v].fKLM[2] = eval_line(verts[v].fPosition, klmEqs + 6, 1.f); + } + pipelineBuilder.setRenderTarget(rt); - BezierCubicOrConicTestBatch::Geometry geometry; - geometry.fColor = gp->color(); - geometry.fBounds = bounds; - - SkAutoTUnref batch(BezierCubicOrConicTestBatch::Create(gp, geometry, klmEqs, - klmSigns[c])); - - tt.target()->drawBatch(&pipelineBuilder, batch, NULL); + tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer()); + tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangleFan_GrPrimitiveType, + 0, 0,4,6); } ++col; if (numCols == col) { @@ -373,16 +300,25 @@ protected: SkASSERT(tt.target()); GrPipelineBuilder pipelineBuilder; + + GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVertexStride(), 0); + SkASSERT(gp->getVertexStride() == sizeof(Vertex)); + Vertex* verts = reinterpret_cast(geo.vertices()); + + verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, + bounds.fRight, bounds.fBottom, + sizeof(Vertex)); + for (int v = 0; v < 4; ++v) { + verts[v].fKLM[0] = eval_line(verts[v].fPosition, klmEqs + 0, 1.f); + verts[v].fKLM[1] = eval_line(verts[v].fPosition, klmEqs + 3, 1.f); + verts[v].fKLM[2] = eval_line(verts[v].fPosition, klmEqs + 6, 1.f); + } + pipelineBuilder.setRenderTarget(rt); - BezierCubicOrConicTestBatch::Geometry geometry; - geometry.fColor = gp->color(); - geometry.fBounds = bounds; - - SkAutoTUnref batch(BezierCubicOrConicTestBatch::Create(gp, geometry, klmEqs, - 1.f)); - - tt.target()->drawBatch(&pipelineBuilder, batch, NULL); + tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer()); + tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangleFan_GrPrimitiveType, + 0, 0,4,6); } ++col; if (numCols == col) { @@ -435,79 +371,6 @@ private: }; ////////////////////////////////////////////////////////////////////////////// - -class BezierQuadTestBatch : public GrTestBatch { -public: - struct Geometry : public GrTestBatch::Geometry { - SkRect fBounds; - }; - - const char* name() const SK_OVERRIDE { return "BezierQuadTestBatch"; } - - static GrBatch* Create(const GrGeometryProcessor* gp, const Geometry& geo, - const GrPathUtils::QuadUVMatrix& devToUV) { - return SkNEW_ARGS(BezierQuadTestBatch, (gp, geo, devToUV)); - } - -private: - BezierQuadTestBatch(const GrGeometryProcessor* gp, const Geometry& geo, - const GrPathUtils::QuadUVMatrix& devToUV) - : INHERITED(gp) - , fGeometry(geo) - , fDevToUV(devToUV) { - } - - struct Vertex { - SkPoint fPosition; - float fKLM[4]; // The last value is ignored. The effect expects a vec4f. - }; - - Geometry* geoData(int index) SK_OVERRIDE { - SkASSERT(0 == index); - return &fGeometry; - } - - void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) SK_OVERRIDE { - size_t vertexStride = this->geometryProcessor()->getVertexStride(); - - const GrVertexBuffer* vertexBuffer; - int firstVertex; - - void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, - kVertsPerCubic, - &vertexBuffer, - &firstVertex); - - SkASSERT(vertexStride == sizeof(Vertex)); - Vertex* verts = reinterpret_cast(vertices); - - verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds.fTop, - fGeometry.fBounds.fRight, fGeometry.fBounds.fBottom, - sizeof(Vertex)); - - fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts); - - - GrDrawTarget::DrawInfo drawInfo; - drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); - drawInfo.setVertexBuffer(vertexBuffer); - drawInfo.setStartVertex(firstVertex); - drawInfo.setVertexCount(kVertsPerCubic); - drawInfo.setStartIndex(0); - drawInfo.setIndexCount(kIndicesPerCubic); - drawInfo.setIndexBuffer(batchTarget->quadIndexBuffer()); - batchTarget->draw(drawInfo); - } - - Geometry fGeometry; - GrPathUtils::QuadUVMatrix fDevToUV; - - static const int kVertsPerCubic = 4; - static const int kIndicesPerCubic = 6; - - typedef GrTestBatch INHERITED; -}; - /** * This GM directly exercises effects that draw Bezier quad curves in the GPU backend. */ @@ -621,17 +484,23 @@ protected: SkASSERT(tt.target()); GrPipelineBuilder pipelineBuilder; - pipelineBuilder.setRenderTarget(rt); + + GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVertexStride(), 0); + SkASSERT(gp->getVertexStride() == sizeof(Vertex)); + Vertex* verts = reinterpret_cast(geo.vertices()); + + verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, + bounds.fRight, bounds.fBottom, + sizeof(Vertex)); GrPathUtils::QuadUVMatrix DevToUV(pts); + DevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts); - BezierQuadTestBatch::Geometry geometry; - geometry.fColor = gp->color(); - geometry.fBounds = bounds; + pipelineBuilder.setRenderTarget(rt); - SkAutoTUnref batch(BezierQuadTestBatch::Create(gp, geometry, DevToUV)); - - tt.target()->drawBatch(&pipelineBuilder, batch, NULL); + tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer()); + tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangles_GrPrimitiveType, + 0, 0, 4, 6); } ++col; if (numCols == col) { diff --git a/gm/convexpolyeffect.cpp b/gm/convexpolyeffect.cpp index 0a3be28c73..281ddca77e 100644 --- a/gm/convexpolyeffect.cpp +++ b/gm/convexpolyeffect.cpp @@ -12,13 +12,10 @@ #if SK_SUPPORT_GPU -#include "GrBatchTarget.h" -#include "GrBufferAllocPool.h" #include "GrContext.h" #include "GrDefaultGeoProcFactory.h" #include "GrPathUtils.h" #include "GrTest.h" -#include "GrTestBatch.h" #include "SkColorPriv.h" #include "SkDevice.h" #include "SkGeometry.h" @@ -27,68 +24,6 @@ #include "effects/GrConvexPolyEffect.h" namespace skiagm { - -class ConvexPolyTestBatch : public GrTestBatch { -public: - struct Geometry : public GrTestBatch::Geometry { - SkRect fBounds; - }; - - const char* name() const SK_OVERRIDE { return "ConvexPolyTestBatch"; } - - static GrBatch* Create(const GrGeometryProcessor* gp, const Geometry& geo) { - return SkNEW_ARGS(ConvexPolyTestBatch, (gp, geo)); - } - -private: - ConvexPolyTestBatch(const GrGeometryProcessor* gp, const Geometry& geo) - : INHERITED(gp) - , fGeometry(geo) { - } - - Geometry* geoData(int index) SK_OVERRIDE { - SkASSERT(0 == index); - return &fGeometry; - } - - void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) SK_OVERRIDE { - size_t vertexStride = this->geometryProcessor()->getVertexStride(); - - const GrVertexBuffer* vertexBuffer; - int firstVertex; - - void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, - kVertsPerCubic, - &vertexBuffer, - &firstVertex); - - SkASSERT(vertexStride == sizeof(SkPoint)); - SkPoint* verts = reinterpret_cast(vertices); - - // Make sure any artifacts around the exterior of path are visible by using overly - // conservative bounding geometry. - fGeometry.fBounds.outset(5.f, 5.f); - fGeometry.fBounds.toQuad(verts); - - GrDrawTarget::DrawInfo drawInfo; - drawInfo.setPrimitiveType(kTriangleFan_GrPrimitiveType); - drawInfo.setVertexBuffer(vertexBuffer); - drawInfo.setStartVertex(firstVertex); - drawInfo.setVertexCount(kVertsPerCubic); - drawInfo.setStartIndex(0); - drawInfo.setIndexCount(kIndicesPerCubic); - drawInfo.setIndexBuffer(batchTarget->quadIndexBuffer()); - batchTarget->draw(drawInfo); - } - - Geometry fGeometry; - - static const int kVertsPerCubic = 4; - static const int kIndicesPerCubic = 6; - - typedef GrTestBatch INHERITED; -}; - /** * This GM directly exercises a GrProcessor that draws convex polygons. */ @@ -168,10 +103,6 @@ protected: return; } - SkAutoTUnref gp( - GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType, - 0xff000000)); - SkScalar y = 0; for (SkTLList::Iter iter(fPaths, SkTLList::Iter::kHead_IterStart); iter.get(); @@ -198,16 +129,25 @@ protected: } GrPipelineBuilder pipelineBuilder; + SkAutoTUnref gp( + GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType, + 0xff000000)); pipelineBuilder.addCoverageProcessor(fp); pipelineBuilder.setRenderTarget(rt); - ConvexPolyTestBatch::Geometry geometry; - geometry.fColor = gp->color(); - geometry.fBounds = p.getBounds(); + GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVertexStride(), 0); + SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); + SkPoint* verts = reinterpret_cast(geo.vertices()); - SkAutoTUnref batch(ConvexPolyTestBatch::Create(gp, geometry)); + SkRect bounds = p.getBounds(); + // Make sure any artifacts around the exterior of path are visible by using overly + // conservative bounding geometry. + bounds.outset(5.f, 5.f); + bounds.toQuad(verts); - tt.target()->drawBatch(&pipelineBuilder, batch, NULL); + tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer()); + tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangleFan_GrPrimitiveType, + 0, 0, 4, 6); x += SkScalarCeilToScalar(path->getBounds().width() + 10.f); } @@ -247,16 +187,23 @@ protected: } GrPipelineBuilder pipelineBuilder; + SkAutoTUnref gp( + GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType, + 0xff000000)); pipelineBuilder.addCoverageProcessor(fp); pipelineBuilder.setRenderTarget(rt); - ConvexPolyTestBatch::Geometry geometry; - geometry.fColor = gp->color(); - geometry.fBounds = rect; + GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVertexStride(), 0); + SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); + SkPoint* verts = reinterpret_cast(geo.vertices()); - SkAutoTUnref batch(ConvexPolyTestBatch::Create(gp, geometry)); + SkRect bounds = rect; + bounds.outset(5.f, 5.f); + bounds.toQuad(verts); - tt.target()->drawBatch(&pipelineBuilder, batch, NULL); + tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer()); + tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangleFan_GrPrimitiveType, + 0, 0, 4, 6); x += SkScalarCeilToScalar(rect.width() + 10.f); } diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi index 45bd303da9..a285ee6aa3 100644 --- a/gyp/gmslides.gypi +++ b/gyp/gmslides.gypi @@ -217,7 +217,6 @@ '../gm/yuvtorgbeffect.cpp', # Files needed by particular GMs - '../src/gpu/GrTestBatch.h', '../src/utils/debugger/SkDrawCommand.h', '../src/utils/debugger/SkDrawCommand.cpp', '../src/utils/debugger/SkDebugCanvas.h', diff --git a/src/gpu/GrTestBatch.h b/src/gpu/GrTestBatch.h deleted file mode 100644 index ab294ff28f..0000000000 --- a/src/gpu/GrTestBatch.h +++ /dev/null @@ -1,94 +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 GrTestBatch_DEFINED -#define GrTestBatch_DEFINED - -#include "GrBatch.h" - -/* - * A simple batch only for testing purposes which actually doesn't batch at all, but can fit into - * the batch pipeline and generate arbitrary geometry - */ -class GrTestBatch : public GrBatch { -public: - struct Geometry { - GrColor fColor; - }; - - virtual const char* name() const SK_OVERRIDE = 0; - - void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE { - // When this is called on a batch, there is only one geometry bundle - out->setUnknownFourComponents(); - } - - void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRIDE { - out->setUnknownSingleComponent(); - } - - void initBatchOpt(const GrBatchOpt& batchOpt) {} - - void initBatchTracker(const GrPipelineInfo& init) SK_OVERRIDE { - // Handle any color overrides - if (init.fColorIgnored) { - this->geoData(0)->fColor = GrColor_ILLEGAL; - } else if (GrColor_ILLEGAL != init.fOverrideColor) { - this->geoData(0)->fColor = init.fOverrideColor; - } - - // setup batch properties - fBatch.fColorIgnored = init.fColorIgnored; - fBatch.fColor = this->geoData(0)->fColor; - fBatch.fUsesLocalCoords = init.fUsesLocalCoords; - fBatch.fCoverageIgnored = init.fCoverageIgnored; - } - - void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) SK_OVERRIDE { - batchTarget->initDraw(fGeometryProcessor, pipeline); - - // TODO this is hacky, but the only way we have to initialize the GP is to use the - // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch - // everywhere we can remove this nastiness - GrPipelineInfo init; - init.fColorIgnored = fBatch.fColorIgnored; - init.fOverrideColor = GrColor_ILLEGAL; - init.fCoverageIgnored = fBatch.fCoverageIgnored; - init.fUsesLocalCoords = fBatch.fUsesLocalCoords; - fGeometryProcessor->initBatchTracker(batchTarget->currentBatchTracker(), init); - - this->onGenerateGeometry(batchTarget, pipeline); - } - -protected: - GrTestBatch(const GrGeometryProcessor* gp) { - fGeometryProcessor.reset(SkRef(gp)); - } - - const GrGeometryProcessor* geometryProcessor() const { return fGeometryProcessor; } - -private: - virtual Geometry* geoData(int index) = 0; - - bool onCombineIfPossible(GrBatch* t) SK_OVERRIDE { - return false; - } - - virtual void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) = 0; - - struct BatchTracker { - GrColor fColor; - bool fUsesLocalCoords; - bool fColorIgnored; - bool fCoverageIgnored; - }; - - SkAutoTUnref fGeometryProcessor; - BatchTracker fBatch; -}; - -#endif