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

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

Issue 485873002: Enable subpixel positioning for internal display with dsf larger than 1.0 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/containers/mru_cache.h" 8 #include "base/containers/mru_cache.h"
9 #include "base/hash.h" 9 #include "base/hash.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "ui/gfx/font.h" 16 #include "ui/gfx/font.h"
17 #include "ui/gfx/linux_font_delegate.h" 17 #include "ui/gfx/linux_font_delegate.h"
18 #include "ui/gfx/switches.h" 18 #include "ui/gfx/switches.h"
19 19
20 #include <fontconfig/fontconfig.h> 20 #include <fontconfig/fontconfig.h>
21 21
22 namespace gfx { 22 namespace gfx {
23 23
24 namespace { 24 namespace {
25 25
26 #if defined(OS_CHROMEOS)
27 // A device scale factor for an internal display (if any)
28 // that is used to determine if subpixel positioning should be used
29 // instead of hinting.
30 float device_scale_factor_for_internal_display = 1.0f;
31
32 // Minimum device scale factor to enable text subpixel positioining
33 // for internal display.
34 const float kMinDsfToEnableSubpixelPositioning = 1.2f;
Daniel Erat 2014/08/19 22:32:25 forget if i sent my previous comment asking this:
oshima 2014/08/20 01:41:12 Done. I just removed const and use 1.0f as it's mo
35 #endif
36
26 // Keyed by hashes of FontRenderParamQuery structs from 37 // Keyed by hashes of FontRenderParamQuery structs from
27 // HashFontRenderParamsQuery(). 38 // HashFontRenderParamsQuery().
28 typedef base::MRUCache<uint32, FontRenderParams> Cache; 39 typedef base::MRUCache<uint32, FontRenderParams> Cache;
29 40
30 // Number of recent GetFontRenderParams() results to cache. 41 // Number of recent GetFontRenderParams() results to cache.
31 const size_t kCacheSize = 20; 42 const size_t kCacheSize = 20;
32 43
33 // A cache and the lock that must be held while accessing it. 44 // A cache and the lock that must be held while accessing it.
34 // GetFontRenderParams() is called by both the UI thread and the sandbox IPC 45 // GetFontRenderParams() is called by both the UI thread and the sandbox IPC
35 // thread. 46 // thread.
36 struct SynchronizedCache { 47 struct SynchronizedCache {
37 SynchronizedCache() : cache(kCacheSize) {} 48 SynchronizedCache() : cache(kCacheSize) {}
38 49
39 base::Lock lock; 50 base::Lock lock;
40 Cache cache; 51 Cache cache;
41 }; 52 };
42 53
43 base::LazyInstance<SynchronizedCache>::Leaky g_synchronized_cache = 54 base::LazyInstance<SynchronizedCache>::Leaky g_synchronized_cache =
44 LAZY_INSTANCE_INITIALIZER; 55 LAZY_INSTANCE_INITIALIZER;
45 56
57 bool IsBrowserTextSubpixelPositioningEnabled() {
58 #if defined(OS_CHROMEOS)
59 return device_scale_factor_for_internal_display >=
60 kMinDsfToEnableSubpixelPositioning;
61 #else
62 return false;
63 #endif
64 }
65
46 // Converts Fontconfig FC_HINT_STYLE to FontRenderParams::Hinting. 66 // Converts Fontconfig FC_HINT_STYLE to FontRenderParams::Hinting.
47 FontRenderParams::Hinting ConvertFontconfigHintStyle(int hint_style) { 67 FontRenderParams::Hinting ConvertFontconfigHintStyle(int hint_style) {
48 switch (hint_style) { 68 switch (hint_style) {
49 case FC_HINT_SLIGHT: return FontRenderParams::HINTING_SLIGHT; 69 case FC_HINT_SLIGHT: return FontRenderParams::HINTING_SLIGHT;
50 case FC_HINT_MEDIUM: return FontRenderParams::HINTING_MEDIUM; 70 case FC_HINT_MEDIUM: return FontRenderParams::HINTING_MEDIUM;
51 case FC_HINT_FULL: return FontRenderParams::HINTING_FULL; 71 case FC_HINT_FULL: return FontRenderParams::HINTING_FULL;
52 default: return FontRenderParams::HINTING_NONE; 72 default: return FontRenderParams::HINTING_NONE;
53 } 73 }
54 } 74 }
55 75
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 if (!params.antialiasing) { 200 if (!params.antialiasing) {
181 // Cairo forces full hinting when antialiasing is disabled, since anything 201 // Cairo forces full hinting when antialiasing is disabled, since anything
182 // less than that looks awful; do the same here. Requesting subpixel 202 // less than that looks awful; do the same here. Requesting subpixel
183 // rendering or positioning doesn't make sense either. 203 // rendering or positioning doesn't make sense either.
184 params.hinting = FontRenderParams::HINTING_FULL; 204 params.hinting = FontRenderParams::HINTING_FULL;
185 params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE; 205 params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE;
186 params.subpixel_positioning = false; 206 params.subpixel_positioning = false;
187 } else { 207 } else {
188 // Fontconfig doesn't support configuring subpixel positioning; check a 208 // Fontconfig doesn't support configuring subpixel positioning; check a
189 // flag. 209 // flag.
190 params.subpixel_positioning = CommandLine::ForCurrentProcess()->HasSwitch( 210 params.subpixel_positioning =
191 query.for_web_contents ? 211 query.for_web_contents ?
192 switches::kEnableWebkitTextSubpixelPositioning : 212 CommandLine::ForCurrentProcess()->HasSwitch(
193 switches::kEnableBrowserTextSubpixelPositioning); 213 switches::kEnableWebkitTextSubpixelPositioning) :
214 IsBrowserTextSubpixelPositioningEnabled();
194 215
195 // To enable subpixel positioning, we need to disable hinting. 216 // To enable subpixel positioning, we need to disable hinting.
196 if (params.subpixel_positioning) 217 if (params.subpixel_positioning)
197 params.hinting = FontRenderParams::HINTING_NONE; 218 params.hinting = FontRenderParams::HINTING_NONE;
198 } 219 }
199 220
200 // Use the first family from the list if Fontconfig didn't suggest a family. 221 // Use the first family from the list if Fontconfig didn't suggest a family.
201 if (family_out && family_out->empty() && !query.families.empty()) 222 if (family_out && family_out->empty() && !query.families.empty())
202 *family_out = query.families[0]; 223 *family_out = query.families[0];
203 224
204 // Store the computed struct. It's fine if this overwrites a struct that was 225 // Store the computed struct. It's fine if this overwrites a struct that was
205 // cached by a different thread in the meantime; the values should be 226 // cached by a different thread in the meantime; the values should be
206 // identical. 227 // identical.
207 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); 228 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer();
208 base::AutoLock lock(synchronized_cache->lock); 229 base::AutoLock lock(synchronized_cache->lock);
209 synchronized_cache->cache.Put(hash, params); 230 synchronized_cache->cache.Put(hash, params);
210 231
211 return params; 232 return params;
212 } 233 }
213 234
214 void ClearFontRenderParamsCacheForTest() { 235 void ClearFontRenderParamsCacheForTest() {
215 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); 236 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer();
216 base::AutoLock lock(synchronized_cache->lock); 237 base::AutoLock lock(synchronized_cache->lock);
217 synchronized_cache->cache.Clear(); 238 synchronized_cache->cache.Clear();
218 } 239 }
219 240
241 #if defined(OS_CHROMEOS)
242 void SetDeviceScaleFactorForInternalDisplay(float device_scale_factor) {
243 device_scale_factor_for_internal_display = device_scale_factor;
244 }
245
246 namespace test {
247
248 bool GetBrowserTextSubpixelPoisitioningEnabled() {
249 return IsBrowserTextSubpixelPositioningEnabled();
250 }
251
252 } // namespace test
253
254 #endif
255
220 } // namespace gfx 256 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698