| 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 |
| 11 #include <ctype.h> | 11 #include <ctype.h> |
| 12 #include <sys/ipc.h> | 12 #include <sys/ipc.h> |
| 13 #include <sys/shm.h> | 13 #include <sys/shm.h> |
| 14 | 14 |
| 15 #include <list> | 15 #include <list> |
| 16 #include <map> | 16 #include <map> |
| 17 #include <utility> | 17 #include <utility> |
| 18 #include <vector> | 18 #include <vector> |
| 19 | 19 |
| 20 #include <X11/extensions/shape.h> | 20 #include <X11/extensions/shape.h> |
| 21 #include <X11/extensions/XInput2.h> | 21 #include <X11/extensions/XInput2.h> |
| 22 #include <X11/Xcursor/Xcursor.h> |
| 22 | 23 |
| 23 #include "base/bind.h" | 24 #include "base/bind.h" |
| 24 #include "base/debug/trace_event.h" | 25 #include "base/debug/trace_event.h" |
| 25 #include "base/logging.h" | 26 #include "base/logging.h" |
| 26 #include "base/memory/scoped_ptr.h" | 27 #include "base/memory/scoped_ptr.h" |
| 27 #include "base/memory/singleton.h" | 28 #include "base/memory/singleton.h" |
| 28 #include "base/message_loop/message_loop.h" | 29 #include "base/message_loop/message_loop.h" |
| 29 #include "base/metrics/histogram.h" | 30 #include "base/metrics/histogram.h" |
| 30 #include "base/strings/string_number_conversions.h" | 31 #include "base/strings/string_number_conversions.h" |
| 31 #include "base/strings/string_util.h" | 32 #include "base/strings/string_util.h" |
| 32 #include "base/strings/stringprintf.h" | 33 #include "base/strings/stringprintf.h" |
| 33 #include "base/sys_byteorder.h" | 34 #include "base/sys_byteorder.h" |
| 34 #include "base/threading/thread.h" | 35 #include "base/threading/thread.h" |
| 36 #include "skia/ext/image_operations.h" |
| 35 #include "third_party/skia/include/core/SkBitmap.h" | 37 #include "third_party/skia/include/core/SkBitmap.h" |
| 36 #include "third_party/skia/include/core/SkPostConfig.h" | 38 #include "third_party/skia/include/core/SkPostConfig.h" |
| 37 #include "ui/base/x/x11_menu_list.h" | 39 #include "ui/base/x/x11_menu_list.h" |
| 38 #include "ui/base/x/x11_util_internal.h" | 40 #include "ui/base/x/x11_util_internal.h" |
| 39 #include "ui/events/event_utils.h" | 41 #include "ui/events/event_utils.h" |
| 40 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 42 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| 41 #include "ui/events/x/device_data_manager.h" | 43 #include "ui/events/x/device_data_manager.h" |
| 42 #include "ui/events/x/touch_factory_x11.h" | 44 #include "ui/events/x/touch_factory_x11.h" |
| 43 #include "ui/gfx/canvas.h" | 45 #include "ui/gfx/canvas.h" |
| 44 #include "ui/gfx/image/image_skia.h" | 46 #include "ui/gfx/image/image_skia.h" |
| 45 #include "ui/gfx/image/image_skia_rep.h" | 47 #include "ui/gfx/image/image_skia_rep.h" |
| 46 #include "ui/gfx/point.h" | 48 #include "ui/gfx/point.h" |
| 47 #include "ui/gfx/point_conversions.h" | 49 #include "ui/gfx/point_conversions.h" |
| 48 #include "ui/gfx/rect.h" | 50 #include "ui/gfx/rect.h" |
| 49 #include "ui/gfx/size.h" | 51 #include "ui/gfx/size.h" |
| 52 #include "ui/gfx/skia_util.h" |
| 50 #include "ui/gfx/x/x11_error_tracker.h" | 53 #include "ui/gfx/x/x11_error_tracker.h" |
| 51 | 54 |
| 52 #if defined(OS_FREEBSD) | 55 #if defined(OS_FREEBSD) |
| 53 #include <sys/sysctl.h> | 56 #include <sys/sysctl.h> |
| 54 #include <sys/types.h> | 57 #include <sys/types.h> |
| 55 #endif | 58 #endif |
| 56 | 59 |
| 57 #if defined(USE_AURA) | |
| 58 #include <X11/Xcursor/Xcursor.h> | |
| 59 #include "skia/ext/image_operations.h" | |
| 60 #include "ui/gfx/skia_util.h" | |
| 61 #endif | |
| 62 | |
| 63 namespace ui { | 60 namespace ui { |
| 64 | 61 |
| 65 namespace { | 62 namespace { |
| 66 | 63 |
| 67 int DefaultX11ErrorHandler(XDisplay* d, XErrorEvent* e) { | 64 int DefaultX11ErrorHandler(XDisplay* d, XErrorEvent* e) { |
| 68 if (base::MessageLoop::current()) { | 65 if (base::MessageLoop::current()) { |
| 69 base::MessageLoop::current()->PostTask( | 66 base::MessageLoop::current()->PostTask( |
| 70 FROM_HERE, base::Bind(&LogErrorEventDescription, d, *e)); | 67 FROM_HERE, base::Bind(&LogErrorEventDescription, d, *e)); |
| 71 } else { | 68 } else { |
| 72 LOG(ERROR) | 69 LOG(ERROR) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 133 |
| 137 private: | 134 private: |
| 138 // Maps X11 font cursor shapes to Cursor IDs. | 135 // Maps X11 font cursor shapes to Cursor IDs. |
| 139 std::map<int, ::Cursor> cache_; | 136 std::map<int, ::Cursor> cache_; |
| 140 | 137 |
| 141 DISALLOW_COPY_AND_ASSIGN(XCursorCache); | 138 DISALLOW_COPY_AND_ASSIGN(XCursorCache); |
| 142 }; | 139 }; |
| 143 | 140 |
| 144 XCursorCache* cursor_cache = NULL; | 141 XCursorCache* cursor_cache = NULL; |
| 145 | 142 |
| 146 #if defined(USE_AURA) | |
| 147 // A process wide singleton cache for custom X cursors. | 143 // A process wide singleton cache for custom X cursors. |
| 148 class XCustomCursorCache { | 144 class XCustomCursorCache { |
| 149 public: | 145 public: |
| 150 static XCustomCursorCache* GetInstance() { | 146 static XCustomCursorCache* GetInstance() { |
| 151 return Singleton<XCustomCursorCache>::get(); | 147 return Singleton<XCustomCursorCache>::get(); |
| 152 } | 148 } |
| 153 | 149 |
| 154 ::Cursor InstallCustomCursor(XcursorImage* image) { | 150 ::Cursor InstallCustomCursor(XcursorImage* image) { |
| 155 XCustomCursor* custom_cursor = new XCustomCursor(image); | 151 XCustomCursor* custom_cursor = new XCustomCursor(image); |
| 156 ::Cursor xcursor = custom_cursor->cursor(); | 152 ::Cursor xcursor = custom_cursor->cursor(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 }; | 208 }; |
| 213 | 209 |
| 214 XCustomCursorCache() {} | 210 XCustomCursorCache() {} |
| 215 ~XCustomCursorCache() { | 211 ~XCustomCursorCache() { |
| 216 Clear(); | 212 Clear(); |
| 217 } | 213 } |
| 218 | 214 |
| 219 std::map< ::Cursor, XCustomCursor*> cache_; | 215 std::map< ::Cursor, XCustomCursor*> cache_; |
| 220 DISALLOW_COPY_AND_ASSIGN(XCustomCursorCache); | 216 DISALLOW_COPY_AND_ASSIGN(XCustomCursorCache); |
| 221 }; | 217 }; |
| 222 #endif // defined(USE_AURA) | |
| 223 | 218 |
| 224 bool IsShapeAvailable() { | 219 bool IsShapeAvailable() { |
| 225 int dummy; | 220 int dummy; |
| 226 static bool is_shape_available = | 221 static bool is_shape_available = |
| 227 XShapeQueryExtension(gfx::GetXDisplay(), &dummy, &dummy); | 222 XShapeQueryExtension(gfx::GetXDisplay(), &dummy, &dummy); |
| 228 return is_shape_available; | 223 return is_shape_available; |
| 229 | 224 |
| 230 } | 225 } |
| 231 | 226 |
| 232 } // namespace | 227 } // namespace |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 if (!cursor_cache) | 304 if (!cursor_cache) |
| 310 cursor_cache = new XCursorCache; | 305 cursor_cache = new XCursorCache; |
| 311 return cursor_cache->GetCursor(cursor_shape); | 306 return cursor_cache->GetCursor(cursor_shape); |
| 312 } | 307 } |
| 313 | 308 |
| 314 void ResetXCursorCache() { | 309 void ResetXCursorCache() { |
| 315 delete cursor_cache; | 310 delete cursor_cache; |
| 316 cursor_cache = NULL; | 311 cursor_cache = NULL; |
| 317 } | 312 } |
| 318 | 313 |
| 319 #if defined(USE_AURA) | |
| 320 ::Cursor CreateReffedCustomXCursor(XcursorImage* image) { | 314 ::Cursor CreateReffedCustomXCursor(XcursorImage* image) { |
| 321 return XCustomCursorCache::GetInstance()->InstallCustomCursor(image); | 315 return XCustomCursorCache::GetInstance()->InstallCustomCursor(image); |
| 322 } | 316 } |
| 323 | 317 |
| 324 void RefCustomXCursor(::Cursor cursor) { | 318 void RefCustomXCursor(::Cursor cursor) { |
| 325 XCustomCursorCache::GetInstance()->Ref(cursor); | 319 XCustomCursorCache::GetInstance()->Ref(cursor); |
| 326 } | 320 } |
| 327 | 321 |
| 328 void UnrefCustomXCursor(::Cursor cursor) { | 322 void UnrefCustomXCursor(::Cursor cursor) { |
| 329 XCustomCursorCache::GetInstance()->Unref(cursor); | 323 XCustomCursorCache::GetInstance()->Unref(cursor); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 } | 429 } |
| 436 | 430 |
| 437 if (event_type == XI_Motion && num_coalesced > 0) { | 431 if (event_type == XI_Motion && num_coalesced > 0) { |
| 438 base::TimeDelta delta = ui::EventTimeFromNative(last_event) - | 432 base::TimeDelta delta = ui::EventTimeFromNative(last_event) - |
| 439 ui::EventTimeFromNative(const_cast<XEvent*>(xev)); | 433 ui::EventTimeFromNative(const_cast<XEvent*>(xev)); |
| 440 UMA_HISTOGRAM_COUNTS_10000("Event.CoalescedCount.Mouse", num_coalesced); | 434 UMA_HISTOGRAM_COUNTS_10000("Event.CoalescedCount.Mouse", num_coalesced); |
| 441 UMA_HISTOGRAM_TIMES("Event.CoalescedLatency.Mouse", delta); | 435 UMA_HISTOGRAM_TIMES("Event.CoalescedLatency.Mouse", delta); |
| 442 } | 436 } |
| 443 return num_coalesced; | 437 return num_coalesced; |
| 444 } | 438 } |
| 445 #endif | |
| 446 | 439 |
| 447 void HideHostCursor() { | 440 void HideHostCursor() { |
| 448 CR_DEFINE_STATIC_LOCAL(XScopedCursor, invisible_cursor, | 441 CR_DEFINE_STATIC_LOCAL(XScopedCursor, invisible_cursor, |
| 449 (CreateInvisibleCursor(), gfx::GetXDisplay())); | 442 (CreateInvisibleCursor(), gfx::GetXDisplay())); |
| 450 XDefineCursor(gfx::GetXDisplay(), DefaultRootWindow(gfx::GetXDisplay()), | 443 XDefineCursor(gfx::GetXDisplay(), DefaultRootWindow(gfx::GetXDisplay()), |
| 451 invisible_cursor.get()); | 444 invisible_cursor.get()); |
| 452 } | 445 } |
| 453 | 446 |
| 454 ::Cursor CreateInvisibleCursor() { | 447 ::Cursor CreateInvisibleCursor() { |
| 455 XDisplay* xdisplay = gfx::GetXDisplay(); | 448 XDisplay* xdisplay = gfx::GetXDisplay(); |
| (...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1348 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
| 1356 << "minor_code " << static_cast<int>(error_event.minor_code) | 1349 << "minor_code " << static_cast<int>(error_event.minor_code) |
| 1357 << " (" << request_str << ")"; | 1350 << " (" << request_str << ")"; |
| 1358 } | 1351 } |
| 1359 | 1352 |
| 1360 // ---------------------------------------------------------------------------- | 1353 // ---------------------------------------------------------------------------- |
| 1361 // End of x11_util_internal.h | 1354 // End of x11_util_internal.h |
| 1362 | 1355 |
| 1363 | 1356 |
| 1364 } // namespace ui | 1357 } // namespace ui |
| OLD | NEW |