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
10 * XXX to get CAIRO_HAS_DWRITE_FONT
11 * and cairo_win32_scaled_font_select_font
13 #include "cairo-win32.h"
15 #include "gfxCrashReporterUtils.h"
16 #include "gfxFontUtils.h"
17 #include "gfxWindowsSurface.h"
19 #include "gfxDWriteFonts.h"
20 #include "gfxPlatform.h"
21 #include "gfxTelemetry.h"
23 #include "mozilla/Attributes.h"
24 #include "mozilla/Atomics.h"
26 #include "nsDataHashtable.h"
28 #include "mozilla/Mutex.h"
29 #include "mozilla/RefPtr.h"
36 // This header is available in the June 2010 SDK and in the Win8 SDK
37 #include <d3dcommon.h>
38 // Win 8.0 SDK types we'll need when building using older sdks.
39 #if !defined(D3D_FEATURE_LEVEL_11_1) // defined in the 8.0 SDK only
40 # define D3D_FEATURE_LEVEL_11_1 static_cast<D3D_FEATURE_LEVEL>(0xb100)
41 # define D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION 2048
42 # define D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION 4096
49 class DeviceManagerDx
;
52 class ReadbackManagerD3D11
;
54 } // namespace mozilla
55 struct IDirect3DDevice9
;
60 * Utility to get a Windows HDC from a Moz2D DrawTarget. If the DrawTarget is
61 * not backed by a HDC this will get the HDC for the screen device context
64 class MOZ_STACK_CLASS DCForMetrics final
{
66 explicit DCForMetrics();
68 ~DCForMetrics() { ReleaseDC(nullptr, mDC
); }
70 operator HDC() { return mDC
; }
76 // ClearType parameters set by running ClearType tuner
77 struct ClearTypeParameterInfo
{
78 ClearTypeParameterInfo()
82 enhancedContrast(-1) {}
84 nsString displayName
; // typically just 'DISPLAY1'
86 int32_t pixelStructure
;
87 int32_t clearTypeLevel
;
88 int32_t enhancedContrast
;
91 class gfxWindowsPlatform
: public gfxPlatform
{
92 friend class mozilla::gfx::DeviceManagerDx
;
95 enum TextRenderingMode
{
96 TEXT_RENDERING_NO_CLEARTYPE
,
97 TEXT_RENDERING_NORMAL
,
98 TEXT_RENDERING_GDI_CLASSIC
,
102 gfxWindowsPlatform();
103 virtual ~gfxWindowsPlatform();
104 static gfxWindowsPlatform
* GetPlatform() {
105 return (gfxWindowsPlatform
*)gfxPlatform::GetPlatform();
108 void EnsureDevicesInitialized() override
;
109 bool DevicesInitialized() override
;
111 gfxPlatformFontList
* CreatePlatformFontList() override
;
113 virtual already_AddRefed
<gfxASurface
> CreateOffscreenSurface(
114 const IntSize
& aSize
, gfxImageFormat aFormat
) override
;
117 /* Use GDI and windows surfaces */
120 /* Use 32bpp image surfaces and call StretchDIBits */
121 RENDER_IMAGE_STRETCH32
,
123 /* Use 32bpp image surfaces, and do 32->24 conversion before calling
125 RENDER_IMAGE_STRETCH24
,
127 /* Use Direct2D rendering */
134 bool IsDirect2DBackend();
137 * Updates render mode with relation to the current preferences and
140 void UpdateRenderMode();
143 * Verifies a D2D device is present and working, will attempt to create one
144 * it is non-functional or non-existant.
146 * \param aAttemptForce Attempt to force D2D cairo device creation by using
147 * cairo device creation routines.
149 void VerifyD2DDevice(bool aAttemptForce
);
151 void GetCommonFallbackFonts(uint32_t aCh
, uint32_t aNextCh
, Script aRunScript
,
152 nsTArray
<const char*>& aFontList
) override
;
154 gfxFontGroup
* CreateFontGroup(const mozilla::FontFamilyList
& aFontFamilyList
,
155 const gfxFontStyle
* aStyle
,
156 gfxTextPerfMetrics
* aTextPerf
,
157 gfxUserFontSet
* aUserFontSet
,
158 gfxFloat aDevToCssSize
) override
;
160 bool CanUseHardwareVideoDecoding() override
;
162 void CompositorUpdated() override
;
164 bool DidRenderingDeviceReset(
165 DeviceResetReason
* aResetReason
= nullptr) override
;
166 void SchedulePaintIfDeviceReset() override
;
167 void CheckForContentOnlyDeviceReset();
169 mozilla::gfx::BackendType
GetContentBackendFor(
170 mozilla::layers::LayersBackend aLayers
) override
;
172 mozilla::gfx::BackendType
GetPreferredCanvasBackend() override
;
174 static void GetDLLVersion(char16ptr_t aDLLPath
, nsAString
& aVersion
);
176 // returns ClearType tuning information for each display
177 static void GetCleartypeParams(nsTArray
<ClearTypeParameterInfo
>& aParams
);
179 void FontsPrefsChanged(const char* aPref
) override
;
181 void SetupClearTypeParams();
183 static inline bool DWriteEnabled() {
184 return !!mozilla::gfx::Factory::GetDWriteFactory();
186 inline DWRITE_MEASURING_MODE
DWriteMeasuringMode() { return mMeasuringMode
; }
188 IDWriteRenderingParams
* GetRenderingParams(TextRenderingMode aRenderMode
) {
189 return mRenderingParams
[aRenderMode
];
193 bool DwmCompositionEnabled();
195 mozilla::layers::ReadbackManagerD3D11
* GetReadbackManager();
197 static bool IsOptimus();
199 bool SupportsApzWheelInput() const override
{ return true; }
201 // Recreate devices as needed for a device reset. Returns true if a device
203 bool HandleDeviceReset();
204 void UpdateBackendPrefs();
206 already_AddRefed
<mozilla::gfx::VsyncSource
> CreateHardwareVsyncSource()
208 static mozilla::Atomic
<size_t> sD3D11SharedTextures
;
209 static mozilla::Atomic
<size_t> sD3D9SharedTextures
;
211 bool SupportsPluginDirectBitmapDrawing() override
{ return true; }
212 bool SupportsPluginDirectDXGIDrawing();
214 static void RecordContentDeviceFailure(
215 mozilla::gfx::TelemetryDeviceCode aDevice
);
218 bool AccelerateLayersByDefault() override
{ return true; }
219 void GetAcceleratedCompositorBackends(
220 nsTArray
<mozilla::layers::LayersBackend
>& aBackends
) override
;
221 void GetPlatformCMSOutputProfile(void*& mem
, size_t& size
) override
;
223 void ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData
& aData
) override
;
224 void ImportContentDeviceData(
225 const mozilla::gfx::ContentDeviceData
& aData
) override
;
226 void BuildContentDeviceData(mozilla::gfx::ContentDeviceData
* aOut
) override
;
228 BackendPrefsData
GetBackendPrefs() const override
;
230 bool CheckVariationFontSupport() override
;
233 RenderMode mRenderMode
;
236 bool HasBattery() override
;
239 void InitAcceleration() override
;
240 void InitWebRenderConfig() override
;
242 void InitializeDevices();
243 void InitializeD3D11();
244 void InitializeD2D();
245 bool InitDWriteSupport();
246 bool InitGPUProcessSupport();
248 void DisableD2D(mozilla::gfx::FeatureStatus aStatus
, const char* aMessage
,
249 const nsACString
& aFailureId
);
251 void InitializeConfig();
252 void InitializeD3D9Config();
253 void InitializeD3D11Config();
254 void InitializeD2DConfig();
255 void InitializeDirectDrawConfig();
256 void InitializeAdvancedLayersConfig();
258 void RecordStartupTelemetry();
260 RefPtr
<IDWriteRenderingParams
> mRenderingParams
[TEXT_RENDERING_COUNT
];
261 DWRITE_MEASURING_MODE mMeasuringMode
;
263 RefPtr
<mozilla::layers::ReadbackManagerD3D11
> mD3D11ReadbackManager
;
264 bool mInitializedDevices
= false;
267 #endif /* GFX_WINDOWS_PLATFORM_H */