| 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 "GrTexture.h" | 13 #include "GrTexture.h" |
| 13 #include "SkClipStack.h" | 14 #include "SkClipStack.h" |
| 14 #include "SkDeque.h" | 15 #include "SkDeque.h" |
| 15 #include "SkPath.h" | 16 #include "SkPath.h" |
| 16 #include "SkRefCnt.h" | 17 #include "SkRefCnt.h" |
| 17 #include "SkTLList.h" | 18 #include "SkTLList.h" |
| 18 #include "SkTypes.h" | 19 #include "SkTypes.h" |
| 19 | 20 |
| 20 class GrDrawTarget; | 21 class GrDrawTarget; |
| 21 class GrPathRenderer; | 22 class GrPathRenderer; |
| 22 class GrPathRendererChain; | 23 class GrPathRendererChain; |
| 23 class GrResourceProvider; | 24 class GrResourceProvider; |
| 24 class GrTexture; | 25 class GrTexture; |
| 25 class SkPath; | 26 class SkPath; |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * Produced by GrClipMaskManager. It provides a set of modifications to the draw
ing state that | 29 * 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 * 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 * eventually encapsulate all mechanisms for modifying the scissor, shaders, and
stencil state |
| 31 * to implement clipping. | 32 * to implement clipping. |
| 32 */ | 33 */ |
| 33 class GrAppliedClip : public SkNoncopyable { | 34 class GrAppliedClip : public SkNoncopyable { |
| 34 public: | 35 public: |
| 35 GrAppliedClip() : fHasStencilClip(false) {} | 36 GrAppliedClip() {} |
| 36 const GrFragmentProcessor* clipCoverageFragmentProcessor() const { return fC
lipCoverageFP; } | 37 const GrFragmentProcessor* clipCoverageFragmentProcessor() const { return fC
lipCoverageFP; } |
| 37 const GrScissorState& scissorState() const { return fScissorState; } | 38 const GrScissorState& scissorState() const { return fScissorState; } |
| 38 bool hasStencilClip() const { return fHasStencilClip; } | |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 SkAutoTUnref<const GrFragmentProcessor> fClipCoverageFP; | 41 SkAutoTUnref<const GrFragmentProcessor> fClipCoverageFP; |
| 42 GrScissorState fScissorState; | 42 GrScissorState fScissorState; |
| 43 bool fHasStencilClip; | |
| 44 friend class GrClipMaskManager; | 43 friend class GrClipMaskManager; |
| 45 | 44 |
| 46 typedef SkNoncopyable INHERITED; | 45 typedef SkNoncopyable INHERITED; |
| 47 }; | 46 }; |
| 48 | 47 |
| 49 /** | 48 /** |
| 50 * The clip mask creator handles the generation of the clip mask. If anti | 49 * The clip mask creator handles the generation of the clip mask. If anti |
| 51 * aliasing is requested it will (in the future) generate a single channel | 50 * aliasing is requested it will (in the future) generate a single channel |
| 52 * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit | 51 * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit |
| 53 * mask in the stencil buffer. In the non anti-aliasing case, if the clip | 52 * mask in the stencil buffer. In the non anti-aliasing case, if the clip |
| 54 * mask can be represented as a rectangle then scissoring is used. In all | 53 * mask can be represented as a rectangle then scissoring is used. In all |
| 55 * cases scissoring is used to bound the range of the clip mask. | 54 * cases scissoring is used to bound the range of the clip mask. |
| 56 */ | 55 */ |
| 57 class GrClipMaskManager : SkNoncopyable { | 56 class GrClipMaskManager : SkNoncopyable { |
| 58 public: | 57 public: |
| 59 GrClipMaskManager(GrDrawTarget* owner, bool debugClipBatchToBounds); | 58 GrClipMaskManager(GrDrawTarget* owner, bool debugClipBatchToBounds); |
| 60 | 59 |
| 61 /** | 60 /** |
| 62 * Creates a clip mask if necessary as a stencil buffer or alpha texture | 61 * Creates a clip mask if necessary as a stencil buffer or alpha texture |
| 63 * and sets the GrGpu's scissor and stencil state. If the return is false | 62 * and sets the GrGpu's scissor and stencil state. If the return is false |
| 64 * then the draw can be skipped. devBounds is optional but can help optimize | 63 * then the draw can be skipped. The AutoRestoreEffects is initialized by |
| 65 * clipping. | 64 * the manager when it must install additional effects to implement the |
| 65 * clip. devBounds is optional but can help optimize clipping. |
| 66 */ | 66 */ |
| 67 bool setupClipping(const GrPipelineBuilder&, const SkRect* devBounds, GrAppl
iedClip*); | 67 bool setupClipping(const GrPipelineBuilder&, |
| 68 GrPipelineBuilder::AutoRestoreStencil*, |
| 69 const SkRect* devBounds, |
| 70 GrAppliedClip*); |
| 68 | 71 |
| 69 bool setupScissorClip(const GrPipelineBuilder& pipelineBuilder, | 72 bool setupScissorClip(const GrPipelineBuilder& pipelineBuilder, |
| 73 GrPipelineBuilder::AutoRestoreStencil* ars, |
| 70 const SkIRect& scissor, | 74 const SkIRect& scissor, |
| 71 const SkRect* devBounds, | 75 const SkRect* devBounds, |
| 72 GrAppliedClip* out); | 76 GrAppliedClip* out); |
| 73 | 77 |
| 78 void adjustPathStencilParams(const GrStencilAttachment*, GrStencilSettings*)
; |
| 79 |
| 74 private: | 80 private: |
| 75 inline GrContext* getContext(); | 81 inline GrContext* getContext(); |
| 76 inline const GrCaps* caps() const; | 82 inline const GrCaps* caps() const; |
| 77 inline GrResourceProvider* resourceProvider(); | 83 inline GrResourceProvider* resourceProvider(); |
| 78 | 84 |
| 79 static bool PathNeedsSWRenderer(GrContext* context, | 85 static bool PathNeedsSWRenderer(GrContext* context, |
| 80 bool hasUserStencilSettings, | 86 bool isStencilDisabled, |
| 81 const GrRenderTarget* rt, | 87 const GrRenderTarget* rt, |
| 82 const SkMatrix& viewMatrix, | 88 const SkMatrix& viewMatrix, |
| 83 const SkClipStack::Element* element, | 89 const SkClipStack::Element* element, |
| 84 GrPathRenderer** prOut, | 90 GrPathRenderer** prOut, |
| 85 bool needsStencil); | 91 bool needsStencil); |
| 86 static GrPathRenderer* GetPathRenderer(GrContext* context, | 92 static GrPathRenderer* GetPathRenderer(GrContext* context, |
| 87 GrTexture* texture, | 93 GrTexture* texture, |
| 88 const SkMatrix& viewMatrix, | 94 const SkMatrix& viewMatrix, |
| 89 const SkClipStack::Element* element); | 95 const SkClipStack::Element* element); |
| 90 | 96 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 const GrReducedClip::ElementList& e
lements, | 143 const GrReducedClip::ElementList& e
lements, |
| 138 const SkVector& clipToMaskOffset, | 144 const SkVector& clipToMaskOffset, |
| 139 const SkIRect& clipSpaceIBounds); | 145 const SkIRect& clipSpaceIBounds); |
| 140 | 146 |
| 141 static bool UseSWOnlyPath(GrContext*, | 147 static bool UseSWOnlyPath(GrContext*, |
| 142 const GrPipelineBuilder&, | 148 const GrPipelineBuilder&, |
| 143 const GrRenderTarget* rt, | 149 const GrRenderTarget* rt, |
| 144 const SkVector& clipToMaskOffset, | 150 const SkVector& clipToMaskOffset, |
| 145 const GrReducedClip::ElementList& elements); | 151 const GrReducedClip::ElementList& elements); |
| 146 | 152 |
| 153 /** |
| 154 * Called prior to return control back the GrGpu in setupClipping. It update
s the |
| 155 * GrPipelineBuilder with stencil settings that account for stencil-based cl
ipping. |
| 156 */ |
| 157 void setPipelineBuilderStencil(const GrPipelineBuilder&, |
| 158 GrPipelineBuilder::AutoRestoreStencil*); |
| 159 |
| 160 /** |
| 161 * Adjusts the stencil settings to account for interaction with stencil |
| 162 * clipping. |
| 163 */ |
| 164 void adjustStencilParams(GrStencilSettings* settings, |
| 165 StencilClipMode mode, |
| 166 int stencilBitCnt); |
| 167 |
| 147 GrTexture* createCachedMask(int width, int height, const GrUniqueKey& key, b
ool renderTarget); | 168 GrTexture* createCachedMask(int width, int height, const GrUniqueKey& key, b
ool renderTarget); |
| 148 | 169 |
| 149 static const int kMaxAnalyticElements = 4; | 170 static const int kMaxAnalyticElements = 4; |
| 150 | 171 |
| 151 GrDrawTarget* fDrawTarget; // This is our owning draw target. | 172 GrDrawTarget* fDrawTarget; // This is our owning draw target. |
| 152 StencilClipMode fClipMode; | 173 StencilClipMode fClipMode; |
| 153 bool fDebugClipBatchToBounds; | 174 bool fDebugClipBatchToBounds; |
| 154 | 175 |
| 155 typedef SkNoncopyable INHERITED; | 176 typedef SkNoncopyable INHERITED; |
| 156 }; | 177 }; |
| 157 #endif // GrClipMaskManager_DEFINED | 178 #endif // GrClipMaskManager_DEFINED |
| OLD | NEW |