summaryrefslogtreecommitdiffstats
path: root/ui/gfx/linux_util.cc
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-07 02:06:01 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-07 02:06:01 +0000
commit4a6bef33b6897ceff27eee304afe1a6da5fee4ff (patch)
tree64c7e2cb508ccbe6a9e50be1da7c99b016ea5b52 /ui/gfx/linux_util.cc
parentccb824344b58ae4acbc0b7b30ebcba048a032836 (diff)
downloadchromium_src-4a6bef33b6897ceff27eee304afe1a6da5fee4ff.zip
chromium_src-4a6bef33b6897ceff27eee304afe1a6da5fee4ff.tar.gz
chromium_src-4a6bef33b6897ceff27eee304afe1a6da5fee4ff.tar.bz2
aura: A few changes to have aura_demo compile and run on linux.
* Make 'aura' a component, and export Desktop and Window. * Events (Key and Mouse) from X Events. * Rip non-gtk bits out of gfx/gtk_util into gfx/linux_util BUG=93934,93933 TEST=none Review URL: http://codereview.chromium.org/7833016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99898 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/linux_util.cc')
-rw-r--r--ui/gfx/linux_util.cc99
1 files changed, 99 insertions, 0 deletions
diff --git a/ui/gfx/linux_util.cc b/ui/gfx/linux_util.cc
new file mode 100644
index 0000000..a189233
--- /dev/null
+++ b/ui/gfx/linux_util.cc
@@ -0,0 +1,99 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/linux_util.h"
+
+#include <pango/pango.h>
+#include <pango/pangocairo.h>
+#include <stdlib.h>
+
+#include "base/basictypes.h"
+#include "base/command_line.h"
+#include "base/linux_util.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkUnPreMultiply.h"
+#include "ui/gfx/rect.h"
+
+namespace {
+
+// Common implementation of ConvertAcceleratorsFromWindowsStyle() and
+// RemoveWindowsStyleAccelerators().
+// Replaces all ampersands (as used in our grd files to indicate mnemonics)
+// to |target|. Similarly any underscores get replaced with two underscores as
+// is needed by GTK.
+std::string ConvertAmperstandsTo(const std::string& label,
+ const std::string& target) {
+ std::string ret;
+ ret.reserve(label.length() * 2);
+ for (size_t i = 0; i < label.length(); ++i) {
+ if ('_' == label[i]) {
+ ret.push_back('_');
+ ret.push_back('_');
+ } else if ('&' == label[i]) {
+ if (i + 1 < label.length() && '&' == label[i + 1]) {
+ ret.push_back('&');
+ ++i;
+ } else {
+ ret.append(target);
+ }
+ } else {
+ ret.push_back(label[i]);
+ }
+ }
+
+ return ret;
+}
+
+} // namespace
+
+namespace gfx {
+
+#if defined(USE_WAYLAND) || defined(USE_AURA)
+PangoContext* GetPangoContext() {
+ PangoFontMap* font_map = pango_cairo_font_map_get_default();
+ return pango_font_map_create_context(font_map);
+}
+#endif
+
+double GetPangoResolution() {
+ static double resolution;
+ static bool determined_resolution = false;
+ if (!determined_resolution) {
+ determined_resolution = true;
+ PangoContext* default_context = GetPangoContext();
+ resolution = pango_cairo_context_get_resolution(default_context);
+ g_object_unref(default_context);
+ }
+ return resolution;
+}
+
+std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label) {
+ return ConvertAmperstandsTo(label, "_");
+}
+
+std::string RemoveWindowsStyleAccelerators(const std::string& label) {
+ return ConvertAmperstandsTo(label, "");
+}
+
+uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) {
+ if (stride == 0)
+ stride = width * 4;
+
+ uint8_t* new_pixels = static_cast<uint8_t*>(malloc(height * stride));
+
+ // We have to copy the pixels and swap from BGRA to RGBA.
+ for (int i = 0; i < height; ++i) {
+ for (int j = 0; j < width; ++j) {
+ int idx = i * stride + j * 4;
+ new_pixels[idx] = pixels[idx + 2];
+ new_pixels[idx + 1] = pixels[idx + 1];
+ new_pixels[idx + 2] = pixels[idx];
+ new_pixels[idx + 3] = pixels[idx + 3];
+ }
+ }
+
+ return new_pixels;
+}
+
+} // namespace gfx