-
Notifications
You must be signed in to change notification settings - Fork 4
/
webxr-linux.patch
334 lines (308 loc) · 12.4 KB
/
webxr-linux.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
diff --git a/gfx/gl/SharedSurfaceGL.cpp b/gfx/gl/SharedSurfaceGL.cpp
--- a/gfx/gl/SharedSurfaceGL.cpp
+++ b/gfx/gl/SharedSurfaceGL.cpp
@@ -6,7 +6,9 @@
#include "SharedSurfaceGL.h"
#include "GLBlitHelper.h"
+#include "GLConsts.h"
#include "GLContext.h"
+#include "GLContextEGL.h"
#include "GLReadTexImageHelper.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/layers/TextureForwarder.h"
@@ -16,6 +18,8 @@ namespace mozilla {
namespace gl {
/*static*/
+uint8_t* SharedSurface_Basic::pixelsBuffer = nullptr;
+
UniquePtr<SharedSurface_Basic> SharedSurface_Basic::Create(
const SharedSurfaceDesc& desc) {
auto fb = MozFramebuffer::Create(desc.gl, desc.size, 0, false);
@@ -29,7 +33,25 @@ SharedSurface_Basic::SharedSurface_Basic
: SharedSurface(desc, std::move(fb)) {}
Maybe<layers::SurfaceDescriptor> SharedSurface_Basic::ToSurfaceDescriptor() {
- return Nothing();
+ int width = mFb->mSize.width;
+ int height = mFb->mSize.height;
+ if (!pixelsBuffer) {
+ // Allocate the pixels buffer once.
+ pixelsBuffer = (uint8_t*)malloc(width * height * 4);
+ }
+
+ // Read the pixels from the frame buffer.
+ mDesc.gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mFb->mFB);
+ mDesc.gl->fReadPixels(0, 0, width, height, LOCAL_GL_RGBA,
+ LOCAL_GL_UNSIGNED_BYTE, pixelsBuffer);
+
+ // HACK: pass along the pointer to the pixelsBuffer in the 'fence' field.
+ return Some(layers::SurfaceDescriptorSharedGLTexture(
+ -1,
+ -1,
+ (uintptr_t)pixelsBuffer,
+ mFb->mSize,
+ true));
}
////////////////////////////////////////////////////////////////////////
diff --git a/gfx/gl/SharedSurfaceGL.h b/gfx/gl/SharedSurfaceGL.h
--- a/gfx/gl/SharedSurfaceGL.h
+++ b/gfx/gl/SharedSurfaceGL.h
@@ -19,6 +19,10 @@ class SharedSurface_Basic final : public
static UniquePtr<SharedSurface_Basic> Create(const SharedSurfaceDesc&);
private:
+ // HACK: single static buffer for storing the pixel data.
+ // Image is uploaded and submitted to the compositor in OpenVRSession.
+ static uint8_t* pixelsBuffer;
+
SharedSurface_Basic(const SharedSurfaceDesc& desc,
UniquePtr<MozFramebuffer>&& fb);
diff --git a/gfx/vr/VRManager.cpp b/gfx/vr/VRManager.cpp
--- a/gfx/vr/VRManager.cpp
+++ b/gfx/vr/VRManager.cpp
@@ -1378,7 +1378,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 =
@@ -1426,6 +1427,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::TSurfaceDescriptorSharedGLTexture: {
+ const SurfaceDescriptorSharedGLTexture& desc =
+ aTexture.get_SurfaceDescriptorSharedGLTexture();
+ layer.textureType = VRLayerTextureType::LayerTextureType_SharedGLTexture;
+ // HACK: Retrieve the pointer to the pixel data from the fence field.
+ layer.textureHandle = (void*)desc.fence();
+ layer.textureSize.width = desc.size().width;
+ layer.textureSize.height = desc.size().height;
+ } break;
# endif
default: {
MOZ_ASSERT(false);
@@ -1488,7 +1499,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;
}
}
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
@@ -451,7 +451,8 @@ enum class VRLayerTextureType : uint16_t
LayerTextureType_None = 0,
LayerTextureType_D3D10SurfaceDescriptor = 1,
LayerTextureType_MacIOSurface = 2,
- LayerTextureType_GeckoSurfaceTexture = 3
+ LayerTextureType_GeckoSurfaceTexture = 3,
+ LayerTextureType_SharedGLTexture = 4
};
struct VRLayer_2D_Content {
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
@@ -497,7 +497,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
@@ -18,6 +18,8 @@
# include "mozilla/gfx/DeviceManagerDx.h"
#elif defined(XP_MACOSX)
# include "mozilla/gfx/MacIOSurface.h"
+#elif defined(XP_LINUX)
+# include "GLContextProvider.h"
#endif
#if !defined(XP_WIN)
@@ -1284,6 +1286,14 @@ 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) {
+ mTextureSize = aLayer.textureSize;
+ return SubmitFrame(aTexture, ::vr::ETextureType::TextureType_OpenGL,
+ aLayer.leftEyeRect, aLayer.rightEyeRect);
+}
#endif
bool OpenVRSession::SubmitFrame(const VRLayerTextureHandle& aTextureHandle,
@@ -1303,32 +1313,46 @@ bool OpenVRSession::SubmitFrame(const VR
CFTypeRefPtr<IOSurfaceRef> ioSurface = surf->GetIOSurfaceRef();
tex.handle = (void*)ioSurface.get();
-#else
- tex.handle = aTextureHandle;
#endif
+ tex.eColorSpace = ::vr::EColorSpace::ColorSpace_Gamma;
tex.eType = aTextureType;
- tex.eColorSpace = ::vr::EColorSpace::ColorSpace_Auto;
+
+ if (!mGLContext) {
+ // Create a new GLX context for creating textures for the compositor.
+ nsCString discardFailureId;
+ mGLContext = gl::GLContextProviderGLX::CreateHeadless({}, &discardFailureId);
+ }
+
+ if (mTempTexture == 0) {
+ // Create texture to upload pixel data to.
+ mGLContext->fGenTextures(1, &mTempTexture);
+ }
+ mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTempTexture);
+ mGLContext->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_RGBA8,
+ mTextureSize.width, mTextureSize.height, 0,
+ LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, (void*)aTextureHandle);
+ tex.handle = (void*)mTempTexture;
::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
@@ -16,6 +16,8 @@
#if defined(XP_WIN)
# include <d3d11_1.h>
+#elif defined(XP_LINUX)
+# include "GLContext.h"
#endif
class nsITimer;
@@ -58,6 +60,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:
@@ -73,6 +78,12 @@ class OpenVRSession : public VRSession {
bool mIsWindowsMR;
TimeStamp mLastHapticUpdate;
+#if defined(XP_LINUX)
+ RefPtr<gl::GLContext> mGLContext;
+ GLuint mTempTexture = 0;
+ IntSize_POD mTextureSize;
+#endif
+
static void HapticTimerCallback(nsITimer* aTimer, void* aClosure);
bool InitState(mozilla::gfx::VRSystemState& aSystemState);
void UpdateStageParameters(mozilla::gfx::VRDisplayState& aState);
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
@@ -148,6 +148,13 @@ bool VRSession::SubmitFrame(
return SubmitFrame(aLayer, aLayer.textureHandle);
}
+#elif defined(XP_LINUX)
+
+ if (aLayer.textureType ==
+ VRLayerTextureType::LayerTextureType_SharedGLTexture) {
+ return SubmitFrame(aLayer, aLayer.textureHandle);
+ }
+
#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
@@ -80,7 +80,7 @@ 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