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

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

Issue 1353553002: Create append methods in batch namespaces (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rob's feedback Created 5 years, 3 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.h ('k') | src/gpu/batches/GrNonAAStrokeRectBatch.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/batches/GrNonAAFillRectBatch.cpp
diff --git a/src/gpu/batches/GrNonAAFillRectBatch.cpp b/src/gpu/batches/GrNonAAFillRectBatch.cpp
index 54edb7d7c925ed7eb58591e634862b5f3a36e796..9c79666dd4aa46e9848fcde59c9508c091ea268f 100644
--- a/src/gpu/batches/GrNonAAFillRectBatch.cpp
+++ b/src/gpu/batches/GrNonAAFillRectBatch.cpp
@@ -34,6 +34,13 @@ public:
static void SetBounds(const Geometry& geo, SkRect* outBounds) {
geo.fViewMatrix.mapRect(outBounds, geo.fRect);
}
+
+ template <typename Geometry>
+ static void UpdateBoundsAfterAppend(const Geometry& geo, SkRect* outBounds) {
+ SkRect bounds = geo.fRect;
+ geo.fViewMatrix.mapRect(&bounds);
+ outBounds->join(bounds);
+ }
};
/** We always use per-vertex colors so that rects can be batched across color changes. Sometimes
@@ -187,16 +194,11 @@ public:
typedef GrTInstanceBatch<NonAAFillRectBatchImp> NonAAFillRectBatchSimple;
typedef GrTInstanceBatch<NonAAFillRectBatchPerspectiveImp> NonAAFillRectBatchPerspective;
-namespace GrNonAAFillRectBatch {
-
-GrDrawBatch* Create(GrColor color,
- const SkMatrix& viewMatrix,
- const SkRect& rect,
- const SkRect* localRect,
- const SkMatrix* localMatrix) {
+inline static void append_to_batch(NonAAFillRectBatchSimple* batch, GrColor color,
+ const SkMatrix& viewMatrix, const SkRect& rect,
+ const SkRect* localRect, const SkMatrix* localMatrix) {
SkASSERT(!viewMatrix.hasPerspective() && (!localMatrix || !localMatrix->hasPerspective()));
- NonAAFillRectBatchSimple* batch = NonAAFillRectBatchSimple::Create();
- NonAAFillRectBatchSimple::Geometry& geo = *batch->geometry();
+ NonAAFillRectBatchSimple::Geometry& geo = batch->geoData()->push_back();
geo.fColor = color;
geo.fViewMatrix = viewMatrix;
@@ -211,19 +213,13 @@ GrDrawBatch* Create(GrColor color,
} else {
geo.fLocalQuad.set(rect);
}
-
- batch->init();
- return batch;
}
-GrDrawBatch* CreateWithPerspective(GrColor color,
- const SkMatrix& viewMatrix,
- const SkRect& rect,
- const SkRect* localRect,
- const SkMatrix* localMatrix) {
+inline static void append_to_batch(NonAAFillRectBatchPerspective* batch, GrColor color,
+ const SkMatrix& viewMatrix, const SkRect& rect,
+ const SkRect* localRect, const SkMatrix* localMatrix) {
SkASSERT(viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPerspective()));
- NonAAFillRectBatchPerspective* batch = NonAAFillRectBatchPerspective::Create();
- NonAAFillRectBatchPerspective::Geometry& geo = *batch->geometry();
+ NonAAFillRectBatchPerspective::Geometry& geo = batch->geoData()->push_back();
geo.fColor = color;
geo.fViewMatrix = viewMatrix;
@@ -237,10 +233,67 @@ GrDrawBatch* CreateWithPerspective(GrColor color,
geo.fLocalRect = *localRect;
}
+}
+
+namespace GrNonAAFillRectBatch {
+
+GrDrawBatch* Create(GrColor color,
+ const SkMatrix& viewMatrix,
+ const SkRect& rect,
+ const SkRect* localRect,
+ const SkMatrix* localMatrix) {
+ NonAAFillRectBatchSimple* batch = NonAAFillRectBatchSimple::Create();
+ append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix);
+ batch->init();
+ return batch;
+}
+
+GrDrawBatch* CreateWithPerspective(GrColor color,
+ const SkMatrix& viewMatrix,
+ const SkRect& rect,
+ const SkRect* localRect,
+ const SkMatrix* localMatrix) {
+ NonAAFillRectBatchPerspective* batch = NonAAFillRectBatchPerspective::Create();
+ append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix);
batch->init();
return batch;
}
+bool Append(GrBatch* origBatch,
+ GrColor color,
+ const SkMatrix& viewMatrix,
+ const SkRect& rect,
+ const SkRect* localRect,
+ const SkMatrix* localMatrix) {
+ bool usePerspective = viewMatrix.hasPerspective() ||
+ (localMatrix && localMatrix->hasPerspective());
+
+ if (usePerspective && origBatch->classID() != NonAAFillRectBatchPerspective::ClassID()) {
+ return false;
+ }
+
+ if (!usePerspective) {
+ NonAAFillRectBatchSimple* batch = origBatch->cast<NonAAFillRectBatchSimple>();
+ append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix);
+ batch->updateBoundsAfterAppend();
+ } else {
+ NonAAFillRectBatchPerspective* batch = origBatch->cast<NonAAFillRectBatchPerspective>();
+ const NonAAFillRectBatchPerspective::Geometry& geo = batch->geoData()->back();
+
+ if (!geo.fViewMatrix.cheapEqualTo(viewMatrix) ||
+ geo.fHasLocalRect != SkToBool(localRect) ||
+ geo.fHasLocalMatrix != SkToBool(localMatrix) ||
+ (geo.fHasLocalMatrix && !geo.fLocalMatrix.cheapEqualTo(*localMatrix))) {
+ return false;
+ }
+
+ append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix);
+ batch->updateBoundsAfterAppend();
+ }
+
+ return true;
+}
+
};
///////////////////////////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « src/gpu/batches/GrNonAAFillRectBatch.h ('k') | src/gpu/batches/GrNonAAStrokeRectBatch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698