tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

gfxWindowsPlatform.h (5936B)


      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/. */
      5 
      6 #ifndef GFX_WINDOWS_PLATFORM_H
      7 #define GFX_WINDOWS_PLATFORM_H
      8 
      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"
     20 
     21 #include "mozilla/Mutex.h"
     22 
     23 #include <windows.h>
     24 #include <objbase.h>
     25 
     26 #include <dxgi.h>
     27 
     28 // This header is available in the June 2010 SDK and in the Win8 SDK
     29 #include <d3dcommon.h>
     30 // Win 8.0 SDK types we'll need when building using older sdks.
     31 #if !defined(D3D_FEATURE_LEVEL_11_1)  // defined in the 8.0 SDK only
     32 #  define D3D_FEATURE_LEVEL_11_1 static_cast<D3D_FEATURE_LEVEL>(0xb100)
     33 #  define D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION 2048
     34 #  define D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION 4096
     35 #endif
     36 
     37 namespace mozilla {
     38 namespace gfx {
     39 class DrawTarget;
     40 class FeatureState;
     41 class DeviceManagerDx;
     42 }  // namespace gfx
     43 }  // namespace mozilla
     44 struct IDirect3DDevice9;
     45 struct ID3D11Device;
     46 struct IDXGIAdapter1;
     47 
     48 /**
     49 * Utility to get a Windows HDC from a Moz2D DrawTarget.  If the DrawTarget is
     50 * not backed by a HDC this will get the HDC for the screen device context
     51 * instead.
     52 */
     53 class MOZ_STACK_CLASS DCForMetrics final {
     54 public:
     55  explicit DCForMetrics();
     56 
     57  ~DCForMetrics() { ReleaseDC(nullptr, mDC); }
     58 
     59  operator HDC() { return mDC; }
     60 
     61 private:
     62  HDC mDC;
     63 };
     64 
     65 // ClearType parameters set by running ClearType tuner
     66 struct ClearTypeParameterInfo {
     67  ClearTypeParameterInfo()
     68      : gamma(-1),
     69        pixelStructure(-1),
     70        clearTypeLevel(-1),
     71        enhancedContrast(-1) {}
     72 
     73  nsString displayName;  // typically just 'DISPLAY1'
     74  int32_t gamma;
     75  int32_t pixelStructure;
     76  int32_t clearTypeLevel;
     77  int32_t enhancedContrast;
     78 };
     79 
     80 class gfxWindowsPlatform final : public gfxPlatform {
     81  friend class mozilla::gfx::DeviceManagerDx;
     82 
     83 public:
     84  enum TextRenderingMode {
     85    TEXT_RENDERING_NO_CLEARTYPE,
     86    TEXT_RENDERING_NORMAL,
     87    TEXT_RENDERING_GDI_CLASSIC,
     88    TEXT_RENDERING_COUNT
     89  };
     90 
     91  gfxWindowsPlatform();
     92  virtual ~gfxWindowsPlatform();
     93  static gfxWindowsPlatform* GetPlatform() {
     94    return (gfxWindowsPlatform*)gfxPlatform::GetPlatform();
     95  }
     96 
     97  void EnsureDevicesInitialized() override;
     98  bool DevicesInitialized() override;
     99 
    100  bool CreatePlatformFontList() override;
    101 
    102  virtual already_AddRefed<gfxASurface> CreateOffscreenSurface(
    103      const IntSize& aSize, gfxImageFormat aFormat) override;
    104 
    105  /**
    106   * Updates render mode with relation to the current preferences and
    107   * available devices.
    108   */
    109  void UpdateRenderMode();
    110 
    111  void GetCommonFallbackFonts(uint32_t aCh, Script aRunScript,
    112                              FontPresentation aPresentation,
    113                              nsTArray<const char*>& aFontList) override;
    114 
    115  void CompositorUpdated() override;
    116 
    117  bool DidRenderingDeviceReset(
    118      mozilla::gfx::DeviceResetReason* aResetReason = nullptr) override;
    119  void SchedulePaintIfDeviceReset() override;
    120  void CheckForContentOnlyDeviceReset();
    121 
    122  mozilla::gfx::BackendType GetContentBackendFor(
    123      mozilla::layers::LayersBackend aLayers) override;
    124 
    125  mozilla::gfx::BackendType GetPreferredCanvasBackend() override;
    126 
    127  static void GetDLLVersion(char16ptr_t aDLLPath, nsAString& aVersion);
    128 
    129  // returns ClearType tuning information for each display
    130  static void GetCleartypeParams(nsTArray<ClearTypeParameterInfo>& aParams);
    131 
    132  void FontsPrefsChanged(const char* aPref) override;
    133 
    134  static inline bool DWriteEnabled() {
    135    return !!mozilla::gfx::Factory::GetDWriteFactory();
    136  }
    137 
    138 public:
    139  static nsresult GetGpuTimeSinceProcessStartInMs(uint64_t* aResult);
    140 
    141  static bool IsOptimus();
    142 
    143  bool SupportsApzWheelInput() const override { return true; }
    144 
    145  // Recreate devices as needed for a device reset. Returns true if a device
    146  // reset occurred.
    147  bool HandleDeviceReset();
    148  void UpdateBackendPrefs();
    149 
    150  already_AddRefed<mozilla::gfx::VsyncSource> CreateGlobalHardwareVsyncSource()
    151      override;
    152  static mozilla::Atomic<size_t> sD3D11SharedTextures;
    153  static mozilla::Atomic<size_t> sD3D9SharedTextures;
    154 
    155  bool SupportsPluginDirectBitmapDrawing() override { return true; }
    156 
    157  static void RecordContentDeviceFailure(
    158      mozilla::gfx::TelemetryDeviceCode aDevice);
    159 
    160  static void InitMemoryReportersForGPUProcess();
    161 
    162  static bool CheckVariationFontSupport();
    163 
    164 protected:
    165  bool AccelerateLayersByDefault() override { return true; }
    166 
    167  nsTArray<uint8_t> GetPlatformCMSOutputProfileData() override;
    168 
    169 public:
    170  static nsTArray<uint8_t> GetPlatformCMSOutputProfileData_Impl();
    171 
    172 protected:
    173  void GetPlatformDisplayInfo(mozilla::widget::InfoObject& aObj) override;
    174 
    175  void ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData& aData) override;
    176  void ImportContentDeviceData(
    177      const mozilla::gfx::ContentDeviceData& aData) override;
    178  void BuildContentDeviceData(mozilla::gfx::ContentDeviceData* aOut) override;
    179 
    180  BackendPrefsData GetBackendPrefs() const override;
    181 
    182 private:
    183  void Init();
    184  void InitAcceleration() override;
    185  void InitWebRenderConfig() override;
    186  void InitPlatformHardwareVideoConfig() override;
    187 #ifdef MOZ_WMF_CDM
    188  void InitPlatformHardwarDRMConfig() override;
    189 #endif
    190 
    191  void InitializeDevices();
    192  void InitializeD3D11();
    193  bool InitDWriteSupport();
    194 
    195  void InitializeConfig();
    196  void InitializeD3D9Config();
    197  void InitializeD3D11Config();
    198  void InitializeDirectDrawConfig();
    199 
    200  void RecordStartupTelemetry();
    201 
    202  bool mInitializedDevices = false;
    203 
    204  // Cached contents of the output color profile file
    205  nsTArray<uint8_t> mCachedOutputColorProfile;
    206 };
    207 
    208 #endif /* GFX_WINDOWS_PLATFORM_H */