Commit c7acbaf0 authored by stransky's avatar stransky
Browse files

Bug 1803016 [Wayland] Don't commit wl_buffer if buffer scale doesn't match its size r=emilio

parent 84688dc4
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -597,6 +597,13 @@ void moz_container_wayland_set_scale_factor(MozContainer* container) {
  }
}

bool moz_container_wayland_size_matches_scale_factor_locked(
    const MutexAutoLock& aProofOfLock, MozContainer* container, int aWidth,
    int aHeight) {
  return aWidth % container->wl_container.buffer_scale == 0 &&
         aHeight % container->wl_container.buffer_scale == 0;
}

static bool moz_container_wayland_surface_create_locked(
    const MutexAutoLock& aProofOfLock, MozContainer* container) {
  MozContainerWayland* wl_container = &container->wl_container;
+3 −0
Original line number Diff line number Diff line
@@ -85,6 +85,9 @@ bool moz_container_wayland_egl_window_needs_size_update(MozContainer* container,
void moz_container_wayland_set_scale_factor(MozContainer* container);
void moz_container_wayland_set_scale_factor_locked(
    const mozilla::MutexAutoLock& aProofOfLock, MozContainer* container);
bool moz_container_wayland_size_matches_scale_factor_locked(
    const mozilla::MutexAutoLock& aProofOfLock, MozContainer* container,
    int aWidth, int aHeight);

void moz_container_wayland_add_initial_draw_callback_locked(
    MozContainer* container, const std::function<void(void)>& initial_draw_cb);
+14 −3
Original line number Diff line number Diff line
@@ -285,8 +285,8 @@ void WindowSurfaceWaylandMB::Commit(
  mFrameInProcess = false;

  MozContainer* container = mWindow->GetMozContainer();
  MozContainerSurfaceLock lock(container);
  struct wl_surface* waylandSurface = lock.GetSurface();
  MozContainerSurfaceLock MozContainerLock(container);
  struct wl_surface* waylandSurface = MozContainerLock.GetSurface();
  if (!waylandSurface) {
    LOGWAYLAND(
        "WindowSurfaceWaylandMB::Commit [%p] frame queued: can't lock "
@@ -319,8 +319,19 @@ void WindowSurfaceWaylandMB::Commit(
    }
  }

  // aProofOfLock is a kind of substitution of MozContainerSurfaceLock.
  // MozContainer is locked but MozContainerSurfaceLock doen't convert to
  // MutexAutoLock& so we use aProofOfLock here.
  moz_container_wayland_set_scale_factor_locked(aProofOfLock, container);

  // It's possible that scale factor changed between Lock() and Commit()
  // but window size is the same.
  // Don't attach such buffer as it may have incorrect size,
  // we'll paint new content soon.
  if (moz_container_wayland_size_matches_scale_factor_locked(
          aProofOfLock, container, mWindowSize.width, mWindowSize.height)) {
    mInProgressBuffer->AttachAndCommit(waylandSurface);
  }

  mInProgressBuffer->ResetBufferAge();
  mFrontBuffer = mInProgressBuffer;