Call _set_FMA3_enable(0); to work around VS 2013 CRT AVX bug.
[chromium-blink-merge.git] / ui / gfx / font_render_params_win.cc
blob354d1b248b740e13dfa9e7a815af73f47c6abd9b
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/gfx/font_render_params.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/singleton.h"
9 #include "ui/gfx/win/singleton_hwnd.h"
11 namespace gfx {
13 namespace {
15 // Caches font render params and updates them on system notifications.
16 class CachedFontRenderParams : public gfx::SingletonHwnd::Observer {
17 public:
18 static CachedFontRenderParams* GetInstance() {
19 return Singleton<CachedFontRenderParams>::get();
22 const FontRenderParams& GetParams() {
23 if (params_)
24 return *params_;
26 params_.reset(new FontRenderParams());
27 params_->antialiasing = false;
28 params_->subpixel_positioning = false;
29 params_->autohinter = false;
30 params_->use_bitmaps = false;
31 params_->hinting = FontRenderParams::HINTING_MEDIUM;
32 params_->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE;
34 BOOL enabled = false;
35 if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) && enabled) {
36 params_->antialiasing = true;
37 params_->subpixel_positioning = true;
39 UINT type = 0;
40 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &type, 0) &&
41 type == FE_FONTSMOOTHINGCLEARTYPE) {
42 params_->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB;
45 gfx::SingletonHwnd::GetInstance()->AddObserver(this);
46 return *params_;
49 private:
50 friend struct DefaultSingletonTraits<CachedFontRenderParams>;
52 CachedFontRenderParams() {}
53 virtual ~CachedFontRenderParams() {
54 // Can't remove the SingletonHwnd observer here since SingletonHwnd may have
55 // been destroyed already (both singletons).
58 virtual void OnWndProc(HWND hwnd,
59 UINT message,
60 WPARAM wparam,
61 LPARAM lparam) override {
62 if (message == WM_SETTINGCHANGE) {
63 params_.reset();
64 gfx::SingletonHwnd::GetInstance()->RemoveObserver(this);
68 scoped_ptr<FontRenderParams> params_;
70 DISALLOW_COPY_AND_ASSIGN(CachedFontRenderParams);
73 } // namespace
75 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query,
76 std::string* family_out) {
77 if (family_out)
78 NOTIMPLEMENTED();
79 // Customized font rendering settings are not supported, only defaults.
80 return CachedFontRenderParams::GetInstance()->GetParams();
83 } // namespace gfx