Remove GrContext::drawCustomVertices

Review URL: http://codereview.appspot.com/4910042/



git-svn-id: http://skia.googlecode.com/svn/trunk@2124 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2011-08-16 19:20:44 +00:00
Родитель 178d41e750
Коммит 498776ad9f
4 изменённых файлов: 16 добавлений и 269 удалений

Просмотреть файл

@ -391,62 +391,6 @@ public:
const uint16_t indices[],
int indexCount);
/**
* Similar to drawVertices but caller provides objects that convert to Gr
* types. The count of vertices is given by posSrc.
*
* @param paint describes how to color pixels.
* @param primitiveType primitives type to draw.
* @param posSrc Source of vertex positions. Must implement
* int count() const;
* void writeValue(int i, GrPoint* point) const;
* count returns the total number of vertices and
* writeValue writes a vertex position to point.
* @param texSrc optional, pass NULL to not use explicit tex
* coords. If present provides tex coords with
* method:
* void writeValue(int i, GrPoint* point) const;
* @param texSrc optional, pass NULL to not use per-vertex colors
* If present provides colors with method:
* void writeValue(int i, GrColor* point) const;
* @param indices optional, pass NULL for non-indexed drawing. If
* present supplies indices for indexed drawing
* with following methods:
* int count() const;
* void writeValue(int i, uint16_t* point) const;
* count returns the number of indices and
* writeValue supplies each index.
*/
template <typename POS_SRC,
typename TEX_SRC,
typename COL_SRC,
typename IDX_SRC>
void drawCustomVertices(const GrPaint& paint,
GrPrimitiveType primitiveType,
const POS_SRC& posSrc,
const TEX_SRC* texCoordSrc,
const COL_SRC* colorSrc,
const IDX_SRC* idxSrc);
/**
* To avoid the problem of having to create a typename for NULL parameters,
* these reduced versions of drawCustomVertices are provided.
*/
template <typename POS_SRC>
void drawCustomVertices(const GrPaint& paint,
GrPrimitiveType primitiveType,
const POS_SRC& posSrc);
template <typename POS_SRC, typename TEX_SRC>
void drawCustomVertices(const GrPaint& paint,
GrPrimitiveType primitiveType,
const POS_SRC& posSrc,
const TEX_SRC* texCoordSrc);
template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
void drawCustomVertices(const GrPaint& paint,
GrPrimitiveType primitiveType,
const POS_SRC& posSrc,
const TEX_SRC* texCoordSrc,
const COL_SRC* colorSrc);
///////////////////////////////////////////////////////////////////////////
// Misc.
@ -771,5 +715,3 @@ private:
#endif
#include "GrContext_impl.h"

Просмотреть файл

@ -1,127 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrContext_impl_DEFINED
#define GrContext_impl_DEFINED
template <typename POS_SRC, typename TEX_SRC,
typename COL_SRC, typename IDX_SRC>
inline void GrContext::drawCustomVertices(const GrPaint& paint,
GrPrimitiveType primitiveType,
const POS_SRC& posSrc,
const TEX_SRC* texCoordSrc,
const COL_SRC* colorSrc,
const IDX_SRC* idxSrc) {
GrDrawTarget::AutoReleaseGeometry geo;
GrDrawTarget* target = this->prepareToDraw(paint, kUnbuffered_DrawCategory);
bool hasTexCoords[GrPaint::kTotalStages] = {
NULL != texCoordSrc, // texCoordSrc provides explicit stage 0 coords
0 // remaining stages use positions
};
GrVertexLayout layout = PaintStageVertexLayoutBits(paint, hasTexCoords);
if (NULL != colorSrc) {
layout |= GrDrawTarget::kColor_VertexLayoutBit;
}
int vertexCount = posSrc.count();
int indexCount = (NULL != idxSrc) ? idxSrc->count() : 0;
if (!geo.set(target, layout, vertexCount, indexCount)) {
GrPrintf("Failed to get space for vertices!\n");
return;
}
int texOffsets[GrDrawTarget::kMaxTexCoords];
int colorOffset;
int vsize = GrDrawTarget::VertexSizeAndOffsetsByIdx(layout,
texOffsets,
&colorOffset);
void* curVertex = geo.vertices();
for (int i = 0; i < vertexCount; ++i) {
posSrc.writeValue(i, (GrPoint*)curVertex);
if (texOffsets[0] > 0) {
texCoordSrc->writeValue(i, (GrPoint*)((intptr_t)curVertex + texOffsets[0]));
}
if (colorOffset > 0) {
colorSrc->writeValue(i, (GrColor*)((intptr_t)curVertex + colorOffset));
}
curVertex = (void*)((intptr_t)curVertex + vsize);
}
uint16_t* indices = (uint16_t*) geo.indices();
for (int i = 0; i < indexCount; ++i) {
idxSrc->writeValue(i, indices + i);
}
// we don't currently apply offscreen AA to this path. Need improved
// management of GrDrawTarget's geometry to avoid copying points per-tile.
if (NULL == idxSrc) {
target->drawNonIndexed(primitiveType, 0, vertexCount);
} else {
target->drawIndexed(primitiveType, 0, 0, vertexCount, indexCount);
}
}
class GrNullTexCoordSource {
public:
void writeValue(int i, GrPoint* dstCoord) const { GrAssert(false); }
};
class GrNullColorSource {
public:
void writeValue(int i, GrColor* dstColor) const { GrAssert(false); }
};
class GrNullIndexSource {
public:
void writeValue(int i, uint16_t* dstIndex) const { GrAssert(false); }
int count() const { GrAssert(false); return 0; }
};
template <typename POS_SRC>
inline void GrContext::drawCustomVertices(const GrPaint& paint,
GrPrimitiveType primitiveType,
const POS_SRC& posSrc) {
this->drawCustomVertices<POS_SRC,
GrNullTexCoordSource,
GrNullColorSource,
GrNullIndexSource>(paint, primitiveType, posSrc,
NULL, NULL, NULL);
}
template <typename POS_SRC, typename TEX_SRC>
inline void GrContext::drawCustomVertices(const GrPaint& paint,
GrPrimitiveType primitiveType,
const POS_SRC& posSrc,
const TEX_SRC* texCoordSrc) {
this->drawCustomVertices<POS_SRC, TEX_SRC,
GrNullColorSource,
GrNullIndexSource>(paint, primitiveType, posSrc,
texCoordSrc, NULL, NULL);
}
template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
inline void GrContext::drawCustomVertices(const GrPaint& paint,
GrPrimitiveType primitiveType,
const POS_SRC& posSrc,
const TEX_SRC* texCoordSrc,
const COL_SRC* colorSrc) {
drawCustomVertices<POS_SRC, TEX_SRC, COL_SRC,
GrNullIndexSource>(paint, primitiveType, posSrc,
texCoordSrc, colorSrc, NULL);
}
#endif

Просмотреть файл

@ -87,7 +87,6 @@
'../gpu/include/GrColor.h',
'../gpu/include/GrConfig.h',
'../gpu/include/GrContext.h',
'../gpu/include/GrContext_impl.h',
'../gpu/include/GrDrawTarget.h',
'../gpu/include/GrFontScaler.h',
'../gpu/include/GrGLConfig.h',

Просмотреть файл

@ -539,67 +539,6 @@ bool SkGpuDevice::skPaint2GrPaintShader(const SkPaint& skPaint,
return true;
}
///////////////////////////////////////////////////////////////////////////////
class SkPositionSource {
public:
SkPositionSource(const SkPoint* points, int count)
: fPoints(points), fCount(count) {}
int count() const { return fCount; }
void writeValue(int i, GrPoint* dstPosition) const {
SkASSERT(i < fCount);
dstPosition->fX = fPoints[i].fX;
dstPosition->fY = fPoints[i].fY;
}
private:
const SkPoint* fPoints;
int fCount;
};
class SkTexCoordSource {
public:
SkTexCoordSource(const SkPoint* coords)
: fCoords(coords) {}
void writeValue(int i, GrPoint* dstCoord) const {
dstCoord->fX = fCoords[i].fX;
dstCoord->fY = fCoords[i].fY;
}
private:
const SkPoint* fCoords;
};
class SkColorSource {
public:
SkColorSource(const SkColor* colors) : fColors(colors) {}
void writeValue(int i, GrColor* dstColor) const {
*dstColor = SkGr::SkColor2GrColor(fColors[i]);
}
private:
const SkColor* fColors;
};
class SkIndexSource {
public:
SkIndexSource(const uint16_t* indices, int count)
: fIndices(indices), fCount(count) {
}
int count() const { return fCount; }
void writeValue(int i, uint16_t* dstIndex) const {
*dstIndex = fIndices[i];
}
private:
const uint16_t* fIndices;
int fCount;
};
///////////////////////////////////////////////////////////////////////////////
void SkGpuDevice::clear(SkColor color) {
@ -1464,29 +1403,23 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
}
}
// even if GrColor and SkColor byte offsets match we need
// to perform pre-multiply.
if (NULL == colors) {
fContext->drawVertices(grPaint,
gVertexMode2PrimitiveType[vmode],
vertexCount,
(GrPoint*) vertices,
(GrPoint*) texs,
NULL,
indices,
indexCount);
} else {
SkTexCoordSource texSrc(texs);
SkColorSource colSrc(colors);
SkIndexSource idxSrc(indices, indexCount);
fContext->drawCustomVertices(grPaint,
gVertexMode2PrimitiveType[vmode],
SkPositionSource(vertices, vertexCount),
(NULL == texs) ? NULL : &texSrc,
(NULL == colors) ? NULL : &colSrc,
(NULL == indices) ? NULL : &idxSrc);
SkAutoSTMalloc<128, GrColor> convertedColors(0);
if (NULL != colors) {
// need to convert byte order and from non-PM to PM
convertedColors.realloc(vertexCount);
for (int i = 0; i < vertexCount; ++i) {
convertedColors[i] = SkGr::SkColor2GrColor(colors[i]);
}
colors = convertedColors.get();
}
fContext->drawVertices(grPaint,
gVertexMode2PrimitiveType[vmode],
vertexCount,
(GrPoint*) vertices,
(GrPoint*) texs,
colors,
indices,
indexCount);
}
///////////////////////////////////////////////////////////////////////////////