Bug 1592933 - [Wayland] Cache scale factor for toplevel windows, r=jhorak

Differential Revision: https://phabricator.services.mozilla.com/D51253

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Martin Stransky 2019-11-06 13:18:55 +00:00
Родитель 93728f0682
Коммит 486a8209db
2 изменённых файлов: 21 добавлений и 2 удалений

Просмотреть файл

@ -476,6 +476,9 @@ nsWindow::nsWindow() {
mHasAlphaVisual = false;
mIsPIPWindow = false;
mWindowScaleFactorChanged = true;
mWindowScaleFactor = 1;
}
nsWindow::~nsWindow() {
@ -3440,6 +3443,9 @@ void nsWindow::OnCompositedChanged() {
}
void nsWindow::OnScaleChanged(GtkAllocation* aAllocation) {
// Force scale factor recalculation
mWindowScaleFactorChanged = true;
// This eventually propagate new scale to the PuppetWidgets
OnDPIChanged();
@ -6747,6 +6753,12 @@ GtkWindow* nsWindow::GetCurrentTopmostWindow() {
}
gint nsWindow::GdkScaleFactor() {
// We depend on notify::scale-factor callback which is reliable for toplevel
// windows only, so don't use scale cache for popup windows.
if (mWindowType == eWindowType_toplevel && !mWindowScaleFactorChanged) {
return mWindowScaleFactor;
}
GdkWindow* scaledGdkWindow = mGdkWindow;
if (!mIsX11Display) {
// For popup windows/dialogs with parent window we need to get scale factor
@ -6767,13 +6779,18 @@ gint nsWindow::GdkScaleFactor() {
}
}
}
// Available as of GTK 3.10+
static auto sGdkWindowGetScaleFactorPtr =
(gint(*)(GdkWindow*))dlsym(RTLD_DEFAULT, "gdk_window_get_scale_factor");
if (sGdkWindowGetScaleFactorPtr && scaledGdkWindow) {
return (*sGdkWindowGetScaleFactorPtr)(scaledGdkWindow);
mWindowScaleFactor = (*sGdkWindowGetScaleFactorPtr)(scaledGdkWindow);
} else {
mWindowScaleFactor = ScreenHelperGTK::GetGTKMonitorScaleFactor();
}
return ScreenHelperGTK::GetGTKMonitorScaleFactor();
mWindowScaleFactorChanged = false;
return mWindowScaleFactor;
}
gint nsWindow::DevicePixelsToGdkCoordRoundUp(int pixels) {

Просмотреть файл

@ -448,6 +448,8 @@ class nsWindow final : public nsBaseWidget {
bool mNeedsUpdatingEGLSurface;
bool mCompositorInitiallyPaused;
#endif
bool mWindowScaleFactorChanged;
int mWindowScaleFactor;
private:
void DestroyChildWindows();