From 754f4a89afb8571d0b8cbad0967547be66841b3e Mon Sep 17 00:00:00 2001 From: Kelsey Gilbert Date: Mon, 13 Mar 2023 21:04:12 +0000 Subject: [PATCH] Bug 1799258 - Share all-of-dcomp.h preamble, and deal with outdated mingw dcomp.h. r=gfx-reviewers,sotaro Mingw's dcomp.h is not the official one, but rather a by-hand reproduction. While this newly-updated version has e.g. IDCompositionFilterEffect, it is still missing e.g. IDCompositionColorMatrixEffect. Differential Revision: https://phabricator.services.mozilla.com/D168839 --- gfx/thebes/AllOfDcomp.h | 39 ++++++++++++++++++++++++ gfx/thebes/DeviceManagerDx.cpp | 11 ++----- gfx/thebes/moz.build | 1 + gfx/webrender_bindings/DCLayerTree.cpp | 41 ++++++++++---------------- 4 files changed, 58 insertions(+), 34 deletions(-) create mode 100644 gfx/thebes/AllOfDcomp.h diff --git a/gfx/thebes/AllOfDcomp.h b/gfx/thebes/AllOfDcomp.h new file mode 100644 index 000000000000..5b43182a5c6d --- /dev/null +++ b/gfx/thebes/AllOfDcomp.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * 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_AllOfDcomp_h +#define mozilla_gfx_AllOfDcomp_h + +// Getting everything that we need in dcomp.h defined means messing with some defines. + +#if (_WIN32_WINNT < _WIN32_WINNT_WIN10) + +# define XSTR(x) STR(x) +# define STR(x) #x +// clang-format off + +# pragma message "IDCompositionFilterEffect in dcomp.h requires _WIN32_WINNT >= _WIN32_WINNT_WIN10." +// Pedantically, it actually requires _WIN32_WINNT_WINTHRESHOLD, but that's the +// same as _WIN32_WINNT_WIN10. + +# pragma message "Forcing NTDDI_VERSION " XSTR(NTDDI_VERSION) " -> " XSTR(NTDDI_WIN10) +# undef NTDDI_VERSION +# define NTDDI_VERSION NTDDI_WIN10 + +# pragma message "Forcing _WIN32_WINNT " XSTR(_WIN32_WINNT) " -> " XSTR(_WIN32_WINNT_WIN10) +# undef _WIN32_WINNT +# define _WIN32_WINNT _WIN32_WINNT_WIN10 + +// clang-format on +# undef STR +# undef XSTR + +#endif + +// - + +#include + +#endif // mozilla_gfx_AllOfDcomp_h diff --git a/gfx/thebes/DeviceManagerDx.cpp b/gfx/thebes/DeviceManagerDx.cpp index e99d360b5ed0..100cd3192afc 100644 --- a/gfx/thebes/DeviceManagerDx.cpp +++ b/gfx/thebes/DeviceManagerDx.cpp @@ -25,17 +25,10 @@ #include "nsPrintfCString.h" #include "nsString.h" -#undef _WIN32_WINNT -#define _WIN32_WINNT _WIN32_WINNT_WINBLUE -#undef NTDDI_VERSION -#define NTDDI_VERSION NTDDI_WINBLUE - -// We also need this, or dcomp.h won't give us e.g. IDCompositionDevice3: -#undef _WIN32_WINNT_WINTHRESHOLD -#define _WIN32_WINNT_WINTHRESHOLD _WIN32_WINNT +// - +#include "mozilla/gfx/AllOfDcomp.h" #include -#include #include #include diff --git a/gfx/thebes/moz.build b/gfx/thebes/moz.build index 176cc3c7e5db..9a87ea6aa0b0 100644 --- a/gfx/thebes/moz.build +++ b/gfx/thebes/moz.build @@ -67,6 +67,7 @@ EXPORTS += [ ] EXPORTS.mozilla.gfx += [ + "AllOfDcomp.h", "D3D11Checks.h", "DeviceManagerDx.h", "DisplayConfigWindows.h", diff --git a/gfx/webrender_bindings/DCLayerTree.cpp b/gfx/webrender_bindings/DCLayerTree.cpp index 2e738d4855fe..2faba766f76c 100644 --- a/gfx/webrender_bindings/DCLayerTree.cpp +++ b/gfx/webrender_bindings/DCLayerTree.cpp @@ -8,33 +8,9 @@ // - -#if (_WIN32_WINNT < _WIN32_WINNT_WIN10) - -# define XSTR(x) STR(x) -# define STR(x) #x -// clang-format off - -# pragma message "IDCompositionFilterEffect in dcomp.h requires _WIN32_WINNT >= _WIN32_WINNT_WIN10." -// Pedantically, it actually requires _WIN32_WINNT_WINTHRESHOLD, but that's the -// same as _WIN32_WINNT_WIN10. - -# pragma message "Forcing NTDDI_VERSION " XSTR(NTDDI_VERSION) " -> " XSTR(NTDDI_WIN10) -# undef NTDDI_VERSION -# define NTDDI_VERSION NTDDI_WIN10 - -# pragma message "Forcing _WIN32_WINNT " XSTR(_WIN32_WINNT) " -> " XSTR(_WIN32_WINNT_WIN10) -# undef _WIN32_WINNT -# define _WIN32_WINNT _WIN32_WINNT_WIN10 - -// clang-format on -# undef STR -# undef XSTR - -#endif - +#include "mozilla/gfx/AllOfDcomp.h" #include #include -#include #include // - @@ -57,6 +33,16 @@ #include "nsPrintfCString.h" #include "WinUtils.h" +// - + +#if defined(__MINGW32__) // 64 defines both 32 and 64 +// We need to fake some things, while we wait on updates to mingw's dcomp.h +// header. Just enough that we can successfully fail to work there. +#define MOZ_MINGW_DCOMP_H_INCOMPLETE +struct IDCompositionColorMatrixEffect : public IDCompositionFilterEffect {}; +struct IDCompositionTableTransferEffect : public IDCompositionFilterEffect {}; +#endif // defined(__MINGW32__) + namespace mozilla { namespace wr { @@ -1820,6 +1806,8 @@ ColorManagementChain ColorManagementChain::From( const color::ColorProfileConversionDesc& conv) { auto ret = ColorManagementChain{}; +#if !defined(MOZ_MINGW_DCOMP_H_INCOMPLETE) + const auto Append = [&](const RefPtr& afterLast) { if (ret.last) { afterLast->SetInput(0, ret.last, 0); @@ -1855,6 +1843,9 @@ ColorManagementChain ColorManagementChain::From( ret.dstLinearFromSrcLinear = MaybeAppendColorMatrix(color::mat4(conv.dstLinearFromSrcLinear)); ret.dstTfFromDstLinear = MaybeAppendTableTransfer(conv.dstTfFromDstLinear); + +#endif // !defined(MOZ_MINGW_DCOMP_H_INCOMPLETE) + return ret; }