Bug 1025497 - Stop using gfxImageSurface in Cocoa widget code. r=mstange
☠☠ backed out by 121cf7ced13d ☠ ☠
authorJonathan Watt <jwatt@jwatt.org>
Sun, 15 Jun 2014 01:44:46 +0100
changeset 210685 53e5f619cb62cdea1abe5f45d360e951346a89d3
parent 210684 57f27c0396615eddf44fad520706ce5078ea2e0f
child 210686 79c6d543f29f6b1cb4aa0f5e73f2031680ffe8fa
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1025497
milestone33.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 1025497 - Stop using gfxImageSurface in Cocoa widget code. r=mstange
gfx/layers/Layers.cpp
image/public/imgIContainer.idl
widget/android/AndroidBridge.cpp
widget/android/nsWindow.cpp
widget/cocoa/nsCocoaUtils.mm
widget/cocoa/nsDragService.mm
--- a/gfx/layers/Layers.cpp
+++ b/gfx/layers/Layers.cpp
@@ -9,16 +9,17 @@
 #include <algorithm>                    // for max, min
 #include "AnimationCommon.h"            // for ComputedTimingFunction
 #include "CompositableHost.h"           // for CompositableHost
 #include "ImageContainer.h"             // for ImageContainer, etc
 #include "ImageLayers.h"                // for ImageLayer
 #include "LayerSorter.h"                // for SortLayersBy3DZOrder
 #include "LayersLogging.h"              // for AppendToString
 #include "ReadbackLayer.h"              // for ReadbackLayer
+#include "gfxImageSurface.h"
 #include "gfxPlatform.h"                // for gfxPlatform
 #include "gfxUtils.h"                   // for gfxUtils, etc
 #include "gfx2DGlue.h"
 #include "mozilla/DebugOnly.h"          // for DebugOnly
 #include "mozilla/Telemetry.h"          // for Accumulate
 #include "mozilla/gfx/2D.h"             // for DrawTarget
 #include "mozilla/gfx/BaseSize.h"       // for BaseSize
 #include "mozilla/gfx/Matrix.h"         // for Matrix4x4
--- a/image/public/imgIContainer.idl
+++ b/image/public/imgIContainer.idl
@@ -2,22 +2,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 "nsISupports.idl"
 
 %{C++
-#include "gfxImageSurface.h"
 #include "gfxContext.h"
 #include "gfxMatrix.h"
 #include "gfxRect.h"
 #include "GraphicsFilter.h"
-#include "gfxASurface.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/RefPtr.h"
 #include "nsRect.h"
 #include "nsSize.h"
 #include "limits.h"
 
 namespace mozilla {
 namespace layers {
@@ -36,19 +34,16 @@ class SVGImageContext;
 namespace mozilla {
 namespace image {
 class Orientation;
 }
 }
 
 %}
 
-[ptr] native gfxImageSurface(gfxImageSurface);
-[ptr] native gfxASurface(gfxASurface);
-native gfxImageFormat(gfxASurface::gfxImageFormat);
 [ptr] native gfxContext(gfxContext);
 [ref] native gfxMatrix(gfxMatrix);
 [ref] native gfxRect(gfxRect);
 native gfxGraphicsFilter(GraphicsFilter);
 [ref] native nsIntRect(nsIntRect);
 [ref] native nsIntSize(nsIntSize);
 native nsSize(nsSize);
 [ptr] native nsIFrame(nsIFrame);
@@ -170,19 +165,17 @@ interface imgIContainer : nsISupports
     * as it is used for ensuring that a valid value was passed in.
     */
   const unsigned long FRAME_FIRST = 0;
   const unsigned long FRAME_CURRENT = 1;
   const unsigned long FRAME_MAX_VALUE = 1;
 
   /**
    * Get a surface for the given frame. This may be a platform-native,
-   * optimized surface, so you cannot inspect its pixel data. If you
-   * need that, use gfxASurface::GetAsReadableARGB32ImageSurface or
-   * gfxASurface::CopyToARGB32ImageSurface.
+   * optimized surface.
    *
    * @param aWhichFrame Frame specifier of the FRAME_* variety.
    * @param aFlags Flags of the FLAG_* variety
    */
   [noscript, notxpcom] TempRefSourceSurface getFrame(in uint32_t aWhichFrame,
                                                      in uint32_t aFlags);
 
   /**
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -19,17 +19,16 @@
 #include "AndroidBridgeUtilities.h"
 #include "nsAppShell.h"
 #include "nsOSHelperAppService.h"
 #include "nsWindow.h"
 #include "mozilla/Preferences.h"
 #include "nsThreadUtils.h"
 #include "nsIThreadManager.h"
 #include "mozilla/dom/mobilemessage/PSms.h"
-#include "gfxImageSurface.h"
 #include "gfxPlatform.h"
 #include "gfxContext.h"
 #include "mozilla/gfx/2D.h"
 #include "gfxUtils.h"
 #include "nsPresContext.h"
 #include "nsIDocShell.h"
 #include "nsPIDOMWindow.h"
 #include "mozilla/dom/ScreenOrientation.h"
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -33,17 +33,16 @@ using mozilla::unused;
 
 #include "nsRenderingContext.h"
 #include "nsIDOMSimpleGestureEvent.h"
 
 #include "nsGkAtoms.h"
 #include "nsWidgetsCID.h"
 #include "nsGfxCIID.h"
 
-#include "gfxImageSurface.h"
 #include "gfxContext.h"
 
 #include "Layers.h"
 #include "mozilla/layers/LayerManagerComposite.h"
 #include "mozilla/layers/AsyncCompositionManager.h"
 #include "mozilla/layers/APZCTreeManager.h"
 #include "GLContext.h"
 #include "GLContextProvider.h"
--- a/widget/cocoa/nsCocoaUtils.mm
+++ b/widget/cocoa/nsCocoaUtils.mm
@@ -1,14 +1,13 @@
 /* -*- Mode: C++; tab-width: 20; 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 "gfxPlatform.h"
 #include "gfxUtils.h"
 #include "nsCocoaUtils.h"
 #include "nsChildView.h"
 #include "nsMenuBarX.h"
 #include "nsCocoaWindow.h"
 #include "nsCOMPtr.h"
 #include "nsIInterfaceRequestorUtils.h"
--- a/widget/cocoa/nsDragService.mm
+++ b/widget/cocoa/nsDragService.mm
@@ -160,49 +160,56 @@ nsDragService::ConstructDragImage(nsIDOM
   }
 
   if (NS_FAILED(rv) || !surface)
     return nil;
 
   uint32_t width = aDragRect->width;
   uint32_t height = aDragRect->height;
 
-  nsRefPtr<gfxImageSurface> imgSurface = new gfxImageSurface(
-    gfxIntSize(width, height), gfxImageFormat::ARGB32);
-  if (!imgSurface)
+
+
+  RefPtr<DataSourceSurface> dataSurface =
+    Factory::CreateDataSourceSurface(IntSize(width, height),
+                                     SurfaceFormat::B8G8R8A8);
+  DataSourceSurface::MappedSurface map;
+  if (!dataSurface->Map(DataSourceSurface::MapType::READ_WRITE, &map)) {
     return nil;
+  }
 
   RefPtr<DrawTarget> dt =
-    gfxPlatform::GetPlatform()->
-      CreateDrawTargetForSurface(imgSurface, IntSize(width, height));
-  if (!dt)
+    Factory::CreateDrawTargetForData(BackendType::CAIRO,
+                                     map.mData,
+                                     dataSurface->GetSize(),
+                                     map.mStride,
+                                     dataSurface->GetFormat());
+  if (!dt) {
+    dataSurface->Unmap();
     return nil;
+  }
 
   dt->FillRect(gfx::Rect(0, 0, width, height),
                SurfacePattern(surface, ExtendMode::CLAMP),
                DrawOptions(1.0f, CompositionOp::OP_SOURCE));
 
-  uint32_t* imageData = (uint32_t*)imgSurface->Data();
-  int32_t stride = imgSurface->Stride();
-
   NSBitmapImageRep* imageRep =
     [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
                                             pixelsWide:width
                                             pixelsHigh:height
                                          bitsPerSample:8
                                        samplesPerPixel:4
                                               hasAlpha:YES
                                               isPlanar:NO
                                         colorSpaceName:NSDeviceRGBColorSpace
                                            bytesPerRow:width * 4
                                           bitsPerPixel:32];
 
   uint8_t* dest = [imageRep bitmapData];
   for (uint32_t i = 0; i < height; ++i) {
-    uint8_t* src = (uint8_t *)imageData + i * stride;
+    uint8_t* src = map.mData + i * map.mStride;
     for (uint32_t j = 0; j < width; ++j) {
       // Reduce transparency overall by multipying by a factor. Remember, Alpha
       // is premultipled here. Also, Quartz likes RGBA, so do that translation as well.
 #ifdef IS_BIG_ENDIAN
       dest[0] = uint8_t(src[1] * DRAG_TRANSLUCENCY);
       dest[1] = uint8_t(src[2] * DRAG_TRANSLUCENCY);
       dest[2] = uint8_t(src[3] * DRAG_TRANSLUCENCY);
       dest[3] = uint8_t(src[0] * DRAG_TRANSLUCENCY);
@@ -211,16 +218,17 @@ nsDragService::ConstructDragImage(nsIDOM
       dest[1] = uint8_t(src[1] * DRAG_TRANSLUCENCY);
       dest[2] = uint8_t(src[0] * DRAG_TRANSLUCENCY);
       dest[3] = uint8_t(src[3] * DRAG_TRANSLUCENCY);
 #endif
       src += 4;
       dest += 4;
     }
   }
+  dataSurface->Unmap();
 
   NSImage* image =
     [[NSImage alloc] initWithSize:NSMakeSize(width / scaleFactor,
                                              height / scaleFactor)];
   [image addRepresentation:imageRep];
   [imageRep release];
 
   return [image autorelease];