1/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#ifndef GrClipStackClip_DEFINED
8#define GrClipStackClip_DEFINED
9
10#include "src/core/SkClipStack.h"
11#include "src/gpu/GrClip.h"
12#include "src/gpu/GrReducedClip.h"
13
14class GrPathRenderer;
15class GrTextureProxy;
16
17/**
18 * 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().
20 */
21class GrClipStackClip final : public GrClip {
22public:
23 GrClipStackClip(const SkClipStack* stack = nullptr) { this->reset(stack); }
24
25 void reset(const SkClipStack* stack) { fStack = stack; }
26
27 bool quickContains(const SkRect&) const final;
28 bool quickContains(const SkRRect&) const final;
29 void getConservativeBounds(int width, int height, SkIRect* devResult,
30 bool* isIntersectionOfRects) const final;
31 bool apply(GrRecordingContext*, GrRenderTargetContext*, bool useHWAA,
32 bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const final;
33
34 bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const override;
35
36 sk_sp<GrTextureProxy> testingOnly_createClipMask(GrContext*) const;
37 static const char kMaskTestTag[];
38
39private:
40 static bool PathNeedsSWRenderer(GrRecordingContext* context,
41 const SkIRect& scissorRect,
42 bool hasUserStencilSettings,
43 const GrRenderTargetContext*,
44 const SkMatrix& viewMatrix,
45 const SkClipStack::Element* element,
46 GrPathRenderer** prOut,
47 bool needsStencil);
48
49 bool applyClipMask(GrRecordingContext*, GrRenderTargetContext*, const GrReducedClip&,
50 bool hasUserStencilSettings, GrAppliedClip*) const;
51
52 // Creates an alpha mask of the clip. The mask is a rasterization of elements through the
53 // rect specified by clipSpaceIBounds.
54 GrSurfaceProxyView createAlphaClipMask(GrRecordingContext*, const GrReducedClip&) const;
55
56 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture.
57 GrSurfaceProxyView createSoftwareClipMask(GrRecordingContext*, const GrReducedClip&,
58 GrRenderTargetContext*) const;
59
60 static bool UseSWOnlyPath(GrRecordingContext*,
61 bool hasUserStencilSettings,
62 const GrRenderTargetContext*,
63 const GrReducedClip&);
64
65 const SkClipStack* fStack;
66};
67
68#endif // GrClipStackClip_DEFINED
69