Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit afb76f5

Browse files
committed
Bug 1570123 - Export Input functions from vrhost r=kip
This change adds a new export, SendUIMessageToVRWindow, from vrhost.dll that allows the caller to forward a subset of UI messages to the VR window in Firefox. Differential Revision: https://phabricator.services.mozilla.com/D40828 --HG-- extra : moz-landing-system : lando
1 parent 53d4ac9 commit afb76f5

6 files changed

Lines changed: 67 additions & 15 deletions

File tree

browser/fxr/content/fxrui.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,22 @@
1313
font-family: sans-serif;
1414
font-size: xx-large;
1515
width: 800px;
16-
height: 800px;
16+
height: 400px;
1717
}
1818

1919
div:hover {
2020
background-color: dodgerblue;
2121
}
2222
</style>
23+
<script>
24+
function clickedcheck() {
25+
document.getElementById('clicked').textContent = "Clicked on " + new Date();
26+
}
27+
</script>
2328
</head>
24-
<body>
29+
30+
<body onclick="clickedcheck()">
2531
<div>Hello World!</div>
32+
<div id="clicked"></div>
2633
</body>
2734
</html>

gfx/vr/VRShMem.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,7 @@ void VRShMem::CloseShMem() {
308308
// Callers to JoinShMem should call LeaveShMem for cleanup
309309
bool VRShMem::JoinShMem() {
310310
#if defined(XP_WIN)
311-
// Adding `!XRE_IsParentProcess()` to avoid Win 7 32-bit WebVR tests
312-
// to OpenMutex when there is no GPU process to create
313-
// VRSystemManagerExternal and its mutex.
314311
if (!mMutex && mRequiresMutex) {
315-
# ifdef MOZILLA_INTERNAL_API
316-
MOZ_ASSERT(!XRE_IsParentProcess());
317-
# endif
318-
319312
// Check that there are no errors before making system calls
320313
MOZ_ASSERT(GetLastError() == 0);
321314

gfx/vr/vrhost/vrhost.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ LIBRARY vrhost.dll
1010
EXPORTS
1111
CreateVRWindow PRIVATE
1212
CloseVRWindow PRIVATE
13+
SendUIMessageToVRWindow PRIVATE

gfx/vr/vrhost/vrhostapi.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,36 @@ void CreateVRWindow(char* firefoxFolderPath, char* firefoxProfilePath,
177177

178178
// Sends a message to the VR window to close.
179179
void CloseVRWindow(uint32_t nVRWindowID, bool waitForTerminate) {
180-
::SendMessage(VRWindowManager::GetManager()->GetHWND(nVRWindowID), WM_CLOSE,
181-
0, 0);
180+
HWND hwnd = VRWindowManager::GetManager()->GetHWND(nVRWindowID);
181+
if (hwnd != nullptr) {
182+
::SendMessage(hwnd, WM_CLOSE, 0, 0);
183+
184+
if (waitForTerminate) {
185+
// Wait for Firefox main process to exit
186+
::WaitForSingleObject(VRWindowManager::GetManager()->GetProc(nVRWindowID),
187+
INFINITE);
188+
}
189+
}
190+
}
182191

183-
if (waitForTerminate) {
184-
// Wait for Firefox main process to exit
185-
::WaitForSingleObject(VRWindowManager::GetManager()->GetProc(nVRWindowID),
186-
INFINITE);
192+
// Forwards Win32 UI window messages to the Firefox widget/window associated
193+
// with nVRWindowID. Note that not all message type is supported (only those
194+
// allowed in the switch block below).
195+
void SendUIMessageToVRWindow(uint32_t nVRWindowID, uint32_t msg,
196+
uint64_t wparam, uint64_t lparam) {
197+
HWND hwnd = VRWindowManager::GetManager()->GetHWND(nVRWindowID);
198+
if (hwnd != nullptr) {
199+
switch (msg) {
200+
case WM_MOUSEMOVE:
201+
case WM_LBUTTONDOWN:
202+
case WM_LBUTTONUP:
203+
case WM_MOUSEWHEEL:
204+
case WM_CHAR:
205+
::PostMessage(hwnd, msg, wparam, lparam);
206+
break;
207+
208+
default:
209+
break;
210+
}
187211
}
188212
}

gfx/vr/vrhost/vrhostex.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ typedef void (*PFN_CREATEVRWINDOW)(char* firefoxFolderPath,
2222
uint32_t* height);
2323

2424
typedef void (*PFN_CLOSEVRWINDOW)(uint32_t nVRWindowID, bool waitForTerminate);
25+
26+
typedef void (*PFN_SENDUIMSG)(uint32_t nVRWindowID, uint32_t msg,
27+
uint64_t wparam, uint64_t lparam);

gfx/vr/vrhost/vrhosttest.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ void TestCreateVRWindow() {
232232
PFN_CLOSEVRWINDOW fnClose =
233233
(PFN_CLOSEVRWINDOW)::GetProcAddress(hVRHost, "CloseVRWindow");
234234

235+
PFN_SENDUIMSG fnSendMsg =
236+
(PFN_SENDUIMSG)::GetProcAddress(hVRHost, "SendUIMessageToVRWindow");
237+
235238
// Create the VR Window and store data from creation
236239
char currentDir[MAX_PATH] = {0};
237240
char currentDirProfile[MAX_PATH] = {0};
@@ -251,6 +254,27 @@ void TestCreateVRWindow() {
251254
fnCreate(currentDir, currentDirProfile, 0, 100, 200, &windowId, &hTex,
252255
&width, &height);
253256

257+
// Wait for Fx to finish launch
258+
::Sleep(5000);
259+
260+
printf(
261+
"Now, should see window contents turn from orange to blue with onclick "
262+
"event output...\n");
263+
264+
// Simulate a click, then moving the mouse across the screen
265+
POINT pt;
266+
pt.x = 200;
267+
pt.y = 200;
268+
fnSendMsg(windowId, WM_LBUTTONDOWN, 0, POINTTOPOINTS(pt));
269+
fnSendMsg(windowId, WM_LBUTTONUP, 0, POINTTOPOINTS(pt));
270+
for (int i = 0; i < 100; ++i) {
271+
pt.x++;
272+
fnSendMsg(windowId, WM_MOUSEMOVE, 0, POINTTOPOINTS(pt));
273+
::Sleep(5);
274+
}
275+
276+
::Sleep(2000);
277+
254278
// Close the Firefox VR Window
255279
fnClose(windowId, true);
256280

0 commit comments

Comments
 (0)