blob: 1c4d40b1739f65ac03f8f74ff330c43e9b29ead9 [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;
Brian Osman11052242016-10-27 14:47:55 -040038 bool apply(GrContext*, GrRenderTargetContext*, bool useHWAA, bool hasUserStencilSettings,
csmartdaltonc6f411e2016-08-05 22:32:12 -070039 GrAppliedClip* out) const final;
robertphillips391395d2016-03-02 09:26:36 -080040
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050041 bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const override;
bsalomoncb31e512016-08-26 10:48:19 -070042
Brian Salomon19f0ed52017-01-06 13:54:58 -050043 sk_sp<GrTexture> testingOnly_createClipMask(GrContext*) const;
44 static const char kMaskTestTag[];
45
bsalomon@google.coma3201942012-06-21 19:58:20 +000046private:
robertphillips68737822015-10-29 12:12:21 -070047 static bool PathNeedsSWRenderer(GrContext* context,
cdalton93a379b2016-05-11 13:58:08 -070048 bool hasUserStencilSettings,
Brian Osman11052242016-10-27 14:47:55 -040049 const GrRenderTargetContext*,
robertphillips68737822015-10-29 12:12:21 -070050 const SkMatrix& viewMatrix,
51 const SkClipStack::Element* element,
52 GrPathRenderer** prOut,
53 bool needsStencil);
commit-bot@chromium.orge5a041c2014-03-07 19:43:43 +000054
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000055 // Creates an alpha mask of the clip. The mask is a rasterization of elements through the
56 // rect specified by clipSpaceIBounds.
Brian Salomon19f0ed52017-01-06 13:54:58 -050057 sk_sp<GrTexture> createAlphaClipMask(GrContext*, const GrReducedClip&) const;
joshualitt9853cce2014-11-17 14:22:48 -080058
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000059 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture.
Brian Salomon19f0ed52017-01-06 13:54:58 -050060 sk_sp<GrTexture> createSoftwareClipMask(GrContext*, const GrReducedClip&) const;
robertphillips@google.comf294b772012-04-27 14:29:26 +000061
Brian Salomon19f0ed52017-01-06 13:54:58 -050062 static bool UseSWOnlyPath(GrContext*,
63 bool hasUserStencilSettings,
64 const GrRenderTargetContext*,
65 const GrReducedClip&);
csmartdaltonc6f411e2016-08-05 22:32:12 -070066
Hal Canary144caf52016-11-07 17:57:18 -050067 SkIPoint fOrigin;
68 sk_sp<const SkClipStack> fStack;
robertphillips@google.com1e945b72012-04-16 18:03:03 +000069};
robertphillips976f5f02016-06-03 10:59:20 -070070
csmartdaltonc6f411e2016-08-05 22:32:12 -070071#endif // GrClipStackClip_DEFINED