OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/gfx/font_render_params.h" |
6 | 6 |
7 #include <fontconfig/fontconfig.h> | 7 #include <fontconfig/fontconfig.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/containers/mru_cache.h" | 10 #include "base/containers/mru_cache.h" |
11 #include "base/hash.h" | 11 #include "base/hash.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "ui/gfx/display.h" | |
19 #include "ui/gfx/font.h" | 20 #include "ui/gfx/font.h" |
20 #include "ui/gfx/linux_font_delegate.h" | 21 #include "ui/gfx/linux_font_delegate.h" |
22 #include "ui/gfx/screen.h" | |
21 #include "ui/gfx/switches.h" | 23 #include "ui/gfx/switches.h" |
22 | 24 |
23 namespace gfx { | 25 namespace gfx { |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 #if defined(OS_CHROMEOS) | 29 #if defined(OS_CHROMEOS) |
28 // A device scale factor for an internal display (if any) | 30 // A device scale factor for an internal display (if any) |
29 // that is used to determine if subpixel positioning should be used. | 31 // that is used to determine if subpixel positioning should be used. |
30 float device_scale_factor_for_internal_display = 1.0f; | 32 float device_scale_factor_for_internal_display = 1.0f; |
(...skipping 26 matching lines...) Expand all Loading... | |
57 | 59 |
58 base::Lock lock; | 60 base::Lock lock; |
59 Cache cache; | 61 Cache cache; |
60 }; | 62 }; |
61 | 63 |
62 base::LazyInstance<SynchronizedCache>::Leaky g_synchronized_cache = | 64 base::LazyInstance<SynchronizedCache>::Leaky g_synchronized_cache = |
63 LAZY_INSTANCE_INITIALIZER; | 65 LAZY_INSTANCE_INITIALIZER; |
64 | 66 |
65 bool IsBrowserTextSubpixelPositioningEnabled( | 67 bool IsBrowserTextSubpixelPositioningEnabled( |
66 const FontRenderParamsQuery& query) { | 68 const FontRenderParamsQuery& query) { |
67 #if defined(OS_CHROMEOS) | |
68 return query.device_scale_factor > 1.0f; | 69 return query.device_scale_factor > 1.0f; |
Daniel Erat
2015/03/16 13:57:53
it looks like you're enabling subpixel positioning
stapelberg
2015/03/17 08:36:34
Yeah, enabling this on HiDPi displays is what Chro
| |
69 #else | |
70 return false; | |
71 #endif | |
72 } | 70 } |
73 | 71 |
74 // Converts Fontconfig FC_HINT_STYLE to FontRenderParams::Hinting. | 72 // Converts Fontconfig FC_HINT_STYLE to FontRenderParams::Hinting. |
75 FontRenderParams::Hinting ConvertFontconfigHintStyle(int hint_style) { | 73 FontRenderParams::Hinting ConvertFontconfigHintStyle(int hint_style) { |
76 switch (hint_style) { | 74 switch (hint_style) { |
77 case FC_HINT_SLIGHT: return FontRenderParams::HINTING_SLIGHT; | 75 case FC_HINT_SLIGHT: return FontRenderParams::HINTING_SLIGHT; |
78 case FC_HINT_MEDIUM: return FontRenderParams::HINTING_MEDIUM; | 76 case FC_HINT_MEDIUM: return FontRenderParams::HINTING_MEDIUM; |
79 case FC_HINT_FULL: return FontRenderParams::HINTING_FULL; | 77 case FC_HINT_FULL: return FontRenderParams::HINTING_FULL; |
80 default: return FontRenderParams::HINTING_NONE; | 78 default: return FontRenderParams::HINTING_NONE; |
81 } | 79 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 query.point_size, query.style, JoinString(query.families, ',').c_str(), | 200 query.point_size, query.style, JoinString(query.families, ',').c_str(), |
203 query.device_scale_factor)); | 201 query.device_scale_factor)); |
204 } | 202 } |
205 | 203 |
206 } // namespace | 204 } // namespace |
207 | 205 |
208 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query, | 206 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query, |
209 std::string* family_out) { | 207 std::string* family_out) { |
210 FontRenderParamsQuery actual_query(query); | 208 FontRenderParamsQuery actual_query(query); |
211 #if defined(OS_CHROMEOS) | 209 #if defined(OS_CHROMEOS) |
212 if (actual_query.device_scale_factor == 0) | 210 if (actual_query.device_scale_factor == 0) |
Daniel Erat
2015/03/16 13:57:54
just move this test out of the #ifdefs:
if (actua
stapelberg
2015/03/17 08:36:34
Done.
| |
213 actual_query.device_scale_factor = device_scale_factor_for_internal_display; | 211 actual_query.device_scale_factor = device_scale_factor_for_internal_display; |
212 #else | |
213 // Linux does not support per-display DPI, so we use a slightly simpler code | |
214 // path than on ChromeOS to figure out the device scale factor. | |
Daniel Erat
2015/03/16 13:57:54
nit: s/ChromeOS/Chrome OS/
stapelberg
2015/03/17 08:36:33
Done.
| |
215 if (actual_query.device_scale_factor == 0) { | |
216 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | |
217 if (screen) { | |
Daniel Erat
2015/03/16 13:57:54
does gfx::Screen::GetNativeScreen() ever return nu
stapelberg
2015/03/17 08:36:34
Yes, it can. I’m getting the following segmentatio
oshima
2015/03/17 19:59:02
Doesn't this mean that this code inside block will
stapelberg
2015/03/18 08:17:53
No. When adding a LOG statement before line 218, I
oshima
2015/03/18 21:50:45
Oh, sorry, I was searching for different method na
| |
218 gfx::Display display = screen->GetPrimaryDisplay(); | |
219 actual_query.device_scale_factor = display.device_scale_factor(); | |
220 } | |
221 } | |
214 #endif | 222 #endif |
215 const uint32 hash = HashFontRenderParamsQuery(actual_query); | 223 const uint32 hash = HashFontRenderParamsQuery(actual_query); |
216 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); | 224 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); |
217 | 225 |
218 { | 226 { |
219 // Try to find a cached result so Fontconfig doesn't need to be queried. | 227 // Try to find a cached result so Fontconfig doesn't need to be queried. |
220 base::AutoLock lock(synchronized_cache->lock); | 228 base::AutoLock lock(synchronized_cache->lock); |
221 Cache::const_iterator it = synchronized_cache->cache.Get(hash); | 229 Cache::const_iterator it = synchronized_cache->cache.Get(hash); |
222 if (it != synchronized_cache->cache.end()) { | 230 if (it != synchronized_cache->cache.end()) { |
223 DVLOG(1) << "Returning cached params for " << hash; | 231 DVLOG(1) << "Returning cached params for " << hash; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 float GetFontRenderParamsDeviceScaleFactor() { | 292 float GetFontRenderParamsDeviceScaleFactor() { |
285 return device_scale_factor_for_internal_display; | 293 return device_scale_factor_for_internal_display; |
286 } | 294 } |
287 | 295 |
288 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) { | 296 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) { |
289 device_scale_factor_for_internal_display = device_scale_factor; | 297 device_scale_factor_for_internal_display = device_scale_factor; |
290 } | 298 } |
291 #endif | 299 #endif |
292 | 300 |
293 } // namespace gfx | 301 } // namespace gfx |
OLD | NEW |