Bug 1025497 - Stop using gfxImageSurface in Cocoa widget code. r=mstange
authorJonathan Watt <jwatt@jwatt.org>
Tue, 17 Jun 2014 10:37:45 +0100
changeset 189095 7ba4ba052721f9c3cfdf2e4ba3f545bf6a199f9e
parent 189094 548ea28a6cd6838db4ab0d0e2a073b7983d3ee8d
child 189096 3ff80fbb7fc3e829ce926b35ade7e933c3bfd184
push id26976
push userryanvm@gmail.com
push dateTue, 17 Jun 2014 19:39:20 +0000
treeherdermozilla-central@c4cf1181993e [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/gl/GLTextureImage.cpp
gfx/layers/Layers.cpp
widget/android/AndroidBridge.cpp
widget/android/nsWindow.cpp
widget/cocoa/nsCocoaUtils.mm
widget/cocoa/nsDragService.mm
--- a/gfx/gl/GLTextureImage.cpp
+++ b/gfx/gl/GLTextureImage.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
 /* 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 "GLTextureImage.h"
 #include "GLContext.h"
 #include "gfxContext.h"
+#include "gfxImageSurface.h"
 #include "gfxPlatform.h"
 #include "gfxUtils.h"
 #include "gfx2DGlue.h"
 #include "gfxImageSurface.h"
 #include "ScopedGLHelpers.h"
 #include "GLUploadHelpers.h"
 
 #include "TextureImageEGL.h"
--- 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 "gfxImageSurface.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
--- 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
@@ -161,49 +161,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);
@@ -212,16 +219,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];