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 | d925f2d | 2018-05-07 19:19:06 -0600 | [diff] [blame] | 17 | class GrOpFlushState; |
| 18 | class GrPipeline; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 19 | |
| 20 | /** |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 21 | * 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] | 22 | * |
| 23 | * Paths are drawn as bloated octagons, and coverage is derived from the coverage count mask and |
| 24 | * fill rule. |
| 25 | * |
Chris Dalton | d925f2d | 2018-05-07 19:19:06 -0600 | [diff] [blame] | 26 | * To draw paths, the caller must set up an instance buffer as detailed below, then call drawPaths() |
| 27 | * providing its own instance buffer alongside the buffers found by calling FindIndexBuffer/ |
| 28 | * FindVertexBuffer. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 29 | */ |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 30 | class GrCCPathProcessor : public GrGeometryProcessor { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 31 | public: |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 32 | enum class InstanceAttribs { |
| 33 | kDevBounds, |
| 34 | kDevBounds45, |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 35 | kAtlasOffset, |
| 36 | kColor |
| 37 | }; |
| 38 | static constexpr int kNumInstanceAttribs = 1 + (int)InstanceAttribs::kColor; |
| 39 | |
| 40 | struct Instance { |
Chris Dalton | 13235d8 | 2018-05-23 22:51:22 +0000 | [diff] [blame^] | 41 | SkRect fDevBounds; |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 42 | SkRect fDevBounds45; // Bounding box in "| 1 -1 | * devCoords" space. |
| 43 | // | 1 1 | |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 44 | std::array<int16_t, 2> fAtlasOffset; |
| 45 | uint32_t fColor; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 46 | |
Chris Dalton | 13235d8 | 2018-05-23 22:51:22 +0000 | [diff] [blame^] | 47 | GR_STATIC_ASSERT(SK_SCALAR_IS_FLOAT); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 48 | }; |
| 49 | |
Chris Dalton | 1c54894 | 2018-05-22 13:09:48 -0600 | [diff] [blame] | 50 | GR_STATIC_ASSERT(4 * 10 == sizeof(Instance)); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 51 | |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 52 | static sk_sp<const GrBuffer> FindVertexBuffer(GrOnFlushResourceProvider*); |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame] | 53 | static sk_sp<const GrBuffer> FindIndexBuffer(GrOnFlushResourceProvider*); |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 54 | |
Chris Dalton | 13235d8 | 2018-05-23 22:51:22 +0000 | [diff] [blame^] | 55 | GrCCPathProcessor(GrResourceProvider*, sk_sp<GrTextureProxy> atlas, SkPath::FillType, |
Chris Dalton | 1c54894 | 2018-05-22 13:09:48 -0600 | [diff] [blame] | 56 | const SkMatrix& viewMatrixIfUsingLocalCoords = SkMatrix::I()); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 57 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 58 | const char* name() const override { return "GrCCPathProcessor"; } |
Robert Phillips | e44ef10 | 2017-07-21 15:37:19 -0400 | [diff] [blame] | 59 | const GrSurfaceProxy* atlasProxy() const { return fAtlasAccess.proxy(); } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 60 | const GrTexture* atlas() const { return fAtlasAccess.peekTexture(); } |
Chris Dalton | 1c54894 | 2018-05-22 13:09:48 -0600 | [diff] [blame] | 61 | const SkMatrix& localMatrix() const { return fLocalMatrix; } |
Chris Dalton | 13235d8 | 2018-05-23 22:51:22 +0000 | [diff] [blame^] | 62 | SkPath::FillType fillType() const { return fFillType; } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 63 | const Attribute& getInstanceAttrib(InstanceAttribs attribID) const { |
| 64 | const Attribute& attrib = this->getAttrib((int)attribID); |
| 65 | SkASSERT(Attribute::InputRate::kPerInstance == attrib.fInputRate); |
| 66 | return attrib; |
| 67 | } |
| 68 | const Attribute& getEdgeNormsAttrib() const { |
| 69 | SkASSERT(1 + kNumInstanceAttribs == this->numAttribs()); |
| 70 | const Attribute& attrib = this->getAttrib(kNumInstanceAttribs); |
| 71 | SkASSERT(Attribute::InputRate::kPerVertex == attrib.fInputRate); |
| 72 | return attrib; |
| 73 | } |
| 74 | |
Chris Dalton | 13235d8 | 2018-05-23 22:51:22 +0000 | [diff] [blame^] | 75 | void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 76 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override; |
| 77 | |
Chris Dalton | d925f2d | 2018-05-07 19:19:06 -0600 | [diff] [blame] | 78 | void drawPaths(GrOpFlushState*, const GrPipeline&, const GrBuffer* indexBuffer, |
| 79 | const GrBuffer* vertexBuffer, GrBuffer* instanceBuffer, int baseInstance, |
| 80 | int endInstance, const SkRect& bounds) const; |
| 81 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 82 | private: |
Chris Dalton | 13235d8 | 2018-05-23 22:51:22 +0000 | [diff] [blame^] | 83 | const SkPath::FillType fFillType; |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 84 | const TextureSampler fAtlasAccess; |
Chris Dalton | 1c54894 | 2018-05-22 13:09:48 -0600 | [diff] [blame] | 85 | SkMatrix fLocalMatrix; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 86 | |
| 87 | typedef GrGeometryProcessor INHERITED; |
| 88 | }; |
| 89 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 90 | #endif |