Require matrix for custom stage to be set when custom stage is installed.
authorbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 16 Oct 2012 14:16:11 +0000 (14:16 +0000)
committerbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 16 Oct 2012 14:16:11 +0000 (14:16 +0000)
Review URL: https://codereview.appspot.com/6696044

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

22 files changed:
gm/texdata.cpp
include/core/SkShader.h
include/gpu/GrSamplerState.h
src/core/SkShader.cpp
src/effects/SkBlendImageFilter.cpp
src/effects/SkMorphologyImageFilter.cpp
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
src/gpu/GrClipMaskManager.cpp
src/gpu/GrContext.cpp
src/gpu/GrDrawState.cpp
src/gpu/GrDrawState.h
src/gpu/GrTextContext.cpp
src/gpu/SkGpuDevice.cpp

index 724b4ec8260f760a1f3935000001c67653e1e703..09721acc13e70075e86e387818943b05bf8d7edc 100644 (file)
@@ -112,12 +112,9 @@ protected:
                 ctx->setMatrix(vm);
                 GrMatrix tm;
                 tm = vm;
-                GrMatrix* sampleMat = paint.colorSampler(0)->matrix();
-                *sampleMat = vm;
-                sampleMat->postIDiv(2*S, 2*S);
-                paint.colorSampler(0)->setCustomStage(
-                    SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
-
+                tm.postIDiv(2*S, 2*S);
+                paint.colorSampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect,
+                                                                 (texture)), tm)->unref();
 
                 ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));
 
index 8eb695cd14502af1393e33cb78e0a21bb3d69bdf..a0a1b056d4339d8180881fb3344cc7c400dcf992 100644 (file)
@@ -306,14 +306,13 @@ public:
     virtual GradientType asAGradient(GradientInfo* info) const;
 
     /**
-     *  If the shader subclass has a GrCustomStage implementation, this returns
-     *  a new custom stage (the caller assumes ownership, and will need to
-     *  unref it). A GrContext pointer is required since custom stages may
-     *  need to create textures. The sampler parameter is necessary to set
-     *  up matrix/tile modes/etc, and will eventually be removed.
+     *  If the shader subclass has a GrCustomStage implementation, this installs
+     *  a custom stage on the sampler. A GrContext pointer is required since custom
+     *  stages may need to create textures. The sampler parameter is necessary to set a
+     *  texture matrix. It will eventually be removed and this function will operate as a
+     *  GrCustomStage factory.
      */
-    virtual GrCustomStage* asNewCustomStage(GrContext* context,
-                                            GrSamplerState* sampler) const;
+    virtual bool asNewCustomStage(GrContext* context, GrSamplerState* sampler) const;
 
     //////////////////////////////////////////////////////////////////////////
     //  Factory methods for stock shaders
index 385dba7bddf6bdadc96521ea612f27ddadc97ed2..da52e952771ab396ec636652d6ccd71a54bb7b59 100644 (file)
 
 class GrSamplerState {
 public:
-    static const bool kBilerpDefault = false;
 
-    static const SkShader::TileMode kTileModeDefault = SkShader::kClamp_TileMode;
-
-    /**
-     * Default sampler state is set to clamp, use normal sampling mode, be
-     * unfiltered, and use identity matrix.
-     */
     GrSamplerState()
     : fCustomStage (NULL) {
         memset(this, 0, sizeof(GrSamplerState));
@@ -62,12 +55,6 @@ public:
 
     const GrMatrix& getMatrix() const { return fMatrix; }
 
-    /**
-     * Access the sampler's matrix. See SampleMode for explanation of
-     * relationship between the matrix and sample mode.
-     */
-    GrMatrix* matrix() { return &fMatrix; }
-
     /**
      *  Multiplies the current sampler matrix  a matrix
      *
@@ -80,10 +67,10 @@ public:
      */
     void preConcatMatrix(const GrMatrix& matrix) { fMatrix.preConcat(matrix); }
 
-    void reset(const GrMatrix& matrix) {
-        fMatrix = matrix;
-        GrSafeSetNull(fCustomStage);
-    }
+    /**
+     * Do not call this function. It will be removed soon.
+     */
+    void setMatrixDeprecated(const GrMatrix& matrix) { fMatrix = matrix; }
 
     void reset() {
         fMatrix.reset();
@@ -92,8 +79,16 @@ public:
 
     GrCustomStage* setCustomStage(GrCustomStage* stage) {
         GrSafeAssign(fCustomStage, stage);
+        fMatrix.reset();
         return stage;
     }
+
+    GrCustomStage* setCustomStage(GrCustomStage* stage, const GrMatrix& matrix) {
+        GrSafeAssign(fCustomStage, stage);
+        fMatrix = matrix;
+        return stage;
+    }
+
     const GrCustomStage* getCustomStage() const { return fCustomStage; }
 
 private:
index 2f1def62c18f7a1c762542cfc14071d3bd911d5c..7e3a92bc57dcbb73adcf79fd94e472431c3d6dae 100644 (file)
@@ -205,9 +205,8 @@ SkShader::GradientType SkShader::asAGradient(GradientInfo* info) const {
     return kNone_GradientType;
 }
 
-GrCustomStage* SkShader::asNewCustomStage(GrContext* context,
-                                          GrSamplerState* sampler) const {
-    return NULL;
+bool SkShader::asNewCustomStage(GrContext*, GrSamplerState*) const {
+    return false;
 }
 
 SkShader* SkShader::CreateBitmapShader(const SkBitmap& src,
index 7933e27999739d86d0588bcf2bb254b40a8555f8..1fa3c0da6b25d27331470a17f03d1450871b49f9 100644 (file)
@@ -206,10 +206,8 @@ GrTexture* SkBlendImageFilter::onFilterImageGPU(Proxy* proxy, GrTexture* src, co
     GrMatrix sampleM;
     sampleM.setIDiv(background->width(), background->height());
     GrPaint paint;
-    paint.colorSampler(0)->reset(sampleM);
-    paint.colorSampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (background.get())))->unref();
-    paint.colorSampler(1)->reset(sampleM);
-    paint.colorSampler(1)->setCustomStage(SkNEW_ARGS(GrBlendEffect, (fMode, foreground.get())))->unref();
+    paint.colorSampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (background.get())), sampleM)->unref();
+    paint.colorSampler(1)->setCustomStage(SkNEW_ARGS(GrBlendEffect, (fMode, foreground.get())), sampleM)->unref();
     context->drawRect(paint, rect);
     return dst;
 }
index 64d22be56ec05f04ce9658effb09d865f568ee0f..9bddb9b9e648044b446223e158ddce99de430e99 100644 (file)
@@ -431,8 +431,7 @@ void apply_morphology_pass(GrContext* context,
     GrMatrix sampleM;
     sampleM.setIDiv(texture->width(), texture->height());
     GrPaint paint;
-    paint.colorSampler(0)->reset(sampleM);
-    paint.colorSampler(0)->setCustomStage(SkNEW_ARGS(GrMorphologyEffect, (texture, direction, radius, morphType)))->unref();
+    paint.colorSampler(0)->setCustomStage(SkNEW_ARGS(GrMorphologyEffect, (texture, direction, radius, morphType)), sampleM)->unref();
     context->drawRect(paint, rect);
 }
 
index 4b673f669116134d3d5085e037f2319b8f8305c5..fff218010aab2f7451bf835b32115478f2394039 100644 (file)
@@ -539,9 +539,11 @@ GrCustomStage* GrLinearGradient::TestCreate(SkRandom* random,
                                                                  colors, stops, colorCount,
                                                                  tm));
     GrSamplerState sampler;
-    GrCustomStage* stage = shader->asNewCustomStage(context, &sampler);
-    GrAssert(NULL != stage);
-    return stage;
+    shader->asNewCustomStage(context, &sampler);
+    GrAssert(NULL != sampler.getCustomStage());
+    // const_cast and ref is a hack! Will remove when asNewCustomStage returns GrCustomStage*
+    sampler.getCustomStage()->ref();
+    return const_cast<GrCustomStage*>(sampler.getCustomStage());
 }
 
 /////////////////////////////////////////////////////////////////////
@@ -557,19 +559,30 @@ void GrGLLinearGradient::emitFS(GrGLShaderBuilder* builder,
 
 /////////////////////////////////////////////////////////////////////
 
-GrCustomStage* SkLinearGradient::asNewCustomStage(GrContext* context,
-                                                  GrSamplerState* sampler) const {
+bool SkLinearGradient::asNewCustomStage(GrContext* context, GrSamplerState* sampler) const {
     SkASSERT(NULL != context && NULL != sampler);
-    sampler->matrix()->preConcat(fPtsToUnit);
-    return SkNEW_ARGS(GrLinearGradient, (context, *this, fTileMode));
+
+    SkAutoTUnref<GrCustomStage> stage(SkNEW_ARGS(GrLinearGradient, (context, *this, fTileMode)));
+
+    SkMatrix matrix;
+    if (this->getLocalMatrix(&matrix)) {
+        if (!matrix.invert(&matrix)) {
+            return false;
+        }
+        matrix.postConcat(fPtsToUnit);
+        sampler->setCustomStage(stage, matrix);
+    } else {
+        sampler->setCustomStage(stage, fPtsToUnit);
+    }
+    
+    return true;
 }
 
 #else
 
-GrCustomStage* SkLinearGradient::asNewCustomStage(GrContext* context,
-                                                  GrSamplerState* sampler) const {
+bool SkLinearGradient::asNewCustomStage(GrContext*, GrSamplerState*) const {
     SkDEBUGFAIL("Should not call in GPU-less build");
-    return NULL;
+    return false;
 }
 
 #endif
index 129a56aadc0ffb73af4ccfa2b1851c99245d9578..fe60543d529242ec9b39c990efb44b6651ad2ccb 100644 (file)
@@ -22,8 +22,7 @@ public:
     virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
     virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE;
     virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
-    virtual GrCustomStage* asNewCustomStage(GrContext* context,
-                                            GrSamplerState* sampler) const SK_OVERRIDE;
+    virtual bool asNewCustomStage(GrContext* context, GrSamplerState* sampler) const SK_OVERRIDE;
 
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient)
 
index 512eafb2bad442f41f32eb9d9f10ea6c00491876..0156acdd54a5ae2c81ecf1abbeddbabde91d8de0 100644 (file)
@@ -538,9 +538,11 @@ GrCustomStage* GrRadialGradient::TestCreate(SkRandom* random,
                                                                  colors, stops, colorCount,
                                                                  tm));
     GrSamplerState sampler;
-    GrCustomStage* stage = shader->asNewCustomStage(context, &sampler);
-    GrAssert(NULL != stage);
-    return stage;
+    shader->asNewCustomStage(context, &sampler);
+    GrAssert(NULL != sampler.getCustomStage());
+    // const_cast and ref is a hack! Will remove when asNewCustomStage returns GrCustomStage*
+    sampler.getCustomStage()->ref();
+    return const_cast<GrCustomStage*>(sampler.getCustomStage());
 }
 
 /////////////////////////////////////////////////////////////////////
@@ -556,19 +558,29 @@ void GrGLRadialGradient::emitFS(GrGLShaderBuilder* builder,
 
 /////////////////////////////////////////////////////////////////////
 
-GrCustomStage* SkRadialGradient::asNewCustomStage(GrContext* context,
-    GrSamplerState* sampler) const {
+bool SkRadialGradient::asNewCustomStage(GrContext* context, GrSamplerState* sampler) const {
     SkASSERT(NULL != context && NULL != sampler);
-    sampler->matrix()->preConcat(fPtsToUnit);
-    return SkNEW_ARGS(GrRadialGradient, (context, *this, fTileMode));
+    SkAutoTUnref<GrCustomStage> stage(SkNEW_ARGS(GrRadialGradient, (context, *this, fTileMode)));
+
+    SkMatrix matrix;
+    if (this->getLocalMatrix(&matrix)) {
+        if (!matrix.invert(&matrix)) {
+            return false;
+        }
+        matrix.postConcat(fPtsToUnit);
+        sampler->setCustomStage(stage, matrix);
+    } else {
+        sampler->setCustomStage(stage, fPtsToUnit);
+    }
+
+    return true;
 }
 
 #else
 
-GrCustomStage* SkRadialGradient::asNewCustomStage(GrContext* context,
-    GrSamplerState* sampler) const {
+bool SkRadialGradient::asNewCustomStage(GrContext*, GrSamplerState*) const {
     SkDEBUGFAIL("Should not call in GPU-less build");
-    return NULL;
+    return false;
 }
 
 #endif
index 23a35f7fd297ff7482435f1e63d27d6d0c8eafc8..fc17520e291f3b34086e4cb46d54ea7c568ef927 100644 (file)
@@ -24,8 +24,7 @@ public:
                                  SkMatrix* matrix,
                                  TileMode* xy) const SK_OVERRIDE;
     virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
-    virtual GrCustomStage* asNewCustomStage(GrContext* context,
-        GrSamplerState* sampler) const SK_OVERRIDE;
+    virtual bool asNewCustomStage(GrContext* context, GrSamplerState* sampler) const SK_OVERRIDE;
 
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkRadialGradient)
 
index f18b08ea9cd45d3e46ea66a16666335b6bd7b450..d8cbf9ceb6e8034f36e68a6780468fba360403e9 100644 (file)
@@ -444,9 +444,10 @@ GrCustomStage* GrSweepGradient::TestCreate(SkRandom* random,
     SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, center.fY,
                                                                 colors, stops, colorCount));
     GrSamplerState sampler;
-    GrCustomStage* stage = shader->asNewCustomStage(context, &sampler);
-    GrAssert(NULL != stage);
-    return stage;
+    shader->asNewCustomStage(context, &sampler);
+    GrAssert(NULL != sampler.getCustomStage());
+    // const_cast and ref is a hack! Will remove when asNewCustomStage returns GrCustomStage*
+    return const_cast<GrCustomStage*>(sampler.getCustomStage());
 }
 
 /////////////////////////////////////////////////////////////////////
@@ -463,18 +464,29 @@ void GrGLSweepGradient::emitFS(GrGLShaderBuilder* builder,
 
 /////////////////////////////////////////////////////////////////////
 
-GrCustomStage* SkSweepGradient::asNewCustomStage(GrContext* context,
-    GrSamplerState* sampler) const {
-    sampler->matrix()->preConcat(fPtsToUnit);
-    return SkNEW_ARGS(GrSweepGradient, (context, *this));
+bool SkSweepGradient::asNewCustomStage(GrContext* context, GrSamplerState* sampler) const {
+    SkAutoTUnref<GrCustomStage> stage(SkNEW_ARGS(GrSweepGradient, (context, *this)));
+
+
+    SkMatrix matrix;
+    if (this->getLocalMatrix(&matrix)) {
+        if (!matrix.invert(&matrix)) {
+            return false;
+        }
+        matrix.postConcat(fPtsToUnit);
+        sampler->setCustomStage(stage, matrix);
+    } else {
+        sampler->setCustomStage(stage, fPtsToUnit);
+    }
+    
+    return true;
 }
 
 #else
 
-GrCustomStage* SkSweepGradient::asNewCustomStage(GrContext* context,
-    GrSamplerState* sampler) const {
+bool SkSweepGradient::asNewCustomStage(GrContext*, GrSamplerState*) const {
     SkDEBUGFAIL("Should not call in GPU-less build");
-    return NULL;
+    return false;
 }
 
 #endif
index 2b9dfeb6757e0ee6cd30e1287574f8cf929abe0d..8e42be09216cb5219dee19f704756f988ba0da43 100644 (file)
@@ -24,8 +24,7 @@ public:
 
     virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
 
-    virtual GrCustomStage* asNewCustomStage(GrContext* context,
-        GrSamplerState* sampler) const SK_OVERRIDE;
+    virtual bool asNewCustomStage(GrContext* context, GrSamplerState* sampler) const SK_OVERRIDE;
 
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSweepGradient)
 
index 31e3b37c13db87494b4db3721befbd587e7ac0a3..19b1228c88ed480b5ce9db4a34451c4abcac80e4 100644 (file)
@@ -441,9 +441,11 @@ GrCustomStage* GrConical2Gradient::TestCreate(SkRandom* random,
                                                                           colors, stops, colorCount,
                                                                           tm));
     GrSamplerState sampler;
-    GrCustomStage* stage = shader->asNewCustomStage(context, &sampler);
-    GrAssert(NULL != stage);
-    return stage;
+    shader->asNewCustomStage(context, &sampler);
+    GrAssert(NULL != sampler.getCustomStage());
+    // const_cast and ref is a hack! Will remove when asNewCustomStage returns GrCustomStage*
+    sampler.getCustomStage()->ref();
+    return const_cast<GrCustomStage*>(sampler.getCustomStage());
 }
 
 
@@ -673,28 +675,40 @@ GrCustomStage::StageKey GrGLConical2Gradient::GenKey(const GrCustomStage& s, con
 
 /////////////////////////////////////////////////////////////////////
 
-GrCustomStage* SkTwoPointConicalGradient::asNewCustomStage(
-    GrContext* context, GrSamplerState* sampler) const {
+bool SkTwoPointConicalGradient::asNewCustomStage(GrContext* context,
+                                                 GrSamplerState* sampler) const {
     SkASSERT(NULL != context && NULL != sampler);
+
+    SkMatrix matrix;
     SkPoint diff = fCenter2 - fCenter1;
     SkScalar diffLen = diff.length();
     if (0 != diffLen) {
         SkScalar invDiffLen = SkScalarInvert(diffLen);
-        sampler->matrix()->setSinCos(-SkScalarMul(invDiffLen, diff.fY),
-                          SkScalarMul(invDiffLen, diff.fX));
+        matrix.setSinCos(-SkScalarMul(invDiffLen, diff.fY),
+                         SkScalarMul(invDiffLen, diff.fX));
     } else {
-        sampler->matrix()->reset();
+        matrix.reset();
+    }
+    matrix.preTranslate(-fCenter1.fX, -fCenter1.fY);
+
+    SkMatrix localM;
+    if (this->getLocalMatrix(&localM)) {
+        if (!localM.invert(&localM)) {
+            return false;
+        }
+        matrix.preConcat(localM);
     }
-    sampler->matrix()->preTranslate(-fCenter1.fX, -fCenter1.fY);
-    return SkNEW_ARGS(GrConical2Gradient, (context, *this, fTileMode));
+
+    sampler->setCustomStage(SkNEW_ARGS(GrConical2Gradient, (context, *this, fTileMode)), matrix)->unref();
+
+    return true;
 }
 
 #else
 
-GrCustomStage* SkTwoPointConicalGradient::asNewCustomStage(
-    GrContext* context, GrSamplerState* sampler) const {
+bool SkTwoPointConicalGradient::asNewCustomStage(GrContext*, GrSamplerState*) const {
     SkDEBUGFAIL("Should not call in GPU-less build");
-    return NULL;
+    return false;
 }
 
 #endif
index 4ce72801e040b76b608793c8337325a19c1b7aa1..40544919c3d774615ca289b0e069499e9ebdbeac 100644 (file)
@@ -61,8 +61,7 @@ public:
                                  SkMatrix* matrix,
                                  TileMode* xy) const;
     virtual SkShader::GradientType asAGradient(GradientInfo* info) const  SK_OVERRIDE;
-    virtual GrCustomStage* asNewCustomStage(GrContext* context,
-        GrSamplerState* sampler) const SK_OVERRIDE;
+    virtual bool asNewCustomStage(GrContext* context, GrSamplerState* sampler) const SK_OVERRIDE;
 
     SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }
     SkScalar getStartRadius() const { return fRadius1; }
index 97f335d97c780309d7f23f5dedf115195736a730..2715511e1b0503375ad3fd4adb281728e0958d8e 100644 (file)
@@ -475,9 +475,11 @@ GrCustomStage* GrRadial2Gradient::TestCreate(SkRandom* random,
                                                                          colors, stops, colorCount,
                                                                          tm));
     GrSamplerState sampler;
-    GrCustomStage* stage = shader->asNewCustomStage(context, &sampler);
-    GrAssert(NULL != stage);
-    return stage;
+    shader->asNewCustomStage(context, &sampler);
+    GrAssert(NULL != sampler.getCustomStage());
+    // const_cast and ref is a hack! Will remove when asNewCustomStage returns GrCustomStage*
+    sampler.getCustomStage()->ref();
+    return const_cast<GrCustomStage*>(sampler.getCustomStage());
 }
 
 /////////////////////////////////////////////////////////////////////
@@ -647,27 +649,38 @@ GrCustomStage::StageKey GrGLRadial2Gradient::GenKey(const GrCustomStage& s, cons
 
 /////////////////////////////////////////////////////////////////////
 
-GrCustomStage* SkTwoPointRadialGradient::asNewCustomStage(
-    GrContext* context, GrSamplerState* sampler) const {
+bool SkTwoPointRadialGradient::asNewCustomStage(GrContext* context,
+                                                GrSamplerState* sampler) const {
     SkASSERT(NULL != context && NULL != sampler);
     SkScalar diffLen = fDiff.length();
+    SkMatrix matrix;
     if (0 != diffLen) {
         SkScalar invDiffLen = SkScalarInvert(diffLen);
-        sampler->matrix()->setSinCos(-SkScalarMul(invDiffLen, fDiff.fY),
-                                     SkScalarMul(invDiffLen, fDiff.fX));
+        matrix.setSinCos(-SkScalarMul(invDiffLen, fDiff.fY),
+                         SkScalarMul(invDiffLen, fDiff.fX));
     } else {
-        sampler->matrix()->reset();
+        matrix.reset();
     }
-    sampler->matrix()->preConcat(fPtsToUnit);
-    return SkNEW_ARGS(GrRadial2Gradient, (context, *this, fTileMode));
+    
+    matrix.preConcat(fPtsToUnit);
+
+    SkMatrix localM;
+    if (this->getLocalMatrix(&localM)) {
+        if (!localM.invert(&localM)) {
+            return false;
+        }
+        matrix.preConcat(localM);
+    }
+
+    sampler->setCustomStage(SkNEW_ARGS(GrRadial2Gradient, (context, *this, fTileMode)), matrix)->unref();
+    return true;
 }
 
 #else
 
-GrCustomStage* SkTwoPointRadialGradient::asNewCustomStage(
-    GrContext* context, GrSamplerState* sampler) const {
+bool SkTwoPointRadialGradient::asNewCustomStage(GrContext*, GrSamplerState*) const {
     SkDEBUGFAIL("Should not call in GPU-less build");
-    return NULL;
+    return false;
 }
 
 #endif
index a6036f176fd6b62044b20f369817f18937ccae80..adbb6022652f1112398d4e0e3c6ae87d8da37a58 100644 (file)
@@ -23,8 +23,7 @@ public:
                                  SkMatrix* matrix,
                                  TileMode* xy) const SK_OVERRIDE;
     virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
-    virtual GrCustomStage* asNewCustomStage(GrContext* context,
-        GrSamplerState* sampler) const SK_OVERRIDE;
+    virtual bool asNewCustomStage(GrContext* context, GrSamplerState* sampler) const SK_OVERRIDE;
 
     virtual void shadeSpan(int x, int y, SkPMColor* dstCParam,
                            int count) SK_OVERRIDE;
index 322fba146a55c2bdd5bc98c74a1ca16ad4896deb..aa0c0249a840fd158bb53698dba0711c1772865e 100644 (file)
@@ -41,9 +41,7 @@ void setup_drawstate_aaclip(GrGpu* gpu,
                      SkIntToScalar(-devBound.fTop));
     mat.preConcat(drawState->getViewMatrix());
 
-    drawState->sampler(maskStage)->reset(mat);
-
-    drawState->createTextureEffect(maskStage, result);
+    drawState->createTextureEffect(maskStage, result, mat);
 }
 
 bool path_needs_SW_renderer(GrContext* context,
@@ -495,8 +493,7 @@ void GrClipMaskManager::drawTexture(GrTexture* target,
     GrMatrix sampleM;
     sampleM.setIDiv(texture->width(), texture->height());
 
-    drawState->sampler(0)->reset(sampleM);
-    drawState->createTextureEffect(0, texture);
+    drawState->createTextureEffect(0, texture, sampleM);
 
     GrRect rect = GrRect::MakeWH(SkIntToScalar(target->width()),
                                  SkIntToScalar(target->height()));
index ee3a4e1afb841a8f051bb180b65e0315a5e016ea..8b7d2d0285dbe6f7eb847c6079089142003a4a5c 100644 (file)
@@ -202,11 +202,10 @@ void convolve_gaussian(GrDrawTarget* target,
     drawState->setRenderTarget(rt);
     GrMatrix sampleM;
     sampleM.setIDiv(texture->width(), texture->height());
-    drawState->sampler(0)->reset(sampleM);
     SkAutoTUnref<GrConvolutionEffect> conv(SkNEW_ARGS(GrConvolutionEffect,
                                                       (texture, direction, radius,
                                                        sigma)));
-    drawState->sampler(0)->setCustomStage(conv);
+    drawState->sampler(0)->setCustomStage(conv, sampleM);
     target->drawSimpleRect(rect, NULL);
 }
 
@@ -313,9 +312,8 @@ GrTexture* GrContext::createResizedTexture(const GrTextureDesc& desc,
         // if filtering is not desired then we want to ensure all
         // texels in the resampled image are copies of texels from
         // the original.
-        drawState->sampler(0)->reset();
         GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering);
-        drawState->createTextureEffect(0, clampedTexture, params);
+        drawState->createTextureEffect(0, clampedTexture, GrMatrix::I(), params);
 
         static const GrVertexLayout layout =
                             GrDrawTarget::StageTexCoordVertexLayoutBit(0,0);
@@ -1348,8 +1346,7 @@ bool GrContext::readRenderTargetPixels(GrRenderTarget* target,
                     matrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top);
                 }
                 matrix.postIDiv(src->width(), src->height());
-                drawState->sampler(0)->reset(matrix);
-                drawState->sampler(0)->setCustomStage(stage);
+                drawState->sampler(0)->setCustomStage(stage, matrix);
                 GrRect rect = GrRect::MakeWH(GrIntToScalar(width), GrIntToScalar(height));
                 fGpu->drawSimpleRect(rect, NULL);
                 // we want to read back from the scratch's origin
@@ -1449,8 +1446,7 @@ void GrContext::copyTexture(GrTexture* src, GrRenderTarget* dst) {
     drawState->setRenderTarget(dst);
     GrMatrix sampleM;
     sampleM.setIDiv(src->width(), src->height());
-    drawState->sampler(0)->reset(sampleM);
-    drawState->createTextureEffect(0, src);
+    drawState->createTextureEffect(0, src, sampleM);
     SkRect rect = SkRect::MakeXYWH(0, 0,
                                    SK_Scalar1 * src->width(),
                                    SK_Scalar1 * src->height());
@@ -1558,8 +1554,7 @@ void GrContext::writeRenderTargetPixels(GrRenderTarget* target,
     drawState->setRenderTarget(target);
 
     matrix.setIDiv(texture->width(), texture->height());
-    drawState->sampler(0)->reset(matrix);
-    drawState->sampler(0)->setCustomStage(stage);
+    drawState->sampler(0)->setCustomStage(stage, matrix);
 
     fGpu->drawSimpleRect(GrRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)), NULL);
 }
@@ -1813,14 +1808,15 @@ GrTexture* GrContext::gaussianBlur(GrTexture* srcTexture,
     paint.reset();
 
     for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
-        paint.colorSampler(0)->matrix()->setIDiv(srcTexture->width(),
-                                                   srcTexture->height());
+        GrMatrix matrix;
+        matrix.setIDiv(srcTexture->width(), srcTexture->height());
         this->setRenderTarget(dstTexture->asRenderTarget());
         SkRect dstRect(srcRect);
         scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
-                            i < scaleFactorY ? 0.5f : 1.0f);
+                             i < scaleFactorY ? 0.5f : 1.0f);
+
         paint.colorSampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect,
-                                                           (srcTexture, true)))->unref();
+                                                         (srcTexture, true)), matrix)->unref();
         this->drawRectToRect(paint, dstRect, srcRect);
         srcRect = dstRect;
         srcTexture = dstTexture;
@@ -1873,12 +1869,13 @@ GrTexture* GrContext::gaussianBlur(GrTexture* srcTexture,
         clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop,
                                       1, srcIRect.height());
         this->clear(&clearRect, 0x0);
+        GrMatrix matrix;
         // FIXME:  This should be mitchell, not bilinear.
-        paint.colorSampler(0)->matrix()->setIDiv(srcTexture->width(),
-                                                   srcTexture->height());
+        matrix.setIDiv(srcTexture->width(), srcTexture->height());
         this->setRenderTarget(dstTexture->asRenderTarget());
         paint.colorSampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect,
-                                                           (srcTexture, true)))->unref();
+                                                         (srcTexture, true)),
+                                              matrix)->unref();
         SkRect dstRect(srcRect);
         scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY);
         this->drawRectToRect(paint, dstRect, srcRect);
index da81a76a736c1652c2446b187c1f5e481ad1ad95..cc11f6cd87abf5da3ba315f5c0fab510b10a82fd 100644 (file)
@@ -54,7 +54,7 @@ void GrDrawState::AutoViewMatrixRestore::restore() {
         fDrawState->setViewMatrix(fViewMatrix);
         for (int s = 0; s < GrDrawState::kNumStages; ++s) {
             if (fRestoreMask & (1 << s)) {
-                *fDrawState->sampler(s)->matrix() = fSamplerMatrices[s];
+                fDrawState->sampler(s)->setMatrixDeprecated(fSamplerMatrices[s]);
             }
         }
     }
@@ -77,6 +77,7 @@ void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState,
     for (int s = 0; s < GrDrawState::kNumStages; ++s) {
         if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) {
             fRestoreMask |= (1 << s);
+            fSamplerMatrices[s] = drawState->sampler(s)->getMatrix();
             drawState->sampler(s)->preConcatMatrix(preconcatMatrix);
         }
     }
@@ -89,7 +90,7 @@ void GrDrawState::AutoDeviceCoordDraw::restore() {
         fDrawState->setViewMatrix(fViewMatrix);
         for (int s = 0; s < GrDrawState::kNumStages; ++s) {
             if (fRestoreMask & (1 << s)) {
-                *fDrawState->sampler(s)->matrix() = fSamplerMatrices[s];
+                fDrawState->sampler(s)->setMatrixDeprecated(fSamplerMatrices[s]);
             }
         }
     }
index 69f0aea0a9b0e1799ed5fc5e29efd728b2eacd40..6306c336c6a6f0e5804dd0c492ef5e84583c42d0 100644 (file)
@@ -194,10 +194,17 @@ public:
         this->sampler(stage)->setCustomStage(
             SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
     }
-    void createTextureEffect(int stage, GrTexture* texture, const GrTextureParams& params) {
+    void createTextureEffect(int stage, GrTexture* texture, const GrMatrix& matrix) {
         GrAssert(!this->getSampler(stage).getCustomStage());
-        this->sampler(stage)->setCustomStage(
-            SkNEW_ARGS(GrSingleTextureEffect, (texture, params)))->unref();
+        GrCustomStage* customStage = SkNEW_ARGS(GrSingleTextureEffect, (texture));
+        this->sampler(stage)->setCustomStage(customStage, matrix)->unref();
+    }
+    void createTextureEffect(int stage, GrTexture* texture,
+                             const GrMatrix& matrix,
+                             const GrTextureParams& params) {
+        GrAssert(!this->getSampler(stage).getCustomStage());
+        GrCustomStage* customStage = SkNEW_ARGS(GrSingleTextureEffect, (texture, params));
+        this->sampler(stage)->setCustomStage(customStage, matrix)->unref();
     }
 
 
index c9944b9942fd6eed05ee7112f641e8448a09fc87..c3c361c7995dd6a38f39852c631662d045b41a11 100644 (file)
@@ -35,7 +35,7 @@ void GrTextContext::flushGlyphs() {
         GrAssert(GrIsALIGN4(fCurrVertex));
         GrAssert(fCurrTexture);
         GrTextureParams params(SkShader::kRepeat_TileMode, false);
-        drawState->createTextureEffect(kGlyphMaskStage, fCurrTexture, params);
+        drawState->createTextureEffect(kGlyphMaskStage, fCurrTexture, GrMatrix::I(), params);
 
         if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) {
             if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() ||
index a09b57ff10a545b95f7af137e6c8d92d8f8e5fbb..02bfdbd2159fafe1cd5dd9dd3fdd55cd22fc2572 100644 (file)
@@ -548,25 +548,14 @@ inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
     }
 
     GrSamplerState* sampler = grPaint->colorSampler(kShaderTextureIdx);
-    GrCustomStage* stage = shader->asNewCustomStage(dev->context(), sampler);
-
-    if (NULL != stage) {
-        sampler->setCustomStage(stage)->unref();
-        SkMatrix localM;
-        if (shader->getLocalMatrix(&localM)) {
-            SkMatrix inverse;
-            if (localM.invert(&inverse)) {
-                sampler->matrix()->preConcat(inverse);
-            }
-        }
+    if (shader->asNewCustomStage(dev->context(), sampler)) {
         return true;
     }
 
     SkBitmap bitmap;
-    SkMatrix* matrix = sampler->matrix();
+    SkMatrix matrix;
     SkShader::TileMode tileModes[2];
-    SkShader::BitmapType bmptype = shader->asABitmap(&bitmap, matrix,
-                                                     tileModes);
+    SkShader::BitmapType bmptype = shader->asABitmap(&bitmap, &matrix, tileModes);
 
     if (SkShader::kNone_BitmapType == bmptype) {
         SkShader::GradientInfo info;
@@ -600,23 +589,21 @@ inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
         return false;
     }
 
-    sampler->reset();
-    sampler->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (texture, params)))->unref();
-
-    // since our texture coords will be in local space, we wack the texture
+    // since our texture coords will be in local space, we whack the texture
     // matrix to map them back into 0...1 before we load it
     SkMatrix localM;
     if (shader->getLocalMatrix(&localM)) {
         SkMatrix inverse;
         if (localM.invert(&inverse)) {
-            matrix->preConcat(inverse);
+            matrix.preConcat(inverse);
         }
     }
     if (SkShader::kDefault_BitmapType == bmptype) {
         GrScalar sx = SkFloatToScalar(1.f / bitmap.width());
         GrScalar sy = SkFloatToScalar(1.f / bitmap.height());
-        matrix->postScale(sx, sy);
+        matrix.postScale(sx, sy);
     }
+    sampler->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (texture, params)), matrix)->unref();
 
     return true;
 }
@@ -876,13 +863,11 @@ bool drawWithGPUMaskFilter(GrContext* context, const SkPath& devPath,
         if (!isNormalBlur) {
             context->setIdentityMatrix();
             GrPaint paint;
-            paint.reset();
-            paint.colorSampler(0)->matrix()->setIDiv(pathTexture->width(),
-                                                     pathTexture->height());
+            GrMatrix matrix;
+            matrix.setIDiv(pathTexture->width(), pathTexture->height());
             // Blend pathTexture over blurTexture.
             context->setRenderTarget(blurTexture->asRenderTarget());
-            paint.colorSampler(0)->setCustomStage(SkNEW_ARGS
-                (GrSingleTextureEffect, (pathTexture)))->unref();
+            paint.colorSampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (pathTexture)), matrix)->unref();
             if (SkMaskFilter::kInner_BlurType == blurType) {
                 // inner:  dst = dst * src
                 paint.setBlendFunc(kDC_GrBlendCoeff, kZero_GrBlendCoeff);
@@ -907,13 +892,13 @@ bool drawWithGPUMaskFilter(GrContext* context, const SkPath& devPath,
     static const int MASK_IDX = GrPaint::kMaxCoverageStages - 1;
     // we assume the last mask index is available for use
     GrAssert(!grp->isCoverageStageEnabled(MASK_IDX));
+
+    GrMatrix matrix;
+    matrix.setTranslate(-finalRect.fLeft, -finalRect.fTop);
+    matrix.postIDiv(blurTexture->width(), blurTexture->height());
+
     grp->coverageSampler(MASK_IDX)->reset();
-    grp->coverageSampler(MASK_IDX)->setCustomStage(
-        SkNEW_ARGS(GrSingleTextureEffect, (blurTexture)))->unref();
-    grp->coverageSampler(MASK_IDX)->matrix()->setTranslate(-finalRect.fLeft,
-                                                       -finalRect.fTop);
-    grp->coverageSampler(MASK_IDX)->matrix()->postIDiv(blurTexture->width(),
-                                                   blurTexture->height());
+    grp->coverageSampler(MASK_IDX)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (blurTexture)), matrix)->unref();
     context->drawRect(*grp, finalRect);
     return true;
 }
@@ -964,19 +949,18 @@ bool drawWithMaskFilter(GrContext* context, const SkPath& devPath,
     static const int MASK_IDX = GrPaint::kMaxCoverageStages - 1;
     // we assume the last mask index is available for use
     GrAssert(!grp->isCoverageStageEnabled(MASK_IDX));
-    grp->coverageSampler(MASK_IDX)->reset();
-    grp->coverageSampler(MASK_IDX)->setCustomStage(
-        SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
+
+    GrMatrix m;
+    m.setTranslate(-dstM.fBounds.fLeft*SK_Scalar1, -dstM.fBounds.fTop*SK_Scalar1);
+    m.postIDiv(texture->width(), texture->height());
+
+    grp->coverageSampler(MASK_IDX)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (texture)), m)->unref();
     GrRect d;
     d.setLTRB(GrIntToScalar(dstM.fBounds.fLeft),
               GrIntToScalar(dstM.fBounds.fTop),
               GrIntToScalar(dstM.fBounds.fRight),
               GrIntToScalar(dstM.fBounds.fBottom));
 
-    GrMatrix* m = grp->coverageSampler(MASK_IDX)->matrix();
-    m->setTranslate(-dstM.fBounds.fLeft*SK_Scalar1,
-                         -dstM.fBounds.fTop*SK_Scalar1);
-    m->postIDiv(texture->width(), texture->height());
     context->drawRect(*grp, d);
     return true;
 }
@@ -1385,8 +1369,6 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
 
     GrSamplerState* sampler = grPaint->colorSampler(kBitmapTextureIdx);
 
-    sampler->matrix()->reset();
-
     GrTexture* texture;
     SkAutoCachedTexture act(this, bitmap, &params, &texture);
     if (NULL == texture) {
@@ -1469,8 +1451,7 @@ void apply_custom_stage(GrContext* context,
     GrMatrix sampleM;
     sampleM.setIDiv(srcTexture->width(), srcTexture->height());
     GrPaint paint;
-    paint.colorSampler(0)->reset(sampleM);
-    paint.colorSampler(0)->setCustomStage(stage);
+    paint.colorSampler(0)->setCustomStage(stage, sampleM);
     context->drawRect(paint, rect);
 }