diff options
author | Chris Dalton <csmartdalton@google.com> | 2018-03-07 17:28:07 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-08 02:13:50 +0000 |
commit | df04ce29490a24f9d5b4f5caafd8f6a3368a19e0 (patch) | |
tree | 8ee3e7c10e544d852456b607d6a6476237083e84 /samplecode/SampleCCPRGeometry.cpp | |
parent | 5f20fa2923cdd5c8df36efff2ce7b5bd00c5bbb4 (diff) |
ccpr: Draw curves in a single pass
Throws out the complicated MSAA curve corner shaders, and instead just
ramps coverage to zero at bloat vertices that fall outside the curve.
Updates SampleCCPRGeometry to better visualize this new geometry by
clearing to black and drawing with SkBlendMode::kPlus.
Bug: skia:
Change-Id: Ibe86cbc741d8b015127b10dd43e3b52e7cb35732
Reviewed-on: https://skia-review.googlesource.com/112626
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'samplecode/SampleCCPRGeometry.cpp')
-rw-r--r-- | samplecode/SampleCCPRGeometry.cpp | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/samplecode/SampleCCPRGeometry.cpp b/samplecode/SampleCCPRGeometry.cpp index a90ece09a1..2a7d6640a6 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, @@ -119,14 +115,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 +130,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 +154,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 +166,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 +179,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 +188,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 +212,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]); @@ -254,7 +249,7 @@ void CCPRGeometryView::Op::onExecute(GrOpFlushState* state) { SkDEBUGCODE(proc.enableDebugVisualizations(kDebugBloat)); SkSTArray<1, GrMesh> mesh; - if (GrCCCoverageProcessor::RenderPassIsCubic(fView->fRenderPass)) { + if (RenderPass::kCubics == fView->fRenderPass) { sk_sp<GrBuffer> instBuff(rp->createBuffer( fView->fQuadPointInstances.count() * sizeof(QuadPointInstance), kVertex_GrBufferType, kDynamic_GrAccessPattern, @@ -275,11 +270,11 @@ 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)); } @@ -318,7 +313,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,7 +337,7 @@ bool CCPRGeometryView::onQuery(SkEvent* evt) { } SkUnichar unichar; if (SampleCode::CharQ(*evt, &unichar)) { - if (unichar >= '1' && unichar <= '6') { + if (unichar >= '1' && unichar <= '4') { fRenderPass = RenderPass(unichar - '1'); this->updateAndInval(); return true; |