blob: 6f4b2b10878b7319f0f67bbb8cd03d4a61418cb1 [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;
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:
Brian Salomon9a767722017-03-13 17:57:28 -040023 GrClipStackClip(const SkClipStack* stack = nullptr) { this->reset(stack); }
csmartdaltonc6f411e2016-08-05 22:32:12 -070024
Brian Salomon9a767722017-03-13 17:57:28 -040025 void reset(const SkClipStack* stack) { fStack = stack; }
csmartdaltonc6f411e2016-08-05 22:32:12 -070026
27 bool quickContains(const SkRect&) const final;
bsalomon7f0d9f32016-08-15 14:49:10 -070028 bool quickContains(const SkRRect&) const final;
csmartdaltonc6f411e2016-08-05 22:32:12 -070029 void getConservativeBounds(int width, int height, SkIRect* devResult,
30 bool* isIntersectionOfRects) const final;
Robert Phillips6f0e02f2019-02-13 11:02:28 -050031 bool apply(GrRecordingContext*, GrRenderTargetContext*, bool useHWAA,
32 bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const final;
robertphillips391395d2016-03-02 09:26:36 -080033
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050034 bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const override;
bsalomoncb31e512016-08-26 10:48:19 -070035
Robert Phillips875218e2017-02-24 08:37:13 -050036 sk_sp<GrTextureProxy> testingOnly_createClipMask(GrContext*) const;
Brian Salomonc3833b42018-07-09 18:23:58 +000037 static const char kMaskTestTag[];
Brian Salomon19f0ed52017-01-06 13:54:58 -050038
bsalomon@google.coma3201942012-06-21 19:58:20 +000039private:
Robert Phillips6f0e02f2019-02-13 11:02:28 -050040 static bool PathNeedsSWRenderer(GrRecordingContext* context,
Chris Daltonc5348082018-03-30 15:59:38 +000041 const SkIRect& scissorRect,
42 bool hasUserStencilSettings,
43 const GrRenderTargetContext*,
44 const SkMatrix& viewMatrix,
Brian Salomonc3833b42018-07-09 18:23:58 +000045 const SkClipStack::Element* element,
Chris Daltonc5348082018-03-30 15:59:38 +000046 GrPathRenderer** prOut,
47 bool needsStencil);
48
Robert Phillips6f0e02f2019-02-13 11:02:28 -050049 bool applyClipMask(GrRecordingContext*, GrRenderTargetContext*, const GrReducedClip&,
Chris Daltona32a3c32017-12-05 10:05:21 -070050 bool hasUserStencilSettings, GrAppliedClip*) const;
51
Chris Daltonc5348082018-03-30 15:59:38 +000052 // Creates an alpha mask of the clip. The mask is a rasterization of elements through the
53 // rect specified by clipSpaceIBounds.
Robert Phillips6f0e02f2019-02-13 11:02:28 -050054 sk_sp<GrTextureProxy> createAlphaClipMask(GrRecordingContext*, const GrReducedClip&) const;
Chris Daltonc5348082018-03-30 15:59:38 +000055
56 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture.
Robert Phillips6f0e02f2019-02-13 11:02:28 -050057 sk_sp<GrTextureProxy> createSoftwareClipMask(GrRecordingContext*, const GrReducedClip&,
Brian Osman5d034742017-09-11 13:38:55 -040058 GrRenderTargetContext*) const;
robertphillips@google.comf294b772012-04-27 14:29:26 +000059
Robert Phillips6f0e02f2019-02-13 11:02:28 -050060 static bool UseSWOnlyPath(GrRecordingContext*,
Chris Daltonc5348082018-03-30 15:59:38 +000061 bool hasUserStencilSettings,
62 const GrRenderTargetContext*,
63 const GrReducedClip&);
64
Mike Reed7ba4d712017-03-10 00:21:52 -050065 const SkClipStack* fStack;
robertphillips@google.com1e945b72012-04-16 18:03:03 +000066};
robertphillips976f5f02016-06-03 10:59:20 -070067
csmartdaltonc6f411e2016-08-05 22:32:12 -070068#endif // GrClipStackClip_DEFINED