mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 1753612 [Linux] Sychronize access to WindowSurfaceProvider r=lsalzman
- Remove WindowSurfaceProvider::CleanupWindowSurface() method. - Use default WindowSurfaceProvider destructor. - Use mutex to public WindowSurfaceProvider methods to avoid race of main and render threads. Differential Revision: https://phabricator.services.mozilla.com/D138699
This commit is contained in:
parent
36418078ab
commit
190bb56270
@ -39,6 +39,7 @@ using namespace mozilla::layers;
|
||||
|
||||
WindowSurfaceProvider::WindowSurfaceProvider()
|
||||
: mWindowSurface(nullptr),
|
||||
mMutex("WindowSurfaceProvider"),
|
||||
mWindowSurfaceValid(false)
|
||||
#ifdef MOZ_WAYLAND
|
||||
,
|
||||
@ -54,11 +55,6 @@ WindowSurfaceProvider::WindowSurfaceProvider()
|
||||
{
|
||||
}
|
||||
|
||||
WindowSurfaceProvider::~WindowSurfaceProvider() {
|
||||
CleanupResources();
|
||||
CleanupWindowSurface();
|
||||
}
|
||||
|
||||
#ifdef MOZ_WAYLAND
|
||||
void WindowSurfaceProvider::Initialize(RefPtr<nsWindow> aWidget) {
|
||||
mWindowSurfaceValid = false;
|
||||
@ -77,6 +73,7 @@ void WindowSurfaceProvider::Initialize(Window aWindow, Visual* aVisual,
|
||||
#endif
|
||||
|
||||
void WindowSurfaceProvider::CleanupResources() {
|
||||
MutexAutoLock lock(mMutex);
|
||||
mWindowSurfaceValid = false;
|
||||
#ifdef MOZ_WAYLAND
|
||||
mWidget = nullptr;
|
||||
@ -89,11 +86,6 @@ void WindowSurfaceProvider::CleanupResources() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void WindowSurfaceProvider::CleanupWindowSurface() {
|
||||
mWindowSurface = nullptr;
|
||||
mWindowSurfaceValid = true;
|
||||
}
|
||||
|
||||
RefPtr<WindowSurface> WindowSurfaceProvider::CreateWindowSurface() {
|
||||
#ifdef MOZ_WAYLAND
|
||||
if (GdkIsWaylandDisplay()) {
|
||||
@ -137,8 +129,11 @@ WindowSurfaceProvider::StartRemoteDrawingInRegion(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MutexAutoLock lock(mMutex);
|
||||
|
||||
if (!mWindowSurfaceValid) {
|
||||
CleanupWindowSurface();
|
||||
mWindowSurface = nullptr;
|
||||
mWindowSurfaceValid = true;
|
||||
}
|
||||
|
||||
if (!mWindowSurface) {
|
||||
@ -166,6 +161,7 @@ WindowSurfaceProvider::StartRemoteDrawingInRegion(
|
||||
|
||||
void WindowSurfaceProvider::EndRemoteDrawingInRegion(
|
||||
gfx::DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
|
||||
MutexAutoLock lock(mMutex);
|
||||
// Commit to mWindowSurface only when we have a valid one.
|
||||
if (mWindowSurface && mWindowSurfaceValid) {
|
||||
mWindowSurface->Commit(aInvalidRegion);
|
||||
|
@ -34,7 +34,7 @@ namespace widget {
|
||||
class WindowSurfaceProvider final {
|
||||
public:
|
||||
WindowSurfaceProvider();
|
||||
~WindowSurfaceProvider();
|
||||
~WindowSurfaceProvider() = default;
|
||||
|
||||
/**
|
||||
* Initializes the WindowSurfaceProvider by giving it the window
|
||||
@ -67,6 +67,15 @@ class WindowSurfaceProvider final {
|
||||
void CleanupWindowSurface();
|
||||
|
||||
RefPtr<WindowSurface> mWindowSurface;
|
||||
|
||||
/* While CleanupResources() can be called from Main thread when nsWindow is
|
||||
* destroyed/hidden, StartRemoteDrawingInRegion()/EndRemoteDrawingInRegion()
|
||||
* is called from Compositor thread during rendering.
|
||||
*
|
||||
* As nsWindow CleanupResources() call comes from Gtk/X11 we can't synchronize
|
||||
* that with WebRender so we use lock to synchronize the access.
|
||||
*/
|
||||
mozilla::Mutex mMutex;
|
||||
// WindowSurface needs to be re-created as underlying window was changed.
|
||||
mozilla::Atomic<bool> mWindowSurfaceValid;
|
||||
#ifdef MOZ_WAYLAND
|
||||
|
Loading…
Reference in New Issue
Block a user