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(
|
2021-04-28 15:33:55 +03:00
|
|
|
const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError) {
|
2021-03-17 13:51:45 +03:00
|
|
|
const auto& gl = RenderThread::Get()->SingletonGL(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 =
|
2021-04-28 15:33:55 +03:00
|
|
|
MakeUnique<RenderCompositorANGLE>(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(
|
2021-04-28 15:33:55 +03:00
|
|
|
const RefPtr<widget::CompositorWidget>& aWidget)
|
|
|
|
: RenderCompositor(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) {
|
2021-03-17 13:51:45 +03:00
|
|
|
const auto& gl = RenderThread::Get()->SingletonGL(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.
|
2021-03-17 13:51:45 +03:00
|
|
|
RenderThread::Get()->ClearSingletonGL();
|
2018-06-13 18:01:06 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-12 01:40:40 +03:00
|
|
|
bool RenderCompositorANGLE::Initialize(nsACString& aError) {
|
2020-12-07 23:36:11 +03:00
|
|
|
// TODO(aosmond): This causes us to lose WebRender because it is unable to
|
|
|
|
// distinguish why we failed and retry once the reset is complete. This does
|
|
|
|
// appear to happen in the wild, so we really should try to do something
|
|
|
|
// differently here.
|
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;
|
|
|
|
}
|
2021-03-17 13:51:45 +03:00
|
|
|
const auto gl = RenderThread::Get()->SingletonGL(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,
|
2021-05-17 22:54:35 +03:00
|
|
|
/* enableDepthBuffer */ false, 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();
|
2020-11-12 04:31:19 +03:00
|
|
|
} else if (
|
2020-04-14 06:27:12 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-01-15 06:08:27 +03:00
|
|
|
if (!mSwapChain && dxgiFactory2) {
|
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
|
|
|
|
2021-01-26 01:11:51 +03:00
|
|
|
bool useFlipSequential = gfx::gfxVars::UseWebRenderFlipSequentialWin();
|
|
|
|
if (useFlipSequential && !mWidget->AsWindows()->GetCompositorHwnd()) {
|
|
|
|
useFlipSequential = false;
|
|
|
|
gfxCriticalNoteOnce << "FLIP_SEQUENTIAL needs CompositorHwnd. Fallback";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useFlipSequential) {
|
2019-07-19 12:26:03 +03:00
|
|
|
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;
|
2021-01-26 01:11:51 +03:00
|
|
|
} else if (useFlipSequential) {
|
2021-01-17 01:28:06 +03:00
|
|
|
gfxCriticalNoteOnce << "FLIP_SEQUENTIAL is not supported. Fallback";
|
2018-02-01 15:39:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mSwapChain) {
|
2021-03-12 15:52:16 +03:00
|
|
|
if (mWidget->AsWindows()->GetCompositorHwnd()) {
|
|
|
|
// Destroy compositor window.
|
|
|
|
mWidget->AsWindows()->DestroyCompositorWindow();
|
|
|
|
hwnd = mWidget->AsWindows()->GetHwnd();
|
|
|
|
}
|
|
|
|
|
2018-02-01 15:39:31 +03:00
|
|
|
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.
|
2020-12-07 23:36:11 +03:00
|
|
|
RenderThread::Get()->HandleDeviceReset(
|
2021-03-03 13:29:40 +03:00
|
|
|
"SyncObject", LOCAL_GL_UNKNOWN_CONTEXT_RESET_ARB);
|
2020-02-05 12:39:28 +03:00
|
|
|
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()) {
|
2021-01-21 01:28:50 +03:00
|
|
|
int rectsCount = 0;
|
2020-02-19 21:34:51 +03:00
|
|
|
StackArray<RECT, 1> rects(aDirtyRects.Length());
|
2021-01-21 01:28:50 +03:00
|
|
|
|
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
|
2021-06-02 15:47:03 +03:00
|
|
|
int left = std::max(0, std::min(rect.min.x, bufferSize.width));
|
|
|
|
int top = std::max(0, std::min(rect.min.y, bufferSize.height));
|
|
|
|
int right = std::max(0, std::min(rect.max.x, bufferSize.width));
|
|
|
|
int bottom = std::max(0, std::min(rect.max.y, bufferSize.height));
|
2021-01-21 01:28:50 +03:00
|
|
|
|
|
|
|
// When rect is not empty, the rect could be passed to Present1().
|
|
|
|
if (left < right && top < bottom) {
|
|
|
|
rects[rectsCount].left = left;
|
|
|
|
rects[rectsCount].top = top;
|
|
|
|
rects[rectsCount].right = right;
|
|
|
|
rects[rectsCount].bottom = bottom;
|
|
|
|
rectsCount++;
|
|
|
|
}
|
2019-11-03 13:57:03 +03:00
|
|
|
}
|
|
|
|
|
2021-01-21 01:28:50 +03:00
|
|
|
if (rectsCount > 0) {
|
|
|
|
DXGI_PRESENT_PARAMETERS params;
|
|
|
|
PodZero(¶ms);
|
|
|
|
params.DirtyRectsCount = rectsCount;
|
|
|
|
params.pDirtyRects = rects.data();
|
2019-11-03 13:57:03 +03:00
|
|
|
|
2021-01-21 01:28:50 +03:00
|
|
|
HRESULT hr;
|
|
|
|
hr = mSwapChain1->Present1(0, 0, ¶ms);
|
|
|
|
if (FAILED(hr) && hr != DXGI_STATUS_OCCLUDED) {
|
|
|
|
gfxCriticalNote << "Present1 failed: " << gfx::hexa(hr);
|
|
|
|
mFullRender = true;
|
|
|
|
}
|
2019-11-03 13:57:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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());
|
|
|
|
|
2021-03-17 13:51:45 +03:00
|
|
|
const auto gl = RenderThread::Get()->SingletonGL();
|
2019-06-26 09:03:23 +03:00
|
|
|
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 {
|
2020-12-22 02:40:59 +03:00
|
|
|
auto size = mWidget->GetClientSize();
|
|
|
|
// This size is used for WR DEBUG_OVERLAY. Its DCTile does not like 0.
|
|
|
|
size.width = std::max(size.width, 1);
|
|
|
|
size.height = std::max(size.height, 1);
|
2021-01-04 12:47:29 +03:00
|
|
|
return size;
|
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;
|
|
|
|
}
|
|
|
|
|
2020-12-07 23:36:11 +03:00
|
|
|
GLenum RenderCompositorANGLE::IsContextLost(bool aForce) {
|
|
|
|
// glGetGraphicsResetStatus does not always work to detect timeout detection
|
|
|
|
// and recovery (TDR). On Windows, ANGLE itself is just relying upon the same
|
|
|
|
// API, so we should not need to check it separately.
|
|
|
|
auto reason = mDevice->GetDeviceRemovedReason();
|
|
|
|
switch (reason) {
|
|
|
|
case S_OK:
|
|
|
|
return LOCAL_GL_NO_ERROR;
|
|
|
|
case DXGI_ERROR_DEVICE_REMOVED:
|
|
|
|
case DXGI_ERROR_DRIVER_INTERNAL_ERROR:
|
|
|
|
NS_WARNING("Device reset due to system / different device");
|
|
|
|
return LOCAL_GL_INNOCENT_CONTEXT_RESET_ARB;
|
|
|
|
case DXGI_ERROR_DEVICE_HUNG:
|
|
|
|
case DXGI_ERROR_DEVICE_RESET:
|
|
|
|
case DXGI_ERROR_INVALID_CALL:
|
|
|
|
gfxCriticalError() << "Device reset due to WR device: "
|
|
|
|
<< gfx::hexa(reason);
|
|
|
|
return LOCAL_GL_GUILTY_CONTEXT_RESET_ARB;
|
|
|
|
default:
|
|
|
|
gfxCriticalError() << "Device reset with WR device unexpected reason: "
|
|
|
|
<< gfx::hexa(reason);
|
|
|
|
return LOCAL_GL_UNKNOWN_CONTEXT_RESET_ARB;
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-02-24 17:15:02 +03:00
|
|
|
void RenderCompositorANGLE::GetCompositorCapabilities(
|
|
|
|
CompositorCapabilities* aCaps) {
|
2021-05-26 23:09:58 +03:00
|
|
|
RenderCompositor::GetCompositorCapabilities(aCaps);
|
|
|
|
|
2021-02-24 17:15:02 +03:00
|
|
|
aCaps->virtual_surface_size = VIRTUAL_SURFACE_SIZE;
|
2020-03-10 05:17:35 +03:00
|
|
|
}
|
|
|
|
|
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
|