mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 23:23:33 +00:00
ab2f648351
This change is a continuation of Part 1 (Bug 1570128), where the 2D content rendered by Firefox for Firefox Reality on Desktop is marshalled through VRHost so that it can be presented in a VR environment. A new class, FxrOutputHandler, is created to manage creating a sharable texture, sharing it through VRShMem, and updating it when content updates. This class updates content with both WebRender and conventional rendering output. This initial iteration of FxrOutputHandler does not have synchronization between reading and writing this shared texture across processes. A subsequent fix (Bug 1581881) is pending, which will reuse WebVR code to manage writing to and reading from a pool of textures. This also presents issues with rendering protected media, so an additional class, FxrWindowManager, is created to manage all windows created for Firefox Reality on Desktop so that it can inform whether or not protected media can be presented. The automated manual tests in vrhosttest.cpp now show the real shared texture handle rather than a fake value, which shows that marshaling succeeded. Differential Revision: https://phabricator.services.mozilla.com/D46179 --HG-- extra : moz-landing-system : lando
96 lines
3.3 KiB
C++
96 lines
3.3 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "FxROutputHandler.h"
|
|
#include "mozilla/Assertions.h"
|
|
#include "moz_external_vr.h"
|
|
#include "VRShMem.h"
|
|
|
|
// TryInitialize is responsible for associating this output handler with the
|
|
// calling window's swapchain for subsequent updates. This also creates a
|
|
// texture that can be shared across processes and updates VRShMem with the
|
|
// shared texture handle.
|
|
// See nsFxrCommandLineHandler::Handle for more information about the
|
|
// bootstrap process.
|
|
bool FxROutputHandler::TryInitialize(IDXGISwapChain* aSwapChain,
|
|
ID3D11Device* aDevice) {
|
|
if (mSwapChain == nullptr) {
|
|
RefPtr<ID3D11Texture2D> texOrig = nullptr;
|
|
HRESULT hr =
|
|
aSwapChain->GetBuffer(0, IID_ID3D11Texture2D, getter_AddRefs(texOrig));
|
|
if (hr != S_OK) {
|
|
return false;
|
|
}
|
|
|
|
// Create shareable texture, which will be copied to
|
|
D3D11_TEXTURE2D_DESC descOrig = {0};
|
|
texOrig->GetDesc(&descOrig);
|
|
descOrig.MiscFlags |= D3D11_RESOURCE_MISC_SHARED;
|
|
hr = aDevice->CreateTexture2D(&descOrig, nullptr,
|
|
mTexCopy.StartAssignment());
|
|
if (hr != S_OK) {
|
|
return false;
|
|
}
|
|
|
|
// Now, share the texture to a handle that can be marshaled to another
|
|
// process
|
|
HANDLE hCopy = nullptr;
|
|
RefPtr<IDXGIResource> texResource;
|
|
hr = mTexCopy->QueryInterface(IID_IDXGIResource,
|
|
getter_AddRefs(texResource));
|
|
if (hr != S_OK) {
|
|
return false;
|
|
}
|
|
|
|
hr = texResource->GetSharedHandle(&hCopy);
|
|
if (hr != S_OK) {
|
|
return false;
|
|
}
|
|
|
|
// The texture is successfully created and shared, so cache a
|
|
// pointer to the swapchain to indicate this success.
|
|
mSwapChain = aSwapChain;
|
|
|
|
// Finally, marshal the shared texture handle via VRShMem
|
|
mozilla::gfx::VRShMem shmem(nullptr, true /*aRequiresMutex*/);
|
|
if (shmem.JoinShMem()) {
|
|
mozilla::gfx::VRWindowState windowState = {0};
|
|
shmem.PullWindowState(windowState);
|
|
|
|
// The CLH should have populated hwndFx first
|
|
MOZ_ASSERT(windowState.hwndFx != 0);
|
|
MOZ_ASSERT(windowState.textureFx == nullptr);
|
|
|
|
windowState.textureFx = (HANDLE)hCopy;
|
|
|
|
shmem.PushWindowState(windowState);
|
|
shmem.LeaveShMem();
|
|
|
|
// Notify the waiting host process that the data is now available
|
|
HANDLE hSignal = ::OpenEventA(EVENT_ALL_ACCESS, // dwDesiredAccess
|
|
FALSE, // bInheritHandle
|
|
windowState.signalName // lpName
|
|
);
|
|
::SetEvent(hSignal);
|
|
::CloseHandle(hSignal);
|
|
}
|
|
} else {
|
|
MOZ_ASSERT(aSwapChain == mSwapChain);
|
|
}
|
|
|
|
return mSwapChain != nullptr && aSwapChain == mSwapChain;
|
|
}
|
|
|
|
// Update the contents of the shared texture.
|
|
void FxROutputHandler::UpdateOutput(ID3D11DeviceContext* aCtx) {
|
|
MOZ_ASSERT(mSwapChain != nullptr);
|
|
|
|
ID3D11Texture2D* texOrig = nullptr;
|
|
HRESULT hr = mSwapChain->GetBuffer(0, IID_PPV_ARGS(&texOrig));
|
|
if (hr == S_OK) {
|
|
aCtx->CopyResource(mTexCopy, texOrig);
|
|
texOrig->Release();
|
|
}
|
|
} |