Bug 1582371 - Add DCLayerTree class r=nical

Preparation work for adding DirectComposition support. It does not add a new functionality.

Differential Revision: https://phabricator.services.mozilla.com/D46429

--HG--
extra : moz-landing-system : lando
This commit is contained in:
sotaro 2019-09-19 18:15:11 +00:00
Родитель bcb6a0958d
Коммит 5182120673
5 изменённых файлов: 128 добавлений и 40 удалений

Просмотреть файл

@ -0,0 +1,66 @@
/* -*- 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 "DCLayerTree.h"
#include "mozilla/gfx/DeviceManagerDx.h"
#undef NTDDI_VERSION
#define NTDDI_VERSION NTDDI_WIN8
#include <d3d11.h>
#include <dcomp.h>
#include <dxgi1_2.h>
namespace mozilla {
namespace wr {
/* static */
UniquePtr<DCLayerTree> DCLayerTree::Create(HWND aHwnd) {
RefPtr<IDCompositionDevice> dCompDevice =
gfx::DeviceManagerDx::Get()->GetDirectCompositionDevice();
if (!dCompDevice) {
return nullptr;
}
auto layerTree = MakeUnique<DCLayerTree>(dCompDevice);
if (!layerTree->Initialize(aHwnd)) {
return nullptr;
}
return layerTree;
}
DCLayerTree::DCLayerTree(IDCompositionDevice* aCompositionDevice)
: mCompositionDevice(aCompositionDevice) {}
DCLayerTree::~DCLayerTree() {}
bool DCLayerTree::Initialize(HWND aHwnd) {
HRESULT hr = mCompositionDevice->CreateTargetForHwnd(
aHwnd, TRUE, getter_AddRefs(mCompositionTarget));
if (FAILED(hr)) {
gfxCriticalNote << "Could not create DCompositionTarget: " << gfx::hexa(hr);
return false;
}
hr = mCompositionDevice->CreateVisual(getter_AddRefs(mRootVisual));
if (FAILED(hr)) {
gfxCriticalNote << "Could not create DCompositionVisualt: "
<< gfx::hexa(hr);
return false;
}
return true;
}
void DCLayerTree::SetDefaultSwapChain(IDXGISwapChain1* aSwapChain) {
mRootVisual->SetContent(aSwapChain);
mCompositionTarget->SetRoot(mRootVisual);
mCompositionDevice->Commit();
}
} // namespace wr
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,47 @@
/* -*- 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/. */
#ifndef MOZILLA_GFX_DCLAYER_TREE_H
#define MOZILLA_GFX_DCLAYER_TREE_H
#include <windows.h>
#include "mozilla/RefPtr.h"
#include "mozilla/UniquePtr.h"
struct IDCompositionDevice;
struct IDCompositionTarget;
struct IDCompositionVisual;
struct IDXGISwapChain1;
namespace mozilla {
namespace wr {
/**
* DCLayerTree manages direct composition layers.
* It does not manage gecko's layers::Layer.
*/
class DCLayerTree {
public:
static UniquePtr<DCLayerTree> Create(HWND aHwnd);
explicit DCLayerTree(IDCompositionDevice* aCompositionDevice);
~DCLayerTree();
void SetDefaultSwapChain(IDXGISwapChain1* aSwapChain);
protected:
bool Initialize(HWND aHwnd);
RefPtr<IDCompositionDevice> mCompositionDevice;
RefPtr<IDCompositionTarget> mCompositionTarget;
RefPtr<IDCompositionVisual> mRootVisual;
};
} // namespace wr
} // namespace mozilla
#endif

Просмотреть файл

@ -14,6 +14,7 @@
#include "mozilla/gfx/Logging.h"
#include "mozilla/layers/HelpersD3D11.h"
#include "mozilla/layers/SyncObject.h"
#include "mozilla/webrender/DCLayerTree.h"
#include "mozilla/webrender/RenderThread.h"
#include "mozilla/widget/CompositorWidget.h"
#include "mozilla/widget/WinCompositorWidget.h"
@ -257,44 +258,19 @@ void RenderCompositorANGLE::CreateSwapChainForDCompIfPossible(
return;
}
RefPtr<IDCompositionDevice> dCompDevice =
gfx::DeviceManagerDx::Get()->GetDirectCompositionDevice();
if (!dCompDevice) {
return;
}
MOZ_ASSERT(XRE_IsGPUProcess());
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)));
}
HWND hwnd = mWidget->AsWindows()->GetCompositorHwnd();
if (!hwnd) {
gfxCriticalNote << "Compositor window was not created ";
return;
}
HRESULT hr = dCompDevice->CreateTargetForHwnd(
hwnd, TRUE, getter_AddRefs(mCompositionTarget));
if (FAILED(hr)) {
gfxCriticalNote << "Could not create DCompositionTarget: " << gfx::hexa(hr);
return;
}
hr = dCompDevice->CreateVisual(getter_AddRefs(mVisual));
if (FAILED(hr)) {
gfxCriticalNote << "Could not create DCompositionVisualt: "
<< gfx::hexa(hr);
mDCLayerTree = DCLayerTree::Create(hwnd);
if (!mDCLayerTree) {
return;
}
MOZ_ASSERT(XRE_IsGPUProcess());
HRESULT hr;
RefPtr<IDXGISwapChain1> swapChain1;
bool useTripleBuffering = gfx::gfxVars::UseWebRenderTripleBufferingWin();
@ -326,11 +302,11 @@ void RenderCompositorANGLE::CreateSwapChainForDCompIfPossible(
DXGI_RGBA color = {1.0f, 1.0f, 1.0f, 1.0f};
swapChain1->SetBackgroundColor(&color);
mSwapChain = swapChain1;
mVisual->SetContent(swapChain1);
mCompositionTarget->SetRoot(mVisual);
mCompositionDevice = dCompDevice;
mCompositionDevice->Commit();
mDCLayerTree->SetDefaultSwapChain(swapChain1);
mUseTripleBuffering = useTripleBuffering;
} else {
// Clear CLayerTree on falire
mDCLayerTree = nullptr;
}
}

Просмотреть файл

@ -17,9 +17,6 @@
struct ID3D11DeviceContext;
struct ID3D11Device;
struct ID3D11Query;
struct IDCompositionDevice;
struct IDCompositionTarget;
struct IDCompositionVisual;
struct IDXGIFactory2;
struct IDXGISwapChain;
@ -30,6 +27,8 @@ class GLLibraryEGL;
namespace wr {
class DCLayerTree;
class RenderCompositorANGLE : public RenderCompositor {
public:
static UniquePtr<RenderCompositor> Create(
@ -51,7 +50,7 @@ class RenderCompositorANGLE : public RenderCompositor {
bool UseANGLE() const override { return true; }
bool UseDComp() const override { return !!mCompositionDevice; }
bool UseDComp() const override { return !!mDCLayerTree; }
bool UseTripleBuffering() const override { return mUseTripleBuffering; }
@ -79,9 +78,7 @@ class RenderCompositorANGLE : public RenderCompositor {
RefPtr<ID3D11DeviceContext> mCtx;
RefPtr<IDXGISwapChain> mSwapChain;
RefPtr<IDCompositionDevice> mCompositionDevice;
RefPtr<IDCompositionTarget> mCompositionTarget;
RefPtr<IDCompositionVisual> mVisual;
UniquePtr<DCLayerTree> mDCLayerTree;
std::queue<RefPtr<ID3D11Query>> mWaitForPresentQueries;
RefPtr<ID3D11Query> mRecycledQuery;

Просмотреть файл

@ -60,6 +60,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
if CONFIG['MOZ_ENABLE_D3D10_LAYER']:
DEFINES['MOZ_ENABLE_D3D10_LAYER'] = True
EXPORTS.mozilla.webrender += [
'DCLayerTree.h',
'RenderCompositorANGLE.h',
'RenderD3D11TextureHostOGL.h',
]
@ -67,6 +68,7 @@ if CONFIG['MOZ_ENABLE_D3D10_LAYER']:
'RenderD3D11TextureHostOGL.cpp',
]
SOURCES += [
'DCLayerTree.cpp',
'RenderCompositorANGLE.cpp',
]