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 24 matching lines...) Expand all Loading... | |
55 struct SynchronizedCache { | 57 struct SynchronizedCache { |
56 SynchronizedCache() : cache(kCacheSize) {} | 58 SynchronizedCache() : cache(kCacheSize) {} |
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( |
msw
2015/03/19 19:30:43
nit: maybe inline this now?
stapelberg
2015/03/19 19:39:25
Done.
| |
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; |
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 "%d|%d|%d|%d|%s|%f", query.for_web_contents, query.pixel_size, | 199 "%d|%d|%d|%d|%s|%f", query.for_web_contents, query.pixel_size, |
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); |
209 if (actual_query.device_scale_factor == 0) { | |
211 #if defined(OS_CHROMEOS) | 210 #if defined(OS_CHROMEOS) |
212 if (actual_query.device_scale_factor == 0) | |
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 | |
214 // code path than on Chrome OS to figure out the device scale factor. | |
215 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | |
216 if (screen) { | |
217 gfx::Display display = screen->GetPrimaryDisplay(); | |
218 actual_query.device_scale_factor = display.device_scale_factor(); | |
219 } | |
214 #endif | 220 #endif |
221 } | |
215 const uint32 hash = HashFontRenderParamsQuery(actual_query); | 222 const uint32 hash = HashFontRenderParamsQuery(actual_query); |
216 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); | 223 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); |
217 | 224 |
218 { | 225 { |
219 // Try to find a cached result so Fontconfig doesn't need to be queried. | 226 // Try to find a cached result so Fontconfig doesn't need to be queried. |
220 base::AutoLock lock(synchronized_cache->lock); | 227 base::AutoLock lock(synchronized_cache->lock); |
221 Cache::const_iterator it = synchronized_cache->cache.Get(hash); | 228 Cache::const_iterator it = synchronized_cache->cache.Get(hash); |
222 if (it != synchronized_cache->cache.end()) { | 229 if (it != synchronized_cache->cache.end()) { |
223 DVLOG(1) << "Returning cached params for " << hash; | 230 DVLOG(1) << "Returning cached params for " << hash; |
224 const QueryResult& result = it->second; | 231 const QueryResult& result = it->second; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 float GetFontRenderParamsDeviceScaleFactor() { | 291 float GetFontRenderParamsDeviceScaleFactor() { |
285 return device_scale_factor_for_internal_display; | 292 return device_scale_factor_for_internal_display; |
286 } | 293 } |
287 | 294 |
288 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) { | 295 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) { |
289 device_scale_factor_for_internal_display = device_scale_factor; | 296 device_scale_factor_for_internal_display = device_scale_factor; |
290 } | 297 } |
291 #endif | 298 #endif |
292 | 299 |
293 } // namespace gfx | 300 } // namespace gfx |
OLD | NEW |