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

Side by Side Diff: src/gpu/GrDrawState.h

Issue 448453002: Create struct in GrDrawState to hold key DrawState data. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Change name and add comment to struct Created 6 years, 4 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/GrDrawState.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 2011 Google Inc. 2 * Copyright 2011 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 GrDrawState_DEFINED
9 #define GrDrawState_DEFINED 9 #define GrDrawState_DEFINED
10 10
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 uint8_t getCoverage() const { 208 uint8_t getCoverage() const {
209 return GrColorUnpackR(fCoverage); 209 return GrColorUnpackR(fCoverage);
210 } 210 }
211 211
212 GrColor getCoverageColor() const { 212 GrColor getCoverageColor() const {
213 return fCoverage; 213 return fCoverage;
214 } 214 }
215 215
216 /// @} 216 /// @}
217 217
218 /**
219 * This struct is here so that the GrDrawState can have multiple instances o f state information.
220 * The use of this will come in a future revision when we want to keep track of the original
221 * draw state as well as an optimized version of it.
222 */
223 struct State {
224 State() {
225 this->reset();
226 }
227
228 State(const GrEffectStage* colorArray, int colorCount,
229 const GrEffectStage* coverageArray, int coverageCount)
230 : fColorStages(colorArray, colorCount), fCoverageStages(coverageArra y, coverageCount) {
231 fSrcBlend = kOne_GrBlendCoeff;
232 fDstBlend = kZero_GrBlendCoeff;
233 }
234
235 static bool HaveCompatibleState(const State& a, const State& b, bool exp licitLocalCoords);
236
237 void reset() {
238 fSrcBlend = kOne_GrBlendCoeff;
239 fDstBlend = kZero_GrBlendCoeff;
240 fColorStages.reset();
241 fCoverageStages.reset();
242 }
243
244 GrBlendCoeff fSrcBlend;
245 GrBlendCoeff fDstBlend;
246
247 typedef SkSTArray<4, GrEffectStage> EffectStageArray;
248 EffectStageArray fColorStages;
249 EffectStageArray fCoverageStages;
250 };
251
218 /////////////////////////////////////////////////////////////////////////// 252 ///////////////////////////////////////////////////////////////////////////
219 /// @name Effect Stages 253 /// @name Effect Stages
220 /// Each stage hosts a GrEffect. The effect produces an output color or cove rage in the fragment 254 /// Each stage hosts a GrEffect. The effect produces an output color or cove rage in the fragment
221 /// shader. Its inputs are the output from the previous stage as well as som e variables 255 /// shader. Its inputs are the output from the previous stage as well as som e variables
222 /// available to it in the fragment and vertex shader (e.g. the vertex posit ion, the dst color, 256 /// available to it in the fragment and vertex shader (e.g. the vertex posit ion, the dst color,
223 /// the fragment position, local coordinates). 257 /// the fragment position, local coordinates).
224 /// 258 ///
225 /// The stages are divided into two sets, color-computing and coverage-compu ting. The final 259 /// The stages are divided into two sets, color-computing and coverage-compu ting. The final
226 /// color stage produces the final pixel color. The coverage-computing stage s function exactly 260 /// color stage produces the final pixel color. The coverage-computing stage s function exactly
227 /// as the color-computing but the output of the final coverage stage is tre ated as a fractional 261 /// as the color-computing but the output of the final coverage stage is tre ated as a fractional
228 /// pixel coverage rather than as input to the src/dst color blend step. 262 /// pixel coverage rather than as input to the src/dst color blend step.
229 /// 263 ///
230 /// The input color to the first color-stage is either the constant color or interpolated 264 /// The input color to the first color-stage is either the constant color or interpolated
231 /// per-vertex colors. The input to the first coverage stage is either a con stant coverage 265 /// per-vertex colors. The input to the first coverage stage is either a con stant coverage
232 /// (usually full-coverage) or interpolated per-vertex coverage. 266 /// (usually full-coverage) or interpolated per-vertex coverage.
233 /// 267 ///
234 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the 268 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the
235 /// the color / coverage distinction. 269 /// the color / coverage distinction.
236 //// 270 ////
237 271
238 const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int a ttr1 = -1) { 272 const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int a ttr1 = -1) {
239 SkASSERT(NULL != effect); 273 SkASSERT(NULL != effect);
240 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att r1)); 274 SkNEW_APPEND_TO_TARRAY(&fState.fColorStages, GrEffectStage, (effect, att r0, attr1));
241 this->invalidateBlendOptFlags(); 275 this->invalidateBlendOptFlags();
242 return effect; 276 return effect;
243 } 277 }
244 278
245 const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, in t attr1 = -1) { 279 const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, in t attr1 = -1) {
246 SkASSERT(NULL != effect); 280 SkASSERT(NULL != effect);
247 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1)); 281 SkNEW_APPEND_TO_TARRAY(&fState.fCoverageStages, GrEffectStage, (effect, attr0, attr1));
248 this->invalidateBlendOptFlags(); 282 this->invalidateBlendOptFlags();
249 return effect; 283 return effect;
250 } 284 }
251 285
252 /** 286 /**
253 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin ates. 287 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin ates.
254 */ 288 */
255 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { 289 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) {
256 this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->un ref(); 290 this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->un ref();
257 } 291 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 void set(GrDrawState* ds); 323 void set(GrDrawState* ds);
290 324
291 bool isSet() const { return NULL != fDrawState; } 325 bool isSet() const { return NULL != fDrawState; }
292 326
293 private: 327 private:
294 GrDrawState* fDrawState; 328 GrDrawState* fDrawState;
295 int fColorEffectCnt; 329 int fColorEffectCnt;
296 int fCoverageEffectCnt; 330 int fCoverageEffectCnt;
297 }; 331 };
298 332
299 int numColorStages() const { return fColorStages.count(); } 333 int numColorStages() const { return fState.fColorStages.count(); }
300 int numCoverageStages() const { return fCoverageStages.count(); } 334 int numCoverageStages() const { return fState.fCoverageStages.count(); }
301 int numTotalStages() const { return this->numColorStages() + this->numCovera geStages(); } 335 int numTotalStages() const { return this->numColorStages() + this->numCovera geStages(); }
302 336
303 const GrEffectStage& getColorStage(int stageIdx) const { return fColorStages [stageIdx]; } 337 const GrEffectStage& getColorStage(int stageIdx) const { return fState.fColo rStages[stageIdx]; }
304 const GrEffectStage& getCoverageStage(int stageIdx) const { return fCoverage Stages[stageIdx]; } 338 const GrEffectStage& getCoverageStage(int stageIdx) const { return fState.fC overageStages[stageIdx]; }
305 339
306 /** 340 /**
307 * Checks whether any of the effects will read the dst pixel color. 341 * Checks whether any of the effects will read the dst pixel color.
308 */ 342 */
309 bool willEffectReadDstColor() const; 343 bool willEffectReadDstColor() const;
310 344
311 /// @} 345 /// @}
312 346
313 /////////////////////////////////////////////////////////////////////////// 347 ///////////////////////////////////////////////////////////////////////////
314 /// @name Blending 348 /// @name Blending
315 //// 349 ////
316 350
317 /** 351 /**
318 * Sets the blending function coefficients. 352 * Sets the blending function coefficients.
319 * 353 *
320 * The blend function will be: 354 * The blend function will be:
321 * D' = sat(S*srcCoef + D*dstCoef) 355 * D' = sat(S*srcCoef + D*dstCoef)
322 * 356 *
323 * where D is the existing destination color, S is the incoming source 357 * where D is the existing destination color, S is the incoming source
324 * color, and D' is the new destination color that will be written. sat() 358 * color, and D' is the new destination color that will be written. sat()
325 * is the saturation function. 359 * is the saturation function.
326 * 360 *
327 * @param srcCoef coefficient applied to the src color. 361 * @param srcCoef coefficient applied to the src color.
328 * @param dstCoef coefficient applied to the dst color. 362 * @param dstCoef coefficient applied to the dst color.
329 */ 363 */
330 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { 364 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) {
331 fSrcBlend = srcCoeff; 365 fState.fSrcBlend = srcCoeff;
332 fDstBlend = dstCoeff; 366 fState.fDstBlend = dstCoeff;
333 this->invalidateBlendOptFlags(); 367 this->invalidateBlendOptFlags();
334 #ifdef SK_DEBUG 368 #ifdef SK_DEBUG
335 if (GrBlendCoeffRefsDst(dstCoeff)) { 369 if (GrBlendCoeffRefsDst(dstCoeff)) {
336 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n"); 370 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n");
337 } 371 }
338 if (GrBlendCoeffRefsSrc(srcCoeff)) { 372 if (GrBlendCoeffRefsSrc(srcCoeff)) {
339 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n"); 373 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n");
340 } 374 }
341 #endif 375 #endif
342 } 376 }
343 377
344 GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlend; } 378 GrBlendCoeff getSrcBlendCoeff() const { return fState.fSrcBlend; }
345 GrBlendCoeff getDstBlendCoeff() const { return fDstBlend; } 379 GrBlendCoeff getDstBlendCoeff() const { return fState.fDstBlend; }
346 380
347 void getDstBlendCoeff(GrBlendCoeff* srcBlendCoeff, 381 void getDstBlendCoeff(GrBlendCoeff* srcBlendCoeff,
348 GrBlendCoeff* dstBlendCoeff) const { 382 GrBlendCoeff* dstBlendCoeff) const {
349 *srcBlendCoeff = fSrcBlend; 383 *srcBlendCoeff = fState.fSrcBlend;
350 *dstBlendCoeff = fDstBlend; 384 *dstBlendCoeff = fState.fDstBlend;
351 } 385 }
352 386
353 /** 387 /**
354 * Sets the blending function constant referenced by the following blending 388 * Sets the blending function constant referenced by the following blending
355 * coefficients: 389 * coefficients:
356 * kConstC_GrBlendCoeff 390 * kConstC_GrBlendCoeff
357 * kIConstC_GrBlendCoeff 391 * kIConstC_GrBlendCoeff
358 * kConstA_GrBlendCoeff 392 * kConstA_GrBlendCoeff
359 * kIConstA_GrBlendCoeff 393 * kIConstA_GrBlendCoeff
360 * 394 *
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 794
761 /** This function determines whether the GrDrawStates used for two draws can be combined into 795 /** This function determines whether the GrDrawStates used for two draws can be combined into
762 a single GrDrawState. This is used to avoid storing redundant GrDrawStat es and to determine 796 a single GrDrawState. This is used to avoid storing redundant GrDrawStat es and to determine
763 if draws can be batched. The return value indicates whether combining is possible and, if 797 if draws can be batched. The return value indicates whether combining is possible and, if
764 so, which of the two inputs should be used. */ 798 so, which of the two inputs should be used. */
765 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta te& b); 799 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta te& b);
766 800
767 GrDrawState& operator= (const GrDrawState& that); 801 GrDrawState& operator= (const GrDrawState& that);
768 802
769 private: 803 private:
770
771 void onReset(const SkMatrix* initialViewMatrix); 804 void onReset(const SkMatrix* initialViewMatrix);
772 805
773 BlendOptFlags calcBlendOpts(bool forceCoverage = false, 806 BlendOptFlags calcBlendOpts(bool forceCoverage = false,
774 GrBlendCoeff* srcCoeff = NULL, 807 GrBlendCoeff* srcCoeff = NULL,
775 GrBlendCoeff* dstCoeff = NULL) const; 808 GrBlendCoeff* dstCoeff = NULL) const;
776 809
777 // These fields are roughly sorted by decreasing likelihood of being differe nt in op== 810 // These fields are roughly sorted by decreasing likelihood of being differe nt in op==
778 SkAutoTUnref<GrRenderTarget> fRenderTarget; 811 SkAutoTUnref<GrRenderTarget> fRenderTarget;
779 GrColor fColor; 812 GrColor fColor;
780 SkMatrix fViewMatrix; 813 SkMatrix fViewMatrix;
781 GrBlendCoeff fSrcBlend;
782 GrBlendCoeff fDstBlend;
783 GrColor fBlendConstant; 814 GrColor fBlendConstant;
784 uint32_t fFlagBits; 815 uint32_t fFlagBits;
785 const GrVertexAttrib* fVAPtr; 816 const GrVertexAttrib* fVAPtr;
786 int fVACount; 817 int fVACount;
787 GrStencilSettings fStencilSettings; 818 GrStencilSettings fStencilSettings;
788 GrColor fCoverage; 819 GrColor fCoverage;
789 DrawFace fDrawFace; 820 DrawFace fDrawFace;
790 821
791 typedef SkSTArray<4, GrEffectStage> EffectStageArray; 822 State fState;
792 EffectStageArray fColorStages;
793 EffectStageArray fCoverageStages;
794 823
795 mutable GrBlendCoeff fOptSrcBlend; 824 mutable GrBlendCoeff fOptSrcBlend;
796 mutable GrBlendCoeff fOptDstBlend; 825 mutable GrBlendCoeff fOptDstBlend;
797 mutable BlendOptFlags fBlendOptFlags; 826 mutable BlendOptFlags fBlendOptFlags;
798 827
799 // This is simply a different representation of info in fVertexAttribs and t hus does 828 // This is simply a different representation of info in fVertexAttribs and t hus does
800 // not need to be compared in op==. 829 // not need to be compared in op==.
801 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt ]; 830 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt ];
802 831
803 // Some of the auto restore objects assume that no effects are removed durin g their lifetime. 832 // Some of the auto restore objects assume that no effects are removed durin g their lifetime.
804 // This is used to assert that this condition holds. 833 // This is used to assert that this condition holds.
805 SkDEBUGCODE(int fBlockEffectRemovalCnt;) 834 SkDEBUGCODE(int fBlockEffectRemovalCnt;)
806 835
807 /** 836 /**
808 * Sets vertex attributes for next draw. 837 * Sets vertex attributes for next draw.
809 * 838 *
810 * @param attribs the array of vertex attributes to set. 839 * @param attribs the array of vertex attributes to set.
811 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. 840 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt.
812 */ 841 */
813 void setVertexAttribs(const GrVertexAttrib attribs[], int count); 842 void setVertexAttribs(const GrVertexAttrib attribs[], int count);
814 843
815 typedef SkRefCnt INHERITED; 844 typedef SkRefCnt INHERITED;
816 }; 845 };
817 846
818 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); 847 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags);
819 848
820 #endif 849 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrDrawState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698