OLD | NEW |
---|---|
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 // This file defines utility functions for X11 (Linux only). This code has been | 5 // This file defines utility functions for X11 (Linux only). This code has been |
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support | 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support |
7 // remains woefully incomplete. | 7 // remains woefully incomplete. |
8 | 8 |
9 #include "ui/base/x/x11_util.h" | 9 #include "ui/base/x/x11_util.h" |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... | |
30 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
31 #include "ui/gfx/size.h" | 31 #include "ui/gfx/size.h" |
32 | 32 |
33 #if defined(OS_FREEBSD) | 33 #if defined(OS_FREEBSD) |
34 #include <sys/sysctl.h> | 34 #include <sys/sysctl.h> |
35 #include <sys/types.h> | 35 #include <sys/types.h> |
36 #endif | 36 #endif |
37 | 37 |
38 #if defined(USE_AURA) | 38 #if defined(USE_AURA) |
39 #include <X11/Xcursor/Xcursor.h> | 39 #include <X11/Xcursor/Xcursor.h> |
40 #include "third_party/skia/include/core/SkBitmap.h" | |
41 #include "third_party/skia/include/core/SkUnPreMultiply.h" | |
40 #endif | 42 #endif |
41 | 43 |
42 #if defined(TOOLKIT_GTK) | 44 #if defined(TOOLKIT_GTK) |
43 #include <gdk/gdk.h> | 45 #include <gdk/gdk.h> |
44 #include <gdk/gdkx.h> | 46 #include <gdk/gdkx.h> |
45 #include <gtk/gtk.h> | 47 #include <gtk/gtk.h> |
46 #include "ui/base/gtk/gdk_x_compat.h" | 48 #include "ui/base/gtk/gdk_x_compat.h" |
47 #include "ui/base/gtk/gtk_compat.h" | 49 #include "ui/base/gtk/gtk_compat.h" |
48 #else | 50 #else |
49 // TODO(sad): Use the new way of handling X errors when | 51 // TODO(sad): Use the new way of handling X errors when |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 return XCustomCursorCache::GetInstance()->InstallCustomCursor(image); | 406 return XCustomCursorCache::GetInstance()->InstallCustomCursor(image); |
405 } | 407 } |
406 | 408 |
407 void RefCustomXCursor(::Cursor cursor) { | 409 void RefCustomXCursor(::Cursor cursor) { |
408 XCustomCursorCache::GetInstance()->Ref(cursor); | 410 XCustomCursorCache::GetInstance()->Ref(cursor); |
409 } | 411 } |
410 | 412 |
411 void UnrefCustomXCursor(::Cursor cursor) { | 413 void UnrefCustomXCursor(::Cursor cursor) { |
412 XCustomCursorCache::GetInstance()->Unref(cursor); | 414 XCustomCursorCache::GetInstance()->Unref(cursor); |
413 } | 415 } |
416 | |
417 XcursorImage* SkBitmapToXcursorImage(const SkBitmap* bitmap, | |
418 const gfx::Point& hotspot) { | |
419 DCHECK(bitmap->config() == SkBitmap::kARGB_8888_Config); | |
420 XcursorImage* image = XcursorImageCreate(bitmap->width(), bitmap->height()); | |
sky
2012/05/03 21:09:44
Can you move ConvertSkiatoRGBA to a common place?
varunjain
2012/05/03 22:12:20
Done.
| |
421 image->xhot = hotspot.x(); | |
422 image->yhot = hotspot.y(); | |
423 uint32* pixels = image->pixels; | |
424 | |
425 if (bitmap->width() && bitmap->height()) { | |
426 bitmap->lockPixels(); | |
427 int height = bitmap->height(); | |
428 int width = bitmap->width(); | |
429 for (int y = 0, i = 0; y < height; y++) { | |
430 for (int x = 0; x < width; x++) { | |
431 uint32 pixel = bitmap->getAddr32(0, y)[x]; | |
432 int alpha = SkColorGetA(pixel); | |
433 if (alpha != 0 && alpha != 255) | |
434 pixels[i] = SkUnPreMultiply::PMColorToColor(pixel); | |
435 else | |
436 pixels[i] = pixel; | |
437 ++i; | |
438 } | |
439 } | |
440 bitmap->unlockPixels(); | |
441 } | |
442 return image; | |
443 } | |
414 #endif | 444 #endif |
415 | 445 |
416 XID GetX11RootWindow() { | 446 XID GetX11RootWindow() { |
417 return DefaultRootWindow(GetXDisplay()); | 447 return DefaultRootWindow(GetXDisplay()); |
418 } | 448 } |
419 | 449 |
420 bool GetCurrentDesktop(int* desktop) { | 450 bool GetCurrentDesktop(int* desktop) { |
421 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop); | 451 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop); |
422 } | 452 } |
423 | 453 |
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1226 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1256 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1227 << "minor_code " << static_cast<int>(error_event.minor_code) | 1257 << "minor_code " << static_cast<int>(error_event.minor_code) |
1228 << " (" << request_str << ")"; | 1258 << " (" << request_str << ")"; |
1229 } | 1259 } |
1230 | 1260 |
1231 // ---------------------------------------------------------------------------- | 1261 // ---------------------------------------------------------------------------- |
1232 // End of x11_util_internal.h | 1262 // End of x11_util_internal.h |
1233 | 1263 |
1234 | 1264 |
1235 } // namespace ui | 1265 } // namespace ui |
OLD | NEW |