blob: cb1f6837020d68fbcadc0b687f0d5f403459650a [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
bsalomon@google.coma3201942012-06-21 19:58:20 +000041private:
robertphillips68737822015-10-29 12:12:21 -070042 static bool PathNeedsSWRenderer(GrContext* context,
cdalton93a379b2016-05-11 13:58:08 -070043 bool hasUserStencilSettings,
robertphillips976f5f02016-06-03 10:59:20 -070044 const GrDrawContext*,
robertphillips68737822015-10-29 12:12:21 -070045 const SkMatrix& viewMatrix,
46 const SkClipStack::Element* element,
47 GrPathRenderer** prOut,
48 bool needsStencil);
commit-bot@chromium.orge5a041c2014-03-07 19:43:43 +000049
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000050 // Draws the clip into the stencil buffer
robertphillips976f5f02016-06-03 10:59:20 -070051 static bool CreateStencilClipMask(GrContext*,
52 GrDrawContext*,
csmartdalton77f2fae2016-08-08 09:55:06 -070053 const GrReducedClip&,
robertphillips976f5f02016-06-03 10:59:20 -070054 const SkIPoint& clipSpaceToStencilOffset);
joshualitt9853cce2014-11-17 14:22:48 -080055
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000056 // Creates an alpha mask of the clip. The mask is a rasterization of elements through the
57 // rect specified by clipSpaceIBounds.
robertphillipsc99b8f02016-05-15 07:53:35 -070058 static sk_sp<GrTexture> CreateAlphaClipMask(GrContext*,
csmartdalton77f2fae2016-08-08 09:55:06 -070059 const GrReducedClip&,
60 const SkVector& clipToMaskOffset);
joshualitt9853cce2014-11-17 14:22:48 -080061
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000062 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture.
robertphillips0152d732016-05-20 06:38:43 -070063 static sk_sp<GrTexture> CreateSoftwareClipMask(GrTextureProvider*,
csmartdalton77f2fae2016-08-08 09:55:06 -070064 const GrReducedClip&,
65 const SkVector& clipToMaskOffset);
robertphillips@google.comf294b772012-04-27 14:29:26 +000066
robertphillips391395d2016-03-02 09:26:36 -080067 static bool UseSWOnlyPath(GrContext*,
robertphillips59cf61a2016-07-13 09:18:21 -070068 bool hasUserStencilSettings,
robertphillips976f5f02016-06-03 10:59:20 -070069 const GrDrawContext*,
robertphillips391395d2016-03-02 09:26:36 -080070 const SkVector& clipToMaskOffset,
71 const GrReducedClip::ElementList& elements);
bsalomon@google.comb68addd2012-12-14 13:36:53 +000072
robertphillips976f5f02016-06-03 10:59:20 -070073 static GrTexture* CreateCachedMask(int width, int height, const GrUniqueKey& key,
74 bool renderTarget);
csmartdaltonc6f411e2016-08-05 22:32:12 -070075
76 SkIPoint fOrigin;
77 SkAutoTUnref<const SkClipStack> fStack;
robertphillips@google.com1e945b72012-04-16 18:03:03 +000078};
robertphillips976f5f02016-06-03 10:59:20 -070079
csmartdaltonc6f411e2016-08-05 22:32:12 -070080#endif // GrClipStackClip_DEFINED