Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkTypes.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 9 | |
| 10 | #if SK_SUPPORT_GPU |
| 11 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkCanvas.h" |
| 13 | #include "include/core/SkPaint.h" |
| 14 | #include "include/core/SkPath.h" |
Robert Phillips | 30ebcf7 | 2020-07-09 13:25:17 -0400 | [diff] [blame] | 15 | #include "include/gpu/GrDirectContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "samplecode/Sample.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/core/SkRectPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrContextPriv.h" |
Brian Salomon | f4ba4ec | 2020-03-19 15:54:28 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrGpu.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrMemoryPool.h" |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 21 | #include "src/gpu/GrOnFlushResourceProvider.h" |
| 22 | #include "src/gpu/GrOpFlushState.h" |
Robert Phillips | 30ebcf7 | 2020-07-09 13:25:17 -0400 | [diff] [blame] | 23 | #include "src/gpu/GrRecordingContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "src/gpu/GrRenderTargetContext.h" |
| 25 | #include "src/gpu/GrRenderTargetContextPriv.h" |
| 26 | #include "src/gpu/GrResourceProvider.h" |
| 27 | #include "src/gpu/ccpr/GrCCCoverageProcessor.h" |
| 28 | #include "src/gpu/ccpr/GrCCFillGeometry.h" |
| 29 | #include "src/gpu/ccpr/GrCCStroker.h" |
| 30 | #include "src/gpu/ccpr/GrGSCoverageProcessor.h" |
| 31 | #include "src/gpu/ccpr/GrVSCoverageProcessor.h" |
Michael Ludwig | 663afe5 | 2019-06-03 16:46:19 -0400 | [diff] [blame] | 32 | #include "src/gpu/geometry/GrPathUtils.h" |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 33 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 34 | #include "src/gpu/ops/GrDrawOp.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 35 | |
Brian Salomon | f4ba4ec | 2020-03-19 15:54:28 -0400 | [diff] [blame] | 36 | #ifdef SK_GL |
| 37 | #include "src/gpu/gl/GrGLGpu.h" |
| 38 | #endif |
| 39 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 40 | using TriPointInstance = GrCCCoverageProcessor::TriPointInstance; |
| 41 | using QuadPointInstance = GrCCCoverageProcessor::QuadPointInstance; |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 42 | using PrimitiveType = GrCCCoverageProcessor::PrimitiveType; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 43 | |
Chris Dalton | a640c49 | 2017-09-11 22:04:03 -0700 | [diff] [blame] | 44 | static constexpr float kDebugBloat = 40; |
| 45 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 46 | /** |
| 47 | * This sample visualizes the AA bloat geometry generated by the ccpr geometry shaders. It |
| 48 | * increases the AA bloat by 50x and outputs color instead of coverage (coverage=+1 -> green, |
| 49 | * coverage=0 -> black, coverage=-1 -> red). Use the keys 1-7 to cycle through the different |
| 50 | * geometry processors. |
| 51 | */ |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 52 | class CCPRGeometryView : public Sample { |
Hal Canary | d7639af | 2019-07-17 09:08:11 -0400 | [diff] [blame] | 53 | void onOnceBeforeDraw() override { this->updateGpuData(); } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 54 | void onDrawContent(SkCanvas*) override; |
| 55 | |
Hal Canary | b1f411a | 2019-08-29 10:39:22 -0400 | [diff] [blame] | 56 | Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override; |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 57 | bool onClick(Sample::Click*) override; |
Hal Canary | 6cc65e1 | 2019-07-03 15:53:04 -0400 | [diff] [blame] | 58 | bool onChar(SkUnichar) override; |
Hal Canary | 8a02731 | 2019-07-03 10:55:44 -0400 | [diff] [blame] | 59 | SkString name() override { return SkString("CCPRGeometry"); } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 60 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 61 | class Click; |
Chris Dalton | 8d38a7f | 2018-03-19 14:16:44 -0600 | [diff] [blame] | 62 | class DrawCoverageCountOp; |
| 63 | class VisualizeCoverageCountFP; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 64 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 65 | void updateAndInval() { this->updateGpuData(); } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 66 | |
| 67 | void updateGpuData(); |
| 68 | |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 69 | PrimitiveType fPrimitiveType = PrimitiveType::kTriangles; |
Chris Dalton | be4ffab | 2017-12-08 10:59:58 -0700 | [diff] [blame] | 70 | SkCubicType fCubicType; |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 71 | SkMatrix fCubicKLM; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 72 | |
| 73 | SkPoint fPoints[4] = { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 74 | {100.05f, 100.05f}, {400.75f, 100.05f}, {400.75f, 300.95f}, {100.05f, 300.95f}}; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 75 | |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 76 | float fConicWeight = .5; |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 77 | float fStrokeWidth = 40; |
| 78 | bool fDoStroke = false; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 79 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 80 | SkTArray<TriPointInstance> fTriPointInstances; |
| 81 | SkTArray<QuadPointInstance> fQuadPointInstances; |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 82 | SkPath fPath; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 83 | }; |
| 84 | |
Chris Dalton | 8d38a7f | 2018-03-19 14:16:44 -0600 | [diff] [blame] | 85 | class CCPRGeometryView::DrawCoverageCountOp : public GrDrawOp { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 86 | DEFINE_OP_CLASS_ID |
| 87 | |
| 88 | public: |
Chris Dalton | 8d38a7f | 2018-03-19 14:16:44 -0600 | [diff] [blame] | 89 | DrawCoverageCountOp(CCPRGeometryView* view) : INHERITED(ClassID()), fView(view) { |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 90 | this->setBounds(SkRect::MakeIWH(fView->width(), fView->height()), GrOp::HasAABloat::kNo, |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame] | 91 | GrOp::IsHairline::kNo); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 92 | } |
| 93 | |
Chris Dalton | 8d38a7f | 2018-03-19 14:16:44 -0600 | [diff] [blame] | 94 | const char* name() const override { |
| 95 | return "[Testing/Sample code] CCPRGeometryView::DrawCoverageCountOp"; |
| 96 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 97 | |
| 98 | private: |
| 99 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 100 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, |
| 101 | bool hasMixedSampledCoverage, GrClampType) override { |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 102 | return GrProcessorSet::EmptySetAnalysis(); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 103 | } |
Robert Phillips | c655c3a | 2020-03-18 13:23:45 -0400 | [diff] [blame] | 104 | void onPrePrepare(GrRecordingContext*, |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 105 | const GrSurfaceProxyView* writeView, |
Robert Phillips | c655c3a | 2020-03-18 13:23:45 -0400 | [diff] [blame] | 106 | GrAppliedClip*, |
| 107 | const GrXferProcessor::DstProxyView&) override {} |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 108 | void onPrepare(GrOpFlushState*) override {} |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 109 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 110 | |
| 111 | CCPRGeometryView* fView; |
| 112 | |
| 113 | typedef GrDrawOp INHERITED; |
| 114 | }; |
| 115 | |
Chris Dalton | 8d38a7f | 2018-03-19 14:16:44 -0600 | [diff] [blame] | 116 | class CCPRGeometryView::VisualizeCoverageCountFP : public GrFragmentProcessor { |
| 117 | public: |
| 118 | VisualizeCoverageCountFP() : GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags) {} |
| 119 | |
| 120 | private: |
| 121 | const char* name() const override { |
| 122 | return "[Testing/Sample code] CCPRGeometryView::VisualizeCoverageCountFP"; |
| 123 | } |
| 124 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
Mike Klein | f46d5ca | 2019-12-11 10:45:01 -0500 | [diff] [blame] | 125 | return std::make_unique<VisualizeCoverageCountFP>(); |
Chris Dalton | 8d38a7f | 2018-03-19 14:16:44 -0600 | [diff] [blame] | 126 | } |
| 127 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {} |
| 128 | bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
| 129 | |
| 130 | class Impl : public GrGLSLFragmentProcessor { |
| 131 | void emitCode(EmitArgs& args) override { |
| 132 | GrGLSLFPFragmentBuilder* f = args.fFragBuilder; |
| 133 | f->codeAppendf("half count = %s.a;", args.fInputColor); |
| 134 | f->codeAppendf("%s = half4(clamp(-count, 0, 1), clamp(+count, 0, 1), 0, abs(count));", |
| 135 | args.fOutputColor); |
| 136 | } |
| 137 | }; |
| 138 | |
| 139 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new Impl; } |
| 140 | }; |
| 141 | |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 142 | static void draw_klm_line(int w, int h, SkCanvas* canvas, const SkScalar line[3], SkColor color) { |
| 143 | SkPoint p1, p2; |
| 144 | if (SkScalarAbs(line[1]) > SkScalarAbs(line[0])) { |
| 145 | // Draw from vertical edge to vertical edge. |
| 146 | p1 = {0, -line[2] / line[1]}; |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 147 | p2 = {(SkScalar)w, (-line[2] - w * line[0]) / line[1]}; |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 148 | } else { |
| 149 | // Draw from horizontal edge to horizontal edge. |
| 150 | p1 = {-line[2] / line[0], 0}; |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 151 | p2 = {(-line[2] - h * line[1]) / line[0], (SkScalar)h}; |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | SkPaint linePaint; |
| 155 | linePaint.setColor(color); |
| 156 | linePaint.setAlpha(128); |
| 157 | linePaint.setStyle(SkPaint::kStroke_Style); |
| 158 | linePaint.setStrokeWidth(0); |
| 159 | linePaint.setAntiAlias(true); |
| 160 | canvas->drawLine(p1, p2, linePaint); |
| 161 | } |
| 162 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 163 | void CCPRGeometryView::onDrawContent(SkCanvas* canvas) { |
Chris Dalton | 8738cf4 | 2018-03-09 11:57:40 -0700 | [diff] [blame] | 164 | canvas->clear(SK_ColorBLACK); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 165 | |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 166 | if (!fDoStroke) { |
| 167 | SkPaint outlinePaint; |
| 168 | outlinePaint.setColor(0x80ffffff); |
| 169 | outlinePaint.setStyle(SkPaint::kStroke_Style); |
| 170 | outlinePaint.setStrokeWidth(0); |
| 171 | outlinePaint.setAntiAlias(true); |
| 172 | canvas->drawPath(fPath, outlinePaint); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 173 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 174 | |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 175 | #if 0 |
| 176 | SkPaint gridPaint; |
| 177 | gridPaint.setColor(0x10000000); |
| 178 | gridPaint.setStyle(SkPaint::kStroke_Style); |
| 179 | gridPaint.setStrokeWidth(0); |
| 180 | gridPaint.setAntiAlias(true); |
Chris Dalton | a640c49 | 2017-09-11 22:04:03 -0700 | [diff] [blame] | 181 | for (int y = 0; y < this->height(); y += kDebugBloat) { |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 182 | canvas->drawLine(0, y, this->width(), y, gridPaint); |
| 183 | } |
Chris Dalton | a640c49 | 2017-09-11 22:04:03 -0700 | [diff] [blame] | 184 | for (int x = 0; x < this->width(); x += kDebugBloat) { |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 185 | canvas->drawLine(x, 0, x, this->height(), outlinePaint); |
| 186 | } |
| 187 | #endif |
| 188 | |
Chris Dalton | be4ffab | 2017-12-08 10:59:58 -0700 | [diff] [blame] | 189 | SkString caption; |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 190 | if (GrRenderTargetContext* rtc = canvas->internal_private_accessTopLayerRenderTargetContext()) { |
Chris Dalton | 8d38a7f | 2018-03-19 14:16:44 -0600 | [diff] [blame] | 191 | // Render coverage count. |
Robert Phillips | 30ebcf7 | 2020-07-09 13:25:17 -0400 | [diff] [blame] | 192 | auto ctx = canvas->recordingContext(); |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 193 | SkASSERT(ctx); |
| 194 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 195 | GrOpMemoryPool* pool = ctx->priv().opMemoryPool(); |
Ben Wagner | d4bffed | 2018-08-14 17:51:23 -0400 | [diff] [blame] | 196 | |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 197 | int width = this->width(); |
| 198 | int height = this->height(); |
| 199 | auto ccbuff = GrRenderTargetContext::Make( |
| 200 | ctx, GrColorType::kAlpha_F16, nullptr, SkBackingFit::kApprox, {width, height}); |
Chris Dalton | 8d38a7f | 2018-03-19 14:16:44 -0600 | [diff] [blame] | 201 | SkASSERT(ccbuff); |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 202 | ccbuff->clear(SK_PMColor4fTRANSPARENT); |
Ben Wagner | d4bffed | 2018-08-14 17:51:23 -0400 | [diff] [blame] | 203 | ccbuff->priv().testingOnly_addDrawOp(pool->allocate<DrawCoverageCountOp>(this)); |
Chris Dalton | 8d38a7f | 2018-03-19 14:16:44 -0600 | [diff] [blame] | 204 | |
| 205 | // Visualize coverage count in main canvas. |
| 206 | GrPaint paint; |
Greg Daniel | d2ccbb5 | 2020-02-05 10:45:39 -0500 | [diff] [blame] | 207 | paint.addColorFragmentProcessor( |
| 208 | GrTextureEffect::Make(ccbuff->readSurfaceView(), ccbuff->colorInfo().alphaType())); |
Chris Dalton | 8d38a7f | 2018-03-19 14:16:44 -0600 | [diff] [blame] | 209 | paint.addColorFragmentProcessor( |
Mike Klein | f46d5ca | 2019-12-11 10:45:01 -0500 | [diff] [blame] | 210 | std::make_unique<VisualizeCoverageCountFP>()); |
Chris Dalton | 8d38a7f | 2018-03-19 14:16:44 -0600 | [diff] [blame] | 211 | paint.setPorterDuffXPFactory(SkBlendMode::kSrcOver); |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 212 | rtc->drawRect(nullptr, std::move(paint), GrAA::kNo, SkMatrix::I(), |
Chris Dalton | 8d38a7f | 2018-03-19 14:16:44 -0600 | [diff] [blame] | 213 | SkRect::MakeIWH(this->width(), this->height())); |
| 214 | |
| 215 | // Add label. |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 216 | caption.appendf("PrimitiveType_%s", |
| 217 | GrCCCoverageProcessor::PrimitiveTypeName(fPrimitiveType)); |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 218 | if (PrimitiveType::kCubics == fPrimitiveType) { |
Chris Dalton | be4ffab | 2017-12-08 10:59:58 -0700 | [diff] [blame] | 219 | caption.appendf(" (%s)", SkCubicTypeName(fCubicType)); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 220 | } else if (PrimitiveType::kConics == fPrimitiveType) { |
| 221 | caption.appendf(" (w=%f)", fConicWeight); |
Chris Dalton | be4ffab | 2017-12-08 10:59:58 -0700 | [diff] [blame] | 222 | } |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 223 | if (fDoStroke) { |
| 224 | caption.appendf(" (stroke_width=%f)", fStrokeWidth); |
| 225 | } |
Chris Dalton | be4ffab | 2017-12-08 10:59:58 -0700 | [diff] [blame] | 226 | } else { |
| 227 | caption = "Use GPU backend to visualize geometry."; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | SkPaint pointsPaint; |
| 231 | pointsPaint.setColor(SK_ColorBLUE); |
| 232 | pointsPaint.setStrokeWidth(8); |
| 233 | pointsPaint.setAntiAlias(true); |
| 234 | |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 235 | if (PrimitiveType::kCubics == fPrimitiveType) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 236 | canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, fPoints, pointsPaint); |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 237 | if (!fDoStroke) { |
| 238 | int w = this->width(), h = this->height(); |
| 239 | draw_klm_line(w, h, canvas, &fCubicKLM[0], SK_ColorYELLOW); |
| 240 | draw_klm_line(w, h, canvas, &fCubicKLM[3], SK_ColorBLUE); |
| 241 | draw_klm_line(w, h, canvas, &fCubicKLM[6], SK_ColorRED); |
| 242 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 243 | } else { |
| 244 | canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, fPoints, pointsPaint); |
| 245 | canvas->drawPoints(SkCanvas::kPoints_PointMode, 1, fPoints + 3, pointsPaint); |
| 246 | } |
| 247 | |
Hal Canary | 4484b8f | 2019-01-08 14:00:08 -0500 | [diff] [blame] | 248 | SkFont font(nullptr, 20); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 249 | SkPaint captionPaint; |
Chris Dalton | 8738cf4 | 2018-03-09 11:57:40 -0700 | [diff] [blame] | 250 | captionPaint.setColor(SK_ColorWHITE); |
Hal Canary | 4484b8f | 2019-01-08 14:00:08 -0500 | [diff] [blame] | 251 | canvas->drawString(caption, 10, 30, font, captionPaint); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | void CCPRGeometryView::updateGpuData() { |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 255 | using Verb = GrCCFillGeometry::Verb; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 256 | fTriPointInstances.reset(); |
| 257 | fQuadPointInstances.reset(); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 258 | |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 259 | fPath.reset(); |
| 260 | fPath.moveTo(fPoints[0]); |
| 261 | |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 262 | if (PrimitiveType::kCubics == fPrimitiveType) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 263 | double t[2], s[2]; |
Chris Dalton | be4ffab | 2017-12-08 10:59:58 -0700 | [diff] [blame] | 264 | fCubicType = GrPathUtils::getCubicKLM(fPoints, &fCubicKLM, t, s); |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 265 | GrCCFillGeometry geometry; |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 266 | geometry.beginContour(fPoints[0]); |
Chris Dalton | 7ca3b7b | 2018-04-10 00:21:19 -0600 | [diff] [blame] | 267 | geometry.cubicTo(fPoints, kDebugBloat / 2, kDebugBloat / 2); |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 268 | geometry.endContour(); |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 269 | int ptsIdx = 0; |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 270 | for (Verb verb : geometry.verbs()) { |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 271 | switch (verb) { |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 272 | case Verb::kLineTo: |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 273 | ++ptsIdx; |
| 274 | continue; |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 275 | case Verb::kMonotonicQuadraticTo: |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 276 | ptsIdx += 2; |
| 277 | continue; |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 278 | case Verb::kMonotonicCubicTo: |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 279 | fQuadPointInstances.push_back().set(&geometry.points()[ptsIdx], 0, 0); |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 280 | ptsIdx += 3; |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 281 | continue; |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 282 | default: |
| 283 | continue; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 284 | } |
| 285 | } |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 286 | fPath.cubicTo(fPoints[1], fPoints[2], fPoints[3]); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 287 | } else if (PrimitiveType::kTriangles != fPrimitiveType) { |
Chris Dalton | 7ca3b7b | 2018-04-10 00:21:19 -0600 | [diff] [blame] | 288 | SkPoint P3[3] = {fPoints[0], fPoints[1], fPoints[3]}; |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 289 | GrCCFillGeometry geometry; |
Chris Dalton | 7ca3b7b | 2018-04-10 00:21:19 -0600 | [diff] [blame] | 290 | geometry.beginContour(P3[0]); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 291 | if (PrimitiveType::kQuadratics == fPrimitiveType) { |
| 292 | geometry.quadraticTo(P3); |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 293 | fPath.quadTo(fPoints[1], fPoints[3]); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 294 | } else { |
| 295 | SkASSERT(PrimitiveType::kConics == fPrimitiveType); |
| 296 | geometry.conicTo(P3, fConicWeight); |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 297 | fPath.conicTo(fPoints[1], fPoints[3], fConicWeight); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 298 | } |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 299 | geometry.endContour(); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 300 | int ptsIdx = 0, conicWeightIdx = 0; |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 301 | for (Verb verb : geometry.verbs()) { |
| 302 | if (Verb::kBeginContour == verb || |
| 303 | Verb::kEndOpenContour == verb || |
| 304 | Verb::kEndClosedContour == verb) { |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 305 | continue; |
| 306 | } |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 307 | if (Verb::kLineTo == verb) { |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 308 | ++ptsIdx; |
| 309 | continue; |
| 310 | } |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 311 | SkASSERT(Verb::kMonotonicQuadraticTo == verb || Verb::kMonotonicConicTo == verb); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 312 | if (PrimitiveType::kQuadratics == fPrimitiveType && |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 313 | Verb::kMonotonicQuadraticTo == verb) { |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 314 | fTriPointInstances.push_back().set( |
| 315 | &geometry.points()[ptsIdx], Sk2f(0, 0), |
| 316 | TriPointInstance::Ordering::kXYTransposed); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 317 | } else if (PrimitiveType::kConics == fPrimitiveType && |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 318 | Verb::kMonotonicConicTo == verb) { |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 319 | fQuadPointInstances.push_back().setW(&geometry.points()[ptsIdx], Sk2f(0, 0), |
| 320 | geometry.getConicWeight(conicWeightIdx++)); |
| 321 | } |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 322 | ptsIdx += 2; |
Chris Dalton | b072bb6 | 2017-08-07 09:00:46 -0600 | [diff] [blame] | 323 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 324 | } else { |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 325 | fTriPointInstances.push_back().set( |
| 326 | fPoints[0], fPoints[1], fPoints[3], Sk2f(0, 0), |
| 327 | TriPointInstance::Ordering::kXYTransposed); |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 328 | fPath.lineTo(fPoints[1]); |
| 329 | fPath.lineTo(fPoints[3]); |
| 330 | fPath.close(); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 334 | void CCPRGeometryView::DrawCoverageCountOp::onExecute(GrOpFlushState* state, |
| 335 | const SkRect& chainBounds) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 336 | GrResourceProvider* rp = state->resourceProvider(); |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 337 | auto direct = state->gpu()->getContext(); |
Brian Salomon | f4ba4ec | 2020-03-19 15:54:28 -0400 | [diff] [blame] | 338 | #ifdef SK_GL |
Robert Phillips | 30ebcf7 | 2020-07-09 13:25:17 -0400 | [diff] [blame] | 339 | GrGLGpu* glGpu = GrBackendApi::kOpenGL == direct->backend() |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 340 | ? static_cast<GrGLGpu*>(state->gpu()) |
| 341 | : nullptr; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 342 | if (glGpu) { |
| 343 | glGpu->handleDirtyContext(); |
Chris Dalton | 8738cf4 | 2018-03-09 11:57:40 -0700 | [diff] [blame] | 344 | // GR_GL_CALL(glGpu->glInterface(), PolygonMode(GR_GL_FRONT_AND_BACK, GR_GL_LINE)); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 345 | GR_GL_CALL(glGpu->glInterface(), Enable(GR_GL_LINE_SMOOTH)); |
| 346 | } |
Brian Salomon | f4ba4ec | 2020-03-19 15:54:28 -0400 | [diff] [blame] | 347 | #endif |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 348 | |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 349 | GrPipeline pipeline(GrScissorTest::kDisabled, SkBlendMode::kPlus, |
Brian Salomon | 982f546 | 2020-03-30 12:52:33 -0400 | [diff] [blame] | 350 | state->drawOpArgs().writeSwizzle()); |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 351 | |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 352 | std::unique_ptr<GrCCCoverageProcessor> proc; |
| 353 | if (state->caps().shaderCaps()->geometryShaderSupport()) { |
Mike Klein | f46d5ca | 2019-12-11 10:45:01 -0500 | [diff] [blame] | 354 | proc = std::make_unique<GrGSCoverageProcessor>(); |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 355 | } else { |
Mike Klein | f46d5ca | 2019-12-11 10:45:01 -0500 | [diff] [blame] | 356 | proc = std::make_unique<GrVSCoverageProcessor>(); |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 357 | } |
Chris Dalton | 39ca973 | 2020-03-10 10:34:17 -0600 | [diff] [blame] | 358 | SkDEBUGCODE(proc->enableDebugBloat(kDebugBloat)); |
| 359 | |
| 360 | GrOpsRenderPass* renderPass = state->opsRenderPass(); |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 361 | |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 362 | if (!fView->fDoStroke) { |
Chris Dalton | 39ca973 | 2020-03-10 10:34:17 -0600 | [diff] [blame] | 363 | for (int i = 0; i < proc->numSubpasses(); ++i) { |
| 364 | proc->reset(fView->fPrimitiveType, i, rp); |
| 365 | proc->bindPipeline(state, pipeline, this->bounds()); |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 366 | |
Chris Dalton | 39ca973 | 2020-03-10 10:34:17 -0600 | [diff] [blame] | 367 | if (PrimitiveType::kCubics == fView->fPrimitiveType || |
| 368 | PrimitiveType::kConics == fView->fPrimitiveType) { |
| 369 | sk_sp<GrGpuBuffer> instBuff(rp->createBuffer( |
| 370 | fView->fQuadPointInstances.count() * sizeof(QuadPointInstance), |
| 371 | GrGpuBufferType::kVertex, kDynamic_GrAccessPattern, |
| 372 | fView->fQuadPointInstances.begin())); |
| 373 | if (!fView->fQuadPointInstances.empty() && instBuff) { |
| 374 | proc->bindBuffers(renderPass, instBuff.get()); |
| 375 | proc->drawInstances(renderPass, fView->fQuadPointInstances.count(), 0); |
| 376 | } |
| 377 | } else { |
| 378 | sk_sp<GrGpuBuffer> instBuff(rp->createBuffer( |
| 379 | fView->fTriPointInstances.count() * sizeof(TriPointInstance), |
| 380 | GrGpuBufferType::kVertex, kDynamic_GrAccessPattern, |
| 381 | fView->fTriPointInstances.begin())); |
| 382 | if (!fView->fTriPointInstances.empty() && instBuff) { |
| 383 | proc->bindBuffers(renderPass, instBuff.get()); |
| 384 | proc->drawInstances(renderPass, fView->fTriPointInstances.count(), 0); |
| 385 | } |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 386 | } |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 387 | } |
| 388 | } else if (PrimitiveType::kConics != fView->fPrimitiveType) { // No conic stroke support yet. |
| 389 | GrCCStroker stroker(0,0,0); |
| 390 | |
| 391 | SkPaint p; |
| 392 | p.setStyle(SkPaint::kStroke_Style); |
| 393 | p.setStrokeWidth(fView->fStrokeWidth); |
| 394 | p.setStrokeJoin(SkPaint::kMiter_Join); |
| 395 | p.setStrokeMiter(4); |
| 396 | // p.setStrokeCap(SkPaint::kRound_Cap); |
| 397 | stroker.parseDeviceSpaceStroke(fView->fPath, SkPathPriv::PointData(fView->fPath), |
| 398 | SkStrokeRec(p), p.getStrokeWidth(), GrScissorTest::kDisabled, |
| 399 | SkIRect::MakeWH(fView->width(), fView->height()), {0, 0}); |
| 400 | GrCCStroker::BatchID batchID = stroker.closeCurrentBatch(); |
| 401 | |
Robert Phillips | 30ebcf7 | 2020-07-09 13:25:17 -0400 | [diff] [blame] | 402 | GrOnFlushResourceProvider onFlushRP(direct->priv().drawingManager()); |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 403 | stroker.prepareToDraw(&onFlushRP); |
| 404 | |
| 405 | SkIRect ibounds; |
| 406 | this->bounds().roundOut(&ibounds); |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 407 | stroker.drawStrokes(state, proc.get(), batchID, ibounds); |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 408 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 409 | |
Brian Salomon | f4ba4ec | 2020-03-19 15:54:28 -0400 | [diff] [blame] | 410 | #ifdef SK_GL |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 411 | if (glGpu) { |
Robert Phillips | 30ebcf7 | 2020-07-09 13:25:17 -0400 | [diff] [blame] | 412 | direct->resetContext(kMisc_GrGLBackendState); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 413 | } |
Brian Salomon | f4ba4ec | 2020-03-19 15:54:28 -0400 | [diff] [blame] | 414 | #endif |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 415 | } |
| 416 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 417 | class CCPRGeometryView::Click : public Sample::Click { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 418 | public: |
Hal Canary | fcf6359 | 2019-07-12 11:32:43 -0400 | [diff] [blame] | 419 | Click(int ptIdx) : fPtIdx(ptIdx) {} |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 420 | |
| 421 | void doClick(SkPoint points[]) { |
| 422 | if (fPtIdx >= 0) { |
Hal Canary | fcf6359 | 2019-07-12 11:32:43 -0400 | [diff] [blame] | 423 | points[fPtIdx] += fCurr - fPrev; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 424 | } else { |
| 425 | for (int i = 0; i < 4; ++i) { |
Hal Canary | fcf6359 | 2019-07-12 11:32:43 -0400 | [diff] [blame] | 426 | points[i] += fCurr - fPrev; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | private: |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 432 | int fPtIdx; |
| 433 | }; |
| 434 | |
Hal Canary | b1f411a | 2019-08-29 10:39:22 -0400 | [diff] [blame] | 435 | Sample::Click* CCPRGeometryView::onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 436 | for (int i = 0; i < 4; ++i) { |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 437 | if (PrimitiveType::kCubics != fPrimitiveType && 2 == i) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 438 | continue; |
| 439 | } |
| 440 | if (fabs(x - fPoints[i].x()) < 20 && fabsf(y - fPoints[i].y()) < 20) { |
Hal Canary | fcf6359 | 2019-07-12 11:32:43 -0400 | [diff] [blame] | 441 | return new Click(i); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 442 | } |
| 443 | } |
Hal Canary | fcf6359 | 2019-07-12 11:32:43 -0400 | [diff] [blame] | 444 | return new Click(-1); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 445 | } |
| 446 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 447 | bool CCPRGeometryView::onClick(Sample::Click* click) { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 448 | Click* myClick = (Click*)click; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 449 | myClick->doClick(fPoints); |
| 450 | this->updateAndInval(); |
| 451 | return true; |
| 452 | } |
| 453 | |
Hal Canary | 6cc65e1 | 2019-07-03 15:53:04 -0400 | [diff] [blame] | 454 | bool CCPRGeometryView::onChar(SkUnichar unichar) { |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 455 | if (unichar >= '1' && unichar <= '4') { |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 456 | fPrimitiveType = PrimitiveType(unichar - '1'); |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 457 | if (fPrimitiveType >= PrimitiveType::kWeightedTriangles) { |
| 458 | fPrimitiveType = (PrimitiveType) ((int)fPrimitiveType + 1); |
| 459 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 460 | this->updateAndInval(); |
| 461 | return true; |
| 462 | } |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 463 | float* valueToScale = nullptr; |
| 464 | if (fDoStroke) { |
| 465 | valueToScale = &fStrokeWidth; |
| 466 | } else if (PrimitiveType::kConics == fPrimitiveType) { |
| 467 | valueToScale = &fConicWeight; |
| 468 | } |
| 469 | if (valueToScale) { |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 470 | if (unichar == '+') { |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 471 | *valueToScale *= 2; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 472 | this->updateAndInval(); |
| 473 | return true; |
| 474 | } |
| 475 | if (unichar == '+' || unichar == '=') { |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 476 | *valueToScale *= 5/4.f; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 477 | this->updateAndInval(); |
| 478 | return true; |
| 479 | } |
| 480 | if (unichar == '-') { |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 481 | *valueToScale *= 4/5.f; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 482 | this->updateAndInval(); |
| 483 | return true; |
| 484 | } |
| 485 | if (unichar == '_') { |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 486 | *valueToScale *= .5f; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 487 | this->updateAndInval(); |
| 488 | return true; |
| 489 | } |
| 490 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 491 | if (unichar == 'D') { |
| 492 | SkDebugf(" SkPoint fPoints[4] = {\n"); |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 493 | SkDebugf(" {%ff, %ff},\n", fPoints[0].x(), fPoints[0].y()); |
| 494 | SkDebugf(" {%ff, %ff},\n", fPoints[1].x(), fPoints[1].y()); |
| 495 | SkDebugf(" {%ff, %ff},\n", fPoints[2].x(), fPoints[2].y()); |
| 496 | SkDebugf(" {%ff, %ff}\n", fPoints[3].x(), fPoints[3].y()); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 497 | SkDebugf(" };\n"); |
| 498 | return true; |
| 499 | } |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 500 | if (unichar == 'S') { |
| 501 | fDoStroke = !fDoStroke; |
| 502 | this->updateAndInval(); |
| 503 | } |
Hal Canary | 6cc65e1 | 2019-07-03 15:53:04 -0400 | [diff] [blame] | 504 | return false; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 505 | } |
| 506 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 507 | DEF_SAMPLE(return new CCPRGeometryView;) |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 508 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 509 | #endif // SK_SUPPORT_GPU |