aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-25 15:22:12 +0000
committerGravatar tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-25 15:22:12 +0000
commitb213ed8b767b424cb076bfbab11e936d16526635 (patch)
treed04843a79a3b46d906433633485eb4672dae164c /src
parent1807d0d0de6b5d0273fc55e19c89be1709f07180 (diff)
Simplify vertex layout bitfields by making Position-as-texcoords the
default. http://codereview.appspot.com/6337050/ git-svn-id: http://skia.googlecode.com/svn/trunk@4321 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrAAConvexPathRenderer.cpp5
-rw-r--r--src/gpu/GrAAHairLinePathRenderer.cpp6
-rw-r--r--src/gpu/GrAARectRenderer.cpp5
-rw-r--r--src/gpu/GrClipMaskManager.cpp5
-rw-r--r--src/gpu/GrContext.cpp4
-rw-r--r--src/gpu/GrDefaultPathRenderer.cpp6
-rw-r--r--src/gpu/GrDefaultTextContext.cpp11
-rw-r--r--src/gpu/GrDrawTarget.cpp55
-rw-r--r--src/gpu/GrDrawTarget.h55
-rw-r--r--src/gpu/gl/GrGLProgram.cpp18
-rw-r--r--src/gpu/gl/GrGpuGL_unittest.cpp6
11 files changed, 35 insertions, 141 deletions
diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp
index 74b26085f0..ae4a77337b 100644
--- a/src/gpu/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/GrAAConvexPathRenderer.cpp
@@ -469,11 +469,6 @@ bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath,
drawState->viewMatrix()->reset();
GrVertexLayout layout = 0;
- for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- if ((1 << s) & stageMask) {
- layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s);
- }
- }
layout |= GrDrawTarget::kEdge_VertexLayoutBit;
// We use the fact that SkPath::transform path does subdivision based on
diff --git a/src/gpu/GrAAHairLinePathRenderer.cpp b/src/gpu/GrAAHairLinePathRenderer.cpp
index 3893b9d701..2b8c7c17e5 100644
--- a/src/gpu/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/GrAAHairLinePathRenderer.cpp
@@ -521,12 +521,6 @@ bool GrAAHairLinePathRenderer::createGeom(
GrVertexLayout layout = GrDrawTarget::kEdge_VertexLayoutBit;
- for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- if ((1 << s) & stageMask) {
- layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s);
- }
- }
-
GrMatrix viewM = drawState.getViewMatrix();
PREALLOC_PTARRAY(128) lines;
diff --git a/src/gpu/GrAARectRenderer.cpp b/src/gpu/GrAARectRenderer.cpp
index 5df5efb81a..5e3a017773 100644
--- a/src/gpu/GrAARectRenderer.cpp
+++ b/src/gpu/GrAARectRenderer.cpp
@@ -16,11 +16,6 @@ namespace {
static GrVertexLayout aa_rect_layout(const GrDrawTarget* target,
bool useCoverage) {
GrVertexLayout layout = 0;
- for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- if (NULL != target->getDrawState().getTexture(s)) {
- layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s);
- }
- }
if (useCoverage) {
layout |= GrDrawTarget::kCoverage_VertexLayoutBit;
} else {
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index 6b8074329d..0c4353a3e0 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -44,11 +44,6 @@ void setup_drawstate_aaclip(GrGpu* gpu,
mat);
drawState->setTexture(maskStage, result);
-
- // The AA clipping determination happens long after the geometry has
- // been set up to draw. Here we directly enable the AA clip mask stage
- gpu->addToVertexLayout(
- GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(maskStage));
}
bool path_needs_SW_renderer(GrContext* context,
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 61f37ff2ad..a49bf99924 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -173,8 +173,6 @@ int GrContext::PaintStageVertexLayoutBits(
if ((1 << i) & stageMask) {
if (NULL != hasTexCoords && hasTexCoords[i]) {
layout |= GrDrawTarget::StageTexCoordVertexLayoutBit(i, i);
- } else {
- layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(i);
}
}
}
@@ -1574,7 +1572,7 @@ void GrContext::internalWriteRenderTargetPixels(GrRenderTarget* target,
matrix);
drawState->sampler(0)->setRAndBSwap(swapRAndB);
- GrVertexLayout layout = GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(0);
+ static const GrVertexLayout layout = 0;
static const int VCOUNT = 4;
// TODO: Use GrGpu::drawRect here
GrDrawTarget::AutoReleaseGeometry geo(fGpu, layout, VCOUNT, 0);
diff --git a/src/gpu/GrDefaultPathRenderer.cpp b/src/gpu/GrDefaultPathRenderer.cpp
index feb6a998e6..17363db560 100644
--- a/src/gpu/GrDefaultPathRenderer.cpp
+++ b/src/gpu/GrDefaultPathRenderer.cpp
@@ -208,12 +208,6 @@ bool GrDefaultPathRenderer::createGeom(const SkPath& path,
}
GrVertexLayout layout = 0;
- for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- if ((1 << s) & stageMask) {
- layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s);
- }
- }
-
bool indexed = contourCnt > 1;
int maxIdxs = 0;
diff --git a/src/gpu/GrDefaultTextContext.cpp b/src/gpu/GrDefaultTextContext.cpp
index c6f34e2c53..9530f0789f 100644
--- a/src/gpu/GrDefaultTextContext.cpp
+++ b/src/gpu/GrDefaultTextContext.cpp
@@ -138,17 +138,6 @@ void GrDefaultTextContext::init(GrContext* context,
fVertexLayout =
GrDrawTarget::kTextFormat_VertexLayoutBit |
GrDrawTarget::StageTexCoordVertexLayoutBit(kGlyphMaskStage, 0);
-
- int stageMask = paint.getActiveStageMask();
- if (stageMask) {
- for (int i = 0; i < GrPaint::kTotalStages; ++i) {
- if ((1 << i) & stageMask) {
- fVertexLayout |=
- GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(i);
- GrAssert(i != kGlyphMaskStage);
- }
- }
- }
}
void GrDefaultTextContext::finish() {
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 148dd199a3..a0517160ff 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -34,7 +34,7 @@ void gen_mask_arrays(GrVertexLayout* stageTexCoordMasks,
for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) {
stageTexCoordMasks[s] |= GrDrawTarget::StageTexCoordVertexLayoutBit(s, t);
}
- stageMasks[s] = stageTexCoordMasks[s] | GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s);
+ stageMasks[s] = stageTexCoordMasks[s];
}
for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) {
texCoordMasks[t] = 0;
@@ -83,10 +83,10 @@ const GrVertexLayout gStageTexCoordMasks[] = {
GR_STATIC_ASSERT(GrDrawState::kNumStages == GR_ARRAY_COUNT(gStageTexCoordMasks));
const GrVertexLayout gStageMasks[] = {
- 0x11111,
- 0x22222,
- 0x44444,
- 0x88888,
+ 0x1111,
+ 0x2222,
+ 0x4444,
+ 0x8888,
};
GR_STATIC_ASSERT(GrDrawState::kNumStages == GR_ARRAY_COUNT(gStageMasks));
@@ -99,6 +99,7 @@ const GrVertexLayout gTexCoordMasks[] = {
GR_STATIC_ASSERT(GrDrawState::kMaxTexCoords == GR_ARRAY_COUNT(gTexCoordMasks));
+
bool check_layout(GrVertexLayout layout) {
// can only have 1 or 0 bits set for each stage.
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
@@ -161,7 +162,8 @@ size_t GrDrawTarget::VertexSize(GrVertexLayout vertexLayout) {
int GrDrawTarget::VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout) {
GrAssert(check_layout(vertexLayout));
- if (StagePosAsTexCoordVertexLayoutBit(stage) & vertexLayout) {
+
+ if (!StageUsesTexCoords(vertexLayout, stage)) {
return 0;
}
int tcIdx = VertexTexCoordsForStage(stage, vertexLayout);
@@ -308,14 +310,9 @@ int GrDrawTarget::VertexSizeAndOffsetsByStage(
edgeOffset);
if (NULL != texCoordOffsetsByStage) {
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- int tcIdx;
- if (StagePosAsTexCoordVertexLayoutBit(s) & vertexLayout) {
- texCoordOffsetsByStage[s] = 0;
- } else if ((tcIdx = VertexTexCoordsForStage(s, vertexLayout)) >= 0) {
- texCoordOffsetsByStage[s] = texCoordOffsetsByIdx[tcIdx];
- } else {
- texCoordOffsetsByStage[s] = -1;
- }
+ int tcIdx = VertexTexCoordsForStage(s, vertexLayout);
+ texCoordOffsetsByStage[s] =
+ tcIdx < 0 ? 0 : texCoordOffsetsByIdx[tcIdx];
}
}
return size;
@@ -323,12 +320,6 @@ int GrDrawTarget::VertexSizeAndOffsetsByStage(
////////////////////////////////////////////////////////////////////////////////
-bool GrDrawTarget::VertexUsesStage(int stage, GrVertexLayout vertexLayout) {
- GrAssert(stage < GrDrawState::kNumStages);
- GrAssert(check_layout(vertexLayout));
- return !!(gStageMasks[stage] & vertexLayout);
-}
-
bool GrDrawTarget::VertexUsesTexCoordIdx(int coordIndex,
GrVertexLayout vertexLayout) {
GrAssert(coordIndex < GrDrawState::kMaxTexCoords);
@@ -373,8 +364,6 @@ void GrDrawTarget::VertexLayoutUnitTest() {
run = true;
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- GrAssert(!VertexUsesStage(s, 0));
- GrAssert(-1 == VertexStageCoordOffset(s, 0));
GrVertexLayout stageMask = 0;
for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) {
stageMask |= StageTexCoordVertexLayoutBit(s,t);
@@ -382,8 +371,6 @@ void GrDrawTarget::VertexLayoutUnitTest() {
GrAssert(1 == GrDrawState::kMaxTexCoords ||
!check_layout(stageMask));
GrAssert(gStageTexCoordMasks[s] == stageMask);
- stageMask |= StagePosAsTexCoordVertexLayoutBit(s);
- GrAssert(gStageMasks[s] == stageMask);
GrAssert(!check_layout(stageMask));
}
for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) {
@@ -391,21 +378,17 @@ void GrDrawTarget::VertexLayoutUnitTest() {
GrAssert(!VertexUsesTexCoordIdx(t, 0));
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
tcMask |= StageTexCoordVertexLayoutBit(s,t);
- GrAssert(VertexUsesStage(s, tcMask));
GrAssert(sizeof(GrPoint) == VertexStageCoordOffset(s, tcMask));
GrAssert(VertexUsesTexCoordIdx(t, tcMask));
GrAssert(2*sizeof(GrPoint) == VertexSize(tcMask));
GrAssert(t == VertexTexCoordsForStage(s, tcMask));
for (int s2 = s + 1; s2 < GrDrawState::kNumStages; ++s2) {
- GrAssert(-1 == VertexStageCoordOffset(s2, tcMask));
- GrAssert(!VertexUsesStage(s2, tcMask));
GrAssert(-1 == VertexTexCoordsForStage(s2, tcMask));
#if GR_DEBUG
- GrVertexLayout posAsTex = tcMask | StagePosAsTexCoordVertexLayoutBit(s2);
+ GrVertexLayout posAsTex = tcMask;
#endif
GrAssert(0 == VertexStageCoordOffset(s2, posAsTex));
- GrAssert(VertexUsesStage(s2, posAsTex));
GrAssert(2*sizeof(GrPoint) == VertexSize(posAsTex));
GrAssert(-1 == VertexTexCoordsForStage(s2, posAsTex));
GrAssert(-1 == VertexEdgeOffset(posAsTex));
@@ -461,7 +444,6 @@ void GrDrawTarget::VertexLayoutUnitTest() {
GrAssert(-1 == coverageOffset);
GrAssert(-1 == edgeOffset);
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- GrAssert(VertexUsesStage(s, tcMask));
GrAssert(sizeof(GrPoint) == stageOffsets[s]);
GrAssert(sizeof(GrPoint) == VertexStageCoordOffset(s, tcMask));
}
@@ -576,6 +558,10 @@ bool GrDrawTarget::reserveIndexSpace(int indexCount,
}
+bool GrDrawTarget::StageUsesTexCoords(GrVertexLayout layout, int stage) {
+ return layout & gStageTexCoordMasks[stage];
+}
+
bool GrDrawTarget::reserveVertexAndIndexSpace(GrVertexLayout vertexLayout,
int vertexCount,
int indexCount,
@@ -876,7 +862,7 @@ bool GrDrawTarget::srcAlphaWillBeOne(GrVertexLayout layout) const {
}
// Check if a color stage could create a partial alpha
for (int s = 0; s < drawState.getFirstCoverageStage(); ++s) {
- if (StageWillBeUsed(s, layout, this->getDrawState())) {
+ if (StageWillBeUsed(s, this->getDrawState())) {
GrAssert(NULL != drawState.getTexture(s));
GrPixelConfig config = drawState.getTexture(s)->config();
if (!GrPixelConfigIsOpaque(config)) {
@@ -890,9 +876,6 @@ bool GrDrawTarget::srcAlphaWillBeOne(GrVertexLayout layout) const {
namespace {
GrVertexLayout default_blend_opts_vertex_layout() {
GrVertexLayout layout = 0;
- for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s);
- }
return layout;
}
}
@@ -968,7 +951,7 @@ GrDrawTarget::getBlendOpts(bool forceCoverage,
for (int s = drawState.getFirstCoverageStage();
!hasCoverage && s < GrDrawState::kNumStages;
++s) {
- if (StageWillBeUsed(s, layout, this->getDrawState())) {
+ if (StageWillBeUsed(s, this->getDrawState())) {
hasCoverage = true;
}
}
@@ -1102,8 +1085,6 @@ GrVertexLayout GrDrawTarget::GetRectVertexLayout(StageMask stageMask,
if (NULL != srcRects && NULL != srcRects[i]) {
layout |= StageTexCoordVertexLayoutBit(i, numTC);
++numTC;
- } else {
- layout |= StagePosAsTexCoordVertexLayoutBit(i);
}
}
}
diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h
index cdc5073af6..73de1c5ee2 100644
--- a/src/gpu/GrDrawTarget.h
+++ b/src/gpu/GrDrawTarget.h
@@ -154,7 +154,7 @@ public:
* The format of vertices is represented as a bitfield of flags.
* Flags that indicate the layout of vertex data. Vertices always contain
* positions and may also contain up to GrDrawState::kMaxTexCoords sets
- * of 2D texture * coordinates, per-vertex colors, and per-vertex coverage.
+ * of 2D texture coordinates, per-vertex colors, and per-vertex coverage.
* Each stage can
* use any of the texture coordinates as its input texture coordinates or it
* may use the positions as texture coordinates.
@@ -187,42 +187,14 @@ public:
return 1 << (stage + (texCoordIdx * GrDrawState::kNumStages));
}
+ static bool StageUsesTexCoords(GrVertexLayout layout, int stage);
+
virtual void postClipPush() {};
virtual void preClipPop() {};
private:
static const int TEX_COORD_BIT_CNT = GrDrawState::kNumStages *
GrDrawState::kMaxTexCoords;
-
-public:
- /**
- * Generates a bit indicating that a texture stage uses the position
- * as its texture coordinate.
- *
- * @param stage the stage that will use position as texture
- * coordinates.
- *
- * @return the bit to add to a GrVertexLayout bitfield.
- */
- static int StagePosAsTexCoordVertexLayoutBit(int stage) {
- GrAssert(stage < GrDrawState::kNumStages);
- return (1 << (TEX_COORD_BIT_CNT + stage));
- }
-
- /**
- * Modify the existing vertex layout. Realistically the only thing that
- * can be added w/o recomputing the vertex layout is one of the
- * StagePosAsTexCoordVertexLayoutBit flags
- */
- void addToVertexLayout(int flag) {
- GrAssert((1 << TEX_COORD_BIT_CNT) == flag ||
- (1 << (TEX_COORD_BIT_CNT + 1)) == flag ||
- (1 << (TEX_COORD_BIT_CNT + 2)) == flag ||
- (1 << (TEX_COORD_BIT_CNT + 3)) == flag);
- fGeoSrcStateStack.back().fVertexLayout |= flag;
- }
-
-private:
static const int STAGE_BIT_CNT = TEX_COORD_BIT_CNT +
GrDrawState::kNumStages;
@@ -765,18 +737,6 @@ public:
GrVertexLayout vertexLayout);
/**
- * Helper function to determine if vertex layout contains either explicit or
- * implicit texture coordinates for a stage.
- *
- * @param stage the stage to query
- * @param vertexLayout layout to query
- *
- * @return true if vertex specifies texture coordinates for the stage,
- * false otherwise.
- */
- static bool VertexUsesStage(int stage, GrVertexLayout vertexLayout);
-
- /**
* Helper function to compute the size of each vertex and the offsets of
* texture coordinates and color. Determines tex coord offsets by tex coord
* index rather than by stage. (Each stage can be mapped to any t.c. index
@@ -992,15 +952,14 @@ protected:
return 0;
}
}
- // given a vertex layout and a draw state, will a stage be used?
- static bool StageWillBeUsed(int stage, GrVertexLayout layout,
+ // given (a vertex layout and) a draw state, will a stage be used?
+ static bool StageWillBeUsed(int stage,
const GrDrawState& state) {
- return NULL != state.getTexture(stage) &&
- VertexUsesStage(stage, layout);
+ return NULL != state.getTexture(stage);
}
bool isStageEnabled(int stage) const {
- return StageWillBeUsed(stage, this->getVertexLayout(),
+ return StageWillBeUsed(stage,
this->getDrawState());
}
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index f16812b54d..8b8a9549de 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -592,13 +592,11 @@ bool GrGLProgram::genProgram(const GrGLContextInfo& gl,
const char* inCoords;
// figure out what our input coords are
- if (GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s) &
- layout) {
+ int tcIdx = GrDrawTarget::VertexTexCoordsForStage(s, layout);
+ if (tcIdx < 0) {
inCoords = POS_ATTR_NAME;
} else {
- int tcIdx = GrDrawTarget::VertexTexCoordsForStage(s, layout);
- // we better have input tex coordinates if stage is enabled.
- GrAssert(tcIdx >= 0);
+ // must have input tex coordinates if stage is enabled.
GrAssert(texCoordAttrs[tcIdx].size());
inCoords = texCoordAttrs[tcIdx].c_str();
}
@@ -713,15 +711,13 @@ bool GrGLProgram::genProgram(const GrGLContextInfo& gl,
const char* inCoords;
// figure out what our input coords are
- if (GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s) &
- layout) {
+ int tcIdx =
+ GrDrawTarget::VertexTexCoordsForStage(s, layout);
+ if (tcIdx < 0) {
inCoords = POS_ATTR_NAME;
} else {
- int tcIdx =
- GrDrawTarget::VertexTexCoordsForStage(s, layout);
- // we better have input tex coordinates if stage is
+ // must have input tex coordinates if stage is
// enabled.
- GrAssert(tcIdx >= 0);
GrAssert(texCoordAttrs[tcIdx].size());
inCoords = texCoordAttrs[tcIdx].c_str();
}
diff --git a/src/gpu/gl/GrGpuGL_unittest.cpp b/src/gpu/gl/GrGpuGL_unittest.cpp
index 9dbb708e1b..5845919f49 100644
--- a/src/gpu/gl/GrGpuGL_unittest.cpp
+++ b/src/gpu/gl/GrGpuGL_unittest.cpp
@@ -185,27 +185,25 @@ bool GrGpuGL::programUnitTest() {
SkAutoTUnref<GrCustomStage> customStages[GrDrawState::kNumStages];
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
+ StageDesc& stage = pdesc.fStages[s];
// enable the stage?
if (random_bool(&random)) {
// use separate tex coords?
if (random_bool(&random)) {
int t = random_int(&random, GrDrawState::kMaxTexCoords);
pdesc.fVertexLayout |= StageTexCoordVertexLayoutBit(s, t);
- } else {
- pdesc.fVertexLayout |= StagePosAsTexCoordVertexLayoutBit(s);
}
+ stage.setEnabled(true);
}
// use text-formatted verts?
if (random_bool(&random)) {
pdesc.fVertexLayout |= kTextFormat_VertexLayoutBit;
}
- StageDesc& stage = pdesc.fStages[s];
stage.fCustomStageKey = 0;
stage.fOptFlags = STAGE_OPTS[random_int(&random, GR_ARRAY_COUNT(STAGE_OPTS))];
stage.fInConfigFlags = IN_CONFIG_FLAGS[random_int(&random, GR_ARRAY_COUNT(IN_CONFIG_FLAGS))];
- stage.setEnabled(VertexUsesStage(s, pdesc.fVertexLayout));
bool useCustomEffect = random_bool(&random);
if (useCustomEffect) {