OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #ifndef GrClipMaskManager_DEFINED | 7 #ifndef GrClipMaskManager_DEFINED |
8 #define GrClipMaskManager_DEFINED | 8 #define GrClipMaskManager_DEFINED |
9 | 9 |
10 #include "GrPipelineBuilder.h" | 10 #include "GrPipelineBuilder.h" |
11 #include "GrReducedClip.h" | 11 #include "GrReducedClip.h" |
12 #include "SkClipStack.h" | 12 #include "SkClipStack.h" |
13 #include "SkTypes.h" | 13 #include "SkTypes.h" |
14 | 14 |
15 class GrAppliedClip; | 15 class GrAppliedClip; |
16 class GrClipStackClip; | 16 class GrClipStackClip; |
17 class GrDrawTarget; | 17 class GrDrawContext; |
| 18 class GrFixedClip; |
18 class GrPathRenderer; | 19 class GrPathRenderer; |
19 class GrPathRendererChain; | 20 class GrPathRendererChain; |
20 class GrResourceProvider; | 21 class GrResourceProvider; |
21 class GrTexture; | 22 class GrTexture; |
22 class GrTextureProvider; | 23 class GrTextureProvider; |
23 | 24 |
24 /** | 25 /** |
25 * The clip mask creator handles the generation of the clip mask. If anti | 26 * The clip mask creator handles the generation of the clip mask. If anti |
26 * aliasing is requested it will (in the future) generate a single channel | 27 * aliasing is requested it will (in the future) generate a single channel |
27 * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit | 28 * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit |
28 * mask in the stencil buffer. In the non anti-aliasing case, if the clip | 29 * mask in the stencil buffer. In the non anti-aliasing case, if the clip |
29 * mask can be represented as a rectangle then scissoring is used. In all | 30 * mask can be represented as a rectangle then scissoring is used. In all |
30 * cases scissoring is used to bound the range of the clip mask. | 31 * cases scissoring is used to bound the range of the clip mask. |
31 */ | 32 */ |
32 class GrClipMaskManager : SkNoncopyable { | 33 // This has to remain a class, for now, so it can be friended (by GrDrawContext
& GrContext) |
| 34 class GrClipMaskManager { |
33 public: | 35 public: |
34 GrClipMaskManager(GrDrawTarget* owner) : fDrawTarget(owner) {} | |
35 | |
36 /** | 36 /** |
37 * Creates a clip mask if necessary as a stencil buffer or alpha texture | 37 * Creates a clip mask if necessary as a stencil buffer or alpha texture |
38 * and sets the GrGpu's scissor and stencil state. If the return is false | 38 * and sets the GrGpu's scissor and stencil state. If the return is false |
39 * then the draw can be skipped. devBounds is optional but can help optimize | 39 * then the draw can be skipped. devBounds is optional but can help optimize |
40 * clipping. | 40 * clipping. |
41 */ | 41 */ |
42 bool setupClipping(const GrPipelineBuilder&, const GrClipStackClip&, const S
kRect* devBounds, | 42 static bool SetupClipping(GrContext*, const GrPipelineBuilder&, GrDrawContex
t*, |
43 GrAppliedClip*); | 43 const GrClipStackClip&, const SkRect* devBounds, G
rAppliedClip*); |
44 | 44 |
45 private: | 45 private: |
46 inline GrContext* getContext(); | 46 static void DrawNonAARect(GrDrawContext* drawContext, |
47 inline const GrCaps* caps() const; | 47 const GrFixedClip& clip, |
48 inline GrResourceProvider* resourceProvider(); | 48 const SkMatrix& viewMatrix, |
| 49 const SkRect& rect, |
| 50 bool isAA, |
| 51 const GrUserStencilSettings* stencilSettings); |
49 | 52 |
50 static bool PathNeedsSWRenderer(GrContext* context, | 53 static bool PathNeedsSWRenderer(GrContext* context, |
51 bool hasUserStencilSettings, | 54 bool hasUserStencilSettings, |
52 const GrRenderTarget* rt, | 55 const GrDrawContext*, |
53 const SkMatrix& viewMatrix, | 56 const SkMatrix& viewMatrix, |
54 const SkClipStack::Element* element, | 57 const SkClipStack::Element* element, |
55 GrPathRenderer** prOut, | 58 GrPathRenderer** prOut, |
56 bool needsStencil); | 59 bool needsStencil); |
57 static GrPathRenderer* GetPathRenderer(GrContext* context, | |
58 GrTexture* texture, | |
59 const SkMatrix& viewMatrix, | |
60 const SkClipStack::Element* element); | |
61 | |
62 // Attempts to install a series of coverage effects to implement the clip. R
eturn indicates | |
63 // whether the element list was successfully converted to processors. *fp ma
y be nullptr even | |
64 // when the function succeeds because all the elements were ignored. TODO: M
ake clip reduction | |
65 // bounds-aware and stop checking bounds in this function. Similarly, we sho
uldn't need to pass | |
66 // abortIfAA, but we don't yet know if all the AA elements will be eliminate
d. | |
67 bool getAnalyticClipProcessor(const GrReducedClip::ElementList&, | |
68 bool abortIfAA, | |
69 SkVector& clipOffset, | |
70 const SkRect* devBounds, | |
71 sk_sp<const GrFragmentProcessor>* fp); | |
72 | 60 |
73 // Draws the clip into the stencil buffer | 61 // Draws the clip into the stencil buffer |
74 bool createStencilClipMask(GrRenderTarget*, | 62 static bool CreateStencilClipMask(GrContext*, |
75 int32_t elementsGenID, | 63 GrDrawContext*, |
76 GrReducedClip::InitialState initialState, | 64 int32_t elementsGenID, |
77 const GrReducedClip::ElementList& elements, | 65 GrReducedClip::InitialState initialState, |
78 const SkIRect& clipSpaceIBounds, | 66 const GrReducedClip::ElementList& elements
, |
79 const SkIPoint& clipSpaceToStencilOffset); | 67 const SkIRect& clipSpaceIBounds, |
| 68 const SkIPoint& clipSpaceToStencilOffset); |
80 | 69 |
81 // Creates an alpha mask of the clip. The mask is a rasterization of element
s through the | 70 // Creates an alpha mask of the clip. The mask is a rasterization of element
s through the |
82 // rect specified by clipSpaceIBounds. | 71 // rect specified by clipSpaceIBounds. |
83 static sk_sp<GrTexture> CreateAlphaClipMask(GrContext*, | 72 static sk_sp<GrTexture> CreateAlphaClipMask(GrContext*, |
84 int32_t elementsGenID, | 73 int32_t elementsGenID, |
85 GrReducedClip::InitialState init
ialState, | 74 GrReducedClip::InitialState init
ialState, |
86 const GrReducedClip::ElementList
& elements, | 75 const GrReducedClip::ElementList
& elements, |
87 const SkVector& clipToMaskOffset
, | 76 const SkVector& clipToMaskOffset
, |
88 const SkIRect& clipSpaceIBounds)
; | 77 const SkIRect& clipSpaceIBounds)
; |
89 | 78 |
90 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the
result texture. | 79 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the
result texture. |
91 static sk_sp<GrTexture> CreateSoftwareClipMask(GrTextureProvider*, | 80 static sk_sp<GrTexture> CreateSoftwareClipMask(GrTextureProvider*, |
92 int32_t elementsGenID, | 81 int32_t elementsGenID, |
93 GrReducedClip::InitialState i
nitialState, | 82 GrReducedClip::InitialState i
nitialState, |
94 const GrReducedClip::ElementL
ist& elements, | 83 const GrReducedClip::ElementL
ist& elements, |
95 const SkVector& clipToMaskOff
set, | 84 const SkVector& clipToMaskOff
set, |
96 const SkIRect& clipSpaceIBoun
ds); | 85 const SkIRect& clipSpaceIBoun
ds); |
97 | 86 |
98 static bool UseSWOnlyPath(GrContext*, | 87 static bool UseSWOnlyPath(GrContext*, |
99 const GrPipelineBuilder&, | 88 const GrPipelineBuilder&, |
100 const GrRenderTarget* rt, | 89 const GrDrawContext*, |
101 const SkVector& clipToMaskOffset, | 90 const SkVector& clipToMaskOffset, |
102 const GrReducedClip::ElementList& elements); | 91 const GrReducedClip::ElementList& elements); |
103 | 92 |
104 GrTexture* createCachedMask(int width, int height, const GrUniqueKey& key, b
ool renderTarget); | 93 static GrTexture* CreateCachedMask(int width, int height, const GrUniqueKey&
key, |
| 94 bool renderTarget); |
| 95 }; |
105 | 96 |
106 static const int kMaxAnalyticElements = 4; | |
107 | |
108 GrDrawTarget* fDrawTarget; // This is our owning draw target. | |
109 | |
110 typedef SkNoncopyable INHERITED; | |
111 }; | |
112 #endif // GrClipMaskManager_DEFINED | 97 #endif // GrClipMaskManager_DEFINED |
OLD | NEW |