diff options
author | Chris Dalton <csmartdalton@google.com> | 2018-03-09 11:57:40 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-09 19:25:11 +0000 |
commit | 8738cf4c191d1a6ad2946ec2f9998eec47b55187 (patch) | |
tree | 2195b1658cbf4fcccb9501416240b56c4e828469 /samplecode | |
parent | 43f0ba073068b6334844bd0e2e48f11ddb2b068d (diff) |
ccpr: Simplify triangle corners
Modifies triangle corner shaders to just approximate their coverage with
linear values that ramp to zero at bloat vertices outside the triangle.
For the vertex backend, since corners now have the same fragment shader
as the rest of the triangle, we fold them in with the other steps and
draw triangles in a single pass.
The geometry backend still draws triangles in two passes, as there is
not an apparent performance advantage in combining them.
Updates SampleCCPRGeometry to better visualize this new geometry by
clearing to black and drawing with SkBlendMode::kPlus.
Bug: skia:
Change-Id: Idf8df8ff715dfab7ac91a07b914f65c08e46010b
Reviewed-on: https://skia-review.googlesource.com/113287
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'samplecode')
-rw-r--r-- | samplecode/SampleCCPRGeometry.cpp | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/samplecode/SampleCCPRGeometry.cpp b/samplecode/SampleCCPRGeometry.cpp index a90ece09a1..4b521dea48 100644 --- a/samplecode/SampleCCPRGeometry.cpp +++ b/samplecode/SampleCCPRGeometry.cpp @@ -32,10 +32,6 @@ using RenderPass = GrCCCoverageProcessor::RenderPass; static constexpr float kDebugBloat = 40; -static int is_quadratic(RenderPass pass) { - return pass == RenderPass::kQuadratics || pass == RenderPass::kQuadraticCorners; -} - /** * This sample visualizes the AA bloat geometry generated by the ccpr geometry shaders. It * increases the AA bloat by 50x and outputs color instead of coverage (coverage=+1 -> green, @@ -91,6 +87,7 @@ private: bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override { return false; } void onPrepare(GrOpFlushState*) override {} void onExecute(GrOpFlushState*) override; + void drawRenderPass(GrOpFlushState*, RenderPass); CCPRGeometryView* fView; @@ -119,14 +116,13 @@ static void draw_klm_line(int w, int h, SkCanvas* canvas, const SkScalar line[3] } void CCPRGeometryView::onDrawContent(SkCanvas* canvas) { - SkAutoCanvasRestore acr(canvas, true); - canvas->setMatrix(SkMatrix::I()); + canvas->clear(SK_ColorBLACK); SkPath outline; outline.moveTo(fPoints[0]); - if (GrCCCoverageProcessor::RenderPassIsCubic(fRenderPass)) { + if (RenderPass::kCubics == fRenderPass) { outline.cubicTo(fPoints[1], fPoints[2], fPoints[3]); - } else if (is_quadratic(fRenderPass)) { + } else if (RenderPass::kQuadratics == fRenderPass) { outline.quadTo(fPoints[1], fPoints[3]); } else { outline.lineTo(fPoints[1]); @@ -135,7 +131,7 @@ void CCPRGeometryView::onDrawContent(SkCanvas* canvas) { } SkPaint outlinePaint; - outlinePaint.setColor(0x30000000); + outlinePaint.setColor(0x80ffffff); outlinePaint.setStyle(SkPaint::kStroke_Style); outlinePaint.setStrokeWidth(0); outlinePaint.setAntiAlias(true); @@ -159,7 +155,7 @@ void CCPRGeometryView::onDrawContent(SkCanvas* canvas) { if (GrRenderTargetContext* rtc = canvas->internal_private_accessTopLayerRenderTargetContext()) { rtc->priv().testingOnly_addDrawOp(skstd::make_unique<Op>(this)); caption.appendf("RenderPass_%s", GrCCCoverageProcessor::RenderPassName(fRenderPass)); - if (GrCCCoverageProcessor::RenderPassIsCubic(fRenderPass)) { + if (RenderPass::kCubics == fRenderPass) { caption.appendf(" (%s)", SkCubicTypeName(fCubicType)); } } else { @@ -171,7 +167,7 @@ void CCPRGeometryView::onDrawContent(SkCanvas* canvas) { pointsPaint.setStrokeWidth(8); pointsPaint.setAntiAlias(true); - if (GrCCCoverageProcessor::RenderPassIsCubic(fRenderPass)) { + if (RenderPass::kCubics == fRenderPass) { int w = this->width(), h = this->height(); canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, fPoints, pointsPaint); draw_klm_line(w, h, canvas, &fCubicKLM[0], SK_ColorYELLOW); @@ -184,7 +180,7 @@ void CCPRGeometryView::onDrawContent(SkCanvas* canvas) { SkPaint captionPaint; captionPaint.setTextSize(20); - captionPaint.setColor(SK_ColorBLACK); + captionPaint.setColor(SK_ColorWHITE); captionPaint.setAntiAlias(true); canvas->drawText(caption.c_str(), caption.size(), 10, 30, captionPaint); } @@ -193,7 +189,7 @@ void CCPRGeometryView::updateGpuData() { fTriPointInstances.reset(); fQuadPointInstances.reset(); - if (GrCCCoverageProcessor::RenderPassIsCubic(fRenderPass)) { + if (RenderPass::kCubics == fRenderPass) { double t[2], s[2]; fCubicType = GrPathUtils::getCubicKLM(fPoints, &fCubicKLM, t, s); GrCCGeometry geometry; @@ -217,7 +213,7 @@ void CCPRGeometryView::updateGpuData() { continue; } } - } else if (is_quadratic(fRenderPass)) { + } else if (RenderPass::kQuadratics == fRenderPass) { GrCCGeometry geometry; geometry.beginContour(fPoints[0]); geometry.quadraticTo(fPoints[1], fPoints[3]); @@ -243,18 +239,26 @@ void CCPRGeometryView::updateGpuData() { } void CCPRGeometryView::Op::onExecute(GrOpFlushState* state) { + this->drawRenderPass(state, fView->fRenderPass); + + RenderPass cornerPass = RenderPass((int)fView->fRenderPass + 1); + if (GrCCCoverageProcessor::DoesRenderPass(cornerPass, state->caps())) { + this->drawRenderPass(state, cornerPass); + } +} + +void CCPRGeometryView::Op::drawRenderPass(GrOpFlushState* state, RenderPass renderPass) { GrResourceProvider* rp = state->resourceProvider(); GrContext* context = state->gpu()->getContext(); GrGLGpu* glGpu = kOpenGL_GrBackend == context->contextPriv().getBackend() ? static_cast<GrGLGpu*>(state->gpu()) : nullptr; - GrCCCoverageProcessor proc(rp, fView->fRenderPass, - GrCCCoverageProcessor::WindMethod::kCrossProduct); + GrCCCoverageProcessor proc(rp, renderPass, GrCCCoverageProcessor::WindMethod::kCrossProduct); SkDEBUGCODE(proc.enableDebugVisualizations(kDebugBloat)); SkSTArray<1, GrMesh> mesh; - if (GrCCCoverageProcessor::RenderPassIsCubic(fView->fRenderPass)) { + if (RenderPass::kCubics == renderPass) { sk_sp<GrBuffer> instBuff(rp->createBuffer( fView->fQuadPointInstances.count() * sizeof(QuadPointInstance), kVertex_GrBufferType, kDynamic_GrAccessPattern, @@ -275,17 +279,18 @@ void CCPRGeometryView::Op::onExecute(GrOpFlushState* state) { } GrPipeline pipeline(state->drawOpArgs().fProxy, GrPipeline::ScissorState::kDisabled, - SkBlendMode::kSrcOver); + SkBlendMode::kPlus); if (glGpu) { glGpu->handleDirtyContext(); - GR_GL_CALL(glGpu->glInterface(), PolygonMode(GR_GL_FRONT_AND_BACK, GR_GL_LINE)); + // GR_GL_CALL(glGpu->glInterface(), PolygonMode(GR_GL_FRONT_AND_BACK, GR_GL_LINE)); GR_GL_CALL(glGpu->glInterface(), Enable(GR_GL_LINE_SMOOTH)); } if (!mesh.empty()) { SkASSERT(1 == mesh.count()); - state->rtCommandBuffer()->draw(pipeline, proc, mesh.begin(), nullptr, 1, this->bounds()); + GrGpuRTCommandBuffer* cmdBuff = state->rtCommandBuffer(); + cmdBuff->draw(pipeline, proc, mesh.begin(), nullptr, 1, this->bounds()); } if (glGpu) { @@ -318,7 +323,7 @@ private: SkView::Click* CCPRGeometryView::onFindClickHandler(SkScalar x, SkScalar y, unsigned) { for (int i = 0; i < 4; ++i) { - if (!GrCCCoverageProcessor::RenderPassIsCubic(fRenderPass) && 2 == i) { + if (RenderPass::kCubics != fRenderPass && 2 == i) { continue; } if (fabs(x - fPoints[i].x()) < 20 && fabsf(y - fPoints[i].y()) < 20) { @@ -342,8 +347,8 @@ bool CCPRGeometryView::onQuery(SkEvent* evt) { } SkUnichar unichar; if (SampleCode::CharQ(*evt, &unichar)) { - if (unichar >= '1' && unichar <= '6') { - fRenderPass = RenderPass(unichar - '1'); + if (unichar >= '1' && unichar <= '3') { + fRenderPass = RenderPass((unichar - '1') * 2); this->updateAndInval(); return true; } |