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 #include "ui/aura/root_window_host_linux.h" | 5 #include "ui/aura/root_window_host_linux.h" |
6 | 6 |
7 #include <X11/Xatom.h> | 7 #include <X11/Xatom.h> |
8 #include <X11/Xcursor/Xcursor.h> | 8 #include <X11/Xcursor/Xcursor.h> |
| 9 #include <X11/Xlib.h> |
9 #include <X11/cursorfont.h> | 10 #include <X11/cursorfont.h> |
10 #include <X11/extensions/XInput2.h> | 11 #include <X11/extensions/XInput2.h> |
11 #include <X11/extensions/Xfixes.h> | 12 #include <X11/extensions/Xfixes.h> |
12 #include <X11/extensions/Xrandr.h> | 13 #include <X11/extensions/Xrandr.h> |
13 #include <algorithm> | 14 #include <algorithm> |
14 | 15 |
15 #include "base/message_pump_x.h" | 16 #include "base/message_pump_x.h" |
16 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
17 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
18 #include "grit/ui_resources_standard.h" | 19 #include "grit/ui_resources_standard.h" |
19 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
20 #include "ui/aura/client/user_gesture_client.h" | 21 #include "ui/aura/client/user_gesture_client.h" |
21 #include "ui/aura/dispatcher_linux.h" | 22 #include "ui/aura/dispatcher_linux.h" |
22 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
23 #include "ui/aura/event.h" | 24 #include "ui/aura/event.h" |
24 #include "ui/aura/root_window.h" | 25 #include "ui/aura/root_window.h" |
25 #include "ui/base/cursor/cursor.h" | 26 #include "ui/base/cursor/cursor.h" |
26 #include "ui/base/keycodes/keyboard_codes.h" | 27 #include "ui/base/keycodes/keyboard_codes.h" |
27 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
28 #include "ui/base/touch/touch_factory.h" | 29 #include "ui/base/touch/touch_factory.h" |
29 #include "ui/base/view_prop.h" | 30 #include "ui/base/view_prop.h" |
30 #include "ui/base/x/x11_atom_cache.h" | 31 #include "ui/base/x/x11_atom_cache.h" |
31 #include "ui/base/x/x11_util.h" | 32 #include "ui/base/x/x11_util.h" |
32 #include "ui/compositor/layer.h" | 33 #include "ui/compositor/layer.h" |
| 34 #include "ui/gfx/codec/png_codec.h" |
33 #include "ui/gfx/image/image.h" | 35 #include "ui/gfx/image/image.h" |
34 | 36 |
35 using ui::X11AtomCache; | 37 using ui::X11AtomCache; |
36 using std::max; | 38 using std::max; |
37 using std::min; | 39 using std::min; |
38 | 40 |
39 namespace aura { | 41 namespace aura { |
40 | 42 |
41 namespace { | 43 namespace { |
42 | 44 |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 static const char* k_NET_WM_USER_TIME = "_NET_WM_USER_TIME"; | 790 static const char* k_NET_WM_USER_TIME = "_NET_WM_USER_TIME"; |
789 focus_when_shown_ = focus_when_shown; | 791 focus_when_shown_ = focus_when_shown; |
790 if (IsWindowManagerPresent() && !focus_when_shown_) { | 792 if (IsWindowManagerPresent() && !focus_when_shown_) { |
791 ui::SetIntProperty(xwindow_, | 793 ui::SetIntProperty(xwindow_, |
792 k_NET_WM_USER_TIME, | 794 k_NET_WM_USER_TIME, |
793 k_NET_WM_USER_TIME, | 795 k_NET_WM_USER_TIME, |
794 0); | 796 0); |
795 } | 797 } |
796 } | 798 } |
797 | 799 |
| 800 bool RootWindowHostLinux::GrabSnapshot( |
| 801 const gfx::Rect& snapshot_bounds, |
| 802 std::vector<unsigned char>* png_representation) { |
| 803 XImage* image = XGetImage( |
| 804 xdisplay_, xwindow_, |
| 805 snapshot_bounds.x(), snapshot_bounds.y(), |
| 806 snapshot_bounds.width(), snapshot_bounds.height(), |
| 807 AllPlanes, ZPixmap); |
| 808 |
| 809 gfx::PNGCodec::ColorFormat color_format; |
| 810 |
| 811 if (image->bits_per_pixel == 32) { |
| 812 color_format = (image->byte_order == LSBFirst) ? |
| 813 gfx::PNGCodec::FORMAT_BGRA : gfx::PNGCodec::FORMAT_RGBA; |
| 814 } else if (image->bits_per_pixel == 24) { |
| 815 // PNGCodec accepts FORMAT_RGB for 3 bytes per pixel: |
| 816 color_format = gfx::PNGCodec::FORMAT_RGB; |
| 817 if (image->byte_order == LSBFirst) { |
| 818 LOG(WARNING) << "Converting BGR->RGB will damage the performance..."; |
| 819 int image_size = |
| 820 image->width * image->height * image->bits_per_pixel / 8; |
| 821 for (int i = 0; i < image_size; i += 3) { |
| 822 char tmp = image->data[i]; |
| 823 image->data[i] = image->data[i+2]; |
| 824 image->data[i+2] = tmp; |
| 825 } |
| 826 } |
| 827 } else { |
| 828 LOG(ERROR) << "bits_per_pixel is too small"; |
| 829 XFree(image); |
| 830 return false; |
| 831 } |
| 832 |
| 833 unsigned char* data = reinterpret_cast<unsigned char*>(image->data); |
| 834 gfx::PNGCodec::Encode(data, color_format, snapshot_bounds.size(), |
| 835 image->width * image->bits_per_pixel / 8, |
| 836 true, std::vector<gfx::PNGCodec::Comment>(), |
| 837 png_representation); |
| 838 XFree(image); |
| 839 return true; |
| 840 } |
| 841 |
798 void RootWindowHostLinux::PostNativeEvent( | 842 void RootWindowHostLinux::PostNativeEvent( |
799 const base::NativeEvent& native_event) { | 843 const base::NativeEvent& native_event) { |
800 DCHECK(xwindow_); | 844 DCHECK(xwindow_); |
801 DCHECK(xdisplay_); | 845 DCHECK(xdisplay_); |
802 XEvent xevent = *native_event; | 846 XEvent xevent = *native_event; |
803 xevent.xany.display = xdisplay_; | 847 xevent.xany.display = xdisplay_; |
804 xevent.xany.window = xwindow_; | 848 xevent.xany.window = xwindow_; |
805 | 849 |
806 switch (xevent.type) { | 850 switch (xevent.type) { |
807 case EnterNotify: | 851 case EnterNotify: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostLinuxKey)); | 904 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostLinuxKey)); |
861 } | 905 } |
862 | 906 |
863 // static | 907 // static |
864 gfx::Size RootWindowHost::GetNativeScreenSize() { | 908 gfx::Size RootWindowHost::GetNativeScreenSize() { |
865 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); | 909 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); |
866 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 910 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
867 } | 911 } |
868 | 912 |
869 } // namespace aura | 913 } // namespace aura |
OLD | NEW |