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

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

Issue 2267273006: GPU implementation of drawRegion() (Closed) Base URL: https://skia.googlesource.com/skia.git@drawregion
Patch Set: Keep fixing stuff Created 4 years, 4 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
« src/gpu/SkGpuDevice.cpp ('K') | « src/gpu/batches/GrRegionBatch.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/batches/GrRegionBatch.cpp
diff --git a/src/gpu/batches/GrNonAAFillRectBatch.cpp b/src/gpu/batches/GrRegionBatch.cpp
similarity index 65%
copy from src/gpu/batches/GrNonAAFillRectBatch.cpp
copy to src/gpu/batches/GrRegionBatch.cpp
index 1422951d240d59fab798d40014e612ad57c86be6..595194d746ec2482481cf64f4b7805a3e7a9b155 100644
--- a/src/gpu/batches/GrNonAAFillRectBatch.cpp
+++ b/src/gpu/batches/GrRegionBatch.cpp
@@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
-#include "GrNonAAFillRectBatch.h"
+#include "GrRegionBatch.h"
#include "GrBatchFlushState.h"
#include "GrColor.h"
@@ -16,6 +16,7 @@
#include "GrVertexBatch.h"
#include "SkMatrixPriv.h"
+#include "SkRegion.h"
static const int kVertsPerInstance = 4;
static const int kIndicesPerInstance = 6;
@@ -27,7 +28,7 @@ static const int kIndicesPerInstance = 6;
rect draws.
The vertex attrib order is always pos, color, [local coords].
- */
+*/
static sk_sp<GrGeometryProcessor> make_gp(bool readsCoverage) {
using namespace GrDefaultGeoProcFactory;
Color color(Color::kAttribute_Type);
@@ -41,8 +42,7 @@ static void tesselate(intptr_t vertices,
size_t vertexStride,
GrColor color,
const SkMatrix* viewMatrix,
- const SkRect& rect,
- const GrQuad* localQuad) {
+ const SkRect& rect) {
SkPoint* positions = reinterpret_cast<SkPoint*>(vertices);
positions->setRectFan(rect.fLeft, rect.fTop,
@@ -52,17 +52,6 @@ static void tesselate(intptr_t vertices,
SkMatrixPriv::MapPointsWithStride(*viewMatrix, positions, vertexStride, kVertsPerInstance);
}
- // Setup local coords
- // TODO we should only do this if local coords are being read
- if (localQuad) {
- static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor);
- for (int i = 0; i < kVertsPerInstance; i++) {
- SkPoint* coords = reinterpret_cast<SkPoint*>(vertices + kLocalOffset +
- i * vertexStride);
- *coords = localQuad->point(i);
- }
- }
-
static const int kColorOffset = sizeof(SkPoint);
GrColor* vertColor = reinterpret_cast<GrColor*>(vertices + kColorOffset);
for (int j = 0; j < 4; ++j) {
@@ -71,32 +60,28 @@ static void tesselate(intptr_t vertices,
}
}
-class NonAAFillRectBatch : public GrVertexBatch {
+class RegionBatch : public GrVertexBatch {
msarett 2016/08/25 16:36:17 Could/should this extend NonAAFillRectBatch?
bsalomon 2016/08/25 17:49:02 I don't think it should inherit from it. It's poss
msarett 2016/08/25 20:51:42 Alright cool, thanks.
public:
DEFINE_BATCH_CLASS_ID
- NonAAFillRectBatch(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect,
- const SkRect* localRect, const SkMatrix* localMatrix)
msarett 2016/08/25 16:36:17 Do I need to worry about localRect and localMatrix
bsalomon 2016/08/25 17:49:02 no
msarett 2016/08/25 20:51:42 Acknowledged.
+ RegionBatch(GrColor color, const SkMatrix& viewMatrix, const SkRegion& region)
: 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);
+ SkRegion::Iterator iter(region);
+
+ while (!iter.done()) {
msarett 2016/08/25 16:36:17 Any way to use push_back_n() here?
bsalomon 2016/08/25 17:49:02 I think we should keep it in region form until gen
msarett 2016/08/25 20:51:42 Done.
+ RectInfo& info = fRects.push_back();
+ info.fColor = color;
+ info.fViewMatrix = viewMatrix;
+ SkRect rect = SkRect::Make(iter.rect());
+ info.fRect = rect;
+ iter.next();
}
- this->setTransformedBounds(fRects[0].fRect, viewMatrix, HasAABloat::kNo, IsZeroArea::kNo);
+
+ SkRect bounds = SkRect::Make(region.getBounds());
+ this->setTransformedBounds(bounds, viewMatrix, HasAABloat::kNo, IsZeroArea::kNo);
}
- const char* name() const override { return "NonAAFillRectBatch"; }
+ const char* name() const override { return "GrRegionBatch"; }
SkString dumpInfo() const override {
SkString str;
@@ -125,7 +110,6 @@ public:
}
private:
- NonAAFillRectBatch() : INHERITED(ClassID()) {}
void onPrepareDraws(Target* target) const override {
sk_sp<GrGeometryProcessor> gp = make_gp(fOverrides.readsCoverage());
@@ -153,20 +137,18 @@ private:
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);
+ fRects[i].fRect);
}
helper.recordDraw(target, gp.get());
}
bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
- NonAAFillRectBatch* that = t->cast<NonAAFillRectBatch>();
+ RegionBatch* that = t->cast<RegionBatch>();
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;
}
@@ -180,7 +162,6 @@ private:
GrColor fColor;
SkMatrix fViewMatrix;
SkRect fRect;
- GrQuad fLocalQuad;
};
GrXPOverridesForBatch fOverrides;
@@ -189,36 +170,12 @@ private:
typedef GrVertexBatch INHERITED;
};
-namespace GrNonAAFillRectBatch {
+namespace GrRegionBatch {
GrDrawBatch* Create(GrColor color,
const SkMatrix& viewMatrix,
- const SkRect& rect,
- const SkRect* localRect,
- const SkMatrix* localMatrix) {
- return new NonAAFillRectBatch(color, viewMatrix, rect, localRect, localMatrix);
+ const SkRegion& region) {
+ return new RegionBatch(color, viewMatrix, region);
}
};
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-#ifdef GR_TEST_UTILS
-
-#include "GrBatchTest.h"
-
-DRAW_BATCH_TEST_DEFINE(RectBatch) {
- GrColor color = GrRandomColor(random);
- SkRect rect = GrTest::TestRect(random);
- SkRect localRect = GrTest::TestRect(random);
- SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
- SkMatrix localMatrix = GrTest::TestMatrix(random);
-
- bool hasLocalRect = random->nextBool();
- bool hasLocalMatrix = random->nextBool();
- return GrNonAAFillRectBatch::Create(color, viewMatrix, rect,
- hasLocalRect ? &localRect : nullptr,
- hasLocalMatrix ? &localMatrix : nullptr);
-}
-
-#endif
« src/gpu/SkGpuDevice.cpp ('K') | « src/gpu/batches/GrRegionBatch.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698