Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: ui/gfx/font_render_params_win.cc

Issue 1021643002: Retrieve and pass subpixel lcd geometry on windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ws Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/font_render_params.h" 5 #include "base/files/file_path.h"
6
7 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/singleton.h" 7 #include "base/memory/singleton.h"
8 #include "base/win/registry.h"
9 #include "ui/gfx/font_render_params.h"
9 #include "ui/gfx/win/direct_write.h" 10 #include "ui/gfx/win/direct_write.h"
10 #include "ui/gfx/win/singleton_hwnd.h" 11 #include "ui/gfx/win/singleton_hwnd.h"
11 12
12 namespace gfx { 13 namespace gfx {
13 14
14 namespace { 15 namespace {
15 16
17 FontRenderParams::SubpixelRendering GetSubpixelRenderingGeometry() {
18 DISPLAY_DEVICE display_device = {sizeof(DISPLAY_DEVICE), 0};
19 for (int i = 0; EnumDisplayDevices(nullptr, i, &display_device, 0); ++i) {
20 // TODO(scottmg): We only support the primary device currently.
21 if (display_device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
22 base::FilePath trimmed =
23 base::FilePath(display_device.DeviceName).BaseName();
24 base::win::RegKey key(
25 HKEY_LOCAL_MACHINE,
26 (L"SOFTWARE\\Microsoft\\Avalon.Graphics\\" + trimmed.value()).c_str(),
msw 2015/03/26 20:41:25 Hmm, I wonder why I don't have "Avalon.Graphics" i
scottmg 2015/03/26 21:16:17 Oh, good catch. I just confirmed on a clean Win7 V
27 KEY_READ);
28 DWORD pixel_structure;
29 if (key.ReadValueDW(L"PixelStructure", &pixel_structure) ==
30 ERROR_SUCCESS) {
31 if (pixel_structure == 1)
32 return FontRenderParams::SUBPIXEL_RENDERING_RGB;
33 else if (pixel_structure == 2)
msw 2015/03/26 20:41:25 nit: no else after return.
scottmg 2015/03/26 21:16:17 Done.
34 return FontRenderParams::SUBPIXEL_RENDERING_BGR;
35 }
msw 2015/03/26 20:41:25 nit: can you break the loop of enumerating devices
scottmg 2015/03/26 21:16:17 Done.
36 }
37 }
38
39 // ClearType is not enabled, or retrieval failed.
msw 2015/03/26 20:41:25 nit: I have ClearType on but don't have this key..
scottmg 2015/03/26 21:16:17 Done.
40 return FontRenderParams::SUBPIXEL_RENDERING_NONE;
41 }
42
16 // Caches font render params and updates them on system notifications. 43 // Caches font render params and updates them on system notifications.
17 class CachedFontRenderParams : public gfx::SingletonHwnd::Observer { 44 class CachedFontRenderParams : public gfx::SingletonHwnd::Observer {
18 public: 45 public:
19 static CachedFontRenderParams* GetInstance() { 46 static CachedFontRenderParams* GetInstance() {
20 return Singleton<CachedFontRenderParams>::get(); 47 return Singleton<CachedFontRenderParams>::get();
21 } 48 }
22 49
23 const FontRenderParams& GetParams() { 50 const FontRenderParams& GetParams() {
24 if (params_) 51 if (params_)
25 return *params_; 52 return *params_;
26 53
27 params_.reset(new FontRenderParams()); 54 params_.reset(new FontRenderParams());
28 params_->antialiasing = false; 55 params_->antialiasing = false;
29 params_->subpixel_positioning = false; 56 params_->subpixel_positioning = false;
30 params_->autohinter = false; 57 params_->autohinter = false;
31 params_->use_bitmaps = false; 58 params_->use_bitmaps = false;
32 params_->hinting = FontRenderParams::HINTING_MEDIUM; 59 params_->hinting = FontRenderParams::HINTING_MEDIUM;
33 params_->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE; 60 params_->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE;
34 61
35 BOOL enabled = false; 62 BOOL enabled = false;
36 if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) && enabled) { 63 if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) && enabled) {
37 params_->antialiasing = true; 64 params_->antialiasing = true;
38 // GDI does not support subpixel positioning. 65 // GDI does not support subpixel positioning.
39 params_->subpixel_positioning = win::IsDirectWriteEnabled(); 66 params_->subpixel_positioning = win::IsDirectWriteEnabled();
40 67
41 UINT type = 0; 68 UINT type = 0;
42 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &type, 0) && 69 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &type, 0) &&
43 type == FE_FONTSMOOTHINGCLEARTYPE) { 70 type == FE_FONTSMOOTHINGCLEARTYPE) {
44 params_->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB; 71 params_->subpixel_rendering = GetSubpixelRenderingGeometry();
45 } 72 }
46 } 73 }
47 gfx::SingletonHwnd::GetInstance()->AddObserver(this); 74 gfx::SingletonHwnd::GetInstance()->AddObserver(this);
48 return *params_; 75 return *params_;
49 } 76 }
50 77
51 private: 78 private:
52 friend struct DefaultSingletonTraits<CachedFontRenderParams>; 79 friend struct DefaultSingletonTraits<CachedFontRenderParams>;
53 80
54 CachedFontRenderParams() {} 81 CachedFontRenderParams() {}
(...skipping 21 matching lines...) Expand all
76 103
77 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query, 104 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query,
78 std::string* family_out) { 105 std::string* family_out) {
79 if (family_out) 106 if (family_out)
80 NOTIMPLEMENTED(); 107 NOTIMPLEMENTED();
81 // Customized font rendering settings are not supported, only defaults. 108 // Customized font rendering settings are not supported, only defaults.
82 return CachedFontRenderParams::GetInstance()->GetParams(); 109 return CachedFontRenderParams::GetInstance()->GetParams();
83 } 110 }
84 111
85 } // namespace gfx 112 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698