robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | */ |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 7 | #ifndef GrClipMaskManager_DEFINED |
| 8 | #define GrClipMaskManager_DEFINED |
| 9 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 10 | #include "GrPipelineBuilder.h" |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 11 | #include "GrReducedClip.h" |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 12 | #include "GrStencil.h" |
| 13 | #include "GrTexture.h" |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 14 | #include "SkClipStack.h" |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 15 | #include "SkDeque.h" |
| 16 | #include "SkPath.h" |
| 17 | #include "SkRefCnt.h" |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 18 | #include "SkTLList.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 19 | #include "SkTypes.h" |
robertphillips@google.com | 1fcc1b8 | 2012-08-29 12:52:05 +0000 | [diff] [blame] | 20 | |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 21 | class GrDrawTarget; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 22 | class GrPathRenderer; |
| 23 | class GrPathRendererChain; |
robertphillips | 544b9aa | 2015-10-28 11:01:41 -0700 | [diff] [blame] | 24 | class GrResourceProvider; |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 25 | class GrTexture; |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 26 | class SkPath; |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Produced by GrClipMaskManager. It provides a set of modifications to the drawing state that |
| 30 | * are used to create the final GrPipeline for a GrBatch. This is a work in progress. It will |
| 31 | * eventually encapsulate all mechanisms for modifying the scissor, shaders, and stencil state |
| 32 | * to implement clipping. |
| 33 | */ |
| 34 | class GrAppliedClip : public SkNoncopyable { |
| 35 | public: |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 36 | GrAppliedClip() {} |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 37 | const GrFragmentProcessor* clipCoverageFragmentProcessor() const { return fClipCoverageFP; } |
bsalomon | e91f7b5 | 2015-10-27 06:42:50 -0700 | [diff] [blame] | 38 | const GrScissorState& scissorState() const { return fScissorState; } |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 39 | |
| 40 | private: |
| 41 | SkAutoTUnref<const GrFragmentProcessor> fClipCoverageFP; |
bsalomon | e91f7b5 | 2015-10-27 06:42:50 -0700 | [diff] [blame] | 42 | GrScissorState fScissorState; |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 43 | friend class GrClipMaskManager; |
| 44 | |
| 45 | typedef SkNoncopyable INHERITED; |
| 46 | }; |
| 47 | |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 48 | /** |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 49 | * The clip mask creator handles the generation of the clip mask. If anti |
| 50 | * aliasing is requested it will (in the future) generate a single channel |
| 51 | * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 52 | * mask in the stencil buffer. In the non anti-aliasing case, if the clip |
| 53 | * mask can be represented as a rectangle then scissoring is used. In all |
| 54 | * cases scissoring is used to bound the range of the clip mask. |
| 55 | */ |
commit-bot@chromium.org | e3beb6b | 2014-04-07 19:34:38 +0000 | [diff] [blame] | 56 | class GrClipMaskManager : SkNoncopyable { |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 57 | public: |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 58 | GrClipMaskManager(GrDrawTarget* owner, bool debugClipBatchToBounds); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 59 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 60 | /** |
| 61 | * Creates a clip mask if necessary as a stencil buffer or alpha texture |
| 62 | * and sets the GrGpu's scissor and stencil state. If the return is false |
commit-bot@chromium.org | 3ae0e6c | 2014-02-11 18:24:25 +0000 | [diff] [blame] | 63 | * then the draw can be skipped. The AutoRestoreEffects is initialized by |
| 64 | * the manager when it must install additional effects to implement the |
| 65 | * clip. devBounds is optional but can help optimize clipping. |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 66 | */ |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 67 | bool setupClipping(const GrPipelineBuilder&, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 68 | GrPipelineBuilder::AutoRestoreStencil*, |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 69 | const SkRect* devBounds, |
| 70 | GrAppliedClip*); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 71 | |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 72 | bool setupScissorClip(const GrPipelineBuilder& pipelineBuilder, |
| 73 | GrPipelineBuilder::AutoRestoreStencil* ars, |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 74 | const SkIRect& scissor, |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 75 | const SkRect* devBounds, |
| 76 | GrAppliedClip* out); |
| 77 | |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 78 | void adjustPathStencilParams(const GrStencilAttachment*, GrStencilSettings*); |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 79 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 80 | private: |
bsalomon | edd77a1 | 2015-05-29 09:45:57 -0700 | [diff] [blame] | 81 | inline GrContext* getContext(); |
robertphillips | 544b9aa | 2015-10-28 11:01:41 -0700 | [diff] [blame] | 82 | inline const GrCaps* caps() const; |
| 83 | inline GrResourceProvider* resourceProvider(); |
bsalomon | edd77a1 | 2015-05-29 09:45:57 -0700 | [diff] [blame] | 84 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 85 | static bool PathNeedsSWRenderer(GrContext* context, |
| 86 | bool isStencilDisabled, |
| 87 | const GrRenderTarget* rt, |
| 88 | const SkMatrix& viewMatrix, |
| 89 | const SkClipStack::Element* element, |
| 90 | GrPathRenderer** prOut, |
| 91 | bool needsStencil); |
| 92 | static GrPathRenderer* GetPathRenderer(GrContext* context, |
| 93 | GrTexture* texture, |
| 94 | const SkMatrix& viewMatrix, |
| 95 | const SkClipStack::Element* element); |
| 96 | |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 97 | /** |
| 98 | * Informs the helper function adjustStencilParams() about how the stencil |
| 99 | * buffer clip is being used. |
| 100 | */ |
| 101 | enum StencilClipMode { |
| 102 | // Draw to the clip bit of the stencil buffer |
| 103 | kModifyClip_StencilClipMode, |
| 104 | // Clip against the existing representation of the clip in the high bit |
| 105 | // of the stencil buffer. |
| 106 | kRespectClip_StencilClipMode, |
| 107 | // Neither writing to nor clipping against the clip bit. |
| 108 | kIgnoreClip_StencilClipMode, |
| 109 | }; |
| 110 | |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 111 | // Attempts to install a series of coverage effects to implement the clip. Return indicates |
bsalomon | 0b5b6b2 | 2015-10-14 08:31:34 -0700 | [diff] [blame] | 112 | // whether the element list was successfully converted to processors. *fp may be nullptr even |
| 113 | // when the function succeeds because all the elements were ignored. TODO: Make clip reduction |
bsalomon | a912dde | 2015-10-14 15:01:50 -0700 | [diff] [blame] | 114 | // bounds-aware and stop checking bounds in this function. Similarly, we shouldn't need to pass |
| 115 | // abortIfAA, but we don't yet know if all the AA elements will be eliminated. |
bsalomon | 0b5b6b2 | 2015-10-14 08:31:34 -0700 | [diff] [blame] | 116 | bool getAnalyticClipProcessor(const GrReducedClip::ElementList&, |
bsalomon | a912dde | 2015-10-14 15:01:50 -0700 | [diff] [blame] | 117 | bool abortIfAA, |
bsalomon | 0b5b6b2 | 2015-10-14 08:31:34 -0700 | [diff] [blame] | 118 | SkVector& clipOffset, |
| 119 | const SkRect* devBounds, |
| 120 | const GrFragmentProcessor** fp); |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 121 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 122 | // Draws the clip into the stencil buffer |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 123 | bool createStencilClipMask(GrRenderTarget*, |
| 124 | int32_t elementsGenID, |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 125 | GrReducedClip::InitialState initialState, |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 126 | const GrReducedClip::ElementList& elements, |
| 127 | const SkIRect& clipSpaceIBounds, |
| 128 | const SkIPoint& clipSpaceToStencilOffset); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 129 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 130 | // Creates an alpha mask of the clip. The mask is a rasterization of elements through the |
| 131 | // rect specified by clipSpaceIBounds. |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 132 | static GrTexture* CreateAlphaClipMask(GrContext*, |
| 133 | int32_t elementsGenID, |
| 134 | GrReducedClip::InitialState initialState, |
| 135 | const GrReducedClip::ElementList& elements, |
| 136 | const SkVector& clipToMaskOffset, |
| 137 | const SkIRect& clipSpaceIBounds); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 138 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 139 | // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture. |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 140 | static GrTexture* CreateSoftwareClipMask(GrContext*, |
| 141 | int32_t elementsGenID, |
| 142 | GrReducedClip::InitialState initialState, |
| 143 | const GrReducedClip::ElementList& elements, |
| 144 | const SkVector& clipToMaskOffset, |
| 145 | const SkIRect& clipSpaceIBounds); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 146 | |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 147 | static bool UseSWOnlyPath(GrContext*, |
| 148 | const GrPipelineBuilder&, |
| 149 | const GrRenderTarget* rt, |
| 150 | const SkVector& clipToMaskOffset, |
| 151 | const GrReducedClip::ElementList& elements); |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 152 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 153 | /** |
bsalomon | 9e5fc72 | 2015-02-23 10:01:36 -0800 | [diff] [blame] | 154 | * Called prior to return control back the GrGpu in setupClipping. It updates the |
| 155 | * GrPipelineBuilder with stencil settings that account for stencil-based clipping. |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 156 | */ |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 157 | void setPipelineBuilderStencil(const GrPipelineBuilder&, |
| 158 | GrPipelineBuilder::AutoRestoreStencil*); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 159 | |
| 160 | /** |
| 161 | * Adjusts the stencil settings to account for interaction with stencil |
| 162 | * clipping. |
| 163 | */ |
| 164 | void adjustStencilParams(GrStencilSettings* settings, |
| 165 | StencilClipMode mode, |
| 166 | int stencilBitCnt); |
| 167 | |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 168 | GrTexture* createCachedMask(int width, int height, const GrUniqueKey& key, bool renderTarget); |
| 169 | |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 170 | static const int kMaxAnalyticElements = 4; |
| 171 | |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 172 | GrDrawTarget* fDrawTarget; // This is our owning draw target. |
joshualitt | 7a6184f | 2014-10-29 18:29:27 -0700 | [diff] [blame] | 173 | StencilClipMode fClipMode; |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 174 | bool fDebugClipBatchToBounds; |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 175 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 176 | typedef SkNoncopyable INHERITED; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 177 | }; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 178 | #endif // GrClipMaskManager_DEFINED |