GMs now use batch
BUG=skia: Review URL: https://codereview.chromium.org/865313004
This commit is contained in:
parent
9491f7ff31
commit
3f284d7758
@ -12,9 +12,12 @@
|
|||||||
|
|
||||||
#if SK_SUPPORT_GPU
|
#if SK_SUPPORT_GPU
|
||||||
|
|
||||||
|
#include "GrBatchTarget.h"
|
||||||
|
#include "GrBufferAllocPool.h"
|
||||||
#include "GrContext.h"
|
#include "GrContext.h"
|
||||||
#include "GrPathUtils.h"
|
#include "GrPathUtils.h"
|
||||||
#include "GrTest.h"
|
#include "GrTest.h"
|
||||||
|
#include "GrTestBatch.h"
|
||||||
#include "SkColorPriv.h"
|
#include "SkColorPriv.h"
|
||||||
#include "SkDevice.h"
|
#include "SkDevice.h"
|
||||||
#include "SkGeometry.h"
|
#include "SkGeometry.h"
|
||||||
@ -26,6 +29,86 @@ static inline SkScalar eval_line(const SkPoint& p, const SkScalar lineEq[3], SkS
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace skiagm {
|
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<Vertex*>(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.
|
* This GM directly exercises effects that draw Bezier curves in the GPU backend.
|
||||||
*/
|
*/
|
||||||
@ -44,7 +127,6 @@ protected:
|
|||||||
return SkISize::Make(800, 800);
|
return SkISize::Make(800, 800);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
||||||
GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget();
|
GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget();
|
||||||
if (NULL == rt) {
|
if (NULL == rt) {
|
||||||
@ -147,25 +229,16 @@ protected:
|
|||||||
SkASSERT(tt.target());
|
SkASSERT(tt.target());
|
||||||
|
|
||||||
GrPipelineBuilder pipelineBuilder;
|
GrPipelineBuilder pipelineBuilder;
|
||||||
|
|
||||||
GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVertexStride(), 0);
|
|
||||||
SkASSERT(gp->getVertexStride() == sizeof(Vertex));
|
|
||||||
Vertex* verts = reinterpret_cast<Vertex*>(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);
|
pipelineBuilder.setRenderTarget(rt);
|
||||||
|
|
||||||
tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer());
|
BezierCubicOrConicTestBatch::Geometry geometry;
|
||||||
tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangleFan_GrPrimitiveType,
|
geometry.fColor = gp->color();
|
||||||
0, 0,4,6);
|
geometry.fBounds = bounds;
|
||||||
|
|
||||||
|
SkAutoTUnref<GrBatch> batch(BezierCubicOrConicTestBatch::Create(gp, geometry, klmEqs,
|
||||||
|
klmSigns[c]));
|
||||||
|
|
||||||
|
tt.target()->drawBatch(&pipelineBuilder, batch, NULL);
|
||||||
}
|
}
|
||||||
++col;
|
++col;
|
||||||
if (numCols == col) {
|
if (numCols == col) {
|
||||||
@ -300,25 +373,16 @@ protected:
|
|||||||
SkASSERT(tt.target());
|
SkASSERT(tt.target());
|
||||||
|
|
||||||
GrPipelineBuilder pipelineBuilder;
|
GrPipelineBuilder pipelineBuilder;
|
||||||
|
|
||||||
GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVertexStride(), 0);
|
|
||||||
SkASSERT(gp->getVertexStride() == sizeof(Vertex));
|
|
||||||
Vertex* verts = reinterpret_cast<Vertex*>(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);
|
pipelineBuilder.setRenderTarget(rt);
|
||||||
|
|
||||||
tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer());
|
BezierCubicOrConicTestBatch::Geometry geometry;
|
||||||
tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangleFan_GrPrimitiveType,
|
geometry.fColor = gp->color();
|
||||||
0, 0,4,6);
|
geometry.fBounds = bounds;
|
||||||
|
|
||||||
|
SkAutoTUnref<GrBatch> batch(BezierCubicOrConicTestBatch::Create(gp, geometry, klmEqs,
|
||||||
|
1.f));
|
||||||
|
|
||||||
|
tt.target()->drawBatch(&pipelineBuilder, batch, NULL);
|
||||||
}
|
}
|
||||||
++col;
|
++col;
|
||||||
if (numCols == col) {
|
if (numCols == col) {
|
||||||
@ -371,6 +435,79 @@ 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<Vertex*>(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.
|
* This GM directly exercises effects that draw Bezier quad curves in the GPU backend.
|
||||||
*/
|
*/
|
||||||
@ -484,23 +621,17 @@ protected:
|
|||||||
SkASSERT(tt.target());
|
SkASSERT(tt.target());
|
||||||
|
|
||||||
GrPipelineBuilder pipelineBuilder;
|
GrPipelineBuilder pipelineBuilder;
|
||||||
|
|
||||||
GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVertexStride(), 0);
|
|
||||||
SkASSERT(gp->getVertexStride() == sizeof(Vertex));
|
|
||||||
Vertex* verts = reinterpret_cast<Vertex*>(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);
|
|
||||||
|
|
||||||
pipelineBuilder.setRenderTarget(rt);
|
pipelineBuilder.setRenderTarget(rt);
|
||||||
|
|
||||||
tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer());
|
GrPathUtils::QuadUVMatrix DevToUV(pts);
|
||||||
tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangles_GrPrimitiveType,
|
|
||||||
0, 0, 4, 6);
|
BezierQuadTestBatch::Geometry geometry;
|
||||||
|
geometry.fColor = gp->color();
|
||||||
|
geometry.fBounds = bounds;
|
||||||
|
|
||||||
|
SkAutoTUnref<GrBatch> batch(BezierQuadTestBatch::Create(gp, geometry, DevToUV));
|
||||||
|
|
||||||
|
tt.target()->drawBatch(&pipelineBuilder, batch, NULL);
|
||||||
}
|
}
|
||||||
++col;
|
++col;
|
||||||
if (numCols == col) {
|
if (numCols == col) {
|
||||||
|
@ -12,10 +12,13 @@
|
|||||||
|
|
||||||
#if SK_SUPPORT_GPU
|
#if SK_SUPPORT_GPU
|
||||||
|
|
||||||
|
#include "GrBatchTarget.h"
|
||||||
|
#include "GrBufferAllocPool.h"
|
||||||
#include "GrContext.h"
|
#include "GrContext.h"
|
||||||
#include "GrDefaultGeoProcFactory.h"
|
#include "GrDefaultGeoProcFactory.h"
|
||||||
#include "GrPathUtils.h"
|
#include "GrPathUtils.h"
|
||||||
#include "GrTest.h"
|
#include "GrTest.h"
|
||||||
|
#include "GrTestBatch.h"
|
||||||
#include "SkColorPriv.h"
|
#include "SkColorPriv.h"
|
||||||
#include "SkDevice.h"
|
#include "SkDevice.h"
|
||||||
#include "SkGeometry.h"
|
#include "SkGeometry.h"
|
||||||
@ -24,6 +27,68 @@
|
|||||||
#include "effects/GrConvexPolyEffect.h"
|
#include "effects/GrConvexPolyEffect.h"
|
||||||
|
|
||||||
namespace skiagm {
|
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.
|
* This GM directly exercises a GrProcessor that draws convex polygons.
|
||||||
*/
|
*/
|
||||||
@ -103,6 +168,10 @@ protected:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SkAutoTUnref<const GrGeometryProcessor> gp(
|
||||||
|
GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType,
|
||||||
|
0xff000000));
|
||||||
|
|
||||||
SkScalar y = 0;
|
SkScalar y = 0;
|
||||||
for (SkTLList<SkPath>::Iter iter(fPaths, SkTLList<SkPath>::Iter::kHead_IterStart);
|
for (SkTLList<SkPath>::Iter iter(fPaths, SkTLList<SkPath>::Iter::kHead_IterStart);
|
||||||
iter.get();
|
iter.get();
|
||||||
@ -129,25 +198,16 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
GrPipelineBuilder pipelineBuilder;
|
GrPipelineBuilder pipelineBuilder;
|
||||||
SkAutoTUnref<const GrGeometryProcessor> gp(
|
|
||||||
GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType,
|
|
||||||
0xff000000));
|
|
||||||
pipelineBuilder.addCoverageProcessor(fp);
|
pipelineBuilder.addCoverageProcessor(fp);
|
||||||
pipelineBuilder.setRenderTarget(rt);
|
pipelineBuilder.setRenderTarget(rt);
|
||||||
|
|
||||||
GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVertexStride(), 0);
|
ConvexPolyTestBatch::Geometry geometry;
|
||||||
SkASSERT(gp->getVertexStride() == sizeof(SkPoint));
|
geometry.fColor = gp->color();
|
||||||
SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices());
|
geometry.fBounds = p.getBounds();
|
||||||
|
|
||||||
SkRect bounds = p.getBounds();
|
SkAutoTUnref<GrBatch> batch(ConvexPolyTestBatch::Create(gp, geometry));
|
||||||
// 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()->setIndexSourceToBuffer(context->getQuadIndexBuffer());
|
tt.target()->drawBatch(&pipelineBuilder, batch, NULL);
|
||||||
tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangleFan_GrPrimitiveType,
|
|
||||||
0, 0, 4, 6);
|
|
||||||
|
|
||||||
x += SkScalarCeilToScalar(path->getBounds().width() + 10.f);
|
x += SkScalarCeilToScalar(path->getBounds().width() + 10.f);
|
||||||
}
|
}
|
||||||
@ -187,23 +247,16 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
GrPipelineBuilder pipelineBuilder;
|
GrPipelineBuilder pipelineBuilder;
|
||||||
SkAutoTUnref<const GrGeometryProcessor> gp(
|
|
||||||
GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType,
|
|
||||||
0xff000000));
|
|
||||||
pipelineBuilder.addCoverageProcessor(fp);
|
pipelineBuilder.addCoverageProcessor(fp);
|
||||||
pipelineBuilder.setRenderTarget(rt);
|
pipelineBuilder.setRenderTarget(rt);
|
||||||
|
|
||||||
GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVertexStride(), 0);
|
ConvexPolyTestBatch::Geometry geometry;
|
||||||
SkASSERT(gp->getVertexStride() == sizeof(SkPoint));
|
geometry.fColor = gp->color();
|
||||||
SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices());
|
geometry.fBounds = rect;
|
||||||
|
|
||||||
SkRect bounds = rect;
|
SkAutoTUnref<GrBatch> batch(ConvexPolyTestBatch::Create(gp, geometry));
|
||||||
bounds.outset(5.f, 5.f);
|
|
||||||
bounds.toQuad(verts);
|
|
||||||
|
|
||||||
tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer());
|
tt.target()->drawBatch(&pipelineBuilder, batch, NULL);
|
||||||
tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangleFan_GrPrimitiveType,
|
|
||||||
0, 0, 4, 6);
|
|
||||||
|
|
||||||
x += SkScalarCeilToScalar(rect.width() + 10.f);
|
x += SkScalarCeilToScalar(rect.width() + 10.f);
|
||||||
}
|
}
|
||||||
|
@ -217,6 +217,7 @@
|
|||||||
'../gm/yuvtorgbeffect.cpp',
|
'../gm/yuvtorgbeffect.cpp',
|
||||||
|
|
||||||
# Files needed by particular GMs
|
# Files needed by particular GMs
|
||||||
|
'../src/gpu/GrTestBatch.h',
|
||||||
'../src/utils/debugger/SkDrawCommand.h',
|
'../src/utils/debugger/SkDrawCommand.h',
|
||||||
'../src/utils/debugger/SkDrawCommand.cpp',
|
'../src/utils/debugger/SkDrawCommand.cpp',
|
||||||
'../src/utils/debugger/SkDebugCanvas.h',
|
'../src/utils/debugger/SkDebugCanvas.h',
|
||||||
|
94
src/gpu/GrTestBatch.h
Normal file
94
src/gpu/GrTestBatch.h
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* 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<const GrGeometryProcessor> fGeometryProcessor;
|
||||||
|
BatchTracker fBatch;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user