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

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 float device_scale_factor_for_internal_display = 1.0f;
Alexei Svitkine (slow) 2014/08/21 15:36:38 Nit: add g_ prefix
30 #endif
31
26 // Keyed by hashes of FontRenderParamQuery structs from 32 // Keyed by hashes of FontRenderParamQuery structs from
27 // HashFontRenderParamsQuery(). 33 // HashFontRenderParamsQuery().
28 typedef base::MRUCache<uint32, FontRenderParams> Cache; 34 typedef base::MRUCache<uint32, FontRenderParams> Cache;
29 35
30 // Number of recent GetFontRenderParams() results to cache. 36 // Number of recent GetFontRenderParams() results to cache.
31 const size_t kCacheSize = 20; 37 const size_t kCacheSize = 20;
32 38
33 // A cache and the lock that must be held while accessing it. 39 // 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 40 // GetFontRenderParams() is called by both the UI thread and the sandbox IPC
35 // thread. 41 // thread.
36 struct SynchronizedCache { 42 struct SynchronizedCache {
37 SynchronizedCache() : cache(kCacheSize) {} 43 SynchronizedCache() : cache(kCacheSize) {}
38 44
39 base::Lock lock; 45 base::Lock lock;
40 Cache cache; 46 Cache cache;
41 }; 47 };
42 48
43 base::LazyInstance<SynchronizedCache>::Leaky g_synchronized_cache = 49 base::LazyInstance<SynchronizedCache>::Leaky g_synchronized_cache =
44 LAZY_INSTANCE_INITIALIZER; 50 LAZY_INSTANCE_INITIALIZER;
45 51
52 bool IsBrowserTextSubpixelPositioningEnabled() {
53 #if defined(OS_CHROMEOS)
54 return device_scale_factor_for_internal_display > 1.0f;
55 #else
56 return false;
57 #endif
58 }
59
46 // Converts Fontconfig FC_HINT_STYLE to FontRenderParams::Hinting. 60 // Converts Fontconfig FC_HINT_STYLE to FontRenderParams::Hinting.
47 FontRenderParams::Hinting ConvertFontconfigHintStyle(int hint_style) { 61 FontRenderParams::Hinting ConvertFontconfigHintStyle(int hint_style) {
48 switch (hint_style) { 62 switch (hint_style) {
49 case FC_HINT_SLIGHT: return FontRenderParams::HINTING_SLIGHT; 63 case FC_HINT_SLIGHT: return FontRenderParams::HINTING_SLIGHT;
50 case FC_HINT_MEDIUM: return FontRenderParams::HINTING_MEDIUM; 64 case FC_HINT_MEDIUM: return FontRenderParams::HINTING_MEDIUM;
51 case FC_HINT_FULL: return FontRenderParams::HINTING_FULL; 65 case FC_HINT_FULL: return FontRenderParams::HINTING_FULL;
52 default: return FontRenderParams::HINTING_NONE; 66 default: return FontRenderParams::HINTING_NONE;
53 } 67 }
54 } 68 }
55 69
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 183 }
170 DVLOG(1) << "Computing params for " << hash 184 DVLOG(1) << "Computing params for " << hash
171 << (family_out ? " (family requested)" : ""); 185 << (family_out ? " (family requested)" : "");
172 186
173 // Start with the delegate's settings, but let Fontconfig have the final say. 187 // Start with the delegate's settings, but let Fontconfig have the final say.
174 FontRenderParams params; 188 FontRenderParams params;
175 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); 189 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance();
176 if (delegate) 190 if (delegate)
177 params = delegate->GetDefaultFontRenderParams(); 191 params = delegate->GetDefaultFontRenderParams();
178 QueryFontconfig(query, &params, family_out); 192 QueryFontconfig(query, &params, family_out);
179
180 if (!params.antialiasing) { 193 if (!params.antialiasing) {
181 // Cairo forces full hinting when antialiasing is disabled, since anything 194 // Cairo forces full hinting when antialiasing is disabled, since anything
182 // less than that looks awful; do the same here. Requesting subpixel 195 // less than that looks awful; do the same here. Requesting subpixel
183 // rendering or positioning doesn't make sense either. 196 // rendering or positioning doesn't make sense either.
184 params.hinting = FontRenderParams::HINTING_FULL; 197 params.hinting = FontRenderParams::HINTING_FULL;
185 params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE; 198 params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE;
186 params.subpixel_positioning = false; 199 params.subpixel_positioning = false;
187 } else { 200 } else {
188 // Fontconfig doesn't support configuring subpixel positioning; check a 201 // Fontconfig doesn't support configuring subpixel positioning; check a
189 // flag. 202 // flag.
190 params.subpixel_positioning = CommandLine::ForCurrentProcess()->HasSwitch( 203 params.subpixel_positioning =
191 query.for_web_contents ? 204 query.for_web_contents ?
192 switches::kEnableWebkitTextSubpixelPositioning : 205 CommandLine::ForCurrentProcess()->HasSwitch(
193 switches::kEnableBrowserTextSubpixelPositioning); 206 switches::kEnableWebkitTextSubpixelPositioning) :
207 IsBrowserTextSubpixelPositioningEnabled();
194 208
195 // To enable subpixel positioning, we need to disable hinting. 209 // To enable subpixel positioning, we need to disable hinting.
196 if (params.subpixel_positioning) 210 if (params.subpixel_positioning)
197 params.hinting = FontRenderParams::HINTING_NONE; 211 params.hinting = FontRenderParams::HINTING_NONE;
198 } 212 }
199 213
200 // Use the first family from the list if Fontconfig didn't suggest a family. 214 // Use the first family from the list if Fontconfig didn't suggest a family.
201 if (family_out && family_out->empty() && !query.families.empty()) 215 if (family_out && family_out->empty() && !query.families.empty())
202 *family_out = query.families[0]; 216 *family_out = query.families[0];
203 217
204 // Store the computed struct. It's fine if this overwrites a struct that was 218 // 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 219 // cached by a different thread in the meantime; the values should be
206 // identical. 220 // identical.
207 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); 221 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer();
208 base::AutoLock lock(synchronized_cache->lock); 222 base::AutoLock lock(synchronized_cache->lock);
209 synchronized_cache->cache.Put(hash, params); 223 synchronized_cache->cache.Put(hash, params);
210 224
211 return params; 225 return params;
212 } 226 }
213 227
214 void ClearFontRenderParamsCacheForTest() { 228 void ClearFontRenderParamsCacheForTest() {
215 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); 229 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer();
216 base::AutoLock lock(synchronized_cache->lock); 230 base::AutoLock lock(synchronized_cache->lock);
217 synchronized_cache->cache.Clear(); 231 synchronized_cache->cache.Clear();
218 } 232 }
219 233
234 #if defined(OS_CHROMEOS)
235 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) {
236 device_scale_factor_for_internal_display = device_scale_factor;
237 }
238 #endif
239
220 } // namespace gfx 240 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698