robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 1 | /* |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 2 | * Copyright 2016 Google Inc. |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 7 | #ifndef GrClipStackClip_DEFINED |
| 8 | #define GrClipStackClip_DEFINED |
| 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/core/SkClipStack.h" |
| 11 | #include "src/gpu/GrClip.h" |
| 12 | #include "src/gpu/GrReducedClip.h" |
robertphillips@google.com | 1fcc1b8 | 2012-08-29 12:52:05 +0000 | [diff] [blame] | 13 | |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 14 | class GrPathRenderer; |
Robert Phillips | 875218e | 2017-02-24 08:37:13 -0500 | [diff] [blame] | 15 | class GrTextureProxy; |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 16 | |
| 17 | /** |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 18 | * GrClipStackClip can apply a generic SkClipStack to the draw state. It may need to generate an |
| 19 | * 8-bit alpha clip mask and/or modify the stencil buffer during apply(). |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 20 | */ |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 21 | class GrClipStackClip final : public GrClip { |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 22 | public: |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame^] | 23 | GrClipStackClip(const SkClipStack* stack = nullptr, |
| 24 | const SkMatrixProvider* matrixProvider = nullptr) { |
| 25 | this->reset(stack, matrixProvider); |
| 26 | } |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 27 | |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame^] | 28 | void reset(const SkClipStack* stack, const SkMatrixProvider* matrixProvider) { |
| 29 | fStack = stack; |
| 30 | fMatrixProvider = matrixProvider; |
| 31 | } |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 32 | |
| 33 | bool quickContains(const SkRect&) const final; |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 34 | bool quickContains(const SkRRect&) const final; |
Michael Ludwig | c002d56 | 2020-05-13 14:17:57 -0400 | [diff] [blame] | 35 | SkIRect getConservativeBounds(int width, int height) const final; |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 36 | bool apply(GrRecordingContext*, GrRenderTargetContext*, bool useHWAA, |
| 37 | bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const final; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 38 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 39 | bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const override; |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 40 | |
Robert Phillips | 875218e | 2017-02-24 08:37:13 -0500 | [diff] [blame] | 41 | sk_sp<GrTextureProxy> testingOnly_createClipMask(GrContext*) const; |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 42 | static const char kMaskTestTag[]; |
Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 43 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 44 | private: |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 45 | static bool PathNeedsSWRenderer(GrRecordingContext* context, |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 46 | const SkIRect& scissorRect, |
| 47 | bool hasUserStencilSettings, |
| 48 | const GrRenderTargetContext*, |
| 49 | const SkMatrix& viewMatrix, |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 50 | const SkClipStack::Element* element, |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 51 | GrPathRenderer** prOut, |
| 52 | bool needsStencil); |
| 53 | |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 54 | bool applyClipMask(GrRecordingContext*, GrRenderTargetContext*, const GrReducedClip&, |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 55 | bool hasUserStencilSettings, GrAppliedClip*) const; |
| 56 | |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 57 | // Creates an alpha mask of the clip. The mask is a rasterization of elements through the |
| 58 | // rect specified by clipSpaceIBounds. |
Greg Daniel | e32506b | 2020-02-10 16:00:54 -0500 | [diff] [blame] | 59 | GrSurfaceProxyView createAlphaClipMask(GrRecordingContext*, const GrReducedClip&) const; |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 60 | |
| 61 | // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture. |
Greg Daniel | e32506b | 2020-02-10 16:00:54 -0500 | [diff] [blame] | 62 | GrSurfaceProxyView createSoftwareClipMask(GrRecordingContext*, const GrReducedClip&, |
| 63 | GrRenderTargetContext*) const; |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 64 | |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 65 | static bool UseSWOnlyPath(GrRecordingContext*, |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 66 | bool hasUserStencilSettings, |
| 67 | const GrRenderTargetContext*, |
| 68 | const GrReducedClip&); |
| 69 | |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame^] | 70 | const SkClipStack* fStack; |
| 71 | const SkMatrixProvider* fMatrixProvider; // for applying clip shaders |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 72 | }; |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 73 | |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 74 | #endif // GrClipStackClip_DEFINED |