aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-11-20 09:56:11 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-20 09:56:11 -0800
commitb03c4a35bd319d883925a39871b4972ff1b2c0cc (patch)
treecf06d14e7274276bc830822f6cd28140acdc811f
parent08d1fccf6eeec0a9fd5421e59e4d05daccf6e339 (diff)
Don't use NULL GrOptDrawState to indicate that draw should be skipped.
-rw-r--r--include/gpu/GrGpuResourceRef.h2
-rw-r--r--src/gpu/GrInOrderDrawBuffer.cpp6
-rw-r--r--src/gpu/GrOptDrawState.cpp53
-rw-r--r--src/gpu/GrOptDrawState.h20
-rw-r--r--tests/GLProgramsTest.cpp9
5 files changed, 37 insertions, 53 deletions
diff --git a/include/gpu/GrGpuResourceRef.h b/include/gpu/GrGpuResourceRef.h
index 3742e25195..1f7d31be94 100644
--- a/include/gpu/GrGpuResourceRef.h
+++ b/include/gpu/GrGpuResourceRef.h
@@ -186,6 +186,8 @@ public:
this->release();
}
+ operator bool() const { return SkToBool(fResource); }
+
T* get() const { return fResource; }
private:
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp
index cb44c2bb45..2f90373c33 100644
--- a/src/gpu/GrInOrderDrawBuffer.cpp
+++ b/src/gpu/GrInOrderDrawBuffer.cpp
@@ -727,9 +727,9 @@ bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds,
GrGpu::DrawType drawType,
const GrClipMaskManager::ScissorState& scissor,
const GrDeviceCoordTexture* dstCopy) {
- SkAutoTUnref<GrOptDrawState> optState(GrOptDrawState::Create(ds, fDstGpu, scissor, dstCopy,
- drawType));
- if (!optState) {
+ SkAutoTUnref<GrOptDrawState> optState(
+ SkNEW_ARGS(GrOptDrawState, (ds, fDstGpu, scissor, dstCopy, drawType)));
+ if (optState->mustSkip()) {
return false;
}
if (!fLastState || *optState != *fLastState) {
diff --git a/src/gpu/GrOptDrawState.cpp b/src/gpu/GrOptDrawState.cpp
index 4f2d24f03a..a494b171de 100644
--- a/src/gpu/GrOptDrawState.cpp
+++ b/src/gpu/GrOptDrawState.cpp
@@ -14,14 +14,35 @@
#include "GrProcOptInfo.h"
GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
- GrDrawState::BlendOpt blendOpt,
- GrBlendCoeff optSrcCoeff,
- GrBlendCoeff optDstCoeff,
GrGpu* gpu,
const ScissorState& scissorState,
const GrDeviceCoordTexture* dstCopy,
- GrGpu::DrawType drawType)
-: fRenderTarget(drawState.fRenderTarget.get()) {
+ GrGpu::DrawType drawType) {
+
+ GrBlendCoeff optSrcCoeff;
+ GrBlendCoeff optDstCoeff;
+ GrDrawState::BlendOpt blendOpt = drawState.getBlendOpt(false, &optSrcCoeff, &optDstCoeff);
+
+ // 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 (GrDrawState::kSkipDraw_BlendOpt == blendOpt && GrGpu::kStencilPath_DrawType != drawType) {
+ // Set the fields that don't default init and return. The lack of a render target will
+ // indicate that this can be skipped.
+ fFlags = 0;
+ fVAPtr = NULL;
+ fVACount = 0;
+ fVAStride = 0;
+ fDrawFace = GrDrawState::kInvalid_DrawFace;
+ fSrcBlend = kZero_GrBlendCoeff;
+ fDstBlend = kZero_GrBlendCoeff;
+ fBlendConstant = 0x0;
+ fViewMatrix.reset();
+ return;
+ }
+
+ fRenderTarget.reset(drawState.fRenderTarget.get());
+ SkASSERT(fRenderTarget);
fScissorState = scissorState;
fViewMatrix = drawState.getViewMatrix();
fBlendConstant = drawState.getBlendConstant();
@@ -106,28 +127,6 @@ GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
gpu->buildProgramDesc(*this, descInfo, drawType, &fDesc);
};
-GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState,
- GrGpu* gpu,
- const ScissorState& scissorState,
- const GrDeviceCoordTexture* dstCopy,
- GrGpu::DrawType drawType) {
- GrBlendCoeff srcCoeff;
- GrBlendCoeff dstCoeff;
- GrDrawState::BlendOpt blendOpt = drawState.getBlendOpt(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;
- }
-
- return SkNEW_ARGS(GrOptDrawState, (drawState, blendOpt, srcCoeff,
- dstCoeff, gpu, scissorState, dstCopy, drawType));
-}
-
void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds,
GrDrawState::BlendOpt blendOpt,
const GrDrawTargetCaps& caps,
diff --git a/src/gpu/GrOptDrawState.h b/src/gpu/GrOptDrawState.h
index b727cb5442..91c39a181c 100644
--- a/src/gpu/GrOptDrawState.h
+++ b/src/gpu/GrOptDrawState.h
@@ -30,15 +30,8 @@ public:
typedef GrClipMaskManager::ScissorState ScissorState;
- /**
- * Returns a snapshot of the current optimized state. The GrOptDrawState is reffed and ownership
- * is given to the caller.
- */
- static GrOptDrawState* Create(const GrDrawState& drawState,
- GrGpu*,
- const ScissorState&,
- const GrDeviceCoordTexture* dstCopy,
- GrGpu::DrawType drawType);
+ GrOptDrawState(const GrDrawState& drawState, GrGpu*, const ScissorState&,
+ const GrDeviceCoordTexture* dstCopy, GrGpu::DrawType);
bool operator== (const GrOptDrawState& that) const;
bool operator!= (const GrOptDrawState& that) const { return !(*this == that); }
@@ -182,6 +175,7 @@ public:
bool isDitherState() const { return SkToBool(fFlags & kDither_Flag); }
bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAA_Flag); }
bool isColorWriteDisabled() const { return SkToBool(fFlags & kDisableColorWrite_Flag); }
+ bool mustSkip() const { return NULL == this->getRenderTarget(); }
/// @}
@@ -202,14 +196,6 @@ public:
private:
/**
- * Constructs and optimized drawState out of a GrRODrawState.
- */
- GrOptDrawState(const GrDrawState& drawState, GrDrawState::BlendOpt,
- GrBlendCoeff optSrcCoeff, GrBlendCoeff optDstCoeff,
- GrGpu*, const ScissorState&, const GrDeviceCoordTexture* dstCopy,
- GrGpu::DrawType);
-
- /**
* Loops through all the color stage effects to check if the stage will ignore color input or
* always output a constant color. In the ignore color input case we can ignore all previous
* stages. In the constant color case, we can ignore all previous stages and
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index 83b51d6f66..7da1e72012 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -468,12 +468,9 @@ bool GrDrawTarget::programUnitTest(int maxStages) {
// create optimized draw state, setup readDst texture if required, and build a descriptor
// and program. ODS creation can fail, so we have to check
- SkAutoTUnref<GrOptDrawState> ods(GrOptDrawState::Create(ds,
- gpu,
- scissor,
- &dstCopy,
- drawType));
- if (!ods.get()) {
+ SkAutoTUnref<GrOptDrawState> ods
+ SkNEW_ARGS(GrOptDrawState, (ds, gpu, scissor, &dstCopy, drawType));
+ if (ods->mustSkip()) {
continue;
}
SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(*ods, drawType, gpu));