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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPath.h"
|
2020-07-09 17:25:17 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "samplecode/Sample.h"
|
|
|
|
#include "src/core/SkRectPriv.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2020-03-19 19:54:28 +00:00
|
|
|
#include "src/gpu/GrGpu.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrMemoryPool.h"
|
2020-04-06 17:57:30 +00:00
|
|
|
#include "src/gpu/GrOnFlushResourceProvider.h"
|
|
|
|
#include "src/gpu/GrOpFlushState.h"
|
2020-07-09 17:25:17 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrRenderTargetContext.h"
|
|
|
|
#include "src/gpu/GrRenderTargetContextPriv.h"
|
|
|
|
#include "src/gpu/GrResourceProvider.h"
|
|
|
|
#include "src/gpu/ccpr/GrCCCoverageProcessor.h"
|
|
|
|
#include "src/gpu/ccpr/GrCCFillGeometry.h"
|
|
|
|
#include "src/gpu/ccpr/GrGSCoverageProcessor.h"
|
|
|
|
#include "src/gpu/ccpr/GrVSCoverageProcessor.h"
|
2019-06-03 20:46:19 +00:00
|
|
|
#include "src/gpu/geometry/GrPathUtils.h"
|
2019-11-26 21:20:22 +00:00
|
|
|
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/ops/GrDrawOp.h"
|
2017-07-14 21:17:41 +00:00
|
|
|
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifdef SK_GL
|
|
|
|
#include "src/gpu/gl/GrGLGpu.h"
|
|
|
|
#endif
|
|
|
|
|
2018-02-14 02:46:17 +00:00
|
|
|
using TriPointInstance = GrCCCoverageProcessor::TriPointInstance;
|
|
|
|
using QuadPointInstance = GrCCCoverageProcessor::QuadPointInstance;
|
2018-03-27 01:15:22 +00:00
|
|
|
using PrimitiveType = GrCCCoverageProcessor::PrimitiveType;
|
2017-07-14 21:17:41 +00:00
|
|
|
|
2017-09-12 05:04:03 +00:00
|
|
|
static constexpr float kDebugBloat = 40;
|
|
|
|
|
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.
|
|
|
|
*/
|
2018-08-08 15:36:17 +00:00
|
|
|
class CCPRGeometryView : public Sample {
|
2019-07-17 13:08:11 +00:00
|
|
|
void onOnceBeforeDraw() override { this->updateGpuData(); }
|
2017-07-14 21:17:41 +00:00
|
|
|
void onDrawContent(SkCanvas*) override;
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override;
|
2018-08-08 15:36:17 +00:00
|
|
|
bool onClick(Sample::Click*) override;
|
2019-07-03 19:53:04 +00:00
|
|
|
bool onChar(SkUnichar) override;
|
2019-07-03 14:55:44 +00:00
|
|
|
SkString name() override { return SkString("CCPRGeometry"); }
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
class Click;
|
2018-03-19 20:16:44 +00:00
|
|
|
class DrawCoverageCountOp;
|
|
|
|
class VisualizeCoverageCountFP;
|
2017-07-14 21:17:41 +00:00
|
|
|
|
2018-01-08 22:21:41 +00:00
|
|
|
void updateAndInval() { this->updateGpuData(); }
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
void updateGpuData();
|
|
|
|
|
2020-07-23 21:36:25 +00:00
|
|
|
PrimitiveType fPrimitiveType = PrimitiveType::kCubics;
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
SkPoint fPoints[4] = {
|
2018-01-08 22:21:41 +00:00
|
|
|
{100.05f, 100.05f}, {400.75f, 100.05f}, {400.75f, 300.95f}, {100.05f, 300.95f}};
|
2017-07-14 21:17:41 +00:00
|
|
|
|
2018-04-18 20:07:03 +00:00
|
|
|
float fConicWeight = .5;
|
2018-08-31 11:53:15 +00:00
|
|
|
float fStrokeWidth = 40;
|
2020-07-23 21:36:25 +00:00
|
|
|
SkPaint::Join fStrokeJoin = SkPaint::kMiter_Join;
|
|
|
|
SkPaint::Cap fStrokeCap = SkPaint::kButt_Cap;
|
|
|
|
bool fDoStroke = true;
|
2018-04-18 20:07:03 +00:00
|
|
|
|
2018-02-14 02:46:17 +00:00
|
|
|
SkTArray<TriPointInstance> fTriPointInstances;
|
|
|
|
SkTArray<QuadPointInstance> fQuadPointInstances;
|
2018-08-31 11:53:15 +00:00
|
|
|
SkPath fPath;
|
2017-07-14 21:17:41 +00:00
|
|
|
};
|
|
|
|
|
2018-03-19 20:16:44 +00:00
|
|
|
class CCPRGeometryView::DrawCoverageCountOp : public GrDrawOp {
|
2017-07-14 21:17:41 +00:00
|
|
|
DEFINE_OP_CLASS_ID
|
|
|
|
|
|
|
|
public:
|
2018-03-19 20:16:44 +00:00
|
|
|
DrawCoverageCountOp(CCPRGeometryView* view) : INHERITED(ClassID()), fView(view) {
|
2018-08-20 20:00:30 +00:00
|
|
|
this->setBounds(SkRect::MakeIWH(fView->width(), fView->height()), GrOp::HasAABloat::kNo,
|
2019-10-01 19:14:44 +00:00
|
|
|
GrOp::IsHairline::kNo);
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 20:16:44 +00:00
|
|
|
const char* name() const override {
|
|
|
|
return "[Testing/Sample code] CCPRGeometryView::DrawCoverageCountOp";
|
|
|
|
}
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
2019-06-24 00:07:38 +00:00
|
|
|
GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
|
|
|
|
bool hasMixedSampledCoverage, GrClampType) override {
|
2019-01-15 18:53:00 +00:00
|
|
|
return GrProcessorSet::EmptySetAnalysis();
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
2020-03-18 17:23:45 +00:00
|
|
|
void onPrePrepare(GrRecordingContext*,
|
2020-04-01 20:22:00 +00:00
|
|
|
const GrSurfaceProxyView* writeView,
|
2020-03-18 17:23:45 +00:00
|
|
|
GrAppliedClip*,
|
2020-09-11 13:33:54 +00:00
|
|
|
const GrXferProcessor::DstProxyView&,
|
|
|
|
GrXferBarrierFlags renderPassXferBarriers) override {}
|
2017-07-14 21:17:41 +00:00
|
|
|
void onPrepare(GrOpFlushState*) override {}
|
2018-11-14 18:56:37 +00:00
|
|
|
void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
CCPRGeometryView* fView;
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GrDrawOp;
|
2017-07-14 21:17:41 +00:00
|
|
|
};
|
|
|
|
|
2018-03-19 20:16:44 +00:00
|
|
|
class CCPRGeometryView::VisualizeCoverageCountFP : public GrFragmentProcessor {
|
|
|
|
public:
|
2020-07-21 16:05:47 +00:00
|
|
|
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> inputFP) {
|
|
|
|
return std::unique_ptr<GrFragmentProcessor>(
|
|
|
|
new VisualizeCoverageCountFP(std::move(inputFP)));
|
|
|
|
}
|
2018-03-19 20:16:44 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const char* name() const override {
|
2020-07-21 16:05:47 +00:00
|
|
|
return "VisualizeCoverageCountFP";
|
2018-03-19 20:16:44 +00:00
|
|
|
}
|
|
|
|
std::unique_ptr<GrFragmentProcessor> clone() const override {
|
2020-07-21 16:05:47 +00:00
|
|
|
return std::unique_ptr<GrFragmentProcessor>(new VisualizeCoverageCountFP(*this));
|
|
|
|
}
|
|
|
|
VisualizeCoverageCountFP(std::unique_ptr<GrFragmentProcessor> inputFP)
|
|
|
|
: GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags) {
|
|
|
|
this->registerChild(std::move(inputFP));
|
|
|
|
}
|
|
|
|
VisualizeCoverageCountFP(const VisualizeCoverageCountFP& that)
|
|
|
|
: GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags) {
|
|
|
|
this->cloneAndRegisterAllChildProcessors(that);
|
2018-03-19 20:16:44 +00:00
|
|
|
}
|
|
|
|
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
|
|
|
|
bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
|
|
|
|
|
|
|
|
class Impl : public GrGLSLFragmentProcessor {
|
|
|
|
void emitCode(EmitArgs& args) override {
|
|
|
|
GrGLSLFPFragmentBuilder* f = args.fFragBuilder;
|
2020-07-21 16:05:47 +00:00
|
|
|
static constexpr int kInputFPIndex = 0;
|
|
|
|
SkString inputColor = this->invokeChild(kInputFPIndex, args);
|
|
|
|
f->codeAppendf("half count = %s.a;", inputColor.c_str());
|
2018-03-19 20:16:44 +00:00
|
|
|
f->codeAppendf("%s = half4(clamp(-count, 0, 1), clamp(+count, 0, 1), 0, abs(count));",
|
|
|
|
args.fOutputColor);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new Impl; }
|
|
|
|
};
|
|
|
|
|
2017-07-14 21:17:41 +00:00
|
|
|
void CCPRGeometryView::onDrawContent(SkCanvas* canvas) {
|
2018-03-09 18:57:40 +00:00
|
|
|
canvas->clear(SK_ColorBLACK);
|
2017-07-14 21:17:41 +00:00
|
|
|
|
2020-07-23 21:36:25 +00:00
|
|
|
SkPaint outlinePaint;
|
|
|
|
outlinePaint.setColor(0xff808080);
|
|
|
|
outlinePaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
if (fDoStroke) {
|
|
|
|
outlinePaint.setStrokeWidth(fStrokeWidth);
|
|
|
|
} else {
|
2018-08-31 11:53:15 +00:00
|
|
|
outlinePaint.setStrokeWidth(0);
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
2020-07-23 21:36:25 +00:00
|
|
|
outlinePaint.setStrokeJoin(fStrokeJoin);
|
|
|
|
outlinePaint.setStrokeCap(fStrokeCap);
|
|
|
|
outlinePaint.setAntiAlias(true);
|
|
|
|
canvas->drawPath(fPath, outlinePaint);
|
2017-07-14 21:17:41 +00:00
|
|
|
|
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-12-08 17:59:58 +00:00
|
|
|
SkString caption;
|
2020-07-23 21:36:25 +00:00
|
|
|
caption.appendf("PrimitiveType_%s",
|
|
|
|
GrCCCoverageProcessor::PrimitiveTypeName(fPrimitiveType));
|
|
|
|
if (PrimitiveType::kCubics == fPrimitiveType) {
|
2020-10-30 18:26:20 +00:00
|
|
|
caption.appendf(" (%s)", SkCubicTypeName(SkClassifyCubic(fPoints)));
|
2020-07-23 21:36:25 +00:00
|
|
|
} else if (PrimitiveType::kConics == fPrimitiveType) {
|
|
|
|
caption.appendf(" (w=%f)", fConicWeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fDoStroke) {
|
|
|
|
caption.appendf(" (stroke_width=%f)", fStrokeWidth);
|
|
|
|
} else if (GrRenderTargetContext* rtc =
|
|
|
|
canvas->internal_private_accessTopLayerRenderTargetContext()) {
|
2018-03-19 20:16:44 +00:00
|
|
|
// Render coverage count.
|
2020-07-09 17:25:17 +00:00
|
|
|
auto ctx = canvas->recordingContext();
|
2018-08-20 20:00:30 +00:00
|
|
|
SkASSERT(ctx);
|
|
|
|
|
2020-01-08 16:52:34 +00:00
|
|
|
int width = this->width();
|
|
|
|
int height = this->height();
|
|
|
|
auto ccbuff = GrRenderTargetContext::Make(
|
|
|
|
ctx, GrColorType::kAlpha_F16, nullptr, SkBackingFit::kApprox, {width, height});
|
2018-03-19 20:16:44 +00:00
|
|
|
SkASSERT(ccbuff);
|
2020-05-26 20:57:38 +00:00
|
|
|
ccbuff->clear(SK_PMColor4fTRANSPARENT);
|
2020-10-07 20:46:15 +00:00
|
|
|
ccbuff->priv().testingOnly_addDrawOp(GrOp::Make<DrawCoverageCountOp>(ctx, this));
|
2018-03-19 20:16:44 +00:00
|
|
|
|
|
|
|
// Visualize coverage count in main canvas.
|
|
|
|
GrPaint paint;
|
2020-07-21 16:28:35 +00:00
|
|
|
paint.setColorFragmentProcessor(VisualizeCoverageCountFP::Make(
|
2020-07-21 16:05:47 +00:00
|
|
|
GrTextureEffect::Make(ccbuff->readSurfaceView(), ccbuff->colorInfo().alphaType())));
|
2018-03-19 20:16:44 +00:00
|
|
|
paint.setPorterDuffXPFactory(SkBlendMode::kSrcOver);
|
2020-05-29 13:54:07 +00:00
|
|
|
rtc->drawRect(nullptr, std::move(paint), GrAA::kNo, SkMatrix::I(),
|
2018-03-19 20:16:44 +00:00
|
|
|
SkRect::MakeIWH(this->width(), this->height()));
|
2017-12-08 17:59:58 +00:00
|
|
|
} else {
|
|
|
|
caption = "Use GPU backend to visualize geometry.";
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint pointsPaint;
|
|
|
|
pointsPaint.setColor(SK_ColorBLUE);
|
|
|
|
pointsPaint.setStrokeWidth(8);
|
|
|
|
pointsPaint.setAntiAlias(true);
|
|
|
|
|
2018-03-27 01:15:22 +00:00
|
|
|
if (PrimitiveType::kCubics == fPrimitiveType) {
|
2017-07-14 21:17:41 +00:00
|
|
|
canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, fPoints, pointsPaint);
|
|
|
|
} else {
|
|
|
|
canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, fPoints, pointsPaint);
|
|
|
|
canvas->drawPoints(SkCanvas::kPoints_PointMode, 1, fPoints + 3, pointsPaint);
|
|
|
|
}
|
|
|
|
|
2019-01-08 19:00:08 +00:00
|
|
|
SkFont font(nullptr, 20);
|
2017-07-14 21:17:41 +00:00
|
|
|
SkPaint captionPaint;
|
2018-03-09 18:57:40 +00:00
|
|
|
captionPaint.setColor(SK_ColorWHITE);
|
2019-01-08 19:00:08 +00:00
|
|
|
canvas->drawString(caption, 10, 30, font, captionPaint);
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCPRGeometryView::updateGpuData() {
|
2018-08-20 20:00:30 +00:00
|
|
|
using Verb = GrCCFillGeometry::Verb;
|
2018-02-14 02:46:17 +00:00
|
|
|
fTriPointInstances.reset();
|
|
|
|
fQuadPointInstances.reset();
|
2017-07-14 21:17:41 +00:00
|
|
|
|
2018-08-31 11:53:15 +00:00
|
|
|
fPath.reset();
|
|
|
|
fPath.moveTo(fPoints[0]);
|
|
|
|
|
2018-03-27 01:15:22 +00:00
|
|
|
if (PrimitiveType::kCubics == fPrimitiveType) {
|
2018-08-20 20:00:30 +00:00
|
|
|
GrCCFillGeometry geometry;
|
2017-09-05 22:46:48 +00:00
|
|
|
geometry.beginContour(fPoints[0]);
|
2018-04-10 06:21:19 +00:00
|
|
|
geometry.cubicTo(fPoints, kDebugBloat / 2, kDebugBloat / 2);
|
2017-09-05 22:46:48 +00:00
|
|
|
geometry.endContour();
|
|
|
|
int ptsIdx = 0;
|
2018-08-20 20:00:30 +00:00
|
|
|
for (Verb verb : geometry.verbs()) {
|
2017-09-05 22:46:48 +00:00
|
|
|
switch (verb) {
|
2018-08-20 20:00:30 +00:00
|
|
|
case Verb::kLineTo:
|
2017-09-05 22:46:48 +00:00
|
|
|
++ptsIdx;
|
|
|
|
continue;
|
2018-08-20 20:00:30 +00:00
|
|
|
case Verb::kMonotonicQuadraticTo:
|
2017-09-05 22:46:48 +00:00
|
|
|
ptsIdx += 2;
|
|
|
|
continue;
|
2018-08-20 20:00:30 +00:00
|
|
|
case Verb::kMonotonicCubicTo:
|
2018-02-14 02:46:17 +00:00
|
|
|
fQuadPointInstances.push_back().set(&geometry.points()[ptsIdx], 0, 0);
|
2017-09-05 22:46:48 +00:00
|
|
|
ptsIdx += 3;
|
|
|
|
continue;
|
2018-01-08 22:21:41 +00:00
|
|
|
default:
|
|
|
|
continue;
|
2017-09-05 22:46:48 +00:00
|
|
|
}
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
2018-08-31 11:53:15 +00:00
|
|
|
fPath.cubicTo(fPoints[1], fPoints[2], fPoints[3]);
|
2018-04-18 20:07:03 +00:00
|
|
|
} else if (PrimitiveType::kTriangles != fPrimitiveType) {
|
2018-04-10 06:21:19 +00:00
|
|
|
SkPoint P3[3] = {fPoints[0], fPoints[1], fPoints[3]};
|
2018-08-20 20:00:30 +00:00
|
|
|
GrCCFillGeometry geometry;
|
2018-04-10 06:21:19 +00:00
|
|
|
geometry.beginContour(P3[0]);
|
2018-04-18 20:07:03 +00:00
|
|
|
if (PrimitiveType::kQuadratics == fPrimitiveType) {
|
|
|
|
geometry.quadraticTo(P3);
|
2018-08-31 11:53:15 +00:00
|
|
|
fPath.quadTo(fPoints[1], fPoints[3]);
|
2018-04-18 20:07:03 +00:00
|
|
|
} else {
|
|
|
|
SkASSERT(PrimitiveType::kConics == fPrimitiveType);
|
|
|
|
geometry.conicTo(P3, fConicWeight);
|
2018-08-31 11:53:15 +00:00
|
|
|
fPath.conicTo(fPoints[1], fPoints[3], fConicWeight);
|
2018-04-18 20:07:03 +00:00
|
|
|
}
|
2017-09-05 06:30:07 +00:00
|
|
|
geometry.endContour();
|
2018-04-18 20:07:03 +00:00
|
|
|
int ptsIdx = 0, conicWeightIdx = 0;
|
2018-08-20 20:00:30 +00:00
|
|
|
for (Verb verb : geometry.verbs()) {
|
|
|
|
if (Verb::kBeginContour == verb ||
|
|
|
|
Verb::kEndOpenContour == verb ||
|
|
|
|
Verb::kEndClosedContour == verb) {
|
2017-09-05 06:30:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-08-20 20:00:30 +00:00
|
|
|
if (Verb::kLineTo == verb) {
|
2017-12-22 09:24:53 +00:00
|
|
|
++ptsIdx;
|
|
|
|
continue;
|
|
|
|
}
|
2018-08-20 20:00:30 +00:00
|
|
|
SkASSERT(Verb::kMonotonicQuadraticTo == verb || Verb::kMonotonicConicTo == verb);
|
2018-04-18 20:07:03 +00:00
|
|
|
if (PrimitiveType::kQuadratics == fPrimitiveType &&
|
2018-08-20 20:00:30 +00:00
|
|
|
Verb::kMonotonicQuadraticTo == verb) {
|
2019-07-19 20:20:53 +00:00
|
|
|
fTriPointInstances.push_back().set(
|
|
|
|
&geometry.points()[ptsIdx], Sk2f(0, 0),
|
|
|
|
TriPointInstance::Ordering::kXYTransposed);
|
2018-04-18 20:07:03 +00:00
|
|
|
} else if (PrimitiveType::kConics == fPrimitiveType &&
|
2018-08-20 20:00:30 +00:00
|
|
|
Verb::kMonotonicConicTo == verb) {
|
2018-04-18 20:07:03 +00:00
|
|
|
fQuadPointInstances.push_back().setW(&geometry.points()[ptsIdx], Sk2f(0, 0),
|
|
|
|
geometry.getConicWeight(conicWeightIdx++));
|
|
|
|
}
|
2017-12-04 18:45:51 +00:00
|
|
|
ptsIdx += 2;
|
2017-08-07 15:00:46 +00:00
|
|
|
}
|
2017-07-14 21:17:41 +00:00
|
|
|
} else {
|
2019-07-19 20:20:53 +00:00
|
|
|
fTriPointInstances.push_back().set(
|
|
|
|
fPoints[0], fPoints[1], fPoints[3], Sk2f(0, 0),
|
|
|
|
TriPointInstance::Ordering::kXYTransposed);
|
2018-08-31 11:53:15 +00:00
|
|
|
fPath.lineTo(fPoints[1]);
|
|
|
|
fPath.lineTo(fPoints[3]);
|
|
|
|
fPath.close();
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-14 18:56:37 +00:00
|
|
|
void CCPRGeometryView::DrawCoverageCountOp::onExecute(GrOpFlushState* state,
|
|
|
|
const SkRect& chainBounds) {
|
2017-07-14 21:17:41 +00:00
|
|
|
GrResourceProvider* rp = state->resourceProvider();
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifdef SK_GL
|
2020-07-23 21:36:25 +00:00
|
|
|
auto direct = state->gpu()->getContext();
|
2020-07-09 17:25:17 +00:00
|
|
|
GrGLGpu* glGpu = GrBackendApi::kOpenGL == direct->backend()
|
2018-01-08 22:21:41 +00:00
|
|
|
? static_cast<GrGLGpu*>(state->gpu())
|
|
|
|
: nullptr;
|
2017-07-14 21:17:41 +00:00
|
|
|
if (glGpu) {
|
|
|
|
glGpu->handleDirtyContext();
|
2018-03-09 18:57:40 +00:00
|
|
|
// GR_GL_CALL(glGpu->glInterface(), PolygonMode(GR_GL_FRONT_AND_BACK, GR_GL_LINE));
|
2017-07-14 21:17:41 +00:00
|
|
|
GR_GL_CALL(glGpu->glInterface(), Enable(GR_GL_LINE_SMOOTH));
|
|
|
|
}
|
2020-03-19 19:54:28 +00:00
|
|
|
#endif
|
2017-07-14 21:17:41 +00:00
|
|
|
|
2019-06-19 15:58:01 +00:00
|
|
|
GrPipeline pipeline(GrScissorTest::kDisabled, SkBlendMode::kPlus,
|
2020-03-30 16:52:33 +00:00
|
|
|
state->drawOpArgs().writeSwizzle());
|
2018-08-31 11:53:15 +00:00
|
|
|
|
2019-03-29 18:14:18 +00:00
|
|
|
std::unique_ptr<GrCCCoverageProcessor> proc;
|
|
|
|
if (state->caps().shaderCaps()->geometryShaderSupport()) {
|
2019-12-11 15:45:01 +00:00
|
|
|
proc = std::make_unique<GrGSCoverageProcessor>();
|
2019-03-29 18:14:18 +00:00
|
|
|
} else {
|
2019-12-11 15:45:01 +00:00
|
|
|
proc = std::make_unique<GrVSCoverageProcessor>();
|
2019-03-29 18:14:18 +00:00
|
|
|
}
|
2020-03-10 16:34:17 +00:00
|
|
|
SkDEBUGCODE(proc->enableDebugBloat(kDebugBloat));
|
|
|
|
|
|
|
|
GrOpsRenderPass* renderPass = state->opsRenderPass();
|
2019-03-29 18:14:18 +00:00
|
|
|
|
2020-07-23 21:36:25 +00:00
|
|
|
for (int i = 0; i < proc->numSubpasses(); ++i) {
|
|
|
|
proc->reset(fView->fPrimitiveType, i, rp);
|
|
|
|
proc->bindPipeline(state, pipeline, this->bounds());
|
|
|
|
|
|
|
|
if (PrimitiveType::kCubics == fView->fPrimitiveType ||
|
|
|
|
PrimitiveType::kConics == fView->fPrimitiveType) {
|
|
|
|
sk_sp<GrGpuBuffer> instBuff(rp->createBuffer(
|
|
|
|
fView->fQuadPointInstances.count() * sizeof(QuadPointInstance),
|
|
|
|
GrGpuBufferType::kVertex, kDynamic_GrAccessPattern,
|
|
|
|
fView->fQuadPointInstances.begin()));
|
|
|
|
if (!fView->fQuadPointInstances.empty() && instBuff) {
|
|
|
|
proc->bindBuffers(renderPass, std::move(instBuff));
|
|
|
|
proc->drawInstances(renderPass, fView->fQuadPointInstances.count(), 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sk_sp<GrGpuBuffer> instBuff(rp->createBuffer(
|
|
|
|
fView->fTriPointInstances.count() * sizeof(TriPointInstance),
|
|
|
|
GrGpuBufferType::kVertex, kDynamic_GrAccessPattern,
|
|
|
|
fView->fTriPointInstances.begin()));
|
|
|
|
if (!fView->fTriPointInstances.empty() && instBuff) {
|
|
|
|
proc->bindBuffers(renderPass, std::move(instBuff));
|
|
|
|
proc->drawInstances(renderPass, fView->fTriPointInstances.count(), 0);
|
2018-08-31 11:53:15 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-10 23:41:45 +00:00
|
|
|
}
|
2017-07-14 21:17:41 +00:00
|
|
|
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifdef SK_GL
|
2017-07-14 21:17:41 +00:00
|
|
|
if (glGpu) {
|
2020-07-09 17:25:17 +00:00
|
|
|
direct->resetContext(kMisc_GrGLBackendState);
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
2020-03-19 19:54:28 +00:00
|
|
|
#endif
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class CCPRGeometryView::Click : public Sample::Click {
|
2017-07-14 21:17:41 +00:00
|
|
|
public:
|
2019-07-12 15:32:43 +00:00
|
|
|
Click(int ptIdx) : fPtIdx(ptIdx) {}
|
2017-07-14 21:17:41 +00:00
|
|
|
|
|
|
|
void doClick(SkPoint points[]) {
|
|
|
|
if (fPtIdx >= 0) {
|
2019-07-12 15:32:43 +00:00
|
|
|
points[fPtIdx] += fCurr - fPrev;
|
2017-07-14 21:17:41 +00:00
|
|
|
} else {
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
2019-07-12 15:32:43 +00:00
|
|
|
points[i] += fCurr - fPrev;
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int fPtIdx;
|
|
|
|
};
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
Sample::Click* CCPRGeometryView::onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) {
|
2017-07-14 21:17:41 +00:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
2018-03-27 01:15:22 +00:00
|
|
|
if (PrimitiveType::kCubics != fPrimitiveType && 2 == i) {
|
2017-07-14 21:17:41 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (fabs(x - fPoints[i].x()) < 20 && fabsf(y - fPoints[i].y()) < 20) {
|
2019-07-12 15:32:43 +00:00
|
|
|
return new Click(i);
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-12 15:32:43 +00:00
|
|
|
return new Click(-1);
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
bool CCPRGeometryView::onClick(Sample::Click* click) {
|
2018-01-08 22:21:41 +00:00
|
|
|
Click* myClick = (Click*)click;
|
2017-07-14 21:17:41 +00:00
|
|
|
myClick->doClick(fPoints);
|
|
|
|
this->updateAndInval();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-03 19:53:04 +00:00
|
|
|
bool CCPRGeometryView::onChar(SkUnichar unichar) {
|
2018-04-18 20:07:03 +00:00
|
|
|
if (unichar >= '1' && unichar <= '4') {
|
2018-03-27 01:15:22 +00:00
|
|
|
fPrimitiveType = PrimitiveType(unichar - '1');
|
2018-04-06 22:11:48 +00:00
|
|
|
if (fPrimitiveType >= PrimitiveType::kWeightedTriangles) {
|
|
|
|
fPrimitiveType = (PrimitiveType) ((int)fPrimitiveType + 1);
|
|
|
|
}
|
2017-07-14 21:17:41 +00:00
|
|
|
this->updateAndInval();
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-31 11:53:15 +00:00
|
|
|
float* valueToScale = nullptr;
|
|
|
|
if (fDoStroke) {
|
|
|
|
valueToScale = &fStrokeWidth;
|
|
|
|
} else if (PrimitiveType::kConics == fPrimitiveType) {
|
|
|
|
valueToScale = &fConicWeight;
|
|
|
|
}
|
|
|
|
if (valueToScale) {
|
2018-04-18 20:07:03 +00:00
|
|
|
if (unichar == '+') {
|
2018-08-31 11:53:15 +00:00
|
|
|
*valueToScale *= 2;
|
2018-04-18 20:07:03 +00:00
|
|
|
this->updateAndInval();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (unichar == '+' || unichar == '=') {
|
2018-08-31 11:53:15 +00:00
|
|
|
*valueToScale *= 5/4.f;
|
2018-04-18 20:07:03 +00:00
|
|
|
this->updateAndInval();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (unichar == '-') {
|
2018-08-31 11:53:15 +00:00
|
|
|
*valueToScale *= 4/5.f;
|
2018-04-18 20:07:03 +00:00
|
|
|
this->updateAndInval();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (unichar == '_') {
|
2018-08-31 11:53:15 +00:00
|
|
|
*valueToScale *= .5f;
|
2018-04-18 20:07:03 +00:00
|
|
|
this->updateAndInval();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-07-14 21:17:41 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-08-31 11:53:15 +00:00
|
|
|
if (unichar == 'S') {
|
|
|
|
fDoStroke = !fDoStroke;
|
|
|
|
this->updateAndInval();
|
2020-07-23 21:36:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (unichar == 'J') {
|
|
|
|
fStrokeJoin = (SkPaint::Join)((fStrokeJoin + 1) % 3);
|
|
|
|
this->updateAndInval();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (unichar == 'C') {
|
|
|
|
fStrokeCap = (SkPaint::Cap)((fStrokeCap + 1) % 3);
|
|
|
|
this->updateAndInval();
|
|
|
|
return true;
|
2018-08-31 11:53:15 +00:00
|
|
|
}
|
2019-07-03 19:53:04 +00:00
|
|
|
return false;
|
2017-07-14 21:17:41 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 22:21:41 +00:00
|
|
|
DEF_SAMPLE(return new CCPRGeometryView;)
|
2017-07-14 21:17:41 +00:00
|
|
|
|
2018-01-08 22:21:41 +00:00
|
|
|
#endif // SK_SUPPORT_GPU
|