| 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 "GrTexture.h" | 12 #include "GrTexture.h" |
| 13 #include "SkClipStack.h" | 13 #include "SkClipStack.h" |
| 14 #include "SkDeque.h" | 14 #include "SkDeque.h" |
| 15 #include "SkPath.h" | 15 #include "SkPath.h" |
| 16 #include "SkRefCnt.h" | 16 #include "SkRefCnt.h" |
| 17 #include "SkTLList.h" | 17 #include "SkTLList.h" |
| 18 #include "SkTypes.h" | 18 #include "SkTypes.h" |
| 19 | 19 |
| 20 class GrClip; | 20 class GrAppliedClip; |
| 21 class GrClipStackClip; |
| 21 class GrDrawTarget; | 22 class GrDrawTarget; |
| 22 class GrPathRenderer; | 23 class GrPathRenderer; |
| 23 class GrPathRendererChain; | 24 class GrPathRendererChain; |
| 24 class GrResourceProvider; | 25 class GrResourceProvider; |
| 25 class GrTexture; | 26 class GrTexture; |
| 26 class SkPath; | 27 class SkPath; |
| 27 | 28 |
| 28 /** | 29 /** |
| 29 * Produced by GrClipMaskManager. It provides a set of modifications to the draw
ing state that | |
| 30 * are used to create the final GrPipeline for a GrBatch. This is a work in prog
ress. It will | |
| 31 * eventually encapsulate all mechanisms for modifying the scissor, shaders, and
stencil state | |
| 32 * to implement clipping. | |
| 33 */ | |
| 34 class GrAppliedClip : public SkNoncopyable { | |
| 35 public: | |
| 36 GrAppliedClip() : fHasStencilClip(false) {} | |
| 37 const GrFragmentProcessor* clipCoverageFragmentProcessor() const { return fC
lipCoverageFP; } | |
| 38 const GrScissorState& scissorState() const { return fScissorState; } | |
| 39 bool hasStencilClip() const { return fHasStencilClip; } | |
| 40 | |
| 41 private: | |
| 42 SkAutoTUnref<const GrFragmentProcessor> fClipCoverageFP; | |
| 43 GrScissorState fScissorState; | |
| 44 bool fHasStencilClip; | |
| 45 friend class GrClipMaskManager; | |
| 46 | |
| 47 typedef SkNoncopyable INHERITED; | |
| 48 }; | |
| 49 | |
| 50 /** | |
| 51 * The clip mask creator handles the generation of the clip mask. If anti | 30 * The clip mask creator handles the generation of the clip mask. If anti |
| 52 * aliasing is requested it will (in the future) generate a single channel | 31 * aliasing is requested it will (in the future) generate a single channel |
| 53 * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit | 32 * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit |
| 54 * mask in the stencil buffer. In the non anti-aliasing case, if the clip | 33 * mask in the stencil buffer. In the non anti-aliasing case, if the clip |
| 55 * mask can be represented as a rectangle then scissoring is used. In all | 34 * mask can be represented as a rectangle then scissoring is used. In all |
| 56 * cases scissoring is used to bound the range of the clip mask. | 35 * cases scissoring is used to bound the range of the clip mask. |
| 57 */ | 36 */ |
| 58 class GrClipMaskManager : SkNoncopyable { | 37 class GrClipMaskManager : SkNoncopyable { |
| 59 public: | 38 public: |
| 60 GrClipMaskManager(GrDrawTarget* owner); | 39 GrClipMaskManager(GrDrawTarget* owner) : fDrawTarget(owner) {} |
| 61 | 40 |
| 62 /** | 41 /** |
| 63 * Creates a clip mask if necessary as a stencil buffer or alpha texture | 42 * Creates a clip mask if necessary as a stencil buffer or alpha texture |
| 64 * and sets the GrGpu's scissor and stencil state. If the return is false | 43 * and sets the GrGpu's scissor and stencil state. If the return is false |
| 65 * then the draw can be skipped. devBounds is optional but can help optimize | 44 * then the draw can be skipped. devBounds is optional but can help optimize |
| 66 * clipping. | 45 * clipping. |
| 67 */ | 46 */ |
| 68 bool setupClipping(const GrPipelineBuilder&, const GrClip&, const SkRect* de
vBounds, | 47 bool setupClipping(const GrPipelineBuilder&, const GrClipStackClip&, const S
kRect* devBounds, |
| 69 GrAppliedClip*); | 48 GrAppliedClip*); |
| 70 | 49 |
| 71 private: | 50 private: |
| 72 inline GrContext* getContext(); | 51 inline GrContext* getContext(); |
| 73 inline const GrCaps* caps() const; | 52 inline const GrCaps* caps() const; |
| 74 inline GrResourceProvider* resourceProvider(); | 53 inline GrResourceProvider* resourceProvider(); |
| 75 | 54 |
| 76 static bool PathNeedsSWRenderer(GrContext* context, | 55 static bool PathNeedsSWRenderer(GrContext* context, |
| 77 bool hasUserStencilSettings, | 56 bool hasUserStencilSettings, |
| 78 const GrRenderTarget* rt, | 57 const GrRenderTarget* rt, |
| 79 const SkMatrix& viewMatrix, | 58 const SkMatrix& viewMatrix, |
| 80 const SkClipStack::Element* element, | 59 const SkClipStack::Element* element, |
| 81 GrPathRenderer** prOut, | 60 GrPathRenderer** prOut, |
| 82 bool needsStencil); | 61 bool needsStencil); |
| 83 static GrPathRenderer* GetPathRenderer(GrContext* context, | 62 static GrPathRenderer* GetPathRenderer(GrContext* context, |
| 84 GrTexture* texture, | 63 GrTexture* texture, |
| 85 const SkMatrix& viewMatrix, | 64 const SkMatrix& viewMatrix, |
| 86 const SkClipStack::Element* element); | 65 const SkClipStack::Element* element); |
| 87 | 66 |
| 88 /** | |
| 89 * Informs the helper function adjustStencilParams() about how the stencil | |
| 90 * buffer clip is being used. | |
| 91 */ | |
| 92 enum StencilClipMode { | |
| 93 // Draw to the clip bit of the stencil buffer | |
| 94 kModifyClip_StencilClipMode, | |
| 95 // Clip against the existing representation of the clip in the high bit | |
| 96 // of the stencil buffer. | |
| 97 kRespectClip_StencilClipMode, | |
| 98 // Neither writing to nor clipping against the clip bit. | |
| 99 kIgnoreClip_StencilClipMode, | |
| 100 }; | |
| 101 | |
| 102 // Attempts to install a series of coverage effects to implement the clip. R
eturn indicates | 67 // Attempts to install a series of coverage effects to implement the clip. R
eturn indicates |
| 103 // whether the element list was successfully converted to processors. *fp ma
y be nullptr even | 68 // whether the element list was successfully converted to processors. *fp ma
y be nullptr even |
| 104 // when the function succeeds because all the elements were ignored. TODO: M
ake clip reduction | 69 // when the function succeeds because all the elements were ignored. TODO: M
ake clip reduction |
| 105 // bounds-aware and stop checking bounds in this function. Similarly, we sho
uldn't need to pass | 70 // bounds-aware and stop checking bounds in this function. Similarly, we sho
uldn't need to pass |
| 106 // abortIfAA, but we don't yet know if all the AA elements will be eliminate
d. | 71 // abortIfAA, but we don't yet know if all the AA elements will be eliminate
d. |
| 107 bool getAnalyticClipProcessor(const GrReducedClip::ElementList&, | 72 bool getAnalyticClipProcessor(const GrReducedClip::ElementList&, |
| 108 bool abortIfAA, | 73 bool abortIfAA, |
| 109 SkVector& clipOffset, | 74 SkVector& clipOffset, |
| 110 const SkRect* devBounds, | 75 const SkRect* devBounds, |
| 111 const GrFragmentProcessor** fp); | 76 const GrFragmentProcessor** fp); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 139 const GrPipelineBuilder&, | 104 const GrPipelineBuilder&, |
| 140 const GrRenderTarget* rt, | 105 const GrRenderTarget* rt, |
| 141 const SkVector& clipToMaskOffset, | 106 const SkVector& clipToMaskOffset, |
| 142 const GrReducedClip::ElementList& elements); | 107 const GrReducedClip::ElementList& elements); |
| 143 | 108 |
| 144 GrTexture* createCachedMask(int width, int height, const GrUniqueKey& key, b
ool renderTarget); | 109 GrTexture* createCachedMask(int width, int height, const GrUniqueKey& key, b
ool renderTarget); |
| 145 | 110 |
| 146 static const int kMaxAnalyticElements = 4; | 111 static const int kMaxAnalyticElements = 4; |
| 147 | 112 |
| 148 GrDrawTarget* fDrawTarget; // This is our owning draw target. | 113 GrDrawTarget* fDrawTarget; // This is our owning draw target. |
| 149 StencilClipMode fClipMode; | |
| 150 | 114 |
| 151 typedef SkNoncopyable INHERITED; | 115 typedef SkNoncopyable INHERITED; |
| 152 }; | 116 }; |
| 153 #endif // GrClipMaskManager_DEFINED | 117 #endif // GrClipMaskManager_DEFINED |
| OLD | NEW |