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

Unified Diff: src/gpu/GrDrawContext.cpp

Issue 2066993003: Begin instanced rendering for simple shapes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rix perf regressions 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 | « include/private/GrInstancedPipelineInfo.h ('k') | src/gpu/GrDrawContextPriv.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrDrawContext.cpp
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index d057984f9c67b61e399cfc967437091aad4230f7..dc24fb54390a82fb7eba556aa046c3a4020e0ab2 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -25,6 +25,8 @@
#include "effects/GrRRectEffect.h"
+#include "instanced/InstancedRendering.h"
+
#include "text/GrAtlasTextContext.h"
#include "text/GrStencilAndCoverTextContext.h"
@@ -41,6 +43,8 @@
#define RETURN_FALSE_IF_ABANDONED_PRIV if (fDrawContext->fDrawingManager->wasAbandoned()) { return false; }
#define RETURN_NULL_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return nullptr; }
+using gr_instanced::InstancedRendering;
+
class AutoCheckFlush {
public:
AutoCheckFlush(GrDrawingManager* drawingManager) : fDrawingManager(drawingManager) {
@@ -70,6 +74,7 @@ GrDrawContext::GrDrawContext(GrContext* context,
, fRenderTarget(std::move(rt))
, fDrawTarget(SkSafeRef(fRenderTarget->getLastDrawTarget()))
, fContext(context)
+ , fInstancedPipelineInfo(fRenderTarget.get())
, fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps))
, fAuditTrail(auditTrail)
#ifdef SK_DEBUG
@@ -273,23 +278,29 @@ GrDrawBatch* GrDrawContext::getFillRectBatch(const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& rect,
bool* useHWAA) {
+ if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) {
+ if (GrDrawBatch* batch = ir->recordRect(rect, viewMatrix, paint.getColor(),
+ paint.isAntiAlias(), fInstancedPipelineInfo,
+ useHWAA)) {
+ return batch;
+ }
+ }
- GrDrawBatch* batch = nullptr;
if (should_apply_coverage_aa(paint, fRenderTarget.get(), useHWAA)) {
// The fill path can handle rotation but not skew.
if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
SkRect devBoundRect;
viewMatrix.mapRect(&devBoundRect, rect);
- batch = GrRectBatchFactory::CreateAAFill(paint.getColor(), viewMatrix,
- rect, devBoundRect);
+ return GrRectBatchFactory::CreateAAFill(paint.getColor(), viewMatrix,
+ rect, devBoundRect);
}
} else {
// filled BW rect
- batch = GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rect,
- nullptr, nullptr);
+ return GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rect,
+ nullptr, nullptr);
}
- return batch;
+ return nullptr;
}
void GrDrawContext::drawRect(const GrClip& clip,
@@ -479,9 +490,19 @@ void GrDrawContext::fillRectToRect(const GrClip& clip,
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect");
AutoCheckFlush acf(fDrawingManager);
-
- bool useHWAA;
SkAutoTUnref<GrDrawBatch> batch;
+ bool useHWAA;
+
+ if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) {
+ batch.reset(ir->recordRect(rectToDraw, viewMatrix, paint.getColor(), localRect,
+ paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA));
+ if (batch) {
+ GrPipelineBuilder pipelineBuilder(paint, useHWAA);
+ this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
+ return;
+ }
+ }
+
if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) &&
view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), viewMatrix, rectToDraw,
@@ -508,9 +529,19 @@ void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip,
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatrix");
AutoCheckFlush acf(fDrawingManager);
-
- bool useHWAA;
SkAutoTUnref<GrDrawBatch> batch;
+ bool useHWAA;
+
+ if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) {
+ batch.reset(ir->recordRect(rectToDraw, viewMatrix, paint.getColor(), localMatrix,
+ paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA));
+ if (batch) {
+ GrPipelineBuilder pipelineBuilder(paint, useHWAA);
+ this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
+ return;
+ }
+ }
+
if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) &&
view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, localMatrix,
@@ -607,13 +638,25 @@ void GrDrawContext::drawRRect(const GrClip& clip,
}
SkASSERT(!style.pathEffect()); // this should've been devolved to a path in SkGpuDevice
- const SkStrokeRec stroke = style.strokeRec();
- AutoCheckFlush acf(fDrawingManager);
+ AutoCheckFlush acf(fDrawingManager);
+ const SkStrokeRec stroke = style.strokeRec();
bool useHWAA;
+
+ if (this->getDrawTarget()->instancedRendering() && stroke.isFillStyle()) {
+ InstancedRendering* ir = this->getDrawTarget()->instancedRendering();
+ SkAutoTUnref<GrDrawBatch> batch(ir->recordRRect(rrect, viewMatrix, paint.getColor(),
+ paint.isAntiAlias(), fInstancedPipelineInfo,
+ &useHWAA));
+ if (batch) {
+ GrPipelineBuilder pipelineBuilder(paint, useHWAA);
+ this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
+ return;
+ }
+ }
+
if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) {
GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps();
-
SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(paint.getColor(),
viewMatrix,
rrect,
@@ -640,6 +683,18 @@ bool GrDrawContext::drawFilledDRRect(const GrClip& clip,
SkASSERT(!origInner.isEmpty());
SkASSERT(!origOuter.isEmpty());
+ if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) {
+ bool useHWAA;
+ SkAutoTUnref<GrDrawBatch> batch(ir->recordDRRect(origOuter, origInner, viewMatrix,
+ paintIn.getColor(), paintIn.isAntiAlias(),
+ fInstancedPipelineInfo, &useHWAA));
+ if (batch) {
+ GrPipelineBuilder pipelineBuilder(paintIn, useHWAA);
+ this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
+ return true;
+ }
+ }
+
bool applyAA = paintIn.isAntiAlias() && !fRenderTarget->isUnifiedMultisampled();
GrPrimitiveEdgeType innerEdgeType = applyAA ? kInverseFillAA_GrProcessorEdgeType :
@@ -738,6 +793,19 @@ void GrDrawContext::drawOval(const GrClip& clip,
AutoCheckFlush acf(fDrawingManager);
const SkStrokeRec& stroke = style.strokeRec();
bool useHWAA;
+
+ if (this->getDrawTarget()->instancedRendering() && stroke.isFillStyle()) {
+ InstancedRendering* ir = this->getDrawTarget()->instancedRendering();
+ SkAutoTUnref<GrDrawBatch> batch(ir->recordOval(oval, viewMatrix, paint.getColor(),
+ paint.isAntiAlias(), fInstancedPipelineInfo,
+ &useHWAA));
+ if (batch) {
+ GrPipelineBuilder pipelineBuilder(paint, useHWAA);
+ this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
+ return;
+ }
+ }
+
if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) {
GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps();
SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(paint.getColor(),
« no previous file with comments | « include/private/GrInstancedPipelineInfo.h ('k') | src/gpu/GrDrawContextPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698