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

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
(...skipping 11 matching lines...) Expand all
22 #include "ui/gfx/display.h" 22 #include "ui/gfx/display.h"
23 #include "ui/gfx/font.h" 23 #include "ui/gfx/font.h"
24 #include "ui/gfx/linux_font_delegate.h" 24 #include "ui/gfx/linux_font_delegate.h"
25 #include "ui/gfx/screen.h" 25 #include "ui/gfx/screen.h"
26 #include "ui/gfx/switches.h" 26 #include "ui/gfx/switches.h"
27 27
28 namespace gfx { 28 namespace gfx {
29 29
30 namespace { 30 namespace {
31 31
32 #if defined(OS_CHROMEOS) 32 // A device scale factor used to determine if subpixel positioning
33 // A device scale factor for an internal display (if any) 33 // should be used.
34 // that is used to determine if subpixel positioning should be used. 34 float device_scale_factor_ = 1.0f;
35 float device_scale_factor_for_internal_display = 1.0f;
36 #endif
37 35
38 // Number of recent GetFontRenderParams() results to cache. 36 // Number of recent GetFontRenderParams() results to cache.
39 const size_t kCacheSize = 256; 37 const size_t kCacheSize = 256;
40 38
41 // Cached result from a call to GetFontRenderParams(). 39 // Cached result from a call to GetFontRenderParams().
42 struct QueryResult { 40 struct QueryResult {
43 QueryResult(const FontRenderParams& params, const std::string& family) 41 QueryResult(const FontRenderParams& params, const std::string& family)
44 : params(params), 42 : params(params),
45 family(family) { 43 family(family) {
46 } 44 }
(...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, 195 "%d|%d|%d|%s|%f", query.pixel_size, query.point_size, query.style,
198 base::JoinString(query.families, ",").c_str(), 196 base::JoinString(query.families, ",").c_str(),
199 query.device_scale_factor)); 197 query.device_scale_factor));
200 } 198 }
201 199
202 } // namespace 200 } // namespace
203 201
204 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query, 202 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query,
205 std::string* family_out) { 203 std::string* family_out) {
206 FontRenderParamsQuery actual_query(query); 204 FontRenderParamsQuery actual_query(query);
207 if (actual_query.device_scale_factor == 0) { 205 if (actual_query.device_scale_factor == 0)
208 #if defined(OS_CHROMEOS) 206 actual_query.device_scale_factor = device_scale_factor_;
209 actual_query.device_scale_factor = device_scale_factor_for_internal_display; 207
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); 208 const uint32_t hash = HashFontRenderParamsQuery(actual_query);
221 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); 209 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer();
222 210
223 { 211 {
224 // Try to find a cached result so Fontconfig doesn't need to be queried. 212 // Try to find a cached result so Fontconfig doesn't need to be queried.
225 base::AutoLock lock(synchronized_cache->lock); 213 base::AutoLock lock(synchronized_cache->lock);
226 Cache::const_iterator it = synchronized_cache->cache.Get(hash); 214 Cache::const_iterator it = synchronized_cache->cache.Get(hash);
227 if (it != synchronized_cache->cache.end()) { 215 if (it != synchronized_cache->cache.end()) {
228 DVLOG(1) << "Returning cached params for " << hash; 216 DVLOG(1) << "Returning cached params for " << hash;
229 const QueryResult& result = it->second; 217 const QueryResult& result = it->second;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 260
273 return params; 261 return params;
274 } 262 }
275 263
276 void ClearFontRenderParamsCacheForTest() { 264 void ClearFontRenderParamsCacheForTest() {
277 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); 265 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer();
278 base::AutoLock lock(synchronized_cache->lock); 266 base::AutoLock lock(synchronized_cache->lock);
279 synchronized_cache->cache.Clear(); 267 synchronized_cache->cache.Clear();
280 } 268 }
281 269
282 #if defined(OS_CHROMEOS)
283 float GetFontRenderParamsDeviceScaleFactor() { 270 float GetFontRenderParamsDeviceScaleFactor() {
284 return device_scale_factor_for_internal_display; 271 return device_scale_factor_;
285 } 272 }
286 273
287 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) { 274 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) {
288 device_scale_factor_for_internal_display = device_scale_factor; 275 device_scale_factor_ = device_scale_factor;
289 } 276 }
290 #endif
291 277
292 } // namespace gfx 278 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698