diff options
author | 2015-02-11 13:45:50 -0800 | |
---|---|---|
committer | 2015-02-11 13:45:51 -0800 | |
commit | 95964c670b577d5f49c5eab7af277ad987fd0519 (patch) | |
tree | 288d2e73db1b6a37a99bf368eea3604b2f34881b /gm/convexpolyeffect.cpp | |
parent | 2de59391157850b62ab5891aae349b64eb1d8a17 (diff) |
GMs now use batch
BUG=skia:
Committed: https://skia.googlesource.com/skia/+/3f284d7758d7f35b59d93a22d126f7cd8423be44
Review URL: https://codereview.chromium.org/865313004
Diffstat (limited to 'gm/convexpolyeffect.cpp')
-rw-r--r-- | gm/convexpolyeffect.cpp | 105 |
1 files changed, 79 insertions, 26 deletions
diff --git a/gm/convexpolyeffect.cpp b/gm/convexpolyeffect.cpp index 281ddca77e..0a3be28c73 100644 --- a/gm/convexpolyeffect.cpp +++ b/gm/convexpolyeffect.cpp @@ -12,10 +12,13 @@ #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" @@ -24,6 +27,68 @@ #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<SkPoint*>(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. */ @@ -103,6 +168,10 @@ protected: return; } + SkAutoTUnref<const GrGeometryProcessor> gp( + GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType, + 0xff000000)); + SkScalar y = 0; for (SkTLList<SkPath>::Iter iter(fPaths, SkTLList<SkPath>::Iter::kHead_IterStart); iter.get(); @@ -129,25 +198,16 @@ protected: } GrPipelineBuilder pipelineBuilder; - SkAutoTUnref<const GrGeometryProcessor> gp( - GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType, - 0xff000000)); pipelineBuilder.addCoverageProcessor(fp); pipelineBuilder.setRenderTarget(rt); - GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVertexStride(), 0); - SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); - SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices()); + ConvexPolyTestBatch::Geometry geometry; + geometry.fColor = gp->color(); + geometry.fBounds = p.getBounds(); - 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); + SkAutoTUnref<GrBatch> batch(ConvexPolyTestBatch::Create(gp, geometry)); - tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer()); - tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangleFan_GrPrimitiveType, - 0, 0, 4, 6); + tt.target()->drawBatch(&pipelineBuilder, batch, NULL); x += SkScalarCeilToScalar(path->getBounds().width() + 10.f); } @@ -187,23 +247,16 @@ protected: } GrPipelineBuilder pipelineBuilder; - SkAutoTUnref<const GrGeometryProcessor> gp( - GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType, - 0xff000000)); pipelineBuilder.addCoverageProcessor(fp); pipelineBuilder.setRenderTarget(rt); - GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVertexStride(), 0); - SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); - SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices()); + ConvexPolyTestBatch::Geometry geometry; + geometry.fColor = gp->color(); + geometry.fBounds = rect; - SkRect bounds = rect; - bounds.outset(5.f, 5.f); - bounds.toQuad(verts); + SkAutoTUnref<GrBatch> batch(ConvexPolyTestBatch::Create(gp, geometry)); - tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer()); - tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangleFan_GrPrimitiveType, - 0, 0, 4, 6); + tt.target()->drawBatch(&pipelineBuilder, batch, NULL); x += SkScalarCeilToScalar(rect.width() + 10.f); } |