blob: ad143d6969705e5b817ca0e4b35d09154d25736b [file] [log] [blame]
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001/*
csmartdaltonc6f411e2016-08-05 22:32:12 -07002 * Copyright 2016 Google Inc.
robertphillips@google.com1e945b72012-04-16 18:03:03 +00003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
csmartdaltonc6f411e2016-08-05 22:32:12 -07007#ifndef GrClipStackClip_DEFINED
8#define GrClipStackClip_DEFINED
9
10#include "GrClip.h"
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000011#include "GrReducedClip.h"
robertphillips@google.com641f8b12012-07-31 19:15:58 +000012#include "SkClipStack.h"
robertphillips@google.com1fcc1b82012-08-29 12:52:05 +000013
csmartdaltonc6f411e2016-08-05 22:32:12 -070014class GrPathRenderer;
csmartdalton02fa32c2016-08-19 13:29:27 -070015class GrTexture;
16class GrTextureProvider;
17class GrUniqueKey;
bsalomon0ba8c242015-10-07 09:20:28 -070018
19/**
csmartdaltonc6f411e2016-08-05 22:32:12 -070020 * 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.com1e945b72012-04-16 18:03:03 +000022 */
csmartdaltonc6f411e2016-08-05 22:32:12 -070023class GrClipStackClip final : public GrClip {
robertphillips@google.com1e945b72012-04-16 18:03:03 +000024public:
csmartdaltonc6f411e2016-08-05 22:32:12 -070025 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;
bsalomon7f0d9f32016-08-15 14:49:10 -070035 bool quickContains(const SkRRect&) const final;
csmartdaltonc6f411e2016-08-05 22:32:12 -070036 void getConservativeBounds(int width, int height, SkIRect* devResult,
37 bool* isIntersectionOfRects) const final;
csmartdaltond211e782016-08-15 11:17:19 -070038 bool apply(GrContext*, GrDrawContext*, bool useHWAA, bool hasUserStencilSettings,
csmartdaltonc6f411e2016-08-05 22:32:12 -070039 GrAppliedClip* out) const final;
robertphillips391395d2016-03-02 09:26:36 -080040
bsalomoncb31e512016-08-26 10:48:19 -070041 bool isRRect(const SkRect& rtBounds, SkRRect* rr, bool* aa) const override;
42
bsalomon@google.coma3201942012-06-21 19:58:20 +000043private:
robertphillips68737822015-10-29 12:12:21 -070044 static bool PathNeedsSWRenderer(GrContext* context,
cdalton93a379b2016-05-11 13:58:08 -070045 bool hasUserStencilSettings,
robertphillips976f5f02016-06-03 10:59:20 -070046 const GrDrawContext*,
robertphillips68737822015-10-29 12:12:21 -070047 const SkMatrix& viewMatrix,
48 const SkClipStack::Element* element,
49 GrPathRenderer** prOut,
50 bool needsStencil);
commit-bot@chromium.orge5a041c2014-03-07 19:43:43 +000051
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000052 // Draws the clip into the stencil buffer
robertphillips976f5f02016-06-03 10:59:20 -070053 static bool CreateStencilClipMask(GrContext*,
54 GrDrawContext*,
csmartdalton77f2fae2016-08-08 09:55:06 -070055 const GrReducedClip&,
robertphillips976f5f02016-06-03 10:59:20 -070056 const SkIPoint& clipSpaceToStencilOffset);
joshualitt9853cce2014-11-17 14:22:48 -080057
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000058 // Creates an alpha mask of the clip. The mask is a rasterization of elements through the
59 // rect specified by clipSpaceIBounds.
robertphillipsc99b8f02016-05-15 07:53:35 -070060 static sk_sp<GrTexture> CreateAlphaClipMask(GrContext*,
csmartdalton77f2fae2016-08-08 09:55:06 -070061 const GrReducedClip&,
62 const SkVector& clipToMaskOffset);
joshualitt9853cce2014-11-17 14:22:48 -080063
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000064 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture.
robertphillips0152d732016-05-20 06:38:43 -070065 static sk_sp<GrTexture> CreateSoftwareClipMask(GrTextureProvider*,
csmartdalton77f2fae2016-08-08 09:55:06 -070066 const GrReducedClip&,
67 const SkVector& clipToMaskOffset);
robertphillips@google.comf294b772012-04-27 14:29:26 +000068
robertphillips391395d2016-03-02 09:26:36 -080069 static bool UseSWOnlyPath(GrContext*,
robertphillips59cf61a2016-07-13 09:18:21 -070070 bool hasUserStencilSettings,
robertphillips976f5f02016-06-03 10:59:20 -070071 const GrDrawContext*,
robertphillips391395d2016-03-02 09:26:36 -080072 const SkVector& clipToMaskOffset,
73 const GrReducedClip::ElementList& elements);
bsalomon@google.comb68addd2012-12-14 13:36:53 +000074
robertphillips976f5f02016-06-03 10:59:20 -070075 static GrTexture* CreateCachedMask(int width, int height, const GrUniqueKey& key,
76 bool renderTarget);
csmartdaltonc6f411e2016-08-05 22:32:12 -070077
78 SkIPoint fOrigin;
79 SkAutoTUnref<const SkClipStack> fStack;
robertphillips@google.com1e945b72012-04-16 18:03:03 +000080};
robertphillips976f5f02016-06-03 10:59:20 -070081
csmartdaltonc6f411e2016-08-05 22:32:12 -070082#endif // GrClipStackClip_DEFINED