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 * Copies another draw state. | 35 GrPipelineBuilder(const GrPipelineBuilder& pipelineBuilder) { |
36 **/ | |
37 GrDrawState(const GrDrawState& state) { | |
38 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 36 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
39 *this = state; | 37 *this = pipelineBuilder; |
40 } | 38 } |
41 | 39 |
42 virtual ~GrDrawState(); | 40 virtual ~GrPipelineBuilder(); |
43 | 41 |
44 /** | 42 /** |
45 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta
rget. Note that | 43 * Initializes the GrPipelineBuilder based on a GrPaint, view matrix and ren
der target. Note |
46 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha
ve no GrPaint | 44 * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipeli
neBuilder that have |
47 * equivalents are set to default values with the exception of vertex attrib
ute state which | 45 * no GrPaint equivalents are set to default values with the exception of ve
rtex attribute state |
48 * is unmodified by this function and clipping which will be enabled. | 46 * which is unmodified by this function and clipping which will be enabled. |
49 */ | 47 */ |
50 void setFromPaint(const GrPaint&, GrRenderTarget*); | 48 void setFromPaint(const GrPaint&, GrRenderTarget*); |
51 | 49 |
52 /// @} | 50 /// @} |
53 | 51 |
54 /** | 52 /** |
55 * Depending on features available in the underlying 3D API and the color bl
end mode requested | 53 * 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 | 54 * it may or may not be possible to correctly blend with fractional pixel co
verage generated by |
57 * the fragment shader. | 55 * the fragment shader. |
58 * | 56 * |
59 * This function considers the current draw state and the draw target's capa
bilities to | 57 * This function considers the current GrPipelineBuilder and the draw target
's capabilities to |
60 * determine whether coverage can be handled correctly. This function assume
s that the caller | 58 * 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 | 59 * intends to specify fractional pixel coverage via a primitive processor bu
t may not have |
62 * specified it yet. | 60 * specified it yet. |
63 */ | 61 */ |
64 bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps)
const; | 62 bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps)
const; |
65 | 63 |
66 /** | 64 /** |
67 * This function returns true if the render target destination pixel values
will be read for | 65 * This function returns true if the render target destination pixel values
will be read for |
68 * blending during draw. | 66 * blending during draw. |
69 */ | 67 */ |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, p
arams))->unref(); | 162 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, p
arams))->unref(); |
165 } | 163 } |
166 | 164 |
167 void addCoverageTextureProcessor(GrTexture* texture, | 165 void addCoverageTextureProcessor(GrTexture* texture, |
168 const SkMatrix& matrix, | 166 const SkMatrix& matrix, |
169 const GrTextureParams& params) { | 167 const GrTextureParams& params) { |
170 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix
, params))->unref(); | 168 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix
, params))->unref(); |
171 } | 169 } |
172 | 170 |
173 /** | 171 /** |
174 * When this object is destroyed it will remove any color/coverage effects f
rom the draw state | 172 * When this object is destroyed it will remove any color/coverage effects f
rom the pipeline |
175 * that were added after its constructor. | 173 * builder that were added after its constructor. |
176 * | 174 * |
177 * This class has strange behavior around geometry processor. If there is a
GP on the draw state | 175 * This class has strange behavior around geometry processor. If there is a
GP on the |
178 * it will assert that the GP is not modified until after the destructor of
the ARE. If the | 176 * GrPipelineBuilder it will assert that the GP is not modified until after
the destructor of |
179 * draw state has a NULL GP when the ARE is constructed then it will reset i
t to null in the | 177 * the ARE. If the GrPipelineBuilder has a NULL GP when the ARE is construct
ed then it will reset |
180 * destructor. | 178 * it to null 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 */ | 179 */ |
189 class AutoRestoreEffects : public ::SkNoncopyable { | 180 class AutoRestoreEffects : public ::SkNoncopyable { |
190 public: | 181 public: |
191 AutoRestoreEffects() | 182 AutoRestoreEffects() |
192 : fDrawState(NULL) | 183 : fPipelineBuilder(NULL) |
193 , fColorEffectCnt(0) | 184 , fColorEffectCnt(0) |
194 , fCoverageEffectCnt(0) {} | 185 , fCoverageEffectCnt(0) {} |
195 | 186 |
196 AutoRestoreEffects(GrDrawState* ds) | 187 AutoRestoreEffects(GrPipelineBuilder* ds) |
197 : fDrawState(NULL) | 188 : fPipelineBuilder(NULL) |
198 , fColorEffectCnt(0) | 189 , fColorEffectCnt(0) |
199 , fCoverageEffectCnt(0) { | 190 , fCoverageEffectCnt(0) { |
200 this->set(ds); | 191 this->set(ds); |
201 } | 192 } |
202 | 193 |
203 ~AutoRestoreEffects() { this->set(NULL); } | 194 ~AutoRestoreEffects() { this->set(NULL); } |
204 | 195 |
205 void set(GrDrawState* ds); | 196 void set(GrPipelineBuilder* ds); |
206 | 197 |
207 bool isSet() const { return SkToBool(fDrawState); } | 198 bool isSet() const { return SkToBool(fPipelineBuilder); } |
208 | 199 |
209 private: | 200 private: |
210 GrDrawState* fDrawState; | 201 GrPipelineBuilder* fPipelineBuilder; |
211 int fColorEffectCnt; | 202 int fColorEffectCnt; |
212 int fCoverageEffectCnt; | 203 int fCoverageEffectCnt; |
213 }; | 204 }; |
214 | 205 |
215 /** | 206 /** |
216 * AutoRestoreStencil | 207 * AutoRestoreStencil |
217 * | 208 * |
218 * This simple struct saves and restores the stencil settings | 209 * This simple struct saves and restores the stencil settings |
219 */ | 210 */ |
220 class AutoRestoreStencil : public ::SkNoncopyable { | 211 class AutoRestoreStencil : public ::SkNoncopyable { |
221 public: | 212 public: |
222 AutoRestoreStencil() : fDrawState(NULL) {} | 213 AutoRestoreStencil() : fPipelineBuilder(NULL) {} |
223 | 214 |
224 AutoRestoreStencil(GrDrawState* ds) : fDrawState(NULL) { this->set(ds);
} | 215 AutoRestoreStencil(GrPipelineBuilder* ds) : fPipelineBuilder(NULL) { thi
s->set(ds); } |
225 | 216 |
226 ~AutoRestoreStencil() { this->set(NULL); } | 217 ~AutoRestoreStencil() { this->set(NULL); } |
227 | 218 |
228 void set(GrDrawState* ds) { | 219 void set(GrPipelineBuilder* ds) { |
229 if (fDrawState) { | 220 if (fPipelineBuilder) { |
230 fDrawState->setStencil(fStencilSettings); | 221 fPipelineBuilder->setStencil(fStencilSettings); |
231 } | 222 } |
232 fDrawState = ds; | 223 fPipelineBuilder = ds; |
233 if (ds) { | 224 if (ds) { |
234 fStencilSettings = ds->getStencil(); | 225 fStencilSettings = ds->getStencil(); |
235 } | 226 } |
236 } | 227 } |
237 | 228 |
238 bool isSet() const { return SkToBool(fDrawState); } | 229 bool isSet() const { return SkToBool(fPipelineBuilder); } |
239 | 230 |
240 private: | 231 private: |
241 GrDrawState* fDrawState; | 232 GrPipelineBuilder* fPipelineBuilder; |
242 GrStencilSettings fStencilSettings; | 233 GrStencilSettings fStencilSettings; |
243 }; | 234 }; |
244 | 235 |
245 /// @} | 236 /// @} |
246 | 237 |
247 /////////////////////////////////////////////////////////////////////////// | 238 /////////////////////////////////////////////////////////////////////////// |
248 /// @name Blending | 239 /// @name Blending |
249 //// | 240 //// |
250 | 241 |
251 /** | 242 /** |
252 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional | 243 * 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 */ | 381 */ |
391 void setDrawFace(DrawFace face) { | 382 void setDrawFace(DrawFace face) { |
392 SkASSERT(kInvalid_DrawFace != face); | 383 SkASSERT(kInvalid_DrawFace != face); |
393 fDrawFace = face; | 384 fDrawFace = face; |
394 } | 385 } |
395 | 386 |
396 /// @} | 387 /// @} |
397 | 388 |
398 /////////////////////////////////////////////////////////////////////////// | 389 /////////////////////////////////////////////////////////////////////////// |
399 | 390 |
400 GrDrawState& operator= (const GrDrawState& that); | 391 GrPipelineBuilder& operator= (const GrPipelineBuilder& that); |
401 | 392 |
402 private: | 393 private: |
403 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { | 394 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { |
404 this->calcColorInvariantOutput(pp); | 395 this->calcColorInvariantOutput(pp); |
405 return fColorProcInfo; | 396 return fColorProcInfo; |
406 } | 397 } |
407 | 398 |
408 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const
{ | 399 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const
{ |
409 this->calcCoverageInvariantOutput(pp); | 400 this->calcCoverageInvariantOutput(pp); |
410 return fCoverageProcInfo; | 401 return fCoverageProcInfo; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 | 441 |
451 mutable GrProcOptInfo fColorProcInfo; | 442 mutable GrProcOptInfo fColorProcInfo; |
452 mutable GrProcOptInfo fCoverageProcInfo; | 443 mutable GrProcOptInfo fCoverageProcInfo; |
453 mutable bool fColorProcInfoValid; | 444 mutable bool fColorProcInfoValid; |
454 mutable bool fCoverageProcInfoValid; | 445 mutable bool fCoverageProcInfoValid; |
455 mutable GrColor fColorCache; | 446 mutable GrColor fColorCache; |
456 mutable GrColor fCoverageCache; | 447 mutable GrColor fCoverageCache; |
457 mutable const GrPrimitiveProcessor* fColorPrimProc; | 448 mutable const GrPrimitiveProcessor* fColorPrimProc; |
458 mutable const GrPrimitiveProcessor* fCoveragePrimProc; | 449 mutable const GrPrimitiveProcessor* fCoveragePrimProc; |
459 | 450 |
460 friend class GrOptDrawState; | 451 friend class GrPipeline; |
461 }; | 452 }; |
462 | 453 |
463 #endif | 454 #endif |
OLD | NEW |