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

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: review 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
« no previous file with comments | « ui/gfx/font_render_params.cc ('k') | ui/gfx/platform_font_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(),
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 if (pixel_structure == 2)
34 return FontRenderParams::SUBPIXEL_RENDERING_BGR;
35 }
36 break;
37 }
38 }
39
40 // No explicit ClearType settings, default to RGB.
41 return FontRenderParams::SUBPIXEL_RENDERING_RGB;
42 }
43
16 // Caches font render params and updates them on system notifications. 44 // Caches font render params and updates them on system notifications.
17 class CachedFontRenderParams : public gfx::SingletonHwnd::Observer { 45 class CachedFontRenderParams : public gfx::SingletonHwnd::Observer {
18 public: 46 public:
19 static CachedFontRenderParams* GetInstance() { 47 static CachedFontRenderParams* GetInstance() {
20 return Singleton<CachedFontRenderParams>::get(); 48 return Singleton<CachedFontRenderParams>::get();
21 } 49 }
22 50
23 const FontRenderParams& GetParams() { 51 const FontRenderParams& GetParams() {
24 if (params_) 52 if (params_)
25 return *params_; 53 return *params_;
26 54
27 params_.reset(new FontRenderParams()); 55 params_.reset(new FontRenderParams());
28 params_->antialiasing = false; 56 params_->antialiasing = false;
29 params_->subpixel_positioning = false; 57 params_->subpixel_positioning = false;
30 params_->autohinter = false; 58 params_->autohinter = false;
31 params_->use_bitmaps = false; 59 params_->use_bitmaps = false;
32 params_->hinting = FontRenderParams::HINTING_MEDIUM; 60 params_->hinting = FontRenderParams::HINTING_MEDIUM;
33 params_->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE; 61 params_->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE;
34 62
35 BOOL enabled = false; 63 BOOL enabled = false;
36 if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) && enabled) { 64 if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) && enabled) {
37 params_->antialiasing = true; 65 params_->antialiasing = true;
38 // GDI does not support subpixel positioning. 66 // GDI does not support subpixel positioning.
39 params_->subpixel_positioning = win::IsDirectWriteEnabled(); 67 params_->subpixel_positioning = win::IsDirectWriteEnabled();
40 68
41 UINT type = 0; 69 UINT type = 0;
42 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &type, 0) && 70 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &type, 0) &&
43 type == FE_FONTSMOOTHINGCLEARTYPE) { 71 type == FE_FONTSMOOTHINGCLEARTYPE) {
44 params_->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB; 72 params_->subpixel_rendering = GetSubpixelRenderingGeometry();
45 } 73 }
46 } 74 }
47 gfx::SingletonHwnd::GetInstance()->AddObserver(this); 75 gfx::SingletonHwnd::GetInstance()->AddObserver(this);
48 return *params_; 76 return *params_;
49 } 77 }
50 78
51 private: 79 private:
52 friend struct DefaultSingletonTraits<CachedFontRenderParams>; 80 friend struct DefaultSingletonTraits<CachedFontRenderParams>;
53 81
54 CachedFontRenderParams() {} 82 CachedFontRenderParams() {}
(...skipping 21 matching lines...) Expand all
76 104
77 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query, 105 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query,
78 std::string* family_out) { 106 std::string* family_out) {
79 if (family_out) 107 if (family_out)
80 NOTIMPLEMENTED(); 108 NOTIMPLEMENTED();
81 // Customized font rendering settings are not supported, only defaults. 109 // Customized font rendering settings are not supported, only defaults.
82 return CachedFontRenderParams::GetInstance()->GetParams(); 110 return CachedFontRenderParams::GetInstance()->GetParams();
83 } 111 }
84 112
85 } // namespace gfx 113 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/font_render_params.cc ('k') | ui/gfx/platform_font_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698