Rev the GrContext interface. Context has draw* functions that take a new GrPaint...
authorbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 21 Jan 2011 21:03:59 +0000 (21:03 +0000)
committerbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 21 Jan 2011 21:03:59 +0000 (21:03 +0000)
Remove unused/unsupported point size (we don't draw non-hairline points using GL points).
Change current* getter functions to get* for consistency.
Fix bounds when drawing inverse-filled paths.

git-svn-id: http://skia.googlecode.com/svn/trunk@718 2bbb7eff-a529-9590-31e7-b0007b416f81

22 files changed:
gpu/include/GrContext.h
gpu/include/GrContext_impl.h [new file with mode: 0644]
gpu/include/GrDrawTarget.h
gpu/include/GrPaint.h [new file with mode: 0644]
gpu/include/GrSamplerState.h
gpu/include/GrTextContext.h
gpu/src/GrContext.cpp
gpu/src/GrDrawTarget.cpp
gpu/src/GrGpuGL.cpp
gpu/src/GrGpuGL.h
gpu/src/GrGpuGLFixed.cpp
gpu/src/GrTextContext.cpp
include/gpu/SkGpuDevice.h
include/gpu/SkGr.h
samplecode/SampleApp.cpp
src/gpu/SkGpuDevice.cpp
src/gpu/SkGr.cpp
src/utils/mac/SkOSWindow_Mac.cpp
src/utils/win/SkOSWindow_Win.cpp
vs/SampleApp/SampleApp.vcxproj
xcode/gpu/gpu.xcodeproj/project.pbxproj
xcode/sampleapp/SampleApp.xcodeproj/project.pbxproj

index fdf0e9f..c2838b8 100644 (file)
 \r
 #include "GrClip.h"\r
 #include "GrGpu.h"\r
-#include "GrSamplerState.h"\r
 #include "GrTextureCache.h"\r
 #include "GrInOrderDrawBuffer.h"\r
 #include "GrVertexBufferAllocPool.h"\r
+#include "GrPaint.h"\r
 \r
 class GrFontCache;\r
 class GrPathIter;\r
 \r
-//TODO: move GrGpu enums/nested types here\r
-\r
 class GrContext : public GrRefCnt {\r
 public:\r
     /**\r
@@ -52,6 +50,9 @@ public:
      */\r
     void resetContext();\r
 \r
+    ///////////////////////////////////////////////////////////////////////////\r
+    // Textures\r
+\r
     /**\r
      *  Abandons all textures. Call this if you have lost the associated GPU\r
      *  context, and thus internal texture references/IDs are now invalid.\r
@@ -108,6 +109,35 @@ public:
                                      size_t rowBytes);\r
 \r
     /**\r
+     *  Returns true if the specified use of an indexed texture is supported.\r
+     */\r
+    bool supportsIndex8PixelConfig(const GrSamplerState&, int width, int height);\r
+\r
+    /**\r
+     *  Return the current texture cache limits.\r
+     *\r
+     *  @param maxTextures If non-null, returns maximum number of textures that\r
+     *                     can be held in the cache.\r
+     *  @param maxTextureBytes If non-null, returns maximum number of bytes of\r
+     *                         texture memory that can be held in the cache.\r
+     */\r
+    void getTextureCacheLimits(int* maxTextures, size_t* maxTextureBytes) const;\r
+\r
+    /**\r
+     *  Specify the texture cache limits. If the current cache exceeds either\r
+     *  of these, it will be purged (LRU) to keep the cache within these limits.\r
+     *\r
+     *  @param maxTextures The maximum number of textures that can be held in\r
+     *                     the cache.\r
+     *  @param maxTextureBytes The maximum number of bytes of texture memory\r
+     *                         that can be held in the cache.\r
+     */\r
+    void setTextureCacheLimits(int maxTextures, size_t maxTextureBytes);\r
+\r
+    ///////////////////////////////////////////////////////////////////////////\r
+    // Render targets\r
+\r
+    /**\r
      * Wraps an externally-created rendertarget in a GrRenderTarget.\r
      * e.g. in GL platforamRenderTarget is an FBO id.\r
      */\r
@@ -128,52 +158,91 @@ public:
     }\r
 \r
     /**\r
-     *  Returns true if the specified use of an indexed texture is supported.\r
+     * Sets the render target.\r
+     * @param target    the render target to set. (should not be NULL.)\r
      */\r
-    bool supportsIndex8PixelConfig(const GrSamplerState&, int width, int height);\r
+    void setRenderTarget(GrRenderTarget* target);\r
+\r
+    /**\r
+     * Gets the current render target.\r
+     * @return the currently bound render target. Should never be NULL.\r
+     */\r
+    const GrRenderTarget* getRenderTarget() const;\r
+    GrRenderTarget* getRenderTarget();\r
 \r
     ///////////////////////////////////////////////////////////////////////////\r
+    // Matrix state\r
 \r
-    GrRenderTarget* currentRenderTarget() const;\r
-    void getViewMatrix(GrMatrix* m) const;\r
+    /**\r
+     * Gets the current transformation matrix.\r
+     * @return the current matrix.\r
+     */\r
+    const GrMatrix& getMatrix() const;\r
+\r
+    /**\r
+     * Sets the transformation matrix.\r
+     * @param m the matrix to set.\r
+     */\r
+    void setMatrix(const GrMatrix& m);\r
+\r
+    /**\r
+     * Concats the current matrix. The passed matrix is applied before the\r
+     * current matrix.\r
+     * @param m the matrix to concat.\r
+     */\r
+    void concatMatrix(const GrMatrix& m) const;\r
+\r
+\r
+    ///////////////////////////////////////////////////////////////////////////\r
+    // Clip state\r
+    /**\r
+     * Gets the current clip.\r
+     * @return the current clip.\r
+     */\r
     const GrClip& getClip() const { return fGpu->getClip(); }\r
 \r
-    void setRenderTarget(GrRenderTarget* target);\r
+    /**\r
+     * Sets the clip.\r
+     * @param clip  the clip to set.\r
+     */\r
+    void setClip(const GrClip& clip);\r
 \r
-    void setTexture(int stage, GrTexture* texture);\r
-    void setSamplerState(int stage, const GrSamplerState&);\r
-    void setTextureMatrix(int stage, const GrMatrix& m);\r
+    /**\r
+     * Convenience method for setting the clip to a rect.\r
+     * @param rect  the rect to set as the new clip.\r
+     */\r
+    void setClip(const GrIRect& rect);\r
 \r
-    void setAntiAlias(bool);\r
-    void setDither(bool);\r
-    void setAlpha(uint8_t alpha);\r
-    void setColor(GrColor color);\r
-    void setPointSize(float size);\r
-    void setBlendFunc(GrGpu::BlendCoeff srcCoef, GrGpu::BlendCoeff dstCoef);\r
-    void setViewMatrix(const GrMatrix& m);\r
-    void setClip(const GrClip&);\r
+    ///////////////////////////////////////////////////////////////////////////\r
+    // Draws\r
 \r
     /**\r
-     *  Erase the entire render target, ignoring any clips/scissors.\r
+     *  Erase the entire render target, ignoring any clips\r
      */\r
     void eraseColor(GrColor color);\r
 \r
     /**\r
-     *  Draw everywhere (respecting the clip) with the current color.\r
+     *  Draw everywhere (respecting the clip) with the paint.\r
      */\r
-    void drawFull(bool useTexture);\r
+    void drawPaint(const GrPaint& paint);\r
 \r
     /**\r
-     *  Draw the rect, respecting the current texture if useTexture is true.\r
-     *  If strokeWidth < 0, then the rect is filled, else the rect is stroked\r
-     *  based on strokeWidth. If strokeWidth == 0, then the stroke is always\r
-     *  a single pixel thick.\r
+     *  Draw the rect using a paint.\r
+     *  If strokeWidth < 0, then the rect is filled, else the rect is mitered\r
+     *  stroked based on strokeWidth. If strokeWidth == 0, then the stroke is\r
+     *  always a single pixel thick.\r
+     *  The rects coords are used to access the paint (through texture matrix)\r
      */\r
-    void drawRect(const GrRect&, bool useTexture, GrScalar strokeWidth);\r
+    void drawRect(const GrPaint& paint, const GrRect&, GrScalar strokeWidth = -1);\r
 \r
-    void fillRect(const GrRect& rect, bool useTexture) {\r
-        this->drawRect(rect, useTexture, -1);\r
-    }\r
+    /**\r
+     * Maps a rect of paint coordinates onto the a rect of destination\r
+     * coordinates. The srcRect is transformed by the paint's matrix and the\r
+     * dstRect is transformed by the context's matrix.\r
+     */\r
+    void drawRectToRect(const GrPaint& paint,\r
+                        const GrRect& dstRect,\r
+                        const GrRect& srcRect);\r
 \r
     /**\r
      * Path filling rules\r
@@ -191,16 +260,100 @@ public:
     /**\r
      * Tessellates and draws a path.\r
      *\r
+     * @param paint         describes how to color pixels.\r
      * @param path          the path to draw\r
-     * @param paint         the paint to set before drawing\r
-     * @param useTexture    if true the path vertices will also be used as\r
-     *                      texture coorindates referencing last texture passed\r
-     *                      to setTexture.\r
+     * @param fill          the path filling rule to use.\r
+     * @param translate     optional additional translation applied to the\r
+     *                      path.\r
      */\r
-    void drawPath(GrPathIter* path,\r
+    void drawPath(const GrPaint& paint,\r
+                  GrPathIter* path,\r
                   PathFills fill,\r
-                  bool useTexture,\r
                   const GrPoint* translate = NULL);\r
+    /**\r
+     * Draws vertices with a paint.\r
+     *\r
+     * @param   paint           describes how to color pixels.\r
+     * @param   primitiveType   primitives type to draw.\r
+     * @param   vertexCount     number of vertices.\r
+     * @param   positions       array of vertex positions, required.\r
+     * @param   texCoords       optional array of texture coordinates used\r
+     *                          to access the paint.\r
+     * @param   colors          optional array of per-vertex colors, supercedes\r
+     *                          the paint's color field.\r
+     * @param   indices         optional array of indices. If NULL vertices\r
+     *                          are drawn non-indexed.\r
+     * @param   indexCount      if indices is non-null then this is the\r
+     *                          number of indices.\r
+     */\r
+    void drawVertices(const GrPaint& paint,\r
+                      GrDrawTarget::PrimitiveType primitiveType,\r
+                      int vertexCount,\r
+                      const GrPoint positions[],\r
+                      const GrPoint texs[],\r
+                      const GrColor colors[],\r
+                      const uint16_t indices[],\r
+                      int indexCount);\r
+\r
+    /**\r
+     * Similar to drawVertices but caller provides objects that convert to Gr\r
+     * types. The count of vertices is given by posSrc.\r
+     *\r
+     * @param   paint           describes how to color pixels.\r
+     * @param   primitiveType   primitives type to draw.\r
+     * @param   posSrc          Source of vertex positions. Must implement\r
+     *                              int count() const;\r
+     *                              void writeValue(int i, GrPoint* point) const;\r
+     *                          count returns the total number of vertices and\r
+     *                          writeValue writes a vertex position to point.\r
+     * @param   texSrc          optional, pass NULL to not use explicit tex\r
+     *                          coords. If present provides tex coords with\r
+     *                          method:\r
+     *                              void writeValue(int i, GrPoint* point) const;\r
+     * @param   texSrc          optional, pass NULL to not use per-vertex colors\r
+     *                          If present provides colors with method:\r
+     *                              void writeValue(int i, GrColor* point) const;\r
+     * @param   indices         optional, pass NULL for non-indexed drawing. If\r
+     *                          present supplies indices for indexed drawing\r
+     *                          with following methods:\r
+     *                              int count() const;\r
+     *                              void writeValue(int i, uint16_t* point) const;\r
+     *                          count returns the number of indices and\r
+     *                          writeValue supplies each index.\r
+     */\r
+    template <typename POS_SRC,\r
+              typename TEX_SRC,\r
+              typename COL_SRC,\r
+              typename IDX_SRC>\r
+    void drawCustomVertices(const GrPaint& paint,\r
+                            GrDrawTarget::PrimitiveType primitiveType,\r
+                            const POS_SRC& posSrc,\r
+                            const TEX_SRC* texCoordSrc,\r
+                            const COL_SRC* colorSrc,\r
+                            const IDX_SRC* idxSrc);\r
+    /**\r
+     * To avoid the problem of having to create a typename for NULL parameters,\r
+     * these reduced versions of drawCustomVertices are provided.\r
+     */\r
+    template <typename POS_SRC>\r
+    void drawCustomVertices(const GrPaint& paint,\r
+                            GrDrawTarget::PrimitiveType primitiveType,\r
+                            const POS_SRC& posSrc);\r
+    template <typename POS_SRC, typename TEX_SRC>\r
+    void drawCustomVertices(const GrPaint& paint,\r
+                            GrDrawTarget::PrimitiveType primitiveType,\r
+                            const POS_SRC& posSrc,\r
+                            const TEX_SRC* texCoordSrc);\r
+    template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>\r
+    void drawCustomVertices(const GrPaint& paint,\r
+                            GrDrawTarget::PrimitiveType primitiveType,\r
+                            const POS_SRC& posSrc,\r
+                            const TEX_SRC* texCoordSrc,\r
+                            const COL_SRC* colorSrc);\r
+\r
+\r
+    ///////////////////////////////////////////////////////////////////////////\r
+    // Misc.\r
 \r
     /**\r
      * Call to ensure all drawing to the context has been issued to the\r
@@ -227,39 +380,9 @@ public:
     void writePixels(int left, int top, int width, int height,\r
                      GrTexture::PixelConfig, const void* buffer, size_t stride);\r
 \r
-    /* -------------------------------------------------------\r
-     * Mimicking the GrGpu interface for now\r
-     * TODO: define appropriate higher-level API for context\r
-     */\r
-\r
-    GrVertexBuffer* createVertexBuffer(uint32_t size, bool dynamic);\r
-\r
-    GrIndexBuffer* createIndexBuffer(uint32_t size, bool dynamic);\r
-\r
-    bool reserveAndLockGeometry(GrVertexLayout    vertexLayout,\r
-                                uint32_t          vertexCount,\r
-                                uint32_t          indexCount,\r
-                                void**            vertices,\r
-                                void**            indices);\r
 \r
-    void drawIndexed(GrGpu::PrimitiveType type,\r
-                     uint32_t startVertex,\r
-                     uint32_t startIndex,\r
-                     uint32_t vertexCount,\r
-                     uint32_t indexCount);\r
-\r
-    void drawNonIndexed(GrGpu::PrimitiveType type,\r
-                        uint32_t startVertex,\r
-                        uint32_t vertexCount);\r
-\r
-    void setVertexSourceToArray(const void* array,\r
-                                GrVertexLayout vertexLayout);\r
-    void setIndexSourceToArray(const void* array);\r
-    void setVertexSourceToBuffer(GrVertexBuffer* buffer,\r
-                                GrVertexLayout vertexLayout);\r
-    void setIndexSourceToBuffer(GrIndexBuffer* buffer);\r
-\r
-    void releaseReservedGeometry();\r
+    ///////////////////////////////////////////////////////////////////////////\r
+    // Statistics\r
 \r
     void resetStats();\r
 \r
@@ -267,11 +390,14 @@ public:
 \r
     void printStats() const;\r
 \r
+    ///////////////////////////////////////////////////////////////////////////\r
+    // Helpers\r
+\r
     class AutoRenderTarget : ::GrNoncopyable {\r
     public:\r
         AutoRenderTarget(GrContext* context, GrRenderTarget* target) {\r
             fContext = NULL;\r
-            fPrevTarget = context->currentRenderTarget();\r
+            fPrevTarget = context->getRenderTarget();\r
             if (fPrevTarget != target) {\r
                 context->setRenderTarget(target);\r
                 fContext = context;\r
@@ -287,36 +413,12 @@ public:
         GrRenderTarget* fPrevTarget;\r
     };\r
 \r
-    ///////////////////////////////////////////////////////////////////////////\r
-\r
-    /**\r
-     *  Return the current texture cache limits.\r
-     *\r
-     *  @param maxTextures If non-null, returns maximum number of textures that\r
-     *                     can be held in the cache.\r
-     *  @param maxTextureBytes If non-null, returns maximum number of bytes of\r
-     *                         texture memory that can be held in the cache.\r
-     */\r
-    void getTextureCacheLimits(int* maxTextures, size_t* maxTextureBytes) const;\r
 \r
-    /**\r
-     *  Specify the texture cache limits. If the current cache exceeds either\r
-     *  of these, it will be purged (LRU) to keep the cache within these limits.\r
-     *\r
-     *  @param maxTextures The maximum number of textures that can be held in\r
-     *                     the cache.\r
-     *  @param maxTextureBytes The maximum number of bytes of texture memory\r
-     *                         that can be held in the cache.\r
-     */\r
-    void setTextureCacheLimits(int maxTextures, size_t maxTextureBytes);\r
-\r
-    /* -------------------------------------------------------\r
-     */\r
-\r
-    // Intended only to be used within Ganesh:\r
+    ///////////////////////////////////////////////////////////////////////////\r
+    // Functions intended for internal use only.\r
     GrGpu* getGpu() { return fGpu; }\r
     GrFontCache* getFontCache() { return fFontCache; }\r
-    GrDrawTarget* getTextTarget();\r
+    GrDrawTarget* getTextTarget(const GrPaint& paint);\r
     void flushText();\r
 \r
     const GrIndexBuffer* quadIndexBuffer() const;\r
@@ -331,7 +433,11 @@ private:
     GrInOrderDrawBuffer     fTextDrawBuffer;\r
 \r
     GrContext(GrGpu* gpu);\r
+\r
+    static void SetPaint(const GrPaint& paint, GrDrawTarget* target);\r
+\r
     bool finalizeTextureKey(GrTextureKey*, const GrSamplerState&) const;\r
+    void prepareToDraw(const GrPaint& paint);\r
 \r
     void drawClipIntoStencil();\r
 };\r
@@ -339,17 +445,17 @@ private:
 /**\r
  *  Save/restore the view-matrix in the context.\r
  */\r
-class GrAutoViewMatrix : GrNoncopyable {\r
+class GrAutoMatrix : GrNoncopyable {\r
 public:\r
-    GrAutoViewMatrix(GrContext* ctx) : fContext(ctx) {\r
-        ctx->getViewMatrix(&fMatrix);\r
+    GrAutoMatrix(GrContext* ctx) : fContext(ctx) {\r
+        fMatrix = ctx->getMatrix();\r
     }\r
-    GrAutoViewMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {\r
-        ctx->getViewMatrix(&fMatrix);\r
-        ctx->setViewMatrix(matrix);\r
+    GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {\r
+        fMatrix = ctx->getMatrix();\r
+        ctx->setMatrix(matrix);\r
     }\r
-    ~GrAutoViewMatrix() {\r
-        fContext->setViewMatrix(fMatrix);\r
+    ~GrAutoMatrix() {\r
+        fContext->setMatrix(fMatrix);\r
     }\r
 \r
 private:\r
@@ -359,3 +465,4 @@ private:
 \r
 #endif\r
 \r
+#include "GrContext_impl.h"\r
diff --git a/gpu/include/GrContext_impl.h b/gpu/include/GrContext_impl.h
new file mode 100644 (file)
index 0000000..b54e927
--- /dev/null
@@ -0,0 +1,135 @@
+/*\r
+    Copyright 2011 Google Inc.\r
+\r
+    Licensed under the Apache License, Version 2.0 (the "License");\r
+    you may not use this file except in compliance with the License.\r
+    You may obtain a copy of the License at\r
+\r
+         http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+    Unless required by applicable law or agreed to in writing, software\r
+    distributed under the License is distributed on an "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+    See the License for the specific language governing permissions and\r
+    limitations under the License.\r
+ */\r
+\r
+#ifndef GrContext_impl_DEFINED\r
+#define GrContext_impl_DEFINED\r
+\r
+template <typename POS_SRC, typename TEX_SRC,\r
+          typename COL_SRC, typename IDX_SRC>\r
+inline void GrContext::drawCustomVertices(const GrPaint& paint,\r
+                                          GrDrawTarget::PrimitiveType primitiveType,\r
+                                          const POS_SRC& posSrc,\r
+                                          const TEX_SRC* texCoordSrc,\r
+                                          const COL_SRC* colorSrc,\r
+                                          const IDX_SRC* idxSrc) {\r
+\r
+    GrVertexLayout layout = 0;\r
+\r
+    GrDrawTarget::AutoReleaseGeometry geo;\r
+\r
+    this->prepareToDraw(paint);\r
+\r
+    if (NULL != paint.getTexture()) {\r
+        if (NULL != texCoordSrc) {\r
+            layout |= GrDrawTarget::StageTexCoordVertexLayoutBit(0,0);\r
+        } else {\r
+            layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(0);\r
+        }\r
+    }\r
+\r
+    if (NULL != colorSrc) {\r
+        layout |= GrDrawTarget::kColor_VertexLayoutBit;\r
+    }\r
+\r
+    int vertexCount = posSrc.count();\r
+    int indexCount = (NULL != idxSrc) ? idxSrc->count() : 0;\r
+\r
+    if (!geo.set(fGpu, layout, vertexCount, indexCount)) {\r
+        GrPrintf("Failed to get space for vertices!");\r
+        return;\r
+    }\r
+\r
+    int texOffsets[GrDrawTarget::kMaxTexCoords];\r
+    int colorOffset;\r
+    int vsize = GrDrawTarget::VertexSizeAndOffsetsByIdx(layout,\r
+                                                        texOffsets,\r
+                                                        &colorOffset);\r
+    void* curVertex = geo.vertices();\r
+\r
+    for (int i = 0; i < vertexCount; ++i) {\r
+        posSrc.writeValue(i, (GrPoint*)curVertex);\r
+\r
+        if (texOffsets[0] > 0) {\r
+            texCoordSrc->writeValue(i, (GrPoint*)((intptr_t)curVertex + texOffsets[0]));\r
+        }\r
+        if (colorOffset > 0) {\r
+            colorSrc->writeValue(i, (GrColor*)((intptr_t)curVertex + colorOffset));\r
+        }\r
+        curVertex = (void*)((intptr_t)curVertex + vsize);\r
+    }\r
+\r
+    uint16_t* indices = (uint16_t*) geo.indices();\r
+    for (int i = 0; i < indexCount; ++i) {\r
+        idxSrc->writeValue(i, indices + i);\r
+    }\r
+\r
+    if (NULL == idxSrc) {\r
+        fGpu->drawNonIndexed(primitiveType, 0, vertexCount);\r
+    } else {\r
+        fGpu->drawIndexed(primitiveType, 0, 0, vertexCount, indexCount);\r
+    }\r
+}\r
+\r
+class GrNullTexCoordSource {\r
+public:\r
+    void writeValue(int i, GrPoint* dstCoord) const { GrAssert(false); }\r
+};\r
+\r
+class GrNullColorSource {\r
+public:\r
+    void writeValue(int i, GrColor* dstColor) const { GrAssert(false); }\r
+};\r
+\r
+class GrNullIndexSource {\r
+public:\r
+    void writeValue(int i, uint16_t* dstIndex) const { GrAssert(false); }\r
+    int count() const { GrAssert(false); return 0; }\r
+};\r
+\r
+template <typename POS_SRC>\r
+inline void GrContext::drawCustomVertices(const GrPaint& paint,\r
+                                          GrDrawTarget::PrimitiveType primitiveType,\r
+                                          const POS_SRC& posSrc) {\r
+    this->drawCustomVertices<POS_SRC,\r
+                             GrNullTexCoordSource,\r
+                             GrNullColorSource,\r
+                             GrNullIndexSource>(paint, primitiveType, posSrc,\r
+                                                NULL, NULL, NULL);\r
+}\r
+\r
+template <typename POS_SRC, typename TEX_SRC>\r
+inline void GrContext::drawCustomVertices(const GrPaint& paint,\r
+                                          GrDrawTarget::PrimitiveType primitiveType,\r
+                                          const POS_SRC& posSrc,\r
+                                          const TEX_SRC* texCoordSrc) {\r
+    this->drawCustomVertices<POS_SRC, TEX_SRC,\r
+                             GrNullColorSource,\r
+                             GrNullIndexSource>(paint, primitiveType, posSrc,\r
+                                                texCoordSrc, NULL, NULL);\r
+}\r
+\r
+template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>\r
+inline void GrContext::drawCustomVertices(const GrPaint& paint,\r
+                                          GrDrawTarget::PrimitiveType primitiveType,\r
+                                          const POS_SRC& posSrc,\r
+                                          const TEX_SRC* texCoordSrc,\r
+                                          const COL_SRC* colorSrc) {\r
+    drawCustomVertices<POS_SRC, TEX_SRC, COL_SRC,\r
+                       GrNullIndexSource>(paint, primitiveType, posSrc, \r
+                                          texCoordSrc, colorSrc, NULL);\r
+}\r
+\r
+#endif\r
index 3405bb5..ec84cda 100644 (file)
@@ -34,26 +34,26 @@ class GrIndexBuffer;
 class GrDrawTarget : public GrRefCnt {
 public:
     /**
-     * Number of texture stages. Each stage takes as input a color and 
-     * 2D texture coordinates. The color input to the first enabled stage is the 
-     * per-vertex color or the constant color (setColor/setAlpha) if there are no
-     * per-vertex colors. For subsequent stages the input color is the output  
+     * Number of texture stages. Each stage takes as input a color and
+     * 2D texture coordinates. The color input to the first enabled stage is the
+     * per-vertex color or the constant color (setColor/setAlpha) if there are
+     * no per-vertex colors. For subsequent stages the input color is the output
      * color from the previous enabled stage. The output color of each stage is
-     * the input color modulated with the result of a texture lookup. Texture 
+     * the input color modulated with the result of a texture lookup. Texture
      * lookups are specified by a texture (setTexture), a texture matrix
-     * (setTextureMatrix), and a sampler (setSamplerState). Texture coordinates 
+     * (setTextureMatrix), and a sampler (setSamplerState). Texture coordinates
      * for each stage come from the vertices based on a GrVertexLayout bitfield.
      * The output fragment color is the output color of the last enabled stage.
-     * The presence or absence of texture coordinates for each stage in the 
+     * The presence or absence of texture coordinates for each stage in the
      * vertex layout indicates whether a stage is enabled or not.
      */
-    
+
     // Currently there is just one stage but this will be changed soon.
     enum {
         kNumStages = 1,
         kMaxTexCoords = kNumStages
     };
-    
+
     /**
      * Geometric primitives used for drawing.
      */
@@ -154,7 +154,6 @@ protected:
         GrSamplerState         fSamplerStates[kNumStages];
         GrRenderTarget*        fRenderTarget;
         GrColor                fColor;
-        float                  fPointSize;
         StencilPass             fStencilPass;
         bool                    fReverseFill;
         GrMatrix                fViewMatrix;
@@ -202,14 +201,13 @@ public:
      *            texture has been set, NULL was most recently passed to
      *            setTexture, or the last setTexture was destroyed.
      */
-    GrTexture* currentTexture(int stage) const;
+    const GrTexture* getTexture(int stage) const;
+    GrTexture* getTexture(int stage);
 
     /**
      * Sets the rendertarget used at the next drawing call
      *
-     * @param target  The render target to set. Must be a valid rendertarget.
-     *                That is it is a value that was returned by
-     *                currentRenderTarget() or GrTexture::asRenderTarget().
+     * @param target  The render target to set.
      */
     void setRenderTarget(GrRenderTarget* target);
 
@@ -218,7 +216,8 @@ public:
      *
      * @return    The currently set render target.
      */
-    GrRenderTarget* currentRenderTarget() const;
+    const GrRenderTarget* getRenderTarget() const;
+    GrRenderTarget* getRenderTarget();
 
     /**
      * Sets the sampler state for the next draw.
@@ -318,13 +317,6 @@ public:
     }
 
     /**
-     * Sets the size of points used the next time points are drawn.
-     *
-     * @param the point size
-     */
-    void setPointSize(float size);
-
-    /**
      * Sets the blending function coeffecients.
      *
      * The blend function will be:
@@ -341,9 +333,9 @@ public:
 
     /**
      * Retrieves the current view matrix
-     * @param matrix will be the current view matrix after return.
+     * return the current view matrix.
      */
-    void getViewMatrix(GrMatrix* matrix) const;
+    const GrMatrix& getViewMatrix() const;
 
     /**
      *  Retrieves the inverse of the current view matrix.
@@ -396,7 +388,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 kMaxTexCoords sets of 2D texture 
+     * positions and may also contain up to kMaxTexCoords sets of 2D texture
      * coordinates and per-vertex colors. Each stage can use any of the texture
      * coordinates as its input texture coordinates or it may use the positions.
      *
@@ -404,18 +396,18 @@ public:
      * disabled.
      *
      * Only one type of texture coord can be specified per stage. For
-     * example StageTexCoordVertexLayoutBit(0, 2) and 
+     * example StageTexCoordVertexLayoutBit(0, 2) and
      * StagePosAsTexCoordVertexLayoutBit(0) cannot both be specified.
      *
-     * The order in memory is always (position, texture coord 0, ..., color) 
+     * The order in memory is always (position, texture coord 0, ..., color)
      * with any unused fields omitted. Note that this means that if only texture
-     * coordinates 1 is referenced then there is no texture coordinates 0 and 
+     * coordinates 1 is referenced then there is no texture coordinates 0 and
      * the order would be (position, texture coordinate 1[, color]).
      */
-    
+
     /**
      * Generates a bit indicating that a texture stage uses texture coordinates
-     * 
+     *
      * @param stage       the stage that will use texture coordinates.
      * @param texCoordIdx the index of the texture coordinates to use
      *
@@ -433,31 +425,31 @@ 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 
+     * @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 < kNumStages);
-        return (1 << (TEX_COORD_BIT_CNT + stage)); 
+        return (1 << (TEX_COORD_BIT_CNT + stage));
     }
 private:
     static const int STAGE_BIT_CNT = TEX_COORD_BIT_CNT + kNumStages;
-    
+
 public:
-    
+
     /**
      * Additional Bits that can be specified in GrVertexLayout.
      */
     enum VertexLayoutBits {
-        
+
         kColor_VertexLayoutBit              = 1 << (STAGE_BIT_CNT + 0),
                                                 //<! vertices have colors
         kTextFormat_VertexLayoutBit         = 1 << (STAGE_BIT_CNT + 1),
                                                 //<! use text vertices. (Pos
                                                 //   and tex coords may be
-                                                //   a different type for 
+                                                //   a different type for
                                                 //   text [GrGpuTextVertex vs
                                                 //   GrPoint].)
         // for below assert
@@ -634,12 +626,33 @@ public:
                                                        &fVertices,
                                                        &fIndices);
         }
+
+        AutoReleaseGeometry() {
+            fSuccess = false;
+        }
+
         ~AutoReleaseGeometry() {
             if (fSuccess) {
                 fTarget->releaseReservedGeometry();
             }
         }
 
+        bool set(GrDrawTarget*  target,
+                 GrVertexLayout vertexLayout,
+                 uint32_t       vertexCount,
+                 uint32_t       indexCount) {
+            if (fSuccess) {
+                fTarget->releaseReservedGeometry();
+            }
+            fTarget = target;
+            fSuccess = fTarget->reserveAndLockGeometry(vertexLayout,
+                                                       vertexCount,
+                                                       indexCount,
+                                                       &fVertices,
+                                                       &fIndices);
+            return fSuccess;
+        }
+
         bool succeeded() const { return fSuccess; }
         void* vertices() const { return fVertices; }
         void* indices() const { return fIndices; }
@@ -674,13 +687,13 @@ public:
 
     ////////////////////////////////////////////////////////////////////////////
     // Helpers for picking apart vertex layouts
-    
+
     /**
      * Helper function to compute the size of a vertex from a vertex layout
      * @return size of a single vertex.
      */
     static size_t VertexSize(GrVertexLayout vertexLayout);
-    
+
     /**
      * Helper function for determining the index of texture coordinates that
      * is input for a texture stage. Note that a stage may instead use positions
@@ -698,7 +711,7 @@ public:
     /**
      * Helper function to compute the offset of texture coordinates in a vertex
      * @return offset of texture coordinates in vertex layout or -1 if the
-     *         layout has no texture coordinates. Will be 0 if positions are 
+     *         layout has no texture coordinates. Will be 0 if positions are
      *         used as texture coordinates for the stage.
      */
     static int VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout);
@@ -711,18 +724,18 @@ public:
     static int VertexColorOffset(GrVertexLayout vertexLayout);
 
     /**
-     * Helper function to determine if vertex layout contains explicit texture 
+     * Helper function to determine if vertex layout contains explicit texture
      * coordinates of some index.
      *
      * @param coordIndex    the tex coord index to query
      * @param vertexLayout  layout to query
      *
-     * @return true if vertex specifies texture coordinates for the index, 
+     * @return true if vertex specifies texture coordinates for the index,
      *              false otherwise.
      */
-    static bool VertexUsesTexCoordIdx(int coordIndex, 
+    static bool VertexUsesTexCoordIdx(int coordIndex,
                                       GrVertexLayout vertexLayout);
-    
+
     /**
      * Helper function to determine if vertex layout contains either explicit or
      * implicit texture coordinates for a stage.
@@ -730,15 +743,15 @@ public:
      * @param stage         the stage to query
      * @param vertexLayout  layout to query
      *
-     * @return true if vertex specifies texture coordinates for the stage, 
+     * @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 
+     * 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
      * by StageTexCoordVertexLayoutBit.)
      *
      * @param vertexLayout          the layout to query
@@ -750,12 +763,12 @@ public:
     static int VertexSizeAndOffsetsByIdx(GrVertexLayout vertexLayout,
                                          int texCoordOffsetsByIdx[kMaxTexCoords],
                                          int *colorOffset);
-    
+
     /**
-     * Helper function to compute the size of each vertex and the offsets of 
-     * texture coordinates and color. Determines tex coord offsets by stage 
-     * rather than by index. (Each stage can be mapped to any t.c. index 
-     * by StageTexCoordVertexLayoutBit.) If a stage uses positions for 
+     * Helper function to compute the size of each vertex and the offsets of
+     * texture coordinates and color. Determines tex coord offsets by stage
+     * rather than by index. (Each stage can be mapped to any t.c. index
+     * by StageTexCoordVertexLayoutBit.) If a stage uses positions for
      * tex coords then that stage's offset will be 0 (positions are always at 0).
      *
      * @param vertexLayout              the layout to query
@@ -768,7 +781,7 @@ public:
                                            int texCoordOffsetsByStage[kNumStages],
                                            int *colorOffset);
 protected:
-    
+
     // Helpers for GrDrawTarget subclasses that won't have private access to
     // SavedDrawState but need to peek at the state values.
     static DrState& accessSavedDrawState(SavedDrawState& sds)
diff --git a/gpu/include/GrPaint.h b/gpu/include/GrPaint.h
new file mode 100644 (file)
index 0000000..23902a8
--- /dev/null
@@ -0,0 +1,106 @@
+/*\r
+    Copyright 2011 Google Inc.\r
+\r
+    Licensed under the Apache License, Version 2.0 (the "License");\r
+    you may not use this file except in compliance with the License.\r
+    You may obtain a copy of the License at\r
+\r
+         http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+    Unless required by applicable law or agreed to in writing, software\r
+    distributed under the License is distributed on an "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+    See the License for the specific language governing permissions and\r
+    limitations under the License.\r
+ */\r
+\r
+#ifndef GrPaint_DEFINED\r
+#define GrPaint_DEFINED\r
+\r
+#include "GrTexture.h"\r
+#include "GrSamplerState.h"\r
+#include "GrDrawTarget.h"\r
+\r
+/**\r
+ * The paint describes how pixels are colored when the context draws to\r
+ * them.\r
+ */\r
+class GrPaint {\r
+public:\r
+\r
+    // All the paint fields are public except texture (it's ref-counted)\r
+    GrDrawTarget::BlendCoeff    fSrcBlendCoeff;\r
+    GrDrawTarget::BlendCoeff    fDstBlendCoeff;\r
+    bool                        fAntiAlias;\r
+    bool                        fDither;\r
+\r
+    GrColor                     fColor;\r
+\r
+    GrMatrix                    fTextureMatrix;\r
+    GrSamplerState              fSampler;\r
+\r
+    void setTexture(GrTexture* texture) {\r
+        GrSafeRef(texture);\r
+        GrSafeUnref(fTexture);\r
+        fTexture = texture;\r
+    }\r
+\r
+    GrTexture* getTexture() const { return fTexture; }\r
+\r
+    // uninitialized\r
+    GrPaint() {\r
+        fTexture = NULL;\r
+    }\r
+\r
+    GrPaint(const GrPaint& paint) {\r
+        fSrcBlendCoeff = paint.fSrcBlendCoeff;\r
+        fDstBlendCoeff = paint.fDstBlendCoeff;\r
+        fAntiAlias = paint.fAntiAlias;\r
+        fDither = paint.fDither;\r
+\r
+        fColor = paint.fColor;\r
+\r
+        fTextureMatrix = paint.fTextureMatrix;\r
+        fSampler = paint.fSampler;\r
+        fTexture = paint.fTexture;\r
+        GrSafeRef(fTexture);\r
+    }\r
+\r
+    ~GrPaint() {\r
+        GrSafeUnref(fTexture);\r
+    }\r
+\r
+    // sets paint to src-over, solid white, no texture\r
+    void reset() {\r
+        resetBlend();\r
+        resetOptions();\r
+        resetColor();\r
+        resetTexture();\r
+    }\r
+\r
+private:\r
+    GrTexture*      fTexture;\r
+\r
+    void resetBlend() {\r
+        fSrcBlendCoeff = GrDrawTarget::kOne_BlendCoeff;\r
+        fDstBlendCoeff = GrDrawTarget::kZero_BlendCoeff;\r
+    }\r
+\r
+    void resetOptions() {\r
+        fAntiAlias = false;\r
+        fDither = false;\r
+    }\r
+\r
+    void resetColor() {\r
+        fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff);\r
+    }\r
+\r
+    void resetTexture() {\r
+        setTexture(NULL);\r
+        fTextureMatrix = GrMatrix::I();\r
+        fSampler.setClampNoFilter();\r
+    }\r
+\r
+};\r
+\r
+#endif\r
index 5fb10b9..9715c45 100644 (file)
@@ -46,27 +46,27 @@ public:
         this->setClampNoFilter();
     }
 
-    GrSamplerState(bool filter) {
+    explicit GrSamplerState(bool filter) {
         fWrapX = kClamp_WrapMode;
         fWrapY = kClamp_WrapMode;
         fSampleMode = kNormal_SampleMode;
         fFilter = filter;
     }
-    
+
     GrSamplerState(WrapMode wx, WrapMode wy, bool filter) {
         fWrapX = wx;
         fWrapY = wy;
         fSampleMode = kNormal_SampleMode;
         fFilter = filter;
     }
-    
+
     GrSamplerState(WrapMode wx, WrapMode wy, SampleMode sample, bool filter) {
         fWrapX = wx;
         fWrapY = wy;
         fSampleMode = sample;
         fFilter = filter;
     }
-    
+
     WrapMode getWrapX() const { return fWrapX; }
     WrapMode getWrapY() const { return fWrapY; }
     SampleMode getSampleMode() const { return fSampleMode; }
@@ -95,8 +95,8 @@ public:
     bool     isRadial2PosRoot() const { return fRadial2PosRoot; }
 
     /**
-     * Sets the parameters for kRadial2_SampleMode. The texture 
-     * matrix must be set so that the first point is at (0,0) and the second 
+     * Sets the parameters for kRadial2_SampleMode. The texture
+     * matrix must be set so that the first point is at (0,0) and the second
      * point lies on the x-axis. The second radius minus the first is 1 unit.
      * The additional parameters to define the gradient are specified by this
      * function.
index 6b7446b..d813c09 100644 (file)
@@ -27,7 +27,9 @@ class GrFontScaler;
 
 class GrTextContext {
 public:
-    GrTextContext(GrContext*, const GrMatrix* extMatrix = NULL);
+    GrTextContext(GrContext*,
+                  const GrPaint& paint,
+                  const GrMatrix* extMatrix = NULL);
     ~GrTextContext();
 
     void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top,
@@ -36,6 +38,7 @@ public:
     void flush();   // optional; automatically called by destructor
 
 private:
+    const GrPaint&  fPaint;
     GrContext*      fContext;
     GrDrawTarget*   fDrawTarget;
 
@@ -53,7 +56,7 @@ private:
     };
 
     GrGpuTextVertex* fVertices;
-    
+
     int32_t     fMaxVertices;
     GrTexture*  fCurrTexture;
     int         fCurrVertex;
index ee78848..5e6b824 100644 (file)
@@ -138,17 +138,17 @@ GrTextureEntry* GrContext::createAndLockTexture(GrTextureKey* key,
         GrTexture* texture = fGpu->createTexture(rtDesc, NULL, 0);\r
 \r
         if (NULL != texture) {\r
-            GrGpu::AutoStateRestore asr(fGpu);\r
+            GrDrawTarget::AutoStateRestore asr(fGpu);\r
             fGpu->setRenderTarget(texture->asRenderTarget());\r
             fGpu->setTexture(0, clampEntry->texture());\r
-            fGpu->setStencilPass(GrGpu::kNone_StencilPass);\r
+            fGpu->setStencilPass(GrDrawTarget::kNone_StencilPass);\r
             fGpu->setTextureMatrix(0, GrMatrix::I());\r
             fGpu->setViewMatrix(GrMatrix::I());\r
             fGpu->setAlpha(0xff);\r
-            fGpu->setBlendFunc(GrGpu::kOne_BlendCoeff, GrGpu::kZero_BlendCoeff);\r
-            fGpu->disableState(GrGpu::kDither_StateBit |\r
-                               GrGpu::kClip_StateBit   |\r
-                               GrGpu::kAntialias_StateBit);\r
+            fGpu->setBlendFunc(GrDrawTarget::kOne_BlendCoeff, GrDrawTarget::kZero_BlendCoeff);\r
+            fGpu->disableState(GrDrawTarget::kDither_StateBit |\r
+                               GrDrawTarget::kClip_StateBit   |\r
+                               GrDrawTarget::kAntialias_StateBit);\r
             GrSamplerState stretchSampler(GrSamplerState::kClamp_WrapMode,\r
                                           GrSamplerState::kClamp_WrapMode,\r
                                           sampler.isFilter());\r
@@ -171,7 +171,7 @@ GrTextureEntry* GrContext::createAndLockTexture(GrTextureKey* key,
                                               clampTexture->contentHeight() /\r
                                               clampTexture->allocHeight());\r
                 verts[1].setRectFan(0, 0, tw, th, 2*sizeof(GrPoint));\r
-                fGpu->drawNonIndexed(GrGpu::kTriangleFan_PrimitiveType,\r
+                fGpu->drawNonIndexed(GrDrawTarget::kTriangleFan_PrimitiveType,\r
                                      0, 4);\r
                 entry = fTextureCache->createAndLock(*key, texture);\r
             }\r
@@ -275,11 +275,24 @@ bool GrContext::supportsIndex8PixelConfig(const GrSamplerState& sampler,
 \r
 ////////////////////////////////////////////////////////////////////////////////\r
 \r
+void GrContext::setClip(const GrClip& clip) {\r
+    fGpu->setClip(clip);\r
+    fGpu->enableState(GrDrawTarget::kClip_StateBit);\r
+}\r
+\r
+void GrContext::setClip(const GrIRect& rect) {\r
+    GrClip clip;\r
+    clip.setRect(rect);\r
+    fGpu->setClip(clip);\r
+}\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
 void GrContext::eraseColor(GrColor color) {\r
     fGpu->eraseColor(color);\r
 }\r
 \r
-void GrContext::drawFull(bool useTexture) {\r
+void GrContext::drawPaint(const GrPaint& paint) {\r
     // set rect to be big enough to fill the space, but not super-huge, so we\r
     // don't overflow fixed-point implementations\r
     GrRect r(fGpu->getClip().getBounds());\r
@@ -289,8 +302,7 @@ void GrContext::drawFull(bool useTexture) {
     } else {\r
         GrPrintf("---- fGpu->getViewInverse failed\n");\r
     }\r
-\r
-    this->fillRect(r, useTexture);\r
+    this->drawRect(paint, r);\r
 }\r
 \r
 /*  create a triangle strip that strokes the specified triangle. There are 8\r
@@ -314,8 +326,11 @@ static void setStrokeRectStrip(GrPoint verts[10], const GrRect& rect,
     verts[9] = verts[1];\r
 }\r
 \r
-void GrContext::drawRect(const GrRect& rect, bool useTexture, GrScalar width) {\r
-    GrVertexLayout layout = useTexture ?\r
+void GrContext::drawRect(const GrPaint& paint,\r
+                         const GrRect& rect,\r
+                         GrScalar width) {\r
+\r
+    GrVertexLayout layout = (NULL != paint.getTexture()) ?\r
                             GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(0) :\r
                             0;\r
 \r
@@ -325,21 +340,21 @@ void GrContext::drawRect(const GrRect& rect, bool useTexture, GrScalar width) {
         return;\r
     }\r
 \r
-    this->flushText();\r
+    this->prepareToDraw(paint);\r
 \r
     int vertCount;\r
-    GrGpu::PrimitiveType primType;\r
+    GrDrawTarget::PrimitiveType primType;\r
     GrPoint* vertex = geo.positions();\r
 \r
     if (width >= 0) {\r
         if (width > 0) {\r
             vertCount = 10;\r
-            primType = GrGpu::kTriangleStrip_PrimitiveType;\r
+            primType = GrDrawTarget::kTriangleStrip_PrimitiveType;\r
             setStrokeRectStrip(vertex, rect, width);\r
         } else {\r
             // hairline\r
             vertCount = 5;\r
-            primType = GrGpu::kLineStrip_PrimitiveType;\r
+            primType = GrDrawTarget::kLineStrip_PrimitiveType;\r
             vertex[0].set(rect.fLeft, rect.fTop);\r
             vertex[1].set(rect.fRight, rect.fTop);\r
             vertex[2].set(rect.fRight, rect.fBottom);\r
@@ -348,13 +363,111 @@ void GrContext::drawRect(const GrRect& rect, bool useTexture, GrScalar width) {
         }\r
     } else {\r
         vertCount = 4;\r
-        primType = GrGpu::kTriangleFan_PrimitiveType;\r
+        primType = GrDrawTarget::kTriangleFan_PrimitiveType;\r
         vertex->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);\r
     }\r
 \r
     fGpu->drawNonIndexed(primType, 0, vertCount);\r
 }\r
 \r
+void GrContext::drawRectToRect(const GrPaint& paint,\r
+                               const GrRect& dstRect,\r
+                               const GrRect& srcRect) {\r
+\r
+    if (NULL == paint.getTexture()) {\r
+        drawRect(paint, dstRect);\r
+        return;\r
+    }\r
+\r
+    GrVertexLayout layout = GrDrawTarget::StageTexCoordVertexLayoutBit(0,0);\r
+    static const int VCOUNT = 4;\r
+\r
+    GrDrawTarget::AutoReleaseGeometry geo(fGpu, layout, VCOUNT, 0);\r
+    if (!geo.succeeded()) {\r
+        return;\r
+    }\r
+\r
+    this->prepareToDraw(paint);\r
+\r
+    GrPoint* vertex = (GrPoint*) geo.vertices();\r
+\r
+    vertex[0].setRectFan(dstRect.fLeft, dstRect.fTop,\r
+                         dstRect.fRight, dstRect.fBottom,\r
+                         2 * sizeof(GrPoint));\r
+    vertex[1].setRectFan(srcRect.fLeft, srcRect.fTop,\r
+                         srcRect.fRight, srcRect.fBottom,\r
+                         2 * sizeof(GrPoint));\r
+\r
+    fGpu->drawNonIndexed(GrDrawTarget::kTriangleFan_PrimitiveType, 0, VCOUNT);\r
+}\r
+\r
+void GrContext::drawVertices(const GrPaint& paint,\r
+                             GrDrawTarget::PrimitiveType primitiveType,\r
+                             int vertexCount,\r
+                             const GrPoint positions[],\r
+                             const GrPoint texCoords[],\r
+                             const GrColor colors[],\r
+                             const uint16_t indices[],\r
+                             int indexCount) {\r
+    GrVertexLayout layout = 0;\r
+    bool interLeave = false;\r
+\r
+    GrDrawTarget::AutoReleaseGeometry geo;\r
+\r
+    this->prepareToDraw(paint);\r
+\r
+    if (NULL != paint.getTexture()) {\r
+        if (NULL == texCoords) {\r
+            layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(0);\r
+        } else {\r
+            layout |= GrDrawTarget::StageTexCoordVertexLayoutBit(0,0);\r
+            interLeave = true;\r
+        }\r
+    }\r
+\r
+    if (NULL != colors) {\r
+        layout |= GrDrawTarget::kColor_VertexLayoutBit;\r
+    }\r
+\r
+    static const GrVertexLayout interleaveMask =\r
+        (GrDrawTarget::StageTexCoordVertexLayoutBit(0,0) |\r
+         GrDrawTarget::kColor_VertexLayoutBit);\r
+    if (interleaveMask & layout) {\r
+        if (!geo.set(fGpu, layout, vertexCount, 0)) {\r
+            GrPrintf("Failed to get space for vertices!");\r
+            return;\r
+        }\r
+        int texOffsets[GrDrawTarget::kMaxTexCoords];\r
+        int colorOffset;\r
+        int vsize = GrDrawTarget::VertexSizeAndOffsetsByIdx(layout,\r
+                                                            texOffsets,\r
+                                                            &colorOffset);\r
+        void* curVertex = geo.vertices();\r
+\r
+        for (int i = 0; i < vertexCount; ++i) {\r
+            *((GrPoint*)curVertex) = positions[i];\r
+\r
+            if (texOffsets[0] > 0) {\r
+                *(GrPoint*)((intptr_t)curVertex + texOffsets[0]) = texCoords[i];\r
+            }\r
+            if (colorOffset > 0) {\r
+                *(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i];\r
+            }\r
+            curVertex = (void*)((intptr_t)curVertex + vsize);\r
+        }\r
+    } else {\r
+        fGpu->setVertexSourceToArray(positions, layout);\r
+    }\r
+\r
+    if (NULL != indices) {\r
+        fGpu->setIndexSourceToArray(indices);\r
+        fGpu->drawIndexed(primitiveType, 0, 0, vertexCount, indexCount);\r
+    } else {\r
+        fGpu->drawNonIndexed(primitiveType, 0, vertexCount);\r
+    }\r
+}\r
+\r
+\r
 ////////////////////////////////////////////////////////////////////////////////\r
 \r
 #define NEW_EVAL        1   // Use adaptive path tesselation\r
@@ -533,7 +646,6 @@ static int worst_case_point_count(GrPathIter* path,
 \r
 static inline bool single_pass_path(const GrPathIter& path,\r
                                     GrContext::PathFills fill,\r
-                                    bool useTex,\r
                                     const GrGpu& gpu) {\r
 #if STENCIL_OFF\r
     return true;\r
@@ -554,16 +666,18 @@ static inline bool single_pass_path(const GrPathIter& path,
 #endif\r
 }\r
 \r
-void GrContext::drawPath(GrPathIter* path, PathFills fill,\r
-                         bool useTexture, const GrPoint* translate) {\r
+void GrContext::drawPath(const GrPaint& paint,\r
+                         GrPathIter* path,\r
+                         PathFills fill,\r
+                         const GrPoint* translate) {\r
 \r
-    flushText();\r
 \r
-    GrGpu::AutoStateRestore asr(fGpu);\r
+    this->prepareToDraw(paint);\r
+\r
+    GrDrawTarget::AutoStateRestore asr(fGpu);\r
 \r
 #if NEW_EVAL\r
-    GrMatrix viewM;\r
-    fGpu->getViewMatrix(&viewM);\r
+    GrMatrix viewM = fGpu->getViewMatrix();\r
     // In order to tesselate the path we get a bound on how much the matrix can\r
     // stretch when mapping to screen coordinates.\r
     GrScalar stretch = viewM.getMaxStretch();\r
@@ -594,7 +708,8 @@ void GrContext::drawPath(GrPathIter* path, PathFills fill,
 #endif\r
                                         tol);\r
     GrVertexLayout layout = 0;\r
-    if (useTexture) {\r
+\r
+    if (NULL != paint.getTexture()) {\r
         layout = GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(0);\r
     }\r
     // add 4 to hold the bounding rect\r
@@ -609,20 +724,20 @@ void GrContext::drawPath(GrPathIter* path, PathFills fill,
     path->rewind();\r
 \r
     // TODO: use primitve restart if available rather than multiple draws\r
-    GrGpu::PrimitiveType  type;\r
+    GrDrawTarget::PrimitiveType  type;\r
     int                   passCount = 0;\r
-    GrGpu::StencilPass    passes[3];\r
+    GrDrawTarget::StencilPass    passes[3];\r
     bool                  reverse = false;\r
 \r
     if (kHairLine_PathFill == fill) {\r
-        type = GrGpu::kLineStrip_PrimitiveType;\r
+        type = GrDrawTarget::kLineStrip_PrimitiveType;\r
         passCount = 1;\r
-        passes[0] = GrGpu::kNone_StencilPass;\r
+        passes[0] = GrDrawTarget::kNone_StencilPass;\r
     } else {\r
-        type = GrGpu::kTriangleFan_PrimitiveType;\r
-        if (single_pass_path(*path, fill, useTexture, *fGpu)) {\r
+        type = GrDrawTarget::kTriangleFan_PrimitiveType;\r
+        if (single_pass_path(*path, fill, *fGpu)) {\r
             passCount = 1;\r
-            passes[0] = GrGpu::kNone_StencilPass;\r
+            passes[0] = GrDrawTarget::kNone_StencilPass;\r
         } else {\r
             switch (fill) {\r
                 case kInverseEvenOdd_PathFill:\r
@@ -630,21 +745,21 @@ void GrContext::drawPath(GrPathIter* path, PathFills fill,
                     // fallthrough\r
                 case kEvenOdd_PathFill:\r
                     passCount = 2;\r
-                    passes[0] = GrGpu::kEvenOddStencil_StencilPass;\r
-                    passes[1] = GrGpu::kEvenOddColor_StencilPass;\r
+                    passes[0] = GrDrawTarget::kEvenOddStencil_StencilPass;\r
+                    passes[1] = GrDrawTarget::kEvenOddColor_StencilPass;\r
                     break;\r
 \r
                 case kInverseWinding_PathFill:\r
                     reverse = true;\r
                     // fallthrough\r
                 case kWinding_PathFill:\r
-                    passes[0] = GrGpu::kWindingStencil1_StencilPass;\r
+                    passes[0] = GrDrawTarget::kWindingStencil1_StencilPass;\r
                     if (fGpu->supportsSingleStencilPassWinding()) {\r
-                        passes[1] = GrGpu::kWindingColor_StencilPass;\r
+                        passes[1] = GrDrawTarget::kWindingColor_StencilPass;\r
                         passCount = 2;\r
                     } else {\r
-                        passes[1] = GrGpu::kWindingStencil2_StencilPass;\r
-                        passes[2] = GrGpu::kWindingColor_StencilPass;\r
+                        passes[1] = GrDrawTarget::kWindingStencil2_StencilPass;\r
+                        passes[2] = GrDrawTarget::kWindingColor_StencilPass;\r
                         passCount = 3;\r
                     }\r
                     break;\r
@@ -752,11 +867,15 @@ FINISHED:
     if (useBounds) {\r
         GrRect bounds;\r
         if (reverse) {\r
-            GrAssert(NULL != fGpu->currentRenderTarget());\r
+            GrAssert(NULL != fGpu->getRenderTarget());\r
             // draw over the whole world.\r
             bounds.setLTRB(0, 0,\r
-                           GrIntToScalar(fGpu->currentRenderTarget()->width()),\r
-                           GrIntToScalar(fGpu->currentRenderTarget()->height()));\r
+                           GrIntToScalar(fGpu->getRenderTarget()->width()),\r
+                           GrIntToScalar(fGpu->getRenderTarget()->height()));\r
+            GrMatrix vmi;\r
+            if (fGpu->getViewInverse(&vmi)) {\r
+                vmi.mapRect(&bounds);\r
+            }\r
         } else {\r
             bounds.setBounds((GrPoint*)base, vert - base);\r
         }\r
@@ -766,10 +885,11 @@ FINISHED:
 \r
     for (int p = 0; p < passCount; ++p) {\r
         fGpu->setStencilPass(passes[p]);\r
-        if (useBounds && (GrGpu::kEvenOddColor_StencilPass == passes[p] ||\r
-                          GrGpu::kWindingColor_StencilPass == passes[p])) {\r
-            fGpu->drawNonIndexed(GrGpu::kTriangleFan_PrimitiveType,\r
+        if (useBounds && (GrDrawTarget::kEvenOddColor_StencilPass == passes[p] ||\r
+                          GrDrawTarget::kWindingColor_StencilPass == passes[p])) {\r
+            fGpu->drawNonIndexed(GrDrawTarget::kTriangleFan_PrimitiveType,\r
                                  maxPts, 4);\r
+\r
         } else {\r
             int baseVertex = 0;\r
             for (int sp = 0; sp < subpathCnt; ++sp) {\r
@@ -782,6 +902,8 @@ FINISHED:
     }\r
 }\r
 \r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
 void GrContext::flush(bool flushRenderTarget) {\r
     flushText();\r
     if (flushRenderTarget) {\r
@@ -803,6 +925,10 @@ bool GrContext::readPixels(int left, int top, int width, int height,
 void GrContext::writePixels(int left, int top, int width, int height,\r
                             GrTexture::PixelConfig config, const void* buffer,\r
                             size_t stride) {\r
+\r
+    // TODO: when underlying api has a direct way to do this we should use it\r
+    // (e.g. glDrawPixels on desktop GL).\r
+\r
     const GrGpu::TextureDesc desc = {\r
         0, GrGpu::kNone_AALevel, width, height, config\r
     };\r
@@ -830,32 +956,47 @@ void GrContext::writePixels(int left, int top, int width, int height,
     fGpu->setTexture(0, texture);\r
     fGpu->setSamplerState(0, GrSamplerState::ClampNoFilter());\r
 \r
-    this->fillRect(GrRect(0, 0, GrIntToScalar(width), GrIntToScalar(height)),\r
-                   true);\r
-}\r
+    GrVertexLayout layout = GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(0);\r
+    static const int VCOUNT = 4;\r
 \r
+    GrDrawTarget::AutoReleaseGeometry geo(fGpu, layout, VCOUNT, 0);\r
+    if (!geo.succeeded()) {\r
+        return;\r
+    }\r
+    ((GrPoint*)geo.vertices())->setIRectFan(0, 0, width, height);\r
+    fGpu->drawNonIndexed(GrDrawTarget::kTriangleFan_PrimitiveType, 0, VCOUNT);\r
+}\r
 ////////////////////////////////////////////////////////////////////////////////\r
 \r
+void GrContext::SetPaint(const GrPaint& paint, GrDrawTarget* target) {\r
+    target->setTexture(0, paint.getTexture());\r
+    target->setTextureMatrix(0, paint.fTextureMatrix);\r
+    target->setSamplerState(0, paint.fSampler);\r
+    target->setColor(paint.fColor);\r
 \r
-/* -------------------------------------------------------\r
- * Mimicking the GrGpu interface for now\r
- * TODO: define appropriate higher-level API for context\r
- */\r
-\r
-void GrContext::resetContext() {\r
-    fGpu->resetContext();\r
+    if (paint.fDither) {\r
+        target->enableState(GrDrawTarget::kDither_StateBit);\r
+    } else {\r
+        target->disableState(GrDrawTarget::kDither_StateBit);\r
+    }\r
+    if (paint.fAntiAlias) {\r
+        target->enableState(GrDrawTarget::kAntialias_StateBit);\r
+    } else {\r
+        target->disableState(GrDrawTarget::kAntialias_StateBit);\r
+    }\r
+    target->setBlendFunc(paint.fSrcBlendCoeff, paint.fDstBlendCoeff);\r
 }\r
 \r
-GrVertexBuffer* GrContext::createVertexBuffer(uint32_t size, bool dynamic) {\r
-    return fGpu->createVertexBuffer(size, dynamic);\r
-}\r
+void GrContext::prepareToDraw(const GrPaint& paint) {\r
 \r
-GrIndexBuffer* GrContext::createIndexBuffer(uint32_t size, bool dynamic) {\r
-    return fGpu->createIndexBuffer(size, dynamic);\r
+    flushText();\r
+    SetPaint(paint, fGpu);\r
 }\r
 \r
-void GrContext::setTexture(int stage, GrTexture* texture) {\r
-    fGpu->setTexture(stage, texture);\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+void GrContext::resetContext() {\r
+    fGpu->resetContext();\r
 }\r
 \r
 void GrContext::setRenderTarget(GrRenderTarget* target) {\r
@@ -863,93 +1004,24 @@ void GrContext::setRenderTarget(GrRenderTarget* target) {
     fGpu->setRenderTarget(target);\r
 }\r
 \r
-GrRenderTarget* GrContext::currentRenderTarget() const {\r
-    return fGpu->currentRenderTarget();\r
-}\r
-\r
-void GrContext::setSamplerState(int stage, const GrSamplerState& samplerState) {\r
-    fGpu->setSamplerState(stage, samplerState);\r
+GrRenderTarget* GrContext::getRenderTarget() {\r
+    return fGpu->getRenderTarget();\r
 }\r
 \r
-void GrContext::setTextureMatrix(int stage, const GrMatrix& m) {\r
-    fGpu->setTextureMatrix(stage, m);\r
+const GrRenderTarget* GrContext::getRenderTarget() const {\r
+    return fGpu->getRenderTarget();\r
 }\r
 \r
-void GrContext::getViewMatrix(GrMatrix* m) const {\r
-    fGpu->getViewMatrix(m);\r
+const GrMatrix& GrContext::getMatrix() const {\r
+    return fGpu->getViewMatrix();\r
 }\r
 \r
-void GrContext::setViewMatrix(const GrMatrix& m) {\r
+void GrContext::setMatrix(const GrMatrix& m) {\r
     fGpu->setViewMatrix(m);\r
 }\r
 \r
-bool GrContext::reserveAndLockGeometry(GrVertexLayout    vertexLayout,\r
-                                       uint32_t          vertexCount,\r
-                                       uint32_t          indexCount,\r
-                                       void**            vertices,\r
-                                       void**            indices) {\r
-    return fGpu->reserveAndLockGeometry(vertexLayout,\r
-                                        vertexCount,\r
-                                        indexCount,\r
-                                        vertices,\r
-                                        indices);\r
-}\r
-\r
-void GrContext::drawIndexed(GrGpu::PrimitiveType type,\r
-                            uint32_t startVertex,\r
-                            uint32_t startIndex,\r
-                            uint32_t vertexCount,\r
-                            uint32_t indexCount) {\r
-    flushText();\r
-    fGpu->drawIndexed(type,\r
-                      startVertex,\r
-                      startIndex,\r
-                      vertexCount,\r
-                      indexCount);\r
-}\r
-\r
-void GrContext::drawNonIndexed(GrGpu::PrimitiveType type,\r
-                               uint32_t startVertex,\r
-                               uint32_t vertexCount) {\r
-    flushText();\r
-    fGpu->drawNonIndexed(type,\r
-                         startVertex,\r
-                         vertexCount);\r
-}\r
-\r
-void GrContext::setVertexSourceToArray(const void* array,\r
-                                       GrVertexLayout vertexLayout) {\r
-    fGpu->setVertexSourceToArray(array, vertexLayout);\r
-}\r
-\r
-void GrContext::setIndexSourceToArray(const void* array) {\r
-    fGpu->setIndexSourceToArray(array);\r
-}\r
-\r
-void GrContext::setVertexSourceToBuffer(GrVertexBuffer* buffer,\r
-                                       GrVertexLayout vertexLayout) {\r
-    fGpu->setVertexSourceToBuffer(buffer, vertexLayout);\r
-}\r
-\r
-void GrContext::setIndexSourceToBuffer(GrIndexBuffer* buffer) {\r
-    fGpu->setIndexSourceToBuffer(buffer);\r
-}\r
-\r
-void GrContext::releaseReservedGeometry() {\r
-    fGpu->releaseReservedGeometry();\r
-}\r
-\r
-void GrContext::setClip(const GrClip& clip) {\r
-    fGpu->setClip(clip);\r
-    fGpu->enableState(GrDrawTarget::kClip_StateBit);\r
-}\r
-\r
-void GrContext::setAlpha(uint8_t alpha) {\r
-    fGpu->setAlpha(alpha);\r
-}\r
-\r
-void GrContext::setColor(GrColor color) {\r
-    fGpu->setColor(color);\r
+void GrContext::concatMatrix(const GrMatrix& m) const {\r
+    fGpu->concatViewMatrix(m);\r
 }\r
 \r
 static inline intptr_t setOrClear(intptr_t bits, int shift, intptr_t pred) {\r
@@ -962,34 +1034,6 @@ static inline intptr_t setOrClear(intptr_t bits, int shift, intptr_t pred) {
     return bits;\r
 }\r
 \r
-void GrContext::setAntiAlias(bool aa) {\r
-    if (aa) {\r
-        fGpu->enableState(GrGpu::kAntialias_StateBit);\r
-    } else {\r
-        fGpu->disableState(GrGpu::kAntialias_StateBit);\r
-    }\r
-}\r
-\r
-void GrContext::setDither(bool dither) {\r
-    // hack for now, since iPad dither is hella-slow\r
-    dither = false;\r
-\r
-    if (dither) {\r
-        fGpu->enableState(GrGpu::kDither_StateBit);\r
-    } else {\r
-        fGpu->disableState(GrGpu::kDither_StateBit);\r
-    }\r
-}\r
-\r
-void GrContext::setPointSize(float size) {\r
-    fGpu->setPointSize(size);\r
-}\r
-\r
-void GrContext::setBlendFunc(GrGpu::BlendCoeff srcCoef,\r
-                             GrGpu::BlendCoeff dstCoef) {\r
-    fGpu->setBlendFunc(srcCoef, dstCoef);\r
-}\r
-\r
 void GrContext::resetStats() {\r
     fGpu->resetStats();\r
 }\r
@@ -1031,13 +1075,16 @@ bool GrContext::finalizeTextureKey(GrTextureKey* key,
     return 0 != bits;\r
 }\r
 \r
-GrDrawTarget* GrContext::getTextTarget() {\r
+GrDrawTarget* GrContext::getTextTarget(const GrPaint& paint) {\r
+    GrDrawTarget* target;\r
 #if DEFER_TEXT_RENDERING\r
     fTextDrawBuffer.initializeDrawStateAndClip(*fGpu);\r
-    return &fTextDrawBuffer;\r
+    target = &fTextDrawBuffer;\r
 #else\r
-    return fGpu;\r
+    target = fGpu;\r
 #endif\r
+    SetPaint(paint, target);\r
+    return target;\r
 }\r
 \r
 const GrIndexBuffer* GrContext::quadIndexBuffer() const {\r
@@ -1050,4 +1097,3 @@ int GrContext::maxQuadsInIndexBuffer() const {
 \r
 \r
 \r
-\r
index df0f0be..abc9fb4 100644 (file)
@@ -22,7 +22,7 @@
 // one stage
 template <int N>
 static int stage_mask_recur(int stage) {
-    return GrDrawTarget::StageTexCoordVertexLayoutBit(stage, N) | 
+    return GrDrawTarget::StageTexCoordVertexLayoutBit(stage, N) |
            stage_mask_recur<N+1>(stage);
 }
 template<> // linux build doesn't like static on specializations
@@ -35,7 +35,7 @@ static int stage_tex_coord_mask(int stage) {
 
 // mask of all bits relevant to one stage
 static int stage_mask(int stage) {
-    return stage_tex_coord_mask(stage) | 
+    return stage_tex_coord_mask(stage) |
            GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(stage);
 }
 
@@ -43,7 +43,7 @@ static int stage_mask(int stage) {
 // texture coordinate index
 template <int N>
 static int tex_coord_mask_recur(int texCoordIdx) {
-    return GrDrawTarget::StageTexCoordVertexLayoutBit(N, texCoordIdx) | 
+    return GrDrawTarget::StageTexCoordVertexLayoutBit(N, texCoordIdx) |
            tex_coord_mask_recur<N+1>(texCoordIdx);
 }
 template<> // linux build doesn't like static on specializations
@@ -67,8 +67,8 @@ bool check_layout(GrVertexLayout layout) {
 
 size_t GrDrawTarget::VertexSize(GrVertexLayout vertexLayout) {
     GrAssert(check_layout(vertexLayout));
-    
-    size_t vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ? 
+
+    size_t vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
                         sizeof(GrGpuTextVertex) :
                         sizeof(GrPoint);
 
@@ -91,8 +91,8 @@ int GrDrawTarget::VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout)
     }
     int tcIdx = VertexTexCoordsForStage(stage, vertexLayout);
     if (tcIdx >= 0) {
-        
-        int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ? 
+
+        int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
                                     sizeof(GrGpuTextVertex) :
                                     sizeof(GrPoint);
         int offset = vecSize; // position
@@ -110,9 +110,9 @@ int GrDrawTarget::VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout)
 
 int  GrDrawTarget::VertexColorOffset(GrVertexLayout vertexLayout) {
     GrAssert(check_layout(vertexLayout));
-    
+
     if (vertexLayout & kColor_VertexLayoutBit) {
-        int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ? 
+        int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
                                     sizeof(GrGpuTextVertex) :
                                     sizeof(GrPoint);
         int offset = vecSize; // position
@@ -131,15 +131,15 @@ int GrDrawTarget::VertexSizeAndOffsetsByIdx(GrVertexLayout vertexLayout,
                                              int texCoordOffsetsByIdx[kMaxTexCoords],
                                              int* colorOffset) {
     GrAssert(check_layout(vertexLayout));
-    
+
     GrAssert(NULL != texCoordOffsetsByIdx);
     GrAssert(NULL != colorOffset);
 
-    int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ? 
+    int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
                                                     sizeof(GrGpuTextVertex) :
                                                     sizeof(GrPoint);
     int size = vecSize; // position
-    
+
     for (int t = 0; t < kMaxTexCoords; ++t) {
         if (tex_coord_idx_mask(t) & vertexLayout) {
             texCoordOffsetsByIdx[t] = size;
@@ -164,10 +164,10 @@ int GrDrawTarget::VertexSizeAndOffsetsByStage(GrVertexLayout vertexLayout,
 
     GrAssert(NULL != texCoordOffsetsByStage);
     GrAssert(NULL != colorOffset);
-    
+
     int texCoordOffsetsByIdx[kMaxTexCoords];
-    int size = VertexSizeAndOffsetsByIdx(vertexLayout, 
-                                         texCoordOffsetsByIdx, 
+    int size = VertexSizeAndOffsetsByIdx(vertexLayout,
+                                         texCoordOffsetsByIdx,
                                          colorOffset);
     for (int s = 0; s < kNumStages; ++s) {
         int tcIdx;
@@ -179,7 +179,7 @@ int GrDrawTarget::VertexSizeAndOffsetsByStage(GrVertexLayout vertexLayout,
             texCoordOffsetsByStage[s] = -1;
         }
     }
-    return size;    
+    return size;
 }
 
 bool GrDrawTarget::VertexUsesStage(int stage, GrVertexLayout vertexLayout) {
@@ -188,9 +188,9 @@ bool GrDrawTarget::VertexUsesStage(int stage, GrVertexLayout vertexLayout) {
     return !!(stage_mask(stage) & vertexLayout);
 }
 
-bool GrDrawTarget::VertexUsesTexCoordIdx(int coordIndex, 
+bool GrDrawTarget::VertexUsesTexCoordIdx(int coordIndex,
                                          GrVertexLayout vertexLayout) {
-    GrAssert(coordIndex < kMaxTexCoords);     
+    GrAssert(coordIndex < kMaxTexCoords);
     GrAssert(check_layout(vertexLayout));
     return !!(tex_coord_idx_mask(coordIndex) & vertexLayout);
 }
@@ -222,7 +222,7 @@ void GrDrawTarget::VertexLayoutUnitTest() {
             for (int t = 0; t < kMaxTexCoords; ++t) {
                 stageMask |= StageTexCoordVertexLayoutBit(s,t);
             }
-            GrAssert(1 == kMaxTexCoords || !check_layout(stageMask));            
+            GrAssert(1 == kMaxTexCoords || !check_layout(stageMask));
             GrAssert(stage_tex_coord_mask(s) == stageMask);
             stageMask |= StagePosAsTexCoordVertexLayoutBit(s);
             GrAssert(stage_mask(s) == stageMask);
@@ -242,7 +242,7 @@ void GrDrawTarget::VertexLayoutUnitTest() {
                     GrAssert(-1 == VertexStageCoordOffset(s2, tcMask));
                     GrAssert(!VertexUsesStage(s2, tcMask));
                     GrAssert(-1 == VertexTexCoordsForStage(s2, tcMask));
-                    
+
                     GrVertexLayout posAsTex = tcMask | StagePosAsTexCoordVertexLayoutBit(s2);
                     GrAssert(0 == VertexStageCoordOffset(s2, posAsTex));
                     GrAssert(VertexUsesStage(s2, posAsTex));
@@ -255,7 +255,7 @@ void GrDrawTarget::VertexLayoutUnitTest() {
             }
             GrAssert(tex_coord_idx_mask(t) == tcMask);
             GrAssert(check_layout(tcMask));
-            
+
             int stageOffsets[kNumStages];
             int colorOffset;
             int size;
@@ -300,7 +300,12 @@ void GrDrawTarget::setTexture(int stage, GrTexture* tex) {
     fCurrDrawState.fTextures[stage] = tex;
 }
 
-GrTexture* GrDrawTarget::currentTexture(int stage) const {
+const GrTexture* GrDrawTarget::getTexture(int stage) const {
+    GrAssert(stage >= 0 && stage < kNumStages);
+    return fCurrDrawState.fTextures[stage];
+}
+
+GrTexture* GrDrawTarget::getTexture(int stage) {
     GrAssert(stage >= 0 && stage < kNumStages);
     return fCurrDrawState.fTextures[stage];
 }
@@ -309,7 +314,11 @@ void GrDrawTarget::setRenderTarget(GrRenderTarget* target) {
     fCurrDrawState.fRenderTarget = target;
 }
 
-GrRenderTarget* GrDrawTarget::currentRenderTarget() const {
+const GrRenderTarget* GrDrawTarget::getRenderTarget() const {
+    return fCurrDrawState.fRenderTarget;
+}
+
+GrRenderTarget* GrDrawTarget::getRenderTarget() {
     return fCurrDrawState.fRenderTarget;
 }
 
@@ -321,13 +330,12 @@ void GrDrawTarget::concatViewMatrix(const GrMatrix& matrix) {
     fCurrDrawState.fViewMatrix.preConcat(matrix);
 }
 
-// Can't this just return a const&
-void GrDrawTarget::getViewMatrix(GrMatrix* matrix) const {
-    *matrix = fCurrDrawState.fViewMatrix;
+const GrMatrix& GrDrawTarget::getViewMatrix() const {
+    return fCurrDrawState.fViewMatrix;
 }
 
 bool GrDrawTarget::getViewInverse(GrMatrix* matrix) const {
-    // Mike:  Can we cache this somewhere? 
+    // Mike:  Can we cache this somewhere?
     // Brian: Sure, do we use it often?
 
     GrMatrix inverse;
@@ -366,10 +374,6 @@ void GrDrawTarget::disableState(uint32_t bits) {
     fCurrDrawState.fFlagBits &= ~(bits);
 }
 
-void GrDrawTarget::setPointSize(float size) {
-    fCurrDrawState.fPointSize = size;
-}
-
 void GrDrawTarget::setBlendFunc(BlendCoeff srcCoef,
                                 BlendCoeff dstCoef) {
     fCurrDrawState.fSrcBlend = srcCoef;
index 63cf237..1dbc5fb 100644 (file)
@@ -415,7 +415,6 @@ void GrGpuGL::resetContextHelper() {
     fHWDrawState.fSrcBlend = (BlendCoeff)-1;
     fHWDrawState.fDstBlend = (BlendCoeff)-1;
     fHWDrawState.fColor = GrColor_ILLEGAL;
-    fHWDrawState.fPointSize = -1;
 
     fHWDrawState.fViewMatrix.setScale(GR_ScalarMax, GR_ScalarMax); // illegal
 
@@ -501,6 +500,8 @@ GrRenderTarget* GrGpuGL::createRenderTargetFrom3DApiState() {
                                 this);
 }
 
+///////////////////////////////////////////////////////////////////////////////
+
 // defines stencil formats from more to less preferred
 GLenum GR_GL_STENCIL_FORMAT_ARRAY[] = {
     GR_STENCIL_INDEX8,
@@ -852,7 +853,7 @@ GrTexture* GrGpuGL::createTexture(const TextureDesc& desc,
                 // bind the stencil to rt fbo if present, othewise the tex fbo
                 GR_GLEXT(fExts, FramebufferRenderbuffer(GR_FRAMEBUFFER,
                                                  GR_STENCIL_ATTACHMENT,
-                                                GR_RENDERBUFFER,
+                                                 GR_RENDERBUFFER,
                                                  rtIDs.fStencilRenderbufferID));
             }
             status = GR_GLEXT(fExts, CheckFramebufferStatus(GR_FRAMEBUFFER));
index 611485d..dbc5de3 100644 (file)
@@ -85,7 +85,7 @@ protected:
 
     void eraseStencil(uint32_t value, uint32_t mask);
     virtual void eraseStencilClip();
-    
+
     void setTextureUnit(int unitIdx);
 
     // flushes state that is common to fixed and programmable GL
@@ -123,7 +123,7 @@ private:
     void notifyTextureDelete(GrGLTexture* texture);
     void notifyRenderTargetDelete(GrRenderTarget* renderTarget);
     void notifyTextureRemoveRenderTarget(GrGLTexture* texture);
-    
+
     void setSpareTextureUnit();
 
     void flushRenderTarget();
@@ -156,9 +156,9 @@ private:
 
     // ES requires an extension to support RGBA8 in RenderBufferStorage
     bool fRGBA8Renderbuffer;
-    
+
     int fActiveTextureUnitIdx;
-    
+
     typedef GrGpu INHERITED;
 };
 
index 99a593d..3fd8d5c 100644 (file)
 
 struct GrGpuMatrix {
     GrScalar    fMat[16];
-    
+
     void reset() {
         Gr_bzero(fMat, sizeof(fMat));
         fMat[0] = fMat[5] = fMat[10] = fMat[15] = GR_Scalar1;
     }
-    
+
     void set(const GrMatrix& m) {
         Gr_bzero(fMat, sizeof(fMat));
         fMat[0]  = m[GrMatrix::kScaleX];
         fMat[4]  = m[GrMatrix::kSkewX];
         fMat[12] = m[GrMatrix::kTransX];
-        
+
         fMat[1]  = m[GrMatrix::kSkewY];
         fMat[5]  = m[GrMatrix::kScaleY];
         fMat[13] = m[GrMatrix::kTransY];
-        
+
         fMat[3]  = m[GrMatrix::kPersp0];
         fMat[7]  = m[GrMatrix::kPersp1];
         fMat[15] = m[GrMatrix::kPersp2];
-        
+
         fMat[10] = GR_Scalar1;    // z-scale
     }
 };
@@ -74,7 +74,7 @@ void GrGpuGLFixed::resetContextHelper() {
 
     for (int s = 0; s < kNumStages; ++s) {
         setTextureUnit(s);
-        GR_GL(EnableClientState(GL_VERTEX_ARRAY));    
+        GR_GL(EnableClientState(GL_VERTEX_ARRAY));
         GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE));
         GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB,   GL_MODULATE));
         GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB,      GL_TEXTURE0+s));
@@ -86,12 +86,12 @@ void GrGpuGLFixed::resetContextHelper() {
         GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA));
         GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS));
         GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA));
-        
-        // color oprand0 changes between GL_SRC_COLR and GL_SRC_ALPHA depending 
-        // upon whether we have a (premultiplied) RGBA texture or just an ALPHA 
+
+        // color oprand0 changes between GL_SRC_COLR and GL_SRC_ALPHA depending
+        // upon whether we have a (premultiplied) RGBA texture or just an ALPHA
         // texture, e.g.:
         //glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB,  GL_SRC_COLOR);
-        fHWRGBOperand0[s] = (TextureEnvRGBOperands) -1;    
+        fHWRGBOperand0[s] = (TextureEnvRGBOperands) -1;
     }
 
     fHWGeometryState.fVertexLayout = 0;
@@ -100,11 +100,13 @@ void GrGpuGLFixed::resetContextHelper() {
     GR_GL(DisableClientState(GL_TEXTURE_COORD_ARRAY));
     GR_GL(ShadeModel(GL_FLAT));
     GR_GL(DisableClientState(GL_COLOR_ARRAY));
-    
+
+    GR_GL(PointSize(1.f));
+
     GrGLClearErr();
     fTextVerts = false;
 
-    fHWTextureOrientation = (GrGLTexture::Orientation)-1; // illegal    
+    fHWTextureOrientation = (GrGLTexture::Orientation)-1; // illegal
     fBaseVertex = 0xffffffff;
 }
 
@@ -112,25 +114,25 @@ void GrGpuGLFixed::resetContextHelper() {
 void GrGpuGLFixed::flushProjectionMatrix() {
     float mat[16];
     Gr_bzero(mat, sizeof(mat));
-    
+
     GrAssert(NULL != fCurrDrawState.fRenderTarget);
-    
+
     mat[0] = 2.f / fCurrDrawState.fRenderTarget->width();
     mat[5] = -2.f / fCurrDrawState.fRenderTarget->height();
     mat[10] = -1.f;
     mat[15] = 1;
-    
+
     mat[12] = -1.f;
     mat[13] = 1.f;
-    
+
     GR_GL(MatrixMode(GL_PROJECTION));
     GR_GL(LoadMatrixf(mat));
 }
 
 bool GrGpuGLFixed::flushGraphicsState(PrimitiveType type) {
-    
+
     bool usingTextures[kNumStages];
-    
+
     for (int s = 0; s < kNumStages; ++s) {
         usingTextures[s] = VertexUsesStage(s, fGeometrySrc.fVertexLayout);
 
@@ -139,16 +141,16 @@ bool GrGpuGLFixed::flushGraphicsState(PrimitiveType type) {
             return false;
         }
     }
-    
+
     if (!flushGLStateCommon(type)) {
         return false;
     }
 
-    if (fRenderTargetChanged) {    
+    if (fRenderTargetChanged) {
         flushProjectionMatrix();
         fRenderTargetChanged = false;
     }
-    
+
     for (int s = 0; s < kNumStages; ++s) {
         bool wasUsingTexture = VertexUsesStage(s, fHWGeometryState.fVertexLayout);
         if (usingTextures[s] != wasUsingTexture) {
@@ -160,11 +162,11 @@ bool GrGpuGLFixed::flushGraphicsState(PrimitiveType type) {
             }
         }
     }
-        
+
     uint32_t vertColor = (fGeometrySrc.fVertexLayout & kColor_VertexLayoutBit);
-    uint32_t prevVertColor = (fHWGeometryState.fVertexLayout & 
+    uint32_t prevVertColor = (fHWGeometryState.fVertexLayout &
                               kColor_VertexLayoutBit);
-    
+
     if (vertColor != prevVertColor) {
         if (vertColor) {
             GR_GL(ShadeModel(GL_SMOOTH));
@@ -175,12 +177,7 @@ bool GrGpuGLFixed::flushGraphicsState(PrimitiveType type) {
         }
     }
 
-    if (kPoints_PrimitiveType == type &&
-        fHWDrawState.fPointSize != fCurrDrawState.fPointSize) {
-        GR_GL(PointSize(fCurrDrawState.fPointSize));
-        fHWDrawState.fPointSize = fCurrDrawState.fPointSize;
-    }
-    
+
     if (!vertColor && fHWDrawState.fColor != fCurrDrawState.fColor) {
         GR_GL(Color4ub(GrColorUnpackR(fCurrDrawState.fColor),
                        GrColorUnpackG(fCurrDrawState.fColor),
@@ -194,25 +191,25 @@ bool GrGpuGLFixed::flushGraphicsState(PrimitiveType type) {
         if (usingTextures[s]) {
             GrGLTexture* texture = (GrGLTexture*)fCurrDrawState.fTextures[s];
             if (NULL != texture) {
-                TextureEnvRGBOperands nextRGBOperand0 = 
-                    (texture->config() == GrTexture::kAlpha_8_PixelConfig) ? 
-                        kAlpha_TextureEnvRGBOperand : 
+                TextureEnvRGBOperands nextRGBOperand0 =
+                    (texture->config() == GrTexture::kAlpha_8_PixelConfig) ?
+                        kAlpha_TextureEnvRGBOperand :
                         kColor_TextureEnvRGBOperand;
                 if (fHWRGBOperand0[s] != nextRGBOperand0) {
                     setTextureUnit(s);
-                    GR_GL(TexEnvi(GL_TEXTURE_ENV, 
+                    GR_GL(TexEnvi(GL_TEXTURE_ENV,
                                   GL_OPERAND0_RGB,
-                                  (nextRGBOperand0==kAlpha_TextureEnvRGBOperand) ? 
-                                    GL_SRC_ALPHA : 
+                                  (nextRGBOperand0==kAlpha_TextureEnvRGBOperand) ?
+                                    GL_SRC_ALPHA :
                                     GL_SRC_COLOR));
                     fHWRGBOperand0[s] = nextRGBOperand0;
                 }
-                
+
                 if (fHWTextureOrientation != texture->orientation() ||
-                    fHWDrawState.fTextureMatrices[s] != 
+                    fHWDrawState.fTextureMatrices[s] !=
                     fCurrDrawState.fTextureMatrices[s]) {
                     GrGpuMatrix glm;
-                    if (GrGLTexture::kBottomUp_Orientation == 
+                    if (GrGLTexture::kBottomUp_Orientation ==
                         texture->orientation()) {
                         GrMatrix m(
                             GR_Scalar1, 0, 0,
@@ -227,7 +224,7 @@ bool GrGpuGLFixed::flushGraphicsState(PrimitiveType type) {
                     setTextureUnit(s);
                     GR_GL(MatrixMode(GL_TEXTURE));
                     GR_GL(LoadMatrixf(glm.fMat));
-                    fHWDrawState.fTextureMatrices[s] = 
+                    fHWDrawState.fTextureMatrices[s] =
                                             fCurrDrawState.fTextureMatrices[s];
                     fHWTextureOrientation = texture->orientation();
                 }
@@ -243,7 +240,7 @@ bool GrGpuGLFixed::flushGraphicsState(PrimitiveType type) {
         glm.set(fCurrDrawState.fViewMatrix);
         GR_GL(MatrixMode(GL_MODELVIEW));
         GR_GL(LoadMatrixf(glm.fMat));
-        fHWDrawState.fViewMatrix = 
+        fHWDrawState.fViewMatrix =
         fCurrDrawState.fViewMatrix;
     }
     return true;
@@ -253,49 +250,49 @@ void GrGpuGLFixed::setupGeometry(uint32_t startVertex,
                                  uint32_t startIndex,
                                  uint32_t vertexCount,
                                  uint32_t indexCount) {
-    
+
     int newColorOffset;
     int newTexCoordOffsets[kNumStages];
-    
+
     GLsizei newStride = VertexSizeAndOffsetsByStage(fGeometrySrc.fVertexLayout,
-                                                    newTexCoordOffsets, 
+                                                    newTexCoordOffsets,
                                                     &newColorOffset);
     int oldColorOffset;
     int oldTexCoordOffsets[kNumStages];
     GLsizei oldStride = VertexSizeAndOffsetsByStage(fHWGeometryState.fVertexLayout,
-                                                    oldTexCoordOffsets, 
+                                                    oldTexCoordOffsets,
                                                     &oldColorOffset);
-    
+
     const GLvoid* posPtr = (GLvoid*)(newStride * startVertex);
-    
+
     if (kBuffer_GeometrySrcType == fGeometrySrc.fVertexSrc) {
         GrAssert(NULL != fGeometrySrc.fVertexBuffer);
         GrAssert(!fGeometrySrc.fVertexBuffer->isLocked());
         if (fHWGeometryState.fVertexBuffer != fGeometrySrc.fVertexBuffer) {
-            GrGLVertexBuffer* buf = 
+            GrGLVertexBuffer* buf =
                             (GrGLVertexBuffer*)fGeometrySrc.fVertexBuffer;
             GR_GL(BindBuffer(GL_ARRAY_BUFFER, buf->bufferID()));
             fHWGeometryState.fVertexBuffer = fGeometrySrc.fVertexBuffer;
         }
-    } else { 
+    } else {
         if (kArray_GeometrySrcType == fGeometrySrc.fVertexSrc) {
-            posPtr = (void*)((intptr_t)fGeometrySrc.fVertexArray + 
+            posPtr = (void*)((intptr_t)fGeometrySrc.fVertexArray +
                              (intptr_t)posPtr);
         } else {
             GrAssert(kReserved_GeometrySrcType == fGeometrySrc.fVertexSrc);
-            posPtr = (void*)((intptr_t)fVertices.get() + (intptr_t)posPtr);            
+            posPtr = (void*)((intptr_t)fVertices.get() + (intptr_t)posPtr);
         }
         if (NULL != fHWGeometryState.fVertexBuffer) {
             GR_GL(BindBuffer(GL_ARRAY_BUFFER, 0));
             fHWGeometryState.fVertexBuffer = NULL;
         }
     }
-    
+
     if (kBuffer_GeometrySrcType == fGeometrySrc.fIndexSrc) {
         GrAssert(NULL != fGeometrySrc.fIndexBuffer);
         GrAssert(!fGeometrySrc.fIndexBuffer->isLocked());
         if (fHWGeometryState.fIndexBuffer != fGeometrySrc.fIndexBuffer) {
-            GrGLIndexBuffer* buf = 
+            GrGLIndexBuffer* buf =
             (GrGLIndexBuffer*)fGeometrySrc.fIndexBuffer;
             GR_GL(BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf->bufferID()));
             fHWGeometryState.fIndexBuffer = fGeometrySrc.fIndexBuffer;
@@ -304,29 +301,29 @@ void GrGpuGLFixed::setupGeometry(uint32_t startVertex,
         GR_GL(BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
         fHWGeometryState.fIndexBuffer = NULL;
     }
-    
+
     GLenum scalarType;
     if (fGeometrySrc.fVertexLayout & kTextFormat_VertexLayoutBit) {
         scalarType = GrGLTextType;
     } else {
         scalarType = GrGLType;
     }
-    
+
     bool baseChange = posPtr != fHWGeometryState.fPositionPtr;
-    bool scalarChange = 
+    bool scalarChange =
         (GrGLTextType != GrGLType) &&
         (kTextFormat_VertexLayoutBit &
          (fHWGeometryState.fVertexLayout ^ fGeometrySrc.fVertexLayout));
     bool strideChange = newStride != oldStride;
     bool posChange = baseChange || scalarChange || strideChange;
-    
+
     if (posChange) {
         GR_GL(VertexPointer(2, scalarType, newStride, posPtr));
         fHWGeometryState.fPositionPtr = posPtr;
     }
-    
+
     for (int s = 0; s < kNumStages; ++s) {
-        // need to enable array if tex coord offset is 0 
+        // need to enable array if tex coord offset is 0
         // (using positions as coords)
         if (newTexCoordOffsets[s] >= 0) {
             GLvoid* texCoordPtr = (int8_t*)posPtr + newTexCoordOffsets[s];
@@ -343,7 +340,7 @@ void GrGpuGLFixed::setupGeometry(uint32_t startVertex,
             GR_GL(DisableClientState(GL_TEXTURE_COORD_ARRAY));
         }
     }
-    
+
     if (newColorOffset > 0) {
         GLvoid* colorPtr = (int8_t*)posPtr + newColorOffset;
         if (oldColorOffset <= 0) {
@@ -355,7 +352,7 @@ void GrGpuGLFixed::setupGeometry(uint32_t startVertex,
     } else if (oldColorOffset > 0) {
         GR_GL(DisableClientState(GL_COLOR_ARRAY));
     }
-    
+
     fHWGeometryState.fVertexLayout = fGeometrySrc.fVertexLayout;
 }
 
index 0a777d6..59a907e 100644 (file)
@@ -23,7 +23,7 @@
 #include "GrTextStrike_impl.h"
 #include "GrFontScaler.h"
 
-static const GrVertexLayout VLAYOUT = 
+static const GrVertexLayout VLAYOUT =
                                 GrDrawTarget::kTextFormat_VertexLayoutBit |
                                 GrDrawTarget::StageTexCoordVertexLayoutBit(0,0);
 
@@ -57,7 +57,9 @@ void GrTextContext::flushGlyphs() {
     }
 }
 
-GrTextContext::GrTextContext(GrContext* context, const GrMatrix* extMatrix) {
+GrTextContext::GrTextContext(GrContext* context,
+                             const GrPaint& paint,
+                             const GrMatrix* extMatrix) : fPaint(paint) {
     fContext = context;
     fStrike = NULL;
 
@@ -80,17 +82,17 @@ GrTextContext::GrTextContext(GrContext* context, const GrMatrix* extMatrix) {
         }
     }
 
-    fContext->getViewMatrix(&fOrigViewMatrix);
-    fContext->setViewMatrix(fExtMatrix);
+    fOrigViewMatrix = fContext->getMatrix();
+    fContext->setMatrix(fExtMatrix);
 
     fVertices = NULL;
     fMaxVertices = 0;
-    fDrawTarget = fContext->getTextTarget();
+    fDrawTarget = fContext->getTextTarget(fPaint);
 }
 
 GrTextContext::~GrTextContext() {
     this->flushGlyphs();
-    fContext->setViewMatrix(fOrigViewMatrix);
+    fContext->setMatrix(fOrigViewMatrix);
 }
 
 void GrTextContext::flush() {
@@ -161,12 +163,11 @@ void GrTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
             glyph->fPath = path;
         }
         GrPath::Iter iter(*glyph->fPath);
-        bool useTexture = false;
         GrPoint translate;
         translate.set(GrFixedToScalar(vx - GrIntToFixed(glyph->fBounds.fLeft)),
                       GrFixedToScalar(vy - GrIntToFixed(glyph->fBounds.fTop)));
-        fContext->drawPath(&iter, GrContext::kWinding_PathFill,
-                              useTexture, &translate);
+        fContext->drawPath(fPaint, &iter, GrContext::kWinding_PathFill,
+                           &translate);
         return;
     }
 
@@ -196,7 +197,7 @@ HAS_ATLAS:
         if (flush) {
             this->flushGlyphs();
             fContext->flushText();
-            fDrawTarget = fContext->getTextTarget();
+            fDrawTarget = fContext->getTextTarget(fPaint);
             fMaxVertices = kDefaultRequestedVerts;
             // ignore return, no point in flushing again.
             fDrawTarget->geometryHints(VLAYOUT,
index 9c612c5..49a14da 100644 (file)
@@ -143,6 +143,7 @@ protected:
 
 private:
     GrContext*      fContext;
+
     GrSkDrawProcs*  fDrawProcs;
 
     // state for our offscreen render-target
@@ -152,28 +153,27 @@ private:
     bool            fNeedClear;
     bool            fNeedPrepareRenderTarget;
 
-    SkDrawProcs* initDrawForText(const SkPaint&, GrTextContext*);
-    bool bindDeviceAsTexture(SkPoint* max);
+    // doesn't set the texture/sampler/matrix state
+    // caller needs to null out GrPaint's texture if
+    // non-textured drawing is desired.
+    bool skPaint2GrPaintNoShader(const SkPaint& skPaint,
+                                 bool justAlpha,
+                                 GrPaint* grPaint);
 
-    void prepareRenderTarget(const SkDraw&);
-    void internalDrawBitmap(const SkDraw&, const SkBitmap&,
-                            const SkIRect&, const SkMatrix&, const SkPaint&);
-
-    class AutoPaintShader {
-    public:
-        AutoPaintShader();
-        AutoPaintShader(SkGpuDevice*, const SkPaint& paint, const SkMatrix&);
+    // uses the SkShader to setup paint, act used to
+    // hold lock on cached texture and free it when
+    // destroyed.
+    bool skPaint2GrPaintShader(const SkPaint& skPaint,
+                               SkAutoCachedTexture* act,
+                               const SkMatrix& ctm,
+                               GrPaint* grPaint);
 
-        void init(SkGpuDevice*, const SkPaint& paint, const SkMatrix&);
+    SkDrawProcs* initDrawForText(GrTextContext*);
+    bool bindDeviceAsTexture(GrPaint* paint, SkPoint* max);
 
-        bool failed() const { return !fSuccess; }
-        bool useTex() const { return fTexture != 0; }
-    private:
-        GrTexture*              fTexture;
-        SkAutoCachedTexture     fCachedTexture;
-        bool                    fSuccess;
-    };
-    friend class AutoPaintShader;
+    void prepareRenderTarget(const SkDraw&);
+    void internalDrawBitmap(const SkDraw&, const SkBitmap&,
+                            const SkIRect&, const SkMatrix&, GrPaint* grPaint);
 
     typedef SkDevice INHERITED;
 };
index 4e9801f..2987639 100644 (file)
@@ -55,7 +55,7 @@
     #endif
     #define SkScalarToGrScalar(x)       SkScalarToFloat(x)
 
-#else 
+#else
     #error "Ganesh scalar type not defined"
 #endif
 
@@ -72,7 +72,7 @@
 GR_STATIC_ASSERT((int)GrSamplerState::kClamp_WrapMode == (int)SkShader::kClamp_TileMode);
 GR_STATIC_ASSERT((int)GrSamplerState::kRepeat_WrapMode ==(
                  int)SkShader::kRepeat_TileMode);
-GR_STATIC_ASSERT((int)GrSamplerState::kMirror_WrapMode == 
+GR_STATIC_ASSERT((int)GrSamplerState::kMirror_WrapMode ==
                  (int)SkShader::kMirror_TileMode);
 
 #define sk_tile_mode_to_grwrap(X) ((GrSamplerState::WrapMode)(X))
@@ -117,13 +117,13 @@ public:
         memcpy(dst, &src, sizeof(*dst));
         return *dst;
     }
-    
+
     static inline GrIRect& SetIRect(GrIRect* dst, const SkIRect& src) {
         GR_STATIC_ASSERT(sizeof(*dst) == sizeof(src));
         memcpy(dst, &src, sizeof(*dst));
         return *dst;
     }
-    
+
     /**
      *  Convert the SkBitmap::Config to the corresponding PixelConfig, or
      *  kUnknown_PixelConfig if the conversion cannot be done.
@@ -146,7 +146,7 @@ public:
                   SkScalarToGrScalar(m[7]),
                   SkScalarToGrScalar(m[8]));
     }
-    
+
     static GrColor SkColor2GrColor(SkColor c) {
         SkPMColor pm = SkPreMultiplyColor(c);
         unsigned r = SkGetPackedR32(pm);
@@ -176,7 +176,7 @@ public:
     virtual void rewind();
     virtual ConvexHint hint() const;
 private:
-    
+
 #if !SK_SCALAR_IS_GR_SCALAR
     SkPoint             fPoints[4];
 #endif
@@ -190,9 +190,9 @@ public:
         fIter.reset(clip);
         this->invalidateBoundsCache();
     }
-    
+
     // overrides
-    
+
     virtual bool isDone() { return fIter.done(); }
     virtual void getRect(GrIRect* rect) {
         SkGr::SetIRect(rect, fIter.rect());
@@ -228,11 +228,10 @@ private:
 ////////////////////////////////////////////////////////////////////////////////
 // Helper functions
 
-GrTextureEntry* sk_gr_create_bitmap_texture(GrContext* ctx, 
+GrTextureEntry* sk_gr_create_bitmap_texture(GrContext* ctx,
                                             GrTextureKey* key,
                                             const GrSamplerState& sampler,
                                             const SkBitmap& bitmap);
 
-void sk_gr_set_paint(GrContext* ctx, const SkPaint& paint, bool justAlpha = false);
 
 #endif
index bf8cb6b..e77562a 100644 (file)
@@ -167,7 +167,6 @@ private:
     SkPicture* fPicture;
     SkGpuCanvas* fGpuCanvas;
     GrContext* fGrContext;
-    GrRenderTarget* fGrRenderTarget;
     SkPath fClipPath;
 
     enum CanvasType {
@@ -219,19 +218,14 @@ bool SampleWindow::make3DReady() {
     #endif
 
     if (NULL == fGrContext) {
-        SkASSERT(NULL == fGrRenderTarget);
     #if defined(SK_USE_SHADERS)
         fGrContext = GrContext::Create(GrGpu::kOpenGL_Shaders_Engine, NULL);
     #else
         fGrContext = GrContext::Create(GrGpu::kOpenGL_Fixed_Engine, NULL);
     #endif
-        if (NULL != fGrContext) {
-            fGrRenderTarget = fGrContext->createRenderTargetFrom3DApiState();
-        }
     }
 
     if (NULL != fGrContext) {
-        SkASSERT(NULL != fGrRenderTarget);
         return true;
     } else {
         detachGL();
@@ -255,7 +249,6 @@ SampleWindow::SampleWindow(void* hwnd) : INHERITED(hwnd) {
     fGpuCanvas = NULL;
 
     fGrContext = NULL;
-    fGrRenderTarget = NULL;
 
 #ifdef DEFAULT_TO_GPU
     fCanvasType = kGPU_CanvasType;
@@ -291,9 +284,6 @@ SampleWindow::SampleWindow(void* hwnd) : INHERITED(hwnd) {
 SampleWindow::~SampleWindow() {
     delete fPicture;
     delete fGpuCanvas;
-    if (NULL != fGrRenderTarget) {
-        fGrRenderTarget->unref();
-    }
     if (NULL != fGrContext) {
         fGrContext->unref();
     }
@@ -414,7 +404,11 @@ SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) {
                 SkDevice* device = canvas->getDevice();
                 const SkBitmap& bitmap = device->accessBitmap(true);
 
-                fGpuCanvas = new SkGpuCanvas(fGrContext, fGrRenderTarget);
+                GrRenderTarget* renderTarget;
+                renderTarget = fGrContext->createRenderTargetFrom3DApiState();
+                fGpuCanvas = new SkGpuCanvas(fGrContext, renderTarget);
+                renderTarget->unref();
+
                 device = fGpuCanvas->createDevice(SkBitmap::kARGB_8888_Config,
                                                   bitmap.width(), bitmap.height(),
                                                   false, false);
index f14de35..11f030e 100644 (file)
@@ -82,7 +82,6 @@ GrTexture* SkGpuDevice::SkAutoCachedTexture::set(SkGpuDevice* device,
     if (texture) {
         // return the native texture
         fTex = NULL;
-        device->context()->setTexture(0, texture);
     } else {
         // look it up in our cache
         fTex = device->lockCachedTexture(bitmap, sampler, &texture, false);
@@ -121,8 +120,8 @@ SkGpuDevice::SkGpuDevice(GrContext* context,
     fNeedPrepareRenderTarget = false;
     fDrawProcs = NULL;
 
-    // should I ref() this, and then unref in destructor? <mrr>
     fContext = context;
+    fContext->ref();
 
     fCache = NULL;
     fTexture = NULL;
@@ -197,6 +196,7 @@ SkGpuDevice::~SkGpuDevice() {
     } else if (NULL != fRenderTarget) {
         fRenderTarget->unref();
     }
+    fContext->unref();
 }
 
 intptr_t SkGpuDevice::getLayerTextureHandle() const {
@@ -271,7 +271,7 @@ static void convert_matrixclip(GrContext* context, const SkMatrix& matrix,
                                const SkRegion& clip) {
     GrMatrix grmat;
     SkGr::SkMatrix2GrMatrix(matrix, &grmat);
-    context->setViewMatrix(grmat);
+    context->setMatrix(grmat);
 
     SkGrClipIterator iter;
     iter.reset(clip);
@@ -286,7 +286,7 @@ static void convert_matrixclip(GrContext* context, const SkMatrix& matrix,
 // and not the state from some other canvas/device
 void SkGpuDevice::prepareRenderTarget(const SkDraw& draw) {
     if (fNeedPrepareRenderTarget ||
-        fContext->currentRenderTarget() != fRenderTarget) {
+        fContext->getRenderTarget() != fRenderTarget) {
 
         fContext->setRenderTarget(fRenderTarget);
         convert_matrixclip(fContext, *draw.fMatrix, *draw.fClip);
@@ -314,9 +314,9 @@ void SkGpuDevice::gainFocus(SkCanvas* canvas, const SkMatrix& matrix,
     }
 }
 
-bool SkGpuDevice::bindDeviceAsTexture(SkPoint* max) {
+bool SkGpuDevice::bindDeviceAsTexture(GrPaint* paint, SkPoint* max) {
     if (NULL != fTexture) {
-        fContext->setTexture(0, fTexture);
+        paint->setTexture(fTexture);
         if (NULL != max) {
             max->set(SkFixedToScalar((width() << 16) /
                                      fTexture->allocWidth()),
@@ -330,39 +330,68 @@ bool SkGpuDevice::bindDeviceAsTexture(SkPoint* max) {
 
 ///////////////////////////////////////////////////////////////////////////////
 
-// must be in the same order as SkXfermode::Coeff in SkXfermode.h
+// must be in SkShader::BitmapTypeOrder
 
-SkGpuDevice::AutoPaintShader::AutoPaintShader() {
-    fSuccess = false;
-    fTexture = NULL;
-}
+static const GrSamplerState::SampleMode sk_bmp_type_to_sample_mode[] = {
+    (GrSamplerState::SampleMode) -1,                    // kNone_BitmapType
+    GrSamplerState::kNormal_SampleMode,                 // kDefault_BitmapType
+    GrSamplerState::kRadial_SampleMode,                 // kRadial_BitmapType
+    GrSamplerState::kSweep_SampleMode,                  // kSweep_BitmapType
+    GrSamplerState::kRadial2_SampleMode,                // kTwoPointRadial_BitmapType
+};
 
-SkGpuDevice::AutoPaintShader::AutoPaintShader(SkGpuDevice* device,
-                                              const SkPaint& paint,
-                                              const SkMatrix& matrix) {
-    fSuccess = false;
-    fTexture = NULL;
-    this->init(device, paint, matrix);
+bool SkGpuDevice::skPaint2GrPaintNoShader(const SkPaint& skPaint,
+                                          bool justAlpha,
+                                          GrPaint* grPaint) {
+
+    grPaint->fDither    = skPaint.isDither();
+    grPaint->fAntiAlias = skPaint.isAntiAlias();
+
+    SkXfermode::Coeff sm = SkXfermode::kOne_Coeff;
+    SkXfermode::Coeff dm = SkXfermode::kISA_Coeff;
+
+    SkXfermode* mode = skPaint.getXfermode();
+    if (mode) {
+        if (!mode->asCoeff(&sm, &dm)) {
+            SkDebugf("Unsupported xfer mode.\n");
+#if 0
+            return false;
+#endif
+        }
+    }
+    grPaint->fSrcBlendCoeff = sk_blend_to_grblend(sm);
+    grPaint->fDstBlendCoeff = sk_blend_to_grblend(dm);
+
+    if (justAlpha) {
+        uint8_t alpha = skPaint.getAlpha();
+        grPaint->fColor = GrColorPackRGBA(alpha, alpha, alpha, alpha);
+    } else {
+        grPaint->fColor = SkGr::SkColor2GrColor(skPaint.getColor());
+        grPaint->setTexture(NULL);
+    }
+    return true;
 }
 
-void SkGpuDevice::AutoPaintShader::init(SkGpuDevice* device,
-                                        const SkPaint& paint,
-                                        const SkMatrix& ctm) {
-    fSuccess = true;
-    GrContext* ctx = device->context();
-    sk_gr_set_paint(ctx, paint); // should we pass true for justAlpha if we have a shader/texture?
+bool SkGpuDevice::skPaint2GrPaintShader(const SkPaint& skPaint,
+                                        SkAutoCachedTexture* act,
+                                        const SkMatrix& ctm,
+                                        GrPaint* grPaint) {
+
+    SkASSERT(NULL != act);
 
-    SkShader* shader = paint.getShader();
+    SkShader* shader = skPaint.getShader();
     if (NULL == shader) {
-        return;
+        return this->skPaint2GrPaintNoShader(skPaint, false, grPaint);
+        grPaint->setTexture(NULL);
+        return true;
+    } else if (!this->skPaint2GrPaintNoShader(skPaint, true, grPaint)) {
+        return false;
     }
 
-    if (!shader->setContext(device->accessBitmap(false), paint, ctm)) {
-        fSuccess = false;
-        return;
-    }
+    SkPaint noAlphaPaint(skPaint);
+    noAlphaPaint.setAlpha(255);
+    shader->setContext(this->accessBitmap(false), noAlphaPaint, ctm);
 
-    GrSamplerState::SampleMode sampleMode;
     SkBitmap bitmap;
     SkMatrix matrix;
     SkShader::TileMode tileModes[2];
@@ -370,51 +399,28 @@ void SkGpuDevice::AutoPaintShader::init(SkGpuDevice* device,
     SkShader::BitmapType bmptype = shader->asABitmap(&bitmap, &matrix,
                                                      tileModes, twoPointParams);
 
-    switch (bmptype) {
-    case SkShader::kNone_BitmapType:
-        SkDebugf("shader->asABitmap() == kNone_BitmapType");
-        return;
-    case SkShader::kDefault_BitmapType:
-        sampleMode = GrSamplerState::kNormal_SampleMode;
-        break;
-    case SkShader::kRadial_BitmapType:
-        sampleMode = GrSamplerState::kRadial_SampleMode;
-        break;
-    case SkShader::kSweep_BitmapType:
-        sampleMode = GrSamplerState::kSweep_SampleMode;
-        break;
-    case SkShader::kTwoPointRadial_BitmapType:
-        sampleMode = GrSamplerState::kRadial2_SampleMode;
-        break;
-    default:
-        SkASSERT("Unexpected return from asABitmap");
-        return;
-    }
-
-    bitmap.lockPixels();
-    if (!bitmap.getTexture() && !bitmap.readyToDraw()) {
-        return;
+    GrSamplerState::SampleMode sampleMode = sk_bmp_type_to_sample_mode[bmptype];
+    if (-1 == sampleMode) {
+        SkDebugf("shader->asABitmap() == kNone_BitmapType\n");
+        return false;
     }
+    grPaint->fSampler.setSampleMode(sampleMode);
 
-    // see if we've already cached the bitmap from the shader
-    GrSamplerState samplerState(sk_tile_mode_to_grwrap(tileModes[0]),
-                                sk_tile_mode_to_grwrap(tileModes[1]),
-                                sampleMode,
-                                paint.isFilterBitmap());
+    grPaint->fSampler.setWrapX(sk_tile_mode_to_grwrap(tileModes[0]));
+    grPaint->fSampler.setWrapY(sk_tile_mode_to_grwrap(tileModes[1]));
 
     if (GrSamplerState::kRadial2_SampleMode == sampleMode) {
-        samplerState.setRadial2Params(twoPointParams[0],
-                                      twoPointParams[1],
-                                      twoPointParams[2] < 0);
+        grPaint->fSampler.setRadial2Params(twoPointParams[0],
+                                           twoPointParams[1],
+                                           twoPointParams[2] < 0);
     }
 
-    GrTexture* texture = fCachedTexture.set(device, bitmap, samplerState);
+    GrTexture* texture = act->set(this, bitmap, grPaint->fSampler);
     if (NULL == texture) {
-        return;
+        SkDebugf("Couldn't convert bitmap to texture.\n");
+        return false;
     }
-
-    // the lock has already called setTexture for us
-    ctx->setSamplerState(0, samplerState);
+    grPaint->setTexture(texture);
 
     // since our texture coords will be in local space, we wack the texture
     // matrix to map them back into 0...1 before we load it
@@ -437,40 +443,161 @@ void SkGpuDevice::AutoPaintShader::init(SkGpuDevice* device,
                      (bitmap.width() * texture->allocWidth());
         matrix.postScale(s, s);
     }
+
     GrMatrix grmat;
-    SkGr::SkMatrix2GrMatrix(matrix, &grmat);
-    ctx->setTextureMatrix(0, grmat);
-
-    // since we're going to use a shader/texture, we don't want the color,
-    // just its alpha
-    ctx->setAlpha(paint.getAlpha());
-    // report that we have setup the texture
-    fSuccess = true;
-    fTexture = texture;
+    SkGr::SkMatrix2GrMatrix(matrix, &grPaint->fTextureMatrix);
+
+    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 = SkScalarToGrScalar(fPoints[i].fX);
+        dstPosition->fY = SkScalarToGrScalar(fPoints[i].fY);
+    }
+private:
+    int             fCount;
+    const SkPoint*  fPoints;
+};
+
+class SkTexCoordSource {
+public:
+    SkTexCoordSource(const SkPoint* coords)
+        : fCoords(coords) {}
+
+    void writeValue(int i, GrPoint* dstCoord) const {
+        dstCoord->fX = SkScalarToGrScalar(fCoords[i].fX);
+        dstCoord->fY = SkScalarToGrScalar(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:
+    int             fCount;
+    const uint16_t* fIndices;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+// can be used for positions or texture coordinates
+class SkRectFanSource {
+public:
+    SkRectFanSource(const SkRect& rect) : fRect(rect) {}
+
+    int count() const { return 4; }
+
+    void writeValue(int i, GrPoint* dstPoint) const {
+        SkASSERT(i < 4);
+        dstPoint->fX = SkScalarToGrScalar((i % 3) ? fRect.fRight :
+                                                    fRect.fLeft);
+        dstPoint->fY = SkScalarToGrScalar((i < 2) ? fRect.fTop  :
+                                                    fRect.fBottom);
+    }
+private:
+    const SkRect&   fRect;
+};
+
+class SkIRectFanSource {
+public:
+    SkIRectFanSource(const SkIRect& rect) : fRect(rect) {}
+
+    int count() const { return 4; }
+
+    void writeValue(int i, GrPoint* dstPoint) const {
+        SkASSERT(i < 4);
+        dstPoint->fX = (i % 3) ? GrIntToScalar(fRect.fRight) :
+                                 GrIntToScalar(fRect.fLeft);
+        dstPoint->fY = (i < 2) ? GrIntToScalar(fRect.fTop)  :
+                                 GrIntToScalar(fRect.fBottom);
+    }
+private:
+    const SkIRect&   fRect;
+};
+
+class SkMatRectFanSource {
+public:
+    SkMatRectFanSource(const SkRect& rect, const SkMatrix& matrix)
+        : fRect(rect), fMatrix(matrix) {}
+
+    int count() const { return 4; }
+
+    void writeValue(int i, GrPoint* dstPoint) const {
+        SkASSERT(i < 4);
+
+#if SK_SCALAR_IS_GR_SCALAR
+        fMatrix.mapXY((i % 3) ? fRect.fRight : fRect.fLeft,
+                      (i < 2) ? fRect.fTop   : fRect.fBottom,
+                      (SkPoint*)dstPoint);
+#else
+        SkPoint dst;
+        fMatrix.mapXY((i % 3) ? fRect.fRight : fRect.fLeft,
+                      (i < 2) ? fRect.fTop   : fRect.fBottom,
+                      &dst);
+        dstPoint->fX = SkScalarToGrScalar(dst.fX);
+        dstPoint->fY = SkScalarToGrScalar(dst.fY);
+#endif
+    }
+private:
+    const SkRect&   fRect;
+    const SkMatrix& fMatrix;
+};
+
 ///////////////////////////////////////////////////////////////////////////////
 
 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
     CHECK_SHOULD_DRAW(draw);
 
-    AutoPaintShader   shader(this, paint, *draw.fMatrix);
-    if (shader.failed()) {
+    GrPaint grPaint;
+    SkAutoCachedTexture act;
+    if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix, &grPaint)) {
         return;
     }
-    fContext->drawFull(shader.useTex());
+
+    fContext->drawPaint(grPaint);
 }
 
 // must be in SkCanvas::PointMode order
-static const GrGpu::PrimitiveType gPointMode2PrimtiveType[] = {
-    GrGpu::kPoints_PrimitiveType,
-    GrGpu::kLines_PrimitiveType,
-    GrGpu::kLineStrip_PrimitiveType
+static const GrDrawTarget::PrimitiveType gPointMode2PrimtiveType[] = {
+    GrDrawTarget::kPoints_PrimitiveType,
+    GrDrawTarget::kLines_PrimitiveType,
+    GrDrawTarget::kLineStrip_PrimitiveType
 };
 
 void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
-                            size_t count, const SkPoint pts[], const SkPaint& paint) {
+                             size_t count, const SkPoint pts[], const SkPaint& paint) {
     CHECK_SHOULD_DRAW(draw);
 
     SkScalar width = paint.getStrokeWidth();
@@ -484,27 +611,26 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
         return;
     }
 
-    AutoPaintShader shader(this, paint, *draw.fMatrix);
-    if (shader.failed()) {
+    GrPaint grPaint;
+    SkAutoCachedTexture act;
+    if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix, &grPaint)) {
         return;
     }
 
-    GrVertexLayout layout = shader.useTex() ?
-                            GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(0) :
-                            0;
 #if SK_SCALAR_IS_GR_SCALAR
-    fContext->setVertexSourceToArray(pts, layout);
-    fContext->drawNonIndexed(gPointMode2PrimtiveType[mode], 0, count);
+    fContext->drawVertices(grPaint,
+                           gPointMode2PrimtiveType[mode],
+                           count,
+                           (GrPoint*)pts,
+                           NULL,
+                           NULL,
+                           NULL,
+                           0);
 #else
-    GrPoint* v;
-    fContext->reserveAndLockGeometry(layout, count, 0, (void**)&v, NULL);
-    for (size_t i = 0; i < count; ++i) {
-        v[i].set(SkScalarToGrScalar(pts[i].fX), SkScalarToGrScalar(pts[i].fY));
-    }
-    fContext->drawNonIndexed(gPointMode2PrimtiveType[mode], 0, count);
-    fContext->releaseReservedGeometry();
+    fContext->drawCustomVertices(grPaint,
+                                 gPointMode2PrimtiveType[mode],
+                                 SkPositionSource(pts, count));
 #endif
-
 }
 
 void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect,
@@ -525,12 +651,12 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect,
         return;
     }
 
-    AutoPaintShader shader(this, paint, *draw.fMatrix);
-    if (shader.failed()) {
+    GrPaint grPaint;
+    SkAutoCachedTexture act;
+    if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix,  &grPaint)) {
         return;
     }
-
-    fContext->drawRect(Sk2Gr(rect), shader.useTex(), doStroke ? width : -1);
+    fContext->drawRect(grPaint, Sk2Gr(rect), doStroke ? width : -1);
 }
 
 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& path,
@@ -538,8 +664,9 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& path,
                            bool pathIsMutable) {
     CHECK_SHOULD_DRAW(draw);
 
-    AutoPaintShader shader(this, paint, *draw.fMatrix);
-    if (shader.failed()) {
+    GrPaint grPaint;
+    SkAutoCachedTexture act;
+    if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix, &grPaint)) {
         return;
     }
 
@@ -573,13 +700,13 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& path,
                 fill = GrContext::kInverseEvenOdd_PathFill;
                 break;
             default:
-                SkDebugf("Unsupported path fill type");
+                SkDebugf("Unsupported path fill type\n");
                 return;
         }
     }
 
     SkGrPathIter iter(fillPath);
-    fContext->drawPath(&iter, fill, shader.useTex());
+    fContext->drawPath(grPaint, &iter, fill);
 }
 
 /*
@@ -603,10 +730,16 @@ void SkGpuDevice::drawBitmap(const SkDraw& draw,
         srcRect = *srcRectPtr;
     }
 
+    GrPaint grPaint;
+    if (!this->skPaint2GrPaintNoShader(paint, true, &grPaint)) {
+        return;
+    }
+    grPaint.fSampler.setFilter(paint.isFilterBitmap());
+
     if (bitmap.getTexture() || (bitmap.width() <= MAX_TEXTURE_DIM &&
                                 bitmap.height() <= MAX_TEXTURE_DIM)) {
         // take the fast case
-        this->internalDrawBitmap(draw, bitmap, srcRect, m, paint);
+        this->internalDrawBitmap(draw, bitmap, srcRect, m, &grPaint);
         return;
     }
 
@@ -656,7 +789,7 @@ void SkGpuDevice::drawBitmap(const SkDraw& draw,
                     int dy = tileR.fTop -  DY + SkMax32(0, srcR.fTop);
                     tmpM.preTranslate(SkIntToScalar(dx), SkIntToScalar(dy));
                 }
-                this->internalDrawBitmap(draw, tmpB, srcR, tmpM, paint);
+                this->internalDrawBitmap(draw, tmpB, srcR, tmpM, &grPaint);
             }
         }
     }
@@ -666,13 +799,14 @@ void SkGpuDevice::drawBitmap(const SkDraw& draw,
  *  This is called by drawBitmap(), which has to handle images that may be too
  *  large to be represented by a single texture.
  *
- *  internalDrawBitmap assumes that the specified bitmap will fit in a texture.
+ *  internalDrawBitmap assumes that the specified bitmap will fit in a texture
+ *  and that non-texture portion of the GrPaint has already been setup.
  */
 void SkGpuDevice::internalDrawBitmap(const SkDraw& draw,
                                      const SkBitmap& bitmap,
                                      const SkIRect& srcRect,
                                      const SkMatrix& m,
-                                     const SkPaint& paint) {
+                                     GrPaint* grPaint) {
     SkASSERT(bitmap.width() <= MAX_TEXTURE_DIM &&
              bitmap.height() <= MAX_TEXTURE_DIM);
 
@@ -681,72 +815,35 @@ void SkGpuDevice::internalDrawBitmap(const SkDraw& draw,
         return;
     }
 
-    GrSamplerState sampler(paint.isFilterBitmap()); // defaults to clamp
-    // the lock has already called setTexture for us
-    fContext->setSamplerState(0, sampler);
+    grPaint->fSampler.setWrapX(GrSamplerState::kClamp_WrapMode);
+    grPaint->fSampler.setWrapY(GrSamplerState::kClamp_WrapMode);
+    grPaint->fSampler.setSampleMode(GrSamplerState::kNormal_SampleMode);
 
     GrTexture* texture;
-    SkAutoCachedTexture act(this, bitmap, sampler, &texture);
+    SkAutoCachedTexture act(this, bitmap, grPaint->fSampler, &texture);
     if (NULL == texture) {
         return;
     }
 
-    GrVertexLayout layout = GrDrawTarget::StageTexCoordVertexLayoutBit(0, 0);
-
-    GrPoint* vertex;
-    if (!fContext->reserveAndLockGeometry(layout, 4,
-                                          0, GrTCast<void**>(&vertex), NULL)) {
-        return;
-    }
-
-    {
-        GrMatrix grmat;
-        SkGr::SkMatrix2GrMatrix(m, &grmat);
-        vertex[0].setIRectFan(0, 0, srcRect.width(), srcRect.height(),
-                              2*sizeof(GrPoint));
-        grmat.mapPointsWithStride(vertex, 2*sizeof(GrPoint), 4);
-    }
-
-    SkScalar left   = SkFixedToScalar((srcRect.fLeft << 16) /
-                                      texture->allocWidth());
-    SkScalar right  = SkFixedToScalar((srcRect.fRight << 16) /
-                                      texture->allocWidth());
-    SkScalar top    = SkFixedToScalar((srcRect.fTop << 16) /
-                                      texture->allocHeight());
-    SkScalar bottom = SkFixedToScalar((srcRect.fBottom << 16) /
-                                      texture->allocHeight());
-    vertex[1].setRectFan(left, top, right, bottom, 2*sizeof(GrPoint));
-
-    fContext->setTextureMatrix(0, GrMatrix::I());
-    // now draw the mesh
-    sk_gr_set_paint(fContext, paint, true);
-    fContext->drawNonIndexed(GrGpu::kTriangleFan_PrimitiveType, 0, 4);
-    fContext->releaseReservedGeometry();
-}
+    grPaint->setTexture(texture);
+    grPaint->fTextureMatrix.setIdentity();
 
-static void gl_drawSprite(GrContext* ctx,
-                          int x, int y, int w, int h, const SkPoint& max,
-                          const SkPaint& paint) {
-    GrAutoViewMatrix avm(ctx, GrMatrix::I());
+    SkRect paintRect;
+    paintRect.set(SkFixedToScalar((srcRect.fLeft << 16)  / texture->allocWidth()),
+                  SkFixedToScalar((srcRect.fTop << 16)   / texture->allocHeight()),
+                  SkFixedToScalar((srcRect.fRight << 16) / texture->allocWidth()),
+                  SkFixedToScalar((srcRect.fBottom << 16)/ texture->allocHeight()));
 
-    ctx->setSamplerState(0, GrSamplerState::ClampNoFilter());
-    ctx->setTextureMatrix(0, GrMatrix::I());
+    SkRect dstRect;
+    dstRect.set(SkIntToScalar(0),SkIntToScalar(0), 
+                SkIntToScalar(srcRect.width()), SkIntToScalar(srcRect.height()));
 
-    GrPoint* vertex;
-    GrVertexLayout layout = GrGpu::StageTexCoordVertexLayoutBit(0, 0);
-    if (!ctx->reserveAndLockGeometry(layout, 4, 0,
-                                     GrTCast<void**>(&vertex), NULL)) {
-        return;
-    }
+    SkRectFanSource texSrc(paintRect);
+    fContext->drawCustomVertices(*grPaint,
+                                 GrDrawTarget::kTriangleFan_PrimitiveType,
+                                 SkMatRectFanSource(dstRect, m),
+                                 &texSrc);
 
-    vertex[1].setRectFan(0, 0, max.fX, max.fY, 2*sizeof(GrPoint));
-
-    vertex[0].setIRectFan(x, y, x + w, y + h, 2*sizeof(GrPoint));
-
-    sk_gr_set_paint(ctx, paint, true);
-    // should look to use glDrawTexi() has we do for text...
-    ctx->drawNonIndexed(GrGpu::kTriangleFan_PrimitiveType, 0, 4);
-    ctx->releaseReservedGeometry();
 }
 
 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
@@ -758,16 +855,31 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
         return;
     }
 
-    SkPoint max;
+    GrPaint grPaint;
+    if(!this->skPaint2GrPaintNoShader(paint, true, &grPaint)) {
+        return;
+    }
+
+    GrAutoMatrix avm(fContext, GrMatrix::I());
+
     GrTexture* texture;
-    SkAutoCachedTexture act(this, bitmap, GrSamplerState::ClampNoFilter(),
-                            &texture);
+    grPaint.fSampler.setClampNoFilter();
+    SkAutoCachedTexture act(this, bitmap, grPaint.fSampler, &texture);
 
+    grPaint.fTextureMatrix.setIdentity();
+    grPaint.setTexture(texture);
+
+    SkPoint max;
     max.set(SkFixedToScalar((texture->contentWidth() << 16) /
                              texture->allocWidth()),
             SkFixedToScalar((texture->contentHeight() << 16) /
                             texture->allocHeight()));
-    gl_drawSprite(fContext, left, top, bitmap.width(), bitmap.height(), max, paint);
+
+    fContext->drawRectToRect(grPaint,
+                             GrRect(GrIntToScalar(left), GrIntToScalar(top),
+                                    GrIntToScalar(left + bitmap.width()),
+                                    GrIntToScalar(top + bitmap.height())),
+                             GrRect(0, 0, max.fX, max.fY));
 }
 
 void SkGpuDevice::drawDevice(const SkDraw& draw, SkDevice* dev,
@@ -775,21 +887,41 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkDevice* dev,
     CHECK_SHOULD_DRAW(draw);
 
     SkPoint max;
-    if (((SkGpuDevice*)dev)->bindDeviceAsTexture(&max)) {
-        const SkBitmap& bm = dev->accessBitmap(false);
-        int w = bm.width();
-        int h = bm.height();
-        gl_drawSprite(fContext, x, y, w, h, max, paint);
+    GrPaint grPaint;
+    if (!((SkGpuDevice*)dev)->bindDeviceAsTexture(&grPaint, &max) ||
+        !this->skPaint2GrPaintNoShader(paint, true, &grPaint)) {
+        return;
     }
+
+    SkASSERT(NULL != grPaint.getTexture());
+
+    const SkBitmap& bm = dev->accessBitmap(false);
+    int w = bm.width();
+    int h = bm.height();
+
+    GrAutoMatrix avm(fContext, GrMatrix::I());
+
+    grPaint.fSampler.setClampNoFilter();
+    grPaint.fTextureMatrix.setIdentity();
+
+    fContext->drawRectToRect(grPaint,
+                             GrRect(GrIntToScalar(x), 
+                                    GrIntToScalar(y), 
+                                    GrIntToScalar(x + w), 
+                                    GrIntToScalar(y + h)),
+                             GrRect(0, 
+                                    0, 
+                                    GrIntToScalar(max.fX), 
+                                    GrIntToScalar(max.fY)));
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 
 // must be in SkCanvas::VertexMode order
-static const GrGpu::PrimitiveType gVertexMode2PrimitiveType[] = {
-    GrGpu::kTriangles_PrimitiveType,
-    GrGpu::kTriangleStrip_PrimitiveType,
-    GrGpu::kTriangleFan_PrimitiveType,
+static const GrDrawTarget::PrimitiveType gVertexMode2PrimitiveType[] = {
+    GrDrawTarget::kTriangles_PrimitiveType,
+    GrDrawTarget::kTriangleStrip_PrimitiveType,
+    GrDrawTarget::kTriangleFan_PrimitiveType,
 };
 
 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
@@ -800,77 +932,57 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
                               const SkPaint& paint) {
     CHECK_SHOULD_DRAW(draw);
 
-    sk_gr_set_paint(fContext, paint);
-
-    TexCache* cache = NULL;
-
-    bool useTexture = false;
-
-    AutoPaintShader autoShader;
-
-    if (texs) {
-        autoShader.init(this, paint, *draw.fMatrix);
-
-        if (autoShader.failed()) {
+    GrPaint grPaint;
+    SkAutoCachedTexture act;
+    // we ignore the shader if texs is null.
+    if (NULL == texs) {
+        if (!this->skPaint2GrPaintNoShader(paint, false, &grPaint)) {
+            return;
+        }
+    } else {
+        if (!this->skPaint2GrPaintShader(paint, &act, 
+                                         *draw.fMatrix, 
+                                         &grPaint)) {
             return;
         }
-        useTexture = autoShader.useTex();
     }
 
-    bool releaseVerts = false;
-    GrVertexLayout layout = 0;
-    if (useTexture) {
-        layout |= GrDrawTarget::StageTexCoordVertexLayoutBit(0, 0);
-    }
-    if (NULL != colors) {
-        layout |= GrDrawTarget::kColor_VertexLayoutBit;
+    if (NULL != xmode && NULL != texs && NULL != colors) {
+        SkXfermode::Mode mode;
+        if (!SkXfermode::IsMode(xmode, &mode) ||
+            SkXfermode::kMultiply_Mode != mode) {
+            SkDebugf("Unsupported vertex-color/texture xfer mode.\n");
+#if 0
+            return
+#endif
+        }
     }
 
-    #if SK_SCALAR_IS_GR_SCALAR
-    if (!layout) {
-        fContext->setVertexSourceToArray(vertices, layout);
+#if SK_SCALAR_IS_GR_SCALAR
+    // 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
-    #endif
+#endif
     {
-        void* verts;
-        releaseVerts = true;
-        if (!fContext->reserveAndLockGeometry(layout, vertexCount, 0,
-                                              &verts, NULL)) {
-            return;
-        }
-        int texOffsets[GrDrawTarget::kNumStages];
-        int colorOffset;
-        uint32_t stride = GrDrawTarget::VertexSizeAndOffsetsByStage(layout,
-                                                                    texOffsets,
-                                                                    &colorOffset);
-        for (int i = 0; i < vertexCount; ++i) {
-            GrPoint* p = (GrPoint*)((intptr_t)verts + i * stride);
-            p->set(SkScalarToGrScalar(vertices[i].fX),
-                   SkScalarToGrScalar(vertices[i].fY));
-            if (texOffsets[0] > 0) {
-                GrPoint* t = (GrPoint*)((intptr_t)p + texOffsets[0]);
-                t->set(SkScalarToGrScalar(texs[i].fX),
-                       SkScalarToGrScalar(texs[i].fY));
-            }
-            if (colorOffset > 0) {
-                uint32_t* color = (uint32_t*) ((intptr_t)p + colorOffset);
-                *color = SkGr::SkColor2GrColor(colors[i]);
-            }
-        }
-    }
-    if (indices) {
-        fContext->setIndexSourceToArray(indices);
-        fContext->drawIndexed(gVertexMode2PrimitiveType[vmode], 0, 0,
-                                 vertexCount, indexCount);
-    } else {
-        fContext->drawNonIndexed(gVertexMode2PrimitiveType[vmode],
-                                 0, vertexCount);
-    }
-    if (cache) {
-        this->unlockCachedTexture(cache);
-    }
-    if (releaseVerts) {
-        fContext->releaseReservedGeometry();
+        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);
     }
 }
 
@@ -908,8 +1020,7 @@ static void SkGPU_Draw1Glyph(const SkDraw1Glyph& state,
                                          procs->fFontScaler);
 }
 
-SkDrawProcs* SkGpuDevice::initDrawForText(const SkPaint& paint,
-                                          GrTextContext* context) {
+SkDrawProcs* SkGpuDevice::initDrawForText(GrTextContext* context) {
 
     // deferred allocation
     if (NULL == fDrawProcs) {
@@ -935,9 +1046,15 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
     } else {
         SkAutoExtMatrix aem(draw.fExtMatrix);
         SkDraw myDraw(draw);
-        sk_gr_set_paint(fContext, paint);
-        GrTextContext context(fContext, aem.extMatrix());
-        myDraw.fProcs = this->initDrawForText(paint, &context);
+
+        GrPaint grPaint;
+        SkAutoCachedTexture act;
+
+        if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix, &grPaint)) {
+            return;
+        }
+        GrTextContext context(fContext, grPaint, aem.extMatrix());
+        myDraw.fProcs = this->initDrawForText(&context);
         this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint);
     }
 }
@@ -955,9 +1072,15 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
     } else {
         SkAutoExtMatrix aem(draw.fExtMatrix);
         SkDraw myDraw(draw);
-        sk_gr_set_paint(fContext, paint);
-        GrTextContext context(fContext, aem.extMatrix());
-        myDraw.fProcs = this->initDrawForText(paint, &context);
+
+        GrPaint grPaint;
+        SkAutoCachedTexture act;
+        if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix, &grPaint)) {
+            return;
+        }
+
+        GrTextContext context(fContext, grPaint, aem.extMatrix());
+        myDraw.fProcs = this->initDrawForText(&context);
         this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY,
                                      scalarsPerPos, paint);
     }
@@ -1014,7 +1137,6 @@ SkGpuDevice::TexCache* SkGpuDevice::lockCachedTexture(const SkBitmap& bitmap,
 
     if (NULL != entry) {
         newTexture = entry->texture();
-        ctx->setTexture(0, newTexture);
         if (texture) {
             *texture = newTexture;
         }
index 8849db7..41cf1bd 100644 (file)
 
 /*  Fill out buffer with the compressed format Ganesh expects from a colortable
  based bitmap. [palette (colortable) + indices].
- At the moment Ganesh only supports 8bit version. If Ganesh allowed we others 
+
+ At the moment Ganesh only supports 8bit version. If Ganesh allowed we others
  we could detect that the colortable.count is <= 16, and then repack the
  indices as nibbles to save RAM, but it would take more time (i.e. a lot
  slower than memcpy), so skipping that for now.
+
  Ganesh wants a full 256 palette entry, even though Skia's ctable is only as big
  as the colortable.count says it is.
  */
 static void build_compressed_data(void* buffer, const SkBitmap& bitmap) {
     SkASSERT(SkBitmap::kIndex8_Config == bitmap.config());
-  
+
     SkAutoLockPixels apl(bitmap);
     if (!bitmap.readyToDraw()) {
         SkASSERT(!"bitmap not ready to draw!");
@@ -39,10 +39,10 @@ static void build_compressed_data(void* buffer, const SkBitmap& bitmap) {
 
     SkColorTable* ctable = bitmap.getColorTable();
     char* dst = (char*)buffer;
-    
+
     memcpy(dst, ctable->lockColors(), ctable->count() * sizeof(SkPMColor));
     ctable->unlockColors(false);
-    
+
     // always skip a full 256 number of entries, even if we memcpy'd fewer
     dst += GrGpu::kColorTableSize;
 
@@ -63,7 +63,7 @@ static void build_compressed_data(void* buffer, const SkBitmap& bitmap) {
 
 ////////////////////////////////////////////////////////////////////////////////
 
-GrTextureEntry* sk_gr_create_bitmap_texture(GrContext* ctx, 
+GrTextureEntry* sk_gr_create_bitmap_texture(GrContext* ctx,
                                             GrTextureKey* key,
                                             const GrSamplerState& sampler,
                                             const SkBitmap& origBitmap) {
@@ -75,7 +75,7 @@ GrTextureEntry* sk_gr_create_bitmap_texture(GrContext* ctx,
     SkBitmap tmpBitmap;
 
     const SkBitmap* bitmap = &origBitmap;
-    
+
     GrGpu::TextureDesc desc = {
         0,
         GrGpu::kNone_AALevel,
@@ -83,16 +83,16 @@ GrTextureEntry* sk_gr_create_bitmap_texture(GrContext* ctx,
         bitmap->height(),
         SkGr::Bitmap2PixelConfig(*bitmap)
     };
-    
+
     if (SkBitmap::kIndex8_Config == bitmap->config()) {
         // build_compressed_data doesn't do npot->pot expansion
         // and paletted textures can't be sub-updated
         if (ctx->supportsIndex8PixelConfig(sampler,
                                            bitmap->width(), bitmap->height())) {
-            size_t imagesize = bitmap->width() * bitmap->height() + 
+            size_t imagesize = bitmap->width() * bitmap->height() +
                                 GrGpu::kColorTableSize;
             SkAutoMalloc storage(imagesize);
-        
+
             build_compressed_data(storage.get(), origBitmap);
 
             // our compressed data will be trimmed, so pass width() for its
@@ -105,7 +105,7 @@ GrTextureEntry* sk_gr_create_bitmap_texture(GrContext* ctx,
             // now bitmap points to our temp, which has been promoted to 32bits
             bitmap = &tmpBitmap;
         }
-    } 
+    }
 
     desc.fFormat = SkGr::Bitmap2PixelConfig(*bitmap);
     return ctx->createAndLockTexture(key, sampler, desc, bitmap->getPixels(),
@@ -113,28 +113,7 @@ GrTextureEntry* sk_gr_create_bitmap_texture(GrContext* ctx,
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-  
-void sk_gr_set_paint(GrContext* ctx, const SkPaint& paint, bool justAlpha) {
-    ctx->setDither(paint.isDither());
-    ctx->setAntiAlias(paint.isAntiAlias());
 
-    if (justAlpha) {
-        ctx->setAlpha(paint.getAlpha());
-    } else {
-        ctx->setColor(SkGr::SkColor2GrColor(paint.getColor()));
-    }
-    
-    SkXfermode::Coeff sm = SkXfermode::kOne_Coeff;
-    SkXfermode::Coeff dm = SkXfermode::kISA_Coeff;
-    
-    SkXfermode* mode = paint.getXfermode();
-    if (mode) {
-        mode->asCoeff(&sm, &dm);
-    }   
-    ctx->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm));
-}
-
-////////////////////////////////////////////////////////////////////////////////
 
 SkGrPathIter::Command SkGrPathIter::next(GrPoint pts[]) {
     GrAssert(NULL != pts);
@@ -160,7 +139,7 @@ void SkGrPathIter::rewind() {
 }
 
 GrPathIter::ConvexHint SkGrPathIter::hint() const {
-    return fPath.isConvex() ? GrPathIter::kConvex_ConvexHint : 
+    return fPath.isConvex() ? GrPathIter::kConvex_ConvexHint :
                               GrPathIter::kNone_ConvexHint;
 }
 
index d4ef7e9..e45a445 100644 (file)
@@ -37,26 +37,26 @@ static OSStatus MyDrawEventHandler(EventHandlerCallRef myHandler,
                                    EventRef event, void *userData) {
        // NOTE: GState is save/restored by the HIView system doing the callback,
     // so the draw handler doesn't need to do it
-    
+
        OSStatus status = noErr;
        CGContextRef context;
        HIRect          bounds;
-    
+
        // Get the CGContextRef
-       status = GetEventParameter (event, kEventParamCGContextRef, 
-                                typeCGContextRef, NULL, 
+       status = GetEventParameter (event, kEventParamCGContextRef,
+                                typeCGContextRef, NULL,
                                 sizeof (CGContextRef),
                                 NULL,
                                 &context);
-    
+
        if (status != noErr) {
                SkDebugf("Got error %d getting the context!\n", status);
                return status;
-       }               
-    
+       }
+
        // Get the bounding rectangle
        HIViewGetBounds ((HIViewRef) userData, &bounds);
-       
+
     gCurrOSWin->doPaint(context);
        return status;
 }
@@ -88,13 +88,13 @@ SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd), fAGLCtx(NULL)
 {
        OSStatus    result;
     WindowRef   wr = (WindowRef)hWnd;
-    
+
     HIViewRef imageView, parent;
     HIViewRef rootView = HIViewGetRoot(wr);
     HIViewFindByID(rootView, kHIViewWindowContentID, &parent);
     result = HIImageViewCreate(NULL, &imageView);
        SkASSERT(result == noErr);
-    
+
     result = HIViewAddSubview(parent, imageView);
        SkASSERT(result == noErr);
 
@@ -138,7 +138,7 @@ SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd), fAGLCtx(NULL)
        result = InstallEventHandler(GetWindowEventTarget(wr), handlerUPP,
                                                count, gTypes, this, nil);
        SkASSERT(result == noErr);
-    
+
        gCurrOSWin = this;
        gCurrEventQ = GetCurrentEventQueue();
        gEventTarget = GetWindowEventTarget(wr);
@@ -168,7 +168,7 @@ void SkOSWindow::doPaint(void* ctx)
         CGContextScaleCTM(cg, 1, -1);
 
         CGContextDrawImage(cg, r, img);
-        
+
         CGContextRestoreGState(cg);
 
         CGImageRelease(img);
@@ -179,15 +179,15 @@ void SkOSWindow::doPaint(void* ctx)
 void SkOSWindow::updateSize()
 {
        Rect    r;
-       
+
        GetWindowBounds((WindowRef)fHWND, kWindowContentRgn, &r);
        this->resize(r.right - r.left, r.bottom - r.top);
-    
+
 #if 0
     HIRect    frame;
     HIViewRef imageView = (HIViewRef)getHVIEW();
     HIViewRef parent = HIViewGetSuperview(imageView);
-  
+
     HIViewGetBounds(imageView, &frame);
     SkDebugf("------ %d bounds %g %g %g %g\n", r.right - r.left,
              frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
@@ -245,7 +245,7 @@ enum {
        SK_MacRightKey          = 124,
        SK_MacDownKey           = 125,
        SK_MacUpKey                     = 126,
-    
+
     SK_Mac0Key          = 0x52,
     SK_Mac1Key          = 0x53,
     SK_Mac2Key          = 0x54,
@@ -257,7 +257,7 @@ enum {
     SK_Mac8Key          = 0x5b,
     SK_Mac9Key          = 0x5c
 };
-       
+
 static SkKey raw2key(UInt32 raw)
 {
        static const struct {
@@ -282,7 +282,7 @@ static SkKey raw2key(UInt32 raw)
         { SK_Mac8Key,       k8_SkKey        },
         { SK_Mac9Key,       k9_SkKey        }
        };
-       
+
        for (unsigned i = 0; i < SK_ARRAY_COUNT(gKeys); i++)
                if (gKeys[i].fRaw == raw)
                        return gKeys[i].fKey;
@@ -294,18 +294,18 @@ static void post_skmacevent()
        EventRef        ref;
        OSStatus        status = CreateEvent(nil, SK_MacEventClass, SK_MacEventKind, 0, 0, &ref);
        SkASSERT(status == noErr);
-       
+
 #if 0
        status = SetEventParameter(ref, SK_MacEventParamName, SK_MacEventParamName, sizeof(evt), &evt);
        SkASSERT(status == noErr);
        status = SetEventParameter(ref, SK_MacEventSinkIDParamName, SK_MacEventSinkIDParamName, sizeof(sinkID), &sinkID);
        SkASSERT(status == noErr);
 #endif
-       
+
        EventTargetRef target = gEventTarget;
        SetEventParameter(ref, kEventParamPostTarget, typeEventTargetRef, sizeof(target), &target);
        SkASSERT(status == noErr);
-       
+
        status = PostEventToQueue(gCurrEventQ, ref, kEventPriorityStandard);
        SkASSERT(status == noErr);
 
@@ -456,16 +456,16 @@ AGLContext create_gl(WindowRef wref, bool offscreen)
 {
     GLint major, minor;
     AGLContext ctx;
-    
+
     aglGetVersion(&major, &minor);
     SkDebugf("---- agl version %d %d\n", major, minor);
-    
+
     const GLint pixelAttrs[] = {
         AGL_RGBA,
         AGL_STENCIL_SIZE, 8,
         AGL_SAMPLE_BUFFERS_ARB, 1,
                AGL_MULTISAMPLE,
-               AGL_SAMPLES_ARB, 2,        
+               AGL_SAMPLES_ARB, 2,
                (offscreen ? AGL_OFFSCREEN : AGL_ACCELERATED),
         (offscreen ? AGL_NONE : AGL_DOUBLEBUFFER),
         AGL_NONE
@@ -494,14 +494,20 @@ bool SkOSWindow::attachGL(const SkBitmap* offscreen)
 
     GLboolean success = true;
 
+    int width, height;
+
     if (offscreen) {
         success = aglSetOffScreen((AGLContext)fAGLCtx,
                                     offscreen->width(),
                                     offscreen->height(),
                                     offscreen->rowBytes(),
                                     offscreen->getPixels());
+        width = offscreen->width();
+        height = offscreen->height();
     } else {
         success = aglSetWindowRef((AGLContext)fAGLCtx, (WindowRef)fHWND);
+        width = this->width();
+        height = this->height();
     }
 
     GLenum err = aglGetError();
@@ -509,8 +515,9 @@ bool SkOSWindow::attachGL(const SkBitmap* offscreen)
         SkDebugf("---- setoffscreen %d %d %s [%d %d]\n", success, err,
                  aglErrorString(err), offscreen->width(), offscreen->height());
     }
-    
+
     if (success) {
+        glViewport(0, 0, width, height);
         glClearColor(0, 0, 0, 0);
         glClearStencil(0);
         glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
index 53449b1..d0e6cc3 100644 (file)
@@ -438,6 +438,7 @@ bool SkOSWindow::attachGL(const SkBitmap* offscreen) {
         }
     }
     if (wglMakeCurrent(GetDC((HWND)fHWND), (HGLRC)fHGLRC)) {
+        glViewport(0, 0, this->width(), this->height());
         glClearColor(0, 0, 0, 0);
         glClearStencil(0);
         glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
index 7294cc1..95e7f0a 100644 (file)
@@ -74,6 +74,7 @@
       <IntrinsicFunctions>true</IntrinsicFunctions>\r
       <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
       <AdditionalIncludeDirectories>..\..\include\core;..\..\include\xml;..\..\include\utils;..\..\include\config;..\..\include\views;..\..\src\core;..\..\include\images;..\..\include\effects;..\..\include\gpu;..\..\gpu\include</AdditionalIncludeDirectories>\r
+      <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>\r
     </ClCompile>\r
     <Link>\r
       <SubSystem>Windows</SubSystem>\r
     <ClInclude Include="..\..\gpu\include\GrColor.h" />\r
     <ClInclude Include="..\..\gpu\include\GrConfig.h" />\r
     <ClInclude Include="..\..\gpu\include\GrContext.h" />\r
+    <ClInclude Include="..\..\gpu\include\GrContext_impl.h" />\r
     <ClInclude Include="..\..\gpu\include\GrDrawTarget.h" />\r
     <ClInclude Include="..\..\gpu\include\GrFontScaler.h" />\r
     <ClInclude Include="..\..\gpu\include\GrGLConfig.h" />\r
     <ClInclude Include="..\..\gpu\include\GrMemory.h" />\r
     <ClInclude Include="..\..\gpu\include\GrMesh.h" />\r
     <ClInclude Include="..\..\gpu\include\GrNoncopyable.h" />\r
+    <ClInclude Include="..\..\gpu\include\GrPaint.h" />\r
     <ClInclude Include="..\..\gpu\include\GrPath.h" />\r
     <ClInclude Include="..\..\gpu\include\GrPathIter.h" />\r
     <ClInclude Include="..\..\gpu\include\GrPathSink.h" />\r
index 7aa1a77..0403b49 100644 (file)
@@ -91,6 +91,8 @@
                00115EA912C116CA008296FE /* GrUserConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 00115E6D12C116CA008296FE /* GrUserConfig.h */; };
                00115EAA12C116CA008296FE /* GrVertexBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 00115E6E12C116CA008296FE /* GrVertexBuffer.h */; };
                00115EAB12C116CA008296FE /* GrVertexBufferAllocPool.h in Headers */ = {isa = PBXBuildFile; fileRef = 00115E6F12C116CA008296FE /* GrVertexBufferAllocPool.h */; };
+               D539049B12EA01E30025F3D6 /* GrContext_impl.h in Headers */ = {isa = PBXBuildFile; fileRef = D539049A12EA01E30025F3D6 /* GrContext_impl.h */; };
+               D53904A112EA026E0025F3D6 /* GrPaint.h in Headers */ = {isa = PBXBuildFile; fileRef = D53904A012EA026E0025F3D6 /* GrPaint.h */; };
                D58CAF9A12E7212100CB9277 /* GrGLUtil.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D58CAF9812E7212100CB9277 /* GrGLUtil.cpp */; };
 /* End PBXBuildFile section */
 
                00115E6E12C116CA008296FE /* GrVertexBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GrVertexBuffer.h; path = ../../gpu/include/GrVertexBuffer.h; sourceTree = SOURCE_ROOT; };
                00115E6F12C116CA008296FE /* GrVertexBufferAllocPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GrVertexBufferAllocPool.h; path = ../../gpu/include/GrVertexBufferAllocPool.h; sourceTree = SOURCE_ROOT; };
                D2AAC046055464E500DB518D /* libgpu.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libgpu.a; sourceTree = BUILT_PRODUCTS_DIR; };
+               D539049A12EA01E30025F3D6 /* GrContext_impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GrContext_impl.h; path = ../../gpu/include/GrContext_impl.h; sourceTree = SOURCE_ROOT; };
+               D53904A012EA026E0025F3D6 /* GrPaint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GrPaint.h; path = ../../gpu/include/GrPaint.h; sourceTree = SOURCE_ROOT; };
                D58CAF9812E7212100CB9277 /* GrGLUtil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GrGLUtil.cpp; path = ../../gpu/src/GrGLUtil.cpp; sourceTree = SOURCE_ROOT; };
 /* End PBXFileReference section */
 
                                00115E6D12C116CA008296FE /* GrUserConfig.h */,
                                00115E6E12C116CA008296FE /* GrVertexBuffer.h */,
                                00115E6F12C116CA008296FE /* GrVertexBufferAllocPool.h */,
+                               D53904A012EA026E0025F3D6 /* GrPaint.h */,
                        );
                        name = include;
                        sourceTree = "<group>";
                08FB7795FE84155DC02AAC07 /* Source */ = {
                        isa = PBXGroup;
                        children = (
+                               D539049A12EA01E30025F3D6 /* GrContext_impl.h */,
                                00115DD812C1167A008296FE /* gr_unittests.cpp */,
                                00115DD912C1167A008296FE /* GrAllocPool.cpp */,
                                00115DDA12C1167A008296FE /* GrAtlas.cpp */,
                                00115EA912C116CA008296FE /* GrUserConfig.h in Headers */,
                                00115EAA12C116CA008296FE /* GrVertexBuffer.h in Headers */,
                                00115EAB12C116CA008296FE /* GrVertexBufferAllocPool.h in Headers */,
+                               D539049B12EA01E30025F3D6 /* GrContext_impl.h in Headers */,
+                               D53904A112EA026E0025F3D6 /* GrPaint.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 8787064..18bca17 100644 (file)
@@ -51,7 +51,6 @@
                0041CE430F00A12400695E8C /* SampleLayers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0041CE2D0F00A12400695E8C /* SampleLayers.cpp */; };
                0041CE450F00A12400695E8C /* SampleMeasure.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0041CE2F0F00A12400695E8C /* SampleMeasure.cpp */; };
                0041CE480F00A12400695E8C /* SampleOverflow.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0041CE320F00A12400695E8C /* SampleOverflow.cpp */; };
-               0041CE4A0F00A12400695E8C /* SamplePatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0041CE340F00A12400695E8C /* SamplePatch.cpp */; };
                00575A1810BB02CF00A43B94 /* SampleEffects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00FF39130FC6ED2C00915187 /* SampleEffects.cpp */; };
                00575A3B10BB05FE00A43B94 /* SampleArc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00A41E4A0EFC312F00C9CBEB /* SampleArc.cpp */; };
                00575A9510BB2FF600A43B94 /* SampleMipMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2794C04E0FE72903009AD112 /* SampleMipMap.cpp */; };
@@ -86,7 +85,6 @@
                00AF787E0FE94433007F9650 /* SamplePath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00003C640EFC22A8000FF73A /* SamplePath.cpp */; };
                00AF9B18103CD5EB00CBBCB3 /* SampleDitherBitmap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00AF9B17103CD5EB00CBBCB3 /* SampleDitherBitmap.cpp */; };
                00BB289B104781D00057BF7E /* SampleForth.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00BB289A104781D00057BF7E /* SampleForth.cpp */; };
-               00C1B809103857A400FA5948 /* SampleFillType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0041CE270F00A12400695E8C /* SampleFillType.cpp */; };
                00EB4593104DBB18002B413E /* ForthTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00EB4592104DBB18002B413E /* ForthTests.cpp */; };
                00ED55F3104A10EB00F51FF8 /* StdWords.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00ED55F2104A10EB00F51FF8 /* StdWords.cpp */; };
                00F0441010B447160049C54C /* SamplePathClip.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 007C785D0F3B4C230004B142 /* SamplePathClip.cpp */; };
                8D0C4E8D0486CD37000505A6 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */; };
                8D0C4E8E0486CD37000505A6 /* main.nib in Resources */ = {isa = PBXBuildFile; fileRef = 02345980000FD03B11CA0E72 /* main.nib */; };
                8D0C4E920486CD37000505A6 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 20286C33FDCF999611CA2CEA /* Carbon.framework */; };
+               D5A682D712E9CE8500CDDDC6 /* SamplePatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0041CE340F00A12400695E8C /* SamplePatch.cpp */; };
+               D5F4A21F12E9D75300DE986A /* SampleFillType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0041CE270F00A12400695E8C /* SampleFillType.cpp */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
                                0041CE430F00A12400695E8C /* SampleLayers.cpp in Sources */,
                                0041CE450F00A12400695E8C /* SampleMeasure.cpp in Sources */,
                                0041CE480F00A12400695E8C /* SampleOverflow.cpp in Sources */,
-                               0041CE4A0F00A12400695E8C /* SamplePatch.cpp in Sources */,
                                007A7CB40F01658C00A2D6EE /* SamplePoints.cpp in Sources */,
                                007A7CB80F01658C00A2D6EE /* SampleStrokeText.cpp in Sources */,
                                007A7CBD0F01658C00A2D6EE /* SampleTextOnPath.cpp in Sources */,
                                005E92DC0FF08507008965B9 /* SampleFilter2.cpp in Sources */,
                                27005D16100903C100E275B6 /* SampleLines.cpp in Sources */,
                                27005D5F10095B2B00E275B6 /* SampleCircle.cpp in Sources */,
-                               00C1B809103857A400FA5948 /* SampleFillType.cpp in Sources */,
                                00AF9B18103CD5EB00CBBCB3 /* SampleDitherBitmap.cpp in Sources */,
                                001B871E1042184D00C84ED4 /* Forth.cpp in Sources */,
                                00BB289B104781D00057BF7E /* SampleForth.cpp in Sources */,
                                009F9D0612C3E89F00C7FD4A /* SampleTiling.cpp in Sources */,
                                009F9D0A12C3E8AF00C7FD4A /* SampleFilter.cpp in Sources */,
                                009F9D1A12C3EB2600C7FD4A /* SampleGM.cpp in Sources */,
+                               D5A682D712E9CE8500CDDDC6 /* SamplePatch.cpp in Sources */,
+                               D5F4A21F12E9D75300DE986A /* SampleFillType.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };