Skip to content

Commit

Permalink
Bug 1570123 - Export Input functions from vrhost r=kip
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thomasmo committed Aug 9, 2019
1 parent 7325443 commit b94e836
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 15 deletions.
11 changes: 9 additions & 2 deletions browser/fxr/content/fxrui.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@
font-family: sans-serif;
font-size: xx-large;
width: 800px;
height: 800px;
height: 400px;
}

div:hover {
background-color: dodgerblue;
}
</style>
<script>
function clickedcheck() {
document.getElementById('clicked').textContent = "Clicked on " + new Date();
}
</script>
</head>
<body>

<body onclick="clickedcheck()">
<div>Hello World!</div>
<div id="clicked"></div>
</body>
</html>
7 changes: 0 additions & 7 deletions gfx/vr/VRShMem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,7 @@ void VRShMem::CloseShMem() {
// Callers to JoinShMem should call LeaveShMem for cleanup
bool VRShMem::JoinShMem() {
#if defined(XP_WIN)
// Adding `!XRE_IsParentProcess()` to avoid Win 7 32-bit WebVR tests
// to OpenMutex when there is no GPU process to create
// VRSystemManagerExternal and its mutex.
if (!mMutex && mRequiresMutex) {
# ifdef MOZILLA_INTERNAL_API
MOZ_ASSERT(!XRE_IsParentProcess());
# endif

// Check that there are no errors before making system calls
MOZ_ASSERT(GetLastError() == 0);

Expand Down
1 change: 1 addition & 0 deletions gfx/vr/vrhost/vrhost.def
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ LIBRARY vrhost.dll
EXPORTS
CreateVRWindow PRIVATE
CloseVRWindow PRIVATE
SendUIMessageToVRWindow PRIVATE
36 changes: 30 additions & 6 deletions gfx/vr/vrhost/vrhostapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,36 @@ void CreateVRWindow(char* firefoxFolderPath, char* firefoxProfilePath,

// Sends a message to the VR window to close.
void CloseVRWindow(uint32_t nVRWindowID, bool waitForTerminate) {
::SendMessage(VRWindowManager::GetManager()->GetHWND(nVRWindowID), WM_CLOSE,
0, 0);
HWND hwnd = VRWindowManager::GetManager()->GetHWND(nVRWindowID);
if (hwnd != nullptr) {
::SendMessage(hwnd, WM_CLOSE, 0, 0);

if (waitForTerminate) {
// Wait for Firefox main process to exit
::WaitForSingleObject(VRWindowManager::GetManager()->GetProc(nVRWindowID),
INFINITE);
}
}
}

if (waitForTerminate) {
// Wait for Firefox main process to exit
::WaitForSingleObject(VRWindowManager::GetManager()->GetProc(nVRWindowID),
INFINITE);
// Forwards Win32 UI window messages to the Firefox widget/window associated
// with nVRWindowID. Note that not all message type is supported (only those
// allowed in the switch block below).
void SendUIMessageToVRWindow(uint32_t nVRWindowID, uint32_t msg,
uint64_t wparam, uint64_t lparam) {
HWND hwnd = VRWindowManager::GetManager()->GetHWND(nVRWindowID);
if (hwnd != nullptr) {
switch (msg) {
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MOUSEWHEEL:
case WM_CHAR:
::PostMessage(hwnd, msg, wparam, lparam);
break;

default:
break;
}
}
}
3 changes: 3 additions & 0 deletions gfx/vr/vrhost/vrhostex.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ typedef void (*PFN_CREATEVRWINDOW)(char* firefoxFolderPath,
uint32_t* height);

typedef void (*PFN_CLOSEVRWINDOW)(uint32_t nVRWindowID, bool waitForTerminate);

typedef void (*PFN_SENDUIMSG)(uint32_t nVRWindowID, uint32_t msg,
uint64_t wparam, uint64_t lparam);
24 changes: 24 additions & 0 deletions gfx/vr/vrhost/vrhosttest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ void TestCreateVRWindow() {
PFN_CLOSEVRWINDOW fnClose =
(PFN_CLOSEVRWINDOW)::GetProcAddress(hVRHost, "CloseVRWindow");

PFN_SENDUIMSG fnSendMsg =
(PFN_SENDUIMSG)::GetProcAddress(hVRHost, "SendUIMessageToVRWindow");

// Create the VR Window and store data from creation
char currentDir[MAX_PATH] = {0};
char currentDirProfile[MAX_PATH] = {0};
Expand All @@ -251,6 +254,27 @@ void TestCreateVRWindow() {
fnCreate(currentDir, currentDirProfile, 0, 100, 200, &windowId, &hTex,
&width, &height);

// Wait for Fx to finish launch
::Sleep(5000);

printf(
"Now, should see window contents turn from orange to blue with onclick "
"event output...\n");

// Simulate a click, then moving the mouse across the screen
POINT pt;
pt.x = 200;
pt.y = 200;
fnSendMsg(windowId, WM_LBUTTONDOWN, 0, POINTTOPOINTS(pt));
fnSendMsg(windowId, WM_LBUTTONUP, 0, POINTTOPOINTS(pt));
for (int i = 0; i < 100; ++i) {
pt.x++;
fnSendMsg(windowId, WM_MOUSEMOVE, 0, POINTTOPOINTS(pt));
::Sleep(5);
}

::Sleep(2000);

// Close the Firefox VR Window
fnClose(windowId, true);

Expand Down

0 comments on commit b94e836

Please sign in to comment.