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
diff --git a/gpu/include/GrContext.h b/gpu/include/GrContext.h
index b2928f8..0671701 100644
--- a/gpu/include/GrContext.h
+++ b/gpu/include/GrContext.h
@@ -391,62 +391,6 @@
                       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 @@
 
 #endif
 
-#include "GrContext_impl.h"
-
diff --git a/gpu/include/GrContext_impl.h b/gpu/include/GrContext_impl.h
deleted file mode 100644
index 8596491..0000000
--- a/gpu/include/GrContext_impl.h
+++ /dev/null
@@ -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
diff --git a/gyp/gpu.gyp b/gyp/gpu.gyp
index 3cee3e6..5869dca 100644
--- a/gyp/gpu.gyp
+++ b/gyp/gpu.gyp
@@ -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',
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 761d6cc..9fe54e5 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -541,67 +541,6 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-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) {
     fContext->clear(NULL, color);
 }
@@ -1464,29 +1403,23 @@
         }
     }
 
-    // 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);
 }
 
 ///////////////////////////////////////////////////////////////////////////////