commit a2c849b752fa5d3d9dca7e64388d6304a5b6b866
parent 0e3c36327b9db4fc705e7790f6400db5c4838281
Author: stransky <stransky@redhat.com>
Date: Mon, 24 Nov 2025 06:39:19 +0000
Bug 1988717 [Wayland] Use DesktopIntSize for WaylandSurface unscaled coordinates and remove unused scaled coords frm WaylandSurface r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D273578
Diffstat:
5 files changed, 45 insertions(+), 52 deletions(-)
diff --git a/gfx/layers/NativeLayerWayland.cpp b/gfx/layers/NativeLayerWayland.cpp
@@ -606,7 +606,7 @@ RefPtr<WaylandBuffer> NativeLayerRootWayland::BorrowExternalBuffer(
NativeLayerWayland::NativeLayerWayland(NativeLayerRootWayland* aRootLayer,
const IntSize& aSize, bool aIsOpaque)
: mRootLayer(aRootLayer), mIsOpaque(aIsOpaque), mSize(aSize) {
- mSurface = new WaylandSurface(mRootLayer->GetRootWaylandSurface(), mSize);
+ mSurface = new WaylandSurface(mRootLayer->GetRootWaylandSurface());
#ifdef MOZ_LOGGING
mSurface->SetLoggingWidget(this);
#endif
@@ -794,10 +794,13 @@ void NativeLayerWayland::UpdateLayerPlacementLocked(
mSurface->SetTransformFlippedLocked(aProofOfLock, transform2D._11 < 0.0,
transform2D._22 < 0.0);
+
+ // TODO! Downscale introduces rounding errors here.
auto unscaledRect =
gfx::RoundedToInt(surfaceRectClipped / UnknownScaleFactor(mScale));
- mSurface->MoveLocked(aProofOfLock, unscaledRect.TopLeft());
- mSurface->SetViewPortDestLocked(aProofOfLock, unscaledRect.Size());
+ auto rect = DesktopIntRect::FromUnknownRect(unscaledRect);
+ mSurface->MoveLocked(aProofOfLock, rect.TopLeft());
+ mSurface->SetViewPortDestLocked(aProofOfLock, rect.Size());
auto transform2DInversed = transform2D.Inverse();
Rect bufferClip = transform2DInversed.TransformBounds(surfaceRectClipped);
@@ -864,7 +867,7 @@ bool NativeLayerWayland::Map(WaylandSurfaceLock* aParentWaylandSurfaceLock) {
MOZ_DIAGNOSTIC_ASSERT(mNeedsMainThreadUpdate != MainThreadUpdate::Map);
if (!mSurface->MapLocked(surfaceLock, aParentWaylandSurfaceLock,
- gfx::IntPoint(0, 0))) {
+ DesktopIntPoint())) {
gfxCriticalError() << "NativeLayerWayland::Map() failed!";
return false;
}
diff --git a/widget/gtk/MozContainerWayland.cpp b/widget/gtk/MozContainerWayland.cpp
@@ -83,7 +83,7 @@ using namespace mozilla;
using namespace mozilla::widget;
static bool moz_container_wayland_ensure_surface(
- MozContainer* container, gfx::IntPoint* aPosition = nullptr);
+ MozContainer* container, DesktopIntPoint* aPosition = nullptr);
// Invalidate gtk wl_surface to commit changes to wl_subsurface.
// wl_subsurface changes are effective when parent surface is commited.
@@ -176,14 +176,14 @@ void moz_container_wayland_size_allocate(GtkWidget* widget,
// We need to position our subsurface according to GdkWindow
// when offset changes (GdkWindow is maximized for instance).
// see gtk-clutter-embed.c for reference.
- gfx::IntPoint position(allocation->x, allocation->y);
- moz_container_wayland_ensure_surface(MOZ_CONTAINER(widget), &position);
+ auto pos = DesktopIntPoint(allocation->x, allocation->y);
+ moz_container_wayland_ensure_surface(MOZ_CONTAINER(widget), &pos);
MOZ_WL_CONTAINER(widget)->before_first_size_alloc = false;
}
}
static bool moz_container_wayland_ensure_surface(MozContainer* container,
- gfx::IntPoint* aPosition) {
+ DesktopIntPoint* aPosition) {
WaylandSurface* surface = MOZ_WL_SURFACE(container);
WaylandSurfaceLock lock(surface);
@@ -213,12 +213,8 @@ static bool moz_container_wayland_ensure_surface(MozContainer* container,
nsWindow* window = moz_container_get_nsWindow(container);
MOZ_RELEASE_ASSERT(window);
- gfx::IntPoint subsurfacePosition;
- if (aPosition) {
- subsurfacePosition = *aPosition;
- }
-
- if (!surface->MapLocked(lock, parentSurface, subsurfacePosition)) {
+ if (!surface->MapLocked(lock, parentSurface,
+ aPosition ? *aPosition : DesktopIntPoint())) {
return false;
}
diff --git a/widget/gtk/WaylandSurface.cpp b/widget/gtk/WaylandSurface.cpp
@@ -86,12 +86,10 @@ bool WaylandSurface::IsOpaqueRegionEnabled() {
return sIsOpaqueRegionEnabled;
}
-WaylandSurface::WaylandSurface(RefPtr<WaylandSurface> aParent,
- gfx::IntSize aSize)
- : mSizeScaled(aSize), mParent(aParent) {
- LOGWAYLAND("WaylandSurface::WaylandSurface(), parent [%p] size [%d x %d]",
- mParent ? mParent->GetLoggingWidget() : nullptr, mSizeScaled.width,
- mSizeScaled.height);
+WaylandSurface::WaylandSurface(RefPtr<WaylandSurface> aParent)
+ : mParent(aParent) {
+ LOGWAYLAND("WaylandSurface::WaylandSurface(), parent [%p]",
+ mParent ? mParent->GetLoggingWidget() : nullptr);
struct wl_compositor* compositor = WaylandDisplayGet()->GetCompositor();
mSurface = wl_compositor_create_surface(compositor);
MOZ_RELEASE_ASSERT(mSurface, "Can't create wl_surface!");
@@ -404,7 +402,7 @@ void WaylandSurface::VisibleCallbackHandler() {
bool WaylandSurface::MapLocked(const WaylandSurfaceLock& aProofOfLock,
wl_surface* aParentWLSurface,
WaylandSurfaceLock* aParentWaylandSurfaceLock,
- gfx::IntPoint aSubsurfacePosition,
+ DesktopIntPoint aSubsurfacePosition,
bool aSubsurfaceDesync) {
LOGWAYLAND("WaylandSurface::MapLocked()");
MOZ_DIAGNOSTIC_ASSERT(&aProofOfLock == mSurfaceLock);
@@ -473,14 +471,14 @@ bool WaylandSurface::MapLocked(const WaylandSurfaceLock& aProofOfLock,
bool WaylandSurface::MapLocked(const WaylandSurfaceLock& aProofOfLock,
wl_surface* aParentWLSurface,
- gfx::IntPoint aSubsurfacePosition) {
+ DesktopIntPoint aSubsurfacePosition) {
return MapLocked(aProofOfLock, aParentWLSurface, nullptr, aSubsurfacePosition,
/* aSubsurfaceDesync */ true);
}
bool WaylandSurface::MapLocked(const WaylandSurfaceLock& aProofOfLock,
WaylandSurfaceLock* aParentWaylandSurfaceLock,
- gfx::IntPoint aSubsurfacePosition) {
+ DesktopIntPoint aSubsurfacePosition) {
return MapLocked(aProofOfLock, nullptr, aParentWaylandSurfaceLock,
aSubsurfacePosition,
/* aSubsurfaceDesync */ false);
@@ -544,7 +542,7 @@ void WaylandSurface::UnmapLocked(WaylandSurfaceLock& aSurfaceLock) {
ClearScaleLocked(aSurfaceLock);
MozClearPointer(mViewport, wp_viewport_destroy);
- mViewportDestinationSize = gfx::IntSize(-1, -1);
+ mViewportDestinationSize = DesktopIntSize(-1, -1);
mViewportSourceRect = gfx::Rect(-1, -1, -1, -1);
MozClearPointer(mFractionalScaleListener, wp_fractional_scale_v1_destroy);
@@ -608,7 +606,7 @@ void WaylandSurface::CommitLocked(const WaylandSurfaceLock& aProofOfLock,
}
void WaylandSurface::MoveLocked(const WaylandSurfaceLock& aProofOfLock,
- gfx::IntPoint aPosition) {
+ DesktopIntPoint aPosition) {
MOZ_DIAGNOSTIC_ASSERT(&aProofOfLock == mSurfaceLock);
MOZ_DIAGNOSTIC_ASSERT(mIsMapped);
@@ -617,7 +615,7 @@ void WaylandSurface::MoveLocked(const WaylandSurfaceLock& aProofOfLock,
}
MOZ_DIAGNOSTIC_ASSERT(mSubsurface);
- LOGWAYLAND("WaylandSurface::MoveLocked() [%d,%d]", (int)aPosition.x,
+ LOGWAYLAND("WaylandSurface::MoveLocked() unscaled [%d,%d]", (int)aPosition.x,
(int)aPosition.y);
mSubsurfacePosition = aPosition;
wl_subsurface_set_position(mSubsurface, aPosition.x, aPosition.y);
@@ -785,21 +783,17 @@ void WaylandSurface::SetCeiledScaleLocked(
}
void WaylandSurface::SetSizeLocked(const WaylandSurfaceLock& aProofOfLock,
- gfx::IntSize aSizeScaled,
- gfx::IntSize aSizeUnscaled) {
+ DesktopIntSize aSize) {
MOZ_DIAGNOSTIC_ASSERT(&aProofOfLock == mSurfaceLock);
- LOGVERBOSE(
- "WaylandSurface::SetSizeLocked(): Size [%d x %d] unscaled size [%d x %d]",
- aSizeScaled.width, aSizeScaled.height, aSizeUnscaled.width,
- aSizeUnscaled.height);
- mSizeScaled = aSizeScaled;
+ LOGVERBOSE("WaylandSurface::SetSizeLocked(): size [%d x %d]", aSize.width,
+ aSize.height);
if (mViewportFollowsSizeChanges) {
- SetViewPortDestLocked(aProofOfLock, aSizeUnscaled);
+ SetViewPortDestLocked(aProofOfLock, aSize);
}
}
void WaylandSurface::SetViewPortDestLocked(
- const WaylandSurfaceLock& aProofOfLock, gfx::IntSize aDestSize) {
+ const WaylandSurfaceLock& aProofOfLock, DesktopIntSize aDestSize) {
MOZ_DIAGNOSTIC_ASSERT(&aProofOfLock == mSurfaceLock);
if (!mViewport) {
return;
@@ -967,7 +961,7 @@ wl_egl_window* WaylandSurface::GetEGLWindow(DesktopIntSize aSize) {
}
if (mEGLWindow) {
- SetSizeLocked(lock, scaledSize.ToUnknownSize(), aSize.ToUnknownSize());
+ SetSizeLocked(lock, aSize);
}
return mEGLWindow;
@@ -994,7 +988,7 @@ bool WaylandSurface::SetEGLWindowSize(LayoutDeviceIntSize aSize) {
GetScale());
wl_egl_window_resize(mEGLWindow, aSize.width, aSize.height, 0, 0);
- SetSizeLocked(lock, aSize.ToUnknownSize(), unscaledSize.ToUnknownSize());
+ SetSizeLocked(lock, unscaledSize);
return true;
}
@@ -1083,10 +1077,11 @@ bool WaylandSurface::AttachLocked(const WaylandSurfaceLock& aSurfaceLock,
auto scale = GetScale();
LayoutDeviceIntSize bufferSize = aBuffer->GetSize();
+
// TODO: rounding?
- SetSizeLocked(aSurfaceLock, gfx::IntSize(bufferSize.width, bufferSize.height),
- gfx::IntSize((int)round(bufferSize.width / scale),
- (int)round(bufferSize.height / scale)));
+ DesktopIntSize unscaledSize((int)round(bufferSize.width / scale),
+ (int)round(bufferSize.height / scale));
+ SetSizeLocked(aSurfaceLock, unscaledSize);
LOGWAYLAND(
"WaylandSurface::AttachLocked() transactions [%d] WaylandBuffer [%p] "
@@ -1113,7 +1108,7 @@ void WaylandSurface::RemoveAttachedBufferLocked(
LOGWAYLAND("WaylandSurface::RemoveAttachedBufferLocked()");
- SetSizeLocked(aSurfaceLock, gfx::IntSize(0, 0), gfx::IntSize(0, 0));
+ SetSizeLocked(aSurfaceLock, DesktopIntSize(0, 0));
wl_surface_attach(mSurface, nullptr, 0, 0);
mLatestAttachedBuffer = 0;
mSurfaceNeedsCommit = true;
diff --git a/widget/gtk/WaylandSurface.h b/widget/gtk/WaylandSurface.h
@@ -35,7 +35,7 @@ class WaylandSurface final {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WaylandSurface);
- WaylandSurface(RefPtr<WaylandSurface> aParent, gfx::IntSize aSize);
+ WaylandSurface(RefPtr<WaylandSurface> aParent);
#ifdef MOZ_LOGGING
nsAutoCString GetDebugTag() const;
@@ -96,11 +96,11 @@ class WaylandSurface final {
// Mapped as direct surface of MozContainer
bool MapLocked(const WaylandSurfaceLock& aProofOfLock,
wl_surface* aParentWLSurface,
- gfx::IntPoint aSubsurfacePosition);
+ DesktopIntPoint aSubsurfacePosition);
// Mapped as child of WaylandSurface (used by layers)
bool MapLocked(const WaylandSurfaceLock& aProofOfLock,
WaylandSurfaceLock* aParentWaylandSurfaceLock,
- gfx::IntPoint aSubsurfacePosition);
+ DesktopIntPoint aSubsurfacePosition);
// Unmap surface which hides it
void UnmapLocked(WaylandSurfaceLock& aSurfaceLock);
@@ -159,11 +159,11 @@ class WaylandSurface final {
void PlaceAboveLocked(const WaylandSurfaceLock& aProofOfLock,
WaylandSurfaceLock& aLowerSurfaceLock);
void MoveLocked(const WaylandSurfaceLock& aProofOfLock,
- gfx::IntPoint aPosition);
+ DesktopIntPoint aPosition);
void SetViewPortSourceRectLocked(const WaylandSurfaceLock& aProofOfLock,
gfx::Rect aRect);
void SetViewPortDestLocked(const WaylandSurfaceLock& aProofOfLock,
- gfx::IntSize aDestSize);
+ DesktopIntSize aDestSize);
void SetTransformFlippedLocked(const WaylandSurfaceLock& aProofOfLock,
bool aFlippedX, bool aFlippedY);
@@ -277,10 +277,10 @@ class WaylandSurface final {
bool MapLocked(const WaylandSurfaceLock& aProofOfLock,
wl_surface* aParentWLSurface,
WaylandSurfaceLock* aParentWaylandSurfaceLock,
- gfx::IntPoint aSubsurfacePosition, bool aSubsurfaceDesync);
+ DesktopIntPoint aSubsurfacePosition, bool aSubsurfaceDesync);
void SetSizeLocked(const WaylandSurfaceLock& aProofOfLock,
- gfx::IntSize aSizeScaled, gfx::IntSize aUnscaledSize);
+ DesktopIntSize aSize);
wl_surface* Lock(WaylandSurfaceLock* aWaylandSurfaceLock);
void Unlock(struct wl_surface** aSurface,
@@ -349,7 +349,7 @@ class WaylandSurface final {
bool mSubsurfaceDesync = true;
wl_subsurface* mSubsurface = nullptr;
- gfx::IntPoint mSubsurfacePosition{-1, -1};
+ DesktopIntPoint mSubsurfacePosition{-1, -1};
// Wayland buffers recently attached to this surface or held by
// Wayland compositor.
@@ -371,7 +371,7 @@ class WaylandSurface final {
bool mViewportFollowsSizeChanges = true;
wp_viewport* mViewport = nullptr;
gfx::Rect mViewportSourceRect{-1, -1, -1, -1};
- gfx::IntSize mViewportDestinationSize{-1, -1};
+ DesktopIntSize mViewportDestinationSize{-1, -1};
// Surface flip state on X/Y asix
bool mBufferTransformFlippedX = false;
diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp
@@ -6398,8 +6398,7 @@ nsresult nsWindow::Create(nsIWidget* aParent, const LayoutDeviceIntRect& aRect,
if (GdkIsWaylandDisplay()) {
mSurface = new WaylandSurface(
parentnsWindow ? MOZ_WL_SURFACE(parentnsWindow->GetMozContainer())
- : nullptr,
- gfx::IntSize(ToLayoutDevicePixels(mLastSizeRequest).ToUnknownSize()));
+ : nullptr);
}
container = moz_container_new(this, mSurface);
#else