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

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

Issue 2282983003: Reduce CPU overhead on drawRegion() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update bench 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
« gm/drawregion.cpp ('K') | « gm/drawregion.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/GrRegionBatch.cpp
diff --git a/src/gpu/batches/GrRegionBatch.cpp b/src/gpu/batches/GrRegionBatch.cpp
index 271f6c5b7ee1e0290a63bf7c9b81669b5aa52c51..058baf0ef8fb3aa76d8be8734082975d6f4dfa66 100644
--- a/src/gpu/batches/GrRegionBatch.cpp
+++ b/src/gpu/batches/GrRegionBatch.cpp
@@ -17,31 +17,26 @@
static const int kVertsPerInstance = 4;
static const int kIndicesPerInstance = 6;
-static sk_sp<GrGeometryProcessor> make_gp(bool readsCoverage) {
+static sk_sp<GrGeometryProcessor> make_gp(bool readsCoverage, const SkMatrix& viewMatrix) {
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());
+ LocalCoords localCoords(LocalCoords::kUsePosition_Type);
+ return GrDefaultGeoProcFactory::Make(color, coverage, localCoords, viewMatrix);
}
-static int tesselate_region(intptr_t vertices,
+static void tesselate_region(intptr_t vertices,
size_t vertexStride,
GrColor color,
- const SkMatrix& viewMatrix,
const SkRegion& region) {
SkRegion::Iterator iter(region);
intptr_t verts = vertices;
while (!iter.done()) {
- SkIRect rect = iter.rect();
+ SkRect rect = SkRect::Make(iter.rect());
SkPoint* position = (SkPoint*) verts;
- position->setIRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vertexStride);
-
- static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor);
- SkPoint* localPosition = (SkPoint*) (verts + kLocalOffset);
- localPosition->setIRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vertexStride);
+ position->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vertexStride);
static const int kColorOffset = sizeof(SkPoint);
GrColor* vertColor = reinterpret_cast<GrColor*>(verts + kColorOffset);
@@ -53,13 +48,6 @@ static int tesselate_region(intptr_t vertices,
verts += vertexStride * kVertsPerInstance;
iter.next();
}
-
- SkPoint* positions = reinterpret_cast<SkPoint*>(vertices);
- int numRects = region.computeRegionComplexity();
- SkMatrixPriv::MapPointsWithStride(viewMatrix, positions, vertexStride,
- numRects * kVertsPerInstance);
-
- return numRects;
}
class RegionBatch : public GrVertexBatch {
@@ -67,11 +55,11 @@ public:
DEFINE_BATCH_CLASS_ID
RegionBatch(GrColor color, const SkMatrix& viewMatrix, const SkRegion& region)
- : INHERITED(ClassID()) {
-
+ : INHERITED(ClassID())
+ , fViewMatrix(viewMatrix)
+ {
RegionInfo& info = fRegions.push_back();
info.fColor = color;
- info.fViewMatrix = viewMatrix;
info.fRegion = region;
SkRect bounds = SkRect::Make(region.getBounds());
@@ -108,13 +96,12 @@ public:
private:
void onPrepareDraws(Target* target) const override {
- sk_sp<GrGeometryProcessor> gp = make_gp(fOverrides.readsCoverage());
+ sk_sp<GrGeometryProcessor> gp = make_gp(fOverrides.readsCoverage(), fViewMatrix);
if (!gp) {
SkDebugf("Couldn't create GrGeometryProcessor\n");
return;
}
- SkASSERT(gp->getVertexStride() ==
- sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr));
+ SkASSERT(gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionColorAttr));
int numRegions = fRegions.count();
int numRects = 0;
@@ -134,8 +121,8 @@ private:
intptr_t verts = reinterpret_cast<intptr_t>(vertices);
for (int i = 0; i < numRegions; i++) {
- int numRectsInRegion = tesselate_region(verts, vertexStride, fRegions[i].fColor,
- fRegions[i].fViewMatrix, fRegions[i].fRegion);
+ tesselate_region(verts, vertexStride, fRegions[i].fColor, fRegions[i].fRegion);
+ int numRectsInRegion = fRegions[i].fRegion.computeRegionComplexity();
verts += numRectsInRegion * kVertsPerInstance * vertexStride;
}
helper.recordDraw(target, gp.get());
@@ -148,6 +135,10 @@ private:
return false;
}
+ if (fViewMatrix != that->fViewMatrix) {
+ return false;
+ }
+
fRegions.push_back_n(that->fRegions.count(), that->fRegions.begin());
this->joinBounds(*that);
return true;
@@ -155,10 +146,10 @@ private:
struct RegionInfo {
GrColor fColor;
- SkMatrix fViewMatrix;
SkRegion fRegion;
};
+ SkMatrix fViewMatrix;
GrXPOverridesForBatch fOverrides;
SkSTArray<1, RegionInfo, true> fRegions;
« gm/drawregion.cpp ('K') | « gm/drawregion.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698