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

Side by Side Diff: ui/snapshot/snapshot_gtk.cc

Issue 11399002: Implemented GetWindowSnapshot on RenderViewImpl (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Resolved dependency issues Created 8 years 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
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 "chrome/browser/ui/window_snapshot/window_snapshot.h" 5 #include "ui/snapshot/snapshot.h"
6 6
7 #include <gdk/gdkx.h> 7 #include <gdk/gdkx.h>
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "ui/base/x/x11_util.h" 11 #include "ui/base/x/x11_util.h"
12 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
13 13
14 namespace { 14 namespace {
15 15
16 cairo_status_t SnapshotCallback(void* closure, 16 cairo_status_t SnapshotCallback(void* closure,
17 const unsigned char* data, 17 const unsigned char* data,
18 unsigned int length) { 18 unsigned int length) {
19 std::vector<unsigned char>* png_representation = 19 std::vector<unsigned char>* png_representation =
20 static_cast<std::vector<unsigned char>*>(closure); 20 static_cast<std::vector<unsigned char>*>(closure);
21 21
22 size_t old_size = png_representation->size(); 22 size_t old_size = png_representation->size();
23 png_representation->resize(old_size + length); 23 png_representation->resize(old_size + length);
24 memcpy(&(*png_representation)[old_size], data, length); 24 memcpy(&(*png_representation)[old_size], data, length);
25 return CAIRO_STATUS_SUCCESS; 25 return CAIRO_STATUS_SUCCESS;
26 } 26 }
27 27
28 } // namespace 28 } // namespace
29 29
30 namespace chrome { 30 namespace ui {
31 namespace internal {
32 31
33 bool GrabWindowSnapshot(gfx::NativeWindow window_handle, 32 bool GrabViewSnapshot(gfx::NativeView view_handle,
34 std::vector<unsigned char>* png_representation, 33 std::vector<unsigned char>* png_representation,
35 const gfx::Rect& snapshot_bounds) { 34 const gfx::Rect& snapshot_bounds) {
36 GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window_handle)); 35 GdkWindow* gdk_window = gtk_widget_get_window(view_handle);
37 Display* display = GDK_WINDOW_XDISPLAY(gdk_window); 36 Display* display = GDK_WINDOW_XDISPLAY(gdk_window);
38 XID win = GDK_WINDOW_XID(gdk_window); 37 XID win = GDK_WINDOW_XID(gdk_window);
39 38
40 gfx::Rect window_bounds; 39 gfx::Rect window_bounds;
41 if (ui::GetWindowRect(win, &window_bounds) == 0) { 40 if (ui::GetWindowRect(win, &window_bounds) == 0) {
42 LOG(ERROR) << "Couldn't get window bounds"; 41 LOG(ERROR) << "Couldn't get window bounds";
43 return false; 42 return false;
44 } 43 }
45 44
46 DCHECK_LE(snapshot_bounds.right(), window_bounds.width()); 45 DCHECK_LE(snapshot_bounds.right(), window_bounds.width());
(...skipping 22 matching lines...) Expand all
69 LOG(ERROR) << "Unable to create Cairo surface from XImage data"; 68 LOG(ERROR) << "Unable to create Cairo surface from XImage data";
70 return false; 69 return false;
71 } 70 }
72 cairo_surface_write_to_png_stream( 71 cairo_surface_write_to_png_stream(
73 surface, SnapshotCallback, png_representation); 72 surface, SnapshotCallback, png_representation);
74 cairo_surface_destroy(surface); 73 cairo_surface_destroy(surface);
75 74
76 return true; 75 return true;
77 } 76 }
78 77
79 } // namespace internal 78 bool GrabWindowSnapshot(gfx::NativeWindow window_handle,
80 } // namespace chrome 79 std::vector<unsigned char>* png_representation,
80 const gfx::Rect& snapshot_bounds) {
81 return GrabViewSnapshot(GTK_WIDGET(window_handle), png_representation,
82 snapshot_bounds);
83 }
84
85 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698