1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef _MOZILLA_WIDGET_GTK_WINDOW_SURFACE_PROVIDER_H
8 #define _MOZILLA_WIDGET_GTK_WINDOW_SURFACE_PROVIDER_H
12 #include "mozilla/gfx/2D.h"
13 #include "mozilla/gfx/Types.h"
14 #include "mozilla/layers/LayersTypes.h"
15 #include "mozilla/widget/WindowSurface.h"
17 #include "mozilla/ScopeExit.h"
20 # include <X11/Xlib.h> // for Window, Display, Visual, etc.
21 # include "X11UndefineNone.h"
30 * Holds the logic for creating WindowSurface's for a GTK nsWindow.
31 * The main purpose of this class is to allow sharing of logic between
32 * nsWindow and GtkCompositorWidget, for when OMTC is enabled or disabled.
34 class WindowSurfaceProvider final
{
36 WindowSurfaceProvider();
37 ~WindowSurfaceProvider() = default;
40 * Initializes the WindowSurfaceProvider by giving it the window
41 * handle and display to attach to. WindowSurfaceProvider doesn't
42 * own the Display, Window, etc, and they must continue to exist
43 * while WindowSurfaceProvider is used.
46 void Initialize(RefPtr
<nsWindow
> aWidget
);
49 void Initialize(Window aWindow
, Visual
* aVisual
, int aDepth
, bool aIsShaped
);
53 * Releases any surfaces created by this provider.
54 * This is used by GtkCompositorWidget to get rid
57 void CleanupResources();
59 already_AddRefed
<gfx::DrawTarget
> StartRemoteDrawingInRegion(
60 const LayoutDeviceIntRegion
& aInvalidRegion
,
61 layers::BufferMode
* aBufferMode
);
62 void EndRemoteDrawingInRegion(gfx::DrawTarget
* aDrawTarget
,
63 const LayoutDeviceIntRegion
& aInvalidRegion
);
66 RefPtr
<WindowSurface
> CreateWindowSurface();
67 void CleanupWindowSurface();
69 RefPtr
<WindowSurface
> mWindowSurface
;
71 /* While CleanupResources() can be called from Main thread when nsWindow is
72 * destroyed/hidden, StartRemoteDrawingInRegion()/EndRemoteDrawingInRegion()
73 * is called from Compositor thread during rendering.
75 * As nsWindow CleanupResources() call comes from Gtk/X11 we can't synchronize
76 * that with WebRender so we use lock to synchronize the access.
78 mozilla::Mutex mMutex MOZ_UNANNOTATED
;
79 // WindowSurface needs to be re-created as underlying window was changed.
80 mozilla::Atomic
<bool> mWindowSurfaceValid
;
82 RefPtr
<nsWindow
> mWidget
;
93 } // namespace mozilla
95 #endif // _MOZILLA_WIDGET_GTK_WINDOW_SURFACE_PROVIDER_H