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

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

Issue 508663002: Create an optimized draw state but not hooked in yet to gpu pipeline (Closed) Base URL: https://skia.googlesource.com/skia.git@drawBase
Patch Set: Updates Created 6 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 GrRODrawState_DEFINED 8 #ifndef GrRODrawState_DEFINED
9 #define GrRODrawState_DEFINED 9 #define GrRODrawState_DEFINED
10 10
11 #include "GrStencil.h" 11 #include "GrStencil.h"
12 #include "GrEffectStage.h" 12 #include "GrEffectStage.h"
13 #include "SkMatrix.h" 13 #include "SkMatrix.h"
14 14
15 class GrDrawState;
15 class GrDrawTargetCaps; 16 class GrDrawTargetCaps;
16 class GrPaint; 17 class GrPaint;
17 class GrRenderTarget; 18 class GrRenderTarget;
18 class GrTexture; 19 class GrTexture;
19 20
20 /** 21 /**
21 * Read-only base class for GrDrawState. This class contains all the necessary d ata to represent a 22 * Read-only base class for GrDrawState. This class contains all the necessary d ata to represent a
22 * canonical DrawState. All methods in the class are const, thus once created th e data in the class 23 * canonical DrawState. All methods in the class are const, thus once created th e data in the class
23 * cannot be changed. 24 * cannot be changed.
24 */ 25 */
25 class GrRODrawState : public SkRefCnt { 26 class GrRODrawState : public SkRefCnt {
26 public: 27 public:
27 SK_DECLARE_INST_COUNT(GrRODrawState) 28 SK_DECLARE_INST_COUNT(GrRODrawState)
28 29
30 GrRODrawState() {}
31
32 GrRODrawState& operator= (const GrRODrawState& that);
33
29 /////////////////////////////////////////////////////////////////////////// 34 ///////////////////////////////////////////////////////////////////////////
30 /// @name Vertex Attributes 35 /// @name Vertex Attributes
31 //// 36 ////
32 37
33 enum { 38 enum {
34 kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4, 39 kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4,
35 }; 40 };
36 41
37 const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; } 42 const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; }
38 int getVertexAttribCount() const { return fVACount; } 43 int getVertexAttribCount() const { return fVACount; }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 *dstBlendCoeff = fDstBlend; 151 *dstBlendCoeff = fDstBlend;
147 } 152 }
148 153
149 /** 154 /**
150 * Retrieves the last value set by setBlendConstant() 155 * Retrieves the last value set by setBlendConstant()
151 * @return the blending constant value 156 * @return the blending constant value
152 */ 157 */
153 GrColor getBlendConstant() const { return fBlendConstant; } 158 GrColor getBlendConstant() const { return fBlendConstant; }
154 159
155 /** 160 /**
161 * We don't use supplied vertex color attributes if our blend mode is EmitCo verage or
162 * EmitTransBlack
163 */
164 bool canIgnoreColorAttribute() const;
165
166 /**
156 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional 167 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional
157 * coverage before the blend will give the correct final destination color. In general it 168 * coverage before the blend will give the correct final destination color. In general it
158 * will not as coverage is applied after blending. 169 * will not as coverage is applied after blending.
159 */ 170 */
160 bool canTweakAlphaForCoverage() const; 171 bool canTweakAlphaForCoverage() const;
161 172
162 /** 173 /**
163 * Optimizations for blending / coverage to that can be applied based on the current state. 174 * Optimizations for blending / coverage to that can be applied based on the current state.
164 */ 175 */
165 enum BlendOptFlags { 176 enum BlendOptFlags {
(...skipping 20 matching lines...) Expand all
186 */ 197 */
187 kEmitTransBlack_BlendOptFlag = 0x8, 198 kEmitTransBlack_BlendOptFlag = 0x8,
188 /** 199 /**
189 * Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and Op tDstCoeff cached by 200 * Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and Op tDstCoeff cached by
190 * the get BlendOpts function. 201 * the get BlendOpts function.
191 */ 202 */
192 kInvalid_BlendOptFlag = 1 << 31, 203 kInvalid_BlendOptFlag = 1 << 31,
193 }; 204 };
194 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); 205 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags);
195 206
207 /**
208 * Determines what optimizations can be applied based on the blend. The coef ficients may have
209 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef f are optional
210 * params that receive the tweaked coefficients. Normally the function looks at the current
211 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively
212 * determine the blend optimizations that would be used if there was partial pixel coverage.
213 *
214 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j ust buffer for
215 * playback) must call this function and respect the flags that replace the output color.
216 *
217 * If the cached BlendOptFlags does not have the invalidate bit set, then ge tBlendOpts will
218 * simply returned the cached flags and coefficients. Otherwise it will calc ulate the values.
219 */
220 BlendOptFlags getBlendOpts(bool forceCoverage = false,
221 GrBlendCoeff* srcCoeff = NULL,
222 GrBlendCoeff* dstCoeff = NULL) const;
196 /// @} 223 /// @}
197 224
198 /////////////////////////////////////////////////////////////////////////// 225 ///////////////////////////////////////////////////////////////////////////
199 /// @name View Matrix 226 /// @name View Matrix
200 //// 227 ////
201 228
202 /** 229 /**
203 * Retrieves the current view matrix 230 * Retrieves the current view matrix
204 * @return the current view matrix. 231 * @return the current view matrix.
205 */ 232 */
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 * control over the blend coeffs. When set, there will be a single blend step controlled by 315 * control over the blend coeffs. When set, there will be a single blend step controlled by
289 * setBlendFunc() which will use coverage*color as the src color. 316 * setBlendFunc() which will use coverage*color as the src color.
290 */ 317 */
291 kCoverageDrawing_StateBit = 0x10, 318 kCoverageDrawing_StateBit = 0x10,
292 319
293 // Users of the class may add additional bits to the vector 320 // Users of the class may add additional bits to the vector
294 kDummyStateBit, 321 kDummyStateBit,
295 kLastPublicStateBit = kDummyStateBit-1, 322 kLastPublicStateBit = kDummyStateBit-1,
296 }; 323 };
297 324
325 uint32_t getFlagBits() const { return fFlagBits; }
326
298 bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & f FlagBits); } 327 bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & f FlagBits); }
299 328
300 bool isDitherState() const { return 0 != (fFlagBits & kDither_StateBit); } 329 bool isDitherState() const { return 0 != (fFlagBits & kDither_StateBit); }
301 bool isHWAntialiasState() const { return 0 != (fFlagBits & kHWAntialias_Stat eBit); } 330 bool isHWAntialiasState() const { return 0 != (fFlagBits & kHWAntialias_Stat eBit); }
302 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } 331 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); }
303 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_ StateBit); } 332 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_ StateBit); }
304 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S tateBit); } 333 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S tateBit); }
305 334
306 /// @} 335 /// @}
307 336
(...skipping 12 matching lines...) Expand all
320 /** 349 /**
321 * Gets whether the target is drawing clockwise, counterclockwise, 350 * Gets whether the target is drawing clockwise, counterclockwise,
322 * or both faces. 351 * or both faces.
323 * @return the current draw face(s). 352 * @return the current draw face(s).
324 */ 353 */
325 DrawFace getDrawFace() const { return fDrawFace; } 354 DrawFace getDrawFace() const { return fDrawFace; }
326 355
327 /// @} 356 /// @}
328 357
329 /////////////////////////////////////////////////////////////////////////// 358 ///////////////////////////////////////////////////////////////////////////
359 /// @name Hints
360 /// Hints that when provided can enable optimizations.
361 ////
362
363 enum Hints { kVertexColorsAreOpaque_Hint = 0x1, };
364
365 bool vertexColorsAreOpaque() const { return kVertexColorsAreOpaque_Hint & fH ints; }
366
367 /// @}
368
369 ///////////////////////////////////////////////////////////////////////////
330 370
331 /** Return type for CombineIfPossible. */ 371 /** Return type for CombineIfPossible. */
332 enum CombinedState { 372 enum CombinedState {
333 /** The GrDrawStates cannot be combined. */ 373 /** The GrDrawStates cannot be combined. */
334 kIncompatible_CombinedState, 374 kIncompatible_CombinedState,
335 /** Either draw state can be used in place of the other. */ 375 /** Either draw state can be used in place of the other. */
336 kAOrB_CombinedState, 376 kAOrB_CombinedState,
337 /** Use the first draw state. */ 377 /** Use the first draw state. */
338 kA_CombinedState, 378 kA_CombinedState,
339 /** Use the second draw state. */ 379 /** Use the second draw state. */
340 kB_CombinedState, 380 kB_CombinedState,
341 }; 381 };
342 382
343 protected: 383 protected:
384 explicit GrRODrawState(const GrRODrawState& drawState) : INHERITED() {
385 fRenderTarget.reset(SkSafeRef(drawState.fRenderTarget.get()));
386 }
387
344 bool isEqual(const GrRODrawState& that) const; 388 bool isEqual(const GrRODrawState& that) const;
345 389
390 const int* getFixedFunctionVertexAttribIndices() const {
bsalomon 2014/08/28 15:05:02 If this is protected and the field it returns is p
egdaniel 2014/08/28 15:24:24 Ugh forgot to hit save when test compiling last ti
bsalomon 2014/08/28 15:47:01 Let's just keep it public for now then.
391 return fFixedFunctionVertexAttribIndices;
392 }
393
394
346 // These fields are roughly sorted by decreasing likelihood of being differe nt in op== 395 // These fields are roughly sorted by decreasing likelihood of being differe nt in op==
347 SkAutoTUnref<GrRenderTarget> fRenderTarget; 396 SkAutoTUnref<GrRenderTarget> fRenderTarget;
348 GrColor fColor; 397 GrColor fColor;
349 SkMatrix fViewMatrix; 398 SkMatrix fViewMatrix;
350 GrColor fBlendConstant; 399 GrColor fBlendConstant;
351 uint32_t fFlagBits; 400 uint32_t fFlagBits;
352 const GrVertexAttrib* fVAPtr; 401 const GrVertexAttrib* fVAPtr;
353 int fVACount; 402 int fVACount;
354 size_t fVAStride; 403 size_t fVAStride;
355 GrStencilSettings fStencilSettings; 404 GrStencilSettings fStencilSettings;
356 uint8_t fCoverage; 405 uint8_t fCoverage;
357 DrawFace fDrawFace; 406 DrawFace fDrawFace;
358 GrBlendCoeff fSrcBlend; 407 GrBlendCoeff fSrcBlend;
359 GrBlendCoeff fDstBlend; 408 GrBlendCoeff fDstBlend;
360 409
361 typedef SkSTArray<4, GrEffectStage> EffectStageArray; 410 typedef SkSTArray<4, GrEffectStage> EffectStageArray;
362 EffectStageArray fColorStages; 411 EffectStageArray fColorStages;
363 EffectStageArray fCoverageStages; 412 EffectStageArray fCoverageStages;
364 413
414 uint32_t fHints;
415
365 mutable GrBlendCoeff fOptSrcBlend; 416 mutable GrBlendCoeff fOptSrcBlend;
366 mutable GrBlendCoeff fOptDstBlend; 417 mutable GrBlendCoeff fOptDstBlend;
367 mutable BlendOptFlags fBlendOptFlags; 418 mutable BlendOptFlags fBlendOptFlags;
368 419
369 // This is simply a different representation of info in fVertexAttribs and t hus does 420 // This is simply a different representation of info in fVertexAttribs and t hus does
370 // not need to be compared in op==. 421 // not need to be compared in op==.
371 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt ]; 422 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt ];
372 423
373 private: 424 private:
425 /**
426 * Determines whether src alpha is guaranteed to be one for all src pixels
427 */
428 bool srcAlphaWillBeOne() const;
429
430 /**
431 * Helper function for getBlendOpts.
432 */
433 BlendOptFlags calcBlendOpts(bool forceCoverage = false,
434 GrBlendCoeff* srcCoeff = NULL,
435 GrBlendCoeff* dstCoeff = NULL) const;
436
374 typedef SkRefCnt INHERITED; 437 typedef SkRefCnt INHERITED;
375 }; 438 };
376 439
377 GR_MAKE_BITFIELD_OPS(GrRODrawState::BlendOptFlags); 440 GR_MAKE_BITFIELD_OPS(GrRODrawState::BlendOptFlags);
378 441
379 #endif 442 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698