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 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 11 | #include <array> |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkPath.h" |
| 13 | #include "src/gpu/GrCaps.h" |
| 14 | #include "src/gpu/GrGeometryProcessor.h" |
| 15 | #include "src/gpu/GrPipeline.h" |
Chris Dalton | 8610e9c | 2019-05-09 11:07:10 -0600 | [diff] [blame] | 16 | #include "src/gpu/ccpr/GrOctoBounds.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 17 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 18 | class GrCCPathCacheEntry; |
| 19 | class GrCCPerFlushResources; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 20 | class GrOnFlushResourceProvider; |
Chris Dalton | d925f2d | 2018-05-07 19:19:06 -0600 | [diff] [blame] | 21 | class GrOpFlushState; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 22 | |
| 23 | /** |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 24 | * 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] | 25 | * |
| 26 | * Paths are drawn as bloated octagons, and coverage is derived from the coverage count mask and |
| 27 | * fill rule. |
| 28 | * |
Chris Dalton | d925f2d | 2018-05-07 19:19:06 -0600 | [diff] [blame] | 29 | * To draw paths, the caller must set up an instance buffer as detailed below, then call drawPaths() |
| 30 | * providing its own instance buffer alongside the buffers found by calling FindIndexBuffer/ |
| 31 | * FindVertexBuffer. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 32 | */ |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 33 | class GrCCPathProcessor : public GrGeometryProcessor { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 34 | public: |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 35 | enum class DoEvenOddFill : bool { |
| 36 | kNo = false, |
| 37 | kYes = true |
| 38 | }; |
| 39 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 40 | struct Instance { |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 41 | SkRect fDevBounds; // "right < left" indicates even-odd fill type. |
Chris Dalton | 8610e9c | 2019-05-09 11:07:10 -0600 | [diff] [blame] | 42 | SkRect fDevBounds45; // Bounding box in "| 1 -1 | * devCoords" space. See GrOctoBounds. |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 43 | // | 1 1 | |
| 44 | SkIVector fDevToAtlasOffset; // Translation from device space to location in atlas. |
Brian Osman | c6444d2 | 2019-01-09 16:30:12 -0500 | [diff] [blame] | 45 | uint64_t fColor; // Color always stored as 4 x fp16 |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 46 | |
Chris Dalton | 8610e9c | 2019-05-09 11:07:10 -0600 | [diff] [blame] | 47 | void set(const GrOctoBounds&, const SkIVector& devToAtlasOffset, uint64_t, |
| 48 | DoEvenOddFill = DoEvenOddFill::kNo); |
Brian Osman | c6444d2 | 2019-01-09 16:30:12 -0500 | [diff] [blame] | 49 | void set(const GrCCPathCacheEntry&, const SkIVector& shift, uint64_t, |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 50 | DoEvenOddFill = DoEvenOddFill::kNo); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 51 | }; |
| 52 | |
Brian Osman | c6444d2 | 2019-01-09 16:30:12 -0500 | [diff] [blame] | 53 | GR_STATIC_ASSERT(4 * 12 == sizeof(Instance)); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 54 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 55 | static sk_sp<const GrGpuBuffer> FindVertexBuffer(GrOnFlushResourceProvider*); |
| 56 | static sk_sp<const GrGpuBuffer> FindIndexBuffer(GrOnFlushResourceProvider*); |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 57 | |
Chris Dalton | f91b755 | 2019-04-29 16:21:18 -0600 | [diff] [blame] | 58 | GrCCPathProcessor(const GrTexture* atlasTexture, GrSurfaceOrigin atlasOrigin, |
Chris Dalton | 1c54894 | 2018-05-22 13:09:48 -0600 | [diff] [blame] | 59 | const SkMatrix& viewMatrixIfUsingLocalCoords = SkMatrix::I()); |
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"; } |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame] | 62 | void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {} |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 63 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override; |
| 64 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 65 | void drawPaths(GrOpFlushState*, const GrPipeline&, const GrPipeline::FixedDynamicState*, |
| 66 | const GrCCPerFlushResources&, int baseInstance, int endInstance, |
| 67 | const SkRect& bounds) const; |
Chris Dalton | d925f2d | 2018-05-07 19:19:06 -0600 | [diff] [blame] | 68 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 69 | private: |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 70 | const TextureSampler& onTextureSampler(int) const override { return fAtlasAccess; } |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 71 | |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 72 | const TextureSampler fAtlasAccess; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 73 | SkISize fAtlasSize; |
| 74 | GrSurfaceOrigin fAtlasOrigin; |
| 75 | |
Chris Dalton | 1c54894 | 2018-05-22 13:09:48 -0600 | [diff] [blame] | 76 | SkMatrix fLocalMatrix; |
Chris Dalton | 377b18b | 2019-04-18 13:33:50 -0600 | [diff] [blame] | 77 | static constexpr Attribute kInstanceAttribs[] = { |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 78 | {"devbounds", kFloat4_GrVertexAttribType, kFloat4_GrSLType}, |
| 79 | {"devbounds45", kFloat4_GrVertexAttribType, kFloat4_GrSLType}, |
| 80 | {"dev_to_atlas_offset", kInt2_GrVertexAttribType, kInt2_GrSLType}, |
Brian Osman | c6444d2 | 2019-01-09 16:30:12 -0500 | [diff] [blame] | 81 | {"color", kHalf4_GrVertexAttribType, kHalf4_GrSLType} |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 82 | }; |
Chris Dalton | 377b18b | 2019-04-18 13:33:50 -0600 | [diff] [blame] | 83 | static constexpr int kColorAttribIdx = 3; |
| 84 | static constexpr Attribute kCornersAttrib = |
| 85 | {"corners", kFloat4_GrVertexAttribType, kFloat4_GrSLType}; |
| 86 | |
| 87 | class Impl; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 88 | |
| 89 | typedef GrGeometryProcessor INHERITED; |
| 90 | }; |
| 91 | |
Chris Dalton | 377b18b | 2019-04-18 13:33:50 -0600 | [diff] [blame] | 92 | inline void GrCCPathProcessor::Instance::set( |
Chris Dalton | 8610e9c | 2019-05-09 11:07:10 -0600 | [diff] [blame] | 93 | const GrOctoBounds& octoBounds, const SkIVector& devToAtlasOffset, uint64_t color, |
| 94 | DoEvenOddFill doEvenOddFill) { |
Chris Dalton | 377b18b | 2019-04-18 13:33:50 -0600 | [diff] [blame] | 95 | if (DoEvenOddFill::kNo == doEvenOddFill) { |
| 96 | // We cover "nonzero" paths with clockwise triangles, which is the default result from |
Chris Dalton | 8610e9c | 2019-05-09 11:07:10 -0600 | [diff] [blame] | 97 | // normal octo bounds. |
| 98 | fDevBounds = octoBounds.bounds(); |
| 99 | fDevBounds45 = octoBounds.bounds45(); |
Chris Dalton | 377b18b | 2019-04-18 13:33:50 -0600 | [diff] [blame] | 100 | } else { |
Chris Dalton | 8610e9c | 2019-05-09 11:07:10 -0600 | [diff] [blame] | 101 | // We cover "even/odd" paths with counterclockwise triangles. Here we reorder the bounding |
| 102 | // box vertices so the output is flipped horizontally. |
| 103 | fDevBounds.setLTRB( |
| 104 | octoBounds.right(), octoBounds.top(), octoBounds.left(), octoBounds.bottom()); |
Chris Dalton | 377b18b | 2019-04-18 13:33:50 -0600 | [diff] [blame] | 105 | fDevBounds45.setLTRB( |
Chris Dalton | 8610e9c | 2019-05-09 11:07:10 -0600 | [diff] [blame] | 106 | octoBounds.bottom45(), octoBounds.right45(), octoBounds.top45(), |
| 107 | octoBounds.left45()); |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame] | 108 | } |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 109 | fDevToAtlasOffset = devToAtlasOffset; |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame] | 110 | fColor = color; |
| 111 | } |
| 112 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 113 | #endif |