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_WAYLAND_MULTI_BUFFER_H
8 #define _MOZILLA_WIDGET_GTK_WINDOW_SURFACE_WAYLAND_MULTI_BUFFER_H
10 #include "mozilla/gfx/2D.h"
11 #include "mozilla/gfx/Types.h"
12 #include "mozilla/Mutex.h"
14 #include "nsWaylandDisplay.h"
16 #include "WaylandBuffer.h"
17 #include "WindowSurface.h"
19 namespace mozilla::widget
{
21 using gfx::DrawTarget
;
23 // WindowSurfaceWaylandMB is an abstraction for wl_surface
24 // and related management
25 class WindowSurfaceWaylandMB
: public WindowSurface
{
27 WindowSurfaceWaylandMB(RefPtr
<nsWindow
> aWindow
,
28 GtkCompositorWidget
* aCompositorWidget
);
29 ~WindowSurfaceWaylandMB() = default;
31 // Lock() / Commit() are called by gecko when Firefox
32 // wants to display something. Lock() returns a DrawTarget
33 // where gecko paints. When gecko is done it calls Commit()
34 // and we try to send the DrawTarget (backed by wl_buffer)
35 // to wayland compositor.
37 // If we fail (wayland compositor is busy,
38 // wl_surface is not created yet) we queue the painting
39 // and we send it to wayland compositor in FrameCallbackHandler()/
40 // FlushPendingCommits().
41 already_AddRefed
<DrawTarget
> Lock(
42 const LayoutDeviceIntRegion
& aInvalidRegion
) override
;
43 void Commit(const LayoutDeviceIntRegion
& aInvalidRegion
) final
;
46 void Commit(const MutexAutoLock
& aProofOfLock
,
47 const LayoutDeviceIntRegion
& aInvalidRegion
);
48 RefPtr
<WaylandBufferSHM
> ObtainBufferFromPool(
49 const MutexAutoLock
& aProofOfLock
, const LayoutDeviceIntSize
& aSize
);
50 void ReturnBufferToPool(const MutexAutoLock
& aProofOfLock
,
51 const RefPtr
<WaylandBufferSHM
>& aBuffer
);
52 void EnforcePoolSizeLimit(const MutexAutoLock
& aProofOfLock
);
53 void CollectPendingSurfaces(const MutexAutoLock
& aProofOfLock
);
54 void HandlePartialUpdate(const MutexAutoLock
& aProofOfLock
,
55 const LayoutDeviceIntRegion
& aInvalidRegion
);
56 void IncrementBufferAge(const MutexAutoLock
& aProofOfLock
);
57 // Return true if window size was updated.
58 bool MaybeUpdateWindowSize();
60 mozilla::Mutex mSurfaceLock MOZ_UNANNOTATED
;
62 RefPtr
<nsWindow
> mWindow
;
63 // WindowSurfaceWaylandMB is owned by GtkCompositorWidget so we can't
65 GtkCompositorWidget
* mCompositorWidget
;
66 LayoutDeviceIntSize mWindowSize
;
68 RefPtr
<WaylandBufferSHM
> mInProgressBuffer
;
69 RefPtr
<WaylandBufferSHM
> mFrontBuffer
;
70 LayoutDeviceIntRegion mFrontBufferInvalidRegion
;
73 nsTArray
<RefPtr
<WaylandBufferSHM
>> mInUseBuffers
;
74 nsTArray
<RefPtr
<WaylandBufferSHM
>> mPendingBuffers
;
75 nsTArray
<RefPtr
<WaylandBufferSHM
>> mAvailableBuffers
;
79 bool mCallbackRequested
;
82 } // namespace mozilla::widget
84 #endif // _MOZILLA_WIDGET_GTK_WINDOW_SURFACE_WAYLAND_MULTI_BUFFER_H