| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 | 7 |
| 8 #ifndef GrClip_DEFINED | 8 #ifndef GrClip_DEFINED |
| 9 #define GrClip_DEFINED | 9 #define GrClip_DEFINED |
| 10 | 10 |
| 11 #include "GrTypes.h" |
| 11 #include "GrFragmentProcessor.h" | 12 #include "GrFragmentProcessor.h" |
| 12 #include "GrTypesPriv.h" | |
| 13 #include "SkClipStack.h" | |
| 14 | 13 |
| 15 class GrDrawContext; | |
| 16 class GrPipelineBuilder; | 14 class GrPipelineBuilder; |
| 17 | 15 |
| 18 /** | 16 /** |
| 19 * Produced by GrClip. It provides a set of modifications to the drawing state t
hat are used to | 17 * Produced by GrClip. It provides a set of modifications to the drawing state t
hat are used to |
| 20 * create the final GrPipeline for a GrBatch. | 18 * create the final GrPipeline for a GrBatch. |
| 21 */ | 19 */ |
| 22 class GrAppliedClip : public SkNoncopyable { | 20 class GrAppliedClip : public SkNoncopyable { |
| 23 public: | 21 public: |
| 24 GrAppliedClip() : fHasStencilClip(false), fDeviceBounds(SkRect::MakeLargest(
)) {} | 22 GrAppliedClip() : fHasStencilClip(false), fDeviceBounds(SkRect::MakeLargest(
)) {} |
| 25 GrFragmentProcessor* getClipCoverageFragmentProcessor() const { | 23 GrFragmentProcessor* getClipCoverageFragmentProcessor() const { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 */ | 100 */ |
| 103 class GrClip { | 101 class GrClip { |
| 104 public: | 102 public: |
| 105 virtual bool quickContains(const SkRect&) const = 0; | 103 virtual bool quickContains(const SkRect&) const = 0; |
| 106 virtual void getConservativeBounds(int width, int height, SkIRect* devResult
, | 104 virtual void getConservativeBounds(int width, int height, SkIRect* devResult
, |
| 107 bool* isIntersectionOfRects = nullptr) co
nst = 0; | 105 bool* isIntersectionOfRects = nullptr) co
nst = 0; |
| 108 virtual bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, | 106 virtual bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, |
| 109 const SkRect* devBounds, GrAppliedClip*) const = 0; | 107 const SkRect* devBounds, GrAppliedClip*) const = 0; |
| 110 | 108 |
| 111 virtual ~GrClip() {} | 109 virtual ~GrClip() {} |
| 110 |
| 111 bool isWideOpen() const { return fIsWideOpen; } |
| 112 |
| 113 protected: |
| 114 GrClip(bool isWideOpen) : fIsWideOpen(isWideOpen) {} |
| 115 bool fIsWideOpen; |
| 112 }; | 116 }; |
| 113 | 117 |
| 114 /** | 118 /** |
| 115 * Specialized implementation for no clip. | 119 * Specialized implementation for no clip. |
| 116 */ | 120 */ |
| 117 class GrNoClip final : public GrClip { | 121 class GrNoClip final : public GrClip { |
| 122 public: |
| 123 GrNoClip() : INHERITED(true) {} |
| 118 private: | 124 private: |
| 119 bool quickContains(const SkRect&) const final { return true; } | 125 bool quickContains(const SkRect&) const final { return true; } |
| 120 void getConservativeBounds(int width, int height, SkIRect* devResult, | 126 void getConservativeBounds(int width, int height, SkIRect* devResult, |
| 121 bool* isIntersectionOfRects) const final; | 127 bool* isIntersectionOfRects) const final; |
| 122 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, | 128 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, |
| 123 const SkRect*, GrAppliedClip*) const final { return true; } | 129 const SkRect*, GrAppliedClip*) const final { return true; } |
| 130 typedef GrClip INHERITED; |
| 124 }; | 131 }; |
| 125 | 132 |
| 126 /** | 133 /** |
| 127 * GrFixedClip is a clip that can be represented by fixed-function hardware. It
never modifies the | 134 * GrFixedClip is a clip that can be represented by fixed-function hardware. It
never modifies the |
| 128 * stencil buffer itself, but can be configured to use whatever clip is already
there. | 135 * stencil buffer itself, but can be configured to use whatever clip is already
there. |
| 129 */ | 136 */ |
| 130 class GrFixedClip final : public GrClip { | 137 class GrFixedClip final : public GrClip { |
| 131 public: | 138 public: |
| 132 GrFixedClip() : fDeviceBounds(SkRect::MakeLargest()), fHasStencilClip(false)
{} | 139 GrFixedClip() : INHERITED(true) { |
| 133 GrFixedClip(const SkIRect& scissorRect) | 140 fDeviceBounds = SkRect::MakeLargest(); |
| 134 : fScissorState(scissorRect) | 141 fHasStencilClip = false; |
| 135 , fDeviceBounds(SkRect::Make(scissorRect)) | 142 } |
| 136 , fHasStencilClip(false) {} | 143 GrFixedClip(const SkIRect& scissorRect) : INHERITED(false) { |
| 144 fScissorState = scissorRect; |
| 145 fDeviceBounds = SkRect::Make(scissorRect); |
| 146 fHasStencilClip = false; |
| 147 } |
| 137 | 148 |
| 138 void reset() { | 149 void reset() { |
| 150 fIsWideOpen = true; |
| 139 fScissorState.setDisabled(); | 151 fScissorState.setDisabled(); |
| 140 fDeviceBounds.setLargest(); | 152 fDeviceBounds.setLargest(); |
| 141 fHasStencilClip = false; | 153 fHasStencilClip = false; |
| 142 } | 154 } |
| 143 | 155 |
| 144 void reset(const SkIRect& scissorRect) { | 156 void reset(const SkIRect& scissorRect) { |
| 157 fIsWideOpen = false; |
| 145 fScissorState.set(scissorRect); | 158 fScissorState.set(scissorRect); |
| 146 fDeviceBounds = SkRect::Make(scissorRect); | 159 fDeviceBounds = SkRect::Make(scissorRect); |
| 147 fHasStencilClip = false; | 160 fHasStencilClip = false; |
| 148 } | 161 } |
| 149 | 162 |
| 150 /** | 163 /** |
| 151 * Enables stenciling. The stencil bounds is the device space bounds where t
he stencil test | 164 * Enables stenciling. The stencil bounds is the device space bounds where t
he stencil test |
| 152 * may pass. | 165 * may pass. |
| 153 */ | 166 */ |
| 154 void enableStencilClip(const SkRect& stencilBounds) { | 167 void enableStencilClip(const SkRect& stencilBounds) { |
| 168 fIsWideOpen = false; |
| 155 fHasStencilClip = true; | 169 fHasStencilClip = true; |
| 156 fDeviceBounds = stencilBounds; | 170 fDeviceBounds = stencilBounds; |
| 157 if (fScissorState.enabled()) { | 171 if (fScissorState.enabled()) { |
| 158 const SkIRect& s = fScissorState.rect(); | 172 const SkIRect& s = fScissorState.rect(); |
| 159 fDeviceBounds.fLeft = SkTMax(fDeviceBounds.fLeft, SkIntToScalar(
s.fLeft)); | 173 fDeviceBounds.fLeft = SkTMax(fDeviceBounds.fLeft, SkIntToScalar(
s.fLeft)); |
| 160 fDeviceBounds.fTop = SkTMax(fDeviceBounds.fTop, SkIntToScalar(
s.fTop)); | 174 fDeviceBounds.fTop = SkTMax(fDeviceBounds.fTop, SkIntToScalar(
s.fTop)); |
| 161 fDeviceBounds.fRight = SkTMin(fDeviceBounds.fRight, SkIntToScalar(
s.fRight)); | 175 fDeviceBounds.fRight = SkTMin(fDeviceBounds.fRight, SkIntToScalar(
s.fRight)); |
| 162 fDeviceBounds.fBottom = SkTMin(fDeviceBounds.fBottom, SkIntToScalar(
s.fBottom)); | 176 fDeviceBounds.fBottom = SkTMin(fDeviceBounds.fBottom, SkIntToScalar(
s.fBottom)); |
| 163 } | 177 } |
| 164 } | 178 } |
| 165 | 179 |
| 166 void disableStencilClip() { | 180 void disableStencilClip() { |
| 167 fHasStencilClip = false; | 181 fHasStencilClip = false; |
| 168 if (fScissorState.enabled()) { | 182 if (fScissorState.enabled()) { |
| 183 fIsWideOpen = false; |
| 169 fDeviceBounds = SkRect::Make(fScissorState.rect()); | 184 fDeviceBounds = SkRect::Make(fScissorState.rect()); |
| 170 } else { | 185 } else { |
| 186 fIsWideOpen = true; |
| 171 fDeviceBounds.setLargest(); | 187 fDeviceBounds.setLargest(); |
| 172 } | 188 } |
| 173 } | 189 } |
| 174 | 190 |
| 175 const GrScissorState& scissorState() const { return fScissorState; } | 191 const GrScissorState& scissorState() const { return fScissorState; } |
| 176 bool hasStencilClip() const { return fHasStencilClip; } | 192 bool hasStencilClip() const { return fHasStencilClip; } |
| 177 | 193 |
| 178 bool quickContains(const SkRect&) const final; | 194 bool quickContains(const SkRect&) const final; |
| 179 void getConservativeBounds(int width, int height, SkIRect* devResult, | 195 void getConservativeBounds(int width, int height, SkIRect* devResult, |
| 180 bool* isIntersectionOfRects) const final; | 196 bool* isIntersectionOfRects) const final; |
| 181 | 197 |
| 182 private: | 198 private: |
| 183 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, | 199 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, |
| 184 const SkRect* devBounds, GrAppliedClip* out) const final; | 200 const SkRect* devBounds, GrAppliedClip* out) const final; |
| 185 | 201 |
| 186 GrScissorState fScissorState; | 202 GrScissorState fScissorState; |
| 187 SkRect fDeviceBounds; | 203 SkRect fDeviceBounds; |
| 188 bool fHasStencilClip; | 204 bool fHasStencilClip; |
| 189 }; | 205 typedef GrClip INHERITED; |
| 190 | |
| 191 /** | |
| 192 * GrClipStackClip can apply a generic SkClipStack to the draw state. It may gen
erate clip masks or | |
| 193 * write to the stencil buffer during apply(). | |
| 194 */ | |
| 195 class GrClipStackClip final : public GrClip { | |
| 196 public: | |
| 197 GrClipStackClip(const SkClipStack* stack = nullptr, const SkIPoint* origin =
nullptr) { | |
| 198 this->reset(stack, origin); | |
| 199 } | |
| 200 | |
| 201 void reset(const SkClipStack* stack = nullptr, const SkIPoint* origin = null
ptr) { | |
| 202 fOrigin = origin ? *origin : SkIPoint::Make(0, 0); | |
| 203 fStack.reset(SkSafeRef(stack)); | |
| 204 } | |
| 205 | |
| 206 const SkIPoint& origin() const { return fOrigin; } | |
| 207 const SkClipStack* clipStack() const { return fStack; } | |
| 208 | |
| 209 bool quickContains(const SkRect&) const final; | |
| 210 void getConservativeBounds(int width, int height, SkIRect* devResult, | |
| 211 bool* isIntersectionOfRects) const final; | |
| 212 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, | |
| 213 const SkRect* devBounds, GrAppliedClip*) const final; | |
| 214 | |
| 215 private: | |
| 216 SkIPoint fOrigin; | |
| 217 SkAutoTUnref<const SkClipStack> fStack; | |
| 218 }; | 206 }; |
| 219 | 207 |
| 220 #endif | 208 #endif |
| OLD | NEW |