Bug 1812938 - Part 1. GetWidgetScreen returns Screen instead of nsIScreen. r=emilio,geckoview-reviewers,owlish

`nsIWidget` isn't scriptable, so it is unnecessary to return `nsIScreen` for
`GetWidgetScreen`.

Differential Revision: https://phabricator.services.mozilla.com/D168029
This commit is contained in:
Makoto Kato
2023-02-06 04:51:26 +00:00
parent 867e2d1161
commit b05e6c0ce4
18 changed files with 55 additions and 53 deletions

View File

@@ -89,6 +89,7 @@ class nsIFrame;
class nsIHTMLCollection;
class nsIMozBrowserFrame;
class nsIPrincipal;
class nsIScreen;
class nsIScrollableFrame;
class nsIURI;
class nsMappedAttributes;

View File

@@ -15,7 +15,6 @@ namespace mozilla {
namespace layers {
using namespace gfx;
using namespace widget;
CompositorSession::CompositorSession(nsBaseWidget* aWidget,
CompositorWidgetDelegate* aDelegate,

View File

@@ -10,6 +10,9 @@
#include "mozilla/Observer.h"
#include "mozilla/TypedEnumBits.h"
// Undo X11/X.h's definition of None
#undef None
namespace mozilla::hal {
// Make sure that any change to ScreenOrientation values are also made in

View File

@@ -30,6 +30,7 @@
#include "mozilla/dom/Document.h"
#include "mozilla/dom/DocumentInlines.h"
#include "mozilla/dom/DocGroup.h"
#include "mozilla/widget/Screen.h"
#include "nsPresContext.h"
#include "nsIFrame.h"
#include "nsIWritablePropertyBag2.h"
@@ -68,7 +69,6 @@
#include "nsDocShell.h"
#include "nsIBaseWindow.h"
#include "nsILayoutHistoryState.h"
#include "nsIScreen.h"
#include "nsCharsetSource.h"
#include "mozilla/ReflowInput.h"
#include "nsIImageLoadingContent.h"

View File

@@ -15,6 +15,7 @@
#include "mozilla/StaticPrefs_layout.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/widget/Screen.h"
#include "nsIWidget.h"
#include "nsViewManager.h"
#include "nsIFrame.h"

View File

@@ -117,6 +117,14 @@ void ScreenManager::CopyScreensToAllRemotesIfIsParent() {
NS_IMETHODIMP
ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
int32_t aHeight, nsIScreen** aOutScreen) {
DesktopIntRect rect(aX, aY, aWidth, aHeight);
nsCOMPtr<nsIScreen> screen = ScreenForRect(rect);
screen.forget(aOutScreen);
return NS_OK;
}
already_AddRefed<Screen> ScreenManager::ScreenForRect(
const DesktopIntRect& aRect) {
#if defined(MOZ_WAYLAND) && defined(MOZ_LOGGING)
static bool inWayland = GdkIsWaylandDisplay();
if (inWayland) {
@@ -132,14 +140,13 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
LayoutDeviceIntRect(), LayoutDeviceIntRect(), 0, 0, 0,
DesktopToLayoutDeviceScale(), CSSToLayoutDeviceScale(), 96 /* dpi */,
Screen::IsPseudoDisplay::No, hal::ScreenOrientation::None, 0);
screen.forget(aOutScreen);
return NS_OK;
return screen.forget();
}
// Optimize for the common case. If the number of screens is only
// one then just return the primary screen.
if (mScreenList.Length() == 1) {
return GetPrimaryScreen(aOutScreen);
return GetPrimaryScreen();
}
// which screen should we return?
@@ -148,14 +155,13 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
// walk the list of screens and find the one that has the most
// surface area.
uint32_t area = 0;
DesktopIntRect windowRect(aX, aY, aWidth, aHeight);
for (auto& screen : mScreenList) {
int32_t x, y, width, height;
x = y = width = height = 0;
screen->GetRectDisplayPix(&x, &y, &width, &height);
// calculate the surface area
DesktopIntRect screenRect(x, y, width, height);
screenRect.IntersectRect(screenRect, windowRect);
screenRect.IntersectRect(screenRect, aRect);
uint32_t tempArea = screenRect.Area();
if (tempArea > area) {
which = screen.get();
@@ -167,8 +173,7 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
// return the screen that has the largest intersection.
if (area > 0) {
RefPtr<Screen> ret = which;
ret.forget(aOutScreen);
return NS_OK;
return ret.forget();
}
// If the rect does not intersect a screen, find
@@ -180,17 +185,17 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
screen->GetRectDisplayPix(&x, &y, &width, &height);
uint32_t distanceX = 0;
if (aX > (x + width)) {
distanceX = aX - (x + width);
} else if ((aX + aWidth) < x) {
distanceX = x - (aX + aWidth);
if (aRect.x > (x + width)) {
distanceX = aRect.x - (x + width);
} else if (aRect.XMost() < x) {
distanceX = x - aRect.XMost();
}
uint32_t distanceY = 0;
if (aY > (y + height)) {
distanceY = aY - (y + height);
} else if ((aY + aHeight) < y) {
distanceY = y - (aY + aHeight);
if (aRect.y > (y + height)) {
distanceY = aRect.y - (y + height);
} else if (aRect.YMost() < y) {
distanceY = y - aRect.YMost();
}
uint32_t tempDistance = distanceX * distanceX + distanceY * distanceY;
@@ -204,8 +209,7 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
}
RefPtr<Screen> ret = which;
ret.forget(aOutScreen);
return NS_OK;
return ret.forget();
}
// The screen with the menubar/taskbar. This shouldn't be needed very

View File

@@ -43,6 +43,7 @@ class ScreenManager final : public nsIScreenManager {
void Refresh(nsTArray<mozilla::dom::ScreenDetails>&& aScreens);
void CopyScreensToRemote(mozilla::dom::ContentParent* aContentParent);
already_AddRefed<Screen> GetPrimaryScreen();
already_AddRefed<Screen> ScreenForRect(const DesktopIntRect& aRect);
const nsTArray<RefPtr<Screen>>& CurrentScreenList() const {
return mScreenList;

View File

@@ -101,6 +101,7 @@
#include "mozilla/layers/IAPZCTreeManager.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/widget/AndroidVsync.h"
#include "mozilla/widget/Screen.h"
#define GVS_LOG(...) MOZ_LOG(sGVSupportLog, LogLevel::Warning, (__VA_ARGS__))

View File

@@ -82,6 +82,7 @@
#include "mozilla/layers/WebRenderLayerManager.h"
#include "mozilla/webrender/WebRenderAPI.h"
#include "mozilla/widget/CompositorWidget.h"
#include "mozilla/widget/Screen.h"
#include "gfxUtils.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/BorrowedContext.h"

View File

@@ -55,6 +55,7 @@
#include "mozilla/StaticPrefs_widget.h"
#include "mozilla/WritingModes.h"
#include "mozilla/layers/CompositorBridgeChild.h"
#include "mozilla/widget/Screen.h"
#include <algorithm>
namespace mozilla {

View File

@@ -500,7 +500,8 @@ int ScreenGetterWayland::GetMonitorForWindow(nsWindow* aWindow) {
return -1;
}
RefPtr<nsIScreen> ScreenGetterWayland::GetScreenForWindow(nsWindow* aWindow) {
RefPtr<widget::Screen> ScreenGetterWayland::GetScreenForWindow(
nsWindow* aWindow) {
if (mMonitors.IsEmpty()) {
return nullptr;
}
@@ -522,7 +523,7 @@ RefPtr<nsIScreen> ScreenGetterWayland::GetScreenForWindow(nsWindow* aWindow) {
}
#endif
RefPtr<nsIScreen> ScreenHelperGTK::GetScreenForWindow(nsWindow* aWindow) {
RefPtr<widget::Screen> ScreenHelperGTK::GetScreenForWindow(nsWindow* aWindow) {
return gScreenGetter->GetScreenForWindow(aWindow);
}

View File

@@ -29,7 +29,7 @@ class ScreenGetter {
virtual void Init(){};
virtual void RefreshScreens(){};
virtual RefPtr<nsIScreen> GetScreenForWindow(nsWindow* aWindow) {
virtual RefPtr<widget::Screen> GetScreenForWindow(nsWindow* aWindow) {
return nullptr;
}
};
@@ -70,7 +70,7 @@ class ScreenGetterWayland : public ScreenGetter {
bool RemoveMonitorConfig(int aId);
already_AddRefed<Screen> MakeScreenWayland(gint aMonitor);
RefPtr<nsIScreen> GetScreenForWindow(nsWindow* aWindow);
RefPtr<widget::Screen> GetScreenForWindow(nsWindow* aWindow);
// For internal use from signal callback functions
void RefreshScreens();
@@ -95,7 +95,7 @@ class ScreenHelperGTK final : public ScreenManager::Helper {
~ScreenHelperGTK();
static gint GetGTKMonitorScaleFactor(gint aMonitorNum = 0);
static RefPtr<nsIScreen> GetScreenForWindow(nsWindow* aWindow);
static RefPtr<widget::Screen> GetScreenForWindow(nsWindow* aWindow);
};
} // namespace widget

View File

@@ -96,6 +96,7 @@
#include "nsViewManager.h"
#include "nsXPLookAndFeel.h"
#include "prlink.h"
#include "Screen.h"
#include "ScreenHelperGTK.h"
#include "SystemTimeConverter.h"
#include "WidgetUtilsGtk.h"
@@ -7284,29 +7285,20 @@ void nsWindow::PerformFullscreenTransition(FullscreenTransitionStage aStage,
nullptr);
}
already_AddRefed<nsIScreen> nsWindow::GetWidgetScreen() {
already_AddRefed<widget::Screen> nsWindow::GetWidgetScreen() {
// Wayland can read screen directly
if (GdkIsWaylandDisplay()) {
RefPtr<nsIScreen> screen = ScreenHelperGTK::GetScreenForWindow(this);
if (screen) {
if (RefPtr<Screen> screen = ScreenHelperGTK::GetScreenForWindow(this)) {
return screen.forget();
}
}
nsCOMPtr<nsIScreenManager> screenManager;
screenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
if (!screenManager) {
return nullptr;
}
// GetScreenBounds() is slow for the GTK port so we override and use
// mBounds directly.
ScreenManager& screenManager = ScreenManager::GetSingleton();
LayoutDeviceIntRect bounds = mBounds;
DesktopIntRect deskBounds = RoundedToInt(bounds / GetDesktopToDeviceScale());
nsCOMPtr<nsIScreen> screen;
screenManager->ScreenForRect(deskBounds.x, deskBounds.y, deskBounds.width,
deskBounds.height, getter_AddRefs(screen));
return screen.forget();
return screenManager.ScreenForRect(deskBounds);
}
RefPtr<VsyncDispatcher> nsWindow::GetVsyncDispatcher() {

View File

@@ -110,6 +110,10 @@ class TimeStamp;
#ifdef MOZ_X11
class CurrentX11TimeGetter;
#endif
namespace widget {
class Screen;
} // namespace widget
} // namespace mozilla
class nsWindow final : public nsBaseWidget {
@@ -197,7 +201,7 @@ class nsWindow final : public nsBaseWidget {
void PerformFullscreenTransition(FullscreenTransitionStage aStage,
uint16_t aDuration, nsISupports* aData,
nsIRunnable* aCallback) override;
already_AddRefed<nsIScreen> GetWidgetScreen() override;
already_AddRefed<Screen> GetWidgetScreen() override;
nsresult MakeFullScreen(bool aFullScreen) override;
void HideWindowChrome(bool aShouldHide) override;

View File

@@ -2000,20 +2000,11 @@ LayersId nsBaseWidget::GetRootLayerTreeId() {
: LayersId{0};
}
already_AddRefed<nsIScreen> nsBaseWidget::GetWidgetScreen() {
nsCOMPtr<nsIScreenManager> screenManager;
screenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
if (!screenManager) {
return nullptr;
}
already_AddRefed<widget::Screen> nsBaseWidget::GetWidgetScreen() {
ScreenManager& screenManager = ScreenManager::GetSingleton();
LayoutDeviceIntRect bounds = GetScreenBounds();
DesktopIntRect deskBounds = RoundedToInt(bounds / GetDesktopToDeviceScale());
nsCOMPtr<nsIScreen> screen;
screenManager->ScreenForRect(deskBounds.X(), deskBounds.Y(),
deskBounds.Width(), deskBounds.Height(),
getter_AddRefs(screen));
return screen.forget();
return screenManager.ScreenForRect(deskBounds);
}
mozilla::DesktopToLayoutDeviceScale

View File

@@ -205,7 +205,7 @@ class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference {
uint16_t aDuration, nsISupports* aData,
nsIRunnable* aCallback) override;
void CleanupFullscreenTransition() override {}
already_AddRefed<nsIScreen> GetWidgetScreen() override;
already_AddRefed<Screen> GetWidgetScreen() override;
nsresult MakeFullScreen(bool aFullScreen) override;
void InfallibleMakeFullScreen(bool aFullScreen);

View File

@@ -49,7 +49,6 @@ class nsIRollupListener;
class imgIContainer;
class nsIContent;
class ViewWrapper;
class nsIScreen;
class nsIRunnable;
namespace mozilla {
@@ -87,6 +86,7 @@ class TextEventDispatcher;
class TextEventDispatcherListener;
class CompositorWidget;
class CompositorWidgetInitData;
class Screen;
} // namespace widget
namespace wr {
class DisplayListBuilder;
@@ -383,6 +383,7 @@ class nsIWidget : public nsISupports {
using PopupLevel = mozilla::widget::PopupLevel;
using BorderStyle = mozilla::widget::BorderStyle;
using TransparencyMode = mozilla::widget::TransparencyMode;
using Screen = mozilla::widget::Screen;
// Used in UpdateThemeGeometries.
struct ThemeGeometry {
@@ -1160,7 +1161,7 @@ class nsIWidget : public nsISupports {
/**
* Return the screen the widget is in, or null if we don't know.
*/
virtual already_AddRefed<nsIScreen> GetWidgetScreen() = 0;
virtual already_AddRefed<Screen> GetWidgetScreen() = 0;
/**
* Put the toplevel window into or out of fullscreen mode.

View File

@@ -147,6 +147,7 @@
#include "mozilla/TextEventDispatcherListener.h"
#include "mozilla/widget/nsAutoRollup.h"
#include "mozilla/widget/PlatformWidgetTypes.h"
#include "mozilla/widget/Screen.h"
#include "nsStyleConsts.h"
#include "nsBidiKeyboard.h"
#include "nsStyleConsts.h"