context->getTestTarget(&tt);
SkASSERT(NULL != tt.target());
GrDrawState* drawState = tt.target()->drawState();
- drawState->setVertexAttribs<kAttribs>(2);
+ drawState->setVertexAttribs<kAttribs>(2, sizeof(Vertex));
drawState->addCoverageEffect(effect, 1);
drawState->setRenderTarget(rt);
context->getTestTarget(&tt);
SkASSERT(NULL != tt.target());
GrDrawState* drawState = tt.target()->drawState();
- drawState->setVertexAttribs<kAttribs>(2);
+ drawState->setVertexAttribs<kAttribs>(2, sizeof(Vertex));
drawState->addCoverageEffect(effect, 1);
drawState->setRenderTarget(rt);
context->getTestTarget(&tt);
SkASSERT(NULL != tt.target());
GrDrawState* drawState = tt.target()->drawState();
- drawState->setVertexAttribs<kAttribs>(2);
+ drawState->setVertexAttribs<kAttribs>(2, sizeof(Vertex));
drawState->addCoverageEffect(effect, 1);
drawState->setRenderTarget(rt);
return;
}
GrDrawState* drawState = tt.target()->drawState();
- drawState->setVertexAttribs<kAttribs>(SK_ARRAY_COUNT(kAttribs));
+ drawState->setVertexAttribs<kAttribs>(SK_ARRAY_COUNT(kAttribs), sizeof(SkPoint));
SkMatrix m;
SkPath p;
}
GrDrawState* drawState = tt.target()->drawState();
- drawState->setVertexAttribs<kAttribs>(SK_ARRAY_COUNT(kAttribs));
+ drawState->setVertexAttribs<kAttribs>(SK_ARRAY_COUNT(kAttribs), sizeof(SkPoint));
drawState->addCoverageEffect(effect, 1);
drawState->setIdentityViewMatrix();
drawState->setRenderTarget(rt);
// Our computed verts should all be within one pixel of the segment control points.
devBounds.outset(SK_Scalar1, SK_Scalar1);
- drawState->setVertexAttribs<gPathAttribs>(SK_ARRAY_COUNT(gPathAttribs));
+ drawState->setVertexAttribs<gPathAttribs>(SK_ARRAY_COUNT(gPathAttribs), sizeof(QuadVertex));
static const int kEdgeAttrIndex = 1;
GrEffect* quadEffect = QuadEdgeEffect::Create();
if (!arg.succeeded()) {
return false;
}
- SkASSERT(sizeof(QuadVertex) == drawState->getVertexSize());
verts = reinterpret_cast<QuadVertex*>(arg.vertices());
idxs = reinterpret_cast<uint16_t*>(arg.indices());
int vertCnt = kVertsPerLineSeg * lineCnt;
- drawState->setVertexAttribs<gHairlineLineAttribs>(SK_ARRAY_COUNT(gHairlineLineAttribs));
- SkASSERT(sizeof(LineVertex) == drawState->getVertexSize());
+ drawState->setVertexAttribs<gHairlineLineAttribs>(SK_ARRAY_COUNT(gHairlineLineAttribs),
+ sizeof(LineVertex));
if (!arg->set(target, vertCnt, 0)) {
return false;
int vertCnt = kVertsPerQuad * quadCnt + kVertsPerQuad * conicCnt;
- target->drawState()->setVertexAttribs<gHairlineBezierAttribs>(SK_ARRAY_COUNT(gHairlineBezierAttribs));
- SkASSERT(sizeof(BezierVertex) == target->getDrawState().getVertexSize());
+ int vAttribCnt = SK_ARRAY_COUNT(gHairlineBezierAttribs);
+ target->drawState()->setVertexAttribs<gHairlineBezierAttribs>(vAttribCnt, sizeof(BezierVertex));
if (!arg->set(target, vertCnt, 0)) {
return false;
static CoverageAttribType set_rect_attribs(GrDrawState* drawState) {
if (drawState->canTweakAlphaForCoverage()) {
- drawState->setVertexAttribs<gAARectAttribs>(2);
+ drawState->setVertexAttribs<gAARectAttribs>(2, sizeof(SkPoint) + sizeof(SkColor));
return kUseColor_CoverageAttribType;
} else {
- drawState->setVertexAttribs<gAARectAttribs>(3);
+ drawState->setVertexAttribs<gAARectAttribs>(3, sizeof(SkPoint) + 2 * sizeof(SkColor));
return kUseCoverage_CoverageAttribType;
}
}
}
intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
- size_t vsize = drawState->getVertexSize();
+ size_t vstride = drawState->getVertexStride();
SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts);
- SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vsize);
+ SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vstride);
SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1);
inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height());
combinedMatrix.mapRect(&devRect, rect);
#endif
- set_inset_fan(fan0Pos, vsize, devRect, -SK_ScalarHalf, -SK_ScalarHalf);
- set_inset_fan(fan1Pos, vsize, devRect, inset, inset);
+ set_inset_fan(fan0Pos, vstride, devRect, -SK_ScalarHalf, -SK_ScalarHalf);
+ set_inset_fan(fan1Pos, vstride, devRect, inset, inset);
} else {
// compute transformed (1, 0) and (0, 1) vectors
SkVector vec[2] = {
// create the rotated rect
fan0Pos->setRectFan(rect.fLeft, rect.fTop,
- rect.fRight, rect.fBottom, vsize);
- combinedMatrix.mapPointsWithStride(fan0Pos, vsize, 4);
+ rect.fRight, rect.fBottom, vstride);
+ combinedMatrix.mapPointsWithStride(fan0Pos, vstride, 4);
// Now create the inset points and then outset the original
// rotated points
// TL
- *((SkPoint*)((intptr_t)fan1Pos + 0 * vsize)) =
- *((SkPoint*)((intptr_t)fan0Pos + 0 * vsize)) + vec[0] + vec[1];
- *((SkPoint*)((intptr_t)fan0Pos + 0 * vsize)) -= vec[0] + vec[1];
+ *((SkPoint*)((intptr_t)fan1Pos + 0 * vstride)) =
+ *((SkPoint*)((intptr_t)fan0Pos + 0 * vstride)) + vec[0] + vec[1];
+ *((SkPoint*)((intptr_t)fan0Pos + 0 * vstride)) -= vec[0] + vec[1];
// BL
- *((SkPoint*)((intptr_t)fan1Pos + 1 * vsize)) =
- *((SkPoint*)((intptr_t)fan0Pos + 1 * vsize)) + vec[0] - vec[1];
- *((SkPoint*)((intptr_t)fan0Pos + 1 * vsize)) -= vec[0] - vec[1];
+ *((SkPoint*)((intptr_t)fan1Pos + 1 * vstride)) =
+ *((SkPoint*)((intptr_t)fan0Pos + 1 * vstride)) + vec[0] - vec[1];
+ *((SkPoint*)((intptr_t)fan0Pos + 1 * vstride)) -= vec[0] - vec[1];
// BR
- *((SkPoint*)((intptr_t)fan1Pos + 2 * vsize)) =
- *((SkPoint*)((intptr_t)fan0Pos + 2 * vsize)) - vec[0] - vec[1];
- *((SkPoint*)((intptr_t)fan0Pos + 2 * vsize)) += vec[0] + vec[1];
+ *((SkPoint*)((intptr_t)fan1Pos + 2 * vstride)) =
+ *((SkPoint*)((intptr_t)fan0Pos + 2 * vstride)) - vec[0] - vec[1];
+ *((SkPoint*)((intptr_t)fan0Pos + 2 * vstride)) += vec[0] + vec[1];
// TR
- *((SkPoint*)((intptr_t)fan1Pos + 3 * vsize)) =
- *((SkPoint*)((intptr_t)fan0Pos + 3 * vsize)) - vec[0] + vec[1];
- *((SkPoint*)((intptr_t)fan0Pos + 3 * vsize)) += vec[0] - vec[1];
+ *((SkPoint*)((intptr_t)fan1Pos + 3 * vstride)) =
+ *((SkPoint*)((intptr_t)fan0Pos + 3 * vstride)) - vec[0] + vec[1];
+ *((SkPoint*)((intptr_t)fan0Pos + 3 * vstride)) += vec[0] - vec[1];
}
// Make verts point to vertex color and then set all the color and coverage vertex attrs values.
verts += sizeof(SkPoint);
for (int i = 0; i < 4; ++i) {
if (kUseCoverage_CoverageAttribType == covAttribType) {
- *reinterpret_cast<GrColor*>(verts + i * vsize) = color;
- *reinterpret_cast<GrColor*>(verts + i * vsize + sizeof(GrColor)) = 0;
+ *reinterpret_cast<GrColor*>(verts + i * vstride) = color;
+ *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) = 0;
} else {
- *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
+ *reinterpret_cast<GrColor*>(verts + i * vstride) = 0;
}
}
} else {
innerCoverage = (0xff == scale) ? color : SkAlphaMulQ(color, scale);
}
- verts += 4 * vsize;
+ verts += 4 * vstride;
for (int i = 0; i < 4; ++i) {
if (kUseCoverage_CoverageAttribType == covAttribType) {
- *reinterpret_cast<GrColor*>(verts + i * vsize) = color;
- *reinterpret_cast<GrColor*>(verts + i * vsize + sizeof(GrColor)) = innerCoverage;
+ *reinterpret_cast<GrColor*>(verts + i * vstride) = color;
+ *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) = innerCoverage;
} else {
- *reinterpret_cast<GrColor*>(verts + i * vsize) = innerCoverage;
+ *reinterpret_cast<GrColor*>(verts + i * vstride) = innerCoverage;
}
}
SkScalar newWidth = SkScalarHalf(rect.width() * vec[0].length()) + SK_ScalarHalf;
SkScalar newHeight = SkScalarHalf(rect.height() * vec[1].length()) + SK_ScalarHalf;
- drawState->setVertexAttribs<gAARectVertexAttribs>(SK_ARRAY_COUNT(gAARectVertexAttribs));
- SkASSERT(sizeof(RectVertex) == drawState->getVertexSize());
+ drawState->setVertexAttribs<gAARectVertexAttribs>(SK_ARRAY_COUNT(gAARectVertexAttribs),
+ sizeof(RectVertex));
GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);
if (!geo.succeeded()) {
GrDrawState* drawState = target->drawState();
SkASSERT(combinedMatrix.rectStaysRect());
- drawState->setVertexAttribs<gAAAARectVertexAttribs>(SK_ARRAY_COUNT(gAAAARectVertexAttribs));
- SkASSERT(sizeof(AARectVertex) == drawState->getVertexSize());
+ drawState->setVertexAttribs<gAAAARectVertexAttribs>(SK_ARRAY_COUNT(gAAAARectVertexAttribs),
+ sizeof(AARectVertex));
GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);
if (!geo.succeeded()) {
}
intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
- size_t vsize = drawState->getVertexSize();
+ size_t vstride = drawState->getVertexStride();
// We create vertices for four nested rectangles. There are two ramps from 0 to full
// coverage, one on the exterior of the stroke and the other on the interior.
// The following pointers refer to the four rects, from outermost to innermost.
SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts);
- SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + outerVertexNum * vsize);
- SkPoint* fan2Pos = reinterpret_cast<SkPoint*>(verts + 2 * outerVertexNum * vsize);
- SkPoint* fan3Pos = reinterpret_cast<SkPoint*>(verts + (2 * outerVertexNum + innerVertexNum) * vsize);
+ SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + outerVertexNum * vstride);
+ SkPoint* fan2Pos = reinterpret_cast<SkPoint*>(verts + 2 * outerVertexNum * vstride);
+ SkPoint* fan3Pos = reinterpret_cast<SkPoint*>(verts + (2 * outerVertexNum + innerVertexNum) * vstride);
#ifndef SK_IGNORE_THIN_STROKED_RECT_FIX
// TODO: this only really works if the X & Y margins are the same all around
if (miterStroke) {
// outermost
- set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf);
+ set_inset_fan(fan0Pos, vstride, devOutside, -SK_ScalarHalf, -SK_ScalarHalf);
// inner two
- set_inset_fan(fan1Pos, vsize, devOutside, inset, inset);
- set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset);
+ set_inset_fan(fan1Pos, vstride, devOutside, inset, inset);
+ set_inset_fan(fan2Pos, vstride, devInside, -inset, -inset);
// innermost
- set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf);
+ set_inset_fan(fan3Pos, vstride, devInside, SK_ScalarHalf, SK_ScalarHalf);
} else {
- SkPoint* fan0AssistPos = reinterpret_cast<SkPoint*>(verts + 4 * vsize);
- SkPoint* fan1AssistPos = reinterpret_cast<SkPoint*>(verts + (outerVertexNum + 4) * vsize);
+ SkPoint* fan0AssistPos = reinterpret_cast<SkPoint*>(verts + 4 * vstride);
+ SkPoint* fan1AssistPos = reinterpret_cast<SkPoint*>(verts + (outerVertexNum + 4) * vstride);
// outermost
- set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf);
- set_inset_fan(fan0AssistPos, vsize, devOutsideAssist, -SK_ScalarHalf, -SK_ScalarHalf);
+ set_inset_fan(fan0Pos, vstride, devOutside, -SK_ScalarHalf, -SK_ScalarHalf);
+ set_inset_fan(fan0AssistPos, vstride, devOutsideAssist, -SK_ScalarHalf, -SK_ScalarHalf);
// outer one of the inner two
- set_inset_fan(fan1Pos, vsize, devOutside, inset, inset);
- set_inset_fan(fan1AssistPos, vsize, devOutsideAssist, inset, inset);
+ set_inset_fan(fan1Pos, vstride, devOutside, inset, inset);
+ set_inset_fan(fan1AssistPos, vstride, devOutsideAssist, inset, inset);
// inner one of the inner two
- set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset);
+ set_inset_fan(fan2Pos, vstride, devInside, -inset, -inset);
// innermost
- set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf);
+ set_inset_fan(fan3Pos, vstride, devInside, SK_ScalarHalf, SK_ScalarHalf);
}
// Make verts point to vertex color and then set all the color and coverage vertex attrs values.
verts += sizeof(SkPoint);
for (int i = 0; i < outerVertexNum; ++i) {
if (kUseCoverage_CoverageAttribType == covAttribType) {
- *reinterpret_cast<GrColor*>(verts + i * vsize) = color;
- *reinterpret_cast<GrColor*>(verts + i * vsize + sizeof(GrColor)) = 0;
+ *reinterpret_cast<GrColor*>(verts + i * vstride) = color;
+ *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) = 0;
} else {
- *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
+ *reinterpret_cast<GrColor*>(verts + i * vstride) = 0;
}
}
scale = 0xff;
}
- verts += outerVertexNum * vsize;
+ verts += outerVertexNum * vstride;
GrColor innerCoverage;
if (kUseCoverage_CoverageAttribType == covAttribType) {
innerCoverage = GrColorPackRGBA(scale, scale, scale, scale);
for (int i = 0; i < outerVertexNum + innerVertexNum; ++i) {
if (kUseCoverage_CoverageAttribType == covAttribType) {
- *reinterpret_cast<GrColor*>(verts + i * vsize) = color;
- *reinterpret_cast<GrColor*>(verts + i * vsize + sizeof(GrColor)) = innerCoverage;
+ *reinterpret_cast<GrColor*>(verts + i * vstride) = color;
+ *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) = innerCoverage;
} else {
- *reinterpret_cast<GrColor*>(verts + i * vsize) = innerCoverage;
+ *reinterpret_cast<GrColor*>(verts + i * vstride) = innerCoverage;
}
}
// The innermost rect has 0 coverage
- verts += (outerVertexNum + innerVertexNum) * vsize;
+ verts += (outerVertexNum + innerVertexNum) * vstride;
for (int i = 0; i < innerVertexNum; ++i) {
if (kUseCoverage_CoverageAttribType == covAttribType) {
- *reinterpret_cast<GrColor*>(verts + i * vsize) = color;
- *reinterpret_cast<GrColor*>(verts + i * vsize + sizeof(GrColor)) = 0;
+ *reinterpret_cast<GrColor*>(verts + i * vstride) = color;
+ *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) = 0;
} else {
- *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
+ *reinterpret_cast<GrColor*>(verts + i * vstride) = 0;
}
}
{kVec2f_GrVertexAttribType, sizeof(SkPoint) , kEffect_GrVertexAttribBinding}
};
+static const size_t kTextVASize = 2 * sizeof(SkPoint);
+
// position + color + texture coord
extern const GrVertexAttrib gTextVertexWithColorAttribs[] = {
{kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
{kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVertexAttribBinding}
};
+static const size_t kTextVAColorSize = 2 * sizeof(SkPoint) + sizeof(GrColor);
+
};
GrBitmapTextContext::GrBitmapTextContext(GrContext* context,
bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat();
if (useColorVerts) {
fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>(
- SK_ARRAY_COUNT(gTextVertexWithColorAttribs));
+ SK_ARRAY_COUNT(gTextVertexWithColorAttribs),
+ kTextVAColorSize);
} else {
fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
- SK_ARRAY_COUNT(gTextVertexAttribs));
+ SK_ARRAY_COUNT(gTextVertexAttribs),
+ kTextVASize);
}
fVertexCount = 4*fSkPaint.textToGlyphs(text, byteLength, NULL);
bool success = fDrawTarget->reserveVertexAndIndexSpace(fVertexCount,
size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) :
(2 * sizeof(SkPoint));
- SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexSize());
+ SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexStride());
SkPoint* positions = reinterpret_cast<SkPoint*>(
reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex);
GrTextureParams::kNone_FilterMode);
drawState->addColorTextureEffect(clampedTexture, SkMatrix::I(), params);
- drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttribs));
+ drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttribs),
+ 2 * sizeof(SkPoint));
GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0);
{kVec4ub_GrVertexAttribType, 2*sizeof(SkPoint), kColor_GrVertexAttribBinding}
};
+static const size_t kPosUVAttribsSize = 2 * sizeof(SkPoint);
+static const size_t kPosUVColorAttribsSize = 2 * sizeof(SkPoint) + sizeof(GrColor);
+
extern const GrVertexAttrib gPosColorAttribs[] = {
{kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
{kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVertexAttribBinding},
};
+static const size_t kPosAttribsSize = sizeof(SkPoint);
+static const size_t kPosColorAttribsSize = sizeof(SkPoint) + sizeof(GrColor);
+
static void set_vertex_attributes(GrDrawState* drawState,
const SkPoint* texCoords,
const GrColor* colors,
if (NULL != texCoords && NULL != colors) {
*texOffset = sizeof(SkPoint);
*colorOffset = 2*sizeof(SkPoint);
- drawState->setVertexAttribs<gPosUVColorAttribs>(3);
+ drawState->setVertexAttribs<gPosUVColorAttribs>(3, kPosUVColorAttribsSize);
} else if (NULL != texCoords) {
*texOffset = sizeof(SkPoint);
- drawState->setVertexAttribs<gPosUVColorAttribs>(2);
+ drawState->setVertexAttribs<gPosUVColorAttribs>(2, kPosUVAttribsSize);
} else if (NULL != colors) {
*colorOffset = sizeof(SkPoint);
- drawState->setVertexAttribs<gPosColorAttribs>(2);
+ drawState->setVertexAttribs<gPosColorAttribs>(2, kPosColorAttribsSize);
} else {
- drawState->setVertexAttribs<gPosColorAttribs>(1);
+ drawState->setVertexAttribs<gPosColorAttribs>(1, kPosAttribsSize);
}
}
int colorOffset = -1, texOffset = -1;
set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset);
- size_t vertexSize = drawState->getVertexSize();
- if (sizeof(SkPoint) != vertexSize) {
+ size_t VertexStride = drawState->getVertexStride();
+ if (sizeof(SkPoint) != VertexStride) {
if (!geo.set(target, vertexCount, 0)) {
GrPrintf("Failed to get space for vertices!\n");
return;
if (colorOffset >= 0) {
*(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i];
}
- curVertex = (void*)((intptr_t)curVertex + vertexSize);
+ curVertex = (void*)((intptr_t)curVertex + VertexStride);
}
} else {
target->setVertexSourceToArray(positions, vertexCount);
{kVec2f_GrVertexAttribType, sizeof(SkPoint) , kEffect_GrVertexAttribBinding}
};
+static const size_t kTextVASize = 2 * sizeof(SkPoint);
+
// position + color + texture coord
extern const GrVertexAttrib gTextVertexWithColorAttribs[] = {
{kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
{kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVertexAttribBinding}
};
+static const size_t kTextVAColorSize = 2 * sizeof(SkPoint) + sizeof(GrColor);
+
};
GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
size_t vertSize = fUseLCDText ? (2 * sizeof(SkPoint))
: (2 * sizeof(SkPoint) + sizeof(GrColor));
- SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexSize());
+ SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexStride());
SkPoint* positions = reinterpret_cast<SkPoint*>(
reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex);
SkASSERT(NULL == fVertices);
if (!fUseLCDText) {
fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>(
- SK_ARRAY_COUNT(gTextVertexWithColorAttribs));
+ SK_ARRAY_COUNT(gTextVertexWithColorAttribs),
+ kTextVAColorSize);
} else {
fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
- SK_ARRAY_COUNT(gTextVertexAttribs));
+ SK_ARRAY_COUNT(gTextVertexAttribs),
+ kTextVASize);
}
fVertexCount = 4*fSkPaint.textToGlyphs(text, byteLength, NULL);
bool success = fDrawTarget->reserveVertexAndIndexSpace(fVertexCount,
fFlagBits = that.fFlagBits;
fVACount = that.fVACount;
fVAPtr = that.fVAPtr;
- fVertexSize = that.fVertexSize;
+ fVAStride = that.fVAStride;
fStencilSettings = that.fStencilSettings;
fCoverage = that.fCoverage;
fDrawFace = that.fDrawFace;
////////////////////////////////////////////////////////////////////////////////
-static size_t vertex_size(const GrVertexAttrib* attribs, int count) {
+static void validate_vertex_attribs(const GrVertexAttrib* attribs, int count, size_t stride) {
// this works as long as we're 4 byte-aligned
#ifdef SK_DEBUG
uint32_t overlapCheck = 0;
-#endif
SkASSERT(count <= GrRODrawState::kMaxVertexAttribCnt);
- size_t size = 0;
for (int index = 0; index < count; ++index) {
size_t attribSize = GrVertexAttribTypeSize(attribs[index].fType);
- size += attribSize;
-#ifdef SK_DEBUG
+ size_t attribOffset = attribs[index].fOffset;
+ SkASSERT(attribOffset + attribSize <= stride);
size_t dwordCount = attribSize >> 2;
uint32_t mask = (1 << dwordCount)-1;
- size_t offsetShift = attribs[index].fOffset >> 2;
+ size_t offsetShift = attribOffset >> 2;
SkASSERT(!(overlapCheck & (mask << offsetShift)));
overlapCheck |= (mask << offsetShift);
-#endif
}
- return size;
+#endif
}
////////////////////////////////////////////////////////////////////////////////
-void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) {
+void GrDrawState::internalSetVertexAttribs(const GrVertexAttrib* attribs, int count,
+ size_t stride) {
SkASSERT(count <= kMaxVertexAttribCnt);
fVAPtr = attribs;
fVACount = count;
- fVertexSize = vertex_size(fVAPtr, fVACount);
+ fVAStride = stride;
+ validate_vertex_attribs(fVAPtr, fVACount, fVAStride);
// Set all the indices to -1
memset(fFixedFunctionVertexAttribIndices,
fVAPtr = &kPositionAttrib;
fVACount = 1;
- fVertexSize = GrVertexAttribTypeSize(kVec2f_GrVertexAttribType);
+ fVAStride = GrVertexAttribTypeSize(kVec2f_GrVertexAttribType);
// set all the fixed function indices to -1 except position.
memset(fFixedFunctionVertexAttribIndices,
fDrawState = drawState;
fVAPtr = drawState->fVAPtr;
fVACount = drawState->fVACount;
+ fVAStride = drawState->fVAStride;
fDrawState->setDefaultVertexAttribs();
}
/**
* Sets vertex attributes for next draw. The object driving the templatization
* should be a global GrVertexAttrib array that is never changed.
+ *
+ * @param count the number of attributes being set, limited to kMaxVertexAttribCnt.
+ * @param stride the number of bytes between successive vertex data.
*/
- template <const GrVertexAttrib A[]> void setVertexAttribs(int count) {
- this->setVertexAttribs(A, count);
+ template <const GrVertexAttrib A[]> void setVertexAttribs(int count, size_t stride) {
+ this->internalSetVertexAttribs(A, count, stride);
}
/**
public:
AutoVertexAttribRestore(GrDrawState* drawState);
- ~AutoVertexAttribRestore() { fDrawState->setVertexAttribs(fVAPtr, fVACount); }
+ ~AutoVertexAttribRestore() { fDrawState->internalSetVertexAttribs(fVAPtr, fVACount, fVAStride); }
private:
GrDrawState* fDrawState;
const GrVertexAttrib* fVAPtr;
int fVACount;
+ size_t fVAStride;
};
/// @}
// This is used to assert that this condition holds.
SkDEBUGCODE(int fBlockEffectRemovalCnt;)
- /**
- * Sets vertex attributes for next draw.
- *
- * @param attribs the array of vertex attributes to set.
- * @param count the number of attributes being set, limited to kMaxVertexAttribCnt.
- */
- void setVertexAttribs(const GrVertexAttrib attribs[], int count);
+ void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, size_t stride);
typedef GrRODrawState INHERITED;
};
int indexCount,
void** vertices,
void** indices) {
- size_t vertexSize = this->drawState()->getVertexSize();
+ size_t vertexStride = this->drawState()->getVertexStride();
this->willReserveVertexAndIndexSpace(vertexCount, indexCount);
if (vertexCount) {
- if (!this->reserveVertexSpace(vertexSize, vertexCount, vertices)) {
+ if (!this->reserveVertexSpace(vertexStride, vertexCount, vertices)) {
if (indexCount) {
this->resetIndexSource();
}
this->releasePreviousVertexSource();
GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
geoSrc.fVertexSrc = kArray_GeometrySrcType;
- geoSrc.fVertexSize = this->drawState()->getVertexSize();
+ geoSrc.fVertexSize = this->drawState()->getVertexStride();
geoSrc.fVertexCount = vertexCount;
this->onSetVertexSourceToArray(vertexArray, vertexCount);
}
geoSrc.fVertexSrc = kBuffer_GeometrySrcType;
geoSrc.fVertexBuffer = buffer;
buffer->ref();
- geoSrc.fVertexSize = this->drawState()->getVertexSize();
+ geoSrc.fVertexSize = this->drawState()->getVertexStride();
}
void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) {
void set_vertex_attributes(GrDrawState* drawState, bool hasUVs) {
if (hasUVs) {
- drawState->setVertexAttribs<gBWRectPosUVAttribs>(2);
+ drawState->setVertexAttribs<gBWRectPosUVAttribs>(2, 2 * sizeof(SkPoint));
} else {
- drawState->setVertexAttribs<gBWRectPosUVAttribs>(1);
+ drawState->setVertexAttribs<gBWRectPosUVAttribs>(1, sizeof(SkPoint));
}
}
return;
}
- size_t vsize = this->drawState()->getVertexSize();
- geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize);
+ size_t vstride = this->drawState()->getVertexStride();
+ geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vstride);
if (NULL != localRect) {
SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) +
sizeof(SkPoint));
coords->setRectFan(localRect->fLeft, localRect->fTop,
localRect->fRight, localRect->fBottom,
- vsize);
+ vstride);
if (NULL != localMatrix) {
- localMatrix->mapPointsWithStride(coords, vsize, 4);
+ localMatrix->mapPointsWithStride(coords, vstride, 4);
}
}
SkRect bounds;
*/
static void set_vertex_attributes(GrDrawState* drawState, bool hasLocalCoords, GrColor color) {
if (hasLocalCoords) {
- drawState->setVertexAttribs<kRectAttribs>(3);
+ drawState->setVertexAttribs<kRectAttribs>(3, 2 * sizeof(SkPoint) + sizeof(SkColor));
} else {
- drawState->setVertexAttribs<kRectAttribs>(2);
+ drawState->setVertexAttribs<kRectAttribs>(2, sizeof(SkPoint) + sizeof(SkColor));
}
if (0xFF == GrColorUnpackA(color)) {
drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true);
return;
}
- size_t vsize = drawState->getVertexSize();
+ size_t vstride = drawState->getVertexStride();
- geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize);
- matrix.mapPointsWithStride(geo.positions(), vsize, 4);
+ geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vstride);
+ matrix.mapPointsWithStride(geo.positions(), vstride, 4);
SkRect devBounds;
// since we already computed the dev verts, set the bounds hint. This will help us avoid
// unnecessary clipping in our onDraw().
- get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds);
+ get_vertex_bounds(geo.vertices(), vstride, 4, &devBounds);
if (NULL != localRect) {
static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor);
SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) + kLocalOffset);
coords->setRectFan(localRect->fLeft, localRect->fTop,
localRect->fRight, localRect->fBottom,
- vsize);
+ vstride);
if (NULL != localMatrix) {
- localMatrix->mapPointsWithStride(coords, vsize, 4);
+ localMatrix->mapPointsWithStride(coords, vstride, 4);
}
}
GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + kColorOffset);
for (int i = 0; i < 4; ++i) {
*vertColor = color;
- vertColor = (GrColor*) ((intptr_t) vertColor + vsize);
+ vertColor = (GrColor*) ((intptr_t) vertColor + vstride);
}
this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer());
// update the amount of reserved vertex data actually referenced in draws
size_t vertexBytes = instancesToConcat * info.verticesPerInstance() *
- drawState.getVertexSize();
+ drawState.getVertexStride();
poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexBytes, vertexBytes);
draw->adjustInstanceCount(instancesToConcat);
case kReserved_GeometrySrcType: // fallthrough
case kArray_GeometrySrcType: {
size_t vertexBytes = (info.vertexCount() + info.startVertex()) *
- drawState.getVertexSize();
+ drawState.getVertexStride();
poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexBytes, vertexBytes);
draw->fVertexBuffer = poolState.fPoolVertexBuffer;
draw->adjustStartVertex(poolState.fPoolStartVertex);
*indexCount = currIndices;
}
if (NULL != vertexCount) {
- size_t vertexSize = this->getDrawState().getVertexSize();
- int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize);
+ size_t vertexStride = this->getDrawState().getVertexStride();
+ int32_t currVertices = fVertexPool.currentBufferVertices(vertexStride);
if (*vertexCount > currVertices &&
(!fVertexPool.preallocatedBuffersRemaining() &&
- *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexSize))) {
+ *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexStride))) {
flush = true;
}
return;
}
- drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircleVertexAttribs));
- SkASSERT(sizeof(CircleVertex) == drawState->getVertexSize());
+ drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircleVertexAttribs),
+ sizeof(CircleVertex));
GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);
if (!geo.succeeded()) {
return false;
}
- drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllipseVertexAttribs));
- SkASSERT(sizeof(EllipseVertex) == drawState->getVertexSize());
+ drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllipseVertexAttribs),
+ sizeof(EllipseVertex));
GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);
if (!geo.succeeded()) {
SkScalar innerRatioX = SkScalarDiv(xRadius, innerXRadius);
SkScalar innerRatioY = SkScalarDiv(yRadius, innerYRadius);
- drawState->setVertexAttribs<gDIEllipseVertexAttribs>(SK_ARRAY_COUNT(gDIEllipseVertexAttribs));
- SkASSERT(sizeof(DIEllipseVertex) == drawState->getVertexSize());
+ drawState->setVertexAttribs<gDIEllipseVertexAttribs>(SK_ARRAY_COUNT(gDIEllipseVertexAttribs),
+ sizeof(DIEllipseVertex));
GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);
if (!geo.succeeded()) {
// if the corners are circles, use the circle renderer
if ((!hasStroke || scaledStroke.fX == scaledStroke.fY) && xRadius == yRadius) {
- drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircleVertexAttribs));
- SkASSERT(sizeof(CircleVertex) == drawState->getVertexSize());
+ drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircleVertexAttribs),
+ sizeof(CircleVertex));
GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0);
if (!geo.succeeded()) {
// otherwise we use the ellipse renderer
} else {
- drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllipseVertexAttribs));
- SkASSERT(sizeof(EllipseVertex) == drawState->getVertexSize());
+ drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllipseVertexAttribs),
+ sizeof(EllipseVertex));
SkScalar innerXRadius = 0.0f;
SkScalar innerYRadius = 0.0f;
this->fBlendConstant != that.fBlendConstant ||
this->fFlagBits != that.fFlagBits ||
this->fVACount != that.fVACount ||
+ this->fVAStride != that.fVAStride ||
memcmp(this->fVAPtr, that.fVAPtr, this->fVACount * sizeof(GrVertexAttrib)) ||
this->fStencilSettings != that.fStencilSettings ||
this->fDrawFace != that.fDrawFace) {
}
}
- SkASSERT(this->fVertexSize == that.fVertexSize);
SkASSERT(0 == memcmp(this->fFixedFunctionVertexAttribIndices,
that.fFixedFunctionVertexAttribIndices,
sizeof(this->fFixedFunctionVertexAttribIndices)));
const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; }
int getVertexAttribCount() const { return fVACount; }
- size_t getVertexSize() const { return fVertexSize; }
+ size_t getVertexStride() const { return fVAStride; }
/**
* Getters for index into getVertexAttribs() for particular bindings. -1 is returned if the
kB_CombinedState,
};
- GrRODrawState& operator= (const GrRODrawState& that);
-
protected:
bool isEqual(const GrRODrawState& that) const;
uint32_t fFlagBits;
const GrVertexAttrib* fVAPtr;
int fVACount;
- size_t fVertexSize;
+ size_t fVAStride;
GrStencilSettings fStencilSettings;
uint8_t fCoverage;
DrawFace fDrawFace;
}
// Set up the vertex data for the line and start/end dashes
- drawState->setVertexAttribs<gDashLineVertexAttribs>(SK_ARRAY_COUNT(gDashLineVertexAttribs));
+ drawState->setVertexAttribs<gDashLineVertexAttribs>(SK_ARRAY_COUNT(gDashLineVertexAttribs),
+ sizeof(DashLineVertex));
int totalRectCnt = 0;
void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) {
- GrGLsizei stride = static_cast<GrGLsizei>(this->getDrawState().getVertexSize());
+ GrGLsizei stride = static_cast<GrGLsizei>(this->getDrawState().getVertexStride());
size_t vertexOffsetInBytes = stride * info.startVertex();