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 | |
| 10 | #include "GrClip.h" |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 11 | #include "GrReducedClip.h" |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 12 | #include "SkClipStack.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; |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 15 | class GrTexture; |
| 16 | class GrTextureProvider; |
| 17 | class GrUniqueKey; |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 18 | |
| 19 | /** |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 20 | * GrClipStackClip can apply a generic SkClipStack to the draw state. It may need to generate an |
| 21 | * 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] | 22 | */ |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 23 | class GrClipStackClip final : public GrClip { |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 24 | public: |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 25 | GrClipStackClip(const SkClipStack* stack = nullptr, const SkIPoint* origin = nullptr) { |
| 26 | this->reset(stack, origin); |
| 27 | } |
| 28 | |
| 29 | void reset(const SkClipStack* stack = nullptr, const SkIPoint* origin = nullptr) { |
| 30 | fOrigin = origin ? *origin : SkIPoint::Make(0, 0); |
| 31 | fStack.reset(SkSafeRef(stack)); |
| 32 | } |
| 33 | |
| 34 | bool quickContains(const SkRect&) const final; |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 35 | bool quickContains(const SkRRect&) const final; |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 36 | void getConservativeBounds(int width, int height, SkIRect* devResult, |
| 37 | bool* isIntersectionOfRects) const final; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 38 | bool apply(GrContext*, GrRenderTargetContext*, bool useHWAA, bool hasUserStencilSettings, |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 39 | GrAppliedClip* out) const final; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 40 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 41 | bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const override; |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 42 | |
Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 43 | sk_sp<GrTexture> testingOnly_createClipMask(GrContext*) const; |
| 44 | static const char kMaskTestTag[]; |
| 45 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 46 | private: |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 47 | static bool PathNeedsSWRenderer(GrContext* context, |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 48 | bool hasUserStencilSettings, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 49 | const GrRenderTargetContext*, |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 50 | const SkMatrix& viewMatrix, |
| 51 | const SkClipStack::Element* element, |
| 52 | GrPathRenderer** prOut, |
| 53 | bool needsStencil); |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 54 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 55 | // Creates an alpha mask of the clip. The mask is a rasterization of elements through the |
| 56 | // rect specified by clipSpaceIBounds. |
Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 57 | sk_sp<GrTexture> createAlphaClipMask(GrContext*, const GrReducedClip&) const; |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 58 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 59 | // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture. |
Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 60 | sk_sp<GrTexture> createSoftwareClipMask(GrContext*, const GrReducedClip&) const; |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 61 | |
Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 62 | static bool UseSWOnlyPath(GrContext*, |
| 63 | bool hasUserStencilSettings, |
| 64 | const GrRenderTargetContext*, |
| 65 | const GrReducedClip&); |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 66 | |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 67 | SkIPoint fOrigin; |
| 68 | sk_sp<const SkClipStack> fStack; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 69 | }; |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 70 | |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 71 | #endif // GrClipStackClip_DEFINED |