2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef GFX_WINDOWS_PLATFORM_H
|
|
|
|
#define GFX_WINDOWS_PLATFORM_H
|
|
|
|
|
2010-02-25 22:36:07 -08:00
|
|
|
|
|
|
|
/**
|
2011-02-21 05:47:32 -08:00
|
|
|
* XXX to get CAIRO_HAS_D2D_SURFACE, CAIRO_HAS_DWRITE_FONT
|
|
|
|
* and cairo_win32_scaled_font_select_font
|
2010-02-25 22:36:07 -08:00
|
|
|
*/
|
2011-02-21 05:47:32 -08:00
|
|
|
#include "cairo-win32.h"
|
2010-02-25 22:36:07 -08:00
|
|
|
|
2008-04-03 19:01:22 -07:00
|
|
|
#include "gfxFontUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "gfxWindowsSurface.h"
|
2010-03-17 04:40:29 -07:00
|
|
|
#include "gfxFont.h"
|
2010-02-25 22:36:07 -08:00
|
|
|
#ifdef CAIRO_HAS_DWRITE_FONT
|
|
|
|
#include "gfxDWriteFonts.h"
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "gfxPlatform.h"
|
2014-11-10 13:41:40 -08:00
|
|
|
#include "gfxTypes.h"
|
|
|
|
#include "mozilla/Attributes.h"
|
2009-01-18 12:14:14 -08:00
|
|
|
#include "nsTArray.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
|
2013-05-01 07:27:09 -07:00
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include <windows.h>
|
2010-08-26 15:26:47 -07:00
|
|
|
#include <objbase.h>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-22 12:32:56 -07:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
|
|
|
#include <dxgi.h>
|
|
|
|
#endif
|
|
|
|
|
2013-05-10 06:26:10 -07:00
|
|
|
// This header is available in the June 2010 SDK and in the Win8 SDK
|
|
|
|
#include <d3dcommon.h>
|
2013-05-09 08:32:50 -07:00
|
|
|
// Win 8.0 SDK types we'll need when building using older sdks.
|
2013-05-10 06:26:10 -07:00
|
|
|
#if !defined(D3D_FEATURE_LEVEL_11_1) // defined in the 8.0 SDK only
|
2013-05-09 08:32:50 -07:00
|
|
|
#define D3D_FEATURE_LEVEL_11_1 static_cast<D3D_FEATURE_LEVEL>(0xb100)
|
|
|
|
#define D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION 2048
|
|
|
|
#define D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION 4096
|
|
|
|
#endif
|
|
|
|
|
2013-08-04 00:46:17 -07:00
|
|
|
namespace mozilla {
|
2014-11-10 13:41:40 -08:00
|
|
|
namespace gfx {
|
|
|
|
class DrawTarget;
|
|
|
|
}
|
2013-08-04 00:46:17 -07:00
|
|
|
namespace layers {
|
|
|
|
class DeviceManagerD3D9;
|
2014-07-30 06:38:46 -07:00
|
|
|
class ReadbackManagerD3D11;
|
2013-08-04 00:46:17 -07:00
|
|
|
}
|
|
|
|
}
|
2014-06-18 17:57:51 -07:00
|
|
|
struct IDirect3DDevice9;
|
|
|
|
struct ID3D11Device;
|
|
|
|
struct IDXGIAdapter1;
|
2013-05-01 07:27:09 -07:00
|
|
|
|
2013-08-27 16:24:51 -07:00
|
|
|
class nsIMemoryReporter;
|
2012-02-08 15:13:50 -08:00
|
|
|
|
2014-11-10 13:41:40 -08:00
|
|
|
/**
|
|
|
|
* Utility to get a Windows HDC from a Moz2D DrawTarget. If the DrawTarget is
|
|
|
|
* not backed by a HDC this will get the HDC for the screen device context
|
|
|
|
* instead.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS DCFromDrawTarget MOZ_FINAL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DCFromDrawTarget(mozilla::gfx::DrawTarget& aDrawTarget);
|
2010-03-15 02:34:25 -07:00
|
|
|
|
2014-11-10 13:41:40 -08:00
|
|
|
~DCFromDrawTarget() {
|
|
|
|
if (mNeedsRelease) {
|
|
|
|
ReleaseDC(nullptr, mDC);
|
2011-02-19 12:48:33 -08:00
|
|
|
} else {
|
2014-11-10 13:41:40 -08:00
|
|
|
RestoreDC(mDC, -1);
|
2011-02-19 12:48:33 -08:00
|
|
|
}
|
2010-03-15 02:34:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
operator HDC () {
|
2014-11-10 13:41:40 -08:00
|
|
|
return mDC;
|
2010-03-15 02:34:25 -07:00
|
|
|
}
|
|
|
|
|
2014-11-10 13:41:40 -08:00
|
|
|
private:
|
|
|
|
HDC mDC;
|
|
|
|
bool mNeedsRelease;
|
2010-03-15 02:34:25 -07:00
|
|
|
};
|
|
|
|
|
2011-05-10 17:30:20 -07:00
|
|
|
// ClearType parameters set by running ClearType tuner
|
|
|
|
struct ClearTypeParameterInfo {
|
|
|
|
ClearTypeParameterInfo() :
|
|
|
|
gamma(-1), pixelStructure(-1), clearTypeLevel(-1), enhancedContrast(-1)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
nsString displayName; // typically just 'DISPLAY1'
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t gamma;
|
|
|
|
int32_t pixelStructure;
|
|
|
|
int32_t clearTypeLevel;
|
|
|
|
int32_t enhancedContrast;
|
2011-05-10 17:30:20 -07:00
|
|
|
};
|
|
|
|
|
2013-05-29 14:59:24 -07:00
|
|
|
class gfxWindowsPlatform : public gfxPlatform {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2012-03-19 12:20:18 -07:00
|
|
|
enum TextRenderingMode {
|
|
|
|
TEXT_RENDERING_NO_CLEARTYPE,
|
|
|
|
TEXT_RENDERING_NORMAL,
|
|
|
|
TEXT_RENDERING_GDI_CLASSIC,
|
|
|
|
TEXT_RENDERING_COUNT
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
gfxWindowsPlatform();
|
|
|
|
virtual ~gfxWindowsPlatform();
|
|
|
|
static gfxWindowsPlatform *GetPlatform() {
|
|
|
|
return (gfxWindowsPlatform*) gfxPlatform::GetPlatform();
|
|
|
|
}
|
|
|
|
|
2009-10-07 07:13:40 -07:00
|
|
|
virtual gfxPlatformFontList* CreatePlatformFontList();
|
|
|
|
|
2014-02-09 00:04:38 -08:00
|
|
|
virtual already_AddRefed<gfxASurface>
|
|
|
|
CreateOffscreenSurface(const IntSize& size,
|
|
|
|
gfxContentType contentType) MOZ_OVERRIDE;
|
2012-06-25 19:43:31 -07:00
|
|
|
|
2012-09-24 08:02:49 -07:00
|
|
|
virtual mozilla::TemporaryRef<mozilla::gfx::ScaledFont>
|
2012-07-24 03:18:37 -07:00
|
|
|
GetScaledFontForFont(mozilla::gfx::DrawTarget* aTarget, gfxFont *aFont);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-08 16:34:02 -07:00
|
|
|
enum RenderMode {
|
|
|
|
/* Use GDI and windows surfaces */
|
|
|
|
RENDER_GDI = 0,
|
|
|
|
|
|
|
|
/* Use 32bpp image surfaces and call StretchDIBits */
|
|
|
|
RENDER_IMAGE_STRETCH32,
|
|
|
|
|
|
|
|
/* Use 32bpp image surfaces, and do 32->24 conversion before calling StretchDIBits */
|
|
|
|
RENDER_IMAGE_STRETCH24,
|
|
|
|
|
2010-02-25 22:36:07 -08:00
|
|
|
/* Use Direct2D rendering */
|
|
|
|
RENDER_DIRECT2D,
|
|
|
|
|
2009-07-08 16:34:02 -07:00
|
|
|
/* max */
|
|
|
|
RENDER_MODE_MAX
|
|
|
|
};
|
|
|
|
|
2013-12-18 10:09:10 -08:00
|
|
|
int GetScreenDepth() const;
|
|
|
|
|
2009-07-08 16:34:02 -07:00
|
|
|
RenderMode GetRenderMode() { return mRenderMode; }
|
|
|
|
void SetRenderMode(RenderMode rmode) { mRenderMode = rmode; }
|
|
|
|
|
2010-09-15 15:16:09 -07:00
|
|
|
/**
|
|
|
|
* Updates render mode with relation to the current preferences and
|
|
|
|
* available devices.
|
|
|
|
*/
|
|
|
|
void UpdateRenderMode();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifies a D2D device is present and working, will attempt to create one
|
|
|
|
* it is non-functional or non-existant.
|
|
|
|
*
|
|
|
|
* \param aAttemptForce Attempt to force D2D cairo device creation by using
|
|
|
|
* cairo device creation routines.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
void VerifyD2DDevice(bool aAttemptForce);
|
2010-09-15 15:16:09 -07:00
|
|
|
|
2013-03-22 12:32:56 -07:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
|
|
|
HRESULT CreateDevice(nsRefPtr<IDXGIAdapter1> &adapter1, int featureLevelIndex);
|
|
|
|
#endif
|
|
|
|
|
2013-04-01 02:10:28 -07:00
|
|
|
/**
|
|
|
|
* Return the resolution scaling factor to convert between "logical" or
|
|
|
|
* "screen" pixels as used by Windows (dependent on the DPI scaling option
|
|
|
|
* in the Display control panel) and actual device pixels.
|
|
|
|
*/
|
2013-12-14 12:40:55 -08:00
|
|
|
double GetDPIScale();
|
2013-04-01 02:10:28 -07:00
|
|
|
|
2010-02-24 09:57:57 -08:00
|
|
|
nsresult GetFontList(nsIAtom *aLangGroup,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsACString& aGenericFamily,
|
2009-01-18 12:14:14 -08:00
|
|
|
nsTArray<nsString>& aListOfFonts);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult UpdateFontList();
|
|
|
|
|
2014-09-29 23:27:55 -07:00
|
|
|
virtual void GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aRunScript,
|
2012-03-08 18:05:24 -08:00
|
|
|
nsTArray<const char*>& aFontList);
|
|
|
|
|
2008-03-13 03:32:50 -07:00
|
|
|
nsresult GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName);
|
|
|
|
|
2014-06-05 23:09:23 -07:00
|
|
|
gfxFontGroup *CreateFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
|
2008-09-30 20:01:53 -07:00
|
|
|
const gfxFontStyle *aStyle,
|
|
|
|
gfxUserFontSet *aUserFontSet);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Look up a local platform font using the full font face name (needed to support @font-face src local() )
|
|
|
|
*/
|
2014-09-08 00:23:19 -07:00
|
|
|
virtual gfxFontEntry* LookupLocalFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
|
|
|
bool aItalic);
|
2008-09-30 20:01:53 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Activate a platform font (needed to support @font-face src url() )
|
|
|
|
*/
|
2014-09-08 00:23:19 -07:00
|
|
|
virtual gfxFontEntry* MakePlatformFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
|
|
|
bool aItalic,
|
|
|
|
const uint8_t* aFontData,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLength);
|
2008-09-30 20:01:53 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether format is supported on a platform or not (if unclear, returns true)
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags);
|
2007-04-02 12:06:16 -07:00
|
|
|
|
2014-09-24 10:12:10 -07:00
|
|
|
virtual bool DidRenderingDeviceReset();
|
|
|
|
|
2010-05-26 22:05:30 -07:00
|
|
|
// ClearType is not always enabled even when available (e.g. Windows XP)
|
|
|
|
// if either of these prefs are enabled and apply, use ClearType rendering
|
2011-09-28 23:19:26 -07:00
|
|
|
bool UseClearTypeForDownloadableFonts();
|
|
|
|
bool UseClearTypeAlways();
|
2010-05-26 22:05:30 -07:00
|
|
|
|
2013-12-11 01:46:41 -08:00
|
|
|
static void GetDLLVersion(char16ptr_t aDLLPath, nsAString& aVersion);
|
2011-01-14 04:57:17 -08:00
|
|
|
|
2011-05-10 17:30:20 -07:00
|
|
|
// returns ClearType tuning information for each display
|
|
|
|
static void GetCleartypeParams(nsTArray<ClearTypeParameterInfo>& aParams);
|
|
|
|
|
2011-06-11 19:30:16 -07:00
|
|
|
virtual void FontsPrefsChanged(const char *aPref);
|
2010-05-26 22:05:30 -07:00
|
|
|
|
2011-06-11 19:30:16 -07:00
|
|
|
void SetupClearTypeParams();
|
2011-04-20 23:29:50 -07:00
|
|
|
|
2010-02-25 22:36:07 -08:00
|
|
|
#ifdef CAIRO_HAS_DWRITE_FONT
|
2010-12-02 02:37:17 -08:00
|
|
|
IDWriteFactory *GetDWriteFactory() { return mDWriteFactory; }
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool DWriteEnabled() { return mUseDirectWrite; }
|
2011-04-20 23:29:50 -07:00
|
|
|
inline DWRITE_MEASURING_MODE DWriteMeasuringMode() { return mMeasuringMode; }
|
2011-12-06 04:39:19 -08:00
|
|
|
IDWriteTextAnalyzer *GetDWriteAnalyzer() { return mDWriteAnalyzer; }
|
2012-03-19 12:20:18 -07:00
|
|
|
|
|
|
|
IDWriteRenderingParams *GetRenderingParams(TextRenderingMode aRenderMode)
|
|
|
|
{ return mRenderingParams[aRenderMode]; }
|
2010-08-16 00:15:03 -07:00
|
|
|
#else
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool DWriteEnabled() { return false; }
|
2010-02-25 22:36:07 -08:00
|
|
|
#endif
|
2013-11-21 14:07:56 -08:00
|
|
|
void OnDeviceManagerDestroy(mozilla::layers::DeviceManagerD3D9* aDeviceManager);
|
2013-08-04 00:46:17 -07:00
|
|
|
mozilla::layers::DeviceManagerD3D9* GetD3D9DeviceManager();
|
|
|
|
IDirect3DDevice9* GetD3D9Device();
|
2010-08-10 16:59:51 -07:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
|
|
|
cairo_device_t *GetD2DDevice() { return mD2DDevice; }
|
2012-07-30 07:20:58 -07:00
|
|
|
ID3D10Device1 *GetD3D10Device() { return mD2DDevice ? cairo_d2d_device_get_device(mD2DDevice) : nullptr; }
|
2010-08-10 16:59:51 -07:00
|
|
|
#endif
|
2013-05-01 07:27:09 -07:00
|
|
|
ID3D11Device *GetD3D11Device();
|
2014-09-14 14:51:27 -07:00
|
|
|
ID3D11Device *GetD3D11ContentDevice();
|
2010-02-25 22:36:07 -08:00
|
|
|
|
2014-07-30 06:38:46 -07:00
|
|
|
mozilla::layers::ReadbackManagerD3D11* GetReadbackManager();
|
|
|
|
|
2011-03-01 17:00:33 -08:00
|
|
|
static bool IsOptimus();
|
|
|
|
|
2015-01-20 19:36:01 -08:00
|
|
|
bool IsWARP() { return mIsWARP; }
|
|
|
|
|
2009-07-08 16:34:02 -07:00
|
|
|
protected:
|
|
|
|
RenderMode mRenderMode;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int8_t mUseClearTypeForDownloadableFonts;
|
|
|
|
int8_t mUseClearTypeAlways;
|
2010-05-26 22:05:30 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
void Init();
|
2014-09-14 14:51:27 -07:00
|
|
|
void InitD3D11Devices();
|
2013-05-01 07:27:09 -07:00
|
|
|
IDXGIAdapter1 *GetDXGIAdapter();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mUseDirectWrite;
|
|
|
|
bool mUsingGDIFonts;
|
2010-09-15 15:16:09 -07:00
|
|
|
|
2010-02-25 22:36:07 -08:00
|
|
|
#ifdef CAIRO_HAS_DWRITE_FONT
|
|
|
|
nsRefPtr<IDWriteFactory> mDWriteFactory;
|
2011-12-06 04:39:19 -08:00
|
|
|
nsRefPtr<IDWriteTextAnalyzer> mDWriteAnalyzer;
|
2012-03-19 12:20:18 -07:00
|
|
|
nsRefPtr<IDWriteRenderingParams> mRenderingParams[TEXT_RENDERING_COUNT];
|
2011-04-20 23:29:50 -07:00
|
|
|
DWRITE_MEASURING_MODE mMeasuringMode;
|
2010-02-25 22:36:07 -08:00
|
|
|
#endif
|
2010-08-10 16:59:51 -07:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
|
|
|
cairo_device_t *mD2DDevice;
|
|
|
|
#endif
|
2013-05-01 07:27:09 -07:00
|
|
|
mozilla::RefPtr<IDXGIAdapter1> mAdapter;
|
2013-08-04 00:46:17 -07:00
|
|
|
nsRefPtr<mozilla::layers::DeviceManagerD3D9> mDeviceManager;
|
2013-05-01 07:27:09 -07:00
|
|
|
mozilla::RefPtr<ID3D11Device> mD3D11Device;
|
2014-09-14 14:51:27 -07:00
|
|
|
mozilla::RefPtr<ID3D11Device> mD3D11ContentDevice;
|
2013-05-01 07:27:09 -07:00
|
|
|
bool mD3D11DeviceInitialized;
|
2014-07-30 06:38:46 -07:00
|
|
|
mozilla::RefPtr<mozilla::layers::ReadbackManagerD3D11> mD3D11ReadbackManager;
|
2015-01-20 19:36:01 -08:00
|
|
|
bool mIsWARP;
|
2010-02-25 22:36:07 -08:00
|
|
|
|
2013-11-07 02:20:08 -08:00
|
|
|
virtual void GetPlatformCMSOutputProfile(void* &mem, size_t &size);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2014-12-21 21:41:57 -08:00
|
|
|
bool DoesD3D11TextureSharingWork(ID3D11Device *device);
|
2014-11-03 14:55:00 -08:00
|
|
|
bool DoesD3D11DeviceWork(ID3D11Device *device);
|
2014-10-22 21:15:22 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* GFX_WINDOWS_PLATFORM_H */
|