Bug 1798067 Part 2: Implement gfxWindowsPlatform::SupportsHDR. r=jgilbert,gfx-reviewers
[gecko.git] / gfx / thebes / gfxWindowsPlatform.h
blobb7844a2be1d8d98cfc9374ed69cc27336e1e6168
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GFX_WINDOWS_PLATFORM_H
7 #define GFX_WINDOWS_PLATFORM_H
9 #include "gfxCrashReporterUtils.h"
10 #include "gfxFontUtils.h"
11 #include "gfxWindowsSurface.h"
12 #include "gfxFont.h"
13 #include "gfxDWriteFonts.h"
14 #include "gfxPlatform.h"
15 #include "gfxTelemetry.h"
16 #include "gfxTypes.h"
17 #include "mozilla/Attributes.h"
18 #include "mozilla/Atomics.h"
19 #include "nsTArray.h"
21 #include "mozilla/Mutex.h"
22 #include "mozilla/RefPtr.h"
24 #include <windows.h>
25 #include <objbase.h>
27 #include <dxgi.h>
29 // This header is available in the June 2010 SDK and in the Win8 SDK
30 #include <d3dcommon.h>
31 // Win 8.0 SDK types we'll need when building using older sdks.
32 #if !defined(D3D_FEATURE_LEVEL_11_1) // defined in the 8.0 SDK only
33 # define D3D_FEATURE_LEVEL_11_1 static_cast<D3D_FEATURE_LEVEL>(0xb100)
34 # define D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION 2048
35 # define D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION 4096
36 #endif
38 namespace mozilla {
39 namespace gfx {
40 class DrawTarget;
41 class FeatureState;
42 class DeviceManagerDx;
43 } // namespace gfx
44 } // namespace mozilla
45 struct IDirect3DDevice9;
46 struct ID3D11Device;
47 struct IDXGIAdapter1;
49 /**
50 * Utility to get a Windows HDC from a Moz2D DrawTarget. If the DrawTarget is
51 * not backed by a HDC this will get the HDC for the screen device context
52 * instead.
54 class MOZ_STACK_CLASS DCForMetrics final {
55 public:
56 explicit DCForMetrics();
58 ~DCForMetrics() { ReleaseDC(nullptr, mDC); }
60 operator HDC() { return mDC; }
62 private:
63 HDC mDC;
66 // ClearType parameters set by running ClearType tuner
67 struct ClearTypeParameterInfo {
68 ClearTypeParameterInfo()
69 : gamma(-1),
70 pixelStructure(-1),
71 clearTypeLevel(-1),
72 enhancedContrast(-1) {}
74 nsString displayName; // typically just 'DISPLAY1'
75 int32_t gamma;
76 int32_t pixelStructure;
77 int32_t clearTypeLevel;
78 int32_t enhancedContrast;
81 class gfxWindowsPlatform final : public gfxPlatform {
82 friend class mozilla::gfx::DeviceManagerDx;
84 public:
85 enum TextRenderingMode {
86 TEXT_RENDERING_NO_CLEARTYPE,
87 TEXT_RENDERING_NORMAL,
88 TEXT_RENDERING_GDI_CLASSIC,
89 TEXT_RENDERING_COUNT
92 gfxWindowsPlatform();
93 virtual ~gfxWindowsPlatform();
94 static gfxWindowsPlatform* GetPlatform() {
95 return (gfxWindowsPlatform*)gfxPlatform::GetPlatform();
98 void EnsureDevicesInitialized() override;
99 bool DevicesInitialized() override;
101 bool CreatePlatformFontList() override;
103 virtual already_AddRefed<gfxASurface> CreateOffscreenSurface(
104 const IntSize& aSize, gfxImageFormat aFormat) override;
106 enum RenderMode {
107 /* Use GDI and windows surfaces */
108 RENDER_GDI = 0,
110 /* Use 32bpp image surfaces and call StretchDIBits */
111 RENDER_IMAGE_STRETCH32,
113 /* Use 32bpp image surfaces, and do 32->24 conversion before calling
114 StretchDIBits */
115 RENDER_IMAGE_STRETCH24,
117 /* Use Direct2D rendering */
118 RENDER_DIRECT2D,
120 /* max */
121 RENDER_MODE_MAX
124 bool IsDirect2DBackend();
127 * Updates render mode with relation to the current preferences and
128 * available devices.
130 void UpdateRenderMode();
133 * Verifies a D2D device is present and working, will attempt to create one
134 * it is non-functional or non-existant.
136 * \param aAttemptForce Attempt to force D2D cairo device creation by using
137 * cairo device creation routines.
139 void VerifyD2DDevice(bool aAttemptForce);
141 void GetCommonFallbackFonts(uint32_t aCh, Script aRunScript,
142 eFontPresentation aPresentation,
143 nsTArray<const char*>& aFontList) override;
145 bool CanUseHardwareVideoDecoding() override;
147 void CompositorUpdated() override;
149 bool DidRenderingDeviceReset(
150 DeviceResetReason* aResetReason = nullptr) override;
151 void SchedulePaintIfDeviceReset() override;
152 void CheckForContentOnlyDeviceReset();
154 mozilla::gfx::BackendType GetContentBackendFor(
155 mozilla::layers::LayersBackend aLayers) override;
157 mozilla::gfx::BackendType GetPreferredCanvasBackend() override;
159 static void GetDLLVersion(char16ptr_t aDLLPath, nsAString& aVersion);
161 // returns ClearType tuning information for each display
162 static void GetCleartypeParams(nsTArray<ClearTypeParameterInfo>& aParams);
164 void FontsPrefsChanged(const char* aPref) override;
166 static inline bool DWriteEnabled() {
167 return !!mozilla::gfx::Factory::GetDWriteFactory();
170 public:
171 static nsresult GetGpuTimeSinceProcessStartInMs(uint64_t* aResult);
173 bool DwmCompositionEnabled();
175 static bool IsOptimus();
177 bool SupportsApzWheelInput() const override { return true; }
179 // Recreate devices as needed for a device reset. Returns true if a device
180 // reset occurred.
181 bool HandleDeviceReset();
182 void UpdateBackendPrefs();
184 already_AddRefed<mozilla::gfx::VsyncSource> CreateGlobalHardwareVsyncSource()
185 override;
186 static mozilla::Atomic<size_t> sD3D11SharedTextures;
187 static mozilla::Atomic<size_t> sD3D9SharedTextures;
189 bool SupportsPluginDirectBitmapDrawing() override { return true; }
191 static void RecordContentDeviceFailure(
192 mozilla::gfx::TelemetryDeviceCode aDevice);
194 static void InitMemoryReportersForGPUProcess();
196 static bool CheckVariationFontSupport();
198 bool SupportsHDR() override { return mSupportsHDR; }
200 protected:
201 bool AccelerateLayersByDefault() override { return true; }
202 nsTArray<uint8_t> GetPlatformCMSOutputProfileData() override;
203 void GetPlatformDisplayInfo(mozilla::widget::InfoObject& aObj) override;
205 void ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData& aData) override;
206 void ImportContentDeviceData(
207 const mozilla::gfx::ContentDeviceData& aData) override;
208 void BuildContentDeviceData(mozilla::gfx::ContentDeviceData* aOut) override;
210 BackendPrefsData GetBackendPrefs() const override;
212 void UpdateSupportsHDR();
214 RenderMode mRenderMode;
215 bool mSupportsHDR;
217 private:
218 enum class DwmCompositionStatus : uint32_t {
219 Unknown,
220 Disabled,
221 Enabled,
224 void Init();
225 void InitAcceleration() override;
226 void InitWebRenderConfig() override;
228 void InitializeDevices();
229 void InitializeD3D11();
230 void InitializeD2D();
231 bool InitDWriteSupport();
232 void InitGPUProcessSupport();
234 void DisableD2D(mozilla::gfx::FeatureStatus aStatus, const char* aMessage,
235 const nsACString& aFailureId);
237 void InitializeConfig();
238 void InitializeD3D9Config();
239 void InitializeD3D11Config();
240 void InitializeD2DConfig();
241 void InitializeDirectDrawConfig();
243 void RecordStartupTelemetry();
245 bool mInitializedDevices = false;
247 mozilla::Atomic<DwmCompositionStatus, mozilla::ReleaseAcquire>
248 mDwmCompositionStatus;
250 // Cached contents of the output color profile file
251 nsTArray<uint8_t> mCachedOutputColorProfile;
254 #endif /* GFX_WINDOWS_PLATFORM_H */