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

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

Issue 789583002: Updates subpixel positioning and hinting when DSF is changed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GN Created 6 years 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
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 <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"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 struct SynchronizedCache { 54 struct SynchronizedCache {
55 SynchronizedCache() : cache(kCacheSize) {} 55 SynchronizedCache() : cache(kCacheSize) {}
56 56
57 base::Lock lock; 57 base::Lock lock;
58 Cache cache; 58 Cache cache;
59 }; 59 };
60 60
61 base::LazyInstance<SynchronizedCache>::Leaky g_synchronized_cache = 61 base::LazyInstance<SynchronizedCache>::Leaky g_synchronized_cache =
62 LAZY_INSTANCE_INITIALIZER; 62 LAZY_INSTANCE_INITIALIZER;
63 63
64 bool IsBrowserTextSubpixelPositioningEnabled() {
65 #if defined(OS_CHROMEOS)
66 return device_scale_factor_for_internal_display > 1.0f;
67 #else
68 return false;
69 #endif
70 }
71
72 // Converts Fontconfig FC_HINT_STYLE to FontRenderParams::Hinting. 64 // Converts Fontconfig FC_HINT_STYLE to FontRenderParams::Hinting.
73 FontRenderParams::Hinting ConvertFontconfigHintStyle(int hint_style) { 65 FontRenderParams::Hinting ConvertFontconfigHintStyle(int hint_style) {
74 switch (hint_style) { 66 switch (hint_style) {
75 case FC_HINT_SLIGHT: return FontRenderParams::HINTING_SLIGHT; 67 case FC_HINT_SLIGHT: return FontRenderParams::HINTING_SLIGHT;
76 case FC_HINT_MEDIUM: return FontRenderParams::HINTING_MEDIUM; 68 case FC_HINT_MEDIUM: return FontRenderParams::HINTING_MEDIUM;
77 case FC_HINT_FULL: return FontRenderParams::HINTING_FULL; 69 case FC_HINT_FULL: return FontRenderParams::HINTING_FULL;
78 default: return FontRenderParams::HINTING_NONE; 70 default: return FontRenderParams::HINTING_NONE;
79 } 71 }
80 } 72 }
81 73
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // Serialize |query| into a string and hash it to a value suitable for use as a 171 // Serialize |query| into a string and hash it to a value suitable for use as a
180 // cache key. 172 // cache key.
181 uint32 HashFontRenderParamsQuery(const FontRenderParamsQuery& query) { 173 uint32 HashFontRenderParamsQuery(const FontRenderParamsQuery& query) {
182 return base::Hash(base::StringPrintf("%d|%d|%d|%d|%s", 174 return base::Hash(base::StringPrintf("%d|%d|%d|%d|%s",
183 query.for_web_contents, query.pixel_size, query.point_size, query.style, 175 query.for_web_contents, query.pixel_size, query.point_size, query.style,
184 JoinString(query.families, ',').c_str())); 176 JoinString(query.families, ',').c_str()));
185 } 177 }
186 178
187 } // namespace 179 } // namespace
188 180
189 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query, 181 FontRenderParams GetSystemFontRenderParams(const FontRenderParamsQuery& query,
190 std::string* family_out) { 182 std::string* family_out) {
191 const uint32 hash = HashFontRenderParamsQuery(query); 183 const uint32 hash = HashFontRenderParamsQuery(query);
192 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); 184 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer();
193 185
194 { 186 {
195 // Try to find a cached result so Fontconfig doesn't need to be queried. 187 // Try to find a cached result so Fontconfig doesn't need to be queried.
196 base::AutoLock lock(synchronized_cache->lock); 188 base::AutoLock lock(synchronized_cache->lock);
197 Cache::const_iterator it = synchronized_cache->cache.Get(hash); 189 Cache::const_iterator it = synchronized_cache->cache.Get(hash);
198 if (it != synchronized_cache->cache.end()) { 190 if (it != synchronized_cache->cache.end()) {
199 DVLOG(1) << "Returning cached params for " << hash; 191 DVLOG(1) << "Returning cached params for " << hash;
200 const QueryResult& result = it->second; 192 const QueryResult& result = it->second;
(...skipping 12 matching lines...) Expand all
213 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); 205 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance();
214 if (delegate) 206 if (delegate)
215 params = delegate->GetDefaultFontRenderParams(); 207 params = delegate->GetDefaultFontRenderParams();
216 QueryFontconfig(query, &params, family_out); 208 QueryFontconfig(query, &params, family_out);
217 if (!params.antialiasing) { 209 if (!params.antialiasing) {
218 // Cairo forces full hinting when antialiasing is disabled, since anything 210 // Cairo forces full hinting when antialiasing is disabled, since anything
219 // less than that looks awful; do the same here. Requesting subpixel 211 // less than that looks awful; do the same here. Requesting subpixel
220 // rendering or positioning doesn't make sense either. 212 // rendering or positioning doesn't make sense either.
221 params.hinting = FontRenderParams::HINTING_FULL; 213 params.hinting = FontRenderParams::HINTING_FULL;
222 params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE; 214 params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE;
223 params.subpixel_positioning = false;
224 } else {
225 // Fontconfig doesn't support configuring subpixel positioning; check a
226 // flag.
227 params.subpixel_positioning =
228 query.for_web_contents ?
229 CommandLine::ForCurrentProcess()->HasSwitch(
230 switches::kEnableWebkitTextSubpixelPositioning) :
231 IsBrowserTextSubpixelPositioningEnabled();
232
233 // To enable subpixel positioning, we need to disable hinting.
234 if (params.subpixel_positioning)
235 params.hinting = FontRenderParams::HINTING_NONE;
236 } 215 }
216 params.subpixel_positioning = false;
237 217
238 // Use the first family from the list if Fontconfig didn't suggest a family. 218 // Use the first family from the list if Fontconfig didn't suggest a family.
239 if (family_out && family_out->empty() && !query.families.empty()) 219 if (family_out && family_out->empty() && !query.families.empty())
240 *family_out = query.families[0]; 220 *family_out = query.families[0];
241 221
242 { 222 {
243 // Store the result. It's fine if this overwrites a result that was cached 223 // Store the result. It's fine if this overwrites a result that was cached
244 // by a different thread in the meantime; the values should be identical. 224 // by a different thread in the meantime; the values should be identical.
245 base::AutoLock lock(synchronized_cache->lock); 225 base::AutoLock lock(synchronized_cache->lock);
246 synchronized_cache->cache.Put(hash, 226 synchronized_cache->cache.Put(hash,
247 QueryResult(params, family_out ? *family_out : std::string())); 227 QueryResult(params, family_out ? *family_out : std::string()));
248 } 228 }
249 229
250 return params; 230 return params;
251 } 231 }
252 232
253 void ClearFontRenderParamsCacheForTest() { 233 void ClearFontRenderParamsCacheForTest() {
254 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); 234 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer();
255 base::AutoLock lock(synchronized_cache->lock); 235 base::AutoLock lock(synchronized_cache->lock);
256 synchronized_cache->cache.Clear(); 236 synchronized_cache->cache.Clear();
257 } 237 }
258 238
259 #if defined(OS_CHROMEOS) 239 #if defined(OS_CHROMEOS)
260 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) { 240 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) {
261 device_scale_factor_for_internal_display = device_scale_factor; 241 device_scale_factor_for_internal_display = device_scale_factor;
262 } 242 }
263 #endif 243 #endif
264 244
265 } // namespace gfx 245 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698