blob: 7bef90bb9523ac42f25a445895ef5cf54826ce8f [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/core/SkClipStack.h"
11#include "src/gpu/GrClip.h"
12#include "src/gpu/GrReducedClip.h"
robertphillips@google.com1fcc1b82012-08-29 12:52:05 +000013
csmartdaltonc6f411e2016-08-05 22:32:12 -070014class GrPathRenderer;
Robert Phillips875218e2017-02-24 08:37:13 -050015class GrTextureProxy;
bsalomon0ba8c242015-10-07 09:20:28 -070016
17/**
csmartdaltonc6f411e2016-08-05 22:32:12 -070018 * 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.com1e945b72012-04-16 18:03:03 +000020 */
csmartdaltonc6f411e2016-08-05 22:32:12 -070021class GrClipStackClip final : public GrClip {
robertphillips@google.com1e945b72012-04-16 18:03:03 +000022public:
Michael Ludwig4e221bd2020-06-05 11:29:36 -040023 GrClipStackClip(const SkClipStack* stack = nullptr,
24 const SkMatrixProvider* matrixProvider = nullptr) {
25 this->reset(stack, matrixProvider);
26 }
csmartdaltonc6f411e2016-08-05 22:32:12 -070027
Michael Ludwig4e221bd2020-06-05 11:29:36 -040028 void reset(const SkClipStack* stack, const SkMatrixProvider* matrixProvider) {
29 fStack = stack;
30 fMatrixProvider = matrixProvider;
31 }
csmartdaltonc6f411e2016-08-05 22:32:12 -070032
33 bool quickContains(const SkRect&) const final;
bsalomon7f0d9f32016-08-15 14:49:10 -070034 bool quickContains(const SkRRect&) const final;
Michael Ludwigc002d562020-05-13 14:17:57 -040035 SkIRect getConservativeBounds(int width, int height) const final;
Robert Phillips6f0e02f2019-02-13 11:02:28 -050036 bool apply(GrRecordingContext*, GrRenderTargetContext*, bool useHWAA,
37 bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const final;
robertphillips391395d2016-03-02 09:26:36 -080038
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050039 bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const override;
bsalomoncb31e512016-08-26 10:48:19 -070040
Robert Phillips875218e2017-02-24 08:37:13 -050041 sk_sp<GrTextureProxy> testingOnly_createClipMask(GrContext*) const;
Brian Salomonc3833b42018-07-09 18:23:58 +000042 static const char kMaskTestTag[];
Brian Salomon19f0ed52017-01-06 13:54:58 -050043
bsalomon@google.coma3201942012-06-21 19:58:20 +000044private:
Robert Phillips6f0e02f2019-02-13 11:02:28 -050045 static bool PathNeedsSWRenderer(GrRecordingContext* context,
Chris Daltonc5348082018-03-30 15:59:38 +000046 const SkIRect& scissorRect,
47 bool hasUserStencilSettings,
48 const GrRenderTargetContext*,
49 const SkMatrix& viewMatrix,
Brian Salomonc3833b42018-07-09 18:23:58 +000050 const SkClipStack::Element* element,
Chris Daltonc5348082018-03-30 15:59:38 +000051 GrPathRenderer** prOut,
52 bool needsStencil);
53
Robert Phillips6f0e02f2019-02-13 11:02:28 -050054 bool applyClipMask(GrRecordingContext*, GrRenderTargetContext*, const GrReducedClip&,
Chris Daltona32a3c32017-12-05 10:05:21 -070055 bool hasUserStencilSettings, GrAppliedClip*) const;
56
Chris Daltonc5348082018-03-30 15:59:38 +000057 // Creates an alpha mask of the clip. The mask is a rasterization of elements through the
58 // rect specified by clipSpaceIBounds.
Greg Daniele32506b2020-02-10 16:00:54 -050059 GrSurfaceProxyView createAlphaClipMask(GrRecordingContext*, const GrReducedClip&) const;
Chris Daltonc5348082018-03-30 15:59:38 +000060
61 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture.
Greg Daniele32506b2020-02-10 16:00:54 -050062 GrSurfaceProxyView createSoftwareClipMask(GrRecordingContext*, const GrReducedClip&,
63 GrRenderTargetContext*) const;
robertphillips@google.comf294b772012-04-27 14:29:26 +000064
Robert Phillips6f0e02f2019-02-13 11:02:28 -050065 static bool UseSWOnlyPath(GrRecordingContext*,
Chris Daltonc5348082018-03-30 15:59:38 +000066 bool hasUserStencilSettings,
67 const GrRenderTargetContext*,
68 const GrReducedClip&);
69
Michael Ludwig4e221bd2020-06-05 11:29:36 -040070 const SkClipStack* fStack;
71 const SkMatrixProvider* fMatrixProvider; // for applying clip shaders
robertphillips@google.com1e945b72012-04-16 18:03:03 +000072};
robertphillips976f5f02016-06-03 10:59:20 -070073
csmartdaltonc6f411e2016-08-05 22:32:12 -070074#endif // GrClipStackClip_DEFINED