Bug 1194751 - Part 6.1 change nsScreenManagerAndroid::ScreenForId to a concrete method. r=snorp
authorKan-Ru Chen <kanru@kanru.info>
Thu, 09 Mar 2017 19:30:53 +0800
changeset 349723 ad1425bed4ea19d0e098f7051e93f191d21e195c
parent 349722 5a58b77947bf1146bd7080fc2e64e8b04c585861
child 349724 f4fa50b511ae0cc8d5940e47cf39cc317ade66be
push id39555
push userkchen@mozilla.com
push dateMon, 27 Mar 2017 03:43:07 +0000
treeherderautoland@81099dbf284b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1194751
milestone55.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 1194751 - Part 6.1 change nsScreenManagerAndroid::ScreenForId to a concrete method. r=snorp nsIScreen::GetId and nsIScreenManager::ScreenForId is removed in patch part 6. These methods are still used by Fennec on Android to implement Presentation API support so I changed them to concrete methods in nsScreenAndroid and nsScreenManagerAndroid. nsScreenAndroid and nsScreenManagerAndroid does not use the generic Screen and ScreenManager class because its implementation is quite different. MozReview-Commit-ID: 4rxxIgvNxMb
widget/android/nsScreenManagerAndroid.cpp
widget/android/nsScreenManagerAndroid.h
widget/android/nsWindow.cpp
--- a/widget/android/nsScreenManagerAndroid.cpp
+++ b/widget/android/nsScreenManagerAndroid.cpp
@@ -50,23 +50,16 @@ nsScreenAndroid::GetDensity() {
         mDensity = mozilla::jni::IsAvailable() ? GeckoAppShell::GetDensity()
                                                : 1.0; // xpcshell most likely
         return mDensity;
     }
     return 1.0;
 }
 
 NS_IMETHODIMP
-nsScreenAndroid::GetId(uint32_t *outId)
-{
-    *outId = mId;
-    return NS_OK;
-}
-
-NS_IMETHODIMP
 nsScreenAndroid::GetRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight)
 {
     if (mDisplayType != DisplayType::DISPLAY_PRIMARY) {
         *outLeft   = mRect.x;
         *outTop    = mRect.y;
         *outWidth  = mRect.width;
         *outHeight = mRect.height;
 
@@ -174,34 +167,34 @@ nsScreenManagerAndroid::nsScreenManagerA
 
 nsScreenManagerAndroid::~nsScreenManagerAndroid()
 {
 }
 
 NS_IMETHODIMP
 nsScreenManagerAndroid::GetPrimaryScreen(nsIScreen **outScreen)
 {
-    ScreenForId(PRIMARY_SCREEN_ID, outScreen);
+    RefPtr<nsScreenAndroid> screen = ScreenForId(PRIMARY_SCREEN_ID);
+    if (screen) {
+        screen.forget(outScreen);
+    }
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsScreenManagerAndroid::ScreenForId(uint32_t aId,
-                                    nsIScreen **outScreen)
+already_AddRefed<nsScreenAndroid>
+nsScreenManagerAndroid::ScreenForId(uint32_t aId)
 {
     for (size_t i = 0; i < mScreens.Length(); ++i) {
         if (aId == mScreens[i]->GetId()) {
-            nsCOMPtr<nsIScreen> screen = (nsIScreen*) mScreens[i];
-            screen.forget(outScreen);
-            return NS_OK;
+            RefPtr<nsScreenAndroid> screen = mScreens[i];
+            return screen.forget();
         }
     }
 
-    *outScreen = nullptr;
-    return NS_OK;
+    return nullptr;
 }
 
 NS_IMETHODIMP
 nsScreenManagerAndroid::ScreenForRect(int32_t inLeft,
                                       int32_t inTop,
                                       int32_t inWidth,
                                       int32_t inHeight,
                                       nsIScreen **outScreen)
--- a/widget/android/nsScreenManagerAndroid.h
+++ b/widget/android/nsScreenManagerAndroid.h
@@ -15,17 +15,16 @@
 #include "mozilla/WidgetUtils.h"
 
 class nsScreenAndroid final : public nsBaseScreen
 {
 public:
     nsScreenAndroid(DisplayType aDisplayType, nsIntRect aRect);
     ~nsScreenAndroid();
 
-    NS_IMETHOD GetId(uint32_t* aId) override;
     NS_IMETHOD GetRect(int32_t* aLeft, int32_t* aTop, int32_t* aWidth, int32_t* aHeight) override;
     NS_IMETHOD GetAvailRect(int32_t* aLeft, int32_t* aTop, int32_t* aWidth, int32_t* aHeight) override;
     NS_IMETHOD GetPixelDepth(int32_t* aPixelDepth) override;
     NS_IMETHOD GetColorDepth(int32_t* aColorDepth) override;
 
     uint32_t GetId() const { return mId; };
     DisplayType GetDisplayType() const { return mDisplayType; }
 
@@ -47,16 +46,17 @@ private:
 public:
     class ScreenManagerHelperSupport;
 
     nsScreenManagerAndroid();
 
     NS_DECL_ISUPPORTS
     NS_DECL_NSISCREENMANAGER
 
+    already_AddRefed<nsScreenAndroid> ScreenForId(uint32_t aId);
     already_AddRefed<nsScreenAndroid> AddScreen(DisplayType aDisplayType,
                                                 nsIntRect aRect = nsIntRect());
     void RemoveScreen(uint32_t aScreenId);
 
 protected:
     nsTArray<RefPtr<nsScreenAndroid>> mScreens;
 };
 
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -2337,20 +2337,19 @@ nsWindow::GetCompositorBridgeChild() con
 
 already_AddRefed<nsIScreen>
 nsWindow::GetWidgetScreen()
 {
     nsCOMPtr<nsIScreenManager> screenMgr =
         do_GetService("@mozilla.org/gfx/screenmanager;1");
     MOZ_ASSERT(screenMgr, "Failed to get nsIScreenManager");
 
-    nsCOMPtr<nsIScreen> screen;
-    screenMgr->ScreenForId(mScreenId, getter_AddRefs(screen));
-
-    return screen.forget();
+    RefPtr<nsScreenManagerAndroid> screenMgrAndroid =
+        (nsScreenManagerAndroid*) screenMgr.get();
+    return screenMgrAndroid->ScreenForId(mScreenId);
 }
 
 jni::DependentRef<java::GeckoLayerClient>
 nsWindow::GetLayerClient()
 {
     if (NativePtr<LayerViewSupport>::Locked lvs{mLayerViewSupport}) {
         return lvs->GetLayerClient().Get();
     }