Bug 1019753, part 2 - Use Moz2D DataSourceSurfaces instead of Thebes gfxImageSurfaces in DocumentRendererParent.cpp and ImageEncoder.cpp. r=mattwoodrow
☠☠ backed out by 85a943b54bd5 ☠ ☠
authorJonathan Watt <jwatt@jwatt.org>
Wed, 04 Jun 2014 08:08:39 +0100
changeset 205696 8dc53499b0c07077df186c7c6dcc62b98aa318d2
parent 205695 c5953a77827641fdf9c17c3e6745599cb47fce16
child 205697 89e48a42e8a560df6e083329906c5f0950e7f5b9
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1019753
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1019753, part 2 - Use Moz2D DataSourceSurfaces instead of Thebes gfxImageSurfaces in DocumentRendererParent.cpp and ImageEncoder.cpp. r=mattwoodrow
content/canvas/src/DocumentRendererParent.cpp
content/canvas/src/ImageEncoder.cpp
image/test/crashtests/crashtests.list
--- a/content/canvas/src/DocumentRendererParent.cpp
+++ b/content/canvas/src/DocumentRendererParent.cpp
@@ -1,17 +1,20 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "mozilla/gfx/2D.h"
 #include "mozilla/ipc/DocumentRendererParent.h"
-#include "gfxImageSurface.h"
+#include "mozilla/RefPtr.h"
 #include "gfxPattern.h"
 #include "nsICanvasRenderingContextInternal.h"
 
+using namespace mozilla;
+using namespace mozilla::gfx;
 using namespace mozilla::ipc;
 
 DocumentRendererParent::DocumentRendererParent()
 {}
 
 DocumentRendererParent::~DocumentRendererParent()
 {}
 
@@ -23,22 +26,22 @@ void DocumentRendererParent::SetCanvasCo
 }
 
 void DocumentRendererParent::DrawToCanvas(const nsIntSize& aSize,
                                           const nsCString& aData)
 {
     if (!mCanvas || !mCanvasContext)
         return;
 
-    nsRefPtr<gfxImageSurface> surf =
-        new gfxImageSurface(reinterpret_cast<uint8_t*>(const_cast<nsCString&>(aData).BeginWriting()),
-                            gfxIntSize(aSize.width, aSize.height),
-                            aSize.width * 4,
-                            gfxImageFormat::ARGB32);
-    nsRefPtr<gfxPattern> pat = new gfxPattern(surf);
+    RefPtr<DataSourceSurface> dataSurface =
+        Factory::CreateWrappingDataSourceSurface(reinterpret_cast<uint8_t*>(const_cast<nsCString&>(aData).BeginWriting()),
+                                                 aSize.width * 4,
+                                                 IntSize(aSize.width, aSize.height),
+                                                 SurfaceFormat::B8G8R8A8);
+    nsRefPtr<gfxPattern> pat = new gfxPattern(dataSurface, Matrix());
 
     gfxRect rect(gfxPoint(0, 0), gfxSize(aSize.width, aSize.height));
     mCanvasContext->NewPath();
     mCanvasContext->PixelSnappedRectangleAndSetPattern(rect, pat);
     mCanvasContext->Fill();
 
     // get rid of the pattern surface ref, because aData is very
     // likely to go away shortly
--- a/content/canvas/src/ImageEncoder.cpp
+++ b/content/canvas/src/ImageEncoder.cpp
@@ -1,16 +1,20 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "gfxImageSurface.h"
 #include "ImageEncoder.h"
 #include "mozilla/dom/CanvasRenderingContext2D.h"
+#include "mozilla/gfx/2D.h"
+#include "mozilla/gfx/DataSurfaceHelpers.h"
+#include "mozilla/RefPtr.h"
+
+using namespace mozilla::gfx;
 
 namespace mozilla {
 namespace dom {
 
 class EncodingCompleteEvent : public nsRunnable
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
@@ -277,29 +281,38 @@ ImageEncoder::ExtractDataInternal(const 
     rv = aContext->GetInputStream(encoderType.get(),
                                   nsPromiseFlatString(aOptions).get(),
                                   getter_AddRefs(imgStream));
   } else {
     // no context, so we have to encode an empty image
     // note that if we didn't have a current context, the spec says we're
     // supposed to just return transparent black pixels of the canvas
     // dimensions.
-    nsRefPtr<gfxImageSurface> emptyCanvas =
-      new gfxImageSurface(gfxIntSize(aSize.width, aSize.height),
-                          gfxImageFormat::ARGB32);
-    if (emptyCanvas->CairoStatus()) {
+    RefPtr<DataSourceSurface> emptyCanvas =
+      Factory::CreateDataSourceSurfaceWithStride(IntSize(aSize.width, aSize.height),
+                                                 SurfaceFormat::B8G8R8A8,
+                                                 4 * aSize.width);
+
+    if (!emptyCanvas) {
+      NS_ERROR("Failded to create DataSourceSurface");
       return NS_ERROR_INVALID_ARG;
     }
-    rv = aEncoder->InitFromData(emptyCanvas->Data(),
+    ClearDataSourceSurface(emptyCanvas);
+    DataSourceSurface::MappedSurface map;
+    if (!emptyCanvas->Map(DataSourceSurface::MapType::WRITE, &map)) {
+      return NS_ERROR_INVALID_ARG;
+    }
+    rv = aEncoder->InitFromData(map.mData,
                                 aSize.width * aSize.height * 4,
                                 aSize.width,
                                 aSize.height,
                                 aSize.width * 4,
                                 imgIEncoder::INPUT_FORMAT_HOSTARGB,
                                 aOptions);
+    emptyCanvas->Unmap();
     if (NS_SUCCEEDED(rv)) {
       imgStream = do_QueryInterface(aEncoder);
     }
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
   imgStream.forget(aStream);
   return rv;
--- a/image/test/crashtests/crashtests.list
+++ b/image/test/crashtests/crashtests.list
@@ -25,17 +25,17 @@ load invalid-icc-profile.jpg
 # interpret as 0-width and 0-height.
 load 256-width.ico
 load 256-height.ico
 
 # A 3-frame animated GIF with an inordinate delay between the second and third
 # frame.
 HTTP load delayedframe.sjs
 
-load 681190.html
+asserts-if(winWidget,0-1) load 681190.html # asserts can't create such a big surface
 skip-if(Android&&smallScreen) skip-if(B2G) load 694165-1.xhtml # nexus-s Android 2.3.6, bug 876275 for B2G on a VM
 load 732319-1.html
 load 844403-1.html
 
 load truncated-second-frame.png # bug 863975
 
 # Bug 863958
 # This icon's size is such that it leads to multiple writes to the PNG decoder