Bug 1764283 [Wayland] Don't commit to MozContainer when WindowSurfaceProvider internals are released r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D143602
This commit is contained in:
stransky 2022-04-14 06:14:45 +00:00
Родитель d4e98eaeed
Коммит 5c5510777a
1 изменённых файлов: 27 добавлений и 19 удалений

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

@ -161,28 +161,36 @@ WindowSurfaceProvider::StartRemoteDrawingInRegion(
void WindowSurfaceProvider::EndRemoteDrawingInRegion(
gfx::DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
#if defined(MOZ_WAYLAND)
if (GdkIsWaylandDisplay() && moz_container_wayland_is_commiting_to_parent(
mWidget->GetMozContainer())) {
// If we're drawing directly to wl_surface owned by Gtk we need to use it
// in main thread to sync with Gtk access to it.
NS_DispatchToMainThread(NS_NewRunnableFunction(
"WindowSurfaceProvider::EndRemoteDrawingInRegion",
[RefPtr{mWidget}, this, aInvalidRegion]() {
MutexAutoLock lock(mMutex);
// Commit to mWindowSurface only when we have a valid one.
if (mWindowSurface && mWindowSurfaceValid) {
mWindowSurface->Commit(aInvalidRegion);
}
}));
MutexAutoLock lock(mMutex);
// Commit to mWindowSurface only if we have a valid one.
if (!mWindowSurface || !mWindowSurfaceValid) {
return;
}
#endif
MutexAutoLock lock(mMutex);
// Commit to mWindowSurface only when we have a valid one.
if (mWindowSurface && mWindowSurfaceValid) {
mWindowSurface->Commit(aInvalidRegion);
#if defined(MOZ_WAYLAND)
if (GdkIsWaylandDisplay()) {
// We're called too early or we're unmapped.
// Don't draw anything.
if (!mWidget) {
return;
}
if (moz_container_wayland_is_commiting_to_parent(
mWidget->GetMozContainer())) {
// If we're drawing directly to wl_surface owned by Gtk we need to use it
// in main thread to sync with Gtk access to it.
NS_DispatchToMainThread(NS_NewRunnableFunction(
"WindowSurfaceProvider::EndRemoteDrawingInRegion",
[RefPtr{mWidget}, this, aInvalidRegion]() {
MutexAutoLock lock(mMutex);
// Commit to mWindowSurface only when we have a valid one.
if (mWindowSurface && mWindowSurfaceValid) {
mWindowSurface->Commit(aInvalidRegion);
}
}));
return;
}
}
#endif
mWindowSurface->Commit(aInvalidRegion);
}
} // namespace widget