blob: bfb6a908e1ba684bd825317b6d9d3eb2579d157e [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 Ludwige06a8972020-06-11 10:29:00 -040023 GrClipStackClip(const SkISize& dimensions,
24 const SkClipStack* stack = nullptr,
25 const SkMatrixProvider* matrixProvider = nullptr)
26 : fDeviceSize(dimensions)
27 , fStack(stack)
28 , fMatrixProvider(matrixProvider) {}
csmartdaltonc6f411e2016-08-05 22:32:12 -070029
Michael Ludwige06a8972020-06-11 10:29:00 -040030 SkIRect getConservativeBounds() const final;
Chris Daltonea46ef32021-07-12 15:09:06 -060031 Effect apply(GrRecordingContext*, GrSurfaceDrawContext*, GrDrawOp*, GrAAType aaType,
32 GrAppliedClip* out, SkRect* bounds) const final;
Michael Ludwig6397e802020-08-05 15:50:01 -040033 PreClipResult preApply(const SkRect& drawBounds, GrAA aa) const final;
bsalomoncb31e512016-08-26 10:48:19 -070034
Robert Phillips4e105e22020-07-16 09:18:50 -040035 sk_sp<GrTextureProxy> testingOnly_createClipMask(GrRecordingContext*) const;
Brian Salomonc3833b42018-07-09 18:23:58 +000036 static const char kMaskTestTag[];
Brian Salomon19f0ed52017-01-06 13:54:58 -050037
bsalomon@google.coma3201942012-06-21 19:58:20 +000038private:
Brian Salomoneebe7352020-12-09 16:37:04 -050039 bool applyClipMask(GrRecordingContext*, GrSurfaceDrawContext*, const GrReducedClip&,
Chris Dalton6edc8d92021-05-27 09:40:43 -060040 GrAppliedClip*) const;
Chris Daltona32a3c32017-12-05 10:05:21 -070041
Chris Daltonc5348082018-03-30 15:59:38 +000042 // Creates an alpha mask of the clip. The mask is a rasterization of elements through the
43 // rect specified by clipSpaceIBounds.
Greg Daniele32506b2020-02-10 16:00:54 -050044 GrSurfaceProxyView createAlphaClipMask(GrRecordingContext*, const GrReducedClip&) const;
Chris Daltonc5348082018-03-30 15:59:38 +000045
46 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture.
Greg Daniele32506b2020-02-10 16:00:54 -050047 GrSurfaceProxyView createSoftwareClipMask(GrRecordingContext*, const GrReducedClip&,
Brian Salomoneebe7352020-12-09 16:37:04 -050048 GrSurfaceDrawContext*) const;
robertphillips@google.comf294b772012-04-27 14:29:26 +000049
Robert Phillips6f0e02f2019-02-13 11:02:28 -050050 static bool UseSWOnlyPath(GrRecordingContext*,
Brian Salomoneebe7352020-12-09 16:37:04 -050051 const GrSurfaceDrawContext*,
Chris Daltonc5348082018-03-30 15:59:38 +000052 const GrReducedClip&);
53
Michael Ludwige06a8972020-06-11 10:29:00 -040054 // SkClipStack does not track device bounds explicitly, but it will refine these device bounds
55 // as clip elements are added to the stack.
56 SkISize fDeviceSize;
Michael Ludwig4e221bd2020-06-05 11:29:36 -040057 const SkClipStack* fStack;
58 const SkMatrixProvider* fMatrixProvider; // for applying clip shaders
robertphillips@google.com1e945b72012-04-16 18:03:03 +000059};
robertphillips976f5f02016-06-03 10:59:20 -070060
csmartdaltonc6f411e2016-08-05 22:32:12 -070061#endif // GrClipStackClip_DEFINED