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

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

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