Commit 6230e206 authored by erg@google.com's avatar erg@google.com

Revert "Upload GdkPixbufs into cairo surfaces so they (hopefully) live on the X

server and have better performance. In the presence of XRender, let cairo do
things smarter."

Valgrind problems.

This reverts commit 03871714c3e5b39ee0f8369ecc2313c02fe0ca08 (r25814).

Review URL: http://codereview.chromium.org/200071

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25828 0039d316-1c4b-4281-b951-d872f2087c98
parent 20515f1c
......@@ -242,10 +242,6 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>,
// Save the modified bitmap at image_cache_[id].
virtual void SaveThemeBitmap(const std::string resource_name, int id);
// Clears the platform-specific caches. Do not call directly; it's called
// from ClearCaches().
virtual void FreePlatformCaches();
Profile* profile() { return profile_; }
// Subclasses may need us to not use the on-disk image cache. The GTK
......@@ -316,6 +312,10 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>,
// Frees generated images and clears the image cache.
void ClearCaches();
// Clears the platform-specific caches. Do not call directly; it's called
// from ClearCaches().
void FreePlatformCaches();
// Encode image at image_cache_[id] as PNG and write to disk.
bool WriteImagesToDisk();
......
......@@ -21,7 +21,6 @@
#include "chrome/browser/gtk/bookmark_tree_model.h"
#include "chrome/browser/gtk/bookmark_utils_gtk.h"
#include "chrome/browser/gtk/browser_window_gtk.h"
#include "chrome/browser/gtk/cairo_cached_surface.h"
#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/gtk_chrome_button.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
......@@ -906,9 +905,10 @@ gboolean BookmarkBarGtk::OnEventBoxExpose(GtkWidget* widget,
bar->window_->tabstrip()->GetTabStripOriginForWidget(widget);
GtkThemeProvider* theme_provider = bar->theme_provider_;
CairoCachedSurface* background = theme_provider->GetSurfaceNamed(
IDR_THEME_TOOLBAR, widget);
background->SetSource(cr, tabstrip_origin.x(), tabstrip_origin.y());
GdkPixbuf* toolbar_background = theme_provider->GetPixbufNamed(
IDR_THEME_TOOLBAR);
gdk_cairo_set_source_pixbuf(cr, toolbar_background, tabstrip_origin.x(),
tabstrip_origin.y());
// We tile the toolbar background in both directions.
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
cairo_rectangle(cr,
......
......@@ -20,7 +20,6 @@
#include "chrome/browser/encoding_menu_controller.h"
#include "chrome/browser/gtk/back_forward_button_gtk.h"
#include "chrome/browser/gtk/browser_window_gtk.h"
#include "chrome/browser/gtk/cairo_cached_surface.h"
#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/go_button_gtk.h"
#include "chrome/browser/gtk/gtk_chrome_button.h"
......@@ -542,9 +541,10 @@ gboolean BrowserToolbarGtk::OnAlignmentExpose(GtkWidget* widget,
gfx::Point tabstrip_origin =
toolbar->window_->tabstrip()->GetTabStripOriginForWidget(widget);
GtkThemeProvider* theme_provider = toolbar->theme_provider_;
CairoCachedSurface* background = theme_provider->GetSurfaceNamed(
IDR_THEME_TOOLBAR, widget);
background->SetSource(cr, tabstrip_origin.x(), tabstrip_origin.y());
GdkPixbuf* toolbar_background = theme_provider->GetPixbufNamed(
IDR_THEME_TOOLBAR);
gdk_cairo_set_source_pixbuf(cr, toolbar_background, tabstrip_origin.x(),
tabstrip_origin.y());
// We tile the toolbar background in both directions.
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
cairo_rectangle(cr,
......
......@@ -41,7 +41,6 @@
#include "chrome/browser/gtk/bookmark_manager_gtk.h"
#include "chrome/browser/gtk/browser_titlebar.h"
#include "chrome/browser/gtk/browser_toolbar_gtk.h"
#include "chrome/browser/gtk/cairo_cached_surface.h"
#include "chrome/browser/gtk/clear_browsing_data_dialog_gtk.h"
#include "chrome/browser/gtk/download_shelf_gtk.h"
#include "chrome/browser/gtk/edit_search_engine_dialog.h"
......@@ -340,11 +339,12 @@ gboolean OnCompactNavSpacerExpose(GtkWidget* widget,
// tab strip.
gfx::Point tabstrip_origin =
window->tabstrip()->GetTabStripOriginForWidget(widget);
GtkThemeProvider* theme_provider = GtkThemeProvider::GetFrom(
window->browser()->profile());
CairoCachedSurface* background = theme_provider->GetSurfaceNamed(
IDR_THEME_TOOLBAR, widget);
background->SetSource(cr, tabstrip_origin.x(), tabstrip_origin.y());
ThemeProvider* theme_provider =
window->browser()->profile()->GetThemeProvider();
GdkPixbuf* toolbar_background = theme_provider->GetPixbufNamed(
IDR_THEME_TOOLBAR);
gdk_cairo_set_source_pixbuf(cr, toolbar_background, tabstrip_origin.x(),
tabstrip_origin.y());
// We tile the toolbar background in both directions.
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
cairo_rectangle(cr,
......@@ -596,8 +596,8 @@ void BrowserWindowGtk::HandleKeyboardEvent(GdkEventKey* event) {
gboolean BrowserWindowGtk::OnCustomFrameExpose(GtkWidget* widget,
GdkEventExpose* event,
BrowserWindowGtk* window) {
GtkThemeProvider* theme_provider = GtkThemeProvider::GetFrom(
window->browser()->profile());
ThemeProvider* theme_provider =
window->browser()->profile()->GetThemeProvider();
// Draw the default background.
cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
......@@ -613,19 +613,18 @@ gboolean BrowserWindowGtk::OnCustomFrameExpose(GtkWidget* widget,
image_name = window->browser()->profile()->IsOffTheRecord() ?
IDR_THEME_FRAME_INCOGNITO_INACTIVE : IDR_THEME_FRAME_INACTIVE;
}
CairoCachedSurface* surface = theme_provider->GetSurfaceNamed(
image_name, widget);
surface->SetSource(cr, 0, 0);
GdkPixbuf* pixbuf = theme_provider->GetPixbufNamed(image_name);
gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
cairo_rectangle(cr, event->area.x, event->area.y,
event->area.width, event->area.height);
cairo_fill(cr);
if (theme_provider->HasCustomImage(IDR_THEME_FRAME_OVERLAY)) {
CairoCachedSurface* theme_overlay = theme_provider->GetSurfaceNamed(
GdkPixbuf* theme_overlay = theme_provider->GetPixbufNamed(
window->IsActive() ? IDR_THEME_FRAME_OVERLAY
: IDR_THEME_FRAME_OVERLAY_INACTIVE, widget);
theme_overlay->SetSource(cr, 0, 0);
: IDR_THEME_FRAME_OVERLAY_INACTIVE);
gdk_cairo_set_source_pixbuf(cr, theme_overlay, 0, 0);
cairo_paint(cr);
}
......@@ -655,20 +654,21 @@ gboolean BrowserWindowGtk::OnCustomFrameExpose(GtkWidget* widget,
void BrowserWindowGtk::DrawContentShadow(cairo_t* cr,
BrowserWindowGtk* window) {
// Draw the shadow above the toolbar. Tabs on the tabstrip will draw over us.
GtkThemeProvider* theme_provider = GtkThemeProvider::GetFrom(
window->browser()->profile());
ThemeProvider* theme_provider =
window->browser()->profile()->GetThemeProvider();
int left_x, top_y;
gtk_widget_translate_coordinates(window->content_vbox_,
GTK_WIDGET(window->window_), 0, 0, &left_x,
&top_y);
int width = window->content_vbox_->allocation.width;
CairoCachedSurface* top_center = theme_provider->GetSurfaceNamed(
IDR_CONTENT_TOP_CENTER, window->content_vbox_);
top_center->SetSource(cr, left_x, top_y - kContentShadowThickness);
GdkPixbuf* top_center =
theme_provider->GetPixbufNamed(IDR_CONTENT_TOP_CENTER);
gdk_cairo_set_source_pixbuf(cr, top_center,
left_x, top_y - kContentShadowThickness);
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
cairo_rectangle(cr, left_x, top_y - kContentShadowThickness, width,
top_center->Height());
gdk_pixbuf_get_height(top_center));
cairo_fill(cr);
// Only draw the rest of the shadow if the user has the custom frame enabled.
......@@ -680,10 +680,10 @@ void BrowserWindowGtk::DrawContentShadow(cairo_t* cr,
// corners extend to the base of the toolbar (one pixel above the dividing
// line).
int right_x = left_x + width;
CairoCachedSurface* top_left = theme_provider->GetSurfaceNamed(
IDR_CONTENT_TOP_LEFT_CORNER, window->content_vbox_);
top_left->SetSource(
cr, left_x - kContentShadowThickness, top_y - kContentShadowThickness);
GdkPixbuf* top_left =
theme_provider->GetPixbufNamed(IDR_CONTENT_TOP_LEFT_CORNER);
gdk_cairo_set_source_pixbuf(cr, top_left,
left_x - kContentShadowThickness, top_y - kContentShadowThickness);
// The toolbar is shorter in location bar only mode so clip the image to the
// height of the toolbar + the amount of shadow above the toolbar.
int top_corner_height =
......@@ -696,9 +696,10 @@ void BrowserWindowGtk::DrawContentShadow(cairo_t* cr,
cairo_fill(cr);
// Likewise, we crop off the left column of pixels for the top right corner.
CairoCachedSurface* top_right = theme_provider->GetSurfaceNamed(
IDR_CONTENT_TOP_RIGHT_CORNER, window->content_vbox_);
top_right->SetSource(cr, right_x - 1, top_y - kContentShadowThickness);
GdkPixbuf* top_right =
theme_provider->GetPixbufNamed(IDR_CONTENT_TOP_RIGHT_CORNER);
gdk_cairo_set_source_pixbuf(cr, top_right,
right_x - 1, top_y - kContentShadowThickness);
cairo_rectangle(cr,
right_x,
top_y - kContentShadowThickness,
......@@ -717,9 +718,9 @@ void BrowserWindowGtk::DrawContentShadow(cairo_t* cr,
// drawn by the bottom corners.
int side_height = bottom_y - side_y - 1;
if (side_height > 0) {
CairoCachedSurface* left = theme_provider->GetSurfaceNamed(
IDR_CONTENT_LEFT_SIDE, window->content_vbox_);
left->SetSource(cr, left_x - kContentShadowThickness, side_y);
GdkPixbuf* left = theme_provider->GetPixbufNamed(IDR_CONTENT_LEFT_SIDE);
gdk_cairo_set_source_pixbuf(cr, left,
left_x - kContentShadowThickness, side_y);
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
cairo_rectangle(cr,
left_x - kContentShadowThickness,
......@@ -728,9 +729,8 @@ void BrowserWindowGtk::DrawContentShadow(cairo_t* cr,
side_height);
cairo_fill(cr);
CairoCachedSurface* right = theme_provider->GetSurfaceNamed(
IDR_CONTENT_RIGHT_SIDE, window->content_vbox_);
right->SetSource(cr, right_x - 1, side_y);
GdkPixbuf* right = theme_provider->GetPixbufNamed(IDR_CONTENT_RIGHT_SIDE);
gdk_cairo_set_source_pixbuf(cr, right, right_x - 1, side_y);
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
cairo_rectangle(cr,
right_x,
......@@ -742,21 +742,24 @@ void BrowserWindowGtk::DrawContentShadow(cairo_t* cr,
// Draw the bottom corners. The bottom corners also draw the bottom row of
// pixels of the side shadows.
CairoCachedSurface* bottom_left = theme_provider->GetSurfaceNamed(
IDR_CONTENT_BOTTOM_LEFT_CORNER, window->content_vbox_);
bottom_left->SetSource(cr, left_x - kContentShadowThickness, bottom_y - 1);
GdkPixbuf* bottom_left =
theme_provider->GetPixbufNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER);
gdk_cairo_set_source_pixbuf(cr, bottom_left,
left_x - kContentShadowThickness, bottom_y - 1);
cairo_paint(cr);
CairoCachedSurface* bottom_right = theme_provider->GetSurfaceNamed(
IDR_CONTENT_BOTTOM_RIGHT_CORNER, window->content_vbox_);
bottom_right->SetSource(cr, right_x - 1, bottom_y - 1);
GdkPixbuf* bottom_right =
theme_provider->GetPixbufNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER);
gdk_cairo_set_source_pixbuf(cr, bottom_right,
right_x - 1, bottom_y - 1);
cairo_paint(cr);
// Finally, draw the bottom row. Since we don't overlap the contents, we clip
// the top row of pixels.
CairoCachedSurface* bottom = theme_provider->GetSurfaceNamed(
IDR_CONTENT_BOTTOM_CENTER, window->content_vbox_);
bottom->SetSource(cr, left_x + 1, bottom_y - 1);
GdkPixbuf* bottom =
theme_provider->GetPixbufNamed(IDR_CONTENT_BOTTOM_CENTER);
gdk_cairo_set_source_pixbuf(cr, bottom,
left_x + 1, bottom_y - 1);
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
cairo_rectangle(cr,
left_x + 1,
......
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/gtk/cairo_cached_surface.h"
#include "base/basictypes.h"
#include "base/logging.h"
CairoCachedSurface::CairoCachedSurface() : pixbuf_(NULL), surface_(NULL) {
}
CairoCachedSurface::~CairoCachedSurface() {
if (surface_)
cairo_surface_destroy(surface_);
if (pixbuf_)
g_object_unref(pixbuf_);
}
int CairoCachedSurface::Width() const {
return pixbuf_ ? gdk_pixbuf_get_width(pixbuf_) : -1;
}
int CairoCachedSurface::Height() const {
return pixbuf_ ? gdk_pixbuf_get_height(pixbuf_) : -1;
}
void CairoCachedSurface::UsePixbuf(GdkPixbuf* pixbuf) {
if (surface_) {
cairo_surface_destroy(surface_);
surface_ = NULL;
}
if (pixbuf)
g_object_ref(pixbuf);
if (pixbuf_)
g_object_unref(pixbuf_);
pixbuf_ = pixbuf;
}
void CairoCachedSurface::SetSource(cairo_t* cr, int x, int y) {
DCHECK(pixbuf_);
DCHECK(cr);
if (!surface_) {
// First time here since last UsePixbuf call. Generate the surface.
cairo_surface_t* target = cairo_get_target(cr);
surface_ = cairo_surface_create_similar(
target,
CAIRO_CONTENT_COLOR_ALPHA,
gdk_pixbuf_get_width(pixbuf_),
gdk_pixbuf_get_height(pixbuf_));
DCHECK(surface_);
DCHECK(cairo_surface_get_type(surface_) == CAIRO_SURFACE_TYPE_XLIB ||
cairo_surface_get_type(surface_) == CAIRO_SURFACE_TYPE_XCB);
cairo_t* copy_cr = cairo_create(surface_);
gdk_cairo_set_source_pixbuf(copy_cr, pixbuf_, 0, 0);
cairo_paint(copy_cr);
cairo_destroy(copy_cr);
}
cairo_set_source_surface(cr, surface_, x, y);
}
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_GTK_CAIRO_CACHED_SURFACE_H_
#define CHROME_BROWSER_GTK_CAIRO_CACHED_SURFACE_H_
#include <gtk/gtk.h>
// A helper class that takes a GdkPixbuf* and renders it to the screen. Unlike
// gdk_cairo_set_source_pixbuf(), CairoCachedSurface assumes that the pixbuf is
// immutable after UsePixbuf() is called and can be sent to the X server
// once. From then on, that cached version is used so we don't upload the same
// image each and every time we expose.
//
// Most cached surfaces are owned by the GtkThemeProvider, which associates
// them with a certain XDisplay. Some users of surfaces (CustomDrawButtonBase,
// for example) own their surfaces instead since they interact with the
// ResourceBundle instead of the GtkThemeProvider.
class CairoCachedSurface {
public:
CairoCachedSurface();
~CairoCachedSurface();
// Whether this CairoCachedSurface owns a GdkPixbuf.
bool valid() const {
return pixbuf_;
}
// The dimensions of the underlying pixbuf/surface. (or -1 if invalid.)
int Width() const;
int Height() const;
// Sets the pixbuf that we pass to cairo. Calling UsePixbuf() only derefs the
// current pixbuf and surface (if they exist). Actually transfering data to
// the X server occurs at SetSource() time. Calling UsePixbuf() should only
// be done once as it clears cached data from the X server.
void UsePixbuf(GdkPixbuf* pixbuf);
// Sets our pixbuf as the active surface starting at (x, y), uploading it in
// case we don't have an X backed surface cached.
void SetSource(cairo_t* cr, int x, int y);
// Raw access to the pixbuf. May be NULL. Used for a few gdk operations
// regarding window shaping.
GdkPixbuf* pixbuf() { return pixbuf_; }
private:
// The source pixbuf.
GdkPixbuf* pixbuf_;
// Our cached surface. This should be a xlib surface so the data lives on the
// server instead of on the client.
cairo_surface_t* surface_;
};
#endif // CHROME_BROWSER_GTK_CAIRO_CACHED_SURFACE_H_
......@@ -9,7 +9,6 @@
#include "app/theme_provider.h"
#include "base/basictypes.h"
#include "base/gfx/gtk_util.h"
#include "chrome/browser/gtk/cairo_cached_surface.h"
#include "chrome/browser/gtk/gtk_chrome_button.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
#include "chrome/common/gtk_util.h"
......@@ -26,10 +25,6 @@ CustomDrawButtonBase::CustomDrawButtonBase(GtkThemeProvider* theme_provider,
highlight_id_(highlight_id),
depressed_id_(depressed_id),
theme_provider_(theme_provider) {
for (int i = 0; i < (GTK_STATE_INSENSITIVE + 1); ++i)
surfaces_[i].reset(new CairoCachedSurface);
background_image_.reset(new CairoCachedSurface);
if (theme_provider) {
// Load images by pretending that we got a BROWSER_THEME_CHANGED
// notification.
......@@ -41,39 +36,34 @@ CustomDrawButtonBase::CustomDrawButtonBase(GtkThemeProvider* theme_provider,
} else {
// Load the button images from the resource bundle.
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
surfaces_[GTK_STATE_NORMAL]->UsePixbuf(
normal_id ? rb.GetRTLEnabledPixbufNamed(normal_id) : NULL);
surfaces_[GTK_STATE_ACTIVE]->UsePixbuf(
active_id ? rb.GetRTLEnabledPixbufNamed(active_id) : NULL);
surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf(
highlight_id ? rb.GetRTLEnabledPixbufNamed(highlight_id) : NULL);
surfaces_[GTK_STATE_SELECTED]->UsePixbuf(NULL);
surfaces_[GTK_STATE_INSENSITIVE]->UsePixbuf(
depressed_id ? rb.GetRTLEnabledPixbufNamed(depressed_id) : NULL);
pixbufs_[GTK_STATE_NORMAL] =
normal_id ? rb.GetRTLEnabledPixbufNamed(normal_id) : NULL;
pixbufs_[GTK_STATE_ACTIVE] =
active_id ? rb.GetRTLEnabledPixbufNamed(active_id) : NULL;
pixbufs_[GTK_STATE_PRELIGHT] =
highlight_id ? rb.GetRTLEnabledPixbufNamed(highlight_id) : NULL;
pixbufs_[GTK_STATE_SELECTED] = NULL;
pixbufs_[GTK_STATE_INSENSITIVE] =
depressed_id ? rb.GetRTLEnabledPixbufNamed(depressed_id) : NULL;
}
}
CustomDrawButtonBase::~CustomDrawButtonBase() {
}
int CustomDrawButtonBase::Width() const {
return surfaces_[0]->Width();
}
int CustomDrawButtonBase::Height() const {
return surfaces_[0]->Height();
if (background_image_) {
g_object_unref(background_image_);
background_image_ = NULL;
}
}
gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget, GdkEventExpose* e) {
CairoCachedSurface* pixbuf =
surfaces_[paint_override_ >= 0 ?
paint_override_ : GTK_WIDGET_STATE(widget)].get();
GdkPixbuf* pixbuf = pixbufs_[paint_override_ >= 0 ?
paint_override_ : GTK_WIDGET_STATE(widget)];
// Fall back to the default image if we don't have one for this state.
if (!pixbuf || !pixbuf->valid())
pixbuf = surfaces_[GTK_STATE_NORMAL].get();
if (!pixbuf)
pixbuf = pixbufs_[GTK_STATE_NORMAL];
if (!pixbuf || !pixbuf->valid())
if (!pixbuf)
return FALSE;
cairo_t* cairo_context = gdk_cairo_create(GDK_DRAWABLE(widget->window));
......@@ -81,16 +71,16 @@ gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget, GdkEventExpose* e) {
// The widget might be larger than the pixbuf. Paint the pixbuf flush with the
// start of the widget (left for LTR, right for RTL) and its bottom.
gfx::Rect bounds = gfx::Rect(0, 0, pixbuf->Width(), 0);
gfx::Rect bounds = gfx::Rect(0, 0, gdk_pixbuf_get_width(pixbuf), 0);
int x = gtk_util::MirroredLeftPointForRect(widget, bounds);
int y = widget->allocation.height - pixbuf->Height();
int y = widget->allocation.height - gdk_pixbuf_get_height(pixbuf);
if (background_image_->valid()) {
background_image_->SetSource(cairo_context, x, y);
if (background_image_) {
gdk_cairo_set_source_pixbuf(cairo_context, background_image_, x, y);
cairo_paint(cairo_context);
}
pixbuf->SetSource(cairo_context, x, y);
gdk_cairo_set_source_pixbuf(cairo_context, pixbuf, x, y);
cairo_paint(cairo_context);
cairo_destroy(cairo_context);
......@@ -100,16 +90,14 @@ gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget, GdkEventExpose* e) {
void CustomDrawButtonBase::SetBackground(SkColor color,
SkBitmap* image, SkBitmap* mask) {
if (!image || !mask) {
if (background_image_->valid()) {
background_image_->UsePixbuf(NULL);
if (background_image_) {
g_object_unref(background_image_);
background_image_ = NULL;
}
} else {
SkBitmap img = skia::ImageOperations::CreateButtonBackground(color,
*image, *mask);
GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&img);
background_image_->UsePixbuf(pixbuf);
g_object_unref(pixbuf);
background_image_ = gfx::GdkPixbufFromSkBitmap(&img);
}
}
......@@ -118,15 +106,15 @@ void CustomDrawButtonBase::Observe(NotificationType type,
DCHECK(theme_provider_);
DCHECK(NotificationType::BROWSER_THEME_CHANGED == type);
surfaces_[GTK_STATE_NORMAL]->UsePixbuf(normal_id_ ?
theme_provider_->GetRTLEnabledPixbufNamed(normal_id_) : NULL);
surfaces_[GTK_STATE_ACTIVE]->UsePixbuf(active_id_ ?
theme_provider_->GetRTLEnabledPixbufNamed(active_id_) : NULL);
surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf(highlight_id_ ?
theme_provider_->GetRTLEnabledPixbufNamed(highlight_id_) : NULL);
surfaces_[GTK_STATE_SELECTED]->UsePixbuf(NULL);
surfaces_[GTK_STATE_INSENSITIVE]->UsePixbuf(depressed_id_ ?
theme_provider_->GetRTLEnabledPixbufNamed(depressed_id_) : NULL);
pixbufs_[GTK_STATE_NORMAL] = normal_id_ ?
theme_provider_->GetRTLEnabledPixbufNamed(normal_id_) : NULL;
pixbufs_[GTK_STATE_ACTIVE] = active_id_ ?
theme_provider_->GetRTLEnabledPixbufNamed(active_id_) : NULL;
pixbufs_[GTK_STATE_PRELIGHT] = highlight_id_ ?
theme_provider_->GetRTLEnabledPixbufNamed(highlight_id_) : NULL;
pixbufs_[GTK_STATE_SELECTED] = NULL;
pixbufs_[GTK_STATE_INSENSITIVE] = depressed_id_ ?
theme_provider_->GetRTLEnabledPixbufNamed(depressed_id_) : NULL;
}
CustomDrawButton::CustomDrawButton(int normal_id, int active_id,
......@@ -223,8 +211,9 @@ void CustomDrawButton::SetBrowserTheme() {
gtk_widget_set_app_paintable(widget_.get(), FALSE);
gtk_widget_set_double_buffered(widget_.get(), TRUE);
} else {
gtk_widget_set_size_request(widget_.get(), button_base_.Width(),
button_base_.Height());
gtk_widget_set_size_request(widget_.get(),
gdk_pixbuf_get_width(button_base_.pixbufs(0)),
gdk_pixbuf_get_height(button_base_.pixbufs(0)));
gtk_widget_set_app_paintable(widget_.get(), TRUE);
// We effectively double-buffer by virtue of having only one image...
......
......@@ -16,7 +16,6 @@
#include "chrome/common/owned_widget_gtk.h"
#include "third_party/skia/include/core/SkBitmap.h"
class CairoCachedSurface;
class GtkThemeProvider;
// These classes implement two kinds of custom-drawn buttons. They're
......@@ -37,9 +36,7 @@ class CustomDrawButtonBase : public NotificationObserver {
~CustomDrawButtonBase();
// Returns the dimensions of the first surface.
int Width() const;
int Height() const;
GdkPixbuf* pixbufs(int i) const { return pixbufs_[i]; }
gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e);
......@@ -55,12 +52,12 @@ class CustomDrawButtonBase : public NotificationObserver {
const NotificationDetails& details);
private:
// We store one surface for each possible state of the button;
// We store one GdkPixbuf* for each possible state of the button;
// INSENSITIVE is the last available state;
scoped_ptr<CairoCachedSurface> surfaces_[GTK_STATE_INSENSITIVE + 1];
GdkPixbuf* pixbufs_[GTK_STATE_INSENSITIVE + 1];
// The background image.
scoped_ptr<CairoCachedSurface> background_image_;
GdkPixbuf* background_image_;
// If non-negative, the state to paint the button.
int paint_override_;
......
......@@ -13,7 +13,6 @@
#include "chrome/browser/profile.h"
#include "chrome/browser/find_bar_controller.h"
#include "chrome/browser/gtk/browser_window_gtk.h"
#include "chrome/browser/gtk/cairo_cached_surface.h"
#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
#include "chrome/browser/gtk/nine_box.h"
......@@ -763,13 +762,14 @@ gboolean FindBarGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e,
cairo_clip(cr);
gfx::Point tabstrip_origin =
bar->window_->tabstrip()->GetTabStripOriginForWidget(widget);
CairoCachedSurface* background = bar->theme_provider_->GetSurfaceNamed(
IDR_THEME_TOOLBAR, widget);
background->SetSource(cr, tabstrip_origin.x(), tabstrip_origin.y());
GdkPixbuf* background = bar->browser_->profile()->GetThemeProvider()->
GetPixbufNamed(IDR_THEME_TOOLBAR);
gdk_cairo_set_source_pixbuf(cr, background,
tabstrip_origin.x(), tabstrip_origin.y());
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
cairo_rectangle(cr, tabstrip_origin.x(), tabstrip_origin.y(),
e->area.x + e->area.width - tabstrip_origin.x(),
background->Height());
gdk_pixbuf_get_height(background));
cairo_fill(cr);
cairo_destroy(cr);
......
......@@ -36,7 +36,9 @@ GoButtonGtk::GoButtonGtk(LocationBarViewGtk* location_bar, Browser* browser)
go_(theme_provider_, IDR_GO, IDR_GO_P, IDR_GO_H, 0),
stop_(theme_provider_, IDR_STOP, IDR_STOP_P, IDR_STOP_H, 0),
widget_(gtk_chrome_button_new()) {
gtk_widget_set_size_request(widget_.get(), go_.Width(), go_.Height());
gtk_widget_set_size_request(widget_.get(),
gdk_pixbuf_get_width(go_.pixbufs(0)),
gdk_pixbuf_get_height(go_.pixbufs(0)));
gtk_widget_set_app_paintable(widget_.get(), TRUE);
// We effectively double-buffer by virtue of having only one image...
......@@ -243,7 +245,9 @@ void GoButtonGtk::UpdateThemeButtons() {
gtk_widget_set_app_paintable(widget_.get(), FALSE);
gtk_widget_set_double_buffered(widget_.get(), TRUE);
} else {
gtk_widget_set_size_request(widget_.get(), go_.Width(), go_.Height());
gtk_widget_set_size_request(widget_.get(),
gdk_pixbuf_get_width(go_.pixbufs(0)),
gdk_pixbuf_get_height(go_.pixbufs(0)));
gtk_widget_set_app_paintable(widget_.get(), TRUE);
// We effectively double-buffer by virtue of having only one image...
......
......@@ -9,7 +9,6 @@
#include "base/gfx/gtk_util.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/gtk/cairo_cached_surface.h"
#include "chrome/browser/gtk/gtk_chrome_button.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/notification_details.h"
......@@ -164,25 +163,6 @@ GdkColor GtkThemeProvider::GetBorderColor() {
return color;
}
CairoCachedSurface* GtkThemeProvider::GetSurfaceNamed(
int id, GtkWidget* widget_on_display) {
GdkDisplay* display = gtk_widget_get_display(widget_on_display);
CairoCachedSurfaceMap& surface_map = per_display_surfaces_[display];
// Check to see if we already have the pixbuf in the cache.
CairoCachedSurfaceMap::const_iterator found = surface_map.find(id);
if (found != surface_map.end())
return found->second;
GdkPixbuf* pixbuf = GetPixbufNamed(id);
CairoCachedSurface* surface = new CairoCachedSurface;
surface->UsePixbuf(pixbuf);
surface_map[id] = surface;
return surface;
}
void GtkThemeProvider::LoadThemePrefs() {
if (use_gtk_) {
LoadGtkValues();
......@@ -228,19 +208,6 @@ void GtkThemeProvider::SaveThemeBitmap(const std::string resource_name,
}
}
void GtkThemeProvider::FreePlatformCaches() {
BrowserThemeProvider::FreePlatformCaches();
for (PerDisplaySurfaceMap::iterator it = per_display_surfaces_.begin();
it != per_display_surfaces_.end(); ++it) {
for (CairoCachedSurfaceMap::iterator jt = it->second.begin();
jt != it->second.end(); ++jt) {
delete jt->second;
}
}
per_display_surfaces_.clear();
}
// static
void GtkThemeProvider::OnStyleSet(GtkWidget* widget,
GtkStyle* previous_style,
......
......@@ -5,7 +5,6 @@
#ifndef CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_
#define CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_
#include <map>
#include <string>
#include <vector>
......@@ -15,10 +14,8 @@
#include "skia/ext/skia_utils.h"
class CairoCachedSurface;
class Profile;
typedef struct _GdkDisplay GdkDisplay;
typedef struct _GtkStyle GtkStyle;
typedef struct _GtkWidget GtkWidget;
......@@ -70,11 +67,6 @@ class GtkThemeProvider : public BrowserThemeProvider,
GtkWidget* fake_window() { return fake_window_; }
GtkWidget* fake_label() { return fake_label_.get(); }
// Returns a CairoCachedSurface for a particular Display. CairoCachedSurfaces
// (hopefully) live on the X server, instead of the client so we don't have
// to send the image to the server on each expose.
CairoCachedSurface* GetSurfaceNamed(int id, GtkWidget* widget_on_display);
protected:
// Possibly creates a theme specific version of theme_toolbar_default.
// (minimally acceptable version right now, which is just a fill of the bg
......@@ -93,9 +85,6 @@ class GtkThemeProvider : public BrowserThemeProvider,
// the superclass.
virtual void SaveThemeBitmap(const std::string resource_name, int id);
// Additionally frees the CairoCachedSurfaces.
virtual void FreePlatformCaches();
// Handles signal from GTK that our theme has been changed.
static void OnStyleSet(GtkWidget* widget,
GtkStyle* previous_style,
......@@ -124,11 +113,6 @@ class GtkThemeProvider : public BrowserThemeProvider,
// A list of all GtkChromeButton instances. We hold on to these to notify
// them of theme changes.
std::vector<GtkWidget*> chrome_buttons_;
// Cairo surfaces for each GdkDisplay.
typedef std::map<int, CairoCachedSurface*> CairoCachedSurfaceMap;
typedef std::map<GdkDisplay*, CairoCachedSurfaceMap> PerDisplaySurfaceMap;
PerDisplaySurfaceMap per_display_surfaces_;
};
#endif // CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_
......@@ -24,8 +24,9 @@ ToolbarStarToggleGtk::ToolbarStarToggleGtk(BrowserToolbarGtk* host)
theme_provider_(GtkThemeProvider::GetFrom(host->profile())),
unstarred_(theme_provider_, IDR_STAR, IDR_STAR_P, IDR_STAR_H, IDR_STAR_D),
starred_(theme_provider_, IDR_STARRED, IDR_STARRED_P, IDR_STARRED_H, 0) {
gtk_widget_set_size_request(widget_.get(), unstarred_.Width(),
unstarred_.Height());
gtk_widget_set_size_request(widget_.get(),
gdk_pixbuf_get_width(unstarred_.pixbufs(0)),
gdk_pixbuf_get_height(unstarred_.pixbufs(0)));
gtk_widget_set_app_paintable(widget_.get(), TRUE);
// We effectively double-buffer by virtue of having only one image...
......@@ -130,8 +131,9 @@ void ToolbarStarToggleGtk::UpdateGTKButton() {
gtk_widget_set_app_paintable(widget_.get(), FALSE);
gtk_widget_set_double_buffered(widget_.get(), TRUE);
} else {
gtk_widget_set_size_request(widget_.get(), unstarred_.Width(),
unstarred_.Height());
gtk_widget_set_size_request(widget_.get(),
gdk_pixbuf_get_width(unstarred_.pixbufs(0)),
gdk_pixbuf_get_height(unstarred_.pixbufs(0)));
gtk_widget_set_app_paintable(widget_.get(), TRUE);
// We effectively double-buffer by virtue of having only one image...
......
......@@ -1250,8 +1250,6 @@
'browser/gtk/browser_window_factory_gtk.cc',
'browser/gtk/browser_window_gtk.cc',
'browser/gtk/browser_window_gtk.h',
'browser/gtk/cairo_cached_surface.cc',
'browser/gtk/cairo_cached_surface.h',
'browser/gtk/clear_browsing_data_dialog_gtk.cc',
'browser/gtk/clear_browsing_data_dialog_gtk.h',
'browser/gtk/constrained_window_gtk.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment