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

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

Powered by Google App Engine
This is Rietveld 408576698