Bug 1883287 - Don't wait for the hidden window to be created on Linux to load the...
[gecko.git] / gfx / layers / NativeLayerWayland.h
blob0c45adc3119d485d51e649dd45548c93a31b6a64
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_layers_NativeLayerWayland_h
7 #define mozilla_layers_NativeLayerWayland_h
9 #include <deque>
10 #include <unordered_map>
12 #include "mozilla/Mutex.h"
13 #include "mozilla/layers/NativeLayer.h"
14 #include "mozilla/layers/SurfacePoolWayland.h"
15 #include "mozilla/widget/MozContainerWayland.h"
16 #include "nsRegion.h"
17 #include "nsTArray.h"
19 namespace mozilla::layers {
21 typedef void (*CallbackFunc)(void* aData, uint32_t aTime);
23 class CallbackMultiplexHelper final {
24 public:
25 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CallbackMultiplexHelper);
27 explicit CallbackMultiplexHelper(CallbackFunc aCallbackFunc,
28 void* aCallbackData);
30 void Callback(uint32_t aTime);
31 bool IsActive() { return mActive; }
33 private:
34 ~CallbackMultiplexHelper() = default;
36 void RunCallback(uint32_t aTime);
38 bool mActive = true;
39 CallbackFunc mCallbackFunc = nullptr;
40 void* mCallbackData = nullptr;
43 class NativeLayerRootWayland final : public NativeLayerRoot {
44 public:
45 static already_AddRefed<NativeLayerRootWayland> CreateForMozContainer(
46 MozContainer* aContainer);
48 virtual NativeLayerRootWayland* AsNativeLayerRootWayland() override {
49 return this;
52 // Overridden methods
53 already_AddRefed<NativeLayer> CreateLayer(
54 const gfx::IntSize& aSize, bool aIsOpaque,
55 SurfacePoolHandle* aSurfacePoolHandle) override;
56 already_AddRefed<NativeLayer> CreateLayerForExternalTexture(
57 bool aIsOpaque) override;
59 void AppendLayer(NativeLayer* aLayer) override;
60 void RemoveLayer(NativeLayer* aLayer) override;
61 void SetLayers(const nsTArray<RefPtr<NativeLayer>>& aLayers) override;
63 void PrepareForCommit() override { mFrameInProcess = true; };
64 bool CommitToScreen() override;
66 void UpdateLayersOnMainThread();
67 void AfterFrameClockAfterPaint();
68 void RequestFrameCallback(CallbackFunc aCallbackFunc, void* aCallbackData);
70 private:
71 explicit NativeLayerRootWayland(MozContainer* aContainer);
72 ~NativeLayerRootWayland();
74 bool CommitToScreen(const MutexAutoLock& aProofOfLock);
76 Mutex mMutex MOZ_UNANNOTATED;
78 MozContainer* mContainer = nullptr;
79 wl_surface* mWlSurface = nullptr;
80 RefPtr<widget::WaylandBufferSHM> mShmBuffer;
82 nsTArray<RefPtr<NativeLayerWayland>> mSublayers;
83 nsTArray<RefPtr<NativeLayerWayland>> mOldSublayers;
84 nsTArray<RefPtr<NativeLayerWayland>> mSublayersOnMainThread;
85 bool mNewLayers = false;
87 bool mFrameInProcess = false;
88 bool mCallbackRequested = false;
90 gulong mGdkAfterPaintId = 0;
91 RefPtr<CallbackMultiplexHelper> mCallbackMultiplexHelper;
94 class NativeLayerWayland final : public NativeLayer {
95 public:
96 virtual NativeLayerWayland* AsNativeLayerWayland() override { return this; }
98 // Overridden methods
99 gfx::IntSize GetSize() override;
100 void SetPosition(const gfx::IntPoint& aPosition) override;
101 gfx::IntPoint GetPosition() override;
102 void SetTransform(const gfx::Matrix4x4& aTransform) override;
103 gfx::Matrix4x4 GetTransform() override;
104 gfx::IntRect GetRect() override;
105 void SetSamplingFilter(gfx::SamplingFilter aSamplingFilter) override;
106 RefPtr<gfx::DrawTarget> NextSurfaceAsDrawTarget(
107 const gfx::IntRect& aDisplayRect, const gfx::IntRegion& aUpdateRegion,
108 gfx::BackendType aBackendType) override;
109 Maybe<GLuint> NextSurfaceAsFramebuffer(const gfx::IntRect& aDisplayRect,
110 const gfx::IntRegion& aUpdateRegion,
111 bool aNeedsDepth) override;
112 void NotifySurfaceReady() override;
113 void DiscardBackbuffers() override;
114 bool IsOpaque() override;
115 void SetClipRect(const Maybe<gfx::IntRect>& aClipRect) override;
116 Maybe<gfx::IntRect> ClipRect() override;
117 gfx::IntRect CurrentSurfaceDisplayRect() override;
118 void SetSurfaceIsFlipped(bool aIsFlipped) override;
119 bool SurfaceIsFlipped() override;
121 void AttachExternalImage(wr::RenderTextureHost* aExternalImage) override;
123 void Commit();
124 void Unmap();
125 void EnsureParentSurface(wl_surface* aParentSurface);
126 const RefPtr<SurfacePoolHandleWayland> GetSurfacePoolHandle() {
127 return mSurfacePoolHandle;
129 void SetBufferTransformFlipped(bool aFlippedX, bool aFlippedY);
130 void SetSubsurfacePosition(int aX, int aY);
131 void SetViewportSourceRect(const gfx::Rect aSourceRect);
132 void SetViewportDestinationSize(int aWidth, int aHeight);
134 void RequestFrameCallback(
135 const RefPtr<CallbackMultiplexHelper>& aMultiplexHelper);
136 static void FrameCallbackHandler(void* aData, wl_callback* aCallback,
137 uint32_t aTime);
139 private:
140 friend class NativeLayerRootWayland;
142 NativeLayerWayland(const gfx::IntSize& aSize, bool aIsOpaque,
143 SurfacePoolHandleWayland* aSurfacePoolHandle);
144 explicit NativeLayerWayland(bool aIsOpaque);
145 ~NativeLayerWayland() override;
147 void HandlePartialUpdate(const MutexAutoLock& aProofOfLock);
148 void FrameCallbackHandler(wl_callback* aCallback, uint32_t aTime);
150 Mutex mMutex MOZ_UNANNOTATED;
152 const RefPtr<SurfacePoolHandleWayland> mSurfacePoolHandle;
153 const gfx::IntSize mSize;
154 const bool mIsOpaque = false;
155 gfx::IntPoint mPosition;
156 gfx::Matrix4x4 mTransform;
157 gfx::IntRect mDisplayRect;
158 gfx::IntRegion mDirtyRegion;
159 Maybe<gfx::IntRect> mClipRect;
160 gfx::SamplingFilter mSamplingFilter = gfx::SamplingFilter::POINT;
161 bool mSurfaceIsFlipped = false;
162 bool mHasBufferAttached = false;
164 wl_surface* mWlSurface = nullptr;
165 wl_surface* mParentWlSurface = nullptr;
166 wl_subsurface* mWlSubsurface = nullptr;
167 wl_callback* mCallback = nullptr;
168 wp_viewport* mViewport = nullptr;
169 bool mBufferTransformFlippedX = false;
170 bool mBufferTransformFlippedY = false;
171 gfx::IntPoint mSubsurfacePosition = gfx::IntPoint(0, 0);
172 gfx::Rect mViewportSourceRect = gfx::Rect(-1, -1, -1, -1);
173 gfx::IntSize mViewportDestinationSize = gfx::IntSize(-1, -1);
174 nsTArray<RefPtr<CallbackMultiplexHelper>> mCallbackMultiplexHelpers;
176 RefPtr<widget::WaylandBuffer> mInProgressBuffer;
177 RefPtr<widget::WaylandBuffer> mFrontBuffer;
180 } // namespace mozilla::layers
182 #endif // mozilla_layers_NativeLayerWayland_h