Bug 1325199: Only read system parameters for ClearType when we receive a paint event. r=jrmuizel
MozReview-Commit-ID: EjQyCcdWXEc
--- a/gfx/thebes/gfxDWriteFonts.cpp
+++ b/gfx/thebes/gfxDWriteFonts.cpp
@@ -42,16 +42,18 @@ GetCairoAntialiasOption(gfxFont::Antiali
#ifndef SPI_GETFONTSMOOTHINGTYPE
#define SPI_GETFONTSMOOTHINGTYPE 0x200a
#endif
#ifndef FE_FONTSMOOTHINGCLEARTYPE
#define FE_FONTSMOOTHINGCLEARTYPE 2
#endif
+bool gfxDWriteFont::mUseClearType = true;
+
static bool
UsingClearType()
{
BOOL fontSmoothing;
if (!SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &fontSmoothing, 0) ||
!fontSmoothing)
{
return false;
@@ -112,16 +114,22 @@ gfxDWriteFont::~gfxDWriteFont()
cairo_font_face_destroy(mCairoFontFace);
}
if (mScaledFont) {
cairo_scaled_font_destroy(mScaledFont);
}
delete mMetrics;
}
+void
+gfxDWriteFont::UpdateClearTypeUsage()
+{
+ mUseClearType = UsingClearType();
+}
+
gfxFont*
gfxDWriteFont::CopyWithAntialiasOption(AntialiasOption anAAOption)
{
return new gfxDWriteFont(static_cast<gfxDWriteFontEntry*>(mFontEntry.get()),
&mStyle, mNeedsBold, anAAOption);
}
const gfxFont::Metrics&
@@ -168,17 +176,17 @@ gfxDWriteFont::ComputeMetrics(AntialiasO
fontMetrics.designUnitsPerEm;
mAdjustedSize = mStyle.GetAdjustedSize(aspect);
} else {
mAdjustedSize = mStyle.size;
}
// Note that GetMeasuringMode depends on mAdjustedSize
if ((anAAOption == gfxFont::kAntialiasDefault &&
- UsingClearType() &&
+ mUseClearType &&
GetMeasuringMode() == DWRITE_MEASURING_MODE_NATURAL) ||
anAAOption == gfxFont::kAntialiasSubpixel)
{
mUseSubpixelPositions = true;
// note that this may be reset to FALSE if we determine that a bitmap
// strike is going to be used
}
@@ -595,17 +603,17 @@ gfxDWriteFont::GetGlyphWidth(DrawTarget&
width = NS_lround(MeasureGlyphWidth(aGID) * 65536.0);
mGlyphWidths->Put(aGID, width);
return width;
}
already_AddRefed<GlyphRenderingOptions>
gfxDWriteFont::GetGlyphRenderingOptions(const TextRunDrawParams* aRunParams)
{
- if (UsingClearType()) {
+ if (mUseClearType) {
return Factory::CreateDWriteGlyphRenderingOptions(
gfxWindowsPlatform::GetPlatform()->GetRenderingParams(GetForceGDIClassic() ?
gfxWindowsPlatform::TEXT_RENDERING_GDI_CLASSIC : gfxWindowsPlatform::TEXT_RENDERING_NORMAL));
} else {
return Factory::CreateDWriteGlyphRenderingOptions(gfxWindowsPlatform::GetPlatform()->
GetRenderingParams(gfxWindowsPlatform::TEXT_RENDERING_NO_CLEARTYPE));
}
}
--- a/gfx/thebes/gfxDWriteFonts.h
+++ b/gfx/thebes/gfxDWriteFonts.h
@@ -24,16 +24,18 @@ class gfxDWriteFont : public gfxFont
{
public:
gfxDWriteFont(gfxFontEntry *aFontEntry,
const gfxFontStyle *aFontStyle,
bool aNeedsBold = false,
AntialiasOption = kAntialiasDefault);
~gfxDWriteFont();
+ static void UpdateClearTypeUsage();
+
virtual gfxFont*
CopyWithAntialiasOption(AntialiasOption anAAOption) override;
virtual uint32_t GetSpaceGlyph() override;
virtual bool SetupCairoFont(DrawTarget* aDrawTarget) override;
virtual bool AllowSubpixelAA() override
@@ -97,11 +99,12 @@ protected:
uint32_t mSpaceGlyph;
bool mNeedsOblique;
bool mNeedsBold;
bool mUseSubpixelPositions;
bool mAllowManualShowGlyphs;
bool mAzureScaledFontIsCairo;
+ static bool mUseClearType;
};
#endif
--- a/widget/windows/nsWindowGfx.cpp
+++ b/widget/windows/nsWindowGfx.cpp
@@ -24,16 +24,17 @@ using mozilla::plugins::PluginInstancePa
#include "nsWindowGfx.h"
#include "nsAppRunner.h"
#include <windows.h>
#include "gfxEnv.h"
#include "gfxImageSurface.h"
#include "gfxUtils.h"
#include "gfxWindowsSurface.h"
#include "gfxWindowsPlatform.h"
+#include "gfxDWriteFonts.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"
#include "mozilla/gfx/Tools.h"
#include "mozilla/RefPtr.h"
#include "mozilla/UniquePtrExtensions.h"
#include "nsGfxCIID.h"
#include "gfxContext.h"
#include "prmem.h"
@@ -182,16 +183,18 @@ bool nsWindow::OnPaint(HDC aDC, uint32_t
for (nsWindow* window : windows) {
window->OnRenderingDeviceReset(resetSeqNo);
}
gfxCriticalNote << "(nsWindow) Finished device reset.";
return false;
}
+ gfxDWriteFont::UpdateClearTypeUsage();
+
// After we CallUpdateWindow to the child, occasionally a WM_PAINT message
// is posted to the parent event loop with an empty update rect. Do a
// dummy paint so that Windows stops dispatching WM_PAINT in an inifinite
// loop. See bug 543788.
if (IsPlugin()) {
RECT updateRect;
if (!GetUpdateRect(mWnd, &updateRect, FALSE) ||
(updateRect.left == updateRect.right &&