aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar Chris Dalton <csmartdalton@google.com>2018-04-18 14:07:03 -0600
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-18 20:43:54 +0000
commit9f2dab0fdd3784e599099deb50653a35d5b238c8 (patch)
tree321816be62daad05cede102972d88d3cb772cb64 /samplecode
parent91ab15588451be2f7ec87635590f1e4f90bbbf9a (diff)
ccpr: Implement conics
TBR=egdaniel@google.com Bug: skia: Change-Id: Idf7811dc285961db52db41c9ff145afda40c274d Reviewed-on: https://skia-review.googlesource.com/122127 Reviewed-by: Chris Dalton <csmartdalton@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SampleCCPRGeometry.cpp78
1 files changed, 63 insertions, 15 deletions
diff --git a/samplecode/SampleCCPRGeometry.cpp b/samplecode/SampleCCPRGeometry.cpp
index a6e408749a..52e1181e8c 100644
--- a/samplecode/SampleCCPRGeometry.cpp
+++ b/samplecode/SampleCCPRGeometry.cpp
@@ -63,6 +63,8 @@ private:
SkPoint fPoints[4] = {
{100.05f, 100.05f}, {400.75f, 100.05f}, {400.75f, 300.95f}, {100.05f, 300.95f}};
+ float fConicWeight = .5;
+
SkTArray<TriPointInstance> fTriPointInstances;
SkTArray<QuadPointInstance> fQuadPointInstances;
@@ -148,14 +150,22 @@ void CCPRGeometryView::onDrawContent(SkCanvas* canvas) {
SkPath outline;
outline.moveTo(fPoints[0]);
- if (PrimitiveType::kCubics == fPrimitiveType) {
- outline.cubicTo(fPoints[1], fPoints[2], fPoints[3]);
- } else if (PrimitiveType::kQuadratics == fPrimitiveType) {
- outline.quadTo(fPoints[1], fPoints[3]);
- } else {
- outline.lineTo(fPoints[1]);
- outline.lineTo(fPoints[3]);
- outline.close();
+ switch (fPrimitiveType) {
+ case PrimitiveType::kTriangles:
+ case PrimitiveType::kWeightedTriangles:
+ outline.lineTo(fPoints[1]);
+ outline.lineTo(fPoints[3]);
+ outline.close();
+ break;
+ case PrimitiveType::kQuadratics:
+ outline.quadTo(fPoints[1], fPoints[3]);
+ break;
+ case PrimitiveType::kCubics:
+ outline.cubicTo(fPoints[1], fPoints[2], fPoints[3]);
+ break;
+ case PrimitiveType::kConics:
+ outline.conicTo(fPoints[1], fPoints[3], fConicWeight);
+ break;
}
SkPaint outlinePaint;
@@ -208,6 +218,8 @@ void CCPRGeometryView::onDrawContent(SkCanvas* canvas) {
GrCCCoverageProcessor::PrimitiveTypeName(fPrimitiveType));
if (PrimitiveType::kCubics == fPrimitiveType) {
caption.appendf(" (%s)", SkCubicTypeName(fCubicType));
+ } else if (PrimitiveType::kConics == fPrimitiveType) {
+ caption.appendf(" (w=%f)", fConicWeight);
}
} else {
caption = "Use GPU backend to visualize geometry.";
@@ -264,13 +276,18 @@ void CCPRGeometryView::updateGpuData() {
continue;
}
}
- } else if (PrimitiveType::kQuadratics == fPrimitiveType) {
+ } else if (PrimitiveType::kTriangles != fPrimitiveType) {
SkPoint P3[3] = {fPoints[0], fPoints[1], fPoints[3]};
GrCCGeometry geometry;
geometry.beginContour(P3[0]);
- geometry.quadraticTo(P3);
+ if (PrimitiveType::kQuadratics == fPrimitiveType) {
+ geometry.quadraticTo(P3);
+ } else {
+ SkASSERT(PrimitiveType::kConics == fPrimitiveType);
+ geometry.conicTo(P3, fConicWeight);
+ }
geometry.endContour();
- int ptsIdx = 0;
+ int ptsIdx = 0, conicWeightIdx = 0;
for (GrCCGeometry::Verb verb : geometry.verbs()) {
if (GrCCGeometry::Verb::kBeginContour == verb ||
GrCCGeometry::Verb::kEndOpenContour == verb ||
@@ -281,8 +298,16 @@ void CCPRGeometryView::updateGpuData() {
++ptsIdx;
continue;
}
- SkASSERT(GrCCGeometry::Verb::kMonotonicQuadraticTo == verb);
- fTriPointInstances.push_back().set(&geometry.points()[ptsIdx], Sk2f(0, 0));
+ SkASSERT(GrCCGeometry::Verb::kMonotonicQuadraticTo == verb ||
+ GrCCGeometry::Verb::kMonotonicConicTo == verb);
+ if (PrimitiveType::kQuadratics == fPrimitiveType &&
+ GrCCGeometry::Verb::kMonotonicQuadraticTo == verb) {
+ fTriPointInstances.push_back().set(&geometry.points()[ptsIdx], Sk2f(0, 0));
+ } else if (PrimitiveType::kConics == fPrimitiveType &&
+ GrCCGeometry::Verb::kMonotonicConicTo == verb) {
+ fQuadPointInstances.push_back().setW(&geometry.points()[ptsIdx], Sk2f(0, 0),
+ geometry.getConicWeight(conicWeightIdx++));
+ }
ptsIdx += 2;
}
} else {
@@ -301,7 +326,8 @@ void CCPRGeometryView::DrawCoverageCountOp::onExecute(GrOpFlushState* state) {
SkDEBUGCODE(proc.enableDebugBloat(kDebugBloat));
SkSTArray<1, GrMesh> mesh;
- if (PrimitiveType::kCubics == fView->fPrimitiveType) {
+ if (PrimitiveType::kCubics == fView->fPrimitiveType ||
+ PrimitiveType::kConics == fView->fPrimitiveType) {
sk_sp<GrBuffer> instBuff(rp->createBuffer(
fView->fQuadPointInstances.count() * sizeof(QuadPointInstance),
kVertex_GrBufferType, kDynamic_GrAccessPattern,
@@ -389,7 +415,7 @@ bool CCPRGeometryView::onQuery(SkEvent* evt) {
}
SkUnichar unichar;
if (SampleCode::CharQ(*evt, &unichar)) {
- if (unichar >= '1' && unichar <= '3') {
+ if (unichar >= '1' && unichar <= '4') {
fPrimitiveType = PrimitiveType(unichar - '1');
if (fPrimitiveType >= PrimitiveType::kWeightedTriangles) {
fPrimitiveType = (PrimitiveType) ((int)fPrimitiveType + 1);
@@ -397,6 +423,28 @@ bool CCPRGeometryView::onQuery(SkEvent* evt) {
this->updateAndInval();
return true;
}
+ if (PrimitiveType::kConics == fPrimitiveType) {
+ if (unichar == '+') {
+ fConicWeight *= 2;
+ this->updateAndInval();
+ return true;
+ }
+ if (unichar == '+' || unichar == '=') {
+ fConicWeight *= 5/4.f;
+ this->updateAndInval();
+ return true;
+ }
+ if (unichar == '-') {
+ fConicWeight *= 4/5.f;
+ this->updateAndInval();
+ return true;
+ }
+ if (unichar == '_') {
+ fConicWeight *= .5f;
+ this->updateAndInval();
+ return true;
+ }
+ }
if (unichar == 'D') {
SkDebugf(" SkPoint fPoints[4] = {\n");
SkDebugf(" {%ff, %ff},\n", fPoints[0].x(), fPoints[0].y());