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 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 8 | #ifndef GrCCPathProcessor_DEFINED |
| 9 | #define GrCCPathProcessor_DEFINED |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 10 | |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame^] | 11 | #include "GrCaps.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 12 | #include "GrGeometryProcessor.h" |
| 13 | #include "SkPath.h" |
| 14 | #include <array> |
| 15 | |
| 16 | class GrOnFlushResourceProvider; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 17 | |
| 18 | /** |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 19 | * This class draws AA paths using the coverage count masks produced by GrCCCoverageProcessor. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 20 | * |
| 21 | * Paths are drawn as bloated octagons, and coverage is derived from the coverage count mask and |
| 22 | * fill rule. |
| 23 | * |
| 24 | * The caller must set up an instance buffer as detailed below, then draw indexed-instanced |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame^] | 25 | * meshes using the buffers and parameters provided by this class. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 26 | */ |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 27 | class GrCCPathProcessor : public GrGeometryProcessor { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 28 | public: |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 29 | enum class InstanceAttribs { |
| 30 | kDevBounds, |
| 31 | kDevBounds45, |
| 32 | kViewMatrix, // FIXME: This causes a lot of duplication. It could move to a texel buffer. |
| 33 | kViewTranslate, |
| 34 | kAtlasOffset, |
| 35 | kColor |
| 36 | }; |
| 37 | static constexpr int kNumInstanceAttribs = 1 + (int)InstanceAttribs::kColor; |
| 38 | |
| 39 | struct Instance { |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 40 | SkRect fDevBounds; |
| 41 | SkRect fDevBounds45; // Bounding box in "| 1 -1 | * devCoords" space. |
| 42 | // | 1 1 | |
| 43 | std::array<float, 4> fViewMatrix; // {kScaleX, kSkewy, kSkewX, kScaleY} |
| 44 | std::array<float, 2> fViewTranslate; |
| 45 | std::array<int16_t, 2> fAtlasOffset; |
| 46 | uint32_t fColor; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 47 | |
| 48 | GR_STATIC_ASSERT(SK_SCALAR_IS_FLOAT); |
| 49 | }; |
| 50 | |
Chris Dalton | a045eea | 2017-10-24 13:22:10 -0600 | [diff] [blame] | 51 | GR_STATIC_ASSERT(4 * 16 == sizeof(Instance)); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 52 | |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame^] | 53 | static GrPrimitiveType MeshPrimitiveType(const GrCaps& caps) { |
| 54 | return caps.usePrimitiveRestart() ? GrPrimitiveType::kTriangleStrip |
| 55 | : GrPrimitiveType::kTriangles; |
| 56 | } |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 57 | static sk_sp<const GrBuffer> FindVertexBuffer(GrOnFlushResourceProvider*); |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame^] | 58 | static sk_sp<const GrBuffer> FindIndexBuffer(GrOnFlushResourceProvider*); |
| 59 | static int NumIndicesPerInstance(const GrCaps&); |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 60 | |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame^] | 61 | GrCCPathProcessor(GrResourceProvider*, sk_sp<GrTextureProxy> atlas, SkPath::FillType); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 62 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 63 | const char* name() const override { return "GrCCPathProcessor"; } |
Robert Phillips | e44ef10 | 2017-07-21 15:37:19 -0400 | [diff] [blame] | 64 | const GrSurfaceProxy* atlasProxy() const { return fAtlasAccess.proxy(); } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 65 | const GrTexture* atlas() const { return fAtlasAccess.peekTexture(); } |
| 66 | SkPath::FillType fillType() const { return fFillType; } |
| 67 | const Attribute& getInstanceAttrib(InstanceAttribs attribID) const { |
| 68 | const Attribute& attrib = this->getAttrib((int)attribID); |
| 69 | SkASSERT(Attribute::InputRate::kPerInstance == attrib.fInputRate); |
| 70 | return attrib; |
| 71 | } |
| 72 | const Attribute& getEdgeNormsAttrib() const { |
| 73 | SkASSERT(1 + kNumInstanceAttribs == this->numAttribs()); |
| 74 | const Attribute& attrib = this->getAttrib(kNumInstanceAttribs); |
| 75 | SkASSERT(Attribute::InputRate::kPerVertex == attrib.fInputRate); |
| 76 | return attrib; |
| 77 | } |
| 78 | |
| 79 | void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
| 80 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override; |
| 81 | |
| 82 | private: |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 83 | const SkPath::FillType fFillType; |
| 84 | const TextureSampler fAtlasAccess; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 85 | |
| 86 | typedef GrGeometryProcessor INHERITED; |
| 87 | }; |
| 88 | |
| 89 | #endif |