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

Unified Diff: src/gpu/GrDrawState.h

Issue 446953002: Add an opaqueness hint to GrDrawState. (Closed) Base URL: https://skia.googlesource.com/skia.git@greg
Patch Set: remove whitespace at end of line 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 side-by-side diff with in-line comments
Download patch
Index: src/gpu/GrDrawState.h
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 6603cc9665832a1068be8a352def570eb83a960b..e50d64a9028e1b239f732f1cd91731bbc3b28789 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -8,21 +8,18 @@
#ifndef GrDrawState_DEFINED
#define GrDrawState_DEFINED
-#include "GrBackendEffectFactory.h"
#include "GrBlend.h"
#include "GrColor.h"
#include "GrEffectStage.h"
-#include "GrPaint.h"
-#include "GrRenderTarget.h"
#include "GrStencil.h"
-#include "GrTemplates.h"
-#include "GrTexture.h"
-#include "GrTypesPriv.h"
#include "effects/GrSimpleTextureEffect.h"
#include "SkMatrix.h"
-#include "SkTypes.h"
-#include "SkXfermode.h"
+
+class GrDrawTargetCaps;
+class GrPaint;
+class GrRenderTarget;
+class GrTexture;
class GrDrawState : public SkRefCnt {
public:
@@ -161,6 +158,18 @@ public:
*/
bool hasSolidCoverage() const;
+ /**
+ * Depending on features available in the underlying 3D API and the color blend mode requested
+ * it may or may not be possible to correctly blend with fractional pixel coverage generated by
+ * the fragment shader.
+ *
+ * This function considers the current draw state and the draw target's capabilities to
+ * determine whether coverage can be handled correctly. This function assumes that the caller
+ * intends to specify fractional pixel coverage (via setCoverage(), through a coverage vertex
+ * attribute, or a coverage effect) but may not have specified it yet.
+ */
+ bool couldApplyCoverage(const GrDrawTargetCaps& caps) const;
+
/// @}
///////////////////////////////////////////////////////////////////////////
@@ -185,9 +194,7 @@ public:
*
* @param alpha The alpha value to set as the color.
*/
- void setAlpha(uint8_t a) {
- this->setColor((a << 24) | (a << 16) | (a << 8) | a);
- }
+ void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); }
/// @}
@@ -205,13 +212,9 @@ public:
this->invalidateBlendOptFlags();
}
- uint8_t getCoverage() const {
- return GrColorUnpackR(fCoverage);
- }
+ uint8_t getCoverage() const { return GrColorUnpackR(fCoverage); }
- GrColor getCoverageColor() const {
- return fCoverage;
- }
+ GrColor getCoverageColor() const { return fCoverage; }
/// @}
@@ -561,9 +564,7 @@ public:
*
* @param target The render target to set.
*/
- void setRenderTarget(GrRenderTarget* target) {
- fRenderTarget.reset(SkSafeRef(target));
- }
+ void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); }
/**
* Retrieves the currently set render-target.
@@ -722,29 +723,13 @@ public:
}
}
- bool isDitherState() const {
- return 0 != (fFlagBits & kDither_StateBit);
- }
-
- bool isHWAntialiasState() const {
- return 0 != (fFlagBits & kHWAntialias_StateBit);
- }
+ bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & fFlagBits); }
- bool isClipState() const {
- return 0 != (fFlagBits & kClip_StateBit);
- }
-
- bool isColorWriteDisabled() const {
- return 0 != (fFlagBits & kNoColorWrites_StateBit);
- }
-
- bool isCoverageDrawing() const {
- return 0 != (fFlagBits & kCoverageDrawing_StateBit);
- }
-
- bool isStateFlagEnabled(uint32_t stateBit) const {
- return 0 != (stateBit & fFlagBits);
- }
+ bool isDitherState() const { return 0 != (fFlagBits & kDither_StateBit); }
+ bool isHWAntialiasState() const { return 0 != (fFlagBits & kHWAntialias_StateBit); }
+ bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); }
+ bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_StateBit); }
+ bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_StateBit); }
/// @}
@@ -779,6 +764,16 @@ public:
/// @}
///////////////////////////////////////////////////////////////////////////
+ /// @name Hints
robertphillips 2014/08/06 20:29:12 More info here?
bsalomon 2014/08/08 15:00:12 Done.
+ ////
+
+ enum Hints { kVertexColorsAreOpaque_Hint = 0x1, };
+
+ void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (fHints & ~hint); }
+
+ /// @}
+
+ ///////////////////////////////////////////////////////////////////////////
/** Return type for CombineIfPossible. */
enum CombinedState {
@@ -796,7 +791,8 @@ public:
a single GrDrawState. This is used to avoid storing redundant GrDrawStates and to determine
if draws can be batched. The return value indicates whether combining is possible and, if
so, which of the two inputs should be used. */
- static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawState& b);
+ static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawState& b,
+ const GrDrawTargetCaps& caps);
GrDrawState& operator= (const GrDrawState& that);
@@ -804,8 +800,8 @@ private:
void onReset(const SkMatrix* initialViewMatrix);
BlendOptFlags calcBlendOpts(bool forceCoverage = false,
- GrBlendCoeff* srcCoeff = NULL,
- GrBlendCoeff* dstCoeff = NULL) const;
+ GrBlendCoeff* srcCoeff = NULL,
+ GrBlendCoeff* dstCoeff = NULL) const;
// These fields are roughly sorted by decreasing likelihood of being different in op==
SkAutoTUnref<GrRenderTarget> fRenderTarget;
@@ -820,10 +816,12 @@ private:
DrawFace fDrawFace;
State fState;
+
+ uint32_t fHints;
- mutable GrBlendCoeff fOptSrcBlend;
- mutable GrBlendCoeff fOptDstBlend;
- mutable BlendOptFlags fBlendOptFlags;
+ mutable GrBlendCoeff fOptSrcBlend;
+ mutable GrBlendCoeff fOptDstBlend;
+ mutable BlendOptFlags fBlendOptFlags;
// This is simply a different representation of info in fVertexAttribs and thus does
// not need to be compared in op==.

Powered by Google App Engine
This is Rietveld 408576698