aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar Chris Dalton <csmartdalton@google.com>2017-10-16 10:44:41 -0600
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-16 20:08:41 +0000
commit6a3dbeed00fe725099277040e3e2fc7d8ecb9751 (patch)
treed19ab1d8b2c6849fc45ac188e1c7773d3cd32c39 /samplecode
parent6376517472259310185b224f58973fdc24edbe6a (diff)
Refactor CCPR coverage shaders for a vertex impl
Decouples geometry generation and analytic coverage. This paves the way for a vertex shader implementation. TBR=egdaniel@google.com Bug: skia: Change-Id: I2a183401bfe70b9f14b9b1cf035de6020a2135fa Reviewed-on: https://skia-review.googlesource.com/60103 Reviewed-by: Chris Dalton <csmartdalton@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SampleCCPRGeometry.cpp52
1 files changed, 26 insertions, 26 deletions
diff --git a/samplecode/SampleCCPRGeometry.cpp b/samplecode/SampleCCPRGeometry.cpp
index e152e1ec62..aa1fb8b8a4 100644
--- a/samplecode/SampleCCPRGeometry.cpp
+++ b/samplecode/SampleCCPRGeometry.cpp
@@ -27,16 +27,16 @@
using TriangleInstance = GrCCPRCoverageProcessor::TriangleInstance;
using CurveInstance = GrCCPRCoverageProcessor::CurveInstance;
-using Mode = GrCCPRCoverageProcessor::Mode;
+using RenderPass = GrCCPRCoverageProcessor::RenderPass;
static constexpr float kDebugBloat = 40;
-static int num_points(Mode mode) {
- return mode >= Mode::kSerpentineHulls ? 4 : 3;
+static int num_points(RenderPass renderPass) {
+ return renderPass >= RenderPass::kSerpentineHulls ? 4 : 3;
}
-static int is_quadratic(Mode mode) {
- return mode >= Mode::kQuadraticHulls && mode < Mode::kSerpentineHulls;
+static int is_quadratic(RenderPass renderPass) {
+ return renderPass >= RenderPass::kQuadraticHulls && renderPass < RenderPass::kSerpentineHulls;
}
/**
@@ -65,7 +65,7 @@ private:
void updateGpuData();
- Mode fMode = Mode::kTriangleHulls;
+ RenderPass fRenderPass = RenderPass::kTriangleHulls;
SkMatrix fCubicKLM;
SkPoint fPoints[4] = {
@@ -136,9 +136,9 @@ void CCPRGeometryView::onDrawContent(SkCanvas* canvas) {
SkPath outline;
outline.moveTo(fPoints[0]);
- if (4 == num_points(fMode)) {
+ if (4 == num_points(fRenderPass)) {
outline.cubicTo(fPoints[1], fPoints[2], fPoints[3]);
- } else if (is_quadratic(fMode)) {
+ } else if (is_quadratic(fRenderPass)) {
outline.quadTo(fPoints[1], fPoints[3]);
} else {
outline.lineTo(fPoints[1]);
@@ -172,7 +172,7 @@ void CCPRGeometryView::onDrawContent(SkCanvas* canvas) {
if (GrRenderTargetContext* rtc =
canvas->internal_private_accessTopLayerRenderTargetContext()) {
rtc->priv().testingOnly_addDrawOp(skstd::make_unique<Op>(this));
- caption = GrCCPRCoverageProcessor::GetProcessorName(fMode);
+ caption = GrCCPRCoverageProcessor::GetRenderPassName(fRenderPass);
}
SkPaint pointsPaint;
@@ -180,7 +180,7 @@ void CCPRGeometryView::onDrawContent(SkCanvas* canvas) {
pointsPaint.setStrokeWidth(8);
pointsPaint.setAntiAlias(true);
- if (4 == num_points(fMode)) {
+ if (4 == num_points(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);
@@ -199,7 +199,7 @@ void CCPRGeometryView::onDrawContent(SkCanvas* canvas) {
}
void CCPRGeometryView::updateGpuData() {
- int vertexCount = num_points(fMode);
+ int vertexCount = num_points(fRenderPass);
fGpuPoints.reset();
fInstanceData.reset();
@@ -208,17 +208,17 @@ void CCPRGeometryView::updateGpuData() {
if (4 == vertexCount) {
double t[2], s[2];
SkCubicType type = GrPathUtils::getCubicKLM(fPoints, &fCubicKLM, t, s);
- if (Mode::kSerpentineHulls == fMode && SkCubicType::kLoop == type) {
- fMode = Mode::kLoopHulls;
+ if (RenderPass::kSerpentineHulls == fRenderPass && SkCubicType::kLoop == type) {
+ fRenderPass = RenderPass::kLoopHulls;
}
- if (Mode::kSerpentineCorners == fMode && SkCubicType::kLoop == type) {
- fMode = Mode::kLoopCorners;
+ if (RenderPass::kSerpentineCorners == fRenderPass && SkCubicType::kLoop == type) {
+ fRenderPass = RenderPass::kLoopCorners;
}
- if (Mode::kLoopHulls == fMode && SkCubicType::kLoop != type) {
- fMode = Mode::kSerpentineHulls;
+ if (RenderPass::kLoopHulls == fRenderPass && SkCubicType::kLoop != type) {
+ fRenderPass = RenderPass::kSerpentineHulls;
}
- if (Mode::kLoopCorners == fMode && SkCubicType::kLoop != type) {
- fMode = Mode::kSerpentineCorners;
+ if (RenderPass::kLoopCorners == fRenderPass && SkCubicType::kLoop != type) {
+ fRenderPass = RenderPass::kSerpentineCorners;
}
GrCCPRGeometry geometry;
@@ -245,7 +245,7 @@ void CCPRGeometryView::updateGpuData() {
default: continue;
}
}
- } else if (is_quadratic(fMode)) {
+ } else if (is_quadratic(fRenderPass)) {
GrCCPRGeometry geometry;
geometry.beginContour(fPoints[0]);
geometry.quadraticTo(fPoints[1], fPoints[3]);
@@ -282,7 +282,7 @@ void CCPRGeometryView::Op::onExecute(GrOpFlushState* state) {
GrContext* context = state->gpu()->getContext();
GrGLGpu* glGpu = kOpenGL_GrBackend == context->contextPriv().getBackend() ?
static_cast<GrGLGpu*>(state->gpu()) : nullptr;
- int vertexCount = num_points(fView->fMode);
+ int vertexCount = num_points(fView->fRenderPass);
sk_sp<GrBuffer> pointsBuffer(rp->createBuffer(fView->fGpuPoints.count() * sizeof(SkPoint),
kTexel_GrBufferType, kDynamic_GrAccessPattern,
@@ -305,7 +305,7 @@ void CCPRGeometryView::Op::onExecute(GrOpFlushState* state) {
GrPipeline pipeline(state->drawOpArgs().fProxy, GrPipeline::ScissorState::kDisabled,
SkBlendMode::kSrcOver);
- GrCCPRCoverageProcessor ccprProc(fView->fMode, pointsBuffer.get());
+ GrCCPRCoverageProcessor ccprProc(fView->fRenderPass, pointsBuffer.get());
SkDEBUGCODE(ccprProc.enableDebugVisualizations(kDebugBloat);)
GrMesh mesh(4 == vertexCount ? GrPrimitiveType::kLinesAdjacency : GrPrimitiveType::kTriangles);
@@ -349,7 +349,7 @@ private:
SkView::Click* CCPRGeometryView::onFindClickHandler(SkScalar x, SkScalar y, unsigned) {
for (int i = 0; i < 4; ++i) {
- if (4 != num_points(fMode) && 2 == i) {
+ if (4 != num_points(fRenderPass) && 2 == i) {
continue;
}
if (fabs(x - fPoints[i].x()) < 20 && fabsf(y - fPoints[i].y()) < 20) {
@@ -374,11 +374,11 @@ bool CCPRGeometryView::onQuery(SkEvent* evt) {
SkUnichar unichar;
if (SampleCode::CharQ(*evt, &unichar)) {
if (unichar >= '1' && unichar <= '7') {
- fMode = Mode(unichar - '1');
- if (fMode >= Mode::kLoopHulls) {
+ fRenderPass = RenderPass(unichar - '1');
+ if (fRenderPass >= RenderPass::kLoopHulls) {
// '6' -> kSerpentineHulls, '7' -> kSerpentineCorners. updateGpuData converts to
// kLoop* if needed.
- fMode = Mode(int(fMode) + 1);
+ fRenderPass = RenderPass(int(fRenderPass) + 1);
}
this->updateAndInval();
return true;