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

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

Issue 1543183002: Switch to standard integer types in ui/gfx/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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
« no previous file with comments | « ui/gfx/font_list_unittest.cc ('k') | ui/gfx/font_render_params_linux_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
9 #include <stdint.h>
8 10
9 #include "base/command_line.h" 11 #include "base/command_line.h"
10 #include "base/containers/mru_cache.h" 12 #include "base/containers/mru_cache.h"
11 #include "base/hash.h" 13 #include "base/hash.h"
12 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
13 #include "base/logging.h" 15 #include "base/logging.h"
14 #include "base/macros.h" 16 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
16 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
18 #include "base/synchronization/lock.h" 20 #include "base/synchronization/lock.h"
21 #include "build/build_config.h"
19 #include "ui/gfx/display.h" 22 #include "ui/gfx/display.h"
20 #include "ui/gfx/font.h" 23 #include "ui/gfx/font.h"
21 #include "ui/gfx/linux_font_delegate.h" 24 #include "ui/gfx/linux_font_delegate.h"
22 #include "ui/gfx/screen.h" 25 #include "ui/gfx/screen.h"
23 #include "ui/gfx/switches.h" 26 #include "ui/gfx/switches.h"
24 27
25 namespace gfx { 28 namespace gfx {
26 29
27 namespace { 30 namespace {
28 31
(...skipping 13 matching lines...) Expand all
42 family(family) { 45 family(family) {
43 } 46 }
44 ~QueryResult() {} 47 ~QueryResult() {}
45 48
46 FontRenderParams params; 49 FontRenderParams params;
47 std::string family; 50 std::string family;
48 }; 51 };
49 52
50 // Keyed by hashes of FontRenderParamQuery structs from 53 // Keyed by hashes of FontRenderParamQuery structs from
51 // HashFontRenderParamsQuery(). 54 // HashFontRenderParamsQuery().
52 typedef base::MRUCache<uint32, QueryResult> Cache; 55 typedef base::MRUCache<uint32_t, QueryResult> Cache;
53 56
54 // A cache and the lock that must be held while accessing it. 57 // A cache and the lock that must be held while accessing it.
55 // GetFontRenderParams() is called by both the UI thread and the sandbox IPC 58 // GetFontRenderParams() is called by both the UI thread and the sandbox IPC
56 // thread. 59 // thread.
57 struct SynchronizedCache { 60 struct SynchronizedCache {
58 SynchronizedCache() : cache(kCacheSize) {} 61 SynchronizedCache() : cache(kCacheSize) {}
59 62
60 base::Lock lock; 63 base::Lock lock;
61 Cache cache; 64 Cache cache;
62 }; 65 };
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 if (FcPatternGetInteger(result_pattern.get(), FC_RGBA, 0, &fc_rgba) == 185 if (FcPatternGetInteger(result_pattern.get(), FC_RGBA, 0, &fc_rgba) ==
183 FcResultMatch) 186 FcResultMatch)
184 params_out->subpixel_rendering = ConvertFontconfigRgba(fc_rgba); 187 params_out->subpixel_rendering = ConvertFontconfigRgba(fc_rgba);
185 } 188 }
186 189
187 return true; 190 return true;
188 } 191 }
189 192
190 // Serialize |query| into a string and hash it to a value suitable for use as a 193 // Serialize |query| into a string and hash it to a value suitable for use as a
191 // cache key. 194 // cache key.
192 uint32 HashFontRenderParamsQuery(const FontRenderParamsQuery& query) { 195 uint32_t HashFontRenderParamsQuery(const FontRenderParamsQuery& query) {
193 return base::Hash(base::StringPrintf( 196 return base::Hash(base::StringPrintf(
194 "%d|%d|%d|%s|%f", query.pixel_size, query.point_size, query.style, 197 "%d|%d|%d|%s|%f", query.pixel_size, query.point_size, query.style,
195 base::JoinString(query.families, ",").c_str(), 198 base::JoinString(query.families, ",").c_str(),
196 query.device_scale_factor)); 199 query.device_scale_factor));
197 } 200 }
198 201
199 } // namespace 202 } // namespace
200 203
201 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query, 204 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query,
202 std::string* family_out) { 205 std::string* family_out) {
203 FontRenderParamsQuery actual_query(query); 206 FontRenderParamsQuery actual_query(query);
204 if (actual_query.device_scale_factor == 0) { 207 if (actual_query.device_scale_factor == 0) {
205 #if defined(OS_CHROMEOS) 208 #if defined(OS_CHROMEOS)
206 actual_query.device_scale_factor = device_scale_factor_for_internal_display; 209 actual_query.device_scale_factor = device_scale_factor_for_internal_display;
207 #else 210 #else
208 // Linux does not support per-display DPI, so we use a slightly simpler 211 // Linux does not support per-display DPI, so we use a slightly simpler
209 // code path than on Chrome OS to figure out the device scale factor. 212 // code path than on Chrome OS to figure out the device scale factor.
210 gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); 213 gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE);
211 if (screen) { 214 if (screen) {
212 gfx::Display display = screen->GetPrimaryDisplay(); 215 gfx::Display display = screen->GetPrimaryDisplay();
213 actual_query.device_scale_factor = display.device_scale_factor(); 216 actual_query.device_scale_factor = display.device_scale_factor();
214 } 217 }
215 #endif 218 #endif
216 } 219 }
217 const uint32 hash = HashFontRenderParamsQuery(actual_query); 220 const uint32_t hash = HashFontRenderParamsQuery(actual_query);
218 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer(); 221 SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer();
219 222
220 { 223 {
221 // Try to find a cached result so Fontconfig doesn't need to be queried. 224 // Try to find a cached result so Fontconfig doesn't need to be queried.
222 base::AutoLock lock(synchronized_cache->lock); 225 base::AutoLock lock(synchronized_cache->lock);
223 Cache::const_iterator it = synchronized_cache->cache.Get(hash); 226 Cache::const_iterator it = synchronized_cache->cache.Get(hash);
224 if (it != synchronized_cache->cache.end()) { 227 if (it != synchronized_cache->cache.end()) {
225 DVLOG(1) << "Returning cached params for " << hash; 228 DVLOG(1) << "Returning cached params for " << hash;
226 const QueryResult& result = it->second; 229 const QueryResult& result = it->second;
227 if (family_out) 230 if (family_out)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 float GetFontRenderParamsDeviceScaleFactor() { 283 float GetFontRenderParamsDeviceScaleFactor() {
281 return device_scale_factor_for_internal_display; 284 return device_scale_factor_for_internal_display;
282 } 285 }
283 286
284 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) { 287 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) {
285 device_scale_factor_for_internal_display = device_scale_factor; 288 device_scale_factor_for_internal_display = device_scale_factor;
286 } 289 }
287 #endif 290 #endif
288 291
289 } // namespace gfx 292 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/font_list_unittest.cc ('k') | ui/gfx/font_render_params_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698