From 7ca217b3b2b691d09195924c0f1fa03c10e9858f Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Mon, 13 Aug 2018 11:03:08 -0400 Subject: [PATCH] avoid illegal enum values in GrGLGpu This tracks the state of the blend equation and coefficients using an out-of-band bool rather than an illegal enum value. This was caught by -fsanitize=enum. This CL doesn't change the size of fHWBlendState. Change-Id: I8dbc8aaaa07e82186c148ceb19590390051eb296 Reviewed-on: https://skia-review.googlesource.com/146962 Reviewed-by: Chris Dalton Commit-Queue: Mike Klein --- src/gpu/gl/GrGLGpu.cpp | 7 +++++-- src/gpu/gl/GrGLGpu.h | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 2df6382067..6c4ec8de1f 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -2639,9 +2639,10 @@ void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSw fHWBlendState.fEnabled = kYes_TriState; } - if (fHWBlendState.fEquation != equation) { + if (!fHWBlendState.fEquationValid || fHWBlendState.fEquation != equation) { GL_CALL(BlendEquation(gXfermodeEquation2Blend[equation])); fHWBlendState.fEquation = equation; + fHWBlendState.fEquationValid = true; } if (GrBlendEquationIsAdvanced(equation)) { @@ -2650,11 +2651,13 @@ void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSw return; } - if (fHWBlendState.fSrcCoeff != srcCoeff || fHWBlendState.fDstCoeff != dstCoeff) { + if (!fHWBlendState.fCoeffsValid || fHWBlendState.fSrcCoeff != srcCoeff + || fHWBlendState.fDstCoeff != dstCoeff) { GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], gXfermodeCoeff2Blend[dstCoeff])); fHWBlendState.fSrcCoeff = srcCoeff; fHWBlendState.fDstCoeff = dstCoeff; + fHWBlendState.fCoeffsValid = true; } if ((BlendCoeffReferencesConstant(srcCoeff) || BlendCoeffReferencesConstant(dstCoeff))) { diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index 5ac3f84e07..3e798536dc 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -558,13 +558,17 @@ private: GrBlendCoeff fSrcCoeff; GrBlendCoeff fDstCoeff; GrColor fConstColor; + + bool fEquationValid; + bool fCoeffsValid; bool fConstColorValid; + /* there's a spare byte here */ + TriState fEnabled; void invalidate() { - fEquation = static_cast(-1); - fSrcCoeff = static_cast(-1); - fDstCoeff = static_cast(-1); + fEquationValid = false; + fCoeffsValid = false; fConstColorValid = false; fEnabled = kUnknown_TriState; }