-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebxr-linux-dmabuf.patch
369 lines (345 loc) · 13.5 KB
/
webxr-linux-dmabuf.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
diff --git a/gfx/vr/VRManager.cpp b/gfx/vr/VRManager.cpp
--- a/gfx/vr/VRManager.cpp
+++ b/gfx/vr/VRManager.cpp
@@ -46,6 +46,8 @@
# include "GeckoVRManager.h"
# include "mozilla/java/GeckoSurfaceTextureWrappers.h"
# include "mozilla/layers/CompositorThread.h"
+#elif defined(XP_LINUX)
+# include "DMABufSurface.h"
#endif // defined(MOZ_WIDGET_ANDROID)
using namespace mozilla;
@@ -1378,7 +1380,8 @@ bool VRManager::SubmitFrame(const layers
if (mState != VRManagerState::Active) {
return false;
}
-#if defined(XP_WIN) || defined(XP_MACOSX) || defined(MOZ_WIDGET_ANDROID)
+#if defined(XP_WIN) || defined(XP_MACOSX) || defined(MOZ_WIDGET_ANDROID) || \
+ defined(XP_LINUX)
MOZ_ASSERT(mBrowserState.layerState[0].type ==
VRLayerType::LayerType_Stereo_Immersive);
VRLayer_Stereo_Immersive& layer =
@@ -1427,6 +1430,16 @@ bool VRManager::SubmitFrame(const layers
layer.textureSize.width = desc.size().width;
layer.textureSize.height = desc.size().height;
} break;
+# elif defined(XP_LINUX)
+ case SurfaceDescriptor::TSurfaceDescriptorDMABuf: {
+ const SurfaceDescriptorDMABuf& desc =
+ aTexture.get_SurfaceDescriptorDMABuf();
+ layer.textureType = VRLayerTextureType::LayerTextureType_DMABuf;
+ DMABufSurface* surface = DMABufSurface::CreateDMABufSurface(desc).take();
+ layer.textureHandle = (void*)surface;
+ layer.textureSize.width = surface->GetWidth();
+ layer.textureSize.height = surface->GetHeight();
+ } break;
# endif
default: {
MOZ_ASSERT(false);
@@ -1489,7 +1502,7 @@ void VRManager::SubmitFrameInternal(cons
mCurrentSubmitTask = nullptr;
}
-#if defined(XP_WIN) || defined(XP_MACOSX)
+#if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_LINUX)
/**
* Trigger the next VSync immediately after we are successfully
diff --git a/gfx/vr/VRShMem.cpp b/gfx/vr/VRShMem.cpp
--- a/gfx/vr/VRShMem.cpp
+++ b/gfx/vr/VRShMem.cpp
@@ -247,12 +247,20 @@ void VRShMem::CreateShMemForAndroid() {
void VRShMem::ClearShMem() {
if (mExternalShmem != nullptr) {
+ // Note: If the generation is reset, the communication will fail.
+ // The other instance of VRShMem would still think to have read
+ // generation 1, meaning the first (important) update is ignored.
+ long generation = mExternalShmem->geckoGenerationA;
#ifdef MOZILLA_INTERNAL_API
// VRExternalShmem is asserted to be POD
mExternalShmem->Clear();
#else
memset((void*)mExternalShmem, 0, sizeof(VRExternalShmem));
#endif
+
+ // Continue counting generations where we left off.
+ mExternalShmem->geckoGenerationA = mExternalShmem->geckoGenerationB =
+ generation + 1;
}
}
@@ -418,11 +426,12 @@ void VRShMem::PushBrowserState(VRBrowser
status = lock.GetStatus();
# endif // defined(XP_WIN)
- if (status) {
+ if (status && pthread_mutex_lock((pthread_mutex_t*)&(mExternalShmem->geckoMutex)) == 0) {
mExternalShmem->geckoGenerationA = mExternalShmem->geckoGenerationA + 1;
memcpy((void*)&(mExternalShmem->geckoState), (void*)&aBrowserState,
sizeof(VRBrowserState));
mExternalShmem->geckoGenerationB = mExternalShmem->geckoGenerationB + 1;
+ pthread_mutex_unlock((pthread_mutex_t*)&(mExternalShmem->geckoMutex));
}
#endif // defined(MOZ_WIDGET_ANDROID)
}
@@ -462,17 +471,15 @@ void VRShMem::PullBrowserState(mozilla::
}
# endif // defined(XP_WIN)
if (status) {
- VRExternalShmem tmp;
if (mExternalShmem->geckoGenerationA != mBrowserGeneration) {
// TODO - (void *) cast removes volatile semantics.
// The memcpy is not likely to be optimized out, but is theoretically
// possible. Suggest refactoring to either explicitly enforce memory
// order or to use locks.
- memcpy(&tmp, (void*)mExternalShmem, sizeof(VRExternalShmem));
- if (tmp.geckoGenerationA == tmp.geckoGenerationB &&
- tmp.geckoGenerationA != 0) {
- memcpy(&aState, &tmp.geckoState, sizeof(VRBrowserState));
- mBrowserGeneration = tmp.geckoGenerationA;
+ if (pthread_mutex_lock((pthread_mutex_t*)&(mExternalShmem->geckoMutex)) == 0) {
+ memcpy(&aState, (void*)&(mExternalShmem->geckoState), sizeof(VRBrowserState));
+ mBrowserGeneration = mExternalShmem->geckoGenerationA;
+ pthread_mutex_unlock((pthread_mutex_t*)&(mExternalShmem->geckoMutex));
}
}
}
diff --git a/gfx/vr/external_api/moz_external_vr.h b/gfx/vr/external_api/moz_external_vr.h
--- a/gfx/vr/external_api/moz_external_vr.h
+++ b/gfx/vr/external_api/moz_external_vr.h
@@ -452,7 +452,8 @@ enum class VRLayerTextureType : uint16_t
LayerTextureType_None = 0,
LayerTextureType_D3D10SurfaceDescriptor = 1,
LayerTextureType_MacIOSurface = 2,
- LayerTextureType_GeckoSurfaceTexture = 3
+ LayerTextureType_GeckoSurfaceTexture = 3,
+ LayerTextureType_DMABuf = 4
};
struct VRLayer_2D_Content {
@@ -619,6 +620,7 @@ struct VRExternalShmem {
pthread_cond_t servoCond;
#else
int64_t generationA;
+ pthread_mutex_t geckoMutex;
#endif // defined(__ANDROID__)
VRSystemState state;
#if !defined(__ANDROID__)
diff --git a/gfx/vr/ipc/VRLayerChild.cpp b/gfx/vr/ipc/VRLayerChild.cpp
--- a/gfx/vr/ipc/VRLayerChild.cpp
+++ b/gfx/vr/ipc/VRLayerChild.cpp
@@ -92,6 +92,8 @@ void VRLayerChild::SubmitFrame(const VRD
if (kIsAndroid && StaticPrefs::webgl_enable_surface_texture()) {
texType = layers::TextureType::AndroidNativeWindow;
}
+ // HACK: always pick DMABUF
+ texType = layers::TextureType::DMABUF;
webgl->Present(mFramebuffer, texType, true);
mThisFrameTextureDesc = webgl->GetFrontBuffer(mFramebuffer, true);
diff --git a/gfx/vr/moz.build b/gfx/vr/moz.build
--- a/gfx/vr/moz.build
+++ b/gfx/vr/moz.build
@@ -71,6 +71,9 @@ else:
"VRServiceHost.cpp",
]
+if CONFIG["OS_TARGET"] == "Linux":
+ LOCAL_INCLUDES += ["/widget/gtk"]
+
IPDL_SOURCES = [
"ipc/PVR.ipdl",
"ipc/PVRGPU.ipdl",
diff --git a/gfx/vr/service/OSVRSession.cpp b/gfx/vr/service/OSVRSession.cpp
--- a/gfx/vr/service/OSVRSession.cpp
+++ b/gfx/vr/service/OSVRSession.cpp
@@ -496,7 +496,7 @@ bool OSVRSession::SubmitFrame(
return false;
// TODO Implement
}
-#elif defined(XP_MACOSX)
+#elif defined(XP_MACOSX) || defined(XP_LINUX)
bool OSVRSession::SubmitFrame(
const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
const VRLayerTextureHandle& aTexture) {
diff --git a/gfx/vr/service/OSVRSession.h b/gfx/vr/service/OSVRSession.h
--- a/gfx/vr/service/OSVRSession.h
+++ b/gfx/vr/service/OSVRSession.h
@@ -44,7 +44,7 @@ class OSVRSession : public VRSession {
#if defined(XP_WIN)
bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
ID3D11Texture2D* aTexture) override;
-#elif defined(XP_MACOSX)
+#elif defined(XP_MACOSX) || defined(XP_LINUX)
bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
const VRLayerTextureHandle& aTexture) override;
#endif
diff --git a/gfx/vr/service/OpenVRSession.cpp b/gfx/vr/service/OpenVRSession.cpp
--- a/gfx/vr/service/OpenVRSession.cpp
+++ b/gfx/vr/service/OpenVRSession.cpp
@@ -1273,6 +1273,13 @@ bool OpenVRSession::SubmitFrame(
return SubmitFrame(aTexture, ::vr::ETextureType::TextureType_IOSurface,
aLayer.leftEyeRect, aLayer.rightEyeRect);
}
+#elif defined(XP_LINUX)
+bool OpenVRSession::SubmitFrame(
+ const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
+ const VRLayerTextureHandle& aTexture) {
+ return SubmitFrame(aTexture, ::vr::ETextureType::TextureType_OpenGL,
+ aLayer.leftEyeRect, aLayer.rightEyeRect);
+}
#endif
bool OpenVRSession::SubmitFrame(const VRLayerTextureHandle& aTextureHandle,
@@ -1292,32 +1299,32 @@ bool OpenVRSession::SubmitFrame(const VR
CFTypeRefPtr<IOSurfaceRef> ioSurface = surf->GetIOSurfaceRef();
tex.handle = (void*)ioSurface.get();
-#else
+#endif
+ tex.eColorSpace = ::vr::EColorSpace::ColorSpace_Gamma;
+ tex.eType = aTextureType;
+
tex.handle = aTextureHandle;
-#endif
- tex.eType = aTextureType;
- tex.eColorSpace = ::vr::EColorSpace::ColorSpace_Auto;
::vr::VRTextureBounds_t bounds;
bounds.uMin = aLeftEyeRect.x;
- bounds.vMin = 1.0 - aLeftEyeRect.y;
+ bounds.vMin = 1.0 - (aLeftEyeRect.y + aLeftEyeRect.height);
bounds.uMax = aLeftEyeRect.x + aLeftEyeRect.width;
- bounds.vMax = 1.0 - (aLeftEyeRect.y + aLeftEyeRect.height);
+ bounds.vMax = 1.0 - aLeftEyeRect.y;
::vr::EVRCompositorError err;
err = mVRCompositor->Submit(::vr::EVREye::Eye_Left, &tex, &bounds);
if (err != ::vr::EVRCompositorError::VRCompositorError_None) {
- printf_stderr("OpenVR Compositor Submit() failed.\n");
+ printf_stderr("OpenVR Compositor Submit() failed: err=%d.\n", err);
}
bounds.uMin = aRightEyeRect.x;
- bounds.vMin = 1.0 - aRightEyeRect.y;
+ bounds.vMin = 1.0 - (aRightEyeRect.y + aRightEyeRect.height);
bounds.uMax = aRightEyeRect.x + aRightEyeRect.width;
- bounds.vMax = 1.0 - (aRightEyeRect.y + aRightEyeRect.height);
+ bounds.vMax = 1.0 - aRightEyeRect.y;
err = mVRCompositor->Submit(::vr::EVREye::Eye_Right, &tex, &bounds);
if (err != ::vr::EVRCompositorError::VRCompositorError_None) {
- printf_stderr("OpenVR Compositor Submit() failed.\n");
+ printf_stderr("OpenVR Compositor Submit() failed: err=%d\n", err);
}
mVRCompositor->PostPresentHandoff();
diff --git a/gfx/vr/service/OpenVRSession.h b/gfx/vr/service/OpenVRSession.h
--- a/gfx/vr/service/OpenVRSession.h
+++ b/gfx/vr/service/OpenVRSession.h
@@ -58,6 +58,9 @@ class OpenVRSession : public VRSession {
#elif defined(XP_MACOSX)
bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
const VRLayerTextureHandle& aTexture) override;
+#elif defined(XP_LINUX)
+ bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
+ const VRLayerTextureHandle& aTexture) override;
#endif
private:
diff --git a/gfx/vr/service/PuppetSession.cpp b/gfx/vr/service/PuppetSession.cpp
--- a/gfx/vr/service/PuppetSession.cpp
+++ b/gfx/vr/service/PuppetSession.cpp
@@ -89,7 +89,7 @@ bool PuppetSession::SubmitFrame(
ID3D11Texture2D* aTexture) {
return VRPuppetCommandBuffer::Get().SubmitFrame();
}
-#elif defined(XP_MACOSX)
+#elif defined(XP_MACOSX) || defined(XP_LINUX)
bool PuppetSession::SubmitFrame(
const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
const VRLayerTextureHandle& aTexture) {
diff --git a/gfx/vr/service/PuppetSession.h b/gfx/vr/service/PuppetSession.h
--- a/gfx/vr/service/PuppetSession.h
+++ b/gfx/vr/service/PuppetSession.h
@@ -41,7 +41,7 @@ class PuppetSession : public VRSession {
#if defined(XP_WIN)
bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
ID3D11Texture2D* aTexture) override;
-#elif defined(XP_MACOSX)
+#elif defined(XP_MACOSX) || defined(XP_LINUX)
bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
const VRLayerTextureHandle& aTexture) override;
#endif
diff --git a/gfx/vr/service/VRSession.cpp b/gfx/vr/service/VRSession.cpp
--- a/gfx/vr/service/VRSession.cpp
+++ b/gfx/vr/service/VRSession.cpp
@@ -14,6 +14,10 @@
# include <d3d11.h>
#endif // defined(XP_WIN)
+#if defined(XP_LINUX)
+# include "DMABufSurface.h"
+#endif
+
#if defined(MOZILLA_INTERNAL_API)
# if defined(XP_WIN)
# include "mozilla/gfx/Logging.h"
@@ -152,6 +156,30 @@ bool VRSession::SubmitFrame(
return SubmitFrame(aLayer, aLayer.textureHandle);
}
+#elif defined(XP_LINUX)
+
+ if (aLayer.textureType ==
+ VRLayerTextureType::LayerTextureType_DMABuf) {
+ if (!mGLContext) {
+ nsCString discard;
+ mGLContext = gl::GLContextProviderEGL::CreateHeadless({}, &discard);
+ }
+
+ if (!mGLContext || !mGLContext->MakeCurrent(true)) {
+ return false;
+ }
+
+ DMABufSurface* surface = (DMABufSurface*) aLayer.textureHandle;
+ surface->CreateTexture(mGLContext);
+
+ bool result = SubmitFrame(aLayer, (VRLayerTextureHandle) surface->GetTexture());
+
+ surface->ReleaseTextures();
+ surface->ReleaseSurface();
+
+ return result;
+ }
+
#endif
return false;
diff --git a/gfx/vr/service/VRSession.h b/gfx/vr/service/VRSession.h
--- a/gfx/vr/service/VRSession.h
+++ b/gfx/vr/service/VRSession.h
@@ -13,6 +13,9 @@
# include <d3d11_1.h>
#elif defined(XP_MACOSX)
class MacIOSurface;
+#elif defined(XP_LINUX)
+# include "GLContext.h"
+# include "GLContextProvider.h"
#endif
namespace mozilla {
@@ -80,10 +83,13 @@ class VRSession {
ID3D11DeviceContext1* mContext;
ID3DDeviceContextState* mDeviceContextState;
-#elif defined(XP_MACOSX)
+#elif defined(XP_MACOSX) || defined(XP_LINUX)
virtual bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
const VRLayerTextureHandle& aTexture) = 0;
#endif
+#if defined(XP_LINUX)
+ RefPtr<gl::GLContext> mGLContext;
+#endif
void SetControllerSelectionAndSqueezeFrameId(
VRControllerState& controllerState, uint64_t aFrameId);
};
diff --git a/gfx/vr/service/moz.build b/gfx/vr/service/moz.build
--- a/gfx/vr/service/moz.build
+++ b/gfx/vr/service/moz.build
@@ -35,6 +35,8 @@ if CONFIG["TARGET_OS"] in ("WINNT", "OSX
"openvr",
]
LOCAL_INCLUDES += ["/dom/base", "/gfx/layers/d3d11"]
+ if CONFIG["OS_TARGET"] == "Linux":
+ LOCAL_INCLUDES += ["/widget/gtk"]
# OpenVRSession includes MacIOSurface.h which includes Mac headers
# which define Size and Points types in the root namespace that
@@ -48,4 +50,8 @@ if CONFIG["TARGET_OS"] in ("WINNT", "OSX
"OpenVRViveMapper.cpp",
]
+if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":
+ CXXFLAGS += CONFIG["MOZ_GTK3_CFLAGS"]
+ CFLAGS += CONFIG["MOZ_GTK3_CFLAGS"]
+
FINAL_LIBRARY = "xul"