revert 8265-8264 (broke build)
git-svn-id: http://skia.googlecode.com/svn/trunk@8268 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index 7982935..cd5fe1c 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -46,6 +46,28 @@
////////////////////////////////////////////////////////////////////////////////
+namespace {
+
+/**
+ * This function generates a mask that we like to have known at compile
+ * time. When the number of stages is bumped or the way bits are defined in
+ * GrDrawState.h changes this function should be rerun to generate the new mask.
+ * (We attempted to force the compiler to generate the mask using recursive
+ * templates but always wound up with static initializers under gcc, even if
+ * they were just a series of immediate->memory moves.)
+ *
+ */
+void gen_tex_coord_mask(GrAttribBindings* texCoordMask) {
+ *texCoordMask = 0;
+ for (int s = 0; s < GrDrawState::kNumStages; ++s) {
+ *texCoordMask |= GrDrawState::ExplicitTexCoordAttribBindingsBit(s);
+ }
+}
+
+const GrAttribBindings kTexCoord_AttribBindingsMask = (1 << GrDrawState::kNumStages)-1;
+
+} //unnamed namespace
+
const size_t GrDrawState::kVertexAttribSizes[kGrVertexAttribTypeCount] = {
sizeof(float), // kFloat_GrVertexAttribType
2*sizeof(float), // kVec2_GrVertexAttribType
@@ -84,7 +106,7 @@
kColor_AttribBindingsBit,
kCoverage_AttribBindingsBit,
kEdge_AttribBindingsBit,
- kLocalCoords_AttribBindingsBit,
+ kTexCoord_AttribBindingsMask
};
////////////////////////////////////////////////////////////////////////////////
@@ -188,8 +210,20 @@
return true;
}
+////////////////////////////////////////////////////////////////////////////////
+
+bool GrDrawState::AttributesBindExplicitTexCoords(GrAttribBindings attribBindings) {
+ return SkToBool(kTexCoord_AttribBindingsMask & attribBindings);
+}
+
+////////////////////////////////////////////////////////////////////////////////
void GrDrawState::VertexAttributesUnitTest() {
+ // Ensure that our tex coord mask is correct
+ GrAttribBindings texCoordMask;
+ gen_tex_coord_mask(&texCoordMask);
+ GrAssert(texCoordMask == kTexCoord_AttribBindingsMask);
+
// not necessarily exhaustive
static bool run;
if (!run) {
@@ -225,11 +259,27 @@
attribs.push_back(currAttrib);
GrAssert(4*sizeof(char) + 2*sizeof(float) + 3*sizeof(float) + sizeof(float) + 4*sizeof(float) ==
vertex_size(attribs.begin(), attribs.count()));
+
+ GrAttribBindings tcMask = 0;
+ GrAssert(!AttributesBindExplicitTexCoords(0));
+ for (int s = 0; s < GrDrawState::kNumStages; ++s) {
+ tcMask |= ExplicitTexCoordAttribBindingsBit(s);
+ GrAssert(AttributesBindExplicitTexCoords(tcMask));
+ GrAssert(StageBindsExplicitTexCoords(tcMask, s));
+ for (int s2 = s + 1; s2 < GrDrawState::kNumStages; ++s2) {
+ GrAssert(!StageBindsExplicitTexCoords(tcMask, s2));
+ }
+ }
+ GrAssert(kTexCoord_AttribBindingsMask == tcMask);
}
}
////////////////////////////////////////////////////////////////////////////////
+bool GrDrawState::StageBindsExplicitTexCoords(GrAttribBindings bindings, int stageIdx) {
+ return SkToBool(bindings & ExplicitTexCoordAttribBindingsBit(stageIdx));
+}
+
bool GrDrawState::srcAlphaWillBeOne(GrAttribBindings bindings) const {
uint32_t validComponentFlags;
@@ -450,7 +500,8 @@
}
void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState,
- const SkMatrix& preconcatMatrix) {
+ const SkMatrix& preconcatMatrix,
+ uint32_t explicitCoordStageMask) {
this->restore();
fDrawState = drawState;
@@ -462,10 +513,10 @@
fViewMatrix = drawState->getViewMatrix();
drawState->preConcatViewMatrix(preconcatMatrix);
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- if (drawState->isStageEnabled(s)) {
+ if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) {
fRestoreMask |= (1 << s);
fDrawState->fStages[s].saveCoordChange(&fSavedCoordChanges[s]);
- drawState->fStages[s].localCoordChange(preconcatMatrix);
+ drawState->fStages[s].preConcatCoordChange(preconcatMatrix);
}
}
}
@@ -484,7 +535,8 @@
fDrawState = NULL;
}
-bool GrDrawState::AutoDeviceCoordDraw::set(GrDrawState* drawState) {
+bool GrDrawState::AutoDeviceCoordDraw::set(GrDrawState* drawState,
+ uint32_t explicitCoordStageMask) {
GrAssert(NULL != drawState);
this->restore();
@@ -500,7 +552,7 @@
bool inverted = false;
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- if (drawState->isStageEnabled(s)) {
+ if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) {
if (!inverted && !fViewMatrix.invert(&invVM)) {
// sad trombone sound
fDrawState = NULL;
@@ -511,7 +563,7 @@
fRestoreMask |= (1 << s);
GrEffectStage* stage = drawState->fStages + s;
stage->saveCoordChange(&fSavedCoordChanges[s]);
- stage->localCoordChange(invVM);
+ stage->preConcatCoordChange(invVM);
}
}
drawState->viewMatrix()->reset();