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
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;
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 {
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,
if ((1 << i) & stageMask) {
if (NULL != hasTexCoords && hasTexCoords[i]) {
layout |= GrDrawTarget::StageTexCoordVertexLayoutBit(i, i);
- } else {
- layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(i);
}
}
}
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);
}
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;
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() {
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;
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));
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) {
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);
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;
////////////////////////////////////////////////////////////////////////////////
-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);
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);
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) {
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));
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));
}
}
+bool GrDrawTarget::StageUsesTexCoords(GrVertexLayout layout, int stage) {
+ return layout & gStageTexCoordMasks[stage];
+}
+
bool GrDrawTarget::reserveVertexAndIndexSpace(GrVertexLayout vertexLayout,
int vertexCount,
int indexCount,
}
// 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)) {
namespace {
GrVertexLayout default_blend_opts_vertex_layout() {
GrVertexLayout layout = 0;
- for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s);
- }
return layout;
}
}
for (int s = drawState.getFirstCoverageStage();
!hasCoverage && s < GrDrawState::kNumStages;
++s) {
- if (StageWillBeUsed(s, layout, this->getDrawState())) {
+ if (StageWillBeUsed(s, this->getDrawState())) {
hasCoverage = true;
}
}
if (NULL != srcRects && NULL != srcRects[i]) {
layout |= StageTexCoordVertexLayoutBit(i, numTC);
++numTC;
- } else {
- layout |= StagePosAsTexCoordVertexLayoutBit(i);
}
}
}
* 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.
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;
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
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());
}
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();
}
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();
}
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) {