2017-07-14 21:17:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
|
|
|
|
#include "GrContextPriv.h"
|
2017-09-05 22:46:48 +00:00
|
|
|
#include "GrPathUtils.h"
|
2017-07-14 21:17:41 +00:00
|
|
|
#include "GrRenderTargetContext.h"
|
|
|
|
#include "GrRenderTargetContextPriv.h"
|
|
|
|
#include "GrResourceProvider.h"
|
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkMakeUnique.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkView.h"
|
|
|
|
#include "ccpr/GrCCPRCoverageProcessor.h"
|
2017-08-28 16:24:22 +00:00
|
|
|
#include "ccpr/GrCCPRGeometry.h"
|
2017-07-14 21:17:41 +00:00
|
|
|
#include "gl/GrGLGpu.cpp"
|
|
|
|
#include "ops/GrDrawOp.h"
|
|
|
|
|
2017-09-05 06:30:07 +00:00
|
|
|
using TriangleInstance = GrCCPRCoverageProcessor::TriangleInstance;
|
|
|
|
using CurveInstance = GrCCPRCoverageProcessor::CurveInstance;
|
2017-10-16 16:44:41 +00:00
|
|
|
using RenderPass = GrCCPRCoverageProcessor::RenderPass;
|
2017-07-14 21:17:41 +00:00
|
|
|
|
2017-09-12 05:04:03 +00:00
|
|
|
static constexpr float kDebugBloat = 40;
|
|
|
|
|
2017-10-16 16:44:41 +00:00
|
|
|
static int num_points(RenderPass renderPass) {
|
|
|
|
return renderPass >= RenderPass::kSerpentineHulls ? 4 : 3;
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
|
2017-10-16 16:44:41 +00:00
|
|
|
static int is_quadratic(RenderPass renderPass) {
|
|
|
|
return renderPass >= RenderPass::kQuadraticHulls && renderPass < RenderPass::kSerpentineHulls;
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
* coverage=0 -> black, coverage=-1 -> red). Use the keys 1-7 to cycle through the different
|
|
|
|
* geometry processors.
|
|
|
|
*/
|
|
|
|
class CCPRGeometryView : public SampleView {
|
|
|
|
public:
|
|
|
|
CCPRGeometryView() { this->updateGpuData(); }
|
|
|
|
void onDrawContent(SkCanvas*) override;
|
|
|
|
|
|
|
|
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override;
|
|
|
|
bool onClick(SampleView::Click*) override;
|
|
|
|
bool onQuery(SkEvent* evt) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
class Click;
|
|
|
|
class Op;
|
|
|
|
|
|
|
|
void updateAndInval() {
|
|
|
|
this->updateGpuData();
|
|
|
|
this->inval(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateGpuData();
|
|
|
|
|
2017-10-16 16:44:41 +00:00
|
|
|
RenderPass fRenderPass = RenderPass::kTriangleHulls;
|
2017-09-05 22:46:48 +00:00
|
|
|
SkMatrix fCubicKLM;
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
SkPoint fPoints[4] = {
|
|
|
|
{100.05f, 100.05f},
|
2017-10-24 16:59:03 +00:00
|
|
|
{400.75f, 100.05f},
|
2017-07-14 21:17:41 +00:00
|
|
|
{400.75f, 300.95f},
|
2017-10-24 16:59:03 +00:00
|
|
|
{100.05f, 300.95f}
|
2017-07-14 21:17:41 +00:00
|
|
|
};
|
|
|
|
|
2017-09-05 06:30:07 +00:00
|
|
|
SkTArray<SkPoint> fGpuPoints;
|
|
|
|
SkTArray<int32_t> fInstanceData;
|
|
|
|
int fInstanceCount;
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
typedef SampleView INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CCPRGeometryView::Op : public GrDrawOp {
|
|
|
|
DEFINE_OP_CLASS_ID
|
|
|
|
|
|
|
|
public:
|
|
|
|
Op(CCPRGeometryView* view)
|
|
|
|
: INHERITED(ClassID())
|
|
|
|
, fView(view) {
|
|
|
|
this->setBounds(SkRect::MakeLargest(), GrOp::HasAABloat::kNo, GrOp::IsZeroArea::kNo);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* name() const override { return "[Testing/Sample code] CCPRGeometryView::Op"; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
2017-09-20 13:53:22 +00:00
|
|
|
RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*,
|
|
|
|
GrPixelConfigIsClamped) override {
|
2017-07-14 21:17:41 +00:00
|
|
|
return RequiresDstTexture::kNo;
|
|
|
|
}
|
|
|
|
bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override { return false; }
|
|
|
|
void onPrepare(GrOpFlushState*) override {}
|
|
|
|
void onExecute(GrOpFlushState*) override;
|
|
|
|
|
|
|
|
CCPRGeometryView* fView;
|
|
|
|
|
|
|
|
typedef GrDrawOp INHERITED;
|
|
|
|
};
|
|
|
|
|
2017-09-05 22:46:48 +00:00
|
|
|
static void draw_klm_line(int w, int h, SkCanvas* canvas, const SkScalar line[3], SkColor color) {
|
|
|
|
SkPoint p1, p2;
|
|
|
|
if (SkScalarAbs(line[1]) > SkScalarAbs(line[0])) {
|
|
|
|
// Draw from vertical edge to vertical edge.
|
|
|
|
p1 = {0, -line[2] / line[1]};
|
|
|
|
p2 = {(SkScalar) w, (-line[2] - w * line[0]) / line[1]};
|
|
|
|
} else {
|
|
|
|
// Draw from horizontal edge to horizontal edge.
|
|
|
|
p1 = {-line[2] / line[0], 0};
|
|
|
|
p2 = {(-line[2] - h * line[1]) / line[0], (SkScalar) h};
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint linePaint;
|
|
|
|
linePaint.setColor(color);
|
|
|
|
linePaint.setAlpha(128);
|
|
|
|
linePaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
linePaint.setStrokeWidth(0);
|
|
|
|
linePaint.setAntiAlias(true);
|
|
|
|
canvas->drawLine(p1, p2, linePaint);
|
|
|
|
}
|
|
|
|
|
2017-07-14 21:17:41 +00:00
|
|
|
void CCPRGeometryView::onDrawContent(SkCanvas* canvas) {
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
canvas->setMatrix(SkMatrix::I());
|
|
|
|
|
|
|
|
SkPath outline;
|
|
|
|
outline.moveTo(fPoints[0]);
|
2017-10-16 16:44:41 +00:00
|
|
|
if (4 == num_points(fRenderPass)) {
|
2017-07-14 21:17:41 +00:00
|
|
|
outline.cubicTo(fPoints[1], fPoints[2], fPoints[3]);
|
2017-10-16 16:44:41 +00:00
|
|
|
} else if (is_quadratic(fRenderPass)) {
|
2017-07-14 21:17:41 +00:00
|
|
|
outline.quadTo(fPoints[1], fPoints[3]);
|
|
|
|
} else {
|
|
|
|
outline.lineTo(fPoints[1]);
|
|
|
|
outline.lineTo(fPoints[3]);
|
2017-09-05 22:46:48 +00:00
|
|
|
outline.close();
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint outlinePaint;
|
|
|
|
outlinePaint.setColor(0x30000000);
|
|
|
|
outlinePaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
outlinePaint.setStrokeWidth(0);
|
|
|
|
outlinePaint.setAntiAlias(true);
|
|
|
|
canvas->drawPath(outline, outlinePaint);
|
|
|
|
|
2017-09-05 22:46:48 +00:00
|
|
|
#if 0
|
|
|
|
SkPaint gridPaint;
|
|
|
|
gridPaint.setColor(0x10000000);
|
|
|
|
gridPaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
gridPaint.setStrokeWidth(0);
|
|
|
|
gridPaint.setAntiAlias(true);
|
2017-09-12 05:04:03 +00:00
|
|
|
for (int y = 0; y < this->height(); y += kDebugBloat) {
|
2017-09-05 22:46:48 +00:00
|
|
|
canvas->drawLine(0, y, this->width(), y, gridPaint);
|
|
|
|
}
|
2017-09-12 05:04:03 +00:00
|
|
|
for (int x = 0; x < this->width(); x += kDebugBloat) {
|
2017-09-05 22:46:48 +00:00
|
|
|
canvas->drawLine(x, 0, x, this->height(), outlinePaint);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-07-14 21:17:41 +00:00
|
|
|
const char* caption = "Use GPU backend to visualize geometry.";
|
|
|
|
|
|
|
|
if (GrRenderTargetContext* rtc =
|
|
|
|
canvas->internal_private_accessTopLayerRenderTargetContext()) {
|
|
|
|
rtc->priv().testingOnly_addDrawOp(skstd::make_unique<Op>(this));
|
2017-10-16 16:44:41 +00:00
|
|
|
caption = GrCCPRCoverageProcessor::GetRenderPassName(fRenderPass);
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint pointsPaint;
|
|
|
|
pointsPaint.setColor(SK_ColorBLUE);
|
|
|
|
pointsPaint.setStrokeWidth(8);
|
|
|
|
pointsPaint.setAntiAlias(true);
|
|
|
|
|
2017-10-16 16:44:41 +00:00
|
|
|
if (4 == num_points(fRenderPass)) {
|
2017-09-05 22:46:48 +00:00
|
|
|
int w = this->width(), h = this->height();
|
2017-07-14 21:17:41 +00:00
|
|
|
canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, fPoints, pointsPaint);
|
2017-09-05 22:46:48 +00:00
|
|
|
draw_klm_line(w, h, canvas, &fCubicKLM[0], SK_ColorYELLOW);
|
|
|
|
draw_klm_line(w, h, canvas, &fCubicKLM[3], SK_ColorBLUE);
|
|
|
|
draw_klm_line(w, h, canvas, &fCubicKLM[6], SK_ColorRED);
|
2017-07-14 21:17:41 +00:00
|
|
|
} else {
|
|
|
|
canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, fPoints, pointsPaint);
|
|
|
|
canvas->drawPoints(SkCanvas::kPoints_PointMode, 1, fPoints + 3, pointsPaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint captionPaint;
|
|
|
|
captionPaint.setTextSize(20);
|
|
|
|
captionPaint.setColor(SK_ColorBLACK);
|
|
|
|
captionPaint.setAntiAlias(true);
|
|
|
|
canvas->drawText(caption, strlen(caption), 10, 30, captionPaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCPRGeometryView::updateGpuData() {
|
2017-10-16 16:44:41 +00:00
|
|
|
int vertexCount = num_points(fRenderPass);
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
fGpuPoints.reset();
|
2017-09-05 06:30:07 +00:00
|
|
|
fInstanceData.reset();
|
|
|
|
fInstanceCount = 0;
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
if (4 == vertexCount) {
|
|
|
|
double t[2], s[2];
|
2017-09-05 22:46:48 +00:00
|
|
|
SkCubicType type = GrPathUtils::getCubicKLM(fPoints, &fCubicKLM, t, s);
|
2017-10-16 16:44:41 +00:00
|
|
|
if (RenderPass::kSerpentineHulls == fRenderPass && SkCubicType::kLoop == type) {
|
|
|
|
fRenderPass = RenderPass::kLoopHulls;
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
2017-10-16 16:44:41 +00:00
|
|
|
if (RenderPass::kSerpentineCorners == fRenderPass && SkCubicType::kLoop == type) {
|
|
|
|
fRenderPass = RenderPass::kLoopCorners;
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
2017-10-16 16:44:41 +00:00
|
|
|
if (RenderPass::kLoopHulls == fRenderPass && SkCubicType::kLoop != type) {
|
|
|
|
fRenderPass = RenderPass::kSerpentineHulls;
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
2017-10-16 16:44:41 +00:00
|
|
|
if (RenderPass::kLoopCorners == fRenderPass && SkCubicType::kLoop != type) {
|
|
|
|
fRenderPass = RenderPass::kSerpentineCorners;
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
|
2017-09-05 22:46:48 +00:00
|
|
|
GrCCPRGeometry geometry;
|
|
|
|
geometry.beginContour(fPoints[0]);
|
2017-09-12 05:04:03 +00:00
|
|
|
geometry.cubicTo(fPoints[1], fPoints[2], fPoints[3], kDebugBloat/2, kDebugBloat/2);
|
2017-09-05 22:46:48 +00:00
|
|
|
geometry.endContour();
|
|
|
|
fGpuPoints.push_back_n(geometry.points().count(), geometry.points().begin());
|
|
|
|
int ptsIdx = 0;
|
|
|
|
for (GrCCPRGeometry::Verb verb : geometry.verbs()) {
|
|
|
|
switch (verb) {
|
|
|
|
case GrCCPRGeometry::Verb::kLineTo:
|
|
|
|
++ptsIdx;
|
|
|
|
continue;
|
|
|
|
case GrCCPRGeometry::Verb::kMonotonicQuadraticTo:
|
|
|
|
ptsIdx += 2;
|
|
|
|
continue;
|
|
|
|
case GrCCPRGeometry::Verb::kMonotonicSerpentineTo:
|
|
|
|
case GrCCPRGeometry::Verb::kMonotonicLoopTo:
|
|
|
|
fInstanceData.push_back(ptsIdx);
|
|
|
|
fInstanceData.push_back(0); // Atlas offset.
|
|
|
|
ptsIdx += 3;
|
|
|
|
++fInstanceCount;
|
|
|
|
continue;
|
|
|
|
default: continue;
|
|
|
|
}
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
2017-10-16 16:44:41 +00:00
|
|
|
} else if (is_quadratic(fRenderPass)) {
|
2017-09-05 06:30:07 +00:00
|
|
|
GrCCPRGeometry geometry;
|
|
|
|
geometry.beginContour(fPoints[0]);
|
|
|
|
geometry.quadraticTo(fPoints[1], fPoints[3]);
|
|
|
|
geometry.endContour();
|
|
|
|
fGpuPoints.push_back_n(geometry.points().count(), geometry.points().begin());
|
|
|
|
for (GrCCPRGeometry::Verb verb : geometry.verbs()) {
|
|
|
|
if (GrCCPRGeometry::Verb::kBeginContour == verb ||
|
|
|
|
GrCCPRGeometry::Verb::kEndOpenContour == verb ||
|
|
|
|
GrCCPRGeometry::Verb::kEndClosedContour == verb) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SkASSERT(GrCCPRGeometry::Verb::kMonotonicQuadraticTo == verb);
|
|
|
|
fInstanceData.push_back(2 * fInstanceCount++); // Pts idx.
|
|
|
|
fInstanceData.push_back(0); // Atlas offset.
|
2017-08-07 15:00:46 +00:00
|
|
|
}
|
2017-07-14 21:17:41 +00:00
|
|
|
} else {
|
2017-08-07 15:00:46 +00:00
|
|
|
fGpuPoints.push_back(fPoints[0]);
|
|
|
|
fGpuPoints.push_back(fPoints[1]);
|
2017-09-05 06:30:07 +00:00
|
|
|
fGpuPoints.push_back(fPoints[3]);
|
|
|
|
fInstanceData.push_back(0);
|
|
|
|
fInstanceData.push_back(1);
|
|
|
|
fInstanceData.push_back(2);
|
|
|
|
fInstanceData.push_back(0); // Atlas offset.
|
|
|
|
fInstanceCount = 1;
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCPRGeometryView::Op::onExecute(GrOpFlushState* state) {
|
2017-09-05 22:46:48 +00:00
|
|
|
if (fView->fInstanceData.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-14 21:17:41 +00:00
|
|
|
GrResourceProvider* rp = state->resourceProvider();
|
|
|
|
GrContext* context = state->gpu()->getContext();
|
|
|
|
GrGLGpu* glGpu = kOpenGL_GrBackend == context->contextPriv().getBackend() ?
|
|
|
|
static_cast<GrGLGpu*>(state->gpu()) : nullptr;
|
2017-10-16 16:44:41 +00:00
|
|
|
int vertexCount = num_points(fView->fRenderPass);
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
sk_sp<GrBuffer> pointsBuffer(rp->createBuffer(fView->fGpuPoints.count() * sizeof(SkPoint),
|
|
|
|
kTexel_GrBufferType, kDynamic_GrAccessPattern,
|
|
|
|
GrResourceProvider::kNoPendingIO_Flag |
|
|
|
|
GrResourceProvider::kRequireGpuMemory_Flag,
|
|
|
|
fView->fGpuPoints.begin()));
|
|
|
|
if (!pointsBuffer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-05 06:30:07 +00:00
|
|
|
sk_sp<GrBuffer> instanceBuffer(rp->createBuffer(fView->fInstanceData.count() * sizeof(int),
|
2017-07-14 21:17:41 +00:00
|
|
|
kVertex_GrBufferType, kDynamic_GrAccessPattern,
|
|
|
|
GrResourceProvider::kNoPendingIO_Flag |
|
|
|
|
GrResourceProvider::kRequireGpuMemory_Flag,
|
2017-09-05 06:30:07 +00:00
|
|
|
fView->fInstanceData.begin()));
|
2017-07-14 21:17:41 +00:00
|
|
|
if (!instanceBuffer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-26 19:48:41 +00:00
|
|
|
GrPipeline pipeline(state->drawOpArgs().fProxy, GrPipeline::ScissorState::kDisabled,
|
2017-07-14 21:17:41 +00:00
|
|
|
SkBlendMode::kSrcOver);
|
|
|
|
|
2017-10-16 16:44:41 +00:00
|
|
|
GrCCPRCoverageProcessor ccprProc(fView->fRenderPass, pointsBuffer.get());
|
2017-09-12 05:04:03 +00:00
|
|
|
SkDEBUGCODE(ccprProc.enableDebugVisualizations(kDebugBloat);)
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
GrMesh mesh(4 == vertexCount ? GrPrimitiveType::kLinesAdjacency : GrPrimitiveType::kTriangles);
|
2017-09-05 06:30:07 +00:00
|
|
|
mesh.setInstanced(instanceBuffer.get(), fView->fInstanceCount, 0, vertexCount);
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
if (glGpu) {
|
|
|
|
glGpu->handleDirtyContext();
|
|
|
|
GR_GL_CALL(glGpu->glInterface(), PolygonMode(GR_GL_FRONT_AND_BACK, GR_GL_LINE));
|
|
|
|
GR_GL_CALL(glGpu->glInterface(), Enable(GR_GL_LINE_SMOOTH));
|
|
|
|
}
|
|
|
|
|
2017-08-24 19:59:33 +00:00
|
|
|
state->rtCommandBuffer()->draw(pipeline, ccprProc, &mesh, nullptr, 1, this->bounds());
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
if (glGpu) {
|
|
|
|
context->resetContext(kMisc_GrGLBackendState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CCPRGeometryView::Click : public SampleView::Click {
|
|
|
|
public:
|
|
|
|
Click(SkView* target, int ptIdx) : SampleView::Click(target), fPtIdx(ptIdx) {}
|
|
|
|
|
|
|
|
void doClick(SkPoint points[]) {
|
|
|
|
if (fPtIdx >= 0) {
|
|
|
|
this->dragPoint(points, fPtIdx);
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
this->dragPoint(points, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void dragPoint(SkPoint points[], int idx) {
|
|
|
|
SkIPoint delta = fICurr - fIPrev;
|
|
|
|
points[idx] += SkPoint::Make(delta.x(), delta.y());
|
|
|
|
}
|
|
|
|
|
|
|
|
int fPtIdx;
|
|
|
|
};
|
|
|
|
|
|
|
|
SkView::Click* CCPRGeometryView::onFindClickHandler(SkScalar x, SkScalar y, unsigned) {
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
2017-10-16 16:44:41 +00:00
|
|
|
if (4 != num_points(fRenderPass) && 2 == i) {
|
2017-07-14 21:17:41 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (fabs(x - fPoints[i].x()) < 20 && fabsf(y - fPoints[i].y()) < 20) {
|
|
|
|
return new Click(this, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new Click(this, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCPRGeometryView::onClick(SampleView::Click* click) {
|
|
|
|
Click* myClick = (Click*) click;
|
|
|
|
myClick->doClick(fPoints);
|
|
|
|
this->updateAndInval();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCPRGeometryView::onQuery(SkEvent* evt) {
|
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
|
|
|
SampleCode::TitleR(evt, "CCPRGeometry");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
SkUnichar unichar;
|
|
|
|
if (SampleCode::CharQ(*evt, &unichar)) {
|
|
|
|
if (unichar >= '1' && unichar <= '7') {
|
2017-10-16 16:44:41 +00:00
|
|
|
fRenderPass = RenderPass(unichar - '1');
|
|
|
|
if (fRenderPass >= RenderPass::kLoopHulls) {
|
2017-09-05 22:46:48 +00:00
|
|
|
// '6' -> kSerpentineHulls, '7' -> kSerpentineCorners. updateGpuData converts to
|
|
|
|
// kLoop* if needed.
|
2017-10-16 16:44:41 +00:00
|
|
|
fRenderPass = RenderPass(int(fRenderPass) + 1);
|
2017-09-05 22:46:48 +00:00
|
|
|
}
|
2017-07-14 21:17:41 +00:00
|
|
|
this->updateAndInval();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (unichar == 'D') {
|
|
|
|
SkDebugf(" SkPoint fPoints[4] = {\n");
|
2017-09-05 22:46:48 +00:00
|
|
|
SkDebugf(" {%ff, %ff},\n", fPoints[0].x(), fPoints[0].y());
|
|
|
|
SkDebugf(" {%ff, %ff},\n", fPoints[1].x(), fPoints[1].y());
|
|
|
|
SkDebugf(" {%ff, %ff},\n", fPoints[2].x(), fPoints[2].y());
|
|
|
|
SkDebugf(" {%ff, %ff}\n", fPoints[3].x(), fPoints[3].y());
|
2017-07-14 21:17:41 +00:00
|
|
|
SkDebugf(" };\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_SAMPLE( return new CCPRGeometryView; )
|
|
|
|
|
|
|
|
#endif // SK_SUPPORT_GPU
|