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 "GrTexture.h" |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 13 | #include "SkClipStack.h" |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 14 | #include "SkDeque.h" |
| 15 | #include "SkPath.h" |
| 16 | #include "SkRefCnt.h" |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 17 | #include "SkTLList.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 18 | #include "SkTypes.h" |
robertphillips@google.com | 1fcc1b8 | 2012-08-29 12:52:05 +0000 | [diff] [blame] | 19 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 20 | class GrAppliedClip; |
| 21 | class GrClipStackClip; |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 22 | class GrDrawTarget; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 23 | class GrPathRenderer; |
| 24 | class GrPathRendererChain; |
robertphillips | 544b9aa | 2015-10-28 11:01:41 -0700 | [diff] [blame] | 25 | class GrResourceProvider; |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 26 | class GrTexture; |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 27 | class SkPath; |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 30 | * The clip mask creator handles the generation of the clip mask. If anti |
| 31 | * aliasing is requested it will (in the future) generate a single channel |
| 32 | * (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] | 33 | * mask in the stencil buffer. In the non anti-aliasing case, if the clip |
| 34 | * mask can be represented as a rectangle then scissoring is used. In all |
| 35 | * cases scissoring is used to bound the range of the clip mask. |
| 36 | */ |
commit-bot@chromium.org | e3beb6b | 2014-04-07 19:34:38 +0000 | [diff] [blame] | 37 | class GrClipMaskManager : SkNoncopyable { |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 38 | public: |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 39 | GrClipMaskManager(GrDrawTarget* owner) : fDrawTarget(owner) {} |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 40 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 41 | /** |
| 42 | * Creates a clip mask if necessary as a stencil buffer or alpha texture |
| 43 | * and sets the GrGpu's scissor and stencil state. If the return is false |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 44 | * then the draw can be skipped. devBounds is optional but can help optimize |
| 45 | * clipping. |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 46 | */ |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 47 | bool setupClipping(const GrPipelineBuilder&, const GrClipStackClip&, const SkRect* devBounds, |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 48 | GrAppliedClip*); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 49 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 50 | private: |
bsalomon | edd77a1 | 2015-05-29 09:45:57 -0700 | [diff] [blame] | 51 | inline GrContext* getContext(); |
robertphillips | 544b9aa | 2015-10-28 11:01:41 -0700 | [diff] [blame] | 52 | inline const GrCaps* caps() const; |
| 53 | inline GrResourceProvider* resourceProvider(); |
bsalomon | edd77a1 | 2015-05-29 09:45:57 -0700 | [diff] [blame] | 54 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 55 | static bool PathNeedsSWRenderer(GrContext* context, |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 56 | bool hasUserStencilSettings, |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 57 | const GrRenderTarget* rt, |
| 58 | const SkMatrix& viewMatrix, |
| 59 | const SkClipStack::Element* element, |
| 60 | GrPathRenderer** prOut, |
| 61 | bool needsStencil); |
| 62 | static GrPathRenderer* GetPathRenderer(GrContext* context, |
| 63 | GrTexture* texture, |
| 64 | const SkMatrix& viewMatrix, |
| 65 | const SkClipStack::Element* element); |
| 66 | |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 67 | // 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] | 68 | // whether the element list was successfully converted to processors. *fp may be nullptr even |
| 69 | // 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] | 70 | // bounds-aware and stop checking bounds in this function. Similarly, we shouldn't need to pass |
| 71 | // 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] | 72 | bool getAnalyticClipProcessor(const GrReducedClip::ElementList&, |
bsalomon | a912dde | 2015-10-14 15:01:50 -0700 | [diff] [blame] | 73 | bool abortIfAA, |
bsalomon | 0b5b6b2 | 2015-10-14 08:31:34 -0700 | [diff] [blame] | 74 | SkVector& clipOffset, |
| 75 | const SkRect* devBounds, |
| 76 | const GrFragmentProcessor** fp); |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 77 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 78 | // Draws the clip into the stencil buffer |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 79 | bool createStencilClipMask(GrRenderTarget*, |
| 80 | int32_t elementsGenID, |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 81 | GrReducedClip::InitialState initialState, |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 82 | const GrReducedClip::ElementList& elements, |
| 83 | const SkIRect& clipSpaceIBounds, |
| 84 | const SkIPoint& clipSpaceToStencilOffset); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 85 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 86 | // Creates an alpha mask of the clip. The mask is a rasterization of elements through the |
| 87 | // rect specified by clipSpaceIBounds. |
robertphillips | c99b8f0 | 2016-05-15 07:53:35 -0700 | [diff] [blame^] | 88 | static sk_sp<GrTexture> CreateAlphaClipMask(GrContext*, |
| 89 | int32_t elementsGenID, |
| 90 | GrReducedClip::InitialState initialState, |
| 91 | const GrReducedClip::ElementList& elements, |
| 92 | const SkVector& clipToMaskOffset, |
| 93 | const SkIRect& clipSpaceIBounds); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 94 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 95 | // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture. |
robertphillips | c99b8f0 | 2016-05-15 07:53:35 -0700 | [diff] [blame^] | 96 | static sk_sp<GrTexture> CreateSoftwareClipMask(GrContext*, |
| 97 | int32_t elementsGenID, |
| 98 | GrReducedClip::InitialState initialState, |
| 99 | const GrReducedClip::ElementList& elements, |
| 100 | const SkVector& clipToMaskOffset, |
| 101 | const SkIRect& clipSpaceIBounds); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 102 | |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 103 | static bool UseSWOnlyPath(GrContext*, |
| 104 | const GrPipelineBuilder&, |
| 105 | const GrRenderTarget* rt, |
| 106 | const SkVector& clipToMaskOffset, |
| 107 | const GrReducedClip::ElementList& elements); |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 108 | |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 109 | GrTexture* createCachedMask(int width, int height, const GrUniqueKey& key, bool renderTarget); |
| 110 | |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 111 | static const int kMaxAnalyticElements = 4; |
| 112 | |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 113 | GrDrawTarget* fDrawTarget; // This is our owning draw target. |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 114 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 115 | typedef SkNoncopyable INHERITED; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 116 | }; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 117 | #endif // GrClipMaskManager_DEFINED |