Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Unified Diff: src/gpu/batches/GrNonAAFillRectPerspectiveBatch.cpp

Issue 2108403005: Move GrNonAAFillRectPerspectiveBatch to its own file (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix overlength line Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/batches/GrNonAAFillRectBatch.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/batches/GrNonAAFillRectPerspectiveBatch.cpp
diff --git a/src/gpu/batches/GrNonAAFillRectBatch.cpp b/src/gpu/batches/GrNonAAFillRectPerspectiveBatch.cpp
similarity index 61%
copy from src/gpu/batches/GrNonAAFillRectBatch.cpp
copy to src/gpu/batches/GrNonAAFillRectPerspectiveBatch.cpp
index 4a7daf2b793a76f3ef09638e82a98c04b36dc489..3cff209840707bad9857f37f1b565664b6532339 100644
--- a/src/gpu/batches/GrNonAAFillRectBatch.cpp
+++ b/src/gpu/batches/GrNonAAFillRectPerspectiveBatch.cpp
@@ -55,15 +55,6 @@ static sk_sp<GrGeometryProcessor> make_persp_gp(const SkMatrix& viewMatrix,
}
}
-static sk_sp<GrGeometryProcessor> make_gp(bool readsCoverage) {
- using namespace GrDefaultGeoProcFactory;
- Color color(Color::kAttribute_Type);
- Coverage coverage(readsCoverage ? Coverage::kSolid_Type : Coverage::kNone_Type);
-
- LocalCoords localCoords(LocalCoords::kHasExplicit_Type);
- return GrDefaultGeoProcFactory::Make(color, coverage, localCoords, SkMatrix::I());
-}
-
static void tesselate(intptr_t vertices,
size_t vertexStride,
GrColor color,
@@ -98,131 +89,13 @@ static void tesselate(intptr_t vertices,
}
}
-class NonAAFillRectBatch : public GrVertexBatch {
-public:
- DEFINE_BATCH_CLASS_ID
-
- NonAAFillRectBatch(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect,
- const SkRect* localRect, const SkMatrix* localMatrix)
- : INHERITED(ClassID()) {
- SkASSERT(!viewMatrix.hasPerspective() && (!localMatrix ||
- !localMatrix->hasPerspective()));
- RectInfo& info = fRects.push_back();
- info.fColor = color;
- info.fViewMatrix = viewMatrix;
- info.fRect = rect;
- if (localRect && localMatrix) {
- info.fLocalQuad.setFromMappedRect(*localRect, *localMatrix);
- } else if (localRect) {
- info.fLocalQuad.set(*localRect);
- } else if (localMatrix) {
- info.fLocalQuad.setFromMappedRect(rect, *localMatrix);
- } else {
- info.fLocalQuad.set(rect);
- }
- viewMatrix.mapRect(&fBounds, fRects[0].fRect);
- }
-
- const char* name() const override { return "NonAAFillRectBatch"; }
-
- SkString dumpInfo() const override {
- SkString str;
- str.appendf("# batched: %d\n", fRects.count());
- for (int i = 0; i < fRects.count(); ++i) {
- const RectInfo& info = fRects[i];
- str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
- i, info.fColor,
- info.fRect.fLeft, info.fRect.fTop, info.fRect.fRight, info.fRect.fBottom);
- }
- str.append(INHERITED::dumpInfo());
- return str;
- }
-
- void computePipelineOptimizations(GrInitInvariantOutput* color,
- GrInitInvariantOutput* coverage,
- GrBatchToXPOverrides* overrides) const override {
- // When this is called on a batch, there is only one geometry bundle
- color->setKnownFourComponents(fRects[0].fColor);
- coverage->setKnownSingleComponent(0xff);
- }
-
- void initBatchTracker(const GrXPOverridesForBatch& overrides) override {
- overrides.getOverrideColorIfSet(&fRects[0].fColor);
- fOverrides = overrides;
- }
-
-private:
- NonAAFillRectBatch() : INHERITED(ClassID()) {}
-
- void onPrepareDraws(Target* target) const override {
- sk_sp<GrGeometryProcessor> gp = make_gp(fOverrides.readsCoverage());
- if (!gp) {
- SkDebugf("Couldn't create GrGeometryProcessor\n");
- return;
- }
- SkASSERT(gp->getVertexStride() ==
- sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr));
-
- size_t vertexStride = gp->getVertexStride();
- int instanceCount = fRects.count();
-
- SkAutoTUnref<const GrBuffer> indexBuffer(target->resourceProvider()->refQuadIndexBuffer());
- InstancedHelper helper;
- void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexStride,
- indexBuffer, kVertsPerInstance,
- kIndicesPerInstance, instanceCount);
- if (!vertices || !indexBuffer) {
- SkDebugf("Could not allocate vertices\n");
- return;
- }
-
- for (int i = 0; i < instanceCount; i++) {
- intptr_t verts = reinterpret_cast<intptr_t>(vertices) +
- i * kVertsPerInstance * vertexStride;
- tesselate(verts, vertexStride, fRects[i].fColor, &fRects[i].fViewMatrix,
- fRects[i].fRect, &fRects[i].fLocalQuad);
- }
- helper.recordDraw(target, gp.get());
- }
-
- bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
- NonAAFillRectBatch* that = t->cast<NonAAFillRectBatch>();
- if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(),
- that->bounds(), caps)) {
- return false;
- }
-
- // In the event of two batches, one who can tweak, one who cannot, we just fall back to
- // not tweaking
- if (fOverrides.canTweakAlphaForCoverage() && !that->fOverrides.canTweakAlphaForCoverage()) {
- fOverrides = that->fOverrides;
- }
-
- fRects.push_back_n(that->fRects.count(), that->fRects.begin());
- this->joinBounds(that->bounds());
- return true;
- }
-
- struct RectInfo {
- GrColor fColor;
- SkMatrix fViewMatrix;
- SkRect fRect;
- GrQuad fLocalQuad;
- };
-
- GrXPOverridesForBatch fOverrides;
- SkSTArray<1, RectInfo, true> fRects;
-
- typedef GrVertexBatch INHERITED;
-};
-
// We handle perspective in the local matrix or viewmatrix with special batches
-class NonAAFillRectPerspectiveBatch : public GrVertexBatch {
+class GrNonAAFillRectPerspectiveBatch : public GrVertexBatch {
public:
DEFINE_BATCH_CLASS_ID
- NonAAFillRectPerspectiveBatch(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect,
- const SkRect* localRect, const SkMatrix* localMatrix)
+ GrNonAAFillRectPerspectiveBatch(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect,
+ const SkRect* localRect, const SkMatrix* localMatrix)
: INHERITED(ClassID())
, fViewMatrix(viewMatrix) {
SkASSERT(viewMatrix.hasPerspective() || (localMatrix &&
@@ -270,7 +143,7 @@ public:
}
private:
- NonAAFillRectPerspectiveBatch() : INHERITED(ClassID()) {}
+ GrNonAAFillRectPerspectiveBatch() : INHERITED(ClassID()) {}
void onPrepareDraws(Target* target) const override {
sk_sp<GrGeometryProcessor> gp = make_persp_gp(fViewMatrix,
@@ -314,7 +187,7 @@ private:
}
bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
- NonAAFillRectPerspectiveBatch* that = t->cast<NonAAFillRectPerspectiveBatch>();
+ GrNonAAFillRectPerspectiveBatch* that = t->cast<GrNonAAFillRectPerspectiveBatch>();
if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(),
that->bounds(), caps)) {
return false;
@@ -360,20 +233,12 @@ private:
namespace GrNonAAFillRectBatch {
-GrDrawBatch* Create(GrColor color,
- const SkMatrix& viewMatrix,
- const SkRect& rect,
- const SkRect* localRect,
- const SkMatrix* localMatrix) {
- return new NonAAFillRectBatch(color, viewMatrix, rect, localRect, localMatrix);
-}
-
GrDrawBatch* CreateWithPerspective(GrColor color,
const SkMatrix& viewMatrix,
const SkRect& rect,
const SkRect* localRect,
const SkMatrix* localMatrix) {
- return new NonAAFillRectPerspectiveBatch(color, viewMatrix, rect, localRect, localMatrix);
+ return new GrNonAAFillRectPerspectiveBatch(color, viewMatrix, rect, localRect, localMatrix);
}
};
@@ -384,18 +249,22 @@ GrDrawBatch* CreateWithPerspective(GrColor color,
#include "GrBatchTest.h"
-DRAW_BATCH_TEST_DEFINE(RectBatch) {
+DRAW_BATCH_TEST_DEFINE(PerspRectBatch) {
GrColor color = GrRandomColor(random);
SkRect rect = GrTest::TestRect(random);
SkRect localRect = GrTest::TestRect(random);
- SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
- SkMatrix localMatrix = GrTest::TestMatrix(random);
+ SkMatrix viewMatrix = GrTest::TestMatrix(random);
+ bool hasLocalMatrix = random->nextBool();
+ SkMatrix localMatrix;
+ if (!viewMatrix.hasPerspective()) {
+ localMatrix = GrTest::TestMatrixPerspective(random);
+ hasLocalMatrix = true;
+ }
bool hasLocalRect = random->nextBool();
- bool hasLocalMatrix = random->nextBool();
- return GrNonAAFillRectBatch::Create(color, viewMatrix, rect,
- hasLocalRect ? &localRect : nullptr,
- hasLocalMatrix ? &localMatrix : nullptr);
+ return GrNonAAFillRectBatch::CreateWithPerspective(color, viewMatrix, rect,
+ hasLocalRect ? &localRect : nullptr,
+ hasLocalMatrix ? &localMatrix : nullptr);
}
#endif
« no previous file with comments | « src/gpu/batches/GrNonAAFillRectBatch.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698