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 | |
| 11 | #include "GrGeometryProcessor.h" |
| 12 | #include "SkPath.h" |
| 13 | #include <array> |
| 14 | |
| 15 | class GrOnFlushResourceProvider; |
| 16 | class GrShaderCaps; |
| 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 |
| 25 | * triangles using the index and vertex buffers provided by this class. |
| 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: |
| 29 | static constexpr int kPerInstanceIndexCount = 6 * 3; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 30 | |
| 31 | enum class InstanceAttribs { |
| 32 | kDevBounds, |
| 33 | kDevBounds45, |
| 34 | kViewMatrix, // FIXME: This causes a lot of duplication. It could move to a texel buffer. |
| 35 | kViewTranslate, |
| 36 | kAtlasOffset, |
| 37 | kColor |
| 38 | }; |
| 39 | static constexpr int kNumInstanceAttribs = 1 + (int)InstanceAttribs::kColor; |
| 40 | |
| 41 | struct Instance { |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 42 | SkRect fDevBounds; |
| 43 | SkRect fDevBounds45; // Bounding box in "| 1 -1 | * devCoords" space. |
| 44 | // | 1 1 | |
| 45 | std::array<float, 4> fViewMatrix; // {kScaleX, kSkewy, kSkewX, kScaleY} |
| 46 | std::array<float, 2> fViewTranslate; |
| 47 | std::array<int16_t, 2> fAtlasOffset; |
| 48 | uint32_t fColor; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 49 | |
| 50 | GR_STATIC_ASSERT(SK_SCALAR_IS_FLOAT); |
| 51 | }; |
| 52 | |
Chris Dalton | a045eea | 2017-10-24 13:22:10 -0600 | [diff] [blame] | 53 | GR_STATIC_ASSERT(4 * 16 == sizeof(Instance)); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 54 | |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 55 | static sk_sp<const GrBuffer> FindIndexBuffer(GrOnFlushResourceProvider*); |
| 56 | static sk_sp<const GrBuffer> FindVertexBuffer(GrOnFlushResourceProvider*); |
| 57 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 58 | GrCCPathProcessor(GrResourceProvider*, sk_sp<GrTextureProxy> atlas, SkPath::FillType, |
| 59 | const GrShaderCaps&); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 60 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 61 | const char* name() const override { return "GrCCPathProcessor"; } |
Robert Phillips | e44ef10 | 2017-07-21 15:37:19 -0400 | [diff] [blame] | 62 | const GrSurfaceProxy* atlasProxy() const { return fAtlasAccess.proxy(); } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 63 | const GrTexture* atlas() const { return fAtlasAccess.peekTexture(); } |
| 64 | SkPath::FillType fillType() const { return fFillType; } |
| 65 | const Attribute& getInstanceAttrib(InstanceAttribs attribID) const { |
| 66 | const Attribute& attrib = this->getAttrib((int)attribID); |
| 67 | SkASSERT(Attribute::InputRate::kPerInstance == attrib.fInputRate); |
| 68 | return attrib; |
| 69 | } |
| 70 | const Attribute& getEdgeNormsAttrib() const { |
| 71 | SkASSERT(1 + kNumInstanceAttribs == this->numAttribs()); |
| 72 | const Attribute& attrib = this->getAttrib(kNumInstanceAttribs); |
| 73 | SkASSERT(Attribute::InputRate::kPerVertex == attrib.fInputRate); |
| 74 | return attrib; |
| 75 | } |
| 76 | |
| 77 | void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
| 78 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override; |
| 79 | |
| 80 | private: |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 81 | const SkPath::FillType fFillType; |
| 82 | const TextureSampler fAtlasAccess; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 83 | |
| 84 | typedef GrGeometryProcessor INHERITED; |
| 85 | }; |
| 86 | |
| 87 | #endif |