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"
|
2019-11-03 13:57:03 +03:00
|
|
|
#include "mozilla/gfx/StackArray.h"
|
2018-01-19 05:01:04 +03:00
|
|
|
#include "mozilla/layers/HelpersD3D11.h"
|
|
|
|
#include "mozilla/layers/SyncObject.h"
|
2019-10-31 14:59:17 +03:00
|
|
|
#include "mozilla/StaticPrefs_gfx.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"
|
2020-02-06 22:49:25 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2020-09-25 11:57:23 +03:00
|
|
|
#include "nsPrintfCString.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
|
|
|
|
2019-11-30 06:14:58 +03:00
|
|
|
// Flag for PrintWindow() that is defined in Winuser.h. It is defined since
|
|
|
|
// Windows 8.1. This allows PrintWindow to capture window content that is
|
|
|
|
// rendered with DirectComposition.
|
|
|
|
#undef PW_RENDERFULLCONTENT
|
|
|
|
#define PW_RENDERFULLCONTENT 0x00000002
|
|
|
|
|
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(
|
2020-09-12 01:40:40 +03:00
|
|
|
RefPtr<widget::CompositorWidget>&& aWidget, nsACString& aError) {
|
2020-09-13 20:31:14 +03:00
|
|
|
const auto& gl = RenderThread::Get()->SharedGL(aError);
|
2019-06-15 08:21:12 +03:00
|
|
|
if (!gl) {
|
2020-09-13 20:31:14 +03:00
|
|
|
if (aError.IsEmpty()) {
|
|
|
|
aError.Assign("RcANGLE(no shared GL)"_ns);
|
|
|
|
} else {
|
|
|
|
aError.Append("(Create)"_ns);
|
|
|
|
}
|
2019-03-20 14:52:26 +03:00
|
|
|
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));
|
2020-09-12 01:40:40 +03:00
|
|
|
if (!compositor->Initialize(aError)) {
|
2018-01-19 05:01:04 +03:00
|
|
|
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-10-08 13:07:47 +03:00
|
|
|
mUseTripleBuffering(false),
|
2019-11-03 13:57:03 +03:00
|
|
|
mUseAlpha(false),
|
2020-01-24 02:52:05 +03:00
|
|
|
mUseNativeCompositor(true),
|
2019-11-03 13:57:03 +03:00
|
|
|
mUsePartialPresent(false),
|
2020-01-24 02:52:05 +03:00
|
|
|
mFullRender(false),
|
|
|
|
mDisablingNativeCompositor(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
|
|
|
}
|
|
|
|
|
2020-09-12 01:40:40 +03:00
|
|
|
ID3D11Device* RenderCompositorANGLE::GetDeviceOfEGLDisplay(nsACString& aError) {
|
2020-09-13 20:31:14 +03:00
|
|
|
const auto& gl = RenderThread::Get()->SharedGL(aError);
|
2020-08-07 10:14:46 +03:00
|
|
|
if (!gl) {
|
2020-09-13 20:31:14 +03:00
|
|
|
if (aError.IsEmpty()) {
|
|
|
|
aError.Assign("RcANGLE(no shared GL in get device)"_ns);
|
|
|
|
} else {
|
|
|
|
aError.Append("(GetDevice)"_ns);
|
|
|
|
}
|
2020-08-07 10:14:46 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const auto& gle = gl::GLContextEGL::Cast(gl);
|
|
|
|
const auto& egl = gle->mEgl;
|
2019-06-26 09:03:23 +03:00
|
|
|
MOZ_ASSERT(egl);
|
2020-08-07 10:14:46 +03:00
|
|
|
if (!egl || !egl->IsExtensionSupported(gl::EGLExtension::EXT_device_query)) {
|
2020-09-12 01:40:40 +03:00
|
|
|
aError.Assign("RcANGLE(no EXT_device_query support)"_ns);
|
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;
|
2020-08-07 10:14:46 +03:00
|
|
|
egl->fQueryDisplayAttribEXT(LOCAL_EGL_DEVICE_EXT, (EGLAttrib*)&eglDevice);
|
2018-02-27 10:20:36 +03:00
|
|
|
MOZ_ASSERT(eglDevice);
|
|
|
|
ID3D11Device* device = nullptr;
|
2020-08-07 10:14:46 +03:00
|
|
|
egl->mLib->fQueryDeviceAttribEXT(eglDevice, LOCAL_EGL_D3D11_DEVICE_ANGLE,
|
|
|
|
(EGLAttrib*)&device);
|
2018-02-27 10:20:36 +03:00
|
|
|
if (!device) {
|
2020-09-12 01:40:40 +03:00
|
|
|
aError.Assign("RcANGLE(get D3D11Device from EGLDisplay failed)"_ns);
|
2018-02-27 10:20:36 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2020-09-12 01:40:40 +03:00
|
|
|
bool RenderCompositorANGLE::ShutdownEGLLibraryIfNecessary(nsACString& aError) {
|
|
|
|
const auto& displayDevice = GetDeviceOfEGLDisplay(aError);
|
2018-06-13 18:01:06 +03:00
|
|
|
RefPtr<ID3D11Device> device =
|
|
|
|
gfx::DeviceManagerDx::Get()->GetCompositorDevice();
|
2020-10-06 12:31:05 +03:00
|
|
|
|
2018-06-13 18:01:06 +03:00
|
|
|
// 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.
|
2020-10-06 12:31:05 +03:00
|
|
|
|
|
|
|
if ((!displayDevice || device.get() != displayDevice) &&
|
2018-06-13 18:01:06 +03:00
|
|
|
RenderThread::Get()->RendererCount() == 0) {
|
|
|
|
// Shutdown GLLibraryEGL for updating EGLDisplay.
|
2018-10-04 05:54:50 +03:00
|
|
|
RenderThread::Get()->ClearSharedGL();
|
2018-06-13 18:01:06 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-12 01:40:40 +03:00
|
|
|
bool RenderCompositorANGLE::Initialize(nsACString& aError) {
|
2018-06-13 18:01:06 +03:00
|
|
|
if (RenderThread::Get()->IsHandlingDeviceReset()) {
|
2020-09-12 01:40:40 +03:00
|
|
|
aError.Assign("RcANGLE(waiting device reset)"_ns);
|
2018-06-13 18:01:06 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update device if necessary.
|
2020-09-12 01:40:40 +03:00
|
|
|
if (!ShutdownEGLLibraryIfNecessary(aError)) {
|
2020-09-13 20:31:14 +03:00
|
|
|
aError.Append("(Shutdown EGL)"_ns);
|
2018-06-13 18:01:06 +03:00
|
|
|
return false;
|
|
|
|
}
|
2020-09-13 20:31:14 +03:00
|
|
|
const auto gl = RenderThread::Get()->SharedGL(aError);
|
2019-06-26 09:03:23 +03:00
|
|
|
if (!gl) {
|
2020-09-13 20:31:14 +03:00
|
|
|
if (aError.IsEmpty()) {
|
|
|
|
aError.Assign("RcANGLE(no shared GL post maybe shutdown)"_ns);
|
|
|
|
} else {
|
|
|
|
aError.Append("(Initialize)"_ns);
|
|
|
|
}
|
2018-10-05 05:01:20 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-02-27 10:20:36 +03:00
|
|
|
|
2019-10-31 14:59:17 +03:00
|
|
|
// Force enable alpha channel to make sure ANGLE use correct framebuffer
|
|
|
|
// formart
|
|
|
|
const auto& gle = gl::GLContextEGL::Cast(gl);
|
|
|
|
const auto& egl = gle->mEgl;
|
2020-08-07 10:14:46 +03:00
|
|
|
if (!gl::CreateConfig(*egl, &mEGLConfig, /* bpp */ 32,
|
2020-04-21 08:43:35 +03:00
|
|
|
/* enableDepthBuffer */ true, gl->IsGLES())) {
|
2020-09-12 01:40:40 +03:00
|
|
|
aError.Assign("RcANGLE(create EGLConfig failed)"_ns);
|
|
|
|
return false;
|
2019-10-31 14:59:17 +03:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(mEGLConfig);
|
|
|
|
|
2020-09-12 01:40:40 +03:00
|
|
|
mDevice = GetDeviceOfEGLDisplay(aError);
|
2018-02-27 10:20:36 +03:00
|
|
|
|
2018-01-19 05:01:04 +03:00
|
|
|
if (!mDevice) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDevice->GetImmediateContext(getter_AddRefs(mCtx));
|
|
|
|
if (!mCtx) {
|
2020-09-12 01:40:40 +03:00
|
|
|
aError.Assign("RcANGLE(get immediate context failed)"_ns);
|
2018-01-19 05:01:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-05 22:10:12 +03:00
|
|
|
// Create DCLayerTree when DirectComposition is used.
|
|
|
|
if (gfx::gfxVars::UseWebRenderDCompWin()) {
|
2020-04-14 06:27:12 +03:00
|
|
|
HWND compositorHwnd = GetCompositorHwnd();
|
2020-01-05 22:10:12 +03:00
|
|
|
if (compositorHwnd) {
|
2020-09-12 01:40:40 +03:00
|
|
|
mDCLayerTree = DCLayerTree::Create(gl, mEGLConfig, mDevice, mCtx,
|
|
|
|
compositorHwnd, aError);
|
2020-05-25 14:57:05 +03:00
|
|
|
if (!mDCLayerTree) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-05 22:10:12 +03:00
|
|
|
} else {
|
2020-09-12 01:40:40 +03:00
|
|
|
aError.Assign("RcANGLE(no compositor window)"_ns);
|
2020-05-25 14:57:05 +03:00
|
|
|
return false;
|
2020-01-05 22:10:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create SwapChain when compositor is not used
|
|
|
|
if (!UseCompositor()) {
|
2020-09-12 01:40:40 +03:00
|
|
|
if (!CreateSwapChain(aError)) {
|
2020-01-05 22:10:12 +03:00
|
|
|
// SwapChain creation failed.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mSyncObject = layers::SyncObjectHost::CreateSyncObjectHost(mDevice);
|
|
|
|
if (!mSyncObject->Init()) {
|
|
|
|
// Some errors occur. Clear the mSyncObject here.
|
|
|
|
// Then, there will be no texture synchronization.
|
2020-09-12 01:40:40 +03:00
|
|
|
aError.Assign("RcANGLE(create SyncObject failed)"_ns);
|
2020-01-05 22:10:12 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
InitializeUsePartialPresent();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-14 06:27:12 +03:00
|
|
|
HWND RenderCompositorANGLE::GetCompositorHwnd() {
|
|
|
|
HWND hwnd = 0;
|
|
|
|
|
|
|
|
if (XRE_IsGPUProcess()) {
|
|
|
|
hwnd = mWidget->AsWindows()->GetCompositorHwnd();
|
|
|
|
}
|
|
|
|
#ifdef NIGHTLY_BUILD
|
|
|
|
else if (
|
|
|
|
StaticPrefs::
|
|
|
|
gfx_webrender_enabled_no_gpu_process_with_angle_win_AtStartup()) {
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
|
|
|
|
// When GPU process does not exist, we do not need to use compositor window.
|
|
|
|
hwnd = mWidget->AsWindows()->GetHwnd();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return hwnd;
|
|
|
|
}
|
|
|
|
|
2020-09-12 01:40:40 +03:00
|
|
|
bool RenderCompositorANGLE::CreateSwapChain(nsACString& aError) {
|
2020-01-05 22:10:12 +03:00
|
|
|
MOZ_ASSERT(!UseCompositor());
|
|
|
|
|
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);
|
2020-05-25 14:57:05 +03:00
|
|
|
if (gfx::gfxVars::UseWebRenderDCompWin() && !mSwapChain) {
|
|
|
|
MOZ_ASSERT(GetCompositorHwnd());
|
2020-09-12 01:40:40 +03:00
|
|
|
aError.Assign("RcANGLE(create swapchain for dcomp failed)"_ns);
|
2020-05-25 14:57:05 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-03-29 05:23:31 +03:00
|
|
|
|
|
|
|
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-11-12 22:15:39 +03:00
|
|
|
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
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-11-03 13:57:03 +03:00
|
|
|
mSwapChain1 = swapChain1;
|
2019-07-19 12:26:03 +03:00
|
|
|
mUseTripleBuffering = useTripleBuffering;
|
2020-05-25 14:57:05 +03:00
|
|
|
} else if (gfx::gfxVars::UseWebRenderFlipSequentialWin()) {
|
|
|
|
MOZ_ASSERT(GetCompositorHwnd());
|
2020-09-12 01:40:40 +03:00
|
|
|
aError.Assign(
|
|
|
|
nsPrintfCString("RcANGLE(swap chain hwnd create failed %x)", hr));
|
2020-05-25 14:57:05 +03:00
|
|
|
return false;
|
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-11-12 22:15:39 +03:00
|
|
|
swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
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)) {
|
2020-09-12 01:40:40 +03:00
|
|
|
aError.Assign(
|
|
|
|
nsPrintfCString("RcANGLE(swap chain create failed %x)", hr));
|
2018-02-01 15:39:31 +03:00
|
|
|
return false;
|
|
|
|
}
|
2019-11-03 13:57:03 +03:00
|
|
|
|
|
|
|
RefPtr<IDXGISwapChain1> swapChain1;
|
|
|
|
hr = mSwapChain->QueryInterface(
|
|
|
|
(IDXGISwapChain1**)getter_AddRefs(swapChain1));
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
mSwapChain1 = swapChain1;
|
|
|
|
}
|
2018-02-01 15:39:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// We need this because we don't want DXGI to respond to Alt+Enter.
|
|
|
|
dxgiFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_WINDOW_CHANGES);
|
|
|
|
|
2020-01-05 22:10:12 +03:00
|
|
|
if (!ResizeBufferIfNeeded()) {
|
2020-09-12 01:40:40 +03:00
|
|
|
aError.Assign("RcANGLE(resize buffer failed)"_ns);
|
2018-01-19 05:01:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-29 05:23:31 +03:00
|
|
|
void RenderCompositorANGLE::CreateSwapChainForDCompIfPossible(
|
|
|
|
IDXGIFactory2* aDXGIFactory2) {
|
2020-01-05 22:10:12 +03:00
|
|
|
if (!aDXGIFactory2 || !mDCLayerTree) {
|
2018-03-29 05:23:31 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-14 06:27:12 +03:00
|
|
|
HWND hwnd = GetCompositorHwnd();
|
2018-03-29 05:23:31 +03:00
|
|
|
if (!hwnd) {
|
2019-12-10 04:10:23 +03:00
|
|
|
// When DirectComposition or DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL is used,
|
|
|
|
// compositor window needs to exist.
|
|
|
|
if (gfx::gfxVars::UseWebRenderDCompWin() ||
|
|
|
|
gfx::gfxVars::UseWebRenderFlipSequentialWin()) {
|
|
|
|
gfxCriticalNote << "Compositor window was not created";
|
|
|
|
}
|
2018-03-29 05:23:31 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-31 14:59:17 +03:00
|
|
|
// When compositor is enabled, CompositionSurface is used for rendering.
|
|
|
|
// It does not support triple buffering.
|
|
|
|
bool useTripleBuffering =
|
|
|
|
gfx::gfxVars::UseWebRenderTripleBufferingWin() && !UseCompositor();
|
2019-10-10 11:58:00 +03:00
|
|
|
// Non Glass window is common since Windows 10.
|
|
|
|
bool useAlpha = false;
|
2019-10-08 13:07:47 +03:00
|
|
|
RefPtr<IDXGISwapChain1> swapChain1 =
|
|
|
|
CreateSwapChainForDComp(useTripleBuffering, useAlpha);
|
|
|
|
if (swapChain1) {
|
|
|
|
mSwapChain = swapChain1;
|
2019-11-03 13:57:03 +03:00
|
|
|
mSwapChain1 = swapChain1;
|
2019-10-08 13:07:47 +03:00
|
|
|
mUseTripleBuffering = useTripleBuffering;
|
|
|
|
mUseAlpha = useAlpha;
|
|
|
|
mDCLayerTree->SetDefaultSwapChain(swapChain1);
|
|
|
|
} else {
|
|
|
|
// Clear CLayerTree on falire
|
|
|
|
mDCLayerTree = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IDXGISwapChain1> RenderCompositorANGLE::CreateSwapChainForDComp(
|
|
|
|
bool aUseTripleBuffering, bool aUseAlpha) {
|
|
|
|
HRESULT hr;
|
|
|
|
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)));
|
|
|
|
}
|
2018-03-29 05:23:31 +03:00
|
|
|
|
2019-10-08 13:07:47 +03:00
|
|
|
RefPtr<IDXGIFactory2> dxgiFactory2;
|
|
|
|
hr = dxgiFactory->QueryInterface(
|
|
|
|
(IDXGIFactory2**)getter_AddRefs(dxgiFactory2));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IDXGISwapChain1> swapChain1;
|
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-11-12 22:15:39 +03:00
|
|
|
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
2019-10-08 13:07:47 +03:00
|
|
|
if (aUseTripleBuffering) {
|
2018-11-05 12:58:37 +03:00
|
|
|
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-10-08 13:07:47 +03:00
|
|
|
if (aUseAlpha) {
|
|
|
|
// This could degrade performance. Use it only when it is necessary.
|
|
|
|
desc.AlphaMode = DXGI_ALPHA_MODE_PREMULTIPLIED;
|
|
|
|
} else {
|
|
|
|
desc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
|
|
|
|
}
|
2018-03-29 05:23:31 +03:00
|
|
|
desc.Flags = 0;
|
|
|
|
|
2019-10-08 13:07:47 +03:00
|
|
|
hr = dxgiFactory2->CreateSwapChainForComposition(mDevice, &desc, nullptr,
|
|
|
|
getter_AddRefs(swapChain1));
|
2018-03-29 05:23:31 +03:00
|
|
|
if (SUCCEEDED(hr) && swapChain1) {
|
|
|
|
DXGI_RGBA color = {1.0f, 1.0f, 1.0f, 1.0f};
|
|
|
|
swapChain1->SetBackgroundColor(&color);
|
2019-10-08 13:07:47 +03:00
|
|
|
return swapChain1;
|
2018-03-29 05:23:31 +03:00
|
|
|
}
|
2019-10-08 13:07:47 +03:00
|
|
|
|
|
|
|
return nullptr;
|
2018-03-29 05:23:31 +03:00
|
|
|
}
|
|
|
|
|
2019-10-29 23:50:33 +03:00
|
|
|
bool RenderCompositorANGLE::BeginFrame() {
|
2018-03-29 05:21:47 +03:00
|
|
|
mWidget->AsWindows()->UpdateCompositorWndSizeIfNecessary();
|
|
|
|
|
2019-10-31 14:59:17 +03:00
|
|
|
if (!UseCompositor()) {
|
|
|
|
if (mDCLayerTree) {
|
|
|
|
bool useAlpha = mWidget->AsWindows()->HasGlass();
|
|
|
|
// When Alpha usage is changed, SwapChain needs to be recreatd.
|
|
|
|
if (useAlpha != mUseAlpha) {
|
|
|
|
DestroyEGLSurface();
|
|
|
|
mBufferSize.reset();
|
|
|
|
|
|
|
|
RefPtr<IDXGISwapChain1> swapChain1 =
|
|
|
|
CreateSwapChainForDComp(mUseTripleBuffering, useAlpha);
|
|
|
|
if (swapChain1) {
|
|
|
|
mSwapChain = swapChain1;
|
|
|
|
mUseAlpha = useAlpha;
|
|
|
|
mDCLayerTree->SetDefaultSwapChain(swapChain1);
|
2019-11-13 01:13:41 +03:00
|
|
|
// When alpha is used, we want to disable partial present.
|
|
|
|
// See Bug 1595027.
|
|
|
|
if (useAlpha) {
|
|
|
|
mFullRender = true;
|
|
|
|
}
|
2019-10-31 14:59:17 +03:00
|
|
|
} else {
|
|
|
|
gfxCriticalNote << "Failed to re-create SwapChain";
|
|
|
|
RenderThread::Get()->HandleWebRenderError(
|
|
|
|
WebRenderError::NEW_SURFACE);
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-08 13:07:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 14:59:17 +03:00
|
|
|
if (!ResizeBufferIfNeeded()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-01 15:39:31 +03:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-06-11 10:28:30 +03:00
|
|
|
if (RenderThread::Get()->SyncObjectNeeded() && mSyncObject) {
|
2020-02-05 12:39:28 +03:00
|
|
|
if (!mSyncObject->Synchronize(/* aFallible */ true)) {
|
|
|
|
// It's timeout or other error. Handle the device-reset here.
|
|
|
|
RenderThread::Get()->HandleDeviceReset("SyncObject", /* aNotify */ true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-01-19 05:01:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:15:20 +03:00
|
|
|
RenderedFrameId RenderCompositorANGLE::EndFrame(
|
2020-02-19 21:34:51 +03:00
|
|
|
const nsTArray<DeviceIntRect>& aDirtyRects) {
|
2019-11-04 19:15:20 +03:00
|
|
|
RenderedFrameId frameId = GetNextRenderFrameId();
|
2019-12-02 13:41:57 +03:00
|
|
|
InsertGraphicsCommandsFinishedWaitQuery(frameId);
|
2018-01-19 05:01:04 +03:00
|
|
|
|
2019-10-31 14:59:17 +03:00
|
|
|
if (!UseCompositor()) {
|
2020-02-06 22:49:25 +03:00
|
|
|
auto start = TimeStamp::Now();
|
2019-10-31 14:59:17 +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);
|
|
|
|
}
|
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
|
|
|
}
|
2019-11-03 13:57:03 +03:00
|
|
|
|
|
|
|
const LayoutDeviceIntSize& bufferSize = mBufferSize.ref();
|
|
|
|
|
2019-11-13 01:13:41 +03:00
|
|
|
// During high contrast mode, alpha is used. In this case,
|
|
|
|
// IDXGISwapChain1::Present1 shows nothing with compositor window.
|
|
|
|
// In this case, we want to disable partial present by full render.
|
|
|
|
// See Bug 1595027
|
|
|
|
MOZ_ASSERT_IF(mUsePartialPresent && mUseAlpha, mFullRender);
|
|
|
|
|
2020-11-12 04:30:10 +03:00
|
|
|
if (mUsePartialPresent && !mUseAlpha && mSwapChain1) {
|
2019-11-03 13:57:03 +03:00
|
|
|
// Clear full render flag.
|
|
|
|
mFullRender = false;
|
|
|
|
// If there is no diry rect, we skip SwapChain present.
|
2020-02-19 21:34:51 +03:00
|
|
|
if (!aDirtyRects.IsEmpty()) {
|
|
|
|
StackArray<RECT, 1> rects(aDirtyRects.Length());
|
2020-02-19 22:34:16 +03:00
|
|
|
for (size_t i = 0; i < aDirtyRects.Length(); ++i) {
|
|
|
|
const DeviceIntRect& rect = aDirtyRects[i];
|
2019-11-03 13:57:03 +03:00
|
|
|
// Clip rect to bufferSize
|
|
|
|
rects[i].left =
|
|
|
|
std::max(0, std::min(rect.origin.x, bufferSize.width));
|
|
|
|
rects[i].top =
|
|
|
|
std::max(0, std::min(rect.origin.y, bufferSize.height));
|
|
|
|
rects[i].right = std::max(
|
|
|
|
0, std::min(rect.origin.x + rect.size.width, bufferSize.width));
|
|
|
|
rects[i].bottom = std::max(
|
|
|
|
0, std::min(rect.origin.y + rect.size.height, bufferSize.height));
|
|
|
|
}
|
|
|
|
|
|
|
|
DXGI_PRESENT_PARAMETERS params;
|
|
|
|
PodZero(¶ms);
|
2020-02-19 21:34:51 +03:00
|
|
|
params.DirtyRectsCount = aDirtyRects.Length();
|
2019-11-03 13:57:03 +03:00
|
|
|
params.pDirtyRects = rects.data();
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
hr = mSwapChain1->Present1(0, 0, ¶ms);
|
|
|
|
if (FAILED(hr) && hr != DXGI_STATUS_OCCLUDED) {
|
|
|
|
gfxCriticalNote << "Present1 failed: " << gfx::hexa(hr);
|
|
|
|
mFullRender = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mSwapChain->Present(0, 0);
|
|
|
|
}
|
2020-02-06 22:49:25 +03:00
|
|
|
auto end = TimeStamp::Now();
|
|
|
|
mozilla::Telemetry::Accumulate(mozilla::Telemetry::COMPOSITE_SWAP_TIME,
|
2020-02-17 17:39:31 +03:00
|
|
|
(end - start).ToMilliseconds() * 10.);
|
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
|
|
|
}
|
|
|
|
|
2020-01-24 02:52:05 +03:00
|
|
|
if (mDisablingNativeCompositor) {
|
|
|
|
// During disabling native compositor, we need to wait all gpu tasks
|
|
|
|
// complete. Otherwise, rendering window could cause white flash.
|
|
|
|
WaitForPreviousGraphicsCommandsFinishedQuery(/* aWaitAll */ true);
|
|
|
|
mDisablingNativeCompositor = false;
|
|
|
|
}
|
|
|
|
|
2019-10-14 15:55:01 +03:00
|
|
|
if (mDCLayerTree) {
|
|
|
|
mDCLayerTree->MaybeUpdateDebug();
|
2020-01-24 02:52:05 +03:00
|
|
|
mDCLayerTree->MaybeCommit();
|
2019-10-14 15:55:01 +03:00
|
|
|
}
|
2019-11-04 19:15:20 +03:00
|
|
|
|
|
|
|
return frameId;
|
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-12-02 13:41:57 +03:00
|
|
|
return WaitForPreviousGraphicsCommandsFinishedQuery();
|
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;
|
|
|
|
}
|
|
|
|
|
2019-11-03 13:57:03 +03:00
|
|
|
if (mUsePartialPresent) {
|
|
|
|
mFullRender = true;
|
|
|
|
}
|
2019-09-03 15:36:09 +03:00
|
|
|
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(
|
2020-08-07 10:14:46 +03:00
|
|
|
LOCAL_EGL_D3D_TEXTURE_ANGLE, buffer, mEGLConfig, pbuffer_attribs);
|
2018-02-01 15:39:31 +03:00
|
|
|
|
2020-08-07 10:14:46 +03:00
|
|
|
if (!surface) {
|
|
|
|
EGLint err = egl->mLib->fGetError();
|
2018-02-01 15:39:31 +03:00
|
|
|
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);
|
2020-08-07 10:14:46 +03:00
|
|
|
egl->fDestroySurface(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; }
|
|
|
|
|
2019-11-01 14:01:34 +03:00
|
|
|
void RenderCompositorANGLE::Update() {
|
|
|
|
// Update compositor window's size if it exists.
|
|
|
|
// It needs to be called here, since OS might update compositor
|
|
|
|
// window's size at unexpected timing.
|
|
|
|
mWidget->AsWindows()->UpdateCompositorWndSizeIfNecessary();
|
|
|
|
}
|
|
|
|
|
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() {
|
2019-10-31 14:59:17 +03:00
|
|
|
if (!UseCompositor()) {
|
|
|
|
MOZ_ASSERT(mBufferSize.isSome());
|
|
|
|
if (mBufferSize.isNothing()) {
|
|
|
|
return LayoutDeviceIntSize();
|
|
|
|
}
|
|
|
|
return mBufferSize.ref();
|
|
|
|
} else {
|
|
|
|
return mWidget->GetClientSize();
|
2018-02-01 15:39:31 +03:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2019-12-02 13:41:57 +03:00
|
|
|
void RenderCompositorANGLE::InsertGraphicsCommandsFinishedWaitQuery(
|
|
|
|
RenderedFrameId aFrameId) {
|
2018-11-12 04:14:55 +03:00
|
|
|
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);
|
2019-11-04 19:15:20 +03:00
|
|
|
mWaitForPresentQueries.emplace(aFrameId, query);
|
2018-01-19 05:01:04 +03:00
|
|
|
}
|
|
|
|
|
2020-01-24 02:52:05 +03:00
|
|
|
bool RenderCompositorANGLE::WaitForPreviousGraphicsCommandsFinishedQuery(
|
|
|
|
bool aWaitAll) {
|
2018-11-05 12:58:37 +03:00
|
|
|
size_t waitLatency = mUseTripleBuffering ? 3 : 2;
|
2020-01-24 02:52:05 +03:00
|
|
|
if (aWaitAll) {
|
|
|
|
waitLatency = 1;
|
|
|
|
}
|
2018-11-05 12:58:37 +03:00
|
|
|
|
|
|
|
while (mWaitForPresentQueries.size() >= waitLatency) {
|
2019-11-04 19:15:20 +03:00
|
|
|
auto queryPair = mWaitForPresentQueries.front();
|
2018-01-19 05:01:04 +03:00
|
|
|
BOOL result;
|
2019-11-04 19:15:20 +03:00
|
|
|
bool ret =
|
|
|
|
layers::WaitForFrameGPUQuery(mDevice, mCtx, queryPair.second, &result);
|
2018-11-05 12:58:37 +03:00
|
|
|
|
2019-07-11 12:41:38 +03:00
|
|
|
if (!ret) {
|
2019-11-04 19:15:20 +03:00
|
|
|
mWaitForPresentQueries.pop();
|
2019-07-11 12:41:38 +03:00
|
|
|
return false;
|
|
|
|
}
|
2019-11-04 19:15:20 +03:00
|
|
|
|
|
|
|
// Recycle query for later use.
|
|
|
|
mRecycledQuery = queryPair.second;
|
|
|
|
mLastCompletedFrameId = queryPair.first;
|
|
|
|
mWaitForPresentQueries.pop();
|
2019-07-11 12:41:38 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:15:20 +03:00
|
|
|
RenderedFrameId RenderCompositorANGLE::GetLastCompletedFrameId() {
|
|
|
|
while (!mWaitForPresentQueries.empty()) {
|
|
|
|
auto queryPair = mWaitForPresentQueries.front();
|
|
|
|
if (mCtx->GetData(queryPair.second, nullptr, 0, 0) != S_OK) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mRecycledQuery = queryPair.second;
|
|
|
|
mLastCompletedFrameId = queryPair.first;
|
|
|
|
mWaitForPresentQueries.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mLastCompletedFrameId;
|
|
|
|
}
|
|
|
|
|
2019-12-06 16:06:21 +03:00
|
|
|
RenderedFrameId RenderCompositorANGLE::UpdateFrameId() {
|
|
|
|
RenderedFrameId frameId = GetNextRenderFrameId();
|
|
|
|
InsertGraphicsCommandsFinishedWaitQuery(frameId);
|
|
|
|
return frameId;
|
|
|
|
}
|
|
|
|
|
2019-07-11 12:41:38 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-10-31 14:59:17 +03:00
|
|
|
bool RenderCompositorANGLE::UseCompositor() {
|
2020-01-24 02:52:05 +03:00
|
|
|
if (!mUseNativeCompositor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-16 06:50:31 +03:00
|
|
|
if (!mDCLayerTree || !gfx::gfxVars::UseWebRenderCompositor()) {
|
2019-10-31 14:59:17 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-24 02:52:05 +03:00
|
|
|
bool RenderCompositorANGLE::SupportAsyncScreenshot() {
|
|
|
|
return !UseCompositor() && !mDisablingNativeCompositor;
|
|
|
|
}
|
|
|
|
|
2019-10-31 14:59:17 +03:00
|
|
|
bool RenderCompositorANGLE::ShouldUseNativeCompositor() {
|
|
|
|
return UseCompositor();
|
|
|
|
}
|
|
|
|
|
2019-11-07 03:57:23 +03:00
|
|
|
uint32_t RenderCompositorANGLE::GetMaxUpdateRects() {
|
|
|
|
if (UseCompositor() &&
|
|
|
|
StaticPrefs::gfx_webrender_compositor_max_update_rects_AtStartup() > 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-31 14:59:17 +03:00
|
|
|
void RenderCompositorANGLE::CompositorBeginFrame() {
|
|
|
|
mDCLayerTree->CompositorBeginFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderCompositorANGLE::CompositorEndFrame() {
|
|
|
|
mDCLayerTree->CompositorEndFrame();
|
|
|
|
}
|
|
|
|
|
2019-12-18 00:44:03 +03:00
|
|
|
void RenderCompositorANGLE::Bind(wr::NativeTileId aId,
|
2019-10-31 14:59:17 +03:00
|
|
|
wr::DeviceIntPoint* aOffset, uint32_t* aFboId,
|
2020-02-12 07:27:15 +03:00
|
|
|
wr::DeviceIntRect aDirtyRect,
|
|
|
|
wr::DeviceIntRect aValidRect) {
|
|
|
|
mDCLayerTree->Bind(aId, aOffset, aFboId, aDirtyRect, aValidRect);
|
2019-10-31 14:59:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderCompositorANGLE::Unbind() { mDCLayerTree->Unbind(); }
|
|
|
|
|
|
|
|
void RenderCompositorANGLE::CreateSurface(wr::NativeSurfaceId aId,
|
2020-03-10 05:17:35 +03:00
|
|
|
wr::DeviceIntPoint aVirtualOffset,
|
2020-01-06 23:11:21 +03:00
|
|
|
wr::DeviceIntSize aTileSize,
|
|
|
|
bool aIsOpaque) {
|
2020-03-10 05:17:35 +03:00
|
|
|
mDCLayerTree->CreateSurface(aId, aVirtualOffset, aTileSize, aIsOpaque);
|
2019-10-31 14:59:17 +03:00
|
|
|
}
|
|
|
|
|
2020-09-09 04:04:53 +03:00
|
|
|
void RenderCompositorANGLE::CreateExternalSurface(wr::NativeSurfaceId aId,
|
|
|
|
bool aIsOpaque) {
|
|
|
|
mDCLayerTree->CreateExternalSurface(aId, aIsOpaque);
|
|
|
|
}
|
|
|
|
|
2019-10-31 14:59:17 +03:00
|
|
|
void RenderCompositorANGLE::DestroySurface(NativeSurfaceId aId) {
|
|
|
|
mDCLayerTree->DestroySurface(aId);
|
|
|
|
}
|
|
|
|
|
2020-01-06 23:11:21 +03:00
|
|
|
void RenderCompositorANGLE::CreateTile(wr::NativeSurfaceId aId, int aX,
|
|
|
|
int aY) {
|
|
|
|
mDCLayerTree->CreateTile(aId, aX, aY);
|
2019-12-18 00:44:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderCompositorANGLE::DestroyTile(wr::NativeSurfaceId aId, int aX,
|
|
|
|
int aY) {
|
|
|
|
mDCLayerTree->DestroyTile(aId, aX, aY);
|
|
|
|
}
|
|
|
|
|
2020-09-09 04:04:53 +03:00
|
|
|
void RenderCompositorANGLE::AttachExternalImage(
|
|
|
|
wr::NativeSurfaceId aId, wr::ExternalImageId aExternalImage) {
|
|
|
|
mDCLayerTree->AttachExternalImage(aId, aExternalImage);
|
|
|
|
}
|
|
|
|
|
2020-08-04 04:19:59 +03:00
|
|
|
void RenderCompositorANGLE::AddSurface(
|
|
|
|
wr::NativeSurfaceId aId, const wr::CompositorSurfaceTransform& aTransform,
|
2020-08-07 00:14:45 +03:00
|
|
|
wr::DeviceIntRect aClipRect, wr::ImageRendering aImageRendering) {
|
|
|
|
mDCLayerTree->AddSurface(aId, aTransform, aClipRect, aImageRendering);
|
2019-10-31 14:59:17 +03:00
|
|
|
}
|
|
|
|
|
2020-03-10 05:17:35 +03:00
|
|
|
CompositorCapabilities RenderCompositorANGLE::GetCompositorCapabilities() {
|
|
|
|
CompositorCapabilities caps;
|
|
|
|
|
|
|
|
caps.virtual_surface_size = VIRTUAL_SURFACE_SIZE;
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2020-01-24 02:52:05 +03:00
|
|
|
void RenderCompositorANGLE::EnableNativeCompositor(bool aEnable) {
|
|
|
|
// XXX Re-enable native compositor is not handled yet.
|
|
|
|
MOZ_RELEASE_ASSERT(!mDisablingNativeCompositor);
|
|
|
|
MOZ_RELEASE_ASSERT(!aEnable);
|
|
|
|
|
|
|
|
if (!UseCompositor()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mUseNativeCompositor = false;
|
|
|
|
mDCLayerTree->DisableNativeCompositor();
|
|
|
|
|
|
|
|
bool useAlpha = mWidget->AsWindows()->HasGlass();
|
|
|
|
DestroyEGLSurface();
|
|
|
|
mBufferSize.reset();
|
|
|
|
|
|
|
|
RefPtr<IDXGISwapChain1> swapChain1 =
|
|
|
|
CreateSwapChainForDComp(mUseTripleBuffering, useAlpha);
|
|
|
|
if (swapChain1) {
|
|
|
|
mSwapChain = swapChain1;
|
|
|
|
mUseAlpha = useAlpha;
|
|
|
|
mDCLayerTree->SetDefaultSwapChain(swapChain1);
|
|
|
|
// When alpha is used, we want to disable partial present.
|
|
|
|
// See Bug 1595027.
|
|
|
|
if (useAlpha) {
|
|
|
|
mFullRender = true;
|
|
|
|
}
|
|
|
|
ResizeBufferIfNeeded();
|
|
|
|
} else {
|
|
|
|
gfxCriticalNote << "Failed to re-create SwapChain";
|
|
|
|
RenderThread::Get()->HandleWebRenderError(WebRenderError::NEW_SURFACE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mDisablingNativeCompositor = true;
|
|
|
|
}
|
|
|
|
|
2019-11-03 13:57:03 +03:00
|
|
|
void RenderCompositorANGLE::InitializeUsePartialPresent() {
|
2020-03-17 13:26:50 +03:00
|
|
|
// Even when mSwapChain1 is null, we could enable WR partial present, since
|
|
|
|
// when mSwapChain1 is null, SwapChain is blit model swap chain with one
|
|
|
|
// buffer.
|
|
|
|
if (UseCompositor() || mWidget->AsWindows()->HasFxrOutputHandler() ||
|
2019-12-17 08:05:30 +03:00
|
|
|
gfx::gfxVars::WebRenderMaxPartialPresentRects() <= 0) {
|
2019-11-03 13:57:03 +03:00
|
|
|
mUsePartialPresent = false;
|
|
|
|
} else {
|
|
|
|
mUsePartialPresent = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-05 12:06:59 +03:00
|
|
|
bool RenderCompositorANGLE::UsePartialPresent() { return mUsePartialPresent; }
|
|
|
|
|
2020-06-05 08:03:40 +03:00
|
|
|
bool RenderCompositorANGLE::RequestFullRender() { return mFullRender; }
|
2019-11-03 13:57:03 +03:00
|
|
|
|
|
|
|
uint32_t RenderCompositorANGLE::GetMaxPartialPresentRects() {
|
|
|
|
if (!mUsePartialPresent) {
|
|
|
|
return 0;
|
|
|
|
}
|
2019-12-17 08:05:30 +03:00
|
|
|
return gfx::gfxVars::WebRenderMaxPartialPresentRects();
|
2019-11-03 13:57:03 +03:00
|
|
|
}
|
|
|
|
|
2019-11-30 06:14:58 +03:00
|
|
|
bool RenderCompositorANGLE::MaybeReadback(
|
|
|
|
const gfx::IntSize& aReadbackSize, const wr::ImageFormat& aReadbackFormat,
|
2020-08-14 21:40:09 +03:00
|
|
|
const Range<uint8_t>& aReadbackBuffer, bool* aNeedsYFlip) {
|
2019-11-30 06:14:58 +03:00
|
|
|
MOZ_ASSERT(aReadbackFormat == wr::ImageFormat::BGRA8);
|
|
|
|
|
|
|
|
if (!UseCompositor()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-17 17:39:31 +03:00
|
|
|
auto start = TimeStamp::Now();
|
|
|
|
|
2019-11-30 06:14:58 +03:00
|
|
|
HDC nulldc = ::GetDC(NULL);
|
|
|
|
HDC dc = ::CreateCompatibleDC(nulldc);
|
|
|
|
::ReleaseDC(nullptr, nulldc);
|
|
|
|
if (!dc) {
|
|
|
|
gfxCriticalError() << "CreateCompatibleDC failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BITMAPV4HEADER header;
|
|
|
|
memset(&header, 0, sizeof(BITMAPV4HEADER));
|
|
|
|
header.bV4Size = sizeof(BITMAPV4HEADER);
|
|
|
|
header.bV4Width = aReadbackSize.width;
|
|
|
|
header.bV4Height = -LONG(aReadbackSize.height); // top-to-buttom DIB
|
|
|
|
header.bV4Planes = 1;
|
|
|
|
header.bV4BitCount = 32;
|
|
|
|
header.bV4V4Compression = BI_BITFIELDS;
|
|
|
|
header.bV4RedMask = 0x00FF0000;
|
|
|
|
header.bV4GreenMask = 0x0000FF00;
|
|
|
|
header.bV4BlueMask = 0x000000FF;
|
|
|
|
header.bV4AlphaMask = 0xFF000000;
|
|
|
|
|
|
|
|
void* readbackBits = nullptr;
|
|
|
|
HBITMAP bitmap =
|
|
|
|
::CreateDIBSection(dc, reinterpret_cast<BITMAPINFO*>(&header),
|
|
|
|
DIB_RGB_COLORS, &readbackBits, nullptr, 0);
|
|
|
|
if (!bitmap) {
|
|
|
|
::DeleteDC(dc);
|
|
|
|
gfxCriticalError() << "CreateDIBSection failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
::SelectObject(dc, bitmap);
|
|
|
|
|
|
|
|
UINT flags = PW_CLIENTONLY | PW_RENDERFULLCONTENT;
|
|
|
|
HWND hwnd = mWidget->AsWindows()->GetHwnd();
|
|
|
|
|
|
|
|
mDCLayerTree->WaitForCommitCompletion();
|
|
|
|
|
|
|
|
BOOL result = ::PrintWindow(hwnd, dc, flags);
|
|
|
|
if (!result) {
|
|
|
|
::DeleteObject(bitmap);
|
|
|
|
::DeleteDC(dc);
|
|
|
|
gfxCriticalError() << "PrintWindow failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
::GdiFlush();
|
|
|
|
|
|
|
|
memcpy(&aReadbackBuffer[0], readbackBits, aReadbackBuffer.length());
|
|
|
|
|
|
|
|
::DeleteObject(bitmap);
|
|
|
|
::DeleteDC(dc);
|
|
|
|
|
2020-02-17 17:39:31 +03:00
|
|
|
uint32_t latencyMs = round((TimeStamp::Now() - start).ToMilliseconds());
|
|
|
|
if (latencyMs > 500) {
|
|
|
|
gfxCriticalNote << "Readback took too long: " << latencyMs << " ms";
|
|
|
|
}
|
|
|
|
|
2020-08-14 21:40:09 +03:00
|
|
|
if (aNeedsYFlip) {
|
|
|
|
*aNeedsYFlip = false;
|
|
|
|
}
|
|
|
|
|
2019-11-30 06:14:58 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-19 05:01:04 +03:00
|
|
|
} // namespace wr
|
|
|
|
} // namespace mozilla
|