 Chromium Code Reviews
 Chromium Code Reviews Issue 2137543002:
  Use clipped bounds for reordering decisions  (Closed) 
  Base URL: https://chromium.googlesource.com/skia.git@lessstencil
    
  
    Issue 2137543002:
  Use clipped bounds for reordering decisions  (Closed) 
  Base URL: https://chromium.googlesource.com/skia.git@lessstencil| 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 "GrFragmentProcessor.h" | 11 #include "GrFragmentProcessor.h" | 
| 12 #include "GrTypesPriv.h" | 12 #include "GrTypesPriv.h" | 
| 13 #include "SkClipStack.h" | 13 #include "SkClipStack.h" | 
| 14 | 14 | 
| 15 class GrDrawContext; | 15 class GrDrawContext; | 
| 16 class GrPipelineBuilder; | 16 class GrPipelineBuilder; | 
| 17 | 17 | 
| 18 /** | 18 /** | 
| 19 * Produced by GrClip. It provides a set of modifications to the drawing state t hat are used to | 19 * 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. | 20 * create the final GrPipeline for a GrBatch. | 
| 21 */ | 21 */ | 
| 22 class GrAppliedClip : public SkNoncopyable { | 22 class GrAppliedClip : public SkNoncopyable { | 
| 23 public: | 23 public: | 
| 24 GrAppliedClip() : fHasStencilClip(false) {} | 24 GrAppliedClip() : fHasStencilClip(false), fDeviceBounds(SkRect::MakeLargest( )) {} | 
| 25 GrFragmentProcessor* getClipCoverageFragmentProcessor() const { | 25 GrFragmentProcessor* getClipCoverageFragmentProcessor() const { | 
| 26 return fClipCoverageFP.get(); | 26 return fClipCoverageFP.get(); | 
| 27 } | 27 } | 
| 28 const GrScissorState& scissorState() const { return fScissorState; } | 28 const GrScissorState& scissorState() const { return fScissorState; } | 
| 29 bool hasStencilClip() const { return fHasStencilClip; } | 29 bool hasStencilClip() const { return fHasStencilClip; } | 
| 30 | 30 | 
| 31 void makeStencil(bool hasStencil) { | 31 void makeStencil(bool hasStencil, const SkRect& deviceBounds) { | 
| 32 fClipCoverageFP = nullptr; | 32 fClipCoverageFP = nullptr; | 
| 33 fScissorState.setDisabled(); | 33 fScissorState.setDisabled(); | 
| 34 fHasStencilClip = hasStencil; | 34 fHasStencilClip = hasStencil; | 
| 35 fDeviceBounds = deviceBounds; | |
| 35 } | 36 } | 
| 36 | 37 | 
| 37 void makeScissoredStencil(bool hasStencil, const SkIRect& scissor) { | 38 /** | 
| 39 * The device bounds of the clip defaults to the scissor rect, but a tighter bounds (based | |
| 40 * on the known effect of the stencil values) can be provided. | |
| 41 */ | |
| 42 void makeScissoredStencil(const SkIRect& scissor, const SkRect* deviceBounds = nullptr) { | |
| 38 fClipCoverageFP = nullptr; | 43 fClipCoverageFP = nullptr; | 
| 39 fScissorState.set(scissor); | 44 fScissorState.set(scissor); | 
| 40 fHasStencilClip = hasStencil; | 45 fHasStencilClip = true; | 
| 46 if (deviceBounds) { | |
| 47 fDeviceBounds = *deviceBounds; | |
| 48 SkASSERT(scissor.contains(*deviceBounds)) | |
| 49 } else { | |
| 50 fDeviceBounds = SkRect::Make(scissor); | |
| 51 } | |
| 41 } | 52 } | 
| 42 | 53 | 
| 43 void makeFPBased(sk_sp<GrFragmentProcessor> fp) { | 54 void makeFPBased(sk_sp<GrFragmentProcessor> fp, const SkRect& deviceBounds) { | 
| 44 fClipCoverageFP = fp; | 55 fClipCoverageFP = fp; | 
| 45 fScissorState.setDisabled(); | 56 fScissorState.setDisabled(); | 
| 46 fHasStencilClip = false; | 57 fHasStencilClip = false; | 
| 58 fDeviceBounds = deviceBounds; | |
| 47 } | 59 } | 
| 48 | 60 | 
| 49 void makeScissored(SkIRect& scissor) { | 61 void makeScissored(SkIRect& scissor) { | 
| 50 fClipCoverageFP.reset(); | 62 fClipCoverageFP.reset(); | 
| 51 fScissorState.set(scissor); | 63 fScissorState.set(scissor); | 
| 52 fHasStencilClip = false; | 64 fHasStencilClip = false; | 
| 65 fDeviceBounds = SkRect::Make(scissor); | |
| 53 } | 66 } | 
| 54 | 67 | 
| 55 void makeScissoredFPBased(sk_sp<GrFragmentProcessor> fp, SkIRect& scissor) { | 68 /** | 
| 69 * The device bounds of the clip defaults to the scissor rect, but a tighter bounds (based | |
| 70 * on the known effect of the fragment processor) can be provided. | |
| 71 */ | |
| 72 void makeScissoredFPBased(sk_sp<GrFragmentProcessor> fp, const SkIRect& scis sor, | |
| 73 const SkRect* deviceBounds = nullptr) { | |
| 56 fClipCoverageFP = fp; | 74 fClipCoverageFP = fp; | 
| 57 fScissorState.set(scissor); | 75 fScissorState.set(scissor); | 
| 58 fHasStencilClip = false; | 76 fHasStencilClip = false; | 
| 77 if (deviceBounds) { | |
| 78 fDeviceBounds = *deviceBounds; | |
| 79 SkASSERT(scissor.contains(*deviceBounds)) | |
| 80 } else { | |
| 81 fDeviceBounds = SkRect::Make(scissor); | |
| 82 } | |
| 59 } | 83 } | 
| 60 | 84 | 
| 85 /** | |
| 86 * Returns the device bounds of the applied clip. Ideally this considers the combined effect of | |
| 87 * all clipping techniques in play (scissor, stencil, and/or coverage fp). | |
| 88 */ | |
| 
robertphillips
2016/07/08 15:46:14
SkASSERT(!fDeviceBounds.isLargest());
?
 
bsalomon
2016/07/08 17:06:43
It can be largest if the clip can be ignored. GrCM
 | |
| 89 const SkRect& deviceBounds() const { return fDeviceBounds; } | |
| 90 | |
| 61 private: | 91 private: | 
| 62 sk_sp<GrFragmentProcessor> fClipCoverageFP; | 92 sk_sp<GrFragmentProcessor> fClipCoverageFP; | 
| 63 GrScissorState fScissorState; | 93 GrScissorState fScissorState; | 
| 64 bool fHasStencilClip; | 94 bool fHasStencilClip; | 
| 65 | 95 SkRect fDeviceBounds; | 
| 66 typedef SkNoncopyable INHERITED; | 96 typedef SkNoncopyable INHERITED; | 
| 67 }; | 97 }; | 
| 68 | 98 | 
| 69 /** | 99 /** | 
| 70 * GrClip is an abstract base class for applying a clip. It constructs a clip ma sk if necessary, and | 100 * GrClip is an abstract base class for applying a clip. It constructs a clip ma sk if necessary, and | 
| 71 * fills out a GrAppliedClip instructing the caller on how to set up the draw st ate. | 101 * fills out a GrAppliedClip instructing the caller on how to set up the draw st ate. | 
| 72 */ | 102 */ | 
| 73 class GrClip { | 103 class GrClip { | 
| 74 public: | 104 public: | 
| 75 virtual bool quickContains(const SkRect&) const = 0; | 105 virtual bool quickContains(const SkRect&) const = 0; | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 93 const SkRect*, GrAppliedClip*) const final { return true; } | 123 const SkRect*, GrAppliedClip*) const final { return true; } | 
| 94 }; | 124 }; | 
| 95 | 125 | 
| 96 /** | 126 /** | 
| 97 * GrFixedClip is a clip that can be represented by fixed-function hardware. It never modifies the | 127 * GrFixedClip is a clip that can be represented by fixed-function hardware. It never modifies the | 
| 98 * stencil buffer itself, but can be configured to use whatever clip is already there. | 128 * stencil buffer itself, but can be configured to use whatever clip is already there. | 
| 99 */ | 129 */ | 
| 100 class GrFixedClip final : public GrClip { | 130 class GrFixedClip final : public GrClip { | 
| 101 public: | 131 public: | 
| 102 GrFixedClip() : fHasStencilClip(false) {} | 132 GrFixedClip() : fHasStencilClip(false) {} | 
| 103 GrFixedClip(const SkIRect& scissorRect) : fScissorState(scissorRect), fHasSt encilClip(false) {} | 133 GrFixedClip(const SkIRect& scissorRect) | 
| 134 : fScissorState(scissorRect) | |
| 135 , fDeviceBounds(SkRect::Make(scissorRect)) | |
| 136 , fHasStencilClip(false) {} | |
| 104 | 137 | 
| 105 void reset() { | 138 void reset() { | 
| 106 fScissorState.setDisabled(); | 139 fScissorState.setDisabled(); | 
| 140 fDeviceBounds.setLargest(); | |
| 107 fHasStencilClip = false; | 141 fHasStencilClip = false; | 
| 108 } | 142 } | 
| 109 | 143 | 
| 110 void reset(const SkIRect& scissorRect) { | 144 void reset(const SkIRect& scissorRect) { | 
| 111 fScissorState.set(scissorRect); | 145 fScissorState.set(scissorRect); | 
| 146 fDeviceBounds = SkRect::Make(scissorRect); | |
| 112 fHasStencilClip = false; | 147 fHasStencilClip = false; | 
| 113 } | 148 } | 
| 114 | 149 | 
| 115 void enableStencilClip(bool enable) { fHasStencilClip = enable; } | 150 void enableStencilClip(const SkRect& deviceBounds) { | 
| 151 fHasStencilClip = true; | |
| 152 fDeviceBounds = deviceBounds; | |
| 
robertphillips
2016/07/08 15:46:14
We don't need an "if (fScissorState.enabled())" gu
 
bsalomon
2016/07/08 17:06:43
Done.
 | |
| 153 SkASSERT(fScissorState.rect().contains(deviceBounds)); | |
| 154 } | |
| 155 | |
| 156 void disableStencilClip() { | |
| 157 fHasStencilClip = false; | |
| 158 if (fScissorState.enabled()) { | |
| 159 fDeviceBounds = SkRect::Make(fScissorState.rect()); | |
| 160 } else { | |
| 161 fDeviceBounds.setLargest(); | |
| 162 } | |
| 163 } | |
| 116 | 164 | 
| 117 const GrScissorState& scissorState() const { return fScissorState; } | 165 const GrScissorState& scissorState() const { return fScissorState; } | 
| 118 bool hasStencilClip() const { return fHasStencilClip; } | 166 bool hasStencilClip() const { return fHasStencilClip; } | 
| 119 | 167 | 
| 120 bool quickContains(const SkRect&) const final; | 168 bool quickContains(const SkRect&) const final; | 
| 121 void getConservativeBounds(int width, int height, SkIRect* devResult, | 169 void getConservativeBounds(int width, int height, SkIRect* devResult, | 
| 122 bool* isIntersectionOfRects) const final; | 170 bool* isIntersectionOfRects) const final; | 
| 123 | 171 | 
| 124 private: | 172 private: | 
| 125 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, | 173 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, | 
| 126 const SkRect* devBounds, GrAppliedClip* out) const final; | 174 const SkRect* devBounds, GrAppliedClip* out) const final; | 
| 127 | 175 | 
| 128 GrScissorState fScissorState; | 176 GrScissorState fScissorState; | 
| 177 SkRect fDeviceBounds; | |
| 129 bool fHasStencilClip; | 178 bool fHasStencilClip; | 
| 130 }; | 179 }; | 
| 131 | 180 | 
| 132 /** | 181 /** | 
| 133 * GrClipStackClip can apply a generic SkClipStack to the draw state. It may gen erate clip masks or | 182 * GrClipStackClip can apply a generic SkClipStack to the draw state. It may gen erate clip masks or | 
| 134 * write to the stencil buffer during apply(). | 183 * write to the stencil buffer during apply(). | 
| 135 */ | 184 */ | 
| 136 class GrClipStackClip final : public GrClip { | 185 class GrClipStackClip final : public GrClip { | 
| 137 public: | 186 public: | 
| 138 GrClipStackClip(const SkClipStack* stack = nullptr, const SkIPoint* origin = nullptr) { | 187 GrClipStackClip(const SkClipStack* stack = nullptr, const SkIPoint* origin = nullptr) { | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 152 bool* isIntersectionOfRects) const final; | 201 bool* isIntersectionOfRects) const final; | 
| 153 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, | 202 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, | 
| 154 const SkRect* devBounds, GrAppliedClip*) const final; | 203 const SkRect* devBounds, GrAppliedClip*) const final; | 
| 155 | 204 | 
| 156 private: | 205 private: | 
| 157 SkIPoint fOrigin; | 206 SkIPoint fOrigin; | 
| 158 SkAutoTUnref<const SkClipStack> fStack; | 207 SkAutoTUnref<const SkClipStack> fStack; | 
| 159 }; | 208 }; | 
| 160 | 209 | 
| 161 #endif | 210 #endif | 
| OLD | NEW |