Bug 1585278 - Add option of enabling performance debugging counters of DirectComposition r=nical,jrmuizel

IDCompositionDevice is replaced by IDCompositionDevice2. It is necessary for IDCompositionDeviceDebug usage. And for using IDCompositionDevice2, _WIN32_WINNT and NTDDI_VERSION is updated from Windows 8 to Windows 8.1.

Workaround MinGW build failure.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
sotaro 2019-10-07 20:09:17 +00:00
Родитель b4d8e0c7ca
Коммит 3546b3c622
5 изменённых файлов: 103 добавлений и 28 удалений

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

@ -27,8 +27,10 @@
#include "nsPrintfCString.h"
#include "nsString.h"
#undef _WIN32_WINNT
#define _WIN32_WINNT _WIN32_WINNT_WINBLUE
#undef NTDDI_VERSION
#define NTDDI_VERSION NTDDI_WIN8
#define NTDDI_VERSION NTDDI_WINBLUE
#include <d3d11.h>
#include <dcomp.h>
@ -47,9 +49,8 @@ StaticAutoPtr<DeviceManagerDx> DeviceManagerDx::sInstance;
// be used within InitializeD3D11.
decltype(D3D11CreateDevice)* sD3D11CreateDeviceFn = nullptr;
typedef HRESULT(WINAPI* PFN_DCOMPOSITION_CREATE_DEVICE)(
IDXGIDevice* dxgiDevice, REFIID iid, void** dcompositionDevice);
PFN_DCOMPOSITION_CREATE_DEVICE sDcompCreateDeviceFn = nullptr;
// It should only be used within CreateDirectCompositionDevice.
decltype(DCompositionCreateDevice2)* sDcompCreateDevice2Fn = nullptr;
// We don't have access to the DirectDrawCreateEx type in gfxWindowsPlatform.h,
// since it doesn't include ddraw.h, so we use a static here. It should only
@ -110,7 +111,7 @@ bool DeviceManagerDx::LoadDcomp() {
MOZ_ASSERT(gfxVars::UseWebRenderANGLE());
MOZ_ASSERT(gfxVars::UseWebRenderDCompWin());
if (sDcompCreateDeviceFn) {
if (sDcompCreateDevice2Fn) {
return true;
}
@ -119,9 +120,9 @@ bool DeviceManagerDx::LoadDcomp() {
return false;
}
sDcompCreateDeviceFn = reinterpret_cast<PFN_DCOMPOSITION_CREATE_DEVICE>(
::GetProcAddress(module, "DCompositionCreateDevice"));
if (!sDcompCreateDeviceFn) {
sDcompCreateDevice2Fn = (decltype(DCompositionCreateDevice2)*)GetProcAddress(
module, "DCompositionCreateDevice2");
if (!sDcompCreateDevice2Fn) {
return false;
}
@ -308,6 +309,9 @@ bool DeviceManagerDx::CreateCanvasDevice() {
}
void DeviceManagerDx::CreateDirectCompositionDevice() {
// Currently, MinGW build environment does not handle IDCompositionDesktopDevice
// and IDCompositionDevice2
#if !defined(__MINGW32__)
if (!gfxVars::UseWebRenderDCompWin()) {
return;
}
@ -327,11 +331,12 @@ void DeviceManagerDx::CreateDirectCompositionDevice() {
}
HRESULT hr;
RefPtr<IDCompositionDevice> compositionDevice;
RefPtr<IDCompositionDesktopDevice> desktopDevice;
MOZ_SEH_TRY {
hr = sDcompCreateDeviceFn(
dxgiDevice,
IID_PPV_ARGS((IDCompositionDevice**)getter_AddRefs(compositionDevice)));
hr = sDcompCreateDevice2Fn(
dxgiDevice.get(),
IID_PPV_ARGS(
(IDCompositionDesktopDevice**)getter_AddRefs(desktopDevice)));
}
MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { return; }
@ -339,7 +344,14 @@ void DeviceManagerDx::CreateDirectCompositionDevice() {
return;
}
RefPtr<IDCompositionDevice2> compositionDevice;
if (desktopDevice->QueryInterface(IID_PPV_ARGS(
(IDCompositionDevice2**)getter_AddRefs(compositionDevice))) != S_OK) {
return;
}
mDirectCompositionDevice = compositionDevice;
#endif
}
void DeviceManagerDx::ImportDeviceInfo(const D3D11DeviceStatus& aDeviceStatus) {
@ -1131,10 +1143,13 @@ RefPtr<ID3D11Device> DeviceManagerDx::GetCanvasDevice() {
return mCanvasDevice;
}
RefPtr<IDCompositionDevice> DeviceManagerDx::GetDirectCompositionDevice() {
// Currently, MinGW build environment does not handle IDCompositionDevice2
#if !defined(__MINGW32__)
RefPtr<IDCompositionDevice2> DeviceManagerDx::GetDirectCompositionDevice() {
MutexAutoLock lock(mDeviceLock);
return mDirectCompositionDevice;
}
#endif
unsigned DeviceManagerDx::GetCompositorFeatureLevel() const {
if (!mDeviceStatus) {
@ -1216,7 +1231,12 @@ bool DeviceManagerDx::CanUseP016() {
bool DeviceManagerDx::CanUseDComp() {
MutexAutoLock lock(mDeviceLock);
// Currently, MinGW build environment does not handle IDCompositionDevice2
#if !defined(__MINGW32__)
return !!mDirectCompositionDevice;
#else
return false;
#endif
}
void DeviceManagerDx::InitializeDirectDraw() {

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

@ -33,7 +33,7 @@
#endif
struct ID3D11Device;
struct IDCompositionDevice;
struct IDCompositionDevice2;
struct IDirectDraw7;
namespace mozilla {
@ -59,7 +59,10 @@ class DeviceManagerDx final {
RefPtr<ID3D11Device> GetContentDevice();
RefPtr<ID3D11Device> GetCanvasDevice();
RefPtr<ID3D11Device> GetImageDevice();
RefPtr<IDCompositionDevice> GetDirectCompositionDevice();
// Currently, MinGW build environment does not handle IDCompositionDevice2
#if !defined(__MINGW32__)
RefPtr<IDCompositionDevice2> GetDirectCompositionDevice();
#endif
RefPtr<ID3D11Device> GetVRDevice();
RefPtr<ID3D11Device> CreateDecoderDevice();
RefPtr<layers::MLGDevice> GetMLGDevice();
@ -172,8 +175,9 @@ class DeviceManagerDx final {
RefPtr<ID3D11Device> mImageDevice;
RefPtr<ID3D11Device> mVRDevice;
RefPtr<ID3D11Device> mDecoderDevice;
RefPtr<IDCompositionDevice> mDirectCompositionDevice;
#if !defined(__MINGW32__)
RefPtr<IDCompositionDevice2> mDirectCompositionDevice;
#endif
RefPtr<layers::DeviceAttachmentsD3D11> mCompositorAttachments;
RefPtr<layers::MLGDevice> mMLGDevice;
bool mCompositorDeviceSupportsVideo;

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

@ -7,9 +7,12 @@
#include "DCLayerTree.h"
#include "mozilla/gfx/DeviceManagerDx.h"
#include "mozilla/StaticPrefs_gfx.h"
#undef _WIN32_WINNT
#define _WIN32_WINNT _WIN32_WINNT_WINBLUE
#undef NTDDI_VERSION
#define NTDDI_VERSION NTDDI_WIN8
#define NTDDI_VERSION NTDDI_WINBLUE
#include <d3d11.h>
#include <dcomp.h>
@ -18,9 +21,13 @@
namespace mozilla {
namespace wr {
// Currently, MinGW build environment does not handle IDCompositionDesktopDevice
// and IDCompositionDevice2
#if !defined(__MINGW32__)
/* static */
UniquePtr<DCLayerTree> DCLayerTree::Create(HWND aHwnd) {
RefPtr<IDCompositionDevice> dCompDevice =
RefPtr<IDCompositionDevice2> dCompDevice =
gfx::DeviceManagerDx::Get()->GetDirectCompositionDevice();
if (!dCompDevice) {
return nullptr;
@ -34,14 +41,25 @@ UniquePtr<DCLayerTree> DCLayerTree::Create(HWND aHwnd) {
return layerTree;
}
DCLayerTree::DCLayerTree(IDCompositionDevice* aCompositionDevice)
DCLayerTree::DCLayerTree(IDCompositionDevice2* aCompositionDevice)
: mCompositionDevice(aCompositionDevice) {}
DCLayerTree::~DCLayerTree() {}
bool DCLayerTree::Initialize(HWND aHwnd) {
HRESULT hr = mCompositionDevice->CreateTargetForHwnd(
aHwnd, TRUE, getter_AddRefs(mCompositionTarget));
HRESULT hr;
RefPtr<IDCompositionDesktopDevice> desktopDevice;
hr = mCompositionDevice->QueryInterface(
(IDCompositionDesktopDevice**)getter_AddRefs(desktopDevice));
if (FAILED(hr)) {
gfxCriticalNote << "Failed to get IDCompositionDesktopDevice: "
<< gfx::hexa(hr);
return false;
}
hr = desktopDevice->CreateTargetForHwnd(aHwnd, TRUE,
getter_AddRefs(mCompositionTarget));
if (FAILED(hr)) {
gfxCriticalNote << "Could not create DCompositionTarget: " << gfx::hexa(hr);
return false;
@ -60,6 +78,18 @@ bool DCLayerTree::Initialize(HWND aHwnd) {
return false;
}
if (StaticPrefs::gfx_webrender_dcomp_win_debug_counter_enabled_AtStartup()) {
RefPtr<IDCompositionDeviceDebug> debugDevice;
hr = mCompositionDevice->QueryInterface(
(IDCompositionDeviceDebug**)getter_AddRefs(debugDevice));
if (SUCCEEDED(hr)) {
debugDevice->EnableDebugCounters();
} else {
gfxCriticalNote << "Failed to get IDCompositionDesktopDevice: "
<< gfx::hexa(hr);
}
}
mCompositionTarget->SetRoot(mRootVisual);
// Set interporation mode to Linear.
// By default, a visual inherits the interpolation mode of the parent visual.
@ -79,5 +109,6 @@ void DCLayerTree::SetDefaultSwapChain(IDXGISwapChain1* aSwapChain) {
mCompositionDevice->Commit();
}
#endif
} // namespace wr
} // namespace mozilla

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

@ -12,15 +12,18 @@
#include "mozilla/RefPtr.h"
#include "mozilla/UniquePtr.h"
struct IDCompositionDevice;
struct IDCompositionDevice2;
struct IDCompositionTarget;
struct IDCompositionVisual;
struct IDCompositionVisual2;
struct IDXGISwapChain1;
namespace mozilla {
namespace wr {
// Currently, MinGW build environment does not handle IDCompositionDesktopDevice
// and IDCompositionDevice2
#if !defined(__MINGW32__)
/**
* DCLayerTree manages direct composition layers.
* It does not manage gecko's layers::Layer.
@ -28,7 +31,7 @@ namespace wr {
class DCLayerTree {
public:
static UniquePtr<DCLayerTree> Create(HWND aHwnd);
explicit DCLayerTree(IDCompositionDevice* aCompositionDevice);
explicit DCLayerTree(IDCompositionDevice2* aCompositionDevice);
~DCLayerTree();
void SetDefaultSwapChain(IDXGISwapChain1* aSwapChain);
@ -36,11 +39,18 @@ class DCLayerTree {
protected:
bool Initialize(HWND aHwnd);
RefPtr<IDCompositionDevice> mCompositionDevice;
RefPtr<IDCompositionDevice2> mCompositionDevice;
RefPtr<IDCompositionTarget> mCompositionTarget;
RefPtr<IDCompositionVisual> mRootVisual;
RefPtr<IDCompositionVisual> mDefaultSwapChainVisual;
RefPtr<IDCompositionVisual2> mRootVisual;
RefPtr<IDCompositionVisual2> mDefaultSwapChainVisual;
};
#else
class DCLayerTree {
public:
static UniquePtr<DCLayerTree> Create(HWND aHwnd) { return nullptr; }
void SetDefaultSwapChain(IDXGISwapChain1* aSwapChain) {}
};
#endif
} // namespace wr
} // namespace mozilla

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

@ -3542,6 +3542,16 @@
mirror: always
#endif
#ifdef XP_WIN
# Enables display of performance debugging counters when DirectComposition
# is used.
# Performance counters are displayed on the top-right corner of the screen.
- name: gfx.webrender.dcomp-win.debug-counter.enabled
type: bool
value: false
mirror: once
#endif
# Use vsync events generated by hardware
- name: gfx.work-around-driver-bugs
type: bool