From 987b128720fdda5170bbfa8ce114127eeee80e35 Mon Sep 17 00:00:00 2001 From: Kelsey Gilbert Date: Mon, 6 Feb 2023 19:58:56 +0000 Subject: [PATCH] Bug 1799258 - Share all-of-dcomp.h preamble, and deal with outdated mingw dcomp.h. r=gfx-reviewers,sotaro 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 | 50 ++++++++++++++++------------------ 4 files changed, 66 insertions(+), 35 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 9be2ce7472ef..ea3c82714eab 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,18 @@ #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_OLD +struct IDCompositionFilterEffect : public IDCompositionEffect {}; +struct IDCompositionColorMatrixEffect : public IDCompositionFilterEffect {}; +struct IDCompositionTableTransferEffect : public IDCompositionFilterEffect {}; +struct IDCompositionDevice3 : public IDCompositionDevice2 {}; +#endif // defined(__MINGW32__) + namespace mozilla { namespace wr { @@ -645,7 +633,12 @@ DCSurface* DCExternalSurfaceWrapper::EnsureSurfaceForExternalImage( if (cmsMode == CMSMode::Off) return; const auto dcomp = mDCLayerTree->GetCompositionDevice(); - const auto dcomp3 = QI::From(dcomp); + RefPtr dcomp3; +#if !defined(MOZ_MINGW_DCOMP_H_OLD) + dcomp3 = QI::From(dcomp); +#else + (void)dcomp; +#endif if (!dcomp3) { NS_WARNING( "No IDCompositionDevice3, cannot use dcomp for color management."); @@ -1796,6 +1789,8 @@ ColorManagementChain ColorManagementChain::From( const color::ColorProfileConversionDesc& conv) { auto ret = ColorManagementChain{}; +#if !defined(MOZ_MINGW_DCOMP_H_OLD) + const auto Append = [&](const RefPtr& afterLast) { if (ret.last) { afterLast->SetInput(0, ret.last, 0); @@ -1831,6 +1826,9 @@ ColorManagementChain ColorManagementChain::From( ret.dstLinearFromSrcLinear = MaybeAppendColorMatrix(color::mat4(conv.dstLinearFromSrcLinear)); ret.dstTfFromDstLinear = MaybeAppendTableTransfer(conv.dstTfFromDstLinear); + +#endif // !defined(MOZ_MINGW_DCOMP_H_OLD) + return ret; } -- 2.11.4.GIT