Bug 1777562 [wpt PR 34663] - [FedCM] Rename FederatedCredential to IdentityCredential...
[gecko.git] / widget / gtk / WindowSurfaceProvider.h
bloba0d6315591c526f599aa7480ba20e80bedf6fc46
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
10 #include <gdk/gdk.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"
16 #include "Units.h"
17 #include "mozilla/ScopeExit.h"
19 #ifdef MOZ_X11
20 # include <X11/Xlib.h> // for Window, Display, Visual, etc.
21 # include "X11UndefineNone.h"
22 #endif
24 class nsWindow;
26 namespace mozilla {
27 namespace widget {
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 {
35 public:
36 WindowSurfaceProvider();
37 ~WindowSurfaceProvider() = default;
39 /**
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.
45 #ifdef MOZ_WAYLAND
46 void Initialize(RefPtr<nsWindow> aWidget);
47 #endif
48 #ifdef MOZ_X11
49 void Initialize(Window aWindow, Visual* aVisual, int aDepth, bool aIsShaped);
50 #endif
52 /**
53 * Releases any surfaces created by this provider.
54 * This is used by GtkCompositorWidget to get rid
55 * of resources.
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);
65 private:
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;
81 #ifdef MOZ_WAYLAND
82 RefPtr<nsWindow> mWidget;
83 #endif
84 #ifdef MOZ_X11
85 bool mIsShaped;
86 int mXDepth;
87 Window mXWindow;
88 Visual* mXVisual;
89 #endif
92 } // namespace widget
93 } // namespace mozilla
95 #endif // _MOZILLA_WIDGET_GTK_WINDOW_SURFACE_PROVIDER_H