Commit f8c3f434 authored by Makoto Kato's avatar Makoto Kato
Browse files

Bug 1747677 - Add utility method to convert to ScreenConfiguration....

Bug 1747677 - Add utility method to convert to ScreenConfiguration. r=gsvelto,geckoview-reviewers,calu

Gecko uses the redundant code from nsIScreen to SCreenConfiguration. So we
should add a convert method for newer platform implementations.

Differential Revision: https://phabricator.services.mozilla.com/D134698
parent 17388f59
Loading
Loading
Loading
Loading
+6 −28
Original line number Diff line number Diff line
@@ -10,9 +10,8 @@
#include "mozilla/dom/network/Constants.h"
#include "mozilla/java/GeckoAppShellWrappers.h"
#include "mozilla/java/GeckoRuntimeWrappers.h"
#include "nsIScreenManager.h"
#include "mozilla/widget/ScreenManager.h"
#include "nsPIDOMWindow.h"
#include "nsServiceManagerUtils.h"

using namespace mozilla::dom;
using namespace mozilla::hal;
@@ -95,33 +94,12 @@ void GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) {
    return;
  }

  nsresult rv;
  nsCOMPtr<nsIScreenManager> screenMgr =
      do_GetService("@mozilla.org/gfx/screenmanager;1", &rv);
  if (NS_FAILED(rv)) {
    NS_ERROR("Can't find nsIScreenManager!");
    return;
  }

  int32_t colorDepth, pixelDepth;
  int16_t angle;
  hal::ScreenOrientation orientation;
  nsCOMPtr<nsIScreen> screen;

  int32_t rectX, rectY, rectWidth, rectHeight;

  screenMgr->GetPrimaryScreen(getter_AddRefs(screen));

  screen->GetRect(&rectX, &rectY, &rectWidth, &rectHeight);
  screen->GetColorDepth(&colorDepth);
  screen->GetPixelDepth(&pixelDepth);
  orientation =
  RefPtr<widget::Screen> screen =
      widget::ScreenManager::GetSingleton().GetPrimaryScreen();
  *aScreenConfiguration = screen->ToScreenConfiguration();
  aScreenConfiguration->orientation() =
      static_cast<hal::ScreenOrientation>(bridge->GetScreenOrientation());
  angle = bridge->GetScreenAngle();

  *aScreenConfiguration =
      hal::ScreenConfiguration(nsIntRect(rectX, rectY, rectWidth, rectHeight),
                               orientation, angle, colorDepth, pixelDepth);
  aScreenConfiguration->angle() = bridge->GetScreenAngle();
}

RefPtr<MozPromise<bool, bool, false>> LockScreenOrientation(
+10 −23
Original line number Diff line number Diff line
@@ -6,35 +6,22 @@
#define mozilla_fallback_FallbackScreenConfiguration_h

#include "Hal.h"
#include "nsIScreenManager.h"
#include "nsServiceManagerUtils.h"
#include "mozilla/widget/ScreenManager.h"

namespace mozilla {
namespace fallback {

inline void GetCurrentScreenConfiguration(
    hal::ScreenConfiguration* aScreenConfiguration) {
  nsresult rv;
  nsCOMPtr<nsIScreenManager> screenMgr =
      do_GetService("@mozilla.org/gfx/screenmanager;1", &rv);
  if (NS_FAILED(rv)) {
    NS_ERROR("Can't find nsIScreenManager!");
    return;
  }

  int32_t colorDepth, pixelDepth, x, y, w, h;
  hal::ScreenOrientation orientation;
  nsCOMPtr<nsIScreen> screen;

  screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
  screen->GetRect(&x, &y, &w, &h);
  screen->GetColorDepth(&colorDepth);
  screen->GetPixelDepth(&pixelDepth);
  orientation = w >= h ? hal::eScreenOrientation_LandscapePrimary
  RefPtr<widget::Screen> screen =
      widget::ScreenManager::GetSingleton().GetPrimaryScreen();

  *aScreenConfiguration = screen->ToScreenConfiguration();
  aScreenConfiguration->orientation() =
      aScreenConfiguration->rect().Width() >=
              aScreenConfiguration->rect().Height()
          ? hal::eScreenOrientation_LandscapePrimary
          : hal::eScreenOrientation_PortraitPrimary;

  *aScreenConfiguration = hal::ScreenConfiguration(
      nsIntRect(x, y, w, h), orientation, 0, colorDepth, pixelDepth);
}

}  // namespace fallback
+7 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
#include "Screen.h"

#include "mozilla/dom/DOMTypes.h"
#include "mozilla/Hal.h"
#include "mozilla/StaticPrefs_layout.h"

namespace mozilla {
@@ -56,6 +57,12 @@ mozilla::dom::ScreenDetails Screen::ToScreenDetails() {
      mColorDepth, mContentsScale, mDefaultCssScale, mDPI);
}

mozilla::hal::ScreenConfiguration Screen::ToScreenConfiguration() {
  return mozilla::hal::ScreenConfiguration(
      nsIntRect(mRect.x, mRect.y, mRect.width, mRect.height),
      hal::eScreenOrientation_None, 0, mColorDepth, mPixelDepth);
}

NS_IMETHODIMP
Screen::GetRect(int32_t* aOutLeft, int32_t* aOutTop, int32_t* aOutWidth,
                int32_t* aOutHeight) {
+8 −0
Original line number Diff line number Diff line
@@ -15,6 +15,9 @@ namespace mozilla {
namespace dom {
class ScreenDetails;
}  // namespace dom
namespace hal {
class ScreenConfiguration;
}
}  // namespace mozilla

namespace mozilla {
@@ -34,6 +37,11 @@ class Screen final : public nsIScreen {

  mozilla::dom::ScreenDetails ToScreenDetails();

  // Convert to hal's ScreenConfiguration.
  // NOTE: Since Screen doesn't have orientation and angle information,
  //       these can't be set.
  mozilla::hal::ScreenConfiguration ToScreenConfiguration();

 private:
  virtual ~Screen() = default;

+9 −5
Original line number Diff line number Diff line
@@ -209,20 +209,24 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
// The screen with the menubar/taskbar. This shouldn't be needed very
// often.
//
NS_IMETHODIMP
ScreenManager::GetPrimaryScreen(nsIScreen** aPrimaryScreen) {
already_AddRefed<Screen> ScreenManager::GetPrimaryScreen() {
  if (mScreenList.IsEmpty()) {
    MOZ_LOG(sScreenLog, LogLevel::Warning,
            ("No screen available. This can happen in xpcshell."));
    RefPtr<Screen> ret = new Screen(
        LayoutDeviceIntRect(), LayoutDeviceIntRect(), 0, 0,
        DesktopToLayoutDeviceScale(), CSSToLayoutDeviceScale(), 96 /* dpi */);
    ret.forget(aPrimaryScreen);
    return NS_OK;
    return ret.forget();
  }

  RefPtr<Screen> ret = mScreenList[0];
  ret.forget(aPrimaryScreen);
  return ret.forget();
}

NS_IMETHODIMP
ScreenManager::GetPrimaryScreen(nsIScreen** aPrimaryScreen) {
  nsCOMPtr<nsIScreen> screen = GetPrimaryScreen();
  screen.forget(aPrimaryScreen);
  return NS_OK;
}

Loading