diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-14 20:50:58 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-14 20:50:58 +0000 |
commit | 87130f869a23f9a842f3a25212dd37bf29814c9d (patch) | |
tree | 45e24a3c8498929abda551b28ab1d8c18517b98f | |
parent | 5c086d79fabc962ec30ed6755e4a379a65681092 (diff) | |
download | chromium_src-87130f869a23f9a842f3a25212dd37bf29814c9d.zip chromium_src-87130f869a23f9a842f3a25212dd37bf29814c9d.tar.gz chromium_src-87130f869a23f9a842f3a25212dd37bf29814c9d.tar.bz2 |
Gtk: improve performance of tab dragging.
Remove two server trips and two byte swizzles by keeping the tab image server side (instead of piping it through an SkBitmap). This creates noticeably better performance on drawing attached dragged tabs (i.e. when you drag a tab to reorder it, but don't drag out of the tab strip) on non-compositing WMs (I suspect it is better for compositing as well, but did not test it).
BUG=21657
TEST=see above
Review URL: http://codereview.chromium.org/496002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34488 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/gtk/tabs/dragged_tab_gtk.cc | 25 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/dragged_tab_gtk.h | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_renderer_gtk.cc | 6 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_renderer_gtk.h | 4 |
4 files changed, 22 insertions, 20 deletions
diff --git a/chrome/browser/gtk/tabs/dragged_tab_gtk.cc b/chrome/browser/gtk/tabs/dragged_tab_gtk.cc index 1764578..40127ca 100644 --- a/chrome/browser/gtk/tabs/dragged_tab_gtk.cc +++ b/chrome/browser/gtk/tabs/dragged_tab_gtk.cc @@ -241,7 +241,7 @@ void DraggedTabGtk::SetContainerTransparency() { cairo_destroy(cairo_context); } -void DraggedTabGtk::SetContainerShapeMask(GdkPixbuf* pixbuf) { +void DraggedTabGtk::SetContainerShapeMask(cairo_surface_t* surface) { // Create a 1bpp bitmap the size of |container_|. gfx::Size size = bounds().size(); GdkPixmap* pixmap = gdk_pixmap_new(NULL, size.width(), size.height(), 1); @@ -255,7 +255,7 @@ void DraggedTabGtk::SetContainerShapeMask(GdkPixbuf* pixbuf) { cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); if (!attached_) cairo_scale(cairo_context, kScalingFactor, kScalingFactor); - gdk_cairo_set_source_pixbuf(cairo_context, pixbuf, 0, 0); + cairo_set_source_surface(cairo_context, surface, 0, 0); cairo_paint(cairo_context); if (!attached_) { @@ -264,7 +264,7 @@ void DraggedTabGtk::SetContainerShapeMask(GdkPixbuf* pixbuf) { cairo_identity_matrix(cairo_context); cairo_set_source_rgba(cairo_context, 1.0f, 1.0f, 1.0f, 1.0f); int tab_height = static_cast<int>(kScalingFactor * - gdk_pixbuf_get_height(pixbuf) - + renderer_->height() - kDragFrameBorderSize); cairo_rectangle(cairo_context, 0, tab_height, @@ -279,27 +279,22 @@ void DraggedTabGtk::SetContainerShapeMask(GdkPixbuf* pixbuf) { g_object_unref(pixmap); } -GdkPixbuf* DraggedTabGtk::PaintTab() { - SkBitmap bitmap = renderer_->PaintBitmap(); - return gfx::GdkPixbufFromSkBitmap(&bitmap); -} - // static gboolean DraggedTabGtk::OnExposeEvent(GtkWidget* widget, GdkEventExpose* event, DraggedTabGtk* dragged_tab) { - GdkPixbuf* pixbuf = dragged_tab->PaintTab(); + cairo_surface_t* surface = dragged_tab->renderer_->PaintToSurface(); if (gtk_util::IsScreenComposited()) { dragged_tab->SetContainerTransparency(); } else { - dragged_tab->SetContainerShapeMask(pixbuf); + dragged_tab->SetContainerShapeMask(surface); } // Only used when not attached. - int tab_height = static_cast<int>(kScalingFactor * - gdk_pixbuf_get_height(pixbuf)); int tab_width = static_cast<int>(kScalingFactor * - gdk_pixbuf_get_width(pixbuf)); + dragged_tab->renderer_->width()); + int tab_height = static_cast<int>(kScalingFactor * + dragged_tab->renderer_->height()); // Draw the render area. if (dragged_tab->backing_store_ && !dragged_tab->attached_) { @@ -341,12 +336,12 @@ gboolean DraggedTabGtk::OnExposeEvent(GtkWidget* widget, // Draw the tab. if (!dragged_tab->attached_) cairo_scale(cr, kScalingFactor, kScalingFactor); - gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); + cairo_set_source_surface(cr, surface, 0, 0); cairo_paint(cr); cairo_destroy(cr); - g_object_unref(pixbuf); + cairo_surface_destroy(surface); // We've already drawn the tab, so don't propagate the expose-event signal. return TRUE; diff --git a/chrome/browser/gtk/tabs/dragged_tab_gtk.h b/chrome/browser/gtk/tabs/dragged_tab_gtk.h index 0057705..839ce6b 100644 --- a/chrome/browser/gtk/tabs/dragged_tab_gtk.h +++ b/chrome/browser/gtk/tabs/dragged_tab_gtk.h @@ -105,11 +105,8 @@ class DraggedTabGtk : public AnimationDelegate { // Sets the shape mask for the container window to emulate a transparent // container window. This is used if compositing is not available for the // screen. - // |pixbuf| is the pixbuf for the tab only (not the render view). - void SetContainerShapeMask(GdkPixbuf* pixbuf); - - // Paints the tab. The returned pixbuf belongs to the caller. - GdkPixbuf* PaintTab(); + // |surface| represents the tab only (not the render view). + void SetContainerShapeMask(cairo_surface_t* surface); // expose-event handler that notifies when the tab needs to be redrawn. static gboolean OnExposeEvent(GtkWidget* widget, GdkEventExpose* event, diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc index 50502fc..501ecef 100644 --- a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc @@ -600,6 +600,12 @@ SkBitmap TabRendererGtk::PaintBitmap() { return canvas.ExtractBitmap(); } +cairo_surface_t* TabRendererGtk::PaintToSurface() { + gfx::Canvas canvas(width(), height(), false); + Paint(&canvas); + return cairo_surface_reference(cairo_get_target(canvas.beginPlatformPaint())); +} + void TabRendererGtk::SchedulePaint() { gtk_widget_queue_draw(tab_.get()); } diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.h b/chrome/browser/gtk/tabs/tab_renderer_gtk.h index 2544e6e9..3114f05 100644 --- a/chrome/browser/gtk/tabs/tab_renderer_gtk.h +++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.h @@ -128,6 +128,10 @@ class TabRendererGtk : public AnimationDelegate { // Paints the tab into a SkBitmap. virtual SkBitmap PaintBitmap(); + // Paints the tab, and keeps the result server-side. The returned surface must + // be freed with cairo_surface_destroy(). + virtual cairo_surface_t* PaintToSurface(); + // There is no PaintNow available, so the fastest we can do is schedule a // paint with the windowing system. virtual void SchedulePaint(); |