summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-28 22:32:47 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-28 22:32:47 +0000
commit8ebe1b489cd5b7d5c5305a46dfe88bc2ef5833c7 (patch)
treef21231b669ed3a7302fc63623fe72b9109e5f63c /chrome
parentbbbfeff3dc729802a44395a698242371d7a74ee2 (diff)
downloadchromium_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')
-rw-r--r--chrome/browser/views/bug_report_view.cc21
-rw-r--r--chrome/common/x11_util.cc48
-rw-r--r--chrome/common/x11_util.h7
3 files changed, 64 insertions, 12 deletions
diff --git a/chrome/browser/views/bug_report_view.cc b/chrome/browser/views/bug_report_view.cc
index a674eae..f8940ca 100644
--- a/chrome/browser/views/bug_report_view.cc
+++ b/chrome/browser/views/bug_report_view.cc
@@ -30,7 +30,9 @@
#include "views/window/client_view.h"
#include "views/window/window.h"
-#if !defined(OS_CHROMEOS)
+#if defined(OS_CHROMEOS)
+#include "chrome/common/x11_util.h"
+#else
#include "app/win_util.h"
#endif
@@ -92,17 +94,19 @@ void ShowBugReportView(views::Window* parent,
TabContents* tab) {
BugReportView* view = new BugReportView(profile, tab);
-#if !defined(OS_CHROMEOS)
- // TODO(davemoore) implement this for ChromiumOS. derat has code in
- // the window manager (snapshot.cc) that we can start with.
// Grab an exact snapshot of the window that the user is seeing (i.e. as
// rendered--do not re-render, and include windowed plugins).
std::vector<unsigned char> *screenshot_png = new std::vector<unsigned char>;
+
+#if defined(OS_CHROMEOS)
+ x11_util::GrabWindowSnapshot(parent->GetNativeWindow(), screenshot_png);
+#else
win_util::GrabWindowSnapshot(parent->GetNativeWindow(), screenshot_png);
+#endif
+
// The BugReportView takes ownership of the png data, and will dispose of
// it in its destructor.
view->set_png_data(screenshot_png);
-#endif
// Create and show the dialog.
views::Window::CreateChromeWindow(parent->GetNativeWindow(), gfx::Rect(),
@@ -176,11 +180,9 @@ void BugReportView::SetupControl() {
l10n_util::GetString(IDS_BUGREPORT_INCLUDE_PAGE_SOURCE_CHKBOX));
include_page_source_checkbox_->SetChecked(true);
-#if !defined(OS_CHROMEOS)
include_page_image_checkbox_ = new views::Checkbox(
l10n_util::GetString(IDS_BUGREPORT_INCLUDE_PAGE_IMAGE_CHKBOX));
include_page_image_checkbox_->SetChecked(true);
-#endif
// Arranges controls by using GridLayout.
const int column_set_id = 0;
@@ -328,14 +330,9 @@ bool BugReportView::Accept() {
problem_type_,
UTF16ToUTF8(page_url_text_->text()),
UTF16ToUTF8(description_text_->text()),
-#if defined(OS_CHROMEOS)
- NULL,
- 0
-#else
include_page_image_checkbox_->checked() && png_data_.get() ?
reinterpret_cast<const char *>(&((*png_data_.get())[0])) : NULL,
png_data_->size()
-#endif
);
}
return true;
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
diff --git a/chrome/common/x11_util.h b/chrome/common/x11_util.h
index 3f2a92f..1b6f23b 100644
--- a/chrome/common/x11_util.h
+++ b/chrome/common/x11_util.h
@@ -19,6 +19,7 @@
typedef struct _GdkDrawable GdkWindow;
typedef struct _GtkWidget GtkWidget;
+typedef struct _GtkWindow GtkWindow;
typedef unsigned long XID;
typedef struct _XDisplay Display;
@@ -139,6 +140,12 @@ bool GetWindowParent(XID* parent_window, bool* parent_is_root, XID window);
// Get the window manager name.
bool GetWindowManagerName(std::string* name);
+// Grabs a snapshot of the designated window and stores a PNG representation
+// into a byte vector.
+void GrabWindowSnapshot(GtkWindow* gdk_window,
+ std::vector<unsigned char>* png_representation);
+
+
} // namespace x11_util
#endif // CHROME_COMMON_X11_UTIL_H_