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"
13 #include "gfxDWriteFonts.h"
14 #include "gfxPlatform.h"
15 #include "gfxTelemetry.h"
17 #include "mozilla/Attributes.h"
18 #include "mozilla/Atomics.h"
21 #include "mozilla/Mutex.h"
22 #include "mozilla/RefPtr.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
42 class DeviceManagerDx
;
44 } // namespace mozilla
45 struct IDirect3DDevice9
;
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
54 class MOZ_STACK_CLASS DCForMetrics final
{
56 explicit DCForMetrics();
58 ~DCForMetrics() { ReleaseDC(nullptr, mDC
); }
60 operator HDC() { return mDC
; }
66 // ClearType parameters set by running ClearType tuner
67 struct ClearTypeParameterInfo
{
68 ClearTypeParameterInfo()
72 enhancedContrast(-1) {}
74 nsString displayName
; // typically just 'DISPLAY1'
76 int32_t pixelStructure
;
77 int32_t clearTypeLevel
;
78 int32_t enhancedContrast
;
81 class gfxWindowsPlatform final
: public gfxPlatform
{
82 friend class mozilla::gfx::DeviceManagerDx
;
85 enum TextRenderingMode
{
86 TEXT_RENDERING_NO_CLEARTYPE
,
87 TEXT_RENDERING_NORMAL
,
88 TEXT_RENDERING_GDI_CLASSIC
,
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
;
107 /* Use GDI and windows surfaces */
110 /* Use 32bpp image surfaces and call StretchDIBits */
111 RENDER_IMAGE_STRETCH32
,
113 /* Use 32bpp image surfaces, and do 32->24 conversion before calling
115 RENDER_IMAGE_STRETCH24
,
117 /* Use Direct2D rendering */
124 bool IsDirect2DBackend();
127 * Updates render mode with relation to the current preferences and
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 mozilla::gfx::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();
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
179 bool HandleDeviceReset();
180 void UpdateBackendPrefs();
182 already_AddRefed
<mozilla::gfx::VsyncSource
> CreateGlobalHardwareVsyncSource()
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();
197 bool AccelerateLayersByDefault() override
{ return true; }
199 nsTArray
<uint8_t> GetPlatformCMSOutputProfileData() override
;
202 static nsTArray
<uint8_t> GetPlatformCMSOutputProfileData_Impl();
205 void GetPlatformDisplayInfo(mozilla::widget::InfoObject
& aObj
) override
;
207 void ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData
& aData
) override
;
208 void ImportContentDeviceData(
209 const mozilla::gfx::ContentDeviceData
& aData
) override
;
210 void BuildContentDeviceData(mozilla::gfx::ContentDeviceData
* aOut
) override
;
212 BackendPrefsData
GetBackendPrefs() const override
;
214 RenderMode mRenderMode
;
218 void InitAcceleration() override
;
219 void InitWebRenderConfig() override
;
221 void InitializeDevices();
222 void InitializeD3D11();
223 void InitializeD2D();
224 bool InitDWriteSupport();
225 void InitGPUProcessSupport();
227 void DisableD2D(mozilla::gfx::FeatureStatus aStatus
, const char* aMessage
,
228 const nsACString
& aFailureId
);
230 void InitializeConfig();
231 void InitializeD3D9Config();
232 void InitializeD3D11Config();
233 void InitializeD2DConfig();
234 void InitializeDirectDrawConfig();
236 void RecordStartupTelemetry();
238 bool mInitializedDevices
= false;
240 // Cached contents of the output color profile file
241 nsTArray
<uint8_t> mCachedOutputColorProfile
;
244 #endif /* GFX_WINDOWS_PLATFORM_H */