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

Side by Side Diff: chrome/browser/ui/window_snapshot/window_snapshot_x.cc

Issue 6386009: Remove app/win/win_util.h,cc etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code cleanup Created 9 years, 11 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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/window_snapshot/window_snapshot.h"
6
7 #include <gdk/gdkx.h>
8 #include <gtk/gtk.h>
9
10 #include "base/logging.h"
11 #include "ui/base/x/x11_util.h"
12
13 namespace browser {
14
15 static cairo_status_t SnapshotCallback(
16 void *closure, const unsigned char *data, unsigned int length) {
17 std::vector<unsigned char>* png_representation =
18 static_cast<std::vector<unsigned char>*>(closure);
19
20 size_t old_size = png_representation->size();
21 png_representation->resize(old_size + length);
22 memcpy(&(*png_representation)[old_size], data, length);
23 return CAIRO_STATUS_SUCCESS;
24 }
25
26 void GrabWindowSnapshot(gfx::NativeWindow gtk_window,
27 std::vector<unsigned char>* png_representation) {
28 GdkWindow* gdk_window = GTK_WIDGET(gtk_window)->window;
29 Display* display = GDK_WINDOW_XDISPLAY(gdk_window);
30 XID win = GDK_WINDOW_XID(gdk_window);
31 XWindowAttributes attr;
32 if (XGetWindowAttributes(display, win, &attr) == 0) {
33 LOG(ERROR) << "Couldn't get window attributes";
34 return;
35 }
36 XImage* image = XGetImage(
37 display, win, 0, 0, attr.width, attr.height, AllPlanes, ZPixmap);
38 if (!image) {
39 LOG(ERROR) << "Couldn't get image";
40 return;
41 }
42 if (image->depth != 24) {
43 LOG(ERROR)<< "Unsupported image depth " << image->depth;
44 return;
45 }
46 cairo_surface_t* surface =
47 cairo_image_surface_create_for_data(
48 reinterpret_cast<unsigned char*>(image->data),
49 CAIRO_FORMAT_RGB24,
50 image->width,
51 image->height,
52 image->bytes_per_line);
53
54 if (!surface) {
55 LOG(ERROR) << "Unable to create Cairo surface from XImage data";
56 return;
57 }
58 cairo_surface_write_to_png_stream(
59 surface, SnapshotCallback, png_representation);
60 cairo_surface_destroy(surface);
61 }
62
63 } // namespace browser
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698