Merge third_party/skia/src from https://chromium.googlesource.com/external/skia/src.git at 1ffcf188ba353bf82876a8d55a127ea6e1dcb27a

This commit was generated by merge_from_chromium.py.

Change-Id: I1bb3256d62017f06f9b6266f5c21e715f807d337
diff --git a/core/SkBitmapProcShader.h b/core/SkBitmapProcShader.h
index 0a036d3..8d31256 100644
--- a/core/SkBitmapProcShader.h
+++ b/core/SkBitmapProcShader.h
@@ -71,10 +71,7 @@
 // an Sk3DBlitter in SkDraw.cpp
 // Note that some contexts may contain other contexts (e.g. for compose shaders), but we've not
 // yet found a situation where the size below isn't big enough.
-typedef SkSmallAllocator<3, sizeof(SkBitmapProcShader) +
-                            sizeof(SkBitmapProcShader::BitmapProcShaderContext) +
-                            sizeof(SkBitmapProcState) +
-                            sizeof(void*) * 2> SkTBlitterAllocator;
+typedef SkSmallAllocator<3, 768> SkTBlitterAllocator;
 
 // If alloc is non-NULL, it will be used to allocate the returned SkShader, and MUST outlive
 // the SkShader.
diff --git a/core/SkBlitter.cpp b/core/SkBlitter.cpp
index 0e12a62..81e46c5 100644
--- a/core/SkBlitter.cpp
+++ b/core/SkBlitter.cpp
@@ -1,4 +1,3 @@
-
 /*
  * Copyright 2006 The Android Open Source Project
  *
@@ -6,7 +5,6 @@
  * found in the LICENSE file.
  */
 
-
 #include "SkBlitter.h"
 #include "SkAntiRun.h"
 #include "SkColor.h"
@@ -26,8 +24,7 @@
 
 bool SkBlitter::isNullBlitter() const { return false; }
 
-bool SkBlitter::resetShaderContext(const SkBitmap& device, const SkPaint& paint,
-                                   const SkMatrix& matrix) {
+bool SkBlitter::resetShaderContext(const SkShader::ContextRec&) {
     return true;
 }
 
@@ -1030,10 +1027,7 @@
     fShader->unref();
 }
 
-bool SkShaderBlitter::resetShaderContext(const SkBitmap& device, const SkPaint& paint,
-                                         const SkMatrix& matrix) {
-    SkShader::ContextRec rec(device, paint, matrix);
-
+bool SkShaderBlitter::resetShaderContext(const SkShader::ContextRec& rec) {
     // Only destroy the old context if we have a new one. We need to ensure to have a
     // live context in fShaderContext because the storage is owned by an SkSmallAllocator
     // outside of this class.
@@ -1045,6 +1039,7 @@
         // Need a valid context in fShaderContext's storage, so we can later (or our caller) call
         // the in-place destructor.
         SkNEW_PLACEMENT_ARGS(fShaderContext, SkTransparentShaderContext, (*fShader, rec));
+        return false;
     }
-    return ctx != NULL;
+    return true;
 }
diff --git a/core/SkBlitter.h b/core/SkBlitter.h
index f76839e..a3a2196 100644
--- a/core/SkBlitter.h
+++ b/core/SkBlitter.h
@@ -64,8 +64,7 @@
     /**
      *  Special methods for SkShaderBlitter. On all other classes this is a no-op.
      */
-    virtual bool resetShaderContext(const SkBitmap& device, const SkPaint& paint,
-                                    const SkMatrix& matrix);
+    virtual bool resetShaderContext(const SkShader::ContextRec&);
     virtual SkShader::Context* getShaderContext() const;
 
     ///@name non-virtual helpers
diff --git a/core/SkCoreBlitters.h b/core/SkCoreBlitters.h
index 2d22d38..20f9437 100644
--- a/core/SkCoreBlitters.h
+++ b/core/SkCoreBlitters.h
@@ -41,8 +41,7 @@
       *  Will create the context at the same location as the old one (this is safe
       *  because the shader itself is unchanged).
       */
-    virtual bool resetShaderContext(const SkBitmap& device, const SkPaint& paint,
-                                    const SkMatrix& matrix) SK_OVERRIDE;
+    virtual bool resetShaderContext(const SkShader::ContextRec&) SK_OVERRIDE;
 
     virtual SkShader::Context* getShaderContext() const SK_OVERRIDE { return fShaderContext; }
 
diff --git a/core/SkDraw.cpp b/core/SkDraw.cpp
index 9347efe..24c8055 100644
--- a/core/SkDraw.cpp
+++ b/core/SkDraw.cpp
@@ -2403,7 +2403,13 @@
     if (!m.invert(&im)) {
         return false;
     }
-    fDstToUnit.setConcat(im, this->getTotalInverse());
+    // We can't call getTotalInverse(), because we explicitly don't want to look at the localmatrix
+    // as our interators are intrinsically tied to the vertices, and nothing else.
+    SkMatrix ctmInv;
+    if (!this->getCTM().invert(&ctmInv)) {
+        return false;
+    }
+    fDstToUnit.setConcat(im, ctmInv);
     return true;
 }
 
@@ -2556,18 +2562,13 @@
     VertState::Proc vertProc = state.chooseProc(vmode);
 
     if (NULL != textures || NULL != colors) {
-        SkMatrix  tempM;
-        SkMatrix  savedLocalM;
-        if (shader) {
-            savedLocalM = shader->getLocalMatrix();
-        }
-
         while (vertProc(&state)) {
             if (NULL != textures) {
+                SkMatrix tempM;
                 if (texture_to_matrix(state, vertices, textures, &tempM)) {
-                    tempM.postConcat(savedLocalM);
-                    shader->setLocalMatrix(tempM);
-                    if (!blitter->resetShaderContext(*fBitmap, p, *fMatrix)) {
+                    SkShader::ContextRec rec(*fBitmap, p, *fMatrix);
+                    rec.fLocalMatrix = &tempM;
+                    if (!blitter->resetShaderContext(rec)) {
                         continue;
                     }
                 }
@@ -2603,11 +2604,6 @@
             };
             SkScan::FillTriangle(tmp, *fRC, blitter.get());
         }
-
-        // now restore the shader's original local matrix
-        if (NULL != shader) {
-            shader->setLocalMatrix(savedLocalM);
-        }
     } else {
         // no colors[] and no texture
         HairProc hairProc = ChooseHairProc(paint.isAntiAlias());
diff --git a/core/SkPictureShader.cpp b/core/SkPictureShader.cpp
index 9555624..9655e85 100644
--- a/core/SkPictureShader.cpp
+++ b/core/SkPictureShader.cpp
@@ -52,7 +52,7 @@
     fPicture->flatten(buffer);
 }
 
-SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix) const {
+SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatrix* localM) const {
     SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0);
 
     SkMatrix m;
@@ -61,6 +61,9 @@
     } else {
         m = matrix;
     }
+    if (localM) {
+        m.preConcat(*localM);
+    }
 
     // Use a rotation-invariant scale
     SkPoint scale;
@@ -115,11 +118,11 @@
 }
 
 SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void* storage) const {
-    SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix));
+    SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix, rec.fLocalMatrix));
     if (NULL == bitmapShader.get()) {
         return NULL;
     }
-    return PictureShaderContext::Create(storage, *this, rec, bitmapShader.detach());
+    return PictureShaderContext::Create(storage, *this, rec, bitmapShader);
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////
@@ -190,7 +193,7 @@
 
 #if SK_SUPPORT_GPU
 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint) const {
-    SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix()));
+    SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix(), NULL));
     if (!bitmapShader) {
         return NULL;
     }
diff --git a/core/SkPictureShader.h b/core/SkPictureShader.h
index 0fbfbee..27fb674 100644
--- a/core/SkPictureShader.h
+++ b/core/SkPictureShader.h
@@ -41,7 +41,7 @@
 private:
     SkPictureShader(SkPicture*, TileMode, TileMode, const SkMatrix* = NULL);
 
-    SkShader* refBitmapShader(const SkMatrix&) const;
+    SkShader* refBitmapShader(const SkMatrix&, const SkMatrix* localMatrix) const;
 
     SkPicture*  fPicture;
     TileMode    fTmx, fTmy;
diff --git a/core/SkShader.cpp b/core/SkShader.cpp
index 8e6112a..0c954f8 100644
--- a/core/SkShader.cpp
+++ b/core/SkShader.cpp
@@ -53,6 +53,10 @@
         total.setConcat(*m, this->getLocalMatrix());
         m = &total;
     }
+    if (rec.fLocalMatrix) {
+        total.setConcat(*m, *rec.fLocalMatrix);
+        m = &total;
+    }
     return m->invert(totalInverse);
 }
 
@@ -63,7 +67,7 @@
     return this->onCreateContext(rec, storage);
 }
 
-SkShader::Context* SkShader::onCreateContext(const ContextRec&, void*) const {
+SkShader::Context* SkShader::onCreateContext(const ContextRec& rec, void*) const {
     return NULL;
 }
 
@@ -72,7 +76,7 @@
 }
 
 SkShader::Context::Context(const SkShader& shader, const ContextRec& rec)
-    : fShader(shader)
+    : fShader(shader), fCTM(*rec.fMatrix)
 {
     // Because the context parameters must be valid at this point, we know that the matrix is
     // invertible.
diff --git a/gpu/GrPictureUtils.h b/gpu/GrPictureUtils.h
index 8fdb3b8..c625298 100644
--- a/gpu/GrPictureUtils.h
+++ b/gpu/GrPictureUtils.h
@@ -45,6 +45,12 @@
 
     GPUAccelData(Key key) : INHERITED(key) { }
 
+    virtual ~GPUAccelData() {
+        for (int i = 0; i < fSaveLayerInfo.count(); ++i) {
+            SkDELETE(fSaveLayerInfo[i].fPaint);
+        }
+    }
+
     void addSaveLayerInfo(const SaveLayerInfo& info) {
         SkASSERT(info.fSaveLayerOpID < info.fRestoreOpID);
         *fSaveLayerInfo.push() = info;
diff --git a/gpu/SkGpuDevice.cpp b/gpu/SkGpuDevice.cpp
index 3119a9e..517f082 100644
--- a/gpu/SkGpuDevice.cpp
+++ b/gpu/SkGpuDevice.cpp
@@ -1913,7 +1913,7 @@
 void SkGpuDevice::EXPERIMENTAL_optimize(SkPicture* picture) {
     SkPicture::AccelData::Key key = GPUAccelData::ComputeAccelDataKey();
 
-    GPUAccelData* data = SkNEW_ARGS(GPUAccelData, (key));
+    SkAutoTUnref<GPUAccelData> data(SkNEW_ARGS(GPUAccelData, (key)));
 
     picture->EXPERIMENTAL_addAccelData(data);