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

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

Issue 7833016: aura: A few changes to have aura_demo compile and run on linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/linux_util.h ('k') | ui/gfx/platform_font_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #include "ui/gfx/linux_util.h"
6
7 #include <pango/pango.h>
8 #include <pango/pangocairo.h>
9 #include <stdlib.h>
10
11 #include "base/basictypes.h"
12 #include "base/command_line.h"
13 #include "base/linux_util.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "third_party/skia/include/core/SkUnPreMultiply.h"
16 #include "ui/gfx/rect.h"
17
18 namespace {
19
20 // Common implementation of ConvertAcceleratorsFromWindowsStyle() and
21 // RemoveWindowsStyleAccelerators().
22 // Replaces all ampersands (as used in our grd files to indicate mnemonics)
23 // to |target|. Similarly any underscores get replaced with two underscores as
24 // is needed by GTK.
25 std::string ConvertAmperstandsTo(const std::string& label,
26 const std::string& target) {
27 std::string ret;
28 ret.reserve(label.length() * 2);
29 for (size_t i = 0; i < label.length(); ++i) {
30 if ('_' == label[i]) {
31 ret.push_back('_');
32 ret.push_back('_');
33 } else if ('&' == label[i]) {
34 if (i + 1 < label.length() && '&' == label[i + 1]) {
35 ret.push_back('&');
36 ++i;
37 } else {
38 ret.append(target);
39 }
40 } else {
41 ret.push_back(label[i]);
42 }
43 }
44
45 return ret;
46 }
47
48 } // namespace
49
50 namespace gfx {
51
52 #if defined(USE_WAYLAND) || defined(USE_AURA)
53 PangoContext* GetPangoContext() {
54 PangoFontMap* font_map = pango_cairo_font_map_get_default();
55 return pango_font_map_create_context(font_map);
56 }
57 #endif
58
59 double GetPangoResolution() {
60 static double resolution;
61 static bool determined_resolution = false;
62 if (!determined_resolution) {
63 determined_resolution = true;
64 PangoContext* default_context = GetPangoContext();
65 resolution = pango_cairo_context_get_resolution(default_context);
66 g_object_unref(default_context);
67 }
68 return resolution;
69 }
70
71 std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label) {
72 return ConvertAmperstandsTo(label, "_");
73 }
74
75 std::string RemoveWindowsStyleAccelerators(const std::string& label) {
76 return ConvertAmperstandsTo(label, "");
77 }
78
79 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) {
80 if (stride == 0)
81 stride = width * 4;
82
83 uint8_t* new_pixels = static_cast<uint8_t*>(malloc(height * stride));
84
85 // We have to copy the pixels and swap from BGRA to RGBA.
86 for (int i = 0; i < height; ++i) {
87 for (int j = 0; j < width; ++j) {
88 int idx = i * stride + j * 4;
89 new_pixels[idx] = pixels[idx + 2];
90 new_pixels[idx + 1] = pixels[idx + 1];
91 new_pixels[idx + 2] = pixels[idx];
92 new_pixels[idx + 3] = pixels[idx + 3];
93 }
94 }
95
96 return new_pixels;
97 }
98
99 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/linux_util.h ('k') | ui/gfx/platform_font_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698