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

Side by Side Diff: ui/aura/root_window_host_linux.cc

Issue 10386124: Introduce XGetImage() for GrabWindowSnapshot() in ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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
OLDNEW
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_util.h" 31 #include "ui/base/x/x11_util.h"
31 #include "ui/compositor/layer.h" 32 #include "ui/compositor/layer.h"
33 #include "ui/gfx/codec/png_codec.h"
32 #include "ui/gfx/image/image.h" 34 #include "ui/gfx/image/image.h"
33 35
34 using std::max; 36 using std::max;
35 using std::min; 37 using std::min;
36 38
37 namespace aura { 39 namespace aura {
38 40
39 namespace { 41 namespace {
40 42
41 // Standard Linux mouse buttons for going back and forward. 43 // Standard Linux mouse buttons for going back and forward.
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 static const char* k_NET_WM_USER_TIME = "_NET_WM_USER_TIME"; 799 static const char* k_NET_WM_USER_TIME = "_NET_WM_USER_TIME";
798 focus_when_shown_ = focus_when_shown; 800 focus_when_shown_ = focus_when_shown;
799 if (IsWindowManagerPresent() && !focus_when_shown_) { 801 if (IsWindowManagerPresent() && !focus_when_shown_) {
800 ui::SetIntProperty(xwindow_, 802 ui::SetIntProperty(xwindow_,
801 k_NET_WM_USER_TIME, 803 k_NET_WM_USER_TIME,
802 k_NET_WM_USER_TIME, 804 k_NET_WM_USER_TIME,
803 0); 805 0);
804 } 806 }
805 } 807 }
806 808
809 bool RootWindowHostLinux::GrabSnapshot(
810 std::vector<unsigned char>* png_representation,
811 const gfx::Rect& snapshot_bounds) {
812 XImage* image = XGetImage(
813 xdisplay_, xwindow_,
814 snapshot_bounds.x(), snapshot_bounds.y(),
815 snapshot_bounds.width(), snapshot_bounds.height(),
816 AllPlanes, ZPixmap);
817
818 gfx::PNGCodec::ColorFormat color_format;
819
820 if (image->bits_per_pixel == 32) {
821 color_format = (image->byte_order == LSBFirst) ?
822 gfx::PNGCodec::FORMAT_BGRA : gfx::PNGCodec::FORMAT_RGBA;
823 } else if (image->bits_per_pixel == 24) {
824 // PNGCodec accepts FORMAT_RGB for 3 bytes per pixel:
825 color_format = gfx::PNGCodec::FORMAT_RGB;
826 if (image->byte_order == LSBFirst) {
827 LOG(WARNING) << "Converting BGR->RGB will damage the performance...";
828 int image_size =
829 image->width * image->height * image->bits_per_pixel / 8;
830 for (int i = 0; i < image_size; i += 3) {
831 char tmp = image->data[i];
832 image->data[i] = image->data[i+2];
833 image->data[i+2] = tmp;
834 }
835 }
836 } else {
837 LOG(ERROR) << "bits_per_pixel is too small";
Daniel Erat 2012/05/16 19:43:50 don't forget to XFree(image) before returning here
Jun Mukai 2012/05/16 21:43:57 Done.
838 return false;
839 }
840
841 unsigned char* data = reinterpret_cast<unsigned char*>(image->data);
842 gfx::PNGCodec::Encode(data, color_format, snapshot_bounds.size(),
843 image->width * image->bits_per_pixel / 8,
844 true, std::vector<gfx::PNGCodec::Comment>(),
845 png_representation);
846 XFree(image);
847 return true;
848 }
849
807 void RootWindowHostLinux::PostNativeEvent( 850 void RootWindowHostLinux::PostNativeEvent(
808 const base::NativeEvent& native_event) { 851 const base::NativeEvent& native_event) {
809 DCHECK(xwindow_); 852 DCHECK(xwindow_);
810 DCHECK(xdisplay_); 853 DCHECK(xdisplay_);
811 XEvent xevent = *native_event; 854 XEvent xevent = *native_event;
812 xevent.xany.display = xdisplay_; 855 xevent.xany.display = xdisplay_;
813 xevent.xany.window = xwindow_; 856 xevent.xany.window = xwindow_;
814 857
815 switch (xevent.type) { 858 switch (xevent.type) {
816 case EnterNotify: 859 case EnterNotify:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostLinuxKey)); 910 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostLinuxKey));
868 } 911 }
869 912
870 // static 913 // static
871 gfx::Size RootWindowHost::GetNativeScreenSize() { 914 gfx::Size RootWindowHost::GetNativeScreenSize() {
872 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); 915 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay();
873 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); 916 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0));
874 } 917 }
875 918
876 } // namespace aura 919 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698