Performance histograms for extension content verification
[chromium-blink-merge.git] / ui / gfx / font_render_params_linux.cc
blobfdef6a9926ff8b35dd5b6551f57d1595cba369db
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
3 // found in the LICENSE file.
5 #include "ui/gfx/font_render_params_linux.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "ui/gfx/display.h"
10 #include "ui/gfx/switches.h"
12 #include <fontconfig/fontconfig.h>
14 #if defined(OS_LINUX) && defined(USE_AURA) && !defined(OS_CHROMEOS)
15 #include "ui/gfx/linux_font_delegate.h"
16 #endif
18 namespace gfx {
20 namespace {
22 bool SubpixelPositioningRequested(bool renderer) {
23 const CommandLine* cl = CommandLine::ForCurrentProcess();
24 if (renderer) {
25 // Text rendered by Blink in high-DPI mode is poorly-hinted unless subpixel
26 // positioning is used (as opposed to each glyph being individually snapped
27 // to the pixel grid).
28 return cl->HasSwitch(switches::kEnableWebkitTextSubpixelPositioning) ||
29 (Display::HasForceDeviceScaleFactor() &&
30 Display::GetForcedDeviceScaleFactor() != 1.0);
32 return cl->HasSwitch(switches::kEnableBrowserTextSubpixelPositioning);
35 // Initializes |params| with the system's default settings. |renderer| is true
36 // when setting WebKit renderer defaults.
37 void LoadDefaults(FontRenderParams* params, bool renderer) {
38 // For non-GTK builds (read: Aura), just use reasonable hardcoded values.
39 params->antialiasing = true;
40 params->autohinter = true;
41 params->use_bitmaps = true;
42 params->hinting = FontRenderParams::HINTING_SLIGHT;
44 // Fetch default subpixel rendering settings from FontConfig.
45 FcPattern* pattern = FcPatternCreate();
46 FcConfigSubstitute(NULL, pattern, FcMatchPattern);
47 FcDefaultSubstitute(pattern);
48 FcResult result;
49 FcPattern* match = FcFontMatch(0, pattern, &result);
50 DCHECK(match);
51 int fc_rgba = FC_RGBA_RGB;
52 FcPatternGetInteger(match, FC_RGBA, 0, &fc_rgba);
53 FcPatternDestroy(pattern);
54 FcPatternDestroy(match);
56 switch (fc_rgba) {
57 case FC_RGBA_RGB:
58 params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB;
59 break;
60 case FC_RGBA_BGR:
61 params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_BGR;
62 break;
63 case FC_RGBA_VRGB:
64 params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_VRGB;
65 break;
66 case FC_RGBA_VBGR:
67 params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_VBGR;
68 break;
69 default:
70 params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE;
73 #if defined(OS_LINUX) && defined(USE_AURA) && !defined(OS_CHROMEOS)
74 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance();
75 if (delegate) {
76 params->antialiasing = delegate->UseAntialiasing();
77 params->hinting = delegate->GetHintingStyle();
78 params->subpixel_rendering = delegate->GetSubpixelRenderingStyle();
80 #endif
82 params->subpixel_positioning = SubpixelPositioningRequested(renderer);
84 // To enable subpixel positioning, we need to disable hinting.
85 if (params->subpixel_positioning)
86 params->hinting = FontRenderParams::HINTING_NONE;
89 } // namespace
91 const FontRenderParams& GetDefaultFontRenderParams() {
92 static bool loaded_defaults = false;
93 static FontRenderParams default_params;
94 if (!loaded_defaults)
95 LoadDefaults(&default_params, /* renderer */ false);
96 loaded_defaults = true;
97 return default_params;
100 const FontRenderParams& GetDefaultWebKitFontRenderParams() {
101 static bool loaded_defaults = false;
102 static FontRenderParams default_params;
103 if (!loaded_defaults)
104 LoadDefaults(&default_params, /* renderer */ true);
105 loaded_defaults = true;
106 return default_params;
109 bool GetDefaultWebkitSubpixelPositioning() {
110 return SubpixelPositioningRequested(true);
113 } // namespace gfx