2018-01-19 05:01:04 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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 "RenderCompositorANGLE.h"
|
|
|
|
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLContextEGL.h"
|
|
|
|
#include "GLContextProvider.h"
|
|
|
|
#include "mozilla/gfx/DeviceManagerDx.h"
|
2018-11-05 12:58:37 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.h"
|
2018-03-29 05:23:31 +03:00
|
|
|
#include "mozilla/gfx/Logging.h"
|
2018-01-19 05:01:04 +03:00
|
|
|
#include "mozilla/layers/HelpersD3D11.h"
|
|
|
|
#include "mozilla/layers/SyncObject.h"
|
2019-09-19 21:15:11 +03:00
|
|
|
#include "mozilla/webrender/DCLayerTree.h"
|
2018-06-13 18:01:06 +03:00
|
|
|
#include "mozilla/webrender/RenderThread.h"
|
2018-01-19 05:01:04 +03:00
|
|
|
#include "mozilla/widget/CompositorWidget.h"
|
2018-02-01 15:39:31 +03:00
|
|
|
#include "mozilla/widget/WinCompositorWidget.h"
|
|
|
|
#include "mozilla/WindowsVersion.h"
|
Bug 1581855:Part 2 - Present VR output to VR Host r=kip,jrmuizel,sotaro,bryce
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
2019-09-26 15:50:44 +03:00
|
|
|
#include "FxROutputHandler.h"
|
2018-01-19 05:01:04 +03:00
|
|
|
|
2018-03-29 05:23:31 +03:00
|
|
|
#undef NTDDI_VERSION
|
|
|
|
#define NTDDI_VERSION NTDDI_WIN8
|
|
|
|
|
2018-01-19 05:01:04 +03:00
|
|
|
#include <d3d11.h>
|
2018-03-29 05:23:31 +03:00
|
|
|
#include <dcomp.h>
|
2018-02-01 15:39:31 +03:00
|
|
|
#include <dxgi1_2.h>
|
2018-01-19 05:01:04 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace wr {
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
UniquePtr<RenderCompositor> RenderCompositorANGLE::Create(
|
2018-01-19 05:01:04 +03:00
|
|
|
RefPtr<widget::CompositorWidget>&& aWidget) {
|
2019-06-15 08:21:12 +03:00
|
|
|
const auto& gl = RenderThread::Get()->SharedGL();
|
|
|
|
if (!gl) {
|
2019-03-20 14:52:26 +03:00
|
|
|
gfxCriticalNote << "Failed to get shared GL context";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
UniquePtr<RenderCompositorANGLE> compositor =
|
2019-06-26 09:03:23 +03:00
|
|
|
MakeUnique<RenderCompositorANGLE>(std::move(aWidget));
|
2018-01-19 05:01:04 +03:00
|
|
|
if (!compositor->Initialize()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return compositor;
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderCompositorANGLE::RenderCompositorANGLE(
|
2019-06-26 09:03:23 +03:00
|
|
|
RefPtr<widget::CompositorWidget>&& aWidget)
|
2018-05-30 22:15:35 +03:00
|
|
|
: RenderCompositor(std::move(aWidget)),
|
2018-02-01 15:39:31 +03:00
|
|
|
mEGLConfig(nullptr),
|
|
|
|
mEGLSurface(nullptr),
|
2019-06-26 09:03:23 +03:00
|
|
|
mUseTripleBuffering(false) {}
|
2018-01-19 05:01:04 +03:00
|
|
|
|
|
|
|
RenderCompositorANGLE::~RenderCompositorANGLE() {
|
2018-02-10 01:45:44 +03:00
|
|
|
DestroyEGLSurface();
|
|
|
|
MOZ_ASSERT(!mEGLSurface);
|
2018-01-19 05:01:04 +03:00
|
|
|
}
|
|
|
|
|
2018-02-27 10:20:36 +03:00
|
|
|
ID3D11Device* RenderCompositorANGLE::GetDeviceOfEGLDisplay() {
|
2019-06-26 09:03:23 +03:00
|
|
|
auto* egl = gl::GLLibraryEGL::Get();
|
|
|
|
MOZ_ASSERT(egl);
|
|
|
|
if (!egl || !egl->IsExtensionSupported(gl::GLLibraryEGL::EXT_device_query)) {
|
2018-06-29 03:09:48 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2018-02-27 10:20:36 +03:00
|
|
|
|
|
|
|
// Fetch the D3D11 device.
|
|
|
|
EGLDeviceEXT eglDevice = nullptr;
|
2019-06-26 09:03:23 +03:00
|
|
|
egl->fQueryDisplayAttribEXT(egl->Display(), LOCAL_EGL_DEVICE_EXT,
|
|
|
|
(EGLAttrib*)&eglDevice);
|
2018-02-27 10:20:36 +03:00
|
|
|
MOZ_ASSERT(eglDevice);
|
|
|
|
ID3D11Device* device = nullptr;
|
2019-06-26 09:03:23 +03:00
|
|
|
egl->fQueryDeviceAttribEXT(eglDevice, LOCAL_EGL_D3D11_DEVICE_ANGLE,
|
|
|
|
(EGLAttrib*)&device);
|
2018-02-27 10:20:36 +03:00
|
|
|
if (!device) {
|
|
|
|
gfxCriticalNote << "Failed to get D3D11Device from EGLDisplay";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2018-06-13 18:01:06 +03:00
|
|
|
bool RenderCompositorANGLE::SutdownEGLLibraryIfNecessary() {
|
2019-06-26 09:03:23 +03:00
|
|
|
const RefPtr<gl::GLLibraryEGL> egl = gl::GLLibraryEGL::Get();
|
|
|
|
if (!egl) {
|
2018-06-13 18:01:06 +03:00
|
|
|
// egl is not initialized yet;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ID3D11Device> device =
|
|
|
|
gfx::DeviceManagerDx::Get()->GetCompositorDevice();
|
|
|
|
// When DeviceReset is handled by GPUProcessManager/GPUParent,
|
|
|
|
// CompositorDevice is updated to a new device. EGLDisplay also needs to be
|
|
|
|
// updated, since EGLDisplay uses DeviceManagerDx::mCompositorDevice on ANGLE
|
|
|
|
// WebRender use case. EGLDisplay could be updated when Renderer count becomes
|
|
|
|
// 0. It is ensured by GPUProcessManager during handling DeviceReset.
|
|
|
|
// GPUChild::RecvNotifyDeviceReset() destroys all CompositorSessions before
|
|
|
|
// re-creating them.
|
|
|
|
if (device.get() != GetDeviceOfEGLDisplay() &&
|
|
|
|
RenderThread::Get()->RendererCount() == 0) {
|
|
|
|
// Shutdown GLLibraryEGL for updating EGLDisplay.
|
2018-10-04 05:54:50 +03:00
|
|
|
RenderThread::Get()->ClearSharedGL();
|
2019-06-26 09:03:23 +03:00
|
|
|
egl->Shutdown();
|
2018-06-13 18:01:06 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-19 05:01:04 +03:00
|
|
|
bool RenderCompositorANGLE::Initialize() {
|
2018-06-13 18:01:06 +03:00
|
|
|
if (RenderThread::Get()->IsHandlingDeviceReset()) {
|
|
|
|
gfxCriticalNote << "Waiting for handling device reset";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update device if necessary.
|
|
|
|
if (!SutdownEGLLibraryIfNecessary()) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-26 09:03:23 +03:00
|
|
|
const auto gl = RenderThread::Get()->SharedGL();
|
|
|
|
if (!gl) {
|
2018-10-05 05:01:20 +03:00
|
|
|
gfxCriticalNote << "[WR] failed to get shared GL context.";
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-27 10:20:36 +03:00
|
|
|
|
|
|
|
mDevice = GetDeviceOfEGLDisplay();
|
|
|
|
|
2018-01-19 05:01:04 +03:00
|
|
|
if (!mDevice) {
|
2018-09-28 08:36:30 +03:00
|
|
|
gfxCriticalNote << "[WR] failed to get compositor device.";
|
2018-01-19 05:01:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDevice->GetImmediateContext(getter_AddRefs(mCtx));
|
|
|
|
if (!mCtx) {
|
2018-09-28 08:36:30 +03:00
|
|
|
gfxCriticalNote << "[WR] failed to get immediate context.";
|
2018-01-19 05:01:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-01 15:39:31 +03:00
|
|
|
HWND hwnd = mWidget->AsWindows()->GetHwnd();
|
|
|
|
|
|
|
|
RefPtr<IDXGIDevice> dxgiDevice;
|
|
|
|
mDevice->QueryInterface((IDXGIDevice**)getter_AddRefs(dxgiDevice));
|
|
|
|
|
|
|
|
RefPtr<IDXGIFactory> dxgiFactory;
|
|
|
|
{
|
|
|
|
RefPtr<IDXGIAdapter> adapter;
|
|
|
|
dxgiDevice->GetAdapter(getter_AddRefs(adapter));
|
|
|
|
|
|
|
|
adapter->GetParent(
|
|
|
|
IID_PPV_ARGS((IDXGIFactory**)getter_AddRefs(dxgiFactory)));
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IDXGIFactory2> dxgiFactory2;
|
2018-03-29 05:23:31 +03:00
|
|
|
HRESULT hr = dxgiFactory->QueryInterface(
|
|
|
|
(IDXGIFactory2**)getter_AddRefs(dxgiFactory2));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
dxgiFactory2 = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateSwapChainForDCompIfPossible(dxgiFactory2);
|
|
|
|
|
|
|
|
if (!mSwapChain && dxgiFactory2 && IsWin8OrLater()) {
|
2018-02-01 15:39:31 +03:00
|
|
|
RefPtr<IDXGISwapChain1> swapChain1;
|
2019-07-19 12:26:03 +03:00
|
|
|
bool useTripleBuffering = false;
|
2018-02-01 15:39:31 +03:00
|
|
|
|
|
|
|
DXGI_SWAP_CHAIN_DESC1 desc{};
|
|
|
|
desc.Width = 0;
|
|
|
|
desc.Height = 0;
|
|
|
|
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
desc.SampleDesc.Count = 1;
|
|
|
|
desc.SampleDesc.Quality = 0;
|
2019-02-22 02:31:12 +03:00
|
|
|
// DXGI_USAGE_SHADER_INPUT is set for improving performanc of copying from
|
|
|
|
// framebuffer to texture on intel gpu.
|
|
|
|
desc.BufferUsage =
|
|
|
|
DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT;
|
2019-07-19 12:26:03 +03:00
|
|
|
|
|
|
|
if (gfx::gfxVars::UseWebRenderFlipSequentialWin()) {
|
|
|
|
useTripleBuffering = gfx::gfxVars::UseWebRenderTripleBufferingWin();
|
|
|
|
if (useTripleBuffering) {
|
|
|
|
desc.BufferCount = 3;
|
|
|
|
} else {
|
|
|
|
desc.BufferCount = 2;
|
|
|
|
}
|
|
|
|
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
|
|
|
} else {
|
|
|
|
desc.BufferCount = 1;
|
|
|
|
desc.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL;
|
|
|
|
}
|
2018-02-01 15:39:31 +03:00
|
|
|
desc.Scaling = DXGI_SCALING_NONE;
|
|
|
|
desc.Flags = 0;
|
|
|
|
|
2018-03-29 05:23:31 +03:00
|
|
|
hr = dxgiFactory2->CreateSwapChainForHwnd(
|
|
|
|
mDevice, hwnd, &desc, nullptr, nullptr, getter_AddRefs(swapChain1));
|
2018-02-01 15:39:31 +03:00
|
|
|
if (SUCCEEDED(hr) && swapChain1) {
|
|
|
|
DXGI_RGBA color = {1.0f, 1.0f, 1.0f, 1.0f};
|
|
|
|
swapChain1->SetBackgroundColor(&color);
|
|
|
|
mSwapChain = swapChain1;
|
2019-07-19 12:26:03 +03:00
|
|
|
mUseTripleBuffering = useTripleBuffering;
|
2018-02-01 15:39:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mSwapChain) {
|
|
|
|
DXGI_SWAP_CHAIN_DESC swapDesc{};
|
|
|
|
swapDesc.BufferDesc.Width = 0;
|
|
|
|
swapDesc.BufferDesc.Height = 0;
|
|
|
|
swapDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
swapDesc.BufferDesc.RefreshRate.Numerator = 60;
|
|
|
|
swapDesc.BufferDesc.RefreshRate.Denominator = 1;
|
|
|
|
swapDesc.SampleDesc.Count = 1;
|
|
|
|
swapDesc.SampleDesc.Quality = 0;
|
2019-02-22 02:31:12 +03:00
|
|
|
// DXGI_USAGE_SHADER_INPUT is set for improving performanc of copying from
|
|
|
|
// framebuffer to texture on intel gpu.
|
|
|
|
swapDesc.BufferUsage =
|
|
|
|
DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT;
|
2018-02-01 15:39:31 +03:00
|
|
|
swapDesc.BufferCount = 1;
|
|
|
|
swapDesc.OutputWindow = hwnd;
|
|
|
|
swapDesc.Windowed = TRUE;
|
|
|
|
swapDesc.Flags = 0;
|
|
|
|
swapDesc.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL;
|
|
|
|
|
|
|
|
HRESULT hr = dxgiFactory->CreateSwapChain(dxgiDevice, &swapDesc,
|
|
|
|
getter_AddRefs(mSwapChain));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxCriticalNote << "Could not create swap chain: " << gfx::hexa(hr);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need this because we don't want DXGI to respond to Alt+Enter.
|
|
|
|
dxgiFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_WINDOW_CHANGES);
|
|
|
|
|
2018-01-19 05:01:04 +03:00
|
|
|
mSyncObject = layers::SyncObjectHost::CreateSyncObjectHost(mDevice);
|
|
|
|
if (!mSyncObject->Init()) {
|
|
|
|
// Some errors occur. Clear the mSyncObject here.
|
|
|
|
// Then, there will be no texture synchronization.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-01 15:39:31 +03:00
|
|
|
// Force enable alpha channel to make sure ANGLE use correct framebuffer
|
|
|
|
// formart
|
2019-06-26 09:03:23 +03:00
|
|
|
const auto& gle = gl::GLContextEGL::Cast(gl);
|
|
|
|
const auto& egl = gle->mEgl;
|
|
|
|
if (!gl::CreateConfig(egl, &mEGLConfig, /* bpp */ 32,
|
2018-02-01 15:39:31 +03:00
|
|
|
/* enableDepthBuffer */ true)) {
|
|
|
|
gfxCriticalNote << "Failed to create EGLConfig for WebRender";
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(mEGLConfig);
|
|
|
|
|
|
|
|
if (!ResizeBufferIfNeeded()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-19 05:01:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-29 05:23:31 +03:00
|
|
|
void RenderCompositorANGLE::CreateSwapChainForDCompIfPossible(
|
|
|
|
IDXGIFactory2* aDXGIFactory2) {
|
|
|
|
if (!aDXGIFactory2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND hwnd = mWidget->AsWindows()->GetCompositorHwnd();
|
|
|
|
if (!hwnd) {
|
|
|
|
gfxCriticalNote << "Compositor window was not created ";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-19 21:15:11 +03:00
|
|
|
mDCLayerTree = DCLayerTree::Create(hwnd);
|
|
|
|
if (!mDCLayerTree) {
|
2018-03-29 05:23:31 +03:00
|
|
|
return;
|
|
|
|
}
|
2019-09-19 21:15:11 +03:00
|
|
|
MOZ_ASSERT(XRE_IsGPUProcess());
|
2018-03-29 05:23:31 +03:00
|
|
|
|
2019-09-19 21:15:11 +03:00
|
|
|
HRESULT hr;
|
2018-03-29 05:23:31 +03:00
|
|
|
RefPtr<IDXGISwapChain1> swapChain1;
|
2019-07-19 12:26:03 +03:00
|
|
|
bool useTripleBuffering = gfx::gfxVars::UseWebRenderTripleBufferingWin();
|
2018-03-29 05:23:31 +03:00
|
|
|
|
|
|
|
DXGI_SWAP_CHAIN_DESC1 desc{};
|
|
|
|
// DXGI does not like 0x0 swapchains. Swap chain creation failed when 0x0 was
|
|
|
|
// set.
|
|
|
|
desc.Width = 1;
|
|
|
|
desc.Height = 1;
|
|
|
|
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
desc.SampleDesc.Count = 1;
|
|
|
|
desc.SampleDesc.Quality = 0;
|
2019-02-22 02:31:12 +03:00
|
|
|
// DXGI_USAGE_SHADER_INPUT is set for improving performanc of copying from
|
|
|
|
// framebuffer to texture on intel gpu.
|
|
|
|
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT;
|
2018-11-05 12:58:37 +03:00
|
|
|
if (useTripleBuffering) {
|
|
|
|
desc.BufferCount = 3;
|
|
|
|
} else {
|
|
|
|
desc.BufferCount = 2;
|
|
|
|
}
|
2018-03-29 05:23:31 +03:00
|
|
|
// DXGI_SCALING_NONE caused swap chain creation failure.
|
|
|
|
desc.Scaling = DXGI_SCALING_STRETCH;
|
|
|
|
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
2019-09-04 05:40:27 +03:00
|
|
|
desc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
|
2018-03-29 05:23:31 +03:00
|
|
|
desc.Flags = 0;
|
|
|
|
|
|
|
|
hr = aDXGIFactory2->CreateSwapChainForComposition(mDevice, &desc, nullptr,
|
|
|
|
getter_AddRefs(swapChain1));
|
|
|
|
if (SUCCEEDED(hr) && swapChain1) {
|
|
|
|
DXGI_RGBA color = {1.0f, 1.0f, 1.0f, 1.0f};
|
|
|
|
swapChain1->SetBackgroundColor(&color);
|
|
|
|
mSwapChain = swapChain1;
|
2019-09-19 21:15:11 +03:00
|
|
|
mDCLayerTree->SetDefaultSwapChain(swapChain1);
|
2018-11-05 12:58:37 +03:00
|
|
|
mUseTripleBuffering = useTripleBuffering;
|
2019-09-19 21:15:11 +03:00
|
|
|
} else {
|
|
|
|
// Clear CLayerTree on falire
|
|
|
|
mDCLayerTree = nullptr;
|
2018-03-29 05:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-25 20:43:42 +03:00
|
|
|
bool RenderCompositorANGLE::BeginFrame(layers::NativeLayer* aNativeLayer) {
|
|
|
|
MOZ_RELEASE_ASSERT(!aNativeLayer, "Unexpected native layer on this platform");
|
2018-03-29 05:21:47 +03:00
|
|
|
mWidget->AsWindows()->UpdateCompositorWndSizeIfNecessary();
|
|
|
|
|
2018-02-01 15:39:31 +03:00
|
|
|
if (!ResizeBufferIfNeeded()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-04 05:54:50 +03:00
|
|
|
if (!MakeCurrent()) {
|
2018-01-19 05:01:04 +03:00
|
|
|
gfxCriticalNote << "Failed to make render context current, can't draw.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSyncObject) {
|
2018-10-05 08:49:04 +03:00
|
|
|
if (!mSyncObject->Synchronize(/* aFallible */ true)) {
|
2018-06-13 18:01:06 +03:00
|
|
|
// It's timeout or other error. Handle the device-reset here.
|
2018-06-19 13:27:37 +03:00
|
|
|
RenderThread::Get()->HandleDeviceReset("SyncObject", /* aNotify */ true);
|
2018-06-13 18:01:06 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-01-19 05:01:04 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderCompositorANGLE::EndFrame() {
|
|
|
|
InsertPresentWaitQuery();
|
|
|
|
|
Bug 1581855:Part 2 - Present VR output to VR Host r=kip,jrmuizel,sotaro,bryce
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
2019-09-26 15:50:44 +03:00
|
|
|
if (mWidget->AsWindows()->HasFxrOutputHandler()) {
|
|
|
|
// There is a Firefox Reality handler for this swapchain. Update this
|
|
|
|
// window's contents to the VR window.
|
|
|
|
FxROutputHandler* fxrHandler = mWidget->AsWindows()->GetFxrOutputHandler();
|
|
|
|
if (fxrHandler->TryInitialize(mSwapChain, mDevice)) {
|
|
|
|
fxrHandler->UpdateOutput(mCtx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-01 15:39:31 +03:00
|
|
|
mSwapChain->Present(0, 0);
|
2018-11-12 04:36:13 +03:00
|
|
|
}
|
2018-03-29 05:23:31 +03:00
|
|
|
|
2019-07-11 12:41:38 +03:00
|
|
|
bool RenderCompositorANGLE::WaitForGPU() {
|
2018-01-19 05:01:04 +03:00
|
|
|
// Note: this waits on the query we inserted in the previous frame,
|
|
|
|
// not the one we just inserted now. Example:
|
|
|
|
// Insert query #1
|
|
|
|
// Present #1
|
|
|
|
// (first frame, no wait)
|
|
|
|
// Insert query #2
|
|
|
|
// Present #2
|
|
|
|
// Wait for query #1.
|
|
|
|
// Insert query #3
|
|
|
|
// Present #3
|
|
|
|
// Wait for query #2.
|
|
|
|
//
|
|
|
|
// This ensures we're done reading textures before swapping buffers.
|
2019-07-11 12:41:38 +03:00
|
|
|
return WaitForPreviousPresentQuery();
|
2018-01-19 05:01:04 +03:00
|
|
|
}
|
|
|
|
|
2018-02-01 15:39:31 +03:00
|
|
|
bool RenderCompositorANGLE::ResizeBufferIfNeeded() {
|
|
|
|
MOZ_ASSERT(mSwapChain);
|
|
|
|
|
|
|
|
LayoutDeviceIntSize size = mWidget->GetClientSize();
|
|
|
|
|
2018-03-29 05:23:31 +03:00
|
|
|
// DXGI does not like 0x0 swapchains. ResizeBuffers() failed when 0x0 was set
|
|
|
|
// when DComp is used.
|
|
|
|
size.width = std::max(size.width, 1);
|
|
|
|
size.height = std::max(size.height, 1);
|
2018-02-01 15:39:31 +03:00
|
|
|
|
|
|
|
if (mBufferSize.isSome() && mBufferSize.ref() == size) {
|
|
|
|
MOZ_ASSERT(mEGLSurface);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-03 15:36:09 +03:00
|
|
|
// Release EGLSurface of back buffer before calling ResizeBuffers().
|
|
|
|
DestroyEGLSurface();
|
|
|
|
|
|
|
|
mBufferSize = Some(size);
|
|
|
|
|
|
|
|
if (!CreateEGLSurface()) {
|
|
|
|
mBufferSize.reset();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RenderCompositorANGLE::CreateEGLSurface() {
|
|
|
|
MOZ_ASSERT(mBufferSize.isSome());
|
|
|
|
MOZ_ASSERT(mEGLSurface == EGL_NO_SURFACE);
|
|
|
|
|
2018-02-01 15:39:31 +03:00
|
|
|
HRESULT hr;
|
|
|
|
RefPtr<ID3D11Texture2D> backBuf;
|
|
|
|
|
2019-09-03 15:36:09 +03:00
|
|
|
if (mBufferSize.isNothing()) {
|
|
|
|
gfxCriticalNote << "Buffer size is invalid";
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-01 15:39:31 +03:00
|
|
|
|
2019-09-03 15:36:09 +03:00
|
|
|
const LayoutDeviceIntSize& size = mBufferSize.ref();
|
2018-02-01 15:39:31 +03:00
|
|
|
|
|
|
|
// Resize swap chain
|
|
|
|
DXGI_SWAP_CHAIN_DESC desc;
|
|
|
|
hr = mSwapChain->GetDesc(&desc);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxCriticalNote << "Failed to read swap chain description: "
|
|
|
|
<< gfx::hexa(hr) << " Size : " << size;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
hr = mSwapChain->ResizeBuffers(desc.BufferCount, size.width, size.height,
|
|
|
|
DXGI_FORMAT_B8G8R8A8_UNORM, 0);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxCriticalNote << "Failed to resize swap chain buffers: " << gfx::hexa(hr)
|
|
|
|
<< " Size : " << size;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D),
|
|
|
|
(void**)getter_AddRefs(backBuf));
|
|
|
|
if (hr == DXGI_ERROR_INVALID_CALL) {
|
|
|
|
// This happens on some GPUs/drivers when there's a TDR.
|
|
|
|
if (mDevice->GetDeviceRemovedReason() != S_OK) {
|
|
|
|
gfxCriticalError() << "GetBuffer returned invalid call: " << gfx::hexa(hr)
|
|
|
|
<< " Size : " << size;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const EGLint pbuffer_attribs[]{
|
|
|
|
LOCAL_EGL_WIDTH,
|
|
|
|
size.width,
|
|
|
|
LOCAL_EGL_HEIGHT,
|
|
|
|
size.height,
|
|
|
|
LOCAL_EGL_FLEXIBLE_SURFACE_COMPATIBILITY_SUPPORTED_ANGLE,
|
|
|
|
LOCAL_EGL_TRUE,
|
|
|
|
LOCAL_EGL_NONE};
|
|
|
|
|
|
|
|
const auto buffer = reinterpret_cast<EGLClientBuffer>(backBuf.get());
|
|
|
|
|
2019-06-26 09:03:23 +03:00
|
|
|
const auto gl = RenderThread::Get()->SharedGL();
|
|
|
|
const auto& gle = gl::GLContextEGL::Cast(gl);
|
|
|
|
const auto& egl = gle->mEgl;
|
|
|
|
const EGLSurface surface = egl->fCreatePbufferFromClientBuffer(
|
|
|
|
egl->Display(), LOCAL_EGL_D3D_TEXTURE_ANGLE, buffer, mEGLConfig,
|
2018-02-01 15:39:31 +03:00
|
|
|
pbuffer_attribs);
|
|
|
|
|
2019-06-26 09:03:23 +03:00
|
|
|
EGLint err = egl->fGetError();
|
2018-02-01 15:39:31 +03:00
|
|
|
if (err != LOCAL_EGL_SUCCESS) {
|
|
|
|
gfxCriticalError() << "Failed to create Pbuffer of back buffer error: "
|
|
|
|
<< gfx::hexa(err) << " Size : " << size;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mEGLSurface = surface;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderCompositorANGLE::DestroyEGLSurface() {
|
|
|
|
// Release EGLSurface of back buffer before calling ResizeBuffers().
|
|
|
|
if (mEGLSurface) {
|
2019-06-26 09:03:23 +03:00
|
|
|
const auto& gle = gl::GLContextEGL::Cast(gl());
|
|
|
|
const auto& egl = gle->mEgl;
|
|
|
|
gle->SetEGLSurfaceOverride(EGL_NO_SURFACE);
|
|
|
|
egl->fDestroySurface(egl->Display(), mEGLSurface);
|
2018-02-01 15:39:31 +03:00
|
|
|
mEGLSurface = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-19 05:01:04 +03:00
|
|
|
void RenderCompositorANGLE::Pause() {}
|
|
|
|
|
|
|
|
bool RenderCompositorANGLE::Resume() { return true; }
|
|
|
|
|
2018-10-04 05:54:50 +03:00
|
|
|
bool RenderCompositorANGLE::MakeCurrent() {
|
|
|
|
gl::GLContextEGL::Cast(gl())->SetEGLSurfaceOverride(mEGLSurface);
|
|
|
|
return gl()->MakeCurrent();
|
|
|
|
}
|
|
|
|
|
2018-02-01 15:39:31 +03:00
|
|
|
LayoutDeviceIntSize RenderCompositorANGLE::GetBufferSize() {
|
|
|
|
MOZ_ASSERT(mBufferSize.isSome());
|
|
|
|
if (mBufferSize.isNothing()) {
|
|
|
|
return LayoutDeviceIntSize();
|
|
|
|
}
|
|
|
|
return mBufferSize.ref();
|
2018-01-19 05:01:04 +03:00
|
|
|
}
|
|
|
|
|
2018-11-12 04:14:55 +03:00
|
|
|
RefPtr<ID3D11Query> RenderCompositorANGLE::GetD3D11Query() {
|
2018-11-05 12:58:37 +03:00
|
|
|
RefPtr<ID3D11Query> query;
|
2018-11-12 04:14:55 +03:00
|
|
|
|
|
|
|
if (mRecycledQuery) {
|
|
|
|
query = mRecycledQuery.forget();
|
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|
2018-01-19 05:01:04 +03:00
|
|
|
CD3D11_QUERY_DESC desc(D3D11_QUERY_EVENT);
|
2018-11-05 12:58:37 +03:00
|
|
|
HRESULT hr = mDevice->CreateQuery(&desc, getter_AddRefs(query));
|
|
|
|
if (FAILED(hr) || !query) {
|
2018-03-29 05:23:31 +03:00
|
|
|
gfxWarning() << "Could not create D3D11_QUERY_EVENT: " << gfx::hexa(hr);
|
2018-11-12 04:14:55 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderCompositorANGLE::InsertPresentWaitQuery() {
|
|
|
|
RefPtr<ID3D11Query> query;
|
|
|
|
query = GetD3D11Query();
|
|
|
|
if (!query) {
|
2018-01-19 05:01:04 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-05 12:58:37 +03:00
|
|
|
mCtx->End(query);
|
|
|
|
mWaitForPresentQueries.emplace(query);
|
2018-01-19 05:01:04 +03:00
|
|
|
}
|
|
|
|
|
2019-07-11 12:41:38 +03:00
|
|
|
bool RenderCompositorANGLE::WaitForPreviousPresentQuery() {
|
2018-11-05 12:58:37 +03:00
|
|
|
size_t waitLatency = mUseTripleBuffering ? 3 : 2;
|
|
|
|
|
|
|
|
while (mWaitForPresentQueries.size() >= waitLatency) {
|
|
|
|
RefPtr<ID3D11Query>& query = mWaitForPresentQueries.front();
|
2018-01-19 05:01:04 +03:00
|
|
|
BOOL result;
|
2019-07-11 12:41:38 +03:00
|
|
|
bool ret = layers::WaitForFrameGPUQuery(mDevice, mCtx, query, &result);
|
2018-11-05 12:58:37 +03:00
|
|
|
|
2018-11-12 04:14:55 +03:00
|
|
|
// Recycle query for later use.
|
|
|
|
mRecycledQuery = query;
|
2018-11-05 12:58:37 +03:00
|
|
|
mWaitForPresentQueries.pop();
|
2019-07-11 12:41:38 +03:00
|
|
|
if (!ret) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RenderCompositorANGLE::IsContextLost() {
|
|
|
|
// XXX glGetGraphicsResetStatus sometimes did not work for detecting TDR.
|
|
|
|
// Then this function just uses GetDeviceRemovedReason().
|
|
|
|
if (mDevice->GetDeviceRemovedReason() != S_OK) {
|
|
|
|
return true;
|
2018-01-19 05:01:04 +03:00
|
|
|
}
|
2019-07-11 12:41:38 +03:00
|
|
|
return false;
|
2018-01-19 05:01:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace wr
|
|
|
|
} // namespace mozilla
|