| 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 "GrStencil.h" | 12 #include "GrStencil.h" |
| 13 #include "GrTexture.h" | 13 #include "GrTexture.h" |
| 14 #include "SkClipStack.h" | 14 #include "SkClipStack.h" |
| 15 #include "SkDeque.h" | 15 #include "SkDeque.h" |
| 16 #include "SkPath.h" | 16 #include "SkPath.h" |
| 17 #include "SkRefCnt.h" | 17 #include "SkRefCnt.h" |
| 18 #include "SkTLList.h" | 18 #include "SkTLList.h" |
| 19 #include "SkTypes.h" | 19 #include "SkTypes.h" |
| 20 | 20 |
| 21 class GrDrawTarget; | 21 class GrDrawTarget; |
| 22 class GrPathRenderer; | 22 class GrPathRenderer; |
| 23 class GrPathRendererChain; | 23 class GrPathRendererChain; |
| 24 class GrTexture; | 24 class GrTexture; |
| 25 class SkPath; | 25 class SkPath; |
| 26 |
| 27 /** |
| 28 * Produced by GrClipMaskManager. It provides a set of modifications to the draw
ing state that |
| 29 * are used to create the final GrPipeline for a GrBatch. This is a work in prog
ress. It will |
| 30 * eventually encapsulate all mechanisms for modifying the scissor, shaders, and
stencil state |
| 31 * to implement clipping. |
| 32 */ |
| 33 class GrAppliedClip : public SkNoncopyable { |
| 34 public: |
| 35 GrAppliedClip() {} |
| 36 const GrFragmentProcessor* clipCoverageFragmentProcessor() const { return fC
lipCoverageFP; } |
| 37 |
| 38 private: |
| 39 SkAutoTUnref<const GrFragmentProcessor> fClipCoverageFP; |
| 40 friend class GrClipMaskManager; |
| 41 |
| 42 typedef SkNoncopyable INHERITED; |
| 43 }; |
| 44 |
| 26 /** | 45 /** |
| 27 * The clip mask creator handles the generation of the clip mask. If anti | 46 * The clip mask creator handles the generation of the clip mask. If anti |
| 28 * aliasing is requested it will (in the future) generate a single channel | 47 * aliasing is requested it will (in the future) generate a single channel |
| 29 * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit | 48 * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit |
| 30 * mask in the stencil buffer. In the non anti-aliasing case, if the clip | 49 * mask in the stencil buffer. In the non anti-aliasing case, if the clip |
| 31 * mask can be represented as a rectangle then scissoring is used. In all | 50 * mask can be represented as a rectangle then scissoring is used. In all |
| 32 * cases scissoring is used to bound the range of the clip mask. | 51 * cases scissoring is used to bound the range of the clip mask. |
| 33 */ | 52 */ |
| 34 class GrClipMaskManager : SkNoncopyable { | 53 class GrClipMaskManager : SkNoncopyable { |
| 35 public: | 54 public: |
| 36 GrClipMaskManager(GrDrawTarget* owner); | 55 GrClipMaskManager(GrDrawTarget* owner); |
| 37 | 56 |
| 38 /** | 57 /** |
| 39 * Creates a clip mask if necessary as a stencil buffer or alpha texture | 58 * Creates a clip mask if necessary as a stencil buffer or alpha texture |
| 40 * and sets the GrGpu's scissor and stencil state. If the return is false | 59 * and sets the GrGpu's scissor and stencil state. If the return is false |
| 41 * then the draw can be skipped. The AutoRestoreEffects is initialized by | 60 * then the draw can be skipped. The AutoRestoreEffects is initialized by |
| 42 * the manager when it must install additional effects to implement the | 61 * the manager when it must install additional effects to implement the |
| 43 * clip. devBounds is optional but can help optimize clipping. | 62 * clip. devBounds is optional but can help optimize clipping. |
| 44 */ | 63 */ |
| 45 bool setupClipping(const GrPipelineBuilder&, | 64 bool setupClipping(const GrPipelineBuilder&, |
| 46 GrPipelineBuilder::AutoRestoreFragmentProcessorState*, | |
| 47 GrPipelineBuilder::AutoRestoreStencil*, | 65 GrPipelineBuilder::AutoRestoreStencil*, |
| 48 GrScissorState*, | 66 GrScissorState*, |
| 49 const SkRect* devBounds); | 67 const SkRect* devBounds, |
| 68 GrAppliedClip*); |
| 50 | 69 |
| 51 bool isClipInStencil() const { | 70 bool isClipInStencil() const { |
| 52 return kStencil_ClipMaskType == fCurrClipMaskType; | 71 return kStencil_ClipMaskType == fCurrClipMaskType; |
| 53 } | 72 } |
| 54 | 73 |
| 55 bool isClipInAlpha() const { | 74 bool isClipInAlpha() const { |
| 56 return kAlpha_ClipMaskType == fCurrClipMaskType; | 75 return kAlpha_ClipMaskType == fCurrClipMaskType; |
| 57 } | 76 } |
| 58 | 77 |
| 59 void adjustPathStencilParams(const GrStencilAttachment*, GrStencilSettings*)
; | 78 void adjustPathStencilParams(const GrStencilAttachment*, GrStencilSettings*)
; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 70 kModifyClip_StencilClipMode, | 89 kModifyClip_StencilClipMode, |
| 71 // Clip against the existing representation of the clip in the high bit | 90 // Clip against the existing representation of the clip in the high bit |
| 72 // of the stencil buffer. | 91 // of the stencil buffer. |
| 73 kRespectClip_StencilClipMode, | 92 kRespectClip_StencilClipMode, |
| 74 // Neither writing to nor clipping against the clip bit. | 93 // Neither writing to nor clipping against the clip bit. |
| 75 kIgnoreClip_StencilClipMode, | 94 kIgnoreClip_StencilClipMode, |
| 76 }; | 95 }; |
| 77 | 96 |
| 78 // Attempts to install a series of coverage effects to implement the clip. R
eturn indicates | 97 // Attempts to install a series of coverage effects to implement the clip. R
eturn indicates |
| 79 // whether the element list was successfully converted to effects. | 98 // whether the element list was successfully converted to effects. |
| 80 bool installClipEffects(const GrPipelineBuilder&, | 99 const GrFragmentProcessor* getAnalyticClipProcessor(const GrReducedClip::Ele
mentList&, |
| 81 GrPipelineBuilder::AutoRestoreFragmentProcessorState
*, | 100 const SkVector& clipOffs
et, |
| 82 const GrReducedClip::ElementList&, | 101 const SkRect* devBounds)
; |
| 83 const SkVector& clipOffset, | |
| 84 const SkRect* devBounds); | |
| 85 | 102 |
| 86 // Draws the clip into the stencil buffer | 103 // Draws the clip into the stencil buffer |
| 87 bool createStencilClipMask(GrRenderTarget*, | 104 bool createStencilClipMask(GrRenderTarget*, |
| 88 int32_t elementsGenID, | 105 int32_t elementsGenID, |
| 89 GrReducedClip::InitialState initialState, | 106 GrReducedClip::InitialState initialState, |
| 90 const GrReducedClip::ElementList& elements, | 107 const GrReducedClip::ElementList& elements, |
| 91 const SkIRect& clipSpaceIBounds, | 108 const SkIRect& clipSpaceIBounds, |
| 92 const SkIPoint& clipSpaceToStencilOffset); | 109 const SkIPoint& clipSpaceToStencilOffset); |
| 93 | 110 |
| 94 // Creates an alpha mask of the clip. The mask is a rasterization of element
s through the | 111 // Creates an alpha mask of the clip. The mask is a rasterization of element
s through the |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 * We may represent the clip as a mask in the stencil buffer or as an alpha | 174 * We may represent the clip as a mask in the stencil buffer or as an alpha |
| 158 * texture. It may be neither because the scissor rect suffices or we | 175 * texture. It may be neither because the scissor rect suffices or we |
| 159 * haven't yet examined the clip. | 176 * haven't yet examined the clip. |
| 160 */ | 177 */ |
| 161 enum ClipMaskType { | 178 enum ClipMaskType { |
| 162 kNone_ClipMaskType, | 179 kNone_ClipMaskType, |
| 163 kStencil_ClipMaskType, | 180 kStencil_ClipMaskType, |
| 164 kAlpha_ClipMaskType, | 181 kAlpha_ClipMaskType, |
| 165 } fCurrClipMaskType; | 182 } fCurrClipMaskType; |
| 166 | 183 |
| 184 static const int kMaxAnalyticElements = 4; |
| 185 |
| 167 GrDrawTarget* fDrawTarget; // This is our owning draw target. | 186 GrDrawTarget* fDrawTarget; // This is our owning draw target. |
| 168 StencilClipMode fClipMode; | 187 StencilClipMode fClipMode; |
| 169 | 188 |
| 170 typedef SkNoncopyable INHERITED; | 189 typedef SkNoncopyable INHERITED; |
| 171 }; | 190 }; |
| 172 #endif // GrClipMaskManager_DEFINED | 191 #endif // GrClipMaskManager_DEFINED |
| OLD | NEW |