Bug 1751217 Part 3: Make HDR-capable macOS screens report 30 pixelDepth. r=mstange
[gecko.git] / widget / gtk / WindowSurfaceWaylandMultiBuffer.h
blob3e26a1d5b1ffc41955fbb0554ddaa1c2604e3cf9
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"
13 #include "nsTArray.h"
14 #include "nsWaylandDisplay.h"
15 #include "nsWindow.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 {
26 public:
27 explicit WindowSurfaceWaylandMB(RefPtr<nsWindow> aWindow);
28 ~WindowSurfaceWaylandMB() = default;
30 // Lock() / Commit() are called by gecko when Firefox
31 // wants to display something. Lock() returns a DrawTarget
32 // where gecko paints. When gecko is done it calls Commit()
33 // and we try to send the DrawTarget (backed by wl_buffer)
34 // to wayland compositor.
36 // If we fail (wayland compositor is busy,
37 // wl_surface is not created yet) we queue the painting
38 // and we send it to wayland compositor in FrameCallbackHandler()/
39 // FlushPendingCommits().
40 already_AddRefed<DrawTarget> Lock(
41 const LayoutDeviceIntRegion& aInvalidRegion) override;
42 void Commit(const LayoutDeviceIntRegion& aInvalidRegion) final;
44 private:
45 void Commit(const MutexAutoLock& aProofOfLock,
46 const LayoutDeviceIntRegion& aInvalidRegion);
47 RefPtr<WaylandBufferSHM> ObtainBufferFromPool(
48 const MutexAutoLock& aProofOfLock, const LayoutDeviceIntSize& aSize);
49 void ReturnBufferToPool(const MutexAutoLock& aProofOfLock,
50 const RefPtr<WaylandBufferSHM>& aBuffer);
51 void EnforcePoolSizeLimit(const MutexAutoLock& aProofOfLock);
52 void CollectPendingSurfaces(const MutexAutoLock& aProofOfLock);
53 void HandlePartialUpdate(const MutexAutoLock& aProofOfLock,
54 const LayoutDeviceIntRegion& aInvalidRegion);
55 void IncrementBufferAge(const MutexAutoLock& aProofOfLock);
57 mozilla::Mutex mSurfaceLock MOZ_UNANNOTATED;
59 RefPtr<nsWindow> mWindow;
60 LayoutDeviceIntSize mMozContainerSize;
62 RefPtr<WaylandBufferSHM> mInProgressBuffer;
63 RefPtr<WaylandBufferSHM> mFrontBuffer;
64 LayoutDeviceIntRegion mFrontBufferInvalidRegion;
66 // buffer pool
67 nsTArray<RefPtr<WaylandBufferSHM>> mInUseBuffers;
68 nsTArray<RefPtr<WaylandBufferSHM>> mPendingBuffers;
69 nsTArray<RefPtr<WaylandBufferSHM>> mAvailableBuffers;
71 // delayed commits
72 bool mFrameInProcess;
73 bool mCallbackRequested;
76 } // namespace mozilla::widget
78 #endif // _MOZILLA_WIDGET_GTK_WINDOW_SURFACE_WAYLAND_MULTI_BUFFER_H