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

Unified Diff: chrome/browser/ui/window_snapshot/window_snapshot_gtk.cc

Issue 8523022: Change snasphotting API to take in a bounds Rect (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nicer diff Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/window_snapshot/window_snapshot_gtk.cc
diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_gtk.cc b/chrome/browser/ui/window_snapshot/window_snapshot_gtk.cc
index 4507996ad5264b6ab7102f84d2648e8b98d2de3a..5c442c501e2b8b85badc6a7b72776ee05c7338d1 100644
--- a/chrome/browser/ui/window_snapshot/window_snapshot_gtk.cc
+++ b/chrome/browser/ui/window_snapshot/window_snapshot_gtk.cc
@@ -24,25 +24,32 @@ static cairo_status_t SnapshotCallback(
return CAIRO_STATUS_SUCCESS;
}
-gfx::Rect GrabWindowSnapshot(gfx::NativeWindow gtk_window,
- std::vector<unsigned char>* png_representation) {
- GdkWindow* gdk_window = GTK_WIDGET(gtk_window)->window;
+bool GrabWindowSnapshot(gfx::NativeWindow window_handle,
+ std::vector<unsigned char>* png_representation,
+ const gfx::Rect snapshot_bounds) {
+ GdkWindow* gdk_window = GTK_WIDGET(window_handle)->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 gfx::Rect();
+
+ gfx::Rect window_bounds;
+ if (ui::GetWindowRect(win, &window_bounds) == 0) {
+ LOG(ERROR) << "Couldn't get window bounds";
+ return false;
}
+
+ DCHECK(snapshot_bounds.right() <= window_bounds.width());
+ DCHECK(snapshot_bounds.bottom() <= window_bounds.height());
+
XImage* image = XGetImage(
- display, win, 0, 0, attr.width, attr.height, AllPlanes, ZPixmap);
+ display, win, snapshot_bounds.x(), snapshot_bounds.y(),
+ snapshot_bounds.width(), snapshot_bounds.height(), AllPlanes, ZPixmap);
if (!image) {
LOG(ERROR) << "Couldn't get image";
- return gfx::Rect();
+ return false;
}
if (image->depth != 24) {
LOG(ERROR)<< "Unsupported image depth " << image->depth;
- return gfx::Rect();
+ return false;
}
cairo_surface_t* surface =
cairo_image_surface_create_for_data(
@@ -54,13 +61,13 @@ gfx::Rect GrabWindowSnapshot(gfx::NativeWindow gtk_window,
if (!surface) {
LOG(ERROR) << "Unable to create Cairo surface from XImage data";
- return gfx::Rect();
+ return false;
}
cairo_surface_write_to_png_stream(
surface, SnapshotCallback, png_representation);
cairo_surface_destroy(surface);
- return gfx::Rect(image->width, image->height);
+ return true;
}
} // namespace browser

Powered by Google App Engine
This is Rietveld 408576698