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