diff --git a/gfx/webrender_bindings/RenderCompositorSWGL.cpp b/gfx/webrender_bindings/RenderCompositorSWGL.cpp index 1eec99bb3a72..e52b8eba50cd 100644 --- a/gfx/webrender_bindings/RenderCompositorSWGL.cpp +++ b/gfx/webrender_bindings/RenderCompositorSWGL.cpp @@ -57,13 +57,6 @@ bool RenderCompositorSWGL::MakeCurrent() { } bool RenderCompositorSWGL::BeginFrame() { - mRenderWidgetSize = Some(mWidget->GetClientSize()); -#ifdef MOZ_WAYLAND - if (mLastRenderWidgetSize != mRenderWidgetSize.value()) { - mLastRenderWidgetSize = mRenderWidgetSize.value(); - mRequestFullRender = true; - } -#endif // Set up a temporary region representing the entire window surface in case a // dirty region is not supplied. ClearMappedBuffer(); @@ -248,10 +241,7 @@ void RenderCompositorSWGL::CommitMappedBuffer(bool aDirty) { ClearMappedBuffer(); } -void RenderCompositorSWGL::CancelFrame() { - CommitMappedBuffer(false); - mRenderWidgetSize = Nothing(); -} +void RenderCompositorSWGL::CancelFrame() { CommitMappedBuffer(false); } RenderedFrameId RenderCompositorSWGL::EndFrame( const nsTArray& aDirtyRects) { @@ -260,7 +250,6 @@ RenderedFrameId RenderCompositorSWGL::EndFrame( // to EndRemoteDrawingInRegion as for StartRemoteDrawingInRegion. RenderedFrameId frameId = GetNextRenderFrameId(); CommitMappedBuffer(); - mRenderWidgetSize = Nothing(); return frameId; } @@ -289,11 +278,7 @@ bool RenderCompositorSWGL::Resume() { } LayoutDeviceIntSize RenderCompositorSWGL::GetBufferSize() { - // If we're between BeginFrame() and EndFrame()/CancelFrame() calls - // return recent rendering size instead of actual underlying widget - // size. It prevents possible rendering artifacts if widget size was changed. - return mRenderWidgetSize ? mRenderWidgetSize.value() - : mWidget->GetClientSize(); + return mWidget->GetClientSize(); } void RenderCompositorSWGL::GetCompositorCapabilities( diff --git a/gfx/webrender_bindings/RenderCompositorSWGL.h b/gfx/webrender_bindings/RenderCompositorSWGL.h index 2b3ce3545420..7676a34858ba 100644 --- a/gfx/webrender_bindings/RenderCompositorSWGL.h +++ b/gfx/webrender_bindings/RenderCompositorSWGL.h @@ -63,16 +63,10 @@ class RenderCompositorSWGL : public RenderCompositor { void* mContext = nullptr; RefPtr mDT; LayoutDeviceIntRegion mDirtyRegion; - // Keep consistent buffer size between BeginFrame and EndFrame/CancelFrame - // calls to make sure we don't change buffer size during rendering. - Maybe mRenderWidgetSize; RefPtr mSurface; uint8_t* mMappedData = nullptr; int32_t mMappedStride = 0; #ifdef MOZ_WAYLAND - // On Wayland we need to request full render if widget size is changed - // because SW rendering backend reallocates and clears target surface. - LayoutDeviceIntSize mLastRenderWidgetSize; bool mRequestFullRender = false; #endif diff --git a/widget/gtk/GtkCompositorWidget.cpp b/widget/gtk/GtkCompositorWidget.cpp index 2c29d5de03eb..3a2dd3233ce4 100644 --- a/widget/gtk/GtkCompositorWidget.cpp +++ b/widget/gtk/GtkCompositorWidget.cpp @@ -48,7 +48,7 @@ GtkCompositorWidget::GtkCompositorWidget( #endif #if defined(MOZ_WAYLAND) if (GdkIsWaylandDisplay()) { - ConfigureWaylandBackend(); + ConfigureWaylandBackend(mWidget); LOG("GtkCompositorWidget::GtkCompositorWidget() [%p] mWidget %p " "mIsRenderingSuspended %d\n", (void*)mWidget.get(), (void*)mWidget, !!mIsRenderingSuspended); @@ -178,8 +178,8 @@ void GtkCompositorWidget::DisableRendering() { } #if defined(MOZ_WAYLAND) -bool GtkCompositorWidget::ConfigureWaylandBackend() { - mProvider.Initialize(this); +bool GtkCompositorWidget::ConfigureWaylandBackend(RefPtr aWindow) { + mProvider.Initialize(aWindow); return true; } #endif @@ -221,7 +221,7 @@ void GtkCompositorWidget::EnableRendering(const uintptr_t aXWindow, #if defined(MOZ_WAYLAND) if (GdkIsWaylandDisplay()) { LOG(" configure widget %p\n", mWidget.get()); - if (!ConfigureWaylandBackend()) { + if (!ConfigureWaylandBackend(mWidget)) { return; } } diff --git a/widget/gtk/GtkCompositorWidget.h b/widget/gtk/GtkCompositorWidget.h index 601172d09ce6..bc1c3379cd69 100644 --- a/widget/gtk/GtkCompositorWidget.h +++ b/widget/gtk/GtkCompositorWidget.h @@ -99,7 +99,7 @@ class GtkCompositorWidget : public CompositorWidget, private: #if defined(MOZ_WAYLAND) - bool ConfigureWaylandBackend(); + bool ConfigureWaylandBackend(RefPtr aWindow); #endif #if defined(MOZ_X11) bool ConfigureX11Backend(Window aXWindow, bool aShaped); diff --git a/widget/gtk/WindowSurfaceProvider.cpp b/widget/gtk/WindowSurfaceProvider.cpp index faf147a80a4a..f8eee65cc58f 100644 --- a/widget/gtk/WindowSurfaceProvider.cpp +++ b/widget/gtk/WindowSurfaceProvider.cpp @@ -7,7 +7,6 @@ #include "WindowSurfaceProvider.h" #include "gfxPlatformGtk.h" -#include "GtkCompositorWidget.h" #include "mozilla/gfx/Logging.h" #include "mozilla/layers/LayersTypes.h" #include "nsWindow.h" @@ -42,6 +41,10 @@ WindowSurfaceProvider::WindowSurfaceProvider() : mWindowSurface(nullptr), mMutex("WindowSurfaceProvider"), mWindowSurfaceValid(false) +#ifdef MOZ_WAYLAND + , + mWidget(nullptr) +#endif #ifdef MOZ_X11 , mIsShaped(false), @@ -57,11 +60,6 @@ void WindowSurfaceProvider::Initialize(RefPtr aWidget) { mWindowSurfaceValid = false; mWidget = std::move(aWidget); } -void WindowSurfaceProvider::Initialize(GtkCompositorWidget* aCompositorWidget) { - mWindowSurfaceValid = false; - mCompositorWidget = aCompositorWidget; - mWidget = static_cast(aCompositorWidget->RealWidget()); -} #endif #ifdef MOZ_X11 void WindowSurfaceProvider::Initialize(Window aWindow, Visual* aVisual, @@ -95,7 +93,7 @@ RefPtr WindowSurfaceProvider::CreateWindowSurface() { if (!mWidget) { return nullptr; } - return MakeRefPtr(mWidget, mCompositorWidget); + return MakeRefPtr(mWidget); } #endif #ifdef MOZ_X11 diff --git a/widget/gtk/WindowSurfaceProvider.h b/widget/gtk/WindowSurfaceProvider.h index c7c7df42171a..a0d6315591c5 100644 --- a/widget/gtk/WindowSurfaceProvider.h +++ b/widget/gtk/WindowSurfaceProvider.h @@ -44,7 +44,6 @@ class WindowSurfaceProvider final { */ #ifdef MOZ_WAYLAND void Initialize(RefPtr aWidget); - void Initialize(GtkCompositorWidget* aCompositorWidget); #endif #ifdef MOZ_X11 void Initialize(Window aWindow, Visual* aVisual, int aDepth, bool aIsShaped); @@ -81,9 +80,6 @@ class WindowSurfaceProvider final { mozilla::Atomic mWindowSurfaceValid; #ifdef MOZ_WAYLAND RefPtr mWidget; - // WindowSurfaceProvider is owned by GtkCompositorWidget so we don't need - // to reference it. - GtkCompositorWidget* mCompositorWidget = nullptr; #endif #ifdef MOZ_X11 bool mIsShaped; diff --git a/widget/gtk/WindowSurfaceWaylandMultiBuffer.cpp b/widget/gtk/WindowSurfaceWaylandMultiBuffer.cpp index 85ab1942d9e6..c621f2ef6901 100644 --- a/widget/gtk/WindowSurfaceWaylandMultiBuffer.cpp +++ b/widget/gtk/WindowSurfaceWaylandMultiBuffer.cpp @@ -14,7 +14,6 @@ #include "gfx2DGlue.h" #include "gfxPlatform.h" #include "MozContainer.h" -#include "GtkCompositorWidget.h" #include "mozilla/gfx/DataSurfaceHelpers.h" #include "mozilla/gfx/Tools.h" #include "mozilla/ScopeExit.h" @@ -153,29 +152,12 @@ using gfx::DataSourceSurface; #define BACK_BUFFER_NUM 3 -WindowSurfaceWaylandMB::WindowSurfaceWaylandMB( - RefPtr aWindow, GtkCompositorWidget* aCompositorWidget) +WindowSurfaceWaylandMB::WindowSurfaceWaylandMB(RefPtr aWindow) : mSurfaceLock("WindowSurfaceWayland lock"), mWindow(std::move(aWindow)), - mCompositorWidget(aCompositorWidget), mFrameInProcess(false), mCallbackRequested(false) {} -bool WindowSurfaceWaylandMB::MaybeUpdateWindowSize() { - // We want to get window size from compositor widget as it matches window - // size used by parent RenderCompositorSWGL rendrer. - // For main thread rendering mCompositorWidget is not available so get - // window size directly from nsWindow. - LayoutDeviceIntSize newWindowSize = mCompositorWidget - ? mCompositorWidget->GetClientSize() - : mWindow->GetClientSize(); - if (mWindowSize != newWindowSize) { - mWindowSize = newWindowSize; - return true; - } - return false; -} - already_AddRefed WindowSurfaceWaylandMB::Lock( const LayoutDeviceIntRegion& aInvalidRegion) { MutexAutoLock lock(mSurfaceLock); @@ -194,9 +176,11 @@ already_AddRefed WindowSurfaceWaylandMB::Lock( CollectPendingSurfaces(lock); - if (MaybeUpdateWindowSize()) { - LOGWAYLAND(" new window size [%d x %d]", mWindowSize.width, - mWindowSize.height); + LayoutDeviceIntSize newMozContainerSize = mWindow->GetMozContainerSize(); + if (mMozContainerSize != newMozContainerSize) { + mMozContainerSize = newMozContainerSize; + LOGWAYLAND(" new MozContainer size [%d x %d]", mMozContainerSize.width, + mMozContainerSize.height); if (mInProgressBuffer) { ReturnBufferToPool(lock, mInProgressBuffer); mInProgressBuffer = nullptr; @@ -212,7 +196,7 @@ already_AddRefed WindowSurfaceWaylandMB::Lock( if (mFrontBuffer && !mFrontBuffer->IsAttached()) { mInProgressBuffer = mFrontBuffer; } else { - mInProgressBuffer = ObtainBufferFromPool(lock, mWindowSize); + mInProgressBuffer = ObtainBufferFromPool(lock, mMozContainerSize); if (!mInProgressBuffer) { return nullptr; } @@ -273,9 +257,9 @@ void WindowSurfaceWaylandMB::Commit( gfx::IntRect invalidRect = aInvalidRegion.GetBounds().ToUnknownRect(); LOGWAYLAND( "WindowSurfaceWaylandMB::Commit [%p] damage rect [%d, %d] -> [%d x %d] " - "Window [%d x %d]\n", + "MozContainer [%d x %d]\n", (void*)mWindow.get(), invalidRect.x, invalidRect.y, invalidRect.width, - invalidRect.height, mWindowSize.width, mWindowSize.height); + invalidRect.height, mMozContainerSize.width, mMozContainerSize.height); #endif if (!mInProgressBuffer) { @@ -357,7 +341,7 @@ void WindowSurfaceWaylandMB::ReturnBufferToPool( const RefPtr& aBuffer) { if (aBuffer->IsAttached()) { mPendingBuffers.AppendElement(aBuffer); - } else if (aBuffer->IsMatchingSize(mWindowSize)) { + } else if (aBuffer->IsMatchingSize(mMozContainerSize)) { mAvailableBuffers.AppendElement(aBuffer); } mInUseBuffers.RemoveElement(aBuffer); @@ -381,7 +365,7 @@ void WindowSurfaceWaylandMB::CollectPendingSurfaces( const MutexAutoLock& aProofOfLock) { mPendingBuffers.RemoveElementsBy([&](auto& buffer) { if (!buffer->IsAttached()) { - if (buffer->IsMatchingSize(mWindowSize)) { + if (buffer->IsMatchingSize(mMozContainerSize)) { mAvailableBuffers.AppendElement(std::move(buffer)); } return true; diff --git a/widget/gtk/WindowSurfaceWaylandMultiBuffer.h b/widget/gtk/WindowSurfaceWaylandMultiBuffer.h index e14a626de0ed..3e26a1d5b1ff 100644 --- a/widget/gtk/WindowSurfaceWaylandMultiBuffer.h +++ b/widget/gtk/WindowSurfaceWaylandMultiBuffer.h @@ -24,8 +24,7 @@ using gfx::DrawTarget; // and related management class WindowSurfaceWaylandMB : public WindowSurface { public: - WindowSurfaceWaylandMB(RefPtr aWindow, - GtkCompositorWidget* aCompositorWidget); + explicit WindowSurfaceWaylandMB(RefPtr aWindow); ~WindowSurfaceWaylandMB() = default; // Lock() / Commit() are called by gecko when Firefox @@ -54,16 +53,11 @@ class WindowSurfaceWaylandMB : public WindowSurface { void HandlePartialUpdate(const MutexAutoLock& aProofOfLock, const LayoutDeviceIntRegion& aInvalidRegion); void IncrementBufferAge(const MutexAutoLock& aProofOfLock); - // Return true if window size was updated. - bool MaybeUpdateWindowSize(); mozilla::Mutex mSurfaceLock MOZ_UNANNOTATED; RefPtr mWindow; - // WindowSurfaceWaylandMB is owned by GtkCompositorWidget so we can't - // reference it. - GtkCompositorWidget* mCompositorWidget; - LayoutDeviceIntSize mWindowSize; + LayoutDeviceIntSize mMozContainerSize; RefPtr mInProgressBuffer; RefPtr mFrontBuffer; diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index f4a099a7c8b2..8b2cc893fa86 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -9660,6 +9660,18 @@ void nsWindow::SetEGLNativeWindowSize( } #endif +LayoutDeviceIntSize nsWindow::GetMozContainerSize() { + LayoutDeviceIntSize size(0, 0); + if (mContainer) { + GtkAllocation allocation; + gtk_widget_get_allocation(GTK_WIDGET(mContainer), &allocation); + double scale = FractionalScaleFactor(); + size.width = round(allocation.width * scale); + size.height = round(allocation.height * scale); + } + return size; +} + nsWindow* nsWindow::GetWindow(GdkWindow* window) { return get_window_for_gdk_window(window); } diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h index ed01370563cc..1ae9b3f12616 100644 --- a/widget/gtk/nsWindow.h +++ b/widget/gtk/nsWindow.h @@ -274,6 +274,7 @@ class nsWindow final : public nsBaseWidget { static guint32 sLastButtonPressTime; MozContainer* GetMozContainer() { return mContainer; } + LayoutDeviceIntSize GetMozContainerSize(); GdkWindow* GetGdkWindow() const { return mGdkWindow; }; GdkWindow* GetToplevelGdkWindow() const; GtkWidget* GetGtkWidget() const { return mShell; }