Renamed and made public SkGradientShaderBases's 'commonAsAGradient' to 'getGradientTa...
authorrileya@google.com <rileya@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 27 Jul 2012 15:49:05 +0000 (15:49 +0000)
committerrileya@google.com <rileya@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 27 Jul 2012 15:49:05 +0000 (15:49 +0000)
Also tidied up Gr gradient implementation constructors, to take the appropriate SkGradientShaderBase subclass, and where necessary (namely 2pt radial/conical) made them obtain extra parameters from that object, rather than passing them in in addition to it.
Review URL: https://codereview.appspot.com/6449057

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

12 files changed:
src/effects/gradients/SkGradientShader.cpp
src/effects/gradients/SkGradientShaderPriv.h
src/effects/gradients/SkLinearGradient.cpp
src/effects/gradients/SkLinearGradient.h
src/effects/gradients/SkRadialGradient.cpp
src/effects/gradients/SkRadialGradient.h
src/effects/gradients/SkSweepGradient.cpp
src/effects/gradients/SkSweepGradient.h
src/effects/gradients/SkTwoPointConicalGradient.cpp
src/effects/gradients/SkTwoPointConicalGradient.h
src/effects/gradients/SkTwoPointRadialGradient.cpp
src/effects/gradients/SkTwoPointRadialGradient.h

index f5f3f5b6b9ef77e89fcf35b5a65a005d1a8de18a..6bec70f8397e071ff1fc7a083a0bb91598ae6563 100644 (file)
@@ -483,7 +483,7 @@ const SkPMColor* SkGradientShaderBase::getCache32() const {
  *  colors and positions. Note: we don't try to flatten the fMapper, so if one
  *  is present, we skip the cache for now.
  */
-void SkGradientShaderBase::commonAsABitmap(SkBitmap* bitmap) const {
+void SkGradientShaderBase::getGradientTableBitmap(SkBitmap* bitmap) const {
     // our caller assumes no external alpha, so we ensure that our cache is
     // built with 0xFF
     this->setCacheAlpha(0xFF);
@@ -689,23 +689,23 @@ void GrGLGradientStage::emitColorLookup(GrGLShaderBuilder* builder,
 /////////////////////////////////////////////////////////////////////
 
 GrGradientEffect::GrGradientEffect(GrTexture* texture) 
-                                   : fTexture (texture)
-                                   , fUseTexture(true) {
+    : fTexture (texture)
+    , fUseTexture(true) {
     SkSafeRef(fTexture);
 }
 
 GrGradientEffect::GrGradientEffect(GrContext* ctx, 
-                                   const SkShader& shader,
+                                   const SkGradientShaderBase& shader,
                                    GrSamplerState* sampler)
-                                   : fTexture (NULL)
-                                   , fUseTexture (false) {
+    : fTexture (NULL)
+    , fUseTexture (false) {
     // TODO: check for simple cases where we don't need a texture:
     //GradientInfo info;
     //shader.asAGradient(&info);
     //if (info.fColorCount == 2) { ...
 
     SkBitmap bitmap;
-    shader.asABitmap(&bitmap, NULL, NULL);
+    shader.getGradientTableBitmap(&bitmap);
 
     GrContext::TextureCacheEntry entry = GrLockCachedBitmapTexture(ctx, bitmap,
                                                                    sampler->textureParams());
index 23de48cdf9e2ec490d7aeac980f10670d6b5c0ce..93b8c8358f77e26e6ffe2b7862554b6126f4af97 100644 (file)
-\r
-/*\r
- * Copyright 2012 Google Inc.\r
- *\r
- * Use of this source code is governed by a BSD-style license that can be\r
- * found in the LICENSE file.\r
- */\r
-\r
-#ifndef SkGradientShaderPriv_DEFINED\r
-#define SkGradientShaderPriv_DEFINED\r
-\r
-#include "SkGradientShader.h"\r
-#include "SkClampRange.h"\r
-#include "SkColorPriv.h"\r
-#include "SkMallocPixelRef.h"\r
-#include "SkUnitMapper.h"\r
-#include "SkUtils.h"\r
-#include "SkTemplates.h"\r
-#include "SkBitmapCache.h"\r
-#include "SkShader.h"\r
-#include "GrSamplerState.h"\r
-#include "SkGr.h"\r
-#include "gl/GrGLProgramStage.h"\r
-\r
-#ifndef SK_DISABLE_DITHER_32BIT_GRADIENT\r
-    #define USE_DITHER_32BIT_GRADIENT\r
-#endif\r
-\r
-static void sk_memset32_dither(uint32_t dst[], uint32_t v0, uint32_t v1,\r
-                               int count) {\r
-    if (count > 0) {\r
-        if (v0 == v1) {\r
-            sk_memset32(dst, v0, count);\r
-        } else {\r
-            int pairs = count >> 1;\r
-            for (int i = 0; i < pairs; i++) {\r
-                *dst++ = v0;\r
-                *dst++ = v1;\r
-            }\r
-            if (count & 1) {\r
-                *dst = v0;\r
-            }\r
-        }\r
-    }\r
-}\r
-\r
-//  Clamp\r
-\r
-static SkFixed clamp_tileproc(SkFixed x) {\r
-    return SkClampMax(x, 0xFFFF);\r
-}\r
-\r
-// Repeat\r
-\r
-static SkFixed repeat_tileproc(SkFixed x) {\r
-    return x & 0xFFFF;\r
-}\r
-\r
-// Mirror\r
-\r
-// Visual Studio 2010 (MSC_VER=1600) optimizes bit-shift code incorrectly.\r
-// See http://code.google.com/p/skia/issues/detail?id=472\r
-#if defined(_MSC_VER) && (_MSC_VER >= 1600)\r
-#pragma optimize("", off)\r
-#endif\r
-\r
-static inline SkFixed mirror_tileproc(SkFixed x) {\r
-    int s = x << 15 >> 31;\r
-    return (x ^ s) & 0xFFFF;\r
-}\r
-\r
-#if defined(_MSC_VER) && (_MSC_VER >= 1600)\r
-#pragma optimize("", on)\r
-#endif\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-\r
-typedef SkFixed (*TileProc)(SkFixed);\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-\r
-static const TileProc gTileProcs[] = {\r
-    clamp_tileproc,\r
-    repeat_tileproc,\r
-    mirror_tileproc\r
-};\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-\r
-class SkGradientShaderBase : public SkShader {\r
-public:\r
-    SkGradientShaderBase(const SkColor colors[], const SkScalar pos[],\r
-                int colorCount, SkShader::TileMode mode, SkUnitMapper* mapper);\r
-    virtual ~SkGradientShaderBase();\r
-\r
-    // overrides\r
-    virtual bool setContext(const SkBitmap&, const SkPaint&, const SkMatrix&) SK_OVERRIDE;\r
-    virtual uint32_t getFlags() SK_OVERRIDE { return fFlags; }\r
-    virtual bool isOpaque() const SK_OVERRIDE;\r
-\r
-    enum {\r
-        /// Seems like enough for visual accuracy. TODO: if pos[] deserves\r
-        /// it, use a larger cache.\r
-        kCache16Bits    = 8,\r
-        kGradient16Length = (1 << kCache16Bits),\r
-        /// Each cache gets 1 extra entry at the end so we don't have to\r
-        /// test for end-of-cache in lerps. This is also the value used\r
-        /// to stride *writes* into the dither cache; it must not be zero.\r
-        /// Total space for a cache is 2x kCache16Count entries: one\r
-        /// regular cache, one for dithering.\r
-        kCache16Count   = kGradient16Length + 1,\r
-        kCache16Shift   = 16 - kCache16Bits,\r
-        kSqrt16Shift    = 8 - kCache16Bits,\r
-\r
-        /// Seems like enough for visual accuracy. TODO: if pos[] deserves\r
-        /// it, use a larger cache.\r
-        kCache32Bits    = 8,\r
-        kGradient32Length = (1 << kCache32Bits),\r
-        /// Each cache gets 1 extra entry at the end so we don't have to\r
-        /// test for end-of-cache in lerps. This is also the value used\r
-        /// to stride *writes* into the dither cache; it must not be zero.\r
-        /// Total space for a cache is 2x kCache32Count entries: one\r
-        /// regular cache, one for dithering.\r
-        kCache32Count   = kGradient32Length + 1,\r
-        kCache32Shift   = 16 - kCache32Bits,\r
-        kSqrt32Shift    = 8 - kCache32Bits,\r
-\r
-        /// This value is used to *read* the dither cache; it may be 0\r
-        /// if dithering is disabled.\r
-#ifdef USE_DITHER_32BIT_GRADIENT\r
-        kDitherStride32 = kCache32Count,\r
-#else\r
-        kDitherStride32 = 0,\r
-#endif\r
-        kDitherStride16 = kCache16Count,\r
-        kLerpRemainderMask32 = (1 << (16 - kCache32Bits)) - 1\r
-    };\r
-\r
-\r
-protected:\r
-    SkGradientShaderBase(SkFlattenableReadBuffer& );\r
-    virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;\r
-\r
-    SkUnitMapper* fMapper;\r
-    SkMatrix    fPtsToUnit;     // set by subclass\r
-    SkMatrix    fDstToIndex;\r
-    SkMatrix::MapXYProc fDstToIndexProc;\r
-    TileMode    fTileMode;\r
-    TileProc    fTileProc;\r
-    int         fColorCount;\r
-    uint8_t     fDstToIndexClass;\r
-    uint8_t     fFlags;\r
-\r
-    struct Rec {\r
-        SkFixed     fPos;   // 0...1\r
-        uint32_t    fScale; // (1 << 24) / range\r
-    };\r
-    Rec*        fRecs;\r
-\r
-    const uint16_t*     getCache16() const;\r
-    const SkPMColor*    getCache32() const;\r
-\r
-    void commonAsABitmap(SkBitmap*) const;\r
-    void commonAsAGradient(GradientInfo*) const;\r
-\r
-private:\r
-    enum {\r
-        kColorStorageCount = 4, // more than this many colors, and we'll use sk_malloc for the space\r
-\r
-        kStorageSize = kColorStorageCount * (sizeof(SkColor) + sizeof(Rec))\r
-    };\r
-    SkColor     fStorage[(kStorageSize + 3) >> 2];\r
-    SkColor*    fOrigColors; // original colors, before modulation by paint in setContext\r
-    bool        fColorsAreOpaque;\r
-\r
-    mutable uint16_t*   fCache16;   // working ptr. If this is NULL, we need to recompute the cache values\r
-    mutable SkPMColor*  fCache32;   // working ptr. If this is NULL, we need to recompute the cache values\r
-\r
-    mutable uint16_t*   fCache16Storage;    // storage for fCache16, allocated on demand\r
-    mutable SkMallocPixelRef* fCache32PixelRef;\r
-    mutable unsigned    fCacheAlpha;        // the alpha value we used when we computed the cache. larger than 8bits so we can store uninitialized value\r
-\r
-    static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int count);\r
-    static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int count,\r
-                                U8CPU alpha);\r
-    void setCacheAlpha(U8CPU alpha) const;\r
-    void initCommon();\r
-\r
-    typedef SkShader INHERITED;\r
-};\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-\r
-class GrSamplerState;\r
-class GrProgramStageFactory;\r
-\r
-/*\r
- * The intepretation of the texture matrix depends on the sample mode. The\r
- * texture matrix is applied both when the texture coordinates are explicit\r
- * and  when vertex positions are used as texture  coordinates. In the latter\r
- * case the texture matrix is applied to the pre-view-matrix position \r
- * values.\r
- *\r
- * Normal SampleMode\r
- *  The post-matrix texture coordinates are in normalize space with (0,0) at\r
- *  the top-left and (1,1) at the bottom right.\r
- * RadialGradient\r
- *  The matrix specifies the radial gradient parameters.\r
- *  (0,0) in the post-matrix space is center of the radial gradient.\r
- * Radial2Gradient\r
- *   Matrix transforms to space where first circle is centered at the\r
- *   origin. The second circle will be centered (x, 0) where x may be \r
- *   0 and is provided by setRadial2Params. The post-matrix space is \r
- *   normalized such that 1 is the second radius - first radius.\r
- * SweepGradient\r
- *  The angle from the origin of texture coordinates in post-matrix space\r
- *  determines the gradient value.\r
- */\r
-\r
-// Base class for Gr gradient effects\r
-class GrGradientEffect : public GrCustomStage {\r
-public:\r
-\r
-    GrGradientEffect(GrTexture* texture);\r
-    GrGradientEffect(GrContext* ctx, const SkShader& shader, \r
-                     GrSamplerState* sampler);\r
-\r
-    virtual ~GrGradientEffect();\r
-\r
-    unsigned int numTextures() const;\r
-    GrTexture* texture(unsigned int index) const;\r
-\r
-    bool useTexture() const { return fUseTexture; }\r
-\r
-private:\r
-\r
-    GrTexture* fTexture;\r
-    bool fUseTexture;\r
-\r
-    typedef GrCustomStage INHERITED;\r
-\r
-};\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-\r
-// Base class for GL gradient custom stages\r
-class GrGLGradientStage : public GrGLProgramStage {\r
-public:\r
-\r
-    GrGLGradientStage(const GrProgramStageFactory& factory);\r
-    virtual ~GrGLGradientStage();\r
-\r
-    // emit code that gets a fragment's color from an expression for t; for now\r
-    // this always uses the texture, but for simpler cases we'll be able to lerp\r
-    void emitColorLookup(GrGLShaderBuilder* builder, const char* t, \r
-                         const char* outputColor, const char* samplerName);\r
-\r
-private:\r
-\r
-    typedef GrGLProgramStage INHERITED;\r
-};\r
-\r
-#endif\r
-\r
+
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkGradientShaderPriv_DEFINED
+#define SkGradientShaderPriv_DEFINED
+
+#include "SkGradientShader.h"
+#include "SkClampRange.h"
+#include "SkColorPriv.h"
+#include "SkMallocPixelRef.h"
+#include "SkUnitMapper.h"
+#include "SkUtils.h"
+#include "SkTemplates.h"
+#include "SkBitmapCache.h"
+#include "SkShader.h"
+#include "GrSamplerState.h"
+#include "SkGr.h"
+#include "gl/GrGLProgramStage.h"
+
+#ifndef SK_DISABLE_DITHER_32BIT_GRADIENT
+    #define USE_DITHER_32BIT_GRADIENT
+#endif
+
+static void sk_memset32_dither(uint32_t dst[], uint32_t v0, uint32_t v1,
+                               int count) {
+    if (count > 0) {
+        if (v0 == v1) {
+            sk_memset32(dst, v0, count);
+        } else {
+            int pairs = count >> 1;
+            for (int i = 0; i < pairs; i++) {
+                *dst++ = v0;
+                *dst++ = v1;
+            }
+            if (count & 1) {
+                *dst = v0;
+            }
+        }
+    }
+}
+
+//  Clamp
+
+static SkFixed clamp_tileproc(SkFixed x) {
+    return SkClampMax(x, 0xFFFF);
+}
+
+// Repeat
+
+static SkFixed repeat_tileproc(SkFixed x) {
+    return x & 0xFFFF;
+}
+
+// Mirror
+
+// Visual Studio 2010 (MSC_VER=1600) optimizes bit-shift code incorrectly.
+// See http://code.google.com/p/skia/issues/detail?id=472
+#if defined(_MSC_VER) && (_MSC_VER >= 1600)
+#pragma optimize("", off)
+#endif
+
+static inline SkFixed mirror_tileproc(SkFixed x) {
+    int s = x << 15 >> 31;
+    return (x ^ s) & 0xFFFF;
+}
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1600)
+#pragma optimize("", on)
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+
+typedef SkFixed (*TileProc)(SkFixed);
+
+///////////////////////////////////////////////////////////////////////////////
+
+static const TileProc gTileProcs[] = {
+    clamp_tileproc,
+    repeat_tileproc,
+    mirror_tileproc
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+class SkGradientShaderBase : public SkShader {
+public:
+    SkGradientShaderBase(const SkColor colors[], const SkScalar pos[],
+                int colorCount, SkShader::TileMode mode, SkUnitMapper* mapper);
+    virtual ~SkGradientShaderBase();
+
+    // overrides
+    virtual bool setContext(const SkBitmap&, const SkPaint&, const SkMatrix&) SK_OVERRIDE;
+    virtual uint32_t getFlags() SK_OVERRIDE { return fFlags; }
+    virtual bool isOpaque() const SK_OVERRIDE;
+
+    void getGradientTableBitmap(SkBitmap*) const;
+
+    enum {
+        /// Seems like enough for visual accuracy. TODO: if pos[] deserves
+        /// it, use a larger cache.
+        kCache16Bits    = 8,
+        kGradient16Length = (1 << kCache16Bits),
+        /// Each cache gets 1 extra entry at the end so we don't have to
+        /// test for end-of-cache in lerps. This is also the value used
+        /// to stride *writes* into the dither cache; it must not be zero.
+        /// Total space for a cache is 2x kCache16Count entries: one
+        /// regular cache, one for dithering.
+        kCache16Count   = kGradient16Length + 1,
+        kCache16Shift   = 16 - kCache16Bits,
+        kSqrt16Shift    = 8 - kCache16Bits,
+
+        /// Seems like enough for visual accuracy. TODO: if pos[] deserves
+        /// it, use a larger cache.
+        kCache32Bits    = 8,
+        kGradient32Length = (1 << kCache32Bits),
+        /// Each cache gets 1 extra entry at the end so we don't have to
+        /// test for end-of-cache in lerps. This is also the value used
+        /// to stride *writes* into the dither cache; it must not be zero.
+        /// Total space for a cache is 2x kCache32Count entries: one
+        /// regular cache, one for dithering.
+        kCache32Count   = kGradient32Length + 1,
+        kCache32Shift   = 16 - kCache32Bits,
+        kSqrt32Shift    = 8 - kCache32Bits,
+
+        /// This value is used to *read* the dither cache; it may be 0
+        /// if dithering is disabled.
+#ifdef USE_DITHER_32BIT_GRADIENT
+        kDitherStride32 = kCache32Count,
+#else
+        kDitherStride32 = 0,
+#endif
+        kDitherStride16 = kCache16Count,
+        kLerpRemainderMask32 = (1 << (16 - kCache32Bits)) - 1
+    };
+
+
+protected:
+    SkGradientShaderBase(SkFlattenableReadBuffer& );
+    virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
+
+    SkUnitMapper* fMapper;
+    SkMatrix    fPtsToUnit;     // set by subclass
+    SkMatrix    fDstToIndex;
+    SkMatrix::MapXYProc fDstToIndexProc;
+    TileMode    fTileMode;
+    TileProc    fTileProc;
+    int         fColorCount;
+    uint8_t     fDstToIndexClass;
+    uint8_t     fFlags;
+
+    struct Rec {
+        SkFixed     fPos;   // 0...1
+        uint32_t    fScale; // (1 << 24) / range
+    };
+    Rec*        fRecs;
+
+    const uint16_t*     getCache16() const;
+    const SkPMColor*    getCache32() const;
+
+    void commonAsAGradient(GradientInfo*) const;
+
+private:
+    enum {
+        kColorStorageCount = 4, // more than this many colors, and we'll use sk_malloc for the space
+
+        kStorageSize = kColorStorageCount * (sizeof(SkColor) + sizeof(Rec))
+    };
+    SkColor     fStorage[(kStorageSize + 3) >> 2];
+    SkColor*    fOrigColors; // original colors, before modulation by paint in setContext
+    bool        fColorsAreOpaque;
+
+    mutable uint16_t*   fCache16;   // working ptr. If this is NULL, we need to recompute the cache values
+    mutable SkPMColor*  fCache32;   // working ptr. If this is NULL, we need to recompute the cache values
+
+    mutable uint16_t*   fCache16Storage;    // storage for fCache16, allocated on demand
+    mutable SkMallocPixelRef* fCache32PixelRef;
+    mutable unsigned    fCacheAlpha;        // the alpha value we used when we computed the cache. larger than 8bits so we can store uninitialized value
+
+    static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int count);
+    static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int count,
+                                U8CPU alpha);
+    void setCacheAlpha(U8CPU alpha) const;
+    void initCommon();
+
+    typedef SkShader INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+class GrSamplerState;
+class GrProgramStageFactory;
+
+/*
+ * The intepretation of the texture matrix depends on the sample mode. The
+ * texture matrix is applied both when the texture coordinates are explicit
+ * and  when vertex positions are used as texture  coordinates. In the latter
+ * case the texture matrix is applied to the pre-view-matrix position 
+ * values.
+ *
+ * Normal SampleMode
+ *  The post-matrix texture coordinates are in normalize space with (0,0) at
+ *  the top-left and (1,1) at the bottom right.
+ * RadialGradient
+ *  The matrix specifies the radial gradient parameters.
+ *  (0,0) in the post-matrix space is center of the radial gradient.
+ * Radial2Gradient
+ *   Matrix transforms to space where first circle is centered at the
+ *   origin. The second circle will be centered (x, 0) where x may be 
+ *   0 and is provided by setRadial2Params. The post-matrix space is 
+ *   normalized such that 1 is the second radius - first radius.
+ * SweepGradient
+ *  The angle from the origin of texture coordinates in post-matrix space
+ *  determines the gradient value.
+ */
+
+// Base class for Gr gradient effects
+class GrGradientEffect : public GrCustomStage {
+public:
+
+    // FIXME: This constructor is only used in GrGpuGL_unittest.cpp, and should
+    // be removed once an alternative testing setup has been devised.
+    GrGradientEffect(GrTexture* texture);
+    GrGradientEffect(GrContext* ctx, const SkGradientShaderBase& shader, 
+                     GrSamplerState* sampler);
+
+    virtual ~GrGradientEffect();
+
+    unsigned int numTextures() const;
+    GrTexture* texture(unsigned int index) const;
+
+    bool useTexture() const { return fUseTexture; }
+
+private:
+
+    GrTexture* fTexture;
+    bool fUseTexture;
+
+    typedef GrCustomStage INHERITED;
+
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+// Base class for GL gradient custom stages
+class GrGLGradientStage : public GrGLProgramStage {
+public:
+
+    GrGLGradientStage(const GrProgramStageFactory& factory);
+    virtual ~GrGLGradientStage();
+
+    // emit code that gets a fragment's color from an expression for t; for now
+    // this always uses the texture, but for simpler cases we'll be able to lerp
+    void emitColorLookup(GrGLShaderBuilder* builder, const char* t, 
+                         const char* outputColor, const char* samplerName);
+
+private:
+
+    typedef GrGLProgramStage INHERITED;
+};
+
+#endif
+
index cb6fdaf81be372b3f53ccc60db8985f2b1a47c92..49e93459f2096dd52b3a964b268a0819105b28ad 100644 (file)
@@ -291,7 +291,7 @@ SkShader::BitmapType SkLinearGradient::asABitmap(SkBitmap* bitmap,
                                                 SkMatrix* matrix,
                                                 TileMode xy[]) const {
     if (bitmap) {
-        this->commonAsABitmap(bitmap);
+        this->getGradientTableBitmap(bitmap);
     }
     if (matrix) {
         matrix->preConcat(fPtsToUnit);
@@ -518,13 +518,13 @@ void GrGLLinearGradient::emitFS(GrGLShaderBuilder* builder,
 /////////////////////////////////////////////////////////////////////
 
 GrLinearGradient::GrLinearGradient(GrTexture* texture)
-                  : INHERITED(texture) { 
+    : INHERITED(texture) { 
 }
 
 GrLinearGradient::GrLinearGradient(GrContext* ctx, 
-                                   const SkShader& shader,
+                                   const SkLinearGradient& shader,
                                    GrSamplerState* sampler)
-                                   : INHERITED(ctx, shader, sampler) {
+    : INHERITED(ctx, shader, sampler) {
 }
 
 GrLinearGradient::~GrLinearGradient() {
index 714bcdc5f628006dbd4341b8a040fed5956b889e..c4b1b4672d7a74f9bac1ce660e6419ae7617560f 100644 (file)
@@ -46,7 +46,7 @@ class GrLinearGradient : public GrGradientEffect {
 public:
 
     GrLinearGradient(GrTexture* texture);
-    GrLinearGradient(GrContext* ctx, const SkShader& shader,
+    GrLinearGradient(GrContext* ctx, const SkLinearGradient& shader,
                      GrSamplerState* sampler);
     virtual ~GrLinearGradient();
 
index 8feeff5313c21cc076c41d010fe00aac86dc46d7..3a0583bf01f036ac79c535ea55e2deb72bf6550f 100644 (file)
@@ -222,7 +222,7 @@ void SkRadialGradient::shadeSpan16(int x, int y, uint16_t* dstCParam,
 SkShader::BitmapType SkRadialGradient::asABitmap(SkBitmap* bitmap, 
     SkMatrix* matrix, SkShader::TileMode* xy) const {
     if (bitmap) {
-        this->commonAsABitmap(bitmap);
+        this->getGradientTableBitmap(bitmap);
     }
     if (matrix) {
         matrix->setScale(SkIntToScalar(kGradient32Length),
@@ -520,9 +520,10 @@ GrRadialGradient::GrRadialGradient(GrTexture* texture)
 
 }
 
-GrRadialGradient::GrRadialGradient(GrContext* ctx, const SkShader& shader,
+GrRadialGradient::GrRadialGradient(GrContext* ctx, 
+                                   const SkRadialGradient& shader,
                                    GrSamplerState* sampler)
-                                   : INHERITED(ctx, shader, sampler) {
+    : INHERITED(ctx, shader, sampler) {
 }
 
 GrRadialGradient::~GrRadialGradient() {
index a03d7204286cf4cc79c0965267698c7ecb1a2358..0b7e30c2d4d08b4662c228363260251025b4a321 100644 (file)
@@ -48,7 +48,7 @@ class GrRadialGradient : public GrGradientEffect {
 public:
 
     GrRadialGradient(GrTexture* texture);
-    GrRadialGradient(GrContext* ctx, const SkShader& shader,
+    GrRadialGradient(GrContext* ctx, const SkRadialGradient& shader,
                      GrSamplerState* sampler);
     virtual ~GrRadialGradient();
 
index 7f504948fe9f39f5afe43e54a0b1e741968a03e7..963485cdf19c69316cc7bc6440cc2d9bab43c99c 100644 (file)
@@ -19,7 +19,7 @@ SkSweepGradient::SkSweepGradient(SkScalar cx, SkScalar cy, const SkColor colors[
 SkShader::BitmapType SkSweepGradient::asABitmap(SkBitmap* bitmap,
     SkMatrix* matrix, SkShader::TileMode* xy) const {
     if (bitmap) {
-        this->commonAsABitmap(bitmap);
+        this->getGradientTableBitmap(bitmap);
     }
     if (matrix) {
         *matrix = fPtsToUnit;
@@ -429,7 +429,8 @@ GrSweepGradient::GrSweepGradient(GrTexture* texture)
 
 }
 
-GrSweepGradient::GrSweepGradient(GrContext* ctx, const SkShader& shader,
+GrSweepGradient::GrSweepGradient(GrContext* ctx, 
+                                 const SkSweepGradient& shader,
                                  GrSamplerState* sampler) 
                                  : INHERITED(ctx, shader, sampler) {
 }
index 1c2995a6f8d6029df8e6a539d713e1927b8e7dcc..9a6c4eee6d076ef69b21bca2dd7b7f6beeb84a57 100644 (file)
@@ -47,7 +47,7 @@ class GrSweepGradient : public GrGradientEffect {
 public:
 
     GrSweepGradient(GrTexture* texture);
-    GrSweepGradient(GrContext* ctx, const SkShader& shader,
+    GrSweepGradient(GrContext* ctx, const SkSweepGradient& shader,
                      GrSamplerState* sampler);
     virtual ~GrSweepGradient();
 
index 40ce528bef692f56b74e7c15a3c87f6cd640870b..feef3b9e1e162594ac697cf2af52bf1dfe839949 100644 (file)
@@ -257,7 +257,7 @@ SkShader::BitmapType SkTwoPointConicalGradient::asABitmap(
     SkScalar diffLen = 0;
 
     if (bitmap) {
-        this->commonAsABitmap(bitmap);
+        this->getGradientTableBitmap(bitmap);
     }
     if (matrix) {
         diffLen = diff.length();
@@ -308,8 +308,7 @@ GrCustomStage* SkTwoPointConicalGradient::asNewCustomStage(
     sampler->textureParams()->setTileModeX(fTileMode);
     sampler->textureParams()->setTileModeY(kClamp_TileMode);
     sampler->textureParams()->setBilerp(true);
-    return SkNEW_ARGS(GrConical2Gradient, (context, *this, sampler, 
-                      diffLen, fRadius1, fRadius2 - fRadius1));
+    return SkNEW_ARGS(GrConical2Gradient, (context, *this, sampler));
 }
 
 SkTwoPointConicalGradient::SkTwoPointConicalGradient(
@@ -611,7 +610,7 @@ GrConical2Gradient::GrConical2Gradient(GrTexture* texture,
                                        GrScalar center,
                                        GrScalar radius,
                                        GrScalar diffRadius)
-    : INHERITED (texture)
+    : INHERITED(texture)
     , fCenterX1 (center)
     , fRadius0 (radius)
     , fDiffRadius (diffRadius) {
@@ -619,15 +618,12 @@ GrConical2Gradient::GrConical2Gradient(GrTexture* texture,
 }
 
 GrConical2Gradient::GrConical2Gradient(GrContext* ctx, 
-                                       const SkShader& shader,
-                                       GrSamplerState* sampler,
-                                       SkScalar center,
-                                       SkScalar startRadius,
-                                       SkScalar diffRadius)
-                                       : INHERITED(ctx, shader, sampler) 
-                                       , fCenterX1(center)
-                                       , fRadius0(startRadius)
-                                       , fDiffRadius(diffRadius) {
+                                       const SkTwoPointConicalGradient& shader,
+                                       GrSamplerState* sampler)
+    : INHERITED(ctx, shader, sampler) 
+    , fCenterX1(shader.getCenterX1())
+    , fRadius0(shader.getStartRadius())
+    , fDiffRadius(shader.getDiffRadius()) {
 }
 
 GrConical2Gradient::~GrConical2Gradient() {
index fe25fde2030670bd52e0c6a60a8c98ea4b861c52..733ae522c9f4de2d0ac3d6253685227172feaf69 100644 (file)
@@ -64,6 +64,10 @@ public:
     virtual GrCustomStage* asNewCustomStage(GrContext* context,
         GrSamplerState* sampler) const SK_OVERRIDE;
 
+    SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }
+    SkScalar getStartRadius() const { return fRadius1; }
+    SkScalar getDiffRadius() const { return fRadius2 - fRadius1; }
+
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient)
     
 protected:
@@ -87,9 +91,8 @@ class GrConical2Gradient : public GrGradientEffect {
 public:
 
     GrConical2Gradient(GrTexture* texture, GrScalar center, GrScalar radius, GrScalar diffRadius);
-    GrConical2Gradient(GrContext* ctx, const SkShader& shader,
-                       GrSamplerState* sampler, SkScalar center, 
-                       SkScalar radius, SkScalar diffRadius);
+    GrConical2Gradient(GrContext* ctx, const SkTwoPointConicalGradient& shader,
+                       GrSamplerState* sampler);
     virtual ~GrConical2Gradient();
 
     static const char* Name() { return "Two-Point Conical Gradient"; }
index d2612a4f78d23d37616c9887c5cf6da1783a6b3f..ed21d7518032bc616033317a25f03809095b35b6 100644 (file)
@@ -184,7 +184,7 @@ SkShader::BitmapType SkTwoPointRadialGradient::asABitmap(
     SkMatrix* matrix,
     SkShader::TileMode* xy) const {
     if (bitmap) {
-        this->commonAsABitmap(bitmap);
+        this->getGradientTableBitmap(bitmap);
     }
     SkScalar diffL = 0; // just to avoid gcc warning
     if (matrix) {
@@ -235,8 +235,7 @@ GrCustomStage* SkTwoPointRadialGradient::asNewCustomStage(
     sampler->textureParams()->setTileModeX(fTileMode);
     sampler->textureParams()->setTileModeY(kClamp_TileMode);
     sampler->textureParams()->setBilerp(true);
-    return SkNEW_ARGS(GrRadial2Gradient, (context, *this, sampler, 
-        diffLen, fStartRadius, fDiffRadius));
+    return SkNEW_ARGS(GrRadial2Gradient, (context, *this, sampler));
 }
 
 void SkTwoPointRadialGradient::shadeSpan(int x, int y, SkPMColor* dstCParam,
@@ -590,17 +589,15 @@ GrRadial2Gradient::GrRadial2Gradient(GrTexture* texture,
 }
 
 GrRadial2Gradient::GrRadial2Gradient(GrContext* ctx, 
-                                     const SkShader& shader, 
-                                     GrSamplerState* sampler,
-                                     SkScalar center,
-                                     SkScalar startRadius,
-                                     SkScalar diffRadius)
-                                     : INHERITED(ctx, shader, sampler)
-                                     , fCenterX1(center)
-                                     , fRadius0(startRadius) 
-                                     , fPosRoot(diffRadius < 0) {
+                                     const SkTwoPointRadialGradient& shader, 
+                                     GrSamplerState* sampler)
+    : INHERITED(ctx, shader, sampler)
+    , fCenterX1(shader.getCenterX1())
+    , fRadius0(shader.getStartRadius()) 
+    , fPosRoot(shader.getDiffRadius() < 0) {
 }
 
+
 GrRadial2Gradient::~GrRadial2Gradient() {
 
 }
index 6d2b916e5d82d71e504a313e4ef256fc7122a29b..bf94c3cc143ccde95d03c158f846ad86f51a3baa 100644 (file)
@@ -32,6 +32,10 @@ public:
                             const SkPaint& paint,
                             const SkMatrix& matrix) SK_OVERRIDE;
 
+    SkScalar getCenterX1() const { return fDiff.length(); }
+    SkScalar getStartRadius() const { return fStartRadius; }
+    SkScalar getDiffRadius() const { return fDiffRadius; }
+
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointRadialGradient)
 
 protected:
@@ -59,9 +63,8 @@ class GrRadial2Gradient : public GrGradientEffect {
 public:
 
     GrRadial2Gradient(GrTexture* texture, GrScalar center, GrScalar radius, bool posRoot);
-    GrRadial2Gradient(GrContext* ctx, const SkShader& shader,
-                      GrSamplerState* sampler, SkScalar center, 
-                      SkScalar radius, SkScalar diffRadius);
+    GrRadial2Gradient(GrContext* ctx, const SkTwoPointRadialGradient& shader,
+                      GrSamplerState* sampler);
     virtual ~GrRadial2Gradient();
 
     static const char* Name() { return "Two-Point Radial Gradient"; }