Move AAFillRect into CPP for templatization

BUG=skia:

Review URL: https://codereview.chromium.org/1278043003
This commit is contained in:
joshualitt 2015-08-12 06:36:57 -07:00 committed by Commit bot
parent 9cdcabefa3
commit 37eb184e26
4 changed files with 272 additions and 267 deletions

View File

@ -7,9 +7,14 @@
#include "GrAAFillRectBatch.h"
#include "GrBatch.h"
#include "GrColor.h"
#include "GrDefaultGeoProcFactory.h"
#include "GrResourceKey.h"
#include "GrResourceProvider.h"
#include "GrTypes.h"
#include "SkMatrix.h"
#include "SkRect.h"
GR_DECLARE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey);
@ -41,7 +46,34 @@ static const GrGeometryProcessor* create_fill_rect_gp(bool tweakAlphaForCoverage
return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix);
}
void GrAAFillRectBatch::initBatchTracker(const GrPipelineOptimizations& opt) {
class AAFillRectBatch : public GrBatch {
public:
struct Geometry {
GrColor fColor;
SkMatrix fViewMatrix;
SkRect fRect;
SkRect fDevRect;
};
static GrBatch* Create(GrColor color,
const SkMatrix& viewMatrix,
const SkRect& rect,
const SkRect& devRect) {
return SkNEW_ARGS(AAFillRectBatch, (color, viewMatrix, rect, devRect));
}
const char* name() const override { return "AAFillRectBatch"; }
void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
// When this is called on a batch, there is only one geometry bundle
out->setKnownFourComponents(fGeoData[0].fColor);
}
void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override {
out->setUnknownSingleComponent();
}
void initBatchTracker(const GrPipelineOptimizations& opt) override {
// Handle any color overrides
if (!opt.readsColor()) {
fGeoData[0].fColor = GrColor_ILLEGAL;
@ -56,7 +88,7 @@ void GrAAFillRectBatch::initBatchTracker(const GrPipelineOptimizations& opt) {
fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage();
}
void GrAAFillRectBatch::generateGeometry(GrBatchTarget* batchTarget) {
void generateGeometry(GrBatchTarget* batchTarget) override {
bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakAlphaForCoverage,
@ -102,7 +134,26 @@ void GrAAFillRectBatch::generateGeometry(GrBatchTarget* batchTarget) {
helper.issueDraw(batchTarget);
}
const GrIndexBuffer* GrAAFillRectBatch::getIndexBuffer(GrResourceProvider* resourceProvider) {
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
private:
AAFillRectBatch(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect,
const SkRect& devRect) {
this->initClassID<AAFillRectBatch>();
Geometry& geometry = fGeoData.push_back();
geometry.fRect = rect;
geometry.fViewMatrix = viewMatrix;
geometry.fDevRect = devRect;
geometry.fColor = color;
this->setBounds(geometry.fDevRect);
}
static const int kNumAAFillRectsInIndexBuffer = 256;
static const int kVertsPerAAFillRect = 8;
static const int kIndicesPerAAFillRect = 30;
const GrIndexBuffer* getIndexBuffer(GrResourceProvider* resourceProvider) {
GR_DEFINE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey);
static const uint16_t gFillAARectIdx[] = {
@ -118,12 +169,19 @@ const GrIndexBuffer* GrAAFillRectBatch::getIndexBuffer(GrResourceProvider* resou
gAAFillRectIndexBufferKey);
}
bool GrAAFillRectBatch::onCombineIfPossible(GrBatch* t) {
GrColor color() const { return fBatch.fColor; }
bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCoverage; }
bool colorIgnored() const { return fBatch.fColorIgnored; }
const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; }
bool coverageIgnored() const { return fBatch.fCoverageIgnored; }
bool onCombineIfPossible(GrBatch* t) override {
if (!this->pipeline()->isEqual(*t->pipeline())) {
return false;
}
GrAAFillRectBatch* that = t->cast<GrAAFillRectBatch>();
AAFillRectBatch* that = t->cast<AAFillRectBatch>();
SkASSERT(this->usesLocalCoords() == that->usesLocalCoords());
// We apply the viewmatrix to the rect points on the cpu. However, if the pipeline uses
@ -148,7 +206,7 @@ bool GrAAFillRectBatch::onCombineIfPossible(GrBatch* t) {
return true;
}
void GrAAFillRectBatch::generateAAFillRectGeometry(void* vertices,
void generateAAFillRectGeometry(void* vertices,
size_t offset,
size_t vertexStride,
GrColor color,
@ -241,6 +299,29 @@ void GrAAFillRectBatch::generateAAFillRectGeometry(void* vertices,
}
}
struct BatchTracker {
GrColor fColor;
bool fUsesLocalCoords;
bool fColorIgnored;
bool fCoverageIgnored;
bool fCanTweakAlphaForCoverage;
};
BatchTracker fBatch;
SkSTArray<1, Geometry, true> fGeoData;
};
namespace GrAAFillRectBatch {
GrBatch* Create(GrColor color,
const SkMatrix& viewMatrix,
const SkRect& rect,
const SkRect& devRect) {
return AAFillRectBatch::Create(color, viewMatrix, rect, devRect);
}
};
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef GR_TEST_UTILS
@ -248,12 +329,11 @@ void GrAAFillRectBatch::generateAAFillRectGeometry(void* vertices,
#include "GrBatchTest.h"
BATCH_TEST_DEFINE(AAFillRectBatch) {
GrAAFillRectBatch::Geometry geo;
geo.fColor = GrRandomColor(random);
geo.fViewMatrix = GrTest::TestMatrix(random);
geo.fRect = GrTest::TestRect(random);
geo.fDevRect = GrTest::TestRect(random);
return GrAAFillRectBatch::Create(geo);
GrColor color = GrRandomColor(random);
SkMatrix viewMatrix = GrTest::TestMatrix(random);
SkRect rect = GrTest::TestRect(random);
SkRect devRect = GrTest::TestRect(random);
return AAFillRectBatch::Create(color, viewMatrix, rect, devRect);
}
#endif

View File

@ -8,84 +8,19 @@
#ifndef GrAAFillRectBatch_DEFINED
#define GrAAFillRectBatch_DEFINED
#include "GrBatch.h"
#include "GrColor.h"
#include "GrTypes.h"
#include "SkMatrix.h"
#include "SkRect.h"
class GrAAFillRectBatch : public GrBatch {
public:
struct Geometry {
GrColor fColor;
SkMatrix fViewMatrix;
SkRect fRect;
SkRect fDevRect;
};
class GrBatch;
class SkMatrix;
struct SkRect;
static GrBatch* Create(const Geometry& geometry) {
return SkNEW_ARGS(GrAAFillRectBatch, (geometry));
}
namespace GrAAFillRectBatch {
const char* name() const override { return "AAFillRectBatch"; }
void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
// When this is called on a batch, there is only one geometry bundle
out->setKnownFourComponents(fGeoData[0].fColor);
}
void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override {
out->setUnknownSingleComponent();
}
void initBatchTracker(const GrPipelineOptimizations&) override;
void generateGeometry(GrBatchTarget* batchTarget) override;
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
private:
GrAAFillRectBatch(const Geometry& geometry) {
this->initClassID<GrAAFillRectBatch>();
fGeoData.push_back(geometry);
this->setBounds(geometry.fDevRect);
}
static const int kNumAAFillRectsInIndexBuffer = 256;
static const int kVertsPerAAFillRect = 8;
static const int kIndicesPerAAFillRect = 30;
const GrIndexBuffer* getIndexBuffer(GrResourceProvider* resourceProvider);
GrColor color() const { return fBatch.fColor; }
bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCoverage; }
bool colorIgnored() const { return fBatch.fColorIgnored; }
const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; }
bool coverageIgnored() const { return fBatch.fCoverageIgnored; }
bool onCombineIfPossible(GrBatch* t) override;
void generateAAFillRectGeometry(void* vertices,
size_t offset,
size_t vertexStride,
GrColor color,
GrBatch* Create(GrColor color,
const SkMatrix& viewMatrix,
const SkRect& rect,
const SkRect& devRect,
bool tweakAlphaForCoverage) const;
const SkRect& devRect);
struct BatchTracker {
GrColor fColor;
bool fUsesLocalCoords;
bool fColorIgnored;
bool fCoverageIgnored;
bool fCanTweakAlphaForCoverage;
};
BatchTracker fBatch;
SkSTArray<1, Geometry, true> fGeoData;
};
#endif

View File

@ -59,19 +59,6 @@ GrBatch* CreateFillBW(GrColor color,
return GrRectBatch::Create(geometry);
}
GrBatch* CreateFillAA(GrColor color,
const SkMatrix& viewMatrix,
const SkRect& rect,
const SkRect& devRect) {
GrAAFillRectBatch::Geometry geometry;
geometry.fRect = rect;
geometry.fViewMatrix = viewMatrix;
geometry.fDevRect = devRect;
geometry.fColor = color;
return GrAAFillRectBatch::Create(geometry);
}
GrBatch* CreateStrokeBW(GrColor color,
const SkMatrix& viewMatrix,
const SkRect& rect,

View File

@ -8,6 +8,7 @@
#ifndef GrRectBatchFactory_DEFINED
#define GrRectBatchFactory_DEFINED
#include "GrAAFillRectBatch.h"
#include "GrColor.h"
class GrBatch;
@ -26,10 +27,12 @@ GrBatch* CreateFillBW(GrColor color,
const SkRect* localRect,
const SkMatrix* localMatrix);
GrBatch* CreateFillAA(GrColor color,
static GrBatch* CreateFillAA(GrColor color,
const SkMatrix& viewMatrix,
const SkRect& rect,
const SkRect& devRect);
const SkRect& devRect) {
return GrAAFillRectBatch::Create(color, viewMatrix, rect, devRect);
}
GrBatch* CreateStrokeBW(GrColor color,
const SkMatrix& viewMatrix,