Bug 1194751 - Part 6.1 change nsScreenManagerAndroid::ScreenForId to a concrete method. r?snorp draft
authorKan-Ru Chen <kanru@kanru.info>
Thu, 09 Mar 2017 19:30:53 +0800
changeset 551545 e9fcc740570b46365e7a28d79391972661f908a4
parent 551544 2801ce20c65894e7ac9fdad3636b97a489d55e18
child 551546 f4a28c06839d5660ded7095ce5791de3b814f243
push id51077
push userkchen@mozilla.com
push dateMon, 27 Mar 2017 01:06:01 +0000
reviewerssnorp
bugs1194751
milestone55.0a1
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();
     }