2006-02-01 02:35:38 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 11:12:37 +00: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/. */
|
2006-02-01 02:35:38 +00:00
|
|
|
|
|
|
|
#ifndef GFX_WINDOWS_PLATFORM_H
|
|
|
|
#define GFX_WINDOWS_PLATFORM_H
|
|
|
|
|
2010-02-26 06:36:07 +00:00
|
|
|
|
|
|
|
/**
|
2011-02-21 13:47:32 +00:00
|
|
|
* XXX to get CAIRO_HAS_D2D_SURFACE, CAIRO_HAS_DWRITE_FONT
|
|
|
|
* and cairo_win32_scaled_font_select_font
|
2010-02-26 06:36:07 +00:00
|
|
|
*/
|
2011-02-21 13:47:32 +00:00
|
|
|
#include "cairo-win32.h"
|
2010-02-26 06:36:07 +00:00
|
|
|
|
2008-04-04 02:01:22 +00:00
|
|
|
#include "gfxFontUtils.h"
|
2006-02-15 02:48:08 +00:00
|
|
|
#include "gfxWindowsSurface.h"
|
2010-03-17 11:40:29 +00:00
|
|
|
#include "gfxFont.h"
|
2010-02-26 06:36:07 +00:00
|
|
|
#ifdef CAIRO_HAS_DWRITE_FONT
|
|
|
|
#include "gfxDWriteFonts.h"
|
|
|
|
#endif
|
2006-02-01 02:35:38 +00:00
|
|
|
#include "gfxPlatform.h"
|
2010-03-15 09:34:25 +00:00
|
|
|
#include "gfxContext.h"
|
2006-02-01 02:35:38 +00:00
|
|
|
|
2009-01-18 20:14:14 +00:00
|
|
|
#include "nsTArray.h"
|
2006-06-10 00:21:05 +00:00
|
|
|
#include "nsDataHashtable.h"
|
2006-02-15 02:48:08 +00:00
|
|
|
|
2006-02-24 05:15:21 +00:00
|
|
|
#include <windows.h>
|
2010-08-26 22:26:47 +00:00
|
|
|
#include <objbase.h>
|
2006-02-24 05:15:21 +00:00
|
|
|
|
2013-03-22 19:32:56 +00:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
|
|
|
#include <dxgi.h>
|
|
|
|
#endif
|
|
|
|
|
2012-02-08 23:13:50 +00:00
|
|
|
class nsIMemoryMultiReporter;
|
|
|
|
|
2010-03-15 09:34:25 +00:00
|
|
|
// Utility to get a Windows HDC from a thebes context,
|
|
|
|
// used by both GDI and Uniscribe font shapers
|
|
|
|
struct DCFromContext {
|
|
|
|
DCFromContext(gfxContext *aContext) {
|
|
|
|
dc = NULL;
|
|
|
|
nsRefPtr<gfxASurface> aSurface = aContext->CurrentSurface();
|
|
|
|
NS_ASSERTION(aSurface, "DCFromContext: null surface");
|
|
|
|
if (aSurface &&
|
|
|
|
(aSurface->GetType() == gfxASurface::SurfaceTypeWin32 ||
|
|
|
|
aSurface->GetType() == gfxASurface::SurfaceTypeWin32Printing))
|
|
|
|
{
|
|
|
|
dc = static_cast<gfxWindowsSurface*>(aSurface.get())->GetDC();
|
2011-10-17 14:59:28 +00:00
|
|
|
needsRelease = false;
|
2011-02-19 20:48:33 +00:00
|
|
|
SaveDC(dc);
|
|
|
|
cairo_scaled_font_t* scaled =
|
|
|
|
cairo_get_scaled_font(aContext->GetCairo());
|
|
|
|
cairo_win32_scaled_font_select_font(scaled, dc);
|
2010-03-15 09:34:25 +00:00
|
|
|
}
|
|
|
|
if (!dc) {
|
|
|
|
dc = GetDC(NULL);
|
|
|
|
SetGraphicsMode(dc, GM_ADVANCED);
|
2011-10-17 14:59:28 +00:00
|
|
|
needsRelease = true;
|
2010-03-15 09:34:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~DCFromContext() {
|
2011-02-19 20:48:33 +00:00
|
|
|
if (needsRelease) {
|
2010-03-15 09:34:25 +00:00
|
|
|
ReleaseDC(NULL, dc);
|
2011-02-19 20:48:33 +00:00
|
|
|
} else {
|
|
|
|
RestoreDC(dc, -1);
|
|
|
|
}
|
2010-03-15 09:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
operator HDC () {
|
|
|
|
return dc;
|
|
|
|
}
|
|
|
|
|
|
|
|
HDC dc;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool needsRelease;
|
2010-03-15 09:34:25 +00:00
|
|
|
};
|
|
|
|
|
2011-05-11 00:30:20 +00: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 15:56:38 +00:00
|
|
|
int32_t gamma;
|
|
|
|
int32_t pixelStructure;
|
|
|
|
int32_t clearTypeLevel;
|
|
|
|
int32_t enhancedContrast;
|
2011-05-11 00:30:20 +00:00
|
|
|
};
|
|
|
|
|
2009-10-07 14:13:40 +00:00
|
|
|
class THEBES_API gfxWindowsPlatform : public gfxPlatform {
|
2006-02-01 02:35:38 +00:00
|
|
|
public:
|
2012-03-19 19:20:18 +00:00
|
|
|
enum TextRenderingMode {
|
|
|
|
TEXT_RENDERING_NO_CLEARTYPE,
|
|
|
|
TEXT_RENDERING_NORMAL,
|
|
|
|
TEXT_RENDERING_GDI_CLASSIC,
|
|
|
|
TEXT_RENDERING_COUNT
|
|
|
|
};
|
|
|
|
|
2006-02-01 02:35:38 +00:00
|
|
|
gfxWindowsPlatform();
|
2006-02-24 05:15:21 +00:00
|
|
|
virtual ~gfxWindowsPlatform();
|
2006-02-01 02:35:38 +00:00
|
|
|
static gfxWindowsPlatform *GetPlatform() {
|
|
|
|
return (gfxWindowsPlatform*) gfxPlatform::GetPlatform();
|
|
|
|
}
|
|
|
|
|
2009-10-07 14:13:40 +00:00
|
|
|
virtual gfxPlatformFontList* CreatePlatformFontList();
|
|
|
|
|
2007-02-08 20:47:48 +00:00
|
|
|
already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
|
2010-09-16 21:34:53 +00:00
|
|
|
gfxASurface::gfxContentType contentType);
|
2012-06-26 02:43:31 +00:00
|
|
|
virtual already_AddRefed<gfxASurface>
|
|
|
|
CreateOffscreenImageSurface(const gfxIntSize& aSize,
|
|
|
|
gfxASurface::gfxContentType aContentType);
|
|
|
|
|
2012-09-24 15:02:49 +00:00
|
|
|
virtual mozilla::TemporaryRef<mozilla::gfx::ScaledFont>
|
2012-07-24 10:18:37 +00:00
|
|
|
GetScaledFontForFont(mozilla::gfx::DrawTarget* aTarget, gfxFont *aFont);
|
2011-06-24 17:41:18 +00:00
|
|
|
virtual already_AddRefed<gfxASurface>
|
|
|
|
GetThebesSurfaceForDrawTarget(mozilla::gfx::DrawTarget *aTarget);
|
2006-02-01 02:35:38 +00:00
|
|
|
|
2009-07-08 23:34:02 +00: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-26 06:36:07 +00:00
|
|
|
/* Use Direct2D rendering */
|
|
|
|
RENDER_DIRECT2D,
|
|
|
|
|
2009-07-08 23:34:02 +00:00
|
|
|
/* max */
|
|
|
|
RENDER_MODE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
RenderMode GetRenderMode() { return mRenderMode; }
|
|
|
|
void SetRenderMode(RenderMode rmode) { mRenderMode = rmode; }
|
|
|
|
|
2010-09-15 22:16:09 +00: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-29 06:19:26 +00:00
|
|
|
void VerifyD2DDevice(bool aAttemptForce);
|
2010-09-15 22:16:09 +00:00
|
|
|
|
2013-03-22 19:32:56 +00:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
|
|
|
HRESULT CreateDevice(nsRefPtr<IDXGIAdapter1> &adapter1, int featureLevelIndex);
|
|
|
|
#endif
|
|
|
|
|
2010-08-20 01:26:00 +00:00
|
|
|
HDC GetScreenDC() { return mScreenDC; }
|
|
|
|
|
2013-04-01 09:10:28 +00: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.
|
|
|
|
*/
|
|
|
|
double GetDPIScale() {
|
|
|
|
return GetDeviceCaps(mScreenDC, LOGPIXELSY) / 96.0;
|
|
|
|
}
|
|
|
|
|
2010-02-24 17:57:57 +00:00
|
|
|
nsresult GetFontList(nsIAtom *aLangGroup,
|
2006-02-01 02:35:38 +00:00
|
|
|
const nsACString& aGenericFamily,
|
2009-01-18 20:14:14 +00:00
|
|
|
nsTArray<nsString>& aListOfFonts);
|
2006-02-01 02:35:38 +00:00
|
|
|
|
2006-06-15 04:47:23 +00:00
|
|
|
nsresult UpdateFontList();
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual void GetCommonFallbackFonts(const uint32_t aCh,
|
|
|
|
int32_t aRunScript,
|
2012-03-09 02:05:24 +00:00
|
|
|
nsTArray<const char*>& aFontList);
|
|
|
|
|
2006-11-21 06:31:04 +00:00
|
|
|
nsresult ResolveFontName(const nsAString& aFontName,
|
|
|
|
FontResolverCallback aCallback,
|
2011-09-29 06:19:26 +00:00
|
|
|
void *aClosure, bool& aAborted);
|
2006-06-15 04:47:23 +00:00
|
|
|
|
2008-03-13 10:32:50 +00:00
|
|
|
nsresult GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName);
|
|
|
|
|
2007-04-02 19:06:16 +00:00
|
|
|
gfxFontGroup *CreateFontGroup(const nsAString &aFamilies,
|
2008-10-01 03:01:53 +00: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() )
|
|
|
|
*/
|
2009-01-03 03:21:49 +00:00
|
|
|
virtual gfxFontEntry* LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
const nsAString& aFontName);
|
2008-10-01 03:01:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Activate a platform font (needed to support @font-face src url() )
|
|
|
|
*/
|
2008-12-05 23:19:27 +00:00
|
|
|
virtual gfxFontEntry* MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint8_t *aFontData,
|
|
|
|
uint32_t aLength);
|
2008-10-01 03:01:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether format is supported on a platform or not (if unclear, returns true)
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual bool IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags);
|
2007-04-02 19:06:16 +00:00
|
|
|
|
2008-03-19 00:06:55 +00:00
|
|
|
/* Find a FontFamily/FontEntry object that represents a font on your system given a name */
|
2009-10-07 14:13:40 +00:00
|
|
|
gfxFontFamily *FindFontFamily(const nsAString& aName);
|
|
|
|
gfxFontEntry *FindFontEntry(const nsAString& aName, const gfxFontStyle& aFontStyle);
|
2006-02-24 05:15:21 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool GetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> > *array);
|
2009-10-07 14:13:40 +00:00
|
|
|
void SetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> >& array);
|
2008-03-19 00:06:55 +00:00
|
|
|
|
2009-04-04 09:43:42 +00:00
|
|
|
void ClearPrefFonts() { mPrefFonts.Clear(); }
|
|
|
|
|
2010-05-27 05:05:30 +00: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-29 06:19:26 +00:00
|
|
|
bool UseClearTypeForDownloadableFonts();
|
|
|
|
bool UseClearTypeAlways();
|
2010-05-27 05:05:30 +00:00
|
|
|
|
|
|
|
// OS version in 16.16 major/minor form
|
|
|
|
// based on http://msdn.microsoft.com/en-us/library/ms724834(VS.85).aspx
|
|
|
|
enum {
|
|
|
|
kWindowsUnknown = 0,
|
|
|
|
kWindowsXP = 0x50001,
|
|
|
|
kWindowsServer2003 = 0x50002,
|
|
|
|
kWindowsVista = 0x60000,
|
2012-08-31 16:42:07 +00:00
|
|
|
kWindows7 = 0x60001,
|
|
|
|
kWindows8 = 0x60002
|
2010-05-27 05:05:30 +00:00
|
|
|
};
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static int32_t WindowsOSVersion(int32_t *aBuildNum = nullptr);
|
2010-05-27 05:05:30 +00:00
|
|
|
|
2011-01-28 10:35:40 +00:00
|
|
|
static void GetDLLVersion(const PRUnichar *aDLLPath, nsAString& aVersion);
|
2011-01-14 12:57:17 +00:00
|
|
|
|
2011-05-11 00:30:20 +00:00
|
|
|
// returns ClearType tuning information for each display
|
|
|
|
static void GetCleartypeParams(nsTArray<ClearTypeParameterInfo>& aParams);
|
|
|
|
|
2011-06-12 02:30:16 +00:00
|
|
|
virtual void FontsPrefsChanged(const char *aPref);
|
2010-05-27 05:05:30 +00:00
|
|
|
|
2011-06-12 02:30:16 +00:00
|
|
|
void SetupClearTypeParams();
|
2011-04-21 06:29:50 +00:00
|
|
|
|
2010-02-26 06:36:07 +00:00
|
|
|
#ifdef CAIRO_HAS_DWRITE_FONT
|
2010-12-02 10:37:17 +00:00
|
|
|
IDWriteFactory *GetDWriteFactory() { return mDWriteFactory; }
|
2011-09-29 06:19:26 +00:00
|
|
|
inline bool DWriteEnabled() { return mUseDirectWrite; }
|
2011-04-21 06:29:50 +00:00
|
|
|
inline DWRITE_MEASURING_MODE DWriteMeasuringMode() { return mMeasuringMode; }
|
2011-12-06 12:39:19 +00:00
|
|
|
IDWriteTextAnalyzer *GetDWriteAnalyzer() { return mDWriteAnalyzer; }
|
2012-03-19 19:20:18 +00:00
|
|
|
|
|
|
|
IDWriteRenderingParams *GetRenderingParams(TextRenderingMode aRenderMode)
|
|
|
|
{ return mRenderingParams[aRenderMode]; }
|
2010-08-16 07:15:03 +00:00
|
|
|
#else
|
2011-09-29 06:19:26 +00:00
|
|
|
inline bool DWriteEnabled() { return false; }
|
2010-02-26 06:36:07 +00:00
|
|
|
#endif
|
2010-08-10 23:59:51 +00:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
|
|
|
cairo_device_t *GetD2DDevice() { return mD2DDevice; }
|
2012-07-30 14:20:58 +00:00
|
|
|
ID3D10Device1 *GetD3D10Device() { return mD2DDevice ? cairo_d2d_device_get_device(mD2DDevice) : nullptr; }
|
2010-08-10 23:59:51 +00:00
|
|
|
#endif
|
2010-02-26 06:36:07 +00:00
|
|
|
|
2011-03-02 01:00:33 +00:00
|
|
|
static bool IsOptimus();
|
|
|
|
|
2009-07-08 23:34:02 +00:00
|
|
|
protected:
|
|
|
|
RenderMode mRenderMode;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int8_t mUseClearTypeForDownloadableFonts;
|
|
|
|
int8_t mUseClearTypeAlways;
|
2010-08-20 01:26:00 +00:00
|
|
|
HDC mScreenDC;
|
2010-05-27 05:05:30 +00:00
|
|
|
|
2006-02-15 02:48:08 +00:00
|
|
|
private:
|
|
|
|
void Init();
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mUseDirectWrite;
|
|
|
|
bool mUsingGDIFonts;
|
2010-09-15 22:16:09 +00:00
|
|
|
|
2010-02-26 06:36:07 +00:00
|
|
|
#ifdef CAIRO_HAS_DWRITE_FONT
|
|
|
|
nsRefPtr<IDWriteFactory> mDWriteFactory;
|
2011-12-06 12:39:19 +00:00
|
|
|
nsRefPtr<IDWriteTextAnalyzer> mDWriteAnalyzer;
|
2012-03-19 19:20:18 +00:00
|
|
|
nsRefPtr<IDWriteRenderingParams> mRenderingParams[TEXT_RENDERING_COUNT];
|
2011-04-21 06:29:50 +00:00
|
|
|
DWRITE_MEASURING_MODE mMeasuringMode;
|
2010-02-26 06:36:07 +00:00
|
|
|
#endif
|
2010-08-10 23:59:51 +00:00
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
|
|
|
cairo_device_t *mD2DDevice;
|
|
|
|
#endif
|
2010-02-26 06:36:07 +00:00
|
|
|
|
2009-04-07 16:02:11 +00:00
|
|
|
virtual qcms_profile* GetPlatformCMSOutputProfile();
|
2007-07-23 22:02:17 +00:00
|
|
|
|
2009-10-07 14:13:40 +00:00
|
|
|
// TODO: unify this with mPrefFonts (NB: holds families, not fonts) in gfxPlatformFontList
|
|
|
|
nsDataHashtable<nsCStringHashKey, nsTArray<nsRefPtr<gfxFontEntry> > > mPrefFonts;
|
2012-02-08 23:13:50 +00:00
|
|
|
|
|
|
|
nsIMemoryMultiReporter* mGPUAdapterMultiReporter;
|
2006-02-01 02:35:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GFX_WINDOWS_PLATFORM_H */
|