Bug 1265953, part 1 - Convert most of the cocoa widget code from nsAutoPtr to UniquePtr. r=mstange
authorJonathan Watt <jwatt@jwatt.org>
Tue, 19 Apr 2016 11:28:12 +0100
changeset 332040 710324243b622d7b8555769a9676931c04a7ea8c
parent 332039 d430b697c76d7402818653ba2b4fef3c249ffc4e
child 332041 31b3a03707447d000981a6c1aa2dc81697458fc8
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1265953
milestone48.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 1265953, part 1 - Convert most of the cocoa widget code from nsAutoPtr to UniquePtr. r=mstange
widget/cocoa/nsChildView.h
widget/cocoa/nsChildView.mm
widget/cocoa/nsCocoaWindow.h
widget/cocoa/nsDeviceContextSpecX.mm
widget/cocoa/nsMenuBarX.h
widget/cocoa/nsMenuBarX.mm
widget/cocoa/nsMenuGroupOwnerX.h
widget/cocoa/nsMenuItemIconX.h
widget/cocoa/nsMenuItemX.h
widget/cocoa/nsScreenManagerCocoa.h
widget/cocoa/nsSystemStatusBarCocoa.h
--- a/widget/cocoa/nsChildView.h
+++ b/widget/cocoa/nsChildView.h
@@ -645,20 +645,20 @@ protected:
   LayoutDeviceIntRect mTitlebarRect;
 
   // The area of mTitlebarCGContext that needs to be redrawn during the next
   // transaction. Accessed from any thread, protected by mEffectsLock.
   LayoutDeviceIntRegion mUpdatedTitlebarRegion;
   CGContextRef mTitlebarCGContext;
 
   // Compositor thread only
-  nsAutoPtr<RectTextureImage> mResizerImage;
-  nsAutoPtr<RectTextureImage> mCornerMaskImage;
-  nsAutoPtr<RectTextureImage> mTitlebarImage;
-  nsAutoPtr<RectTextureImage> mBasicCompositorImage;
+  mozilla::UniquePtr<RectTextureImage> mResizerImage;
+  mozilla::UniquePtr<RectTextureImage> mCornerMaskImage;
+  mozilla::UniquePtr<RectTextureImage> mTitlebarImage;
+  mozilla::UniquePtr<RectTextureImage> mBasicCompositorImage;
 
   // The area of mTitlebarCGContext that has changed and needs to be
   // uploaded to to mTitlebarImage. Main thread only.
   nsIntRegion           mDirtyTitlebarRegion;
 
   LayoutDeviceIntRegion mDraggableRegion;
 
   // Cached value of [mView backingScaleFactor], to avoid sending two obj-c
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -2067,17 +2067,17 @@ void
 nsChildView::MaybeDrawResizeIndicator(GLManager* aManager)
 {
   MutexAutoLock lock(mEffectsLock);
   if (!mShowsResizeIndicator) {
     return;
   }
 
   if (!mResizerImage) {
-    mResizerImage = new RectTextureImage(aManager->gl());
+    mResizerImage = MakeUnique<RectTextureImage>(aManager->gl());
   }
 
   LayoutDeviceIntSize size = mResizeIndicatorRect.Size();
   mResizerImage->UpdateIfNeeded(size, LayoutDeviceIntRegion(), ^(gfx::DrawTarget* drawTarget, const LayoutDeviceIntRegion& updateRegion) {
     ClearRegion(drawTarget, updateRegion);
     gfx::BorrowedCGContext borrow(drawTarget);
     DrawResizer(borrow.cg);
     borrow.Finish();
@@ -2281,17 +2281,17 @@ nsChildView::MaybeDrawTitlebar(GLManager
     return;
   }
 
   LayoutDeviceIntRegion updatedTitlebarRegion;
   updatedTitlebarRegion.And(mUpdatedTitlebarRegion, mTitlebarRect);
   mUpdatedTitlebarRegion.SetEmpty();
 
   if (!mTitlebarImage) {
-    mTitlebarImage = new RectTextureImage(aManager->gl());
+    mTitlebarImage = MakeUnique<RectTextureImage>(aManager->gl());
   }
 
   mTitlebarImage->UpdateFromCGContext(mTitlebarRect.Size(),
                                       updatedTitlebarRegion,
                                       mTitlebarCGContext);
 
   mTitlebarImage->Draw(aManager, mTitlebarRect.TopLeft());
 }
@@ -2305,17 +2305,17 @@ DrawTopLeftCornerMask(CGContextRef aCtx,
 
 void
 nsChildView::MaybeDrawRoundedCorners(GLManager* aManager,
                                      const LayoutDeviceIntRect& aRect)
 {
   MutexAutoLock lock(mEffectsLock);
 
   if (!mCornerMaskImage) {
-    mCornerMaskImage = new RectTextureImage(aManager->gl());
+    mCornerMaskImage = MakeUnique<RectTextureImage>(aManager->gl());
   }
 
   LayoutDeviceIntSize size(mDevPixelCornerRadius, mDevPixelCornerRadius);
   mCornerMaskImage->UpdateIfNeeded(size, LayoutDeviceIntRegion(), ^(gfx::DrawTarget* drawTarget, const LayoutDeviceIntRegion& updateRegion) {
     ClearRegion(drawTarget, updateRegion);
     RefPtr<gfx::PathBuilder> builder = drawTarget->CreatePathBuilder();
     builder->Arc(gfx::Point(mDevPixelCornerRadius, mDevPixelCornerRadius), mDevPixelCornerRadius, 0, 2.0f * M_PI);
     RefPtr<gfx::Path> path = builder->Finish();
@@ -2626,17 +2626,17 @@ nsChildView::StartRemoteDrawingInRegion(
       return nullptr;
     }
   }
 
   LayoutDeviceIntRegion dirtyRegion(aInvalidRegion);
   LayoutDeviceIntSize renderSize = mBounds.Size();
 
   if (!mBasicCompositorImage) {
-    mBasicCompositorImage = new RectTextureImage(mGLPresenter->gl());
+    mBasicCompositorImage = MakeUnique<RectTextureImage>(mGLPresenter->gl());
   }
 
   RefPtr<gfx::DrawTarget> drawTarget =
     mBasicCompositorImage->BeginUpdate(renderSize, dirtyRegion);
 
   if (!drawTarget) {
     // Composite unchanged textures.
     DoRemoteComposition(mBounds);
--- a/widget/cocoa/nsCocoaWindow.h
+++ b/widget/cocoa/nsCocoaWindow.h
@@ -5,19 +5,19 @@
 
 #ifndef nsCocoaWindow_h_
 #define nsCocoaWindow_h_
 
 #undef DARWIN
 
 #import <Cocoa/Cocoa.h>
 
+#include "mozilla/RefPtr.h"
 #include "nsBaseWidget.h"
 #include "nsPIWidgetCocoa.h"
-#include "nsAutoPtr.h"
 #include "nsCocoaUtils.h"
 
 class nsCocoaWindow;
 class nsChildView;
 class nsMenuBarX;
 @class ChildView;
 
 // If we are using an SDK older than 10.7, define bits we need that are missing
--- a/widget/cocoa/nsDeviceContextSpecX.mm
+++ b/widget/cocoa/nsDeviceContextSpecX.mm
@@ -1,19 +1,19 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* 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 "nsDeviceContextSpecX.h"
 
+#include "mozilla/RefPtr.h"
 #include "nsCRT.h"
 #include <unistd.h>
 
-#include "nsAutoPtr.h"
 #include "nsQueryObject.h"
 #include "nsIServiceManager.h"
 #include "nsIPrintOptions.h"
 #include "nsPrintSettingsX.h"
 
 #include "gfxQuartzSurface.h"
 
 // This must be the last include:
--- a/widget/cocoa/nsMenuBarX.h
+++ b/widget/cocoa/nsMenuBarX.h
@@ -115,14 +115,14 @@ protected:
   nsresult          InsertMenuAtIndex(nsMenuX* aMenu, uint32_t aIndex);
   void              RemoveMenuAtIndex(uint32_t aIndex);
   void              HideItem(nsIDOMDocument* inDoc, const nsAString & inID, nsIContent** outHiddenNode);
   void              AquifyMenuBar();
   NSMenuItem*       CreateNativeAppMenuItem(nsMenuX* inMenu, const nsAString& nodeID, SEL action,
                                             int tag, NativeMenuItemTarget* target);
   nsresult          CreateApplicationMenu(nsMenuX* inMenu);
 
-  nsTArray< nsAutoPtr<nsMenuX> > mMenuArray;
+  nsTArray<mozilla::UniquePtr<nsMenuX>> mMenuArray;
   nsIWidget*         mParentWindow;        // [weak]
   GeckoNSMenu*       mNativeMenu;            // root menu, representing entire menu bar
 };
 
 #endif // nsMenuBarX_h_
--- a/widget/cocoa/nsMenuBarX.mm
+++ b/widget/cocoa/nsMenuBarX.mm
@@ -301,17 +301,17 @@ void nsMenuBarX::ForceUpdateNativeMenuAt
     return;
 
   nsMenuX* currentMenu = NULL;
   int targetIndex = [[indexes objectAtIndex:0] intValue];
   int visible = 0;
   uint32_t length = mMenuArray.Length();
   // first find a menu in the menu bar
   for (unsigned int i = 0; i < length; i++) {
-    nsMenuX* menu = mMenuArray[i];
+    nsMenuX* menu = mMenuArray[i].get();
     if (!nsMenuUtilsX::NodeIsHiddenOrCollapsed(menu->Content())) {
       visible++;
       if (visible == (targetIndex + 1)) {
         currentMenu = menu;
         break;
       }
     }
   }
@@ -361,17 +361,17 @@ void nsMenuBarX::ForceNativeMenuReload()
 }
 
 nsMenuX* nsMenuBarX::GetMenuAt(uint32_t aIndex)
 {
   if (mMenuArray.Length() <= aIndex) {
     NS_ERROR("Requesting menu at invalid index!");
     return NULL;
   }
-  return mMenuArray[aIndex];
+  return mMenuArray[aIndex].get();
 }
 
 nsMenuX* nsMenuBarX::GetXULHelpMenu()
 {
   // The Help menu is usually (always?) the last one, so we start there and
   // count back.
   for (int32_t i = GetMenuCount() - 1; i >= 0; --i) {
     nsMenuX* aMenu = GetMenuAt(i);
--- a/widget/cocoa/nsMenuGroupOwnerX.h
+++ b/widget/cocoa/nsMenuGroupOwnerX.h
@@ -7,20 +7,18 @@
 #define nsMenuGroupOwnerX_h_
 
 #import <Cocoa/Cocoa.h>
 
 #include "nsMenuBaseX.h"
 #include "nsIMutationObserver.h"
 #include "nsHashKeys.h"
 #include "nsDataHashtable.h"
-#include "nsAutoPtr.h"
 #include "nsString.h"
 
-
 class nsMenuItemX;
 class nsChangeObserver;
 class nsIWidget;
 class nsIContent;
 
 class nsMenuGroupOwnerX : public nsMenuObjectX, public nsIMutationObserver
 {
 public:
--- a/widget/cocoa/nsMenuItemIconX.h
+++ b/widget/cocoa/nsMenuItemIconX.h
@@ -5,18 +5,18 @@
 
 /*
  * Retrieves and displays icons in native menu items on Mac OS X.
  */
 
 #ifndef nsMenuItemIconX_h_
 #define nsMenuItemIconX_h_
 
+#include "mozilla/RefPtr.h"
 #include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
 #include "imgINotificationObserver.h"
 
 class nsIURI;
 class nsIContent;
 class imgRequestProxy;
 class nsMenuObjectX;
 
 #import <Cocoa/Cocoa.h>
--- a/widget/cocoa/nsMenuItemX.h
+++ b/widget/cocoa/nsMenuItemX.h
@@ -1,20 +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/. */
 
 #ifndef nsMenuItemX_h_
 #define nsMenuItemX_h_
 
+#include "mozilla/RefPtr.h"
 #include "nsMenuBaseX.h"
 #include "nsMenuGroupOwnerX.h"
 #include "nsChangeObserver.h"
-#include "nsAutoPtr.h"
 
 #import <Cocoa/Cocoa.h>
 
 class nsString;
 class nsMenuItemIconX;
 class nsMenuX;
 
 enum {
--- a/widget/cocoa/nsScreenManagerCocoa.h
+++ b/widget/cocoa/nsScreenManagerCocoa.h
@@ -3,18 +3,18 @@
  * 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/. */
 
 #ifndef nsScreenManagerCocoa_h_
 #define nsScreenManagerCocoa_h_
 
 #import <Cocoa/Cocoa.h>
 
+#include "mozilla/RefPtr.h"
 #include "nsTArray.h"
-#include "nsAutoPtr.h"
 #include "nsIScreenManager.h"
 #include "nsScreenCocoa.h"
 
 class nsScreenManagerCocoa : public nsIScreenManager
 {
 public:
     nsScreenManagerCocoa();
 
--- a/widget/cocoa/nsSystemStatusBarCocoa.h
+++ b/widget/cocoa/nsSystemStatusBarCocoa.h
@@ -1,19 +1,19 @@
 /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
 /* 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/. */
 
 #ifndef nsSystemStatusBarCocoa_h_
 #define nsSystemStatusBarCocoa_h_
 
+#include "mozilla/RefPtr.h"
 #include "nsISystemStatusBar.h"
 #include "nsClassHashtable.h"
-#include "nsAutoPtr.h"
 
 class nsStandaloneNativeMenu;
 @class NSStatusItem;
 
 class nsSystemStatusBarCocoa : public nsISystemStatusBar
 {
 public:
   nsSystemStatusBarCocoa() {}