Bug 1880704 - Crop more PDF rendering and wait differently for rendering r=mboldan
[gecko.git] / gfx / thebes / gfxWindowsPlatform.h
blob0956a384b01f44713e9850fb8b6f339248bff2bd
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 static bool IsOptimus();
175 bool SupportsApzWheelInput() const override { return true; }
177 // Recreate devices as needed for a device reset. Returns true if a device
178 // reset occurred.
179 bool HandleDeviceReset();
180 void UpdateBackendPrefs();
182 already_AddRefed<mozilla::gfx::VsyncSource> CreateGlobalHardwareVsyncSource()
183 override;
184 static mozilla::Atomic<size_t> sD3D11SharedTextures;
185 static mozilla::Atomic<size_t> sD3D9SharedTextures;
187 bool SupportsPluginDirectBitmapDrawing() override { return true; }
189 static void RecordContentDeviceFailure(
190 mozilla::gfx::TelemetryDeviceCode aDevice);
192 static void InitMemoryReportersForGPUProcess();
194 static bool CheckVariationFontSupport();
196 // Always false for content processes.
197 bool SupportsHDR() override { return mSupportsHDR; }
199 protected:
200 bool AccelerateLayersByDefault() override { return true; }
202 nsTArray<uint8_t> GetPlatformCMSOutputProfileData() override;
204 public:
205 static nsTArray<uint8_t> GetPlatformCMSOutputProfileData_Impl();
207 protected:
208 void GetPlatformDisplayInfo(mozilla::widget::InfoObject& aObj) override;
210 void ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData& aData) override;
211 void ImportContentDeviceData(
212 const mozilla::gfx::ContentDeviceData& aData) override;
213 void BuildContentDeviceData(mozilla::gfx::ContentDeviceData* aOut) override;
215 BackendPrefsData GetBackendPrefs() const override;
217 void UpdateSupportsHDR();
219 RenderMode mRenderMode;
220 bool mSupportsHDR;
222 private:
223 void Init();
224 void InitAcceleration() override;
225 void InitWebRenderConfig() override;
227 void InitializeDevices();
228 void InitializeD3D11();
229 void InitializeD2D();
230 bool InitDWriteSupport();
231 void InitGPUProcessSupport();
233 void DisableD2D(mozilla::gfx::FeatureStatus aStatus, const char* aMessage,
234 const nsACString& aFailureId);
236 void InitializeConfig();
237 void InitializeD3D9Config();
238 void InitializeD3D11Config();
239 void InitializeD2DConfig();
240 void InitializeDirectDrawConfig();
242 void RecordStartupTelemetry();
244 bool mInitializedDevices = false;
246 // Cached contents of the output color profile file
247 nsTArray<uint8_t> mCachedOutputColorProfile;
250 #endif /* GFX_WINDOWS_PLATFORM_H */