diff options
author | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-28 22:32:47 +0000 |
---|---|---|
committer | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-28 22:32:47 +0000 |
commit | 8ebe1b489cd5b7d5c5305a46dfe88bc2ef5833c7 (patch) | |
tree | f21231b669ed3a7302fc63623fe72b9109e5f63c /chrome/common/x11_util.cc | |
parent | bbbfeff3dc729802a44395a698242371d7a74ee2 (diff) | |
download | chromium_src-8ebe1b489cd5b7d5c5305a46dfe88bc2ef5833c7.zip chromium_src-8ebe1b489cd5b7d5c5305a46dfe88bc2ef5833c7.tar.gz chromium_src-8ebe1b489cd5b7d5c5305a46dfe88bc2ef5833c7.tar.bz2 |
send the pngs on cros
Added code to stream screenshots
gtk screenshot support
Review URL: http://codereview.chromium.org/517017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35317 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/x11_util.cc')
-rw-r--r-- | chrome/common/x11_util.cc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/chrome/common/x11_util.cc b/chrome/common/x11_util.cc index 556b804..4f8eed7 100644 --- a/chrome/common/x11_util.cc +++ b/chrome/common/x11_util.cc @@ -564,4 +564,52 @@ bool GetWindowManagerName(std::string* wm_name) { return true; } +static cairo_status_t SnapshotCallback( + void *closure, const unsigned char *data, unsigned int length) { + std::vector<unsigned char>* png_representation = + static_cast<std::vector<unsigned char>*>(closure); + + size_t old_size = png_representation->size(); + png_representation->resize(old_size + length); + memcpy(&(*png_representation)[old_size], data, length); + return CAIRO_STATUS_SUCCESS; +} + +void GrabWindowSnapshot(GtkWindow* gtk_window, + std::vector<unsigned char>* png_representation) { + GdkWindow* gdk_window = GTK_WIDGET(gtk_window)->window; + Display* display = GDK_WINDOW_XDISPLAY(gdk_window); + XID win = GDK_WINDOW_XID(gdk_window); + XWindowAttributes attr; + if (XGetWindowAttributes(display, win, &attr) != 0) { + LOG(ERROR) << "Couldn't get window attributes"; + return; + } + XImage* image = XGetImage( + display, win, 0, 0, attr.width, attr.height, AllPlanes, ZPixmap); + if (!image) { + LOG(ERROR) << "Couldn't get image"; + return; + } + if (image->depth != 24) { + LOG(ERROR)<< "Unsupported image depth " << image->depth; + return; + } + cairo_surface_t* surface = + cairo_image_surface_create_for_data( + reinterpret_cast<unsigned char*>(image->data), + CAIRO_FORMAT_RGB24, + image->width, + image->height, + image->bytes_per_line); + + if (!surface) { + LOG(ERROR) << "Unable to create Cairo surface from XImage data"; + return; + } + cairo_surface_write_to_png_stream( + surface, SnapshotCallback, png_representation); + cairo_surface_destroy(surface); +} + } // namespace x11_util |