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 | |
14 | class GrPathRenderer; |
15 | class 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 | */ |
21 | class GrClipStackClip final : public GrClip { |
22 | public: |
23 | GrClipStackClip(const SkISize& dimensions, |
24 | const SkClipStack* stack = nullptr, |
25 | const SkMatrixProvider* matrixProvider = nullptr) |
26 | : fDeviceSize(dimensions) |
27 | , fStack(stack) |
28 | , fMatrixProvider(matrixProvider) {} |
29 | |
30 | SkIRect getConservativeBounds() const final; |
31 | Effect apply(GrRecordingContext*, GrRenderTargetContext*, GrAAType aaType, |
32 | bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const final; |
33 | PreClipResult preApply(const SkRect& drawBounds, GrAA aa) const final; |
34 | |
35 | sk_sp<GrTextureProxy> testingOnly_createClipMask(GrRecordingContext*) const; |
36 | static const char kMaskTestTag[]; |
37 | |
38 | private: |
39 | static bool PathNeedsSWRenderer(GrRecordingContext* context, |
40 | const SkIRect& scissorRect, |
41 | bool hasUserStencilSettings, |
42 | const GrRenderTargetContext*, |
43 | const SkMatrix& viewMatrix, |
44 | const SkClipStack::Element* element, |
45 | GrPathRenderer** prOut, |
46 | bool needsStencil); |
47 | |
48 | bool applyClipMask(GrRecordingContext*, GrRenderTargetContext*, const GrReducedClip&, |
49 | bool hasUserStencilSettings, GrAppliedClip*) const; |
50 | |
51 | // Creates an alpha mask of the clip. The mask is a rasterization of elements through the |
52 | // rect specified by clipSpaceIBounds. |
53 | GrSurfaceProxyView createAlphaClipMask(GrRecordingContext*, const GrReducedClip&) const; |
54 | |
55 | // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture. |
56 | GrSurfaceProxyView createSoftwareClipMask(GrRecordingContext*, const GrReducedClip&, |
57 | GrRenderTargetContext*) const; |
58 | |
59 | static bool UseSWOnlyPath(GrRecordingContext*, |
60 | bool hasUserStencilSettings, |
61 | const GrRenderTargetContext*, |
62 | const GrReducedClip&); |
63 | |
64 | // SkClipStack does not track device bounds explicitly, but it will refine these device bounds |
65 | // as clip elements are added to the stack. |
66 | SkISize fDeviceSize; |
67 | const SkClipStack* fStack; |
68 | const SkMatrixProvider* fMatrixProvider; // for applying clip shaders |
69 | }; |
70 | |
71 | #endif // GrClipStackClip_DEFINED |
72 | |