OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2015 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 GrDrawState_DEFINED | 8 #ifndef GrPipelineBuilder_DEFINED |
9 #define GrDrawState_DEFINED | 9 #define GrPipelineBuilder_DEFINED |
10 | 10 |
11 | 11 |
12 #include "GrBlend.h" | 12 #include "GrBlend.h" |
13 #include "GrDrawTargetCaps.h" | 13 #include "GrDrawTargetCaps.h" |
14 #include "GrGeometryProcessor.h" | 14 #include "GrGeometryProcessor.h" |
15 #include "GrGpuResourceRef.h" | 15 #include "GrGpuResourceRef.h" |
16 #include "GrFragmentStage.h" | 16 #include "GrFragmentStage.h" |
17 #include "GrProcOptInfo.h" | 17 #include "GrProcOptInfo.h" |
18 #include "GrRenderTarget.h" | 18 #include "GrRenderTarget.h" |
19 #include "GrStencil.h" | 19 #include "GrStencil.h" |
20 #include "GrXferProcessor.h" | 20 #include "GrXferProcessor.h" |
21 #include "SkMatrix.h" | 21 #include "SkMatrix.h" |
22 #include "effects/GrCoverageSetOpXP.h" | 22 #include "effects/GrCoverageSetOpXP.h" |
23 #include "effects/GrDisableColorXP.h" | 23 #include "effects/GrDisableColorXP.h" |
24 #include "effects/GrPorterDuffXferProcessor.h" | 24 #include "effects/GrPorterDuffXferProcessor.h" |
25 #include "effects/GrSimpleTextureEffect.h" | 25 #include "effects/GrSimpleTextureEffect.h" |
26 | 26 |
27 class GrDrawTargetCaps; | 27 class GrDrawTargetCaps; |
28 class GrPaint; | 28 class GrPaint; |
29 class GrTexture; | 29 class GrTexture; |
30 | 30 |
31 class GrDrawState { | 31 class GrPipelineBuilder { |
32 public: | 32 public: |
33 GrDrawState(); | 33 GrPipelineBuilder(); |
34 | |
34 /** | 35 /** |
35 * Copies another draw state. | 36 * Copies another pipeline builder. |
36 **/ | 37 **/ |
37 GrDrawState(const GrDrawState& state) { | 38 GrPipelineBuilder(const GrPipelineBuilder& state) { |
38 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 39 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
39 *this = state; | 40 *this = state; |
40 } | 41 } |
41 | 42 |
42 virtual ~GrDrawState(); | 43 virtual ~GrPipelineBuilder(); |
43 | 44 |
44 /** | 45 /** |
45 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta rget. Note that | 46 * Initializes the GrPipelineBuilder based on a GrPaint, view matrix and ren der target. Note that |
46 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha ve no GrPaint | 47 * GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipelineBui lder that have no GrPaint |
joshualitt
2015/01/22 15:55:08
\n
egdaniel
2015/01/22 16:28:56
Done.
| |
47 * equivalents are set to default values with the exception of vertex attrib ute state which | 48 * equivalents are set to default values with the exception of vertex attrib ute state which |
48 * is unmodified by this function and clipping which will be enabled. | 49 * is unmodified by this function and clipping which will be enabled. |
49 */ | 50 */ |
50 void setFromPaint(const GrPaint&, GrRenderTarget*); | 51 void setFromPaint(const GrPaint&, GrRenderTarget*); |
51 | 52 |
52 /// @} | 53 /// @} |
53 | 54 |
54 /** | 55 /** |
55 * Depending on features available in the underlying 3D API and the color bl end mode requested | 56 * Depending on features available in the underlying 3D API and the color bl end mode requested |
56 * it may or may not be possible to correctly blend with fractional pixel co verage generated by | 57 * it may or may not be possible to correctly blend with fractional pixel co verage generated by |
57 * the fragment shader. | 58 * the fragment shader. |
58 * | 59 * |
59 * This function considers the current draw state and the draw target's capa bilities to | 60 * This function considers the current pipeline builder and the draw target' s capabilities to |
joshualitt
2015/01/22 15:55:08
Gr
egdaniel
2015/01/22 16:28:56
Done.
| |
60 * determine whether coverage can be handled correctly. This function assume s that the caller | 61 * determine whether coverage can be handled correctly. This function assume s that the caller |
61 * intends to specify fractional pixel coverage via a primitive processor bu t may not have | 62 * intends to specify fractional pixel coverage via a primitive processor bu t may not have |
62 * specified it yet. | 63 * specified it yet. |
63 */ | 64 */ |
64 bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps) const; | 65 bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps) const; |
65 | 66 |
66 /** | 67 /** |
67 * This function returns true if the render target destination pixel values will be read for | 68 * This function returns true if the render target destination pixel values will be read for |
68 * blending during draw. | 69 * blending during draw. |
69 */ | 70 */ |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, p arams))->unref(); | 165 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, p arams))->unref(); |
165 } | 166 } |
166 | 167 |
167 void addCoverageTextureProcessor(GrTexture* texture, | 168 void addCoverageTextureProcessor(GrTexture* texture, |
168 const SkMatrix& matrix, | 169 const SkMatrix& matrix, |
169 const GrTextureParams& params) { | 170 const GrTextureParams& params) { |
170 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix , params))->unref(); | 171 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix , params))->unref(); |
171 } | 172 } |
172 | 173 |
173 /** | 174 /** |
174 * When this object is destroyed it will remove any color/coverage effects f rom the draw state | 175 * When this object is destroyed it will remove any color/coverage effects f rom the pipeline |
joshualitt
2015/01/22 15:55:08
Gr
egdaniel
2015/01/22 16:28:56
Done.
| |
175 * that were added after its constructor. | 176 * builder that were added after its constructor. |
176 * | 177 * |
177 * This class has strange behavior around geometry processor. If there is a GP on the draw state | 178 * This class has strange behavior around geometry processor. If there is a GP on the pipeline |
178 * it will assert that the GP is not modified until after the destructor of the ARE. If the | 179 * builder it will assert that the GP is not modified until after the destru ctor of the ARE. If |
179 * draw state has a NULL GP when the ARE is constructed then it will reset i t to null in the | 180 * the pipeline builder has a NULL GP when the ARE is constructed then it wi ll reset it to null |
180 * destructor. | 181 * in the destructor. |
181 * | |
182 * TODO: We'd prefer for the ARE to just save and restore the GP. However, t his would add | |
183 * significant complexity to the multi-ref architecture for deferred drawing . Once GrDrawState | |
184 * and GrOptDrawState are fully separated then GrDrawState will never be in the deferred | |
185 * execution state and GrOptDrawState always will be (and will be immutable and therefore | |
186 * unable to have an ARE). At this point we can restore sanity and have the ARE save and restore | |
187 * the GP. | |
188 */ | 182 */ |
189 class AutoRestoreEffects : public ::SkNoncopyable { | 183 class AutoRestoreEffects : public ::SkNoncopyable { |
190 public: | 184 public: |
191 AutoRestoreEffects() | 185 AutoRestoreEffects() |
192 : fDrawState(NULL) | 186 : fPipelineBuilder(NULL) |
193 , fColorEffectCnt(0) | 187 , fColorEffectCnt(0) |
194 , fCoverageEffectCnt(0) {} | 188 , fCoverageEffectCnt(0) {} |
195 | 189 |
196 AutoRestoreEffects(GrDrawState* ds) | 190 AutoRestoreEffects(GrPipelineBuilder* ds) |
197 : fDrawState(NULL) | 191 : fPipelineBuilder(NULL) |
198 , fColorEffectCnt(0) | 192 , fColorEffectCnt(0) |
199 , fCoverageEffectCnt(0) { | 193 , fCoverageEffectCnt(0) { |
200 this->set(ds); | 194 this->set(ds); |
201 } | 195 } |
202 | 196 |
203 ~AutoRestoreEffects() { this->set(NULL); } | 197 ~AutoRestoreEffects() { this->set(NULL); } |
204 | 198 |
205 void set(GrDrawState* ds); | 199 void set(GrPipelineBuilder* ds); |
206 | 200 |
207 bool isSet() const { return SkToBool(fDrawState); } | 201 bool isSet() const { return SkToBool(fPipelineBuilder); } |
208 | 202 |
209 private: | 203 private: |
210 GrDrawState* fDrawState; | 204 GrPipelineBuilder* fPipelineBuilder; |
211 int fColorEffectCnt; | 205 int fColorEffectCnt; |
212 int fCoverageEffectCnt; | 206 int fCoverageEffectCnt; |
213 }; | 207 }; |
214 | 208 |
215 /** | 209 /** |
216 * AutoRestoreStencil | 210 * AutoRestoreStencil |
217 * | 211 * |
218 * This simple struct saves and restores the stencil settings | 212 * This simple struct saves and restores the stencil settings |
219 */ | 213 */ |
220 class AutoRestoreStencil : public ::SkNoncopyable { | 214 class AutoRestoreStencil : public ::SkNoncopyable { |
221 public: | 215 public: |
222 AutoRestoreStencil() : fDrawState(NULL) {} | 216 AutoRestoreStencil() : fPipelineBuilder(NULL) {} |
223 | 217 |
224 AutoRestoreStencil(GrDrawState* ds) : fDrawState(NULL) { this->set(ds); } | 218 AutoRestoreStencil(GrPipelineBuilder* ds) : fPipelineBuilder(NULL) { thi s->set(ds); } |
225 | 219 |
226 ~AutoRestoreStencil() { this->set(NULL); } | 220 ~AutoRestoreStencil() { this->set(NULL); } |
227 | 221 |
228 void set(GrDrawState* ds) { | 222 void set(GrPipelineBuilder* ds) { |
229 if (fDrawState) { | 223 if (fPipelineBuilder) { |
230 fDrawState->setStencil(fStencilSettings); | 224 fPipelineBuilder->setStencil(fStencilSettings); |
231 } | 225 } |
232 fDrawState = ds; | 226 fPipelineBuilder = ds; |
233 if (ds) { | 227 if (ds) { |
234 fStencilSettings = ds->getStencil(); | 228 fStencilSettings = ds->getStencil(); |
235 } | 229 } |
236 } | 230 } |
237 | 231 |
238 bool isSet() const { return SkToBool(fDrawState); } | 232 bool isSet() const { return SkToBool(fPipelineBuilder); } |
239 | 233 |
240 private: | 234 private: |
241 GrDrawState* fDrawState; | 235 GrPipelineBuilder* fPipelineBuilder; |
242 GrStencilSettings fStencilSettings; | 236 GrStencilSettings fStencilSettings; |
243 }; | 237 }; |
244 | 238 |
245 /// @} | 239 /// @} |
246 | 240 |
247 /////////////////////////////////////////////////////////////////////////// | 241 /////////////////////////////////////////////////////////////////////////// |
248 /// @name Blending | 242 /// @name Blending |
249 //// | 243 //// |
250 | 244 |
251 /** | 245 /** |
252 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional | 246 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 */ | 384 */ |
391 void setDrawFace(DrawFace face) { | 385 void setDrawFace(DrawFace face) { |
392 SkASSERT(kInvalid_DrawFace != face); | 386 SkASSERT(kInvalid_DrawFace != face); |
393 fDrawFace = face; | 387 fDrawFace = face; |
394 } | 388 } |
395 | 389 |
396 /// @} | 390 /// @} |
397 | 391 |
398 /////////////////////////////////////////////////////////////////////////// | 392 /////////////////////////////////////////////////////////////////////////// |
399 | 393 |
400 GrDrawState& operator= (const GrDrawState& that); | 394 GrPipelineBuilder& operator= (const GrPipelineBuilder& that); |
401 | 395 |
402 private: | 396 private: |
403 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { | 397 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { |
404 this->calcColorInvariantOutput(pp); | 398 this->calcColorInvariantOutput(pp); |
405 return fColorProcInfo; | 399 return fColorProcInfo; |
406 } | 400 } |
407 | 401 |
408 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const { | 402 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const { |
409 this->calcCoverageInvariantOutput(pp); | 403 this->calcCoverageInvariantOutput(pp); |
410 return fCoverageProcInfo; | 404 return fCoverageProcInfo; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 | 444 |
451 mutable GrProcOptInfo fColorProcInfo; | 445 mutable GrProcOptInfo fColorProcInfo; |
452 mutable GrProcOptInfo fCoverageProcInfo; | 446 mutable GrProcOptInfo fCoverageProcInfo; |
453 mutable bool fColorProcInfoValid; | 447 mutable bool fColorProcInfoValid; |
454 mutable bool fCoverageProcInfoValid; | 448 mutable bool fCoverageProcInfoValid; |
455 mutable GrColor fColorCache; | 449 mutable GrColor fColorCache; |
456 mutable GrColor fCoverageCache; | 450 mutable GrColor fCoverageCache; |
457 mutable const GrPrimitiveProcessor* fColorPrimProc; | 451 mutable const GrPrimitiveProcessor* fColorPrimProc; |
458 mutable const GrPrimitiveProcessor* fCoveragePrimProc; | 452 mutable const GrPrimitiveProcessor* fCoveragePrimProc; |
459 | 453 |
460 friend class GrOptDrawState; | 454 friend class GrPipeline; |
461 }; | 455 }; |
462 | 456 |
463 #endif | 457 #endif |
OLD | NEW |