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

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

Issue 1870873003: Remove screen dependency from font_render_params_linux (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/containers/mru_cache.h" 12 #include "base/containers/mru_cache.h"
13 #include "base/hash.h" 13 #include "base/hash.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
20 #include "base/synchronization/lock.h" 20 #include "base/synchronization/lock.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "ui/gfx/display.h"
23 #include "ui/gfx/font.h" 22 #include "ui/gfx/font.h"
24 #include "ui/gfx/linux_font_delegate.h" 23 #include "ui/gfx/linux_font_delegate.h"
25 #include "ui/gfx/screen.h"
26 #include "ui/gfx/switches.h" 24 #include "ui/gfx/switches.h"
27 25
28 namespace gfx { 26 namespace gfx {
29 27
30 namespace { 28 namespace {
31 29
32 #if defined(OS_CHROMEOS) 30 // A device scale factor used to determine if subpixel positioning
33 // A device scale factor for an internal display (if any) 31 // should be used.
34 // that is used to determine if subpixel positioning should be used. 32 float device_scale_factor_ = 1.0f;
35 float device_scale_factor_for_internal_display = 1.0f;
36 #endif
37 33
38 // Number of recent GetFontRenderParams() results to cache. 34 // Number of recent GetFontRenderParams() results to cache.
39 const size_t kCacheSize = 256; 35 const size_t kCacheSize = 256;
40 36
41 // Cached result from a call to GetFontRenderParams(). 37 // Cached result from a call to GetFontRenderParams().
42 struct QueryResult { 38 struct QueryResult {
43 QueryResult(const FontRenderParams& params, const std::string& family) 39 QueryResult(const FontRenderParams& params, const std::string& family)
44 : params(params), 40 : params(params),
45 family(family) { 41 family(family) {
46 } 42 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 "%d|%d|%d|%s|%f", query.pixel_size, query.point_size, query.style, 193 "%d|%d|%d|%s|%f", query.pixel_size, query.point_size, query.style,
198 base::JoinString(query.families, ",").c_str(), 194 base::JoinString(query.families, ",").c_str(),
199 query.device_scale_factor)); 195 query.device_scale_factor));
200 } 196 }
201 197
202 } // namespace 198 } // namespace
203 199
204 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query, 200 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query,
205 std::string* family_out) { 201 std::string* family_out) {
206 FontRenderParamsQuery actual_query(query); 202 FontRenderParamsQuery actual_query(query);
207 if (actual_query.device_scale_factor == 0) { 203 if (actual_query.device_scale_factor == 0)
208 #if defined(OS_CHROMEOS) 204 actual_query.device_scale_factor = device_scale_factor_;
209 actual_query.device_scale_factor = device_scale_factor_for_internal_display; 205
210 #else
211 // Linux does not support per-display DPI, so we use a slightly simpler
212 // code path than on Chrome OS to figure out the device scale factor.
213 gfx::Screen* screen = gfx::Screen::GetScreen();
214 if (screen) {
215 gfx::Display display = screen->GetPrimaryDisplay();
216 actual_query.device_scale_factor = display.device_scale_factor();
217 }
218 #endif
219 }
220 const uint32_t hash = HashFontRenderParamsQuery(actual_query); 206 const uint32_t hash = HashFontRenderParamsQuery(actual_query);
221 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); 207 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer();
222 208
223 { 209 {
224 // Try to find a cached result so Fontconfig doesn't need to be queried. 210 // Try to find a cached result so Fontconfig doesn't need to be queried.
225 base::AutoLock lock(synchronized_cache->lock); 211 base::AutoLock lock(synchronized_cache->lock);
226 Cache::const_iterator it = synchronized_cache->cache.Get(hash); 212 Cache::const_iterator it = synchronized_cache->cache.Get(hash);
227 if (it != synchronized_cache->cache.end()) { 213 if (it != synchronized_cache->cache.end()) {
228 DVLOG(1) << "Returning cached params for " << hash; 214 DVLOG(1) << "Returning cached params for " << hash;
229 const QueryResult& result = it->second; 215 const QueryResult& result = it->second;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 258
273 return params; 259 return params;
274 } 260 }
275 261
276 void ClearFontRenderParamsCacheForTest() { 262 void ClearFontRenderParamsCacheForTest() {
277 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); 263 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer();
278 base::AutoLock lock(synchronized_cache->lock); 264 base::AutoLock lock(synchronized_cache->lock);
279 synchronized_cache->cache.Clear(); 265 synchronized_cache->cache.Clear();
280 } 266 }
281 267
282 #if defined(OS_CHROMEOS)
283 float GetFontRenderParamsDeviceScaleFactor() { 268 float GetFontRenderParamsDeviceScaleFactor() {
284 return device_scale_factor_for_internal_display; 269 return device_scale_factor_;
285 } 270 }
286 271
287 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) { 272 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) {
288 device_scale_factor_for_internal_display = device_scale_factor; 273 device_scale_factor_ = device_scale_factor;
289 } 274 }
290 #endif
291 275
292 } // namespace gfx 276 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698