Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: include/gpu/GrClip.h

Issue 2137543002: Use clipped bounds for reordering decisions (Closed) Base URL: https://chromium.googlesource.com/skia.git@lessstencil
Patch Set: fix windows warning Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/gpu/GrClip.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 */
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 16 matching lines...) Expand all
92 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, 122 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*,
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() : fDeviceBounds(SkRect::MakeLargest()), 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 /**
151 * Enables stenciling. The stencil bounds is the device space bounds where t he stencil test
152 * may pass.
153 */
154 void enableStencilClip(const SkRect& stencilBounds) {
155 fHasStencilClip = true;
156 fDeviceBounds = stencilBounds;
157 if (fScissorState.enabled()) {
158 const SkIRect& s = fScissorState.rect();
159 fDeviceBounds.fLeft = SkTMax(fDeviceBounds.fLeft, SkIntToScalar( s.fLeft));
160 fDeviceBounds.fTop = SkTMax(fDeviceBounds.fTop, SkIntToScalar( s.fTop));
161 fDeviceBounds.fRight = SkTMin(fDeviceBounds.fRight, SkIntToScalar( s.fRight));
162 fDeviceBounds.fBottom = SkTMin(fDeviceBounds.fBottom, SkIntToScalar( s.fBottom));
163 }
164 }
165
166 void disableStencilClip() {
167 fHasStencilClip = false;
168 if (fScissorState.enabled()) {
169 fDeviceBounds = SkRect::Make(fScissorState.rect());
170 } else {
171 fDeviceBounds.setLargest();
172 }
173 }
116 174
117 const GrScissorState& scissorState() const { return fScissorState; } 175 const GrScissorState& scissorState() const { return fScissorState; }
118 bool hasStencilClip() const { return fHasStencilClip; } 176 bool hasStencilClip() const { return fHasStencilClip; }
119 177
120 bool quickContains(const SkRect&) const final; 178 bool quickContains(const SkRect&) const final;
121 void getConservativeBounds(int width, int height, SkIRect* devResult, 179 void getConservativeBounds(int width, int height, SkIRect* devResult,
122 bool* isIntersectionOfRects) const final; 180 bool* isIntersectionOfRects) const final;
123 181
124 private: 182 private:
125 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, 183 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*,
126 const SkRect* devBounds, GrAppliedClip* out) const final; 184 const SkRect* devBounds, GrAppliedClip* out) const final;
127 185
128 GrScissorState fScissorState; 186 GrScissorState fScissorState;
187 SkRect fDeviceBounds;
129 bool fHasStencilClip; 188 bool fHasStencilClip;
130 }; 189 };
131 190
132 /** 191 /**
133 * GrClipStackClip can apply a generic SkClipStack to the draw state. It may gen erate clip masks or 192 * 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(). 193 * write to the stencil buffer during apply().
135 */ 194 */
136 class GrClipStackClip final : public GrClip { 195 class GrClipStackClip final : public GrClip {
137 public: 196 public:
138 GrClipStackClip(const SkClipStack* stack = nullptr, const SkIPoint* origin = nullptr) { 197 GrClipStackClip(const SkClipStack* stack = nullptr, const SkIPoint* origin = nullptr) {
(...skipping 13 matching lines...) Expand all
152 bool* isIntersectionOfRects) const final; 211 bool* isIntersectionOfRects) const final;
153 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, 212 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*,
154 const SkRect* devBounds, GrAppliedClip*) const final; 213 const SkRect* devBounds, GrAppliedClip*) const final;
155 214
156 private: 215 private:
157 SkIPoint fOrigin; 216 SkIPoint fOrigin;
158 SkAutoTUnref<const SkClipStack> fStack; 217 SkAutoTUnref<const SkClipStack> fStack;
159 }; 218 };
160 219
161 #endif 220 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrClip.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698