Merge from Chromium at DEPS revision 40.0.2214.45

This commit was generated by merge_to_master.py.

Change-Id: I2727aa7130d490d425674c5001e18accc1de6b46
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp
index 1f32a7e..1596fb3 100644
--- a/src/core/SkPictureShader.cpp
+++ b/src/core/SkPictureShader.cpp
@@ -77,7 +77,14 @@
         SkAutoTUnref<SkShader>* result = reinterpret_cast<SkAutoTUnref<SkShader>*>(contextShader);
 
         result->reset(SkRef(rec.fShader.get()));
-        return true;
+
+        SkBitmap tile;
+        rec.fShader.get()->asABitmap(&tile, NULL, NULL);
+        // FIXME: this doesn't protect the pixels from being discarded as soon as we unlock.
+        // Should be handled via a pixel ref generator instead
+        // (https://code.google.com/p/skia/issues/detail?id=3220).
+        SkAutoLockPixels alp(tile, true);
+        return tile.getPixels() != NULL;
     }
 };
 
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index a456a79..e3b590a 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -1574,9 +1574,10 @@
     }
     target->copySurface(dst, src, srcRect, dstPoint);
 
-    if (kFlushWrites_PixelOp & pixelOpsFlags) {
-        this->flush();
-    }
+    // always flush, this is not the behavior of TOT Skia but some uses of GrContext copySurface
+    // in chrome rely on this behavior
+    // see crbug:440671
+    this->flush();
 }
 
 void GrContext::flushSurfaceWrites(GrSurface* surface) {
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index 8482ecd..2d6c19c 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -31,6 +31,7 @@
     fRTFBOID                = idDesc.fRTFBOID;
     fTexFBOID               = idDesc.fTexFBOID;
     fMSColorRenderbufferID  = idDesc.fMSColorRenderbufferID;
+    fIsWrapped              = idDesc.fIsWrapped;
 
     fViewport.fLeft   = 0;
     fViewport.fBottom = 0;
@@ -54,7 +55,7 @@
 }
 
 void GrGLRenderTarget::onRelease() {
-    if (!this->isWrapped()) {
+    if (!fIsWrapped) {
         if (fTexFBOID) {
             GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
         }
@@ -68,6 +69,7 @@
     fRTFBOID                = 0;
     fTexFBOID               = 0;
     fMSColorRenderbufferID  = 0;
+    fIsWrapped              = false;
     INHERITED::onRelease();
 }
 
@@ -75,5 +77,6 @@
     fRTFBOID                = 0;
     fTexFBOID               = 0;
     fMSColorRenderbufferID  = 0;
+    fIsWrapped              = false;
     INHERITED::onAbandon();
 }
diff --git a/src/gpu/gl/GrGLRenderTarget.h b/src/gpu/gl/GrGLRenderTarget.h
index 0f04160..50e3b5a 100644
--- a/src/gpu/gl/GrGLRenderTarget.h
+++ b/src/gpu/gl/GrGLRenderTarget.h
@@ -77,6 +77,10 @@
     GrGLuint      fTexFBOID;
     GrGLuint      fMSColorRenderbufferID;
 
+    // We track this separately from GrGpuResource because this may be both a texture and a render
+    // target, and the texture may be wrapped while the render target is not.
+    bool fIsWrapped;
+
     // when we switch to this render target we want to set the viewport to
     // only render to content area (as opposed to the whole allocation) and
     // we want the rendering to be at top left (GL has origin in bottom left)
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index 8777d1b..ce892dd 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -30,20 +30,23 @@
     fTexParams.invalidate();
     fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
     fTextureID = idDesc.fTextureID;
+    fIsWrapped = idDesc.fIsWrapped;
 }
 
 void GrGLTexture::onRelease() {
     if (fTextureID) {
-        if (!this->isWrapped()) {
+        if (!fIsWrapped) {
             GL_CALL(DeleteTextures(1, &fTextureID));
         }
         fTextureID = 0;
+        fIsWrapped = false;
     }
     INHERITED::onRelease();
 }
 
 void GrGLTexture::onAbandon() {
     fTextureID = 0;
+    fIsWrapped = false;
     INHERITED::onAbandon();
 }
 
diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h
index f23adae..c3c396e 100644
--- a/src/gpu/gl/GrGLTexture.h
+++ b/src/gpu/gl/GrGLTexture.h
@@ -70,6 +70,10 @@
     GrGpu::ResetTimestamp           fTexParamsTimestamp;
     GrGLuint                        fTextureID;
 
+    // We track this separately from GrGpuResource because this may be both a texture and a render
+    // target, and the texture may be wrapped while the render target is not.
+    bool fIsWrapped;
+
     typedef GrTexture INHERITED;
 };
 
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 2f991c8..8c1abc9 100755
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -741,9 +741,12 @@
     CGFloat textSize = ScalarToCG(fRec.fTextSize);
 
     // If a text size of 0 is requested, CoreGraphics will use 12 instead.
-    // If the text size is 0, set it to something tiny.
+    // It would make sense to force the text size to something tiny,
+    // but this causes assertion failures inside CG (drawing glyphs at CGFLOAT_MIN size).
+    // Instead, set such tiny sizes to 1, and transform them down to 0 with a singular transform.
     if (textSize < CGFLOAT_MIN) {
-        textSize = CGFLOAT_MIN;
+        textSize = 1;
+        transform = CGAffineTransformMakeScale(0, 0);
     }
 
     fCTFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize, &transform, ctFontDesc));