зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
17388f5923
Коммит
f8c3f43487
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
RefPtr<widget::Screen> screen =
|
||||
widget::ScreenManager::GetSingleton().GetPrimaryScreen();
|
||||
|
||||
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
|
||||
: hal::eScreenOrientation_PortraitPrimary;
|
||||
|
||||
*aScreenConfiguration = hal::ScreenConfiguration(
|
||||
nsIntRect(x, y, w, h), orientation, 0, colorDepth, pixelDepth);
|
||||
*aScreenConfiguration = screen->ToScreenConfiguration();
|
||||
aScreenConfiguration->orientation() =
|
||||
aScreenConfiguration->rect().Width() >=
|
||||
aScreenConfiguration->rect().Height()
|
||||
? hal::eScreenOrientation_LandscapePrimary
|
||||
: hal::eScreenOrientation_PortraitPrimary;
|
||||
}
|
||||
|
||||
} // namespace fallback
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ class ScreenManager final : public nsIScreenManager {
|
|||
static void Refresh(nsTArray<RefPtr<Screen>>&& aScreens);
|
||||
void Refresh(nsTArray<mozilla::dom::ScreenDetails>&& aScreens);
|
||||
void CopyScreensToRemote(mozilla::dom::ContentParent* aContentParent);
|
||||
already_AddRefed<Screen> GetPrimaryScreen();
|
||||
|
||||
private:
|
||||
ScreenManager();
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
|
||||
#include "nsAppShell.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIScreenManager.h"
|
||||
|
||||
#include "mozilla/Hal.h"
|
||||
#include "mozilla/java/GeckoScreenOrientationNatives.h"
|
||||
#include "mozilla/widget/ScreenManager.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -21,29 +21,15 @@ class GeckoScreenOrientation final
|
|||
|
||||
public:
|
||||
static void OnOrientationChange(int16_t aOrientation, int16_t aAngle) {
|
||||
nsCOMPtr<nsIScreenManager> screenMgr =
|
||||
do_GetService("@mozilla.org/gfx/screenmanager;1");
|
||||
nsCOMPtr<nsIScreen> screen;
|
||||
RefPtr<widget::Screen> screen =
|
||||
widget::ScreenManager::GetSingleton().GetPrimaryScreen();
|
||||
hal::ScreenConfiguration screenConfiguration =
|
||||
screen->ToScreenConfiguration();
|
||||
screenConfiguration.orientation() =
|
||||
static_cast<hal::ScreenOrientation>(aOrientation);
|
||||
screenConfiguration.angle() = aAngle;
|
||||
|
||||
if (!screenMgr ||
|
||||
NS_FAILED(screenMgr->GetPrimaryScreen(getter_AddRefs(screen))) ||
|
||||
!screen) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsIntRect rect;
|
||||
int32_t colorDepth, pixelDepth;
|
||||
|
||||
if (NS_FAILED(
|
||||
screen->GetRect(&rect.x, &rect.y, &rect.width, &rect.height)) ||
|
||||
NS_FAILED(screen->GetColorDepth(&colorDepth)) ||
|
||||
NS_FAILED(screen->GetPixelDepth(&pixelDepth))) {
|
||||
return;
|
||||
}
|
||||
|
||||
hal::NotifyScreenConfigurationChange(hal::ScreenConfiguration(
|
||||
rect, static_cast<hal::ScreenOrientation>(aOrientation), aAngle,
|
||||
colorDepth, pixelDepth));
|
||||
hal::NotifyScreenConfigurationChange(screenConfiguration);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче