aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar egdaniel <egdaniel@google.com>2014-10-07 06:45:44 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-07 06:45:44 -0700
commitb109ac22b4ec3ab3478f5304c96564a0e9df6170 (patch)
treeab4863db8b3307133d48bbffa707b9546061ebcc /src
parentd3ce6b44e582c1a4c73a90b4314a387db8624ca2 (diff)
Make createOptDrawState return NULL if we would end up not drawing
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrDrawState.cpp23
-rw-r--r--src/gpu/GrDrawState.h12
-rw-r--r--src/gpu/GrOptDrawState.cpp37
-rw-r--r--src/gpu/GrOptDrawState.h20
-rw-r--r--src/gpu/gl/GrGpuGL_program.cpp16
5 files changed, 71 insertions, 37 deletions
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index b4cf9c8b41..f967a6fa76 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -12,29 +12,6 @@
//////////////////////////////////////////////////////////////////////////////s
-GrOptDrawState* GrDrawState::createOptState(const GrDrawTargetCaps& caps) const {
- if (NULL == fCachedOptState || caps.getUniqueID() != fCachedCapsID) {
- GrBlendCoeff srcCoeff;
- GrBlendCoeff dstCoeff;
- GrOptDrawState::BlendOptFlags blendFlags =
- (GrOptDrawState::BlendOptFlags) this->getBlendOpts(false, &srcCoeff, &dstCoeff);
- fCachedOptState = SkNEW_ARGS(GrOptDrawState, (*this, blendFlags, srcCoeff, dstCoeff, caps));
- fCachedCapsID = caps.getUniqueID();
- } else {
-#ifdef SK_DEBUG
- GrBlendCoeff srcCoeff;
- GrBlendCoeff dstCoeff;
- GrOptDrawState::BlendOptFlags blendFlags =
- (GrOptDrawState::BlendOptFlags) this->getBlendOpts(false, &srcCoeff, &dstCoeff);
- SkASSERT(GrOptDrawState(*this, blendFlags, srcCoeff, dstCoeff, caps) == *fCachedOptState);
-#endif
- }
- fCachedOptState->ref();
- return fCachedOptState;
-}
-
-//////////////////////////////////////////////////////////////////////////////s
-
bool GrDrawState::isEqual(const GrDrawState& that) const {
bool usingVertexColors = this->hasColorVertexAttribute();
if (!usingVertexColors && this->fColor != that.fColor) {
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index b855c8725b..9d653e6f5c 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -715,14 +715,6 @@ public:
GrDrawState& operator= (const GrDrawState& that);
- /**
- * Returns a snapshot of the current optimized state. If the current drawState has a valid
- * cached optimiezed state it will simply return a pointer to it otherwise it will create a new
- * GrOptDrawState. In all cases the GrOptDrawState is reffed and ownership is given to the
- * caller.
- */
- GrOptDrawState* createOptState(const GrDrawTargetCaps&) const;
-
private:
/**
* Converts refs on GrGpuResources owned directly or indirectly by this GrDrawState into
@@ -829,9 +821,11 @@ private:
mutable GrOptDrawState* fCachedOptState;
mutable uint32_t fCachedCapsID;
+ friend class GrOptDrawState;
+
typedef SkRefCnt INHERITED;
};
-//GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags);
+GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags);
#endif
diff --git a/src/gpu/GrOptDrawState.cpp b/src/gpu/GrOptDrawState.cpp
index 6a79203d1a..802713e21b 100644
--- a/src/gpu/GrOptDrawState.cpp
+++ b/src/gpu/GrOptDrawState.cpp
@@ -9,7 +9,6 @@
#include "GrDrawState.h"
#include "GrDrawTargetCaps.h"
-#include "GrGpu.h"
GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
BlendOptFlags blendOptFlags,
@@ -53,6 +52,42 @@ GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
this->setOutputStateInfo(caps);
};
+GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState, const GrDrawTargetCaps& caps,
+ GrGpu::DrawType drawType) {
+ if (NULL == drawState.fCachedOptState || caps.getUniqueID() != drawState.fCachedCapsID) {
+ GrBlendCoeff srcCoeff;
+ GrBlendCoeff dstCoeff;
+ BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
+ &srcCoeff,
+ &dstCoeff);
+
+ // If our blend coeffs are set to 0,1 we know we will not end up drawing unless we are
+ // stenciling. When path rendering the stencil settings are not always set on the draw state
+ // so we must check the draw type. In cases where we will skip drawing we simply return a
+ // null GrOptDrawState.
+ if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff &&
+ !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != drawType) {
+ return NULL;
+ }
+
+ drawState.fCachedOptState = SkNEW_ARGS(GrOptDrawState, (drawState, blendFlags, srcCoeff,
+ dstCoeff, caps));
+ drawState.fCachedCapsID = caps.getUniqueID();
+ } else {
+#ifdef SK_DEBUG
+ GrBlendCoeff srcCoeff;
+ GrBlendCoeff dstCoeff;
+ BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
+ &srcCoeff,
+ &dstCoeff);
+ SkASSERT(GrOptDrawState(drawState, blendFlags, srcCoeff, dstCoeff, caps) ==
+ *drawState.fCachedOptState);
+#endif
+ }
+ drawState.fCachedOptState->ref();
+ return drawState.fCachedOptState;
+}
+
void GrOptDrawState::setOutputStateInfo(const GrDrawTargetCaps& caps) {
// Set this default and then possibly change our mind if there is coverage.
fPrimaryOutputType = kModulate_PrimaryOutputType;
diff --git a/src/gpu/GrOptDrawState.h b/src/gpu/GrOptDrawState.h
index f0a726e954..1f8c442230 100644
--- a/src/gpu/GrOptDrawState.h
+++ b/src/gpu/GrOptDrawState.h
@@ -8,7 +8,15 @@
#ifndef GrOptDrawState_DEFINED
#define GrOptDrawState_DEFINED
-#include "GrDrawState.h"
+#include "GrColor.h"
+#include "GrGpu.h"
+#include "GrProcessorStage.h"
+#include "GrStencil.h"
+#include "GrTypesPriv.h"
+#include "SkMatrix.h"
+#include "SkRefCnt.h"
+
+class GrDrawState;
/**
* Class that holds an optimized version of a GrDrawState. It is meant to be an immutable class,
@@ -16,6 +24,15 @@
*/
class GrOptDrawState : public SkRefCnt {
public:
+ /**
+ * Returns a snapshot of the current optimized state. If the current drawState has a valid
+ * cached optimiezed state it will simply return a pointer to it otherwise it will create a new
+ * GrOptDrawState. In all cases the GrOptDrawState is reffed and ownership is given to the
+ * caller.
+ */
+ static GrOptDrawState* Create(const GrDrawState& drawState, const GrDrawTargetCaps& caps,
+ GrGpu::DrawType drawType);
+
bool operator== (const GrOptDrawState& that) const;
///////////////////////////////////////////////////////////////////////////
@@ -443,7 +460,6 @@ private:
PrimaryOutputType fPrimaryOutputType : 8;
SecondaryOutputType fSecondaryOutputType : 8;
- friend GrOptDrawState* GrDrawState::createOptState(const GrDrawTargetCaps&) const;
typedef SkRefCnt INHERITED;
};
diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp
index 363d87fbfb..4529a1c22e 100644
--- a/src/gpu/gl/GrGpuGL_program.cpp
+++ b/src/gpu/gl/GrGpuGL_program.cpp
@@ -206,7 +206,13 @@ GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrOptDrawState& optState,
#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstCopy) {
- SkAutoTUnref<GrOptDrawState> optState(this->getDrawState().createOptState(*this->caps()));
+ SkAutoTUnref<GrOptDrawState> optState(GrOptDrawState::Create(this->getDrawState(),
+ *this->caps(),
+ type));
+
+ if (!optState) {
+ return false;
+ }
// GrGpu::setupClipAndFlushState should have already checked this and bailed if not true.
SkASSERT(optState->getRenderTarget());
@@ -294,7 +300,13 @@ bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstC
}
void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) {
- SkAutoTUnref<GrOptDrawState> optState(this->getDrawState().createOptState(*this->caps()));
+ SkAutoTUnref<GrOptDrawState> optState(
+ GrOptDrawState::Create(this->getDrawState(), *this->caps(),
+ PrimTypeToDrawType(info.primitiveType())));
+
+ // If the optState would is NULL it should have been caught in flushGraphicsState before getting
+ // here.
+ SkASSERT(optState);
GrGLsizei stride = static_cast<GrGLsizei>(optState->getVertexStride());