diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-23 23:04:23 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-23 23:04:23 +0000 |
commit | 3024338797b31cd0e0357878bcd5b084e4a8af69 (patch) | |
tree | cf20d1d15f3907bb625a7cd1e465bbc47118821e | |
parent | 218f45da1c19e775cf72f46cc72f1c624927fd93 (diff) | |
download | chromium_src-3024338797b31cd0e0357878bcd5b084e4a8af69.zip chromium_src-3024338797b31cd0e0357878bcd5b084e4a8af69.tar.gz chromium_src-3024338797b31cd0e0357878bcd5b084e4a8af69.tar.bz2 |
Canvas refactoring part 2.
- Rename Canvas to CanvasSkia.
- Create a subclass Canvas that inherits from CanvasSkia for compatibility.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2862025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50664 0039d316-1c4b-4281-b951-d872f2087c98
50 files changed, 351 insertions, 299 deletions
diff --git a/build/common.gypi b/build/common.gypi index afc6e29..51a8b51 100644 --- a/build/common.gypi +++ b/build/common.gypi @@ -584,11 +584,6 @@ }, }, }], - # Though Skia is conceptually shared by Linux and Windows, - # the only _skia files in our tree are Linux-specific. - ['OS!="linux" and OS!="freebsd" and OS!="openbsd"', { - 'sources/': [ ['exclude', '_skia\\.cc$'] ], - }], ['chromeos!=1', { 'sources/': [ ['exclude', '_chromeos\\.cc$'] ] }], diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc index 2795e6e..55b7530 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc @@ -44,6 +44,7 @@ #include "chrome/common/notification_service.h" #include "googleurl/src/url_util.h" #include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "grit/generated_resources.h" #include "net/base/escape.h" #include "skia/ext/skia_utils_win.h" @@ -2176,7 +2177,7 @@ void AutocompleteEditViewWin::DrawSlashForInsecureScheme( // Create a canvas as large as |scheme_rect| to do our drawing, and initialize // it to fully transparent so any antialiasing will look nice when painted // atop the edit. - gfx::Canvas canvas(scheme_rect.Width(), scheme_rect.Height(), false); + gfx::CanvasSkia canvas(scheme_rect.Width(), scheme_rect.Height(), false); canvas.getDevice()->accessBitmap(true).eraseARGB(0, 0, 0, 0); // Calculate the start and end of the stroke, which are just the lower left diff --git a/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm b/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm index 964a76e..9f50222 100644 --- a/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm +++ b/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm @@ -12,7 +12,7 @@ #import "chrome/browser/cocoa/browser_window_controller.h" #import "chrome/browser/cocoa/themed_window.h" #include "chrome/browser/ntp_background_util.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" const CGFloat kBorderRadius = 3.0; @@ -54,7 +54,7 @@ const CGFloat kBorderRadius = 3.0; // Draw the background. { - // CanvasPaint draws to the NSGraphicsContext during its destructor, so + // CanvasSkiaPaint draws to the NSGraphicsContext during its destructor, so // explicitly scope this. // // Paint the entire bookmark bar, even if the damage rect is much smaller @@ -66,7 +66,7 @@ const CGFloat kBorderRadius = 3.0; // already repainting the rest of the bookmark bar below without setting a // clip area, anyway. Also, the only time we weren't asked to redraw the // whole bookmark bar is when the find bar is drawn over it. - gfx::CanvasPaint canvas(bounds, true); + gfx::CanvasSkiaPaint canvas(bounds, true); gfx::Rect area(0, 0, NSWidth(bounds), NSHeight(bounds)); NtpBackgroundUtil::PaintBackgroundDetachedMode(themeProvider, &canvas, diff --git a/chrome/browser/cocoa/download_item_cell.mm b/chrome/browser/cocoa/download_item_cell.mm index 6e14a27..c9843aba 100644 --- a/chrome/browser/cocoa/download_item_cell.mm +++ b/chrome/browser/cocoa/download_item_cell.mm @@ -15,7 +15,7 @@ #include "chrome/browser/download/download_item_model.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/download_util.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "grit/theme_resources.h" #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" @@ -562,7 +562,7 @@ NSGradient* BackgroundTheme::GetNSGradient(int id) const { // Draw progress disk { - // CanvasPaint draws its content to the current NSGraphicsContext in its + // CanvasSkiaPaint draws its content to the current NSGraphicsContext in its // destructor, which needs to be invoked before the icon is drawn below - // hence this nested block. @@ -575,7 +575,7 @@ NSGradient* BackgroundTheme::GetNSGradient(int id) const { download_util::kSmallProgressIconSize, download_util::kSmallProgressIconSize); - gfx::CanvasPaint canvas(dirtyRect, false); + gfx::CanvasSkiaPaint canvas(dirtyRect, false); canvas.set_composite_alpha(true); if (completionAnimation_.get()) { if ([completionAnimation_ isAnimating]) { diff --git a/chrome/browser/cocoa/extensions/browser_action_button.mm b/chrome/browser/cocoa/extensions/browser_action_button.mm index 914f11d..0a7dc46 100644 --- a/chrome/browser/cocoa/extensions/browser_action_button.mm +++ b/chrome/browser/cocoa/extensions/browser_action_button.mm @@ -19,7 +19,7 @@ #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_source.h" #include "chrome/common/notification_type.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "gfx/rect.h" #include "gfx/size.h" #include "skia/ext/skia_utils_mac.h" @@ -326,7 +326,7 @@ class ExtensionImageTrackerBridge : public NotificationObserver, } - (void)drawBadgeWithinFrame:(NSRect)frame { - gfx::CanvasPaint canvas(frame, false); + gfx::CanvasSkiaPaint canvas(frame, false); canvas.set_composite_alpha(true); gfx::Rect boundingRect(NSRectToCGRect(frame)); extensionAction_->PaintBadge(&canvas, boundingRect, tabId_); diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index f5c9f53..b4a6d77 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -41,7 +41,7 @@ #include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "gfx/gtk_util.h" #include "grit/app_resources.h" #include "grit/generated_resources.h" @@ -1267,7 +1267,7 @@ gboolean BookmarkBarGtk::OnEventBoxExpose(GtkWidget* widget, gfx::Size tab_contents_size; if (!GetTabContentsSize(&tab_contents_size)) return FALSE; - gfx::CanvasPaint canvas(event, true); + gfx::CanvasSkiaPaint canvas(event, true); gfx::Rect area = GTK_WIDGET_NO_WINDOW(widget) ? gfx::Rect(widget->allocation) : diff --git a/chrome/browser/gtk/bookmark_utils_gtk.cc b/chrome/browser/gtk/bookmark_utils_gtk.cc index 4c4fb04..3b5c3b5 100644 --- a/chrome/browser/gtk/bookmark_utils_gtk.cc +++ b/chrome/browser/gtk/bookmark_utils_gtk.cc @@ -16,7 +16,7 @@ #include "chrome/browser/gtk/gtk_theme_provider.h" #include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/profile.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "gfx/font.h" #include "gfx/gtk_util.h" @@ -135,7 +135,7 @@ gboolean OnDragIconExpose(GtkWidget* sender, cairo_destroy(cr); // Paint the title text. - gfx::CanvasPaint canvas(event, false); + gfx::CanvasSkiaPaint canvas(event, false); int text_x = gdk_pixbuf_get_width(data->favicon) + kBarButtonPadding; int text_width = sender->allocation.width - text_x; ResourceBundle& rb = ResourceBundle::GetSharedInstance(); diff --git a/chrome/browser/gtk/browser_actions_toolbar_gtk.cc b/chrome/browser/gtk/browser_actions_toolbar_gtk.cc index 2e023b2..f19c720 100644 --- a/chrome/browser/gtk/browser_actions_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_actions_toolbar_gtk.cc @@ -30,7 +30,7 @@ #include "chrome/common/notification_service.h" #include "chrome/common/notification_source.h" #include "chrome/common/notification_type.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "gfx/gtk_util.h" #include "grit/app_resources.h" @@ -278,7 +278,7 @@ class BrowserActionButton : public NotificationObserver, if (action->GetBadgeText(tab_id).empty()) return FALSE; - gfx::CanvasPaint canvas(event, false); + gfx::CanvasSkiaPaint canvas(event, false); gfx::Rect bounding_rect(widget->allocation); action->PaintBadge(&canvas, bounding_rect, tab_id); return FALSE; diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index a3cd9cd..6653b22 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -48,7 +48,7 @@ #include "chrome/common/notification_type.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "gfx/gtk_util.h" #include "gfx/skbitmap_operations.h" #include "grit/chromium_strings.h" @@ -799,7 +799,7 @@ gboolean BrowserToolbarGtk::OnAppMenuImageExpose(GtkWidget* sender, } // Draw the chrome app menu icon onto the canvas. - gfx::CanvasPaint canvas(expose, false); + gfx::CanvasSkiaPaint canvas(expose, false); int x_offset = base::i18n::IsRTL() ? sender->allocation.width - kUpgradeDotOffset - badge.width() : kUpgradeDotOffset; diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc index f64b30f..1a4c9b9 100644 --- a/chrome/browser/gtk/download_item_gtk.cc +++ b/chrome/browser/gtk/download_item_gtk.cc @@ -27,7 +27,7 @@ #include "chrome/browser/gtk/menu_gtk.h" #include "chrome/browser/gtk/nine_box.h" #include "chrome/common/notification_service.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "gfx/color_utils.h" #include "gfx/font.h" #include "gfx/skia_utils_gtk.h" @@ -789,7 +789,7 @@ void DownloadItemGtk::OnClick(GtkWidget* widget) { gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, GdkEventExpose* event) { // Create a transparent canvas. - gfx::CanvasPaint canvas(event, false); + gfx::CanvasSkiaPaint canvas(event, false); if (complete_animation_.get()) { if (complete_animation_->is_animating()) { download_util::PaintDownloadComplete(&canvas, diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index 421bd46..3972ab6 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -49,7 +49,7 @@ #include "chrome/common/notification_service.h" #include "chrome/common/page_transition_types.h" #include "chrome/common/pref_names.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "gfx/font.h" #include "gfx/gtk_util.h" #include "grit/generated_resources.h" @@ -1395,7 +1395,7 @@ gboolean LocationBarViewGtk::PageActionViewGtk::OnExposeEvent( if (badge_text.empty()) return FALSE; - gfx::CanvasPaint canvas(event, false); + gfx::CanvasSkiaPaint canvas(event, false); gfx::Rect bounding_rect(widget->allocation); page_action_->PaintBadge(&canvas, bounding_rect, tab_id); return FALSE; diff --git a/chrome/browser/gtk/tabs/dragged_tab_gtk.cc b/chrome/browser/gtk/tabs/dragged_tab_gtk.cc index 426ab43..52cb110 100644 --- a/chrome/browser/gtk/tabs/dragged_tab_gtk.cc +++ b/chrome/browser/gtk/tabs/dragged_tab_gtk.cc @@ -18,7 +18,6 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tabs/tab_strip_model.h" -#include "gfx/canvas_paint.h" #include "gfx/gtk_util.h" #include "third_party/skia/include/core/SkShader.h" diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc index df16d83..7ab29e6 100644 --- a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc @@ -19,7 +19,7 @@ #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/notification_service.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "gfx/favicon_size.h" #include "gfx/skbitmap_operations.h" #include "grit/app_resources.h" @@ -361,7 +361,7 @@ void TabRendererGtk::PaintFavIconArea(GdkEventExpose* event) { event->area.y = y() + favicon_bounds_.y(); event->area.width = favicon_bounds_.width(); event->area.height = favicon_bounds_.height(); - gfx::CanvasPaint canvas(event, false); + gfx::CanvasSkiaPaint canvas(event, false); // The actual paint methods expect 0, 0 to be the tab top left (see // PaintTab). @@ -767,7 +767,7 @@ SkBitmap* TabRendererGtk::GetMaskedBitmap(const SkBitmap* mask, } void TabRendererGtk::PaintTab(GdkEventExpose* event) { - gfx::CanvasPaint canvas(event, false); + gfx::CanvasSkiaPaint canvas(event, false); if (canvas.is_empty()) return; diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc index 9c4019e..a05105a 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc @@ -22,7 +22,6 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" -#include "gfx/canvas_paint.h" #include "gfx/gtk_util.h" #include "gfx/point.h" #include "grit/app_resources.h" diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.cc b/chrome/browser/renderer_host/render_widget_host_view_win.cc index 5090b38..06292e5 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_win.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc @@ -31,6 +31,7 @@ #include "chrome/common/plugin_messages.h" #include "chrome/common/render_messages.h" #include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "gfx/gdi_util.h" #include "gfx/rect.h" #include "grit/webkit_resources.h" @@ -235,7 +236,7 @@ BOOL CALLBACK DetachPluginWindowsCallback(HWND window, LPARAM param) { void DrawDeemphasized(const gfx::Rect& paint_rect, HDC backing_store_dc, HDC paint_dc) { - gfx::Canvas canvas(paint_rect.width(), paint_rect.height(), true); + gfx::CanvasSkia canvas(paint_rect.width(), paint_rect.height(), true); HDC dc = canvas.beginPlatformPaint(); BitBlt(dc, 0, @@ -685,7 +686,7 @@ void RenderWidgetHostViewWin::DrawResizeCorner(const gfx::Rect& paint_rect, if (!paint_rect.Intersect(resize_corner_rect).IsEmpty()) { SkBitmap* bitmap = ResourceBundle::GetSharedInstance(). GetBitmapNamed(IDR_TEXTAREA_RESIZER); - gfx::Canvas canvas(bitmap->width(), bitmap->height(), false); + gfx::CanvasSkia canvas(bitmap->width(), bitmap->height(), false); canvas.getDevice()->accessBitmap(true).eraseARGB(0, 0, 0, 0); int x = resize_corner_rect.x() + resize_corner_rect.width() - bitmap->width(); @@ -999,9 +1000,9 @@ void RenderWidgetHostViewWin::OnPaint(HDC unused_dc) { void RenderWidgetHostViewWin::DrawBackground(const RECT& dirty_rect, CPaintDC* dc) { if (!background_.empty()) { - gfx::Canvas canvas(dirty_rect.right - dirty_rect.left, - dirty_rect.bottom - dirty_rect.top, - true); // opaque + gfx::CanvasSkia canvas(dirty_rect.right - dirty_rect.left, + dirty_rect.bottom - dirty_rect.top, + true); // opaque canvas.TranslateInt(-dirty_rect.left, -dirty_rect.top); const RECT& dc_rect = dc->m_ps.rcPaint; diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc index 8f9334f2e..df9565c 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc @@ -16,6 +16,7 @@ #include "chrome/browser/views/bubble_border.h" #include "chrome/browser/views/location_bar/location_bar_view.h" #include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "gfx/color_utils.h" #include "gfx/insets.h" #include "gfx/path.h" @@ -764,6 +765,7 @@ void AutocompletePopupContentsView::Paint(gfx::Canvas* canvas) { // Instead, we paint all our children into a second canvas and use that as a // shader to fill a path representing the round-rect clipping region. This // yields a nice anti-aliased edge. + // TODO(beng): Convert to CanvasSkia gfx::Canvas contents_canvas(width(), height(), true); contents_canvas.drawColor(GetColor(NORMAL, BACKGROUND)); View::PaintChildren(&contents_canvas); diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc index 1723f9f..0b97017 100644 --- a/chrome/browser/views/bookmark_bar_view.cc +++ b/chrome/browser/views/bookmark_bar_view.cc @@ -38,6 +38,7 @@ #include "chrome/common/page_transition_types.h" #include "chrome/common/pref_names.h" #include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "grit/app_resources.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -1110,10 +1111,11 @@ void BookmarkBarView::WriteDragData(View* sender, for (int i = 0; i < GetBookmarkButtonCount(); ++i) { if (sender == GetBookmarkButton(i)) { views::TextButton* button = GetBookmarkButton(i); + // TODO(beng): convert to CanvasSkia gfx::Canvas canvas(button->width(), button->height(), false); button->Paint(&canvas, true); - drag_utils::SetDragImageOnDataObject(canvas, button->size(), press_pt, - data); + drag_utils::SetDragImageOnDataObject(canvas, button->size(), + press_pt, data); WriteDragData(model_->GetBookmarkBarNode()->GetChild(i), data); return; } diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc index 18eef4e..e472de6 100644 --- a/chrome/browser/views/browser_actions_container.cc +++ b/chrome/browser/views/browser_actions_container.cc @@ -31,6 +31,7 @@ #include "chrome/common/notification_type.h" #include "chrome/common/pref_names.h" #include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "grit/app_resources.h" #include "grit/generated_resources.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -322,13 +323,15 @@ gfx::Canvas* BrowserActionView::GetIconWithBadge() { if (icon.isNull()) icon = button_->default_icon(); + // TODO(beng): Convert to CanvasSkia gfx::Canvas* canvas = new gfx::Canvas(icon.width(), icon.height(), false); canvas->DrawBitmapInt(icon, 0, 0); if (tab_id >= 0) { gfx::Rect bounds = gfx::Rect(icon.width(), icon.height() + kControlVertOffset); - button_->extension()->browser_action()->PaintBadge(canvas, bounds, tab_id); + button_->extension()->browser_action()->PaintBadge(canvas, + bounds, tab_id); } return canvas; diff --git a/chrome/browser/views/browser_actions_container.h b/chrome/browser/views/browser_actions_container.h index 1b7dbed..ce7ed70 100644 --- a/chrome/browser/views/browser_actions_container.h +++ b/chrome/browser/views/browser_actions_container.h @@ -34,6 +34,10 @@ class ExtensionPopup; class PrefService; class Profile; +namespace gfx { +class CanvasSkia; +} + namespace views { class Menu2; } diff --git a/chrome/browser/views/extensions/browser_action_overflow_menu_controller.cc b/chrome/browser/views/extensions/browser_action_overflow_menu_controller.cc index 894f159..0b66c13 100644 --- a/chrome/browser/views/extensions/browser_action_overflow_menu_controller.cc +++ b/chrome/browser/views/extensions/browser_action_overflow_menu_controller.cc @@ -34,7 +34,7 @@ BrowserActionOverflowMenuController::BrowserActionOverflowMenuController( size_t command_id = 1; // Menu id 0 is reserved, start with 1. for (size_t i = start_index; i < views_->size(); ++i) { BrowserActionView* view = (*views_)[i]; - scoped_ptr<gfx::Canvas> canvas(view->GetIconWithBadge()); + scoped_ptr<gfx::CanvasSkia> canvas(view->GetIconWithBadge()); menu_->AppendMenuItemWithIcon( command_id, UTF8ToWide(view->button()->extension()->name()), diff --git a/chrome/browser/views/infobars/extension_infobar.cc b/chrome/browser/views/infobars/extension_infobar.cc index 4f0f857..6a6be3f 100644 --- a/chrome/browser/views/infobars/extension_infobar.cc +++ b/chrome/browser/views/infobars/extension_infobar.cc @@ -13,7 +13,7 @@ #include "chrome/browser/views/frame/browser_view.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_resource.h" -#include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "grit/theme_resources.h" #include "views/controls/button/menu_button.h" #include "views/controls/menu/menu_2.h" @@ -115,9 +115,10 @@ void ExtensionInfoBar::OnImageLoaded( SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); int image_size = Extension::EXTENSION_ICON_BITTY; - scoped_ptr<gfx::Canvas> canvas( - new gfx::Canvas(image_size + kDropArrowLeftMargin + drop_image->width(), - image_size, false)); + scoped_ptr<gfx::CanvasSkia> canvas( + new gfx::CanvasSkia( + image_size + kDropArrowLeftMargin + drop_image->width(), + image_size, false)); canvas->DrawBitmapInt(*icon, 0, 0, icon->width(), icon->height(), 0, 0, image_size, image_size, diff --git a/chrome/browser/views/sad_tab_view.cc b/chrome/browser/views/sad_tab_view.cc index 0e626d6..fbaa37d5 100644 --- a/chrome/browser/views/sad_tab_view.cc +++ b/chrome/browser/views/sad_tab_view.cc @@ -8,6 +8,7 @@ #include "app/resource_bundle.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "gfx/size.h" #include "gfx/skia_util.h" #include "grit/generated_resources.h" @@ -89,7 +90,7 @@ void SadTabView::Layout() { int title_height = title_font_->height(); title_bounds_.SetRect(title_x, title_y, title_width_, title_height); - gfx::Canvas cc(0, 0, true); + gfx::CanvasSkia cc(0, 0, true); int message_width = static_cast<int>(width() * kMessageSize); int message_height = 0; cc.SizeStringInt(message_, *message_font_, &message_width, &message_height, diff --git a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc index 55f2a32..b3e8194d 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc @@ -21,7 +21,7 @@ #include "chrome/browser/tab_contents/web_drag_dest_gtk.h" #include "chrome/browser/views/sad_tab_view.h" #include "chrome/browser/views/tab_contents/render_view_context_menu_views.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "gfx/point.h" #include "gfx/rect.h" #include "gfx/size.h" @@ -388,7 +388,7 @@ gboolean TabContentsViewGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { gfx::Rect bounds; GetBounds(&bounds, true); sad_tab_->SetBounds(gfx::Rect(0, 0, bounds.width(), bounds.height())); - gfx::CanvasPaint canvas(event); + gfx::CanvasSkiaPaint canvas(event); sad_tab_->ProcessPaint(&canvas); } return false; // False indicates other widgets should get the event as well. diff --git a/chrome/browser/views/tab_contents/tab_contents_view_win.cc b/chrome/browser/views/tab_contents/tab_contents_view_win.cc index 39190f0..0774fea 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_win.cc +++ b/chrome/browser/views/tab_contents/tab_contents_view_win.cc @@ -25,7 +25,7 @@ #include "chrome/browser/views/sad_tab_view.h" #include "chrome/browser/views/tab_contents/render_view_context_menu_views.h" #include "chrome/browser/views/tab_contents/tab_contents_drag_win.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "views/focus/view_storage.h" #include "views/screen.h" #include "views/widget/root_view.h" @@ -392,7 +392,7 @@ void TabContentsViewWin::OnPaint(HDC junk_dc) { CRect cr; GetClientRect(&cr); sad_tab_->SetBounds(gfx::Rect(cr)); - gfx::CanvasPaint canvas(GetNativeView(), true); + gfx::CanvasSkiaPaint canvas(GetNativeView(), true); sad_tab_->ProcessPaint(&canvas); return; } diff --git a/chrome/browser/views/tabs/dragged_tab_view.cc b/chrome/browser/views/tabs/dragged_tab_view.cc index f3148c6..e5c55a4 100644 --- a/chrome/browser/views/tabs/dragged_tab_view.cc +++ b/chrome/browser/views/tabs/dragged_tab_view.cc @@ -6,6 +6,7 @@ #include "chrome/browser/views/tabs/native_view_photobooth.h" #include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "third_party/skia/include/core/SkShader.h" #include "views/widget/widget.h" @@ -185,6 +186,7 @@ void DraggedTabView::PaintAttachedTab(gfx::Canvas* canvas) { void DraggedTabView::PaintDetachedView(gfx::Canvas* canvas) { gfx::Size ps = GetPreferredSize(); + // TODO(beng): Convert to CanvasSkia gfx::Canvas scale_canvas(ps.width(), ps.height(), false); SkBitmap& bitmap_device = const_cast<SkBitmap&>( scale_canvas.getTopPlatformDevice().accessBitmap(true)); diff --git a/chrome/browser/views/tabs/tab.cc b/chrome/browser/views/tabs/tab.cc index e4785be..afb7f6a 100644 --- a/chrome/browser/views/tabs/tab.cc +++ b/chrome/browser/views/tabs/tab.cc @@ -14,6 +14,7 @@ #include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/defaults.h" #include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "gfx/favicon_size.h" #include "gfx/font.h" #include "gfx/path.h" @@ -398,7 +399,7 @@ void Tab::PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas) { SkBitmap background_image = background_canvas.ExtractBitmap(); // Draw a radial gradient to hover_canvas. - gfx::Canvas hover_canvas(width(), height(), false); + gfx::CanvasSkia hover_canvas(width(), height(), false); int radius = kMiniTitleChangeGradientRadius; int x0 = width() + radius - kMiniTitleChangeInitialXOffset; int x1 = radius; diff --git a/chrome/browser/views/theme_helpers.cc b/chrome/browser/views/theme_helpers.cc index 82de958..41f6db5 100644 --- a/chrome/browser/views/theme_helpers.cc +++ b/chrome/browser/views/theme_helpers.cc @@ -9,7 +9,7 @@ #include <atltheme.h> #include "base/logging.h" -#include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "skia/ext/bitmap_platform_device_win.h" #include "third_party/skia/include/effects/SkGradientShader.h" @@ -23,7 +23,7 @@ void GetRebarGradientColors(int width, int x1, int x2, // those so calling code can use them to create gradient brushes for use in // rendering in other directions. - gfx::Canvas canvas(width, 1, true); + gfx::CanvasSkia canvas(width, 1, true); // Render the Rebar gradient into the DIB CTheme theme; diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index 3175922..c16908c 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -25,6 +25,7 @@ #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "gfx/skbitmap_operations.h" @@ -682,8 +683,8 @@ SkBitmap ToolbarView::GetAppMenuIcon() { return icon; // Draw the chrome app menu icon onto the canvas. - scoped_ptr<gfx::Canvas> canvas( - new gfx::Canvas(icon.width(), icon.height(), false)); + scoped_ptr<gfx::CanvasSkia> canvas( + new gfx::CanvasSkia(icon.width(), icon.height(), false)); canvas->DrawBitmapInt(icon, 0, 0); SkBitmap badge; diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc index 8b4068c..9fa30d1 100644 --- a/chrome/renderer/webplugin_delegate_proxy.cc +++ b/chrome/renderer/webplugin_delegate_proxy.cc @@ -30,7 +30,7 @@ #include "chrome/renderer/render_thread.h" #include "chrome/renderer/render_view.h" #include "gfx/blit.h" -#include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "gfx/native_widget_types.h" #include "gfx/size.h" #include "grit/generated_resources.h" @@ -1282,7 +1282,7 @@ void WebPluginDelegateProxy::PaintSadPlugin(WebKit::WebCanvas* native_context, // Make a temporary canvas for the background image. const int width = plugin_rect_.width(); const int height = plugin_rect_.height(); - gfx::Canvas canvas(width, height, false); + gfx::CanvasSkia canvas(width, height, false); #if defined(OS_MACOSX) // Flip the canvas, since the context expects flipped data. canvas.translate(0, height); diff --git a/gfx/canvas.h b/gfx/canvas.h index 53661db..589d77d 100644 --- a/gfx/canvas.h +++ b/gfx/canvas.h @@ -5,129 +5,27 @@ #ifndef GFX_CANVAS_H_ #define GFX_CANVAS_H_ -#include "base/basictypes.h" -#include "gfx/canvas_2.h" -#include "skia/ext/platform_canvas.h" - -#if defined(OS_POSIX) && !defined(OS_MACOSX) -typedef struct _GdkPixbuf GdkPixbuf; -#endif +#include "gfx/canvas_skia.h" namespace gfx { -// Canvas is a SkCanvas subclass that provides a number of methods for common -// operations used throughout an application built using base/gfx and app/gfx. -// -// All methods that take integer arguments (as is used throughout views) -// end with Int. If you need to use methods provided by the superclass -// you'll need to do a conversion. In particular you'll need to use -// macro SkIntToScalar(xxx), or if converting from a scalar to an integer -// SkScalarRound. -// -// A handful of methods in this class are overloaded providing an additional -// argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the -// source and destination colors are combined. Unless otherwise specified, -// the variant that does not take a SkXfermode::Mode uses a transfer mode -// of kSrcOver_Mode. -class Canvas : public skia::PlatformCanvas, - public Canvas2 { +// Temporary compatibility shim, remove once Canvas2->Canvas. +class Canvas : public CanvasSkia { public: - // Creates an empty Canvas. Callers must use initialize before using the - // canvas. - Canvas(); - - Canvas(int width, int height, bool is_opaque); - - virtual ~Canvas(); - - // Compute the size required to draw some text with the provided font. - // Attempts to fit the text with the provided width and height. Increases - // height and then width as needed to make the text fit. This method - // supports multiple lines. - static void SizeStringInt(const std::wstring& text, const gfx::Font& font, - int* width, int* height, int flags); - - // Returns the default text alignment to be used when drawing text on a - // gfx::Canvas based on the directionality of the system locale language. This - // function is used by gfx::Canvas::DrawStringInt when the text alignment is - // not specified. - // - // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or - // gfx::Canvas::TEXT_ALIGN_RIGHT. - static int DefaultCanvasTextAlignment(); - -#if defined(OS_POSIX) && !defined(OS_MACOSX) - // Draw the pixbuf in its natural size at (x, y). - void DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y); -#endif - -#ifdef OS_WIN // Only implemented on Windows for now. - // Draws text with a 1-pixel halo around it of the given color. It allows - // ClearType to be drawn to an otherwise transparenct bitmap for drag images. - // Drag images have only 1-bit of transparency, so we don't do any fancy - // blurring. - void DrawStringWithHalo(const std::wstring& text, - const gfx::Font& font, - const SkColor& text_color, - const SkColor& halo_color, - int x, int y, int w, int h, int flags); -#endif + Canvas(int width, int height, bool is_opaque) + : CanvasSkia(width, height, is_opaque) { + } + Canvas() : CanvasSkia() {} // Overridden from Canvas2: - virtual bool GetClipRect(gfx::Rect* clip_rect); - virtual bool ClipRectInt(int x, int y, int w, int h); - virtual bool IntersectsClipRectInt(int x, int y, int w, int h); - virtual void TranslateInt(int x, int y); - virtual void ScaleInt(int x, int y); - virtual void FillRectInt(int x, int y, int w, int h, - const SkPaint& paint); - virtual void FillRectInt(const SkColor& color, int x, int y, int w, - int h); - virtual void DrawRectInt(const SkColor& color, int x, int y, int w, - int h); - virtual void DrawRectInt(const SkColor& color, int x, int y, int w, int h, - SkXfermode::Mode mode); - virtual void DrawLineInt(const SkColor& color, int x1, int y1, int x2, - int y2); - virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y); - virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y, - const SkPaint& paint); - virtual void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, - int src_w, int src_h, int dest_x, int dest_y, - int dest_w, int dest_h, bool filter); - virtual void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, - int src_w, int src_h, int dest_x, int dest_y, - int dest_w, int dest_h, bool filter, - const SkPaint& paint); - virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, - const SkColor& color, int x, int y, int w, - int h); - virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, - const SkColor& color, - const gfx::Rect& display_rect); - virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, - const SkColor& color, int x, int y, int w, int h, - int flags); - virtual void DrawFocusRect(int x, int y, int width, int height); - virtual void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h); - virtual void TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, - int dest_x, int dest_y, int w, int h); - virtual SkBitmap ExtractBitmap() const; - virtual Canvas* AsCanvas(); + Canvas* AsCanvas() { + return this; + } private: -#if defined(OS_WIN) - // Draws text with the specified color, font and location. The text is - // aligned to the left, vertically centered, clipped to the region. If the - // text is too big, it is truncated and '...' is added to the end. - void DrawStringInt(const std::wstring& text, HFONT font, - const SkColor& color, int x, int y, int w, int h, - int flags); -#endif - DISALLOW_COPY_AND_ASSIGN(Canvas); }; -} // namespace gfx; +} #endif // GFX_CANVAS_H_ diff --git a/gfx/canvas.cc b/gfx/canvas_skia.cc index 28bc231..8fa763a 100644 --- a/gfx/canvas.cc +++ b/gfx/canvas_skia.cc @@ -8,17 +8,18 @@ #include "base/i18n/rtl.h" #include "base/logging.h" +#include "gfx/canvas.h" #include "gfx/font.h" #include "gfx/rect.h" #include "third_party/skia/include/core/SkShader.h" #if defined(OS_WIN) -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #endif namespace gfx { -bool Canvas::GetClipRect(gfx::Rect* r) { +bool CanvasSkia::GetClipRect(gfx::Rect* r) { SkRect clip; if (!getClipBounds(&clip)) { if (r) @@ -31,29 +32,29 @@ bool Canvas::GetClipRect(gfx::Rect* r) { return true; } -bool Canvas::ClipRectInt(int x, int y, int w, int h) { +bool CanvasSkia::ClipRectInt(int x, int y, int w, int h) { SkRect new_clip; new_clip.set(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), SkIntToScalar(y + h)); return clipRect(new_clip); } -bool Canvas::IntersectsClipRectInt(int x, int y, int w, int h) { +bool CanvasSkia::IntersectsClipRectInt(int x, int y, int w, int h) { SkRect clip; return getClipBounds(&clip) && clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), SkIntToScalar(y + h)); } -void Canvas::TranslateInt(int x, int y) { +void CanvasSkia::TranslateInt(int x, int y) { translate(SkIntToScalar(x), SkIntToScalar(y)); } -void Canvas::ScaleInt(int x, int y) { +void CanvasSkia::ScaleInt(int x, int y) { scale(SkIntToScalar(x), SkIntToScalar(y)); } -void Canvas::FillRectInt(const SkColor& color, int x, int y, int w, int h) { +void CanvasSkia::FillRectInt(const SkColor& color, int x, int y, int w, int h) { SkPaint paint; paint.setColor(color); paint.setStyle(SkPaint::kFill_Style); @@ -61,17 +62,17 @@ void Canvas::FillRectInt(const SkColor& color, int x, int y, int w, int h) { FillRectInt(x, y, w, h, paint); } -void Canvas::FillRectInt(int x, int y, int w, int h, const SkPaint& paint) { +void CanvasSkia::FillRectInt(int x, int y, int w, int h, const SkPaint& paint) { SkIRect rc = {x, y, x + w, y + h}; drawIRect(rc, paint); } -void Canvas::DrawRectInt(const SkColor& color, int x, int y, int w, int h) { +void CanvasSkia::DrawRectInt(const SkColor& color, int x, int y, int w, int h) { DrawRectInt(color, x, y, w, h, SkXfermode::kSrcOver_Mode); } -void Canvas::DrawRectInt(const SkColor& color, int x, int y, int w, int h, - SkXfermode::Mode mode) { +void CanvasSkia::DrawRectInt(const SkColor& color, int x, int y, int w, int h, + SkXfermode::Mode mode) { SkPaint paint; paint.setColor(color); paint.setStyle(SkPaint::kStroke_Style); @@ -85,7 +86,8 @@ void Canvas::DrawRectInt(const SkColor& color, int x, int y, int w, int h, drawIRect(rc, paint); } -void Canvas::DrawLineInt(const SkColor& color, int x1, int y1, int x2, int y2) { +void CanvasSkia::DrawLineInt(const SkColor& color, int x1, int y1, int x2, + int y2) { SkPaint paint; paint.setColor(color); paint.setStrokeWidth(SkIntToScalar(1)); @@ -93,7 +95,7 @@ void Canvas::DrawLineInt(const SkColor& color, int x1, int y1, int x2, int y2) { SkIntToScalar(y2), paint); } -void Canvas::DrawFocusRect(int x, int y, int width, int height) { +void CanvasSkia::DrawFocusRect(int x, int y, int width, int height) { // Create a 2D bitmap containing alternating on/off pixels - we do this // so that you never get two pixels of the same color around the edges // of the focus rect (this may mean that opposing edges of the rect may @@ -147,28 +149,28 @@ void Canvas::DrawFocusRect(int x, int y, int width, int height) { drawRect(rect, paint); } -void Canvas::DrawBitmapInt(const SkBitmap& bitmap, int x, int y) { +void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int x, int y) { drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y)); } -void Canvas::DrawBitmapInt(const SkBitmap& bitmap, int x, int y, - const SkPaint& paint) { +void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int x, int y, + const SkPaint& paint) { drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y), &paint); } -void Canvas::DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, - int src_w, int src_h, int dest_x, int dest_y, - int dest_w, int dest_h, - bool filter) { +void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, + int src_w, int src_h, int dest_x, int dest_y, + int dest_w, int dest_h, + bool filter) { SkPaint p; DrawBitmapInt(bitmap, src_x, src_y, src_w, src_h, dest_x, dest_y, dest_w, dest_h, filter, p); } -void Canvas::DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, - int src_w, int src_h, int dest_x, int dest_y, - int dest_w, int dest_h, - bool filter, const SkPaint& paint) { +void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, + int src_w, int src_h, int dest_x, int dest_y, + int dest_w, int dest_h, + bool filter, const SkPaint& paint) { DLOG_ASSERT(src_x + src_w < std::numeric_limits<int16_t>::max() && src_y + src_h < std::numeric_limits<int16_t>::max()); if (src_w <= 0 || src_h <= 0 || dest_w <= 0 || dest_h <= 0) { @@ -217,28 +219,29 @@ void Canvas::DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, drawRect(dest_rect, p); } -void Canvas::DrawStringInt(const std::wstring& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h) { +void CanvasSkia::DrawStringInt(const std::wstring& text, + const gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h) { DrawStringInt(text, font, color, x, y, w, h, - gfx::Canvas::DefaultCanvasTextAlignment()); + gfx::CanvasSkia::DefaultCanvasTextAlignment()); } -void Canvas::DrawStringInt(const std::wstring& text, - const gfx::Font& font, - const SkColor& color, - const gfx::Rect& display_rect) { +void CanvasSkia::DrawStringInt(const std::wstring& text, + const gfx::Font& font, + const SkColor& color, + const gfx::Rect& display_rect) { DrawStringInt(text, font, color, display_rect.x(), display_rect.y(), display_rect.width(), display_rect.height()); } -void Canvas::TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h) { +void CanvasSkia::TileImageInt(const SkBitmap& bitmap, int x, int y, int w, + int h) { TileImageInt(bitmap, 0, 0, x, y, w, h); } -void Canvas::TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, - int dest_x, int dest_y, int w, int h) { +void CanvasSkia::TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, + int dest_x, int dest_y, int w, int h) { if (!IntersectsClipRectInt(dest_x, dest_y, w, h)) return; @@ -260,7 +263,7 @@ void Canvas::TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, restore(); } -SkBitmap Canvas::ExtractBitmap() const { +SkBitmap CanvasSkia::ExtractBitmap() const { const SkBitmap& device_bitmap = getDevice()->accessBitmap(false); // Make a bitmap to return, and a canvas to draw into it. We don't just want @@ -271,12 +274,8 @@ SkBitmap Canvas::ExtractBitmap() const { return result; } -Canvas* Canvas::AsCanvas() { - return this; -} - // static -int Canvas::DefaultCanvasTextAlignment() { +int CanvasSkia::DefaultCanvasTextAlignment() { if (!base::i18n::IsRTL()) return gfx::Canvas::TEXT_ALIGN_LEFT; return gfx::Canvas::TEXT_ALIGN_RIGHT; @@ -295,9 +294,9 @@ Canvas2* Canvas2::CreateCanvas(int width, int height, bool is_opaque) { #if defined(OS_WIN) // TODO(beng): move to canvas_win.cc, etc. -class CanvasPaintWin : public CanvasPaint, public CanvasPaint2 { +class CanvasPaintWin : public CanvasSkiaPaint, public CanvasPaint2 { public: - CanvasPaintWin(gfx::NativeView view) : CanvasPaint(view) {} + CanvasPaintWin(gfx::NativeView view) : CanvasSkiaPaint(view) {} // Overridden from CanvasPaint2: virtual bool IsValid() const { diff --git a/gfx/canvas_skia.h b/gfx/canvas_skia.h new file mode 100644 index 0000000..9a976fd --- /dev/null +++ b/gfx/canvas_skia.h @@ -0,0 +1,135 @@ +// Copyright (c) 2010 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 GFX_CANVAS_SKIA_H_ +#define GFX_CANVAS_SKIA_H_ + +#include "base/basictypes.h" +#include "gfx/canvas_2.h" +#include "skia/ext/platform_canvas.h" + +#if defined(OS_POSIX) && !defined(OS_MACOSX) +typedef struct _GdkPixbuf GdkPixbuf; +#endif + +namespace gfx { + +class Canvas; + +// CanvasSkia is a SkCanvas subclass that provides a number of methods for +// common operations used throughout an application built using base/gfx and +// app/gfx. +// +// All methods that take integer arguments (as is used throughout views) +// end with Int. If you need to use methods provided by the superclass +// you'll need to do a conversion. In particular you'll need to use +// macro SkIntToScalar(xxx), or if converting from a scalar to an integer +// SkScalarRound. +// +// A handful of methods in this class are overloaded providing an additional +// argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the +// source and destination colors are combined. Unless otherwise specified, +// the variant that does not take a SkXfermode::Mode uses a transfer mode +// of kSrcOver_Mode. +class CanvasSkia : public skia::PlatformCanvas, + public Canvas2 { + public: + // Creates an empty Canvas. Callers must use initialize before using the + // canvas. + CanvasSkia(); + + CanvasSkia(int width, int height, bool is_opaque); + + virtual ~CanvasSkia(); + + // Compute the size required to draw some text with the provided font. + // Attempts to fit the text with the provided width and height. Increases + // height and then width as needed to make the text fit. This method + // supports multiple lines. + static void SizeStringInt(const std::wstring& text, const gfx::Font& font, + int* width, int* height, int flags); + + // Returns the default text alignment to be used when drawing text on a + // gfx::CanvasSkia based on the directionality of the system locale language. + // This function is used by gfx::Canvas::DrawStringInt when the text alignment + // is not specified. + // + // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or + // gfx::Canvas::TEXT_ALIGN_RIGHT. + static int DefaultCanvasTextAlignment(); + +#if defined(OS_POSIX) && !defined(OS_MACOSX) + // Draw the pixbuf in its natural size at (x, y). + void DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y); +#endif + +#ifdef OS_WIN // Only implemented on Windows for now. + // Draws text with a 1-pixel halo around it of the given color. It allows + // ClearType to be drawn to an otherwise transparenct bitmap for drag images. + // Drag images have only 1-bit of transparency, so we don't do any fancy + // blurring. + void DrawStringWithHalo(const std::wstring& text, + const gfx::Font& font, + const SkColor& text_color, + const SkColor& halo_color, + int x, int y, int w, int h, int flags); +#endif + + // Overridden from Canvas2: + virtual bool GetClipRect(gfx::Rect* clip_rect); + virtual bool ClipRectInt(int x, int y, int w, int h); + virtual bool IntersectsClipRectInt(int x, int y, int w, int h); + virtual void TranslateInt(int x, int y); + virtual void ScaleInt(int x, int y); + virtual void FillRectInt(int x, int y, int w, int h, + const SkPaint& paint); + virtual void FillRectInt(const SkColor& color, int x, int y, int w, + int h); + virtual void DrawRectInt(const SkColor& color, int x, int y, int w, + int h); + virtual void DrawRectInt(const SkColor& color, int x, int y, int w, int h, + SkXfermode::Mode mode); + virtual void DrawLineInt(const SkColor& color, int x1, int y1, int x2, + int y2); + virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y); + virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y, + const SkPaint& paint); + virtual void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, + int src_w, int src_h, int dest_x, int dest_y, + int dest_w, int dest_h, bool filter); + virtual void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, + int src_w, int src_h, int dest_x, int dest_y, + int dest_w, int dest_h, bool filter, + const SkPaint& paint); + virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, + const SkColor& color, int x, int y, int w, + int h); + virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, + const SkColor& color, + const gfx::Rect& display_rect); + virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, + const SkColor& color, int x, int y, int w, int h, + int flags); + virtual void DrawFocusRect(int x, int y, int width, int height); + virtual void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h); + virtual void TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, + int dest_x, int dest_y, int w, int h); + virtual SkBitmap ExtractBitmap() const; + + private: +#if defined(OS_WIN) + // Draws text with the specified color, font and location. The text is + // aligned to the left, vertically centered, clipped to the region. If the + // text is too big, it is truncated and '...' is added to the end. + void DrawStringInt(const std::wstring& text, HFONT font, + const SkColor& color, int x, int y, int w, int h, + int flags); +#endif + + DISALLOW_COPY_AND_ASSIGN(CanvasSkia); +}; + +} // namespace gfx; + +#endif // GFX_CANVAS_SKIA_H_ diff --git a/gfx/canvas_linux.cc b/gfx/canvas_skia_linux.cc index 3f658d4..59e0e29 100644 --- a/gfx/canvas_linux.cc +++ b/gfx/canvas_skia_linux.cc @@ -91,14 +91,14 @@ static void UpdateCairoFontOptions() { namespace gfx { -Canvas::Canvas(int width, int height, bool is_opaque) +CanvasSkia::CanvasSkia(int width, int height, bool is_opaque) : skia::PlatformCanvas(width, height, is_opaque) { } -Canvas::Canvas() : skia::PlatformCanvas() { +CanvasSkia::CanvasSkia() : skia::PlatformCanvas() { } -Canvas::~Canvas() { +CanvasSkia::~CanvasSkia() { } // Pass a width > 0 to force wrapping and elliding. @@ -168,9 +168,9 @@ static void SetupPangoLayout(PangoLayout* layout, } // static -void Canvas::SizeStringInt(const std::wstring& text, - const gfx::Font& font, - int* width, int* height, int flags) { +void CanvasSkia::SizeStringInt(const std::wstring& text, + const gfx::Font& font, + int* width, int* height, int flags) { int org_width = *width; cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); @@ -202,11 +202,11 @@ void Canvas::SizeStringInt(const std::wstring& text, cairo_surface_destroy(surface); } -void Canvas::DrawStringInt(const std::wstring& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h, - int flags) { +void CanvasSkia::DrawStringInt(const std::wstring& text, + const gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h, + int flags) { if (w <= 0 || h <= 0) return; @@ -255,7 +255,7 @@ void Canvas::DrawStringInt(const std::wstring& text, // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. } -void Canvas::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { +void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { if (!pixbuf) { NOTREACHED(); return; diff --git a/gfx/canvas_mac.mm b/gfx/canvas_skia_mac.mm index 87ff09b..29102fd 100644 --- a/gfx/canvas_mac.mm +++ b/gfx/canvas_skia_mac.mm @@ -14,20 +14,20 @@ namespace gfx { -Canvas::Canvas(int width, int height, bool is_opaque) +CanvasSkia::CanvasSkia(int width, int height, bool is_opaque) : skia::PlatformCanvas(width, height, is_opaque) { } -Canvas::Canvas() : skia::PlatformCanvas() { +CanvasSkia::CanvasSkia() : skia::PlatformCanvas() { } -Canvas::~Canvas() { +CanvasSkia::~CanvasSkia() { } // static -void Canvas::SizeStringInt(const std::wstring& text, - const gfx::Font& font, - int *width, int *height, int flags) { +void CanvasSkia::SizeStringInt(const std::wstring& text, + const gfx::Font& font, + int *width, int *height, int flags) { NSFont* native_font = font.nativeFont(); NSString* ns_string = base::SysWideToNSString(text); NSDictionary* attributes = @@ -38,9 +38,9 @@ void Canvas::SizeStringInt(const std::wstring& text, *height = font.height(); } -void Canvas::DrawStringInt(const std::wstring& text, const gfx::Font& font, - const SkColor& color, int x, int y, int w, int h, - int flags) { +void CanvasSkia::DrawStringInt(const std::wstring& text, const gfx::Font& font, + const SkColor& color, int x, int y, int w, int h, + int flags) { if (!IntersectsClipRectInt(x, y, w, h)) return; diff --git a/gfx/canvas_paint.h b/gfx/canvas_skia_paint.h index a11a693..4e6f768 100644 --- a/gfx/canvas_paint.h +++ b/gfx/canvas_skia_paint.h @@ -2,19 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef GFX_CANVAS_PAINT_H_ -#define GFX_CANVAS_PAINT_H_ +#ifndef GFX_CANVAS_SKIA_PAINT_H_ +#define GFX_CANVAS_SKIA_PAINT_H_ #include "gfx/canvas.h" #include "skia/ext/canvas_paint.h" -// Define a skia::CanvasPaint type that wraps our gfx::Canvas like the +// Define a gfx::CanvasSkiaPaint type that wraps our gfx::Canvas like the // skia::PlatformCanvasPaint wraps PlatformCanvas. namespace gfx { -typedef skia::CanvasPaintT<Canvas> CanvasPaint; +typedef skia::CanvasPaintT<Canvas> CanvasSkiaPaint; } // namespace gfx -#endif // GFX_CANVAS_PAINT_H_ +#endif // GFX_CANVAS_SKIA_PAINT_H_ diff --git a/gfx/canvas_win.cc b/gfx/canvas_skia_win.cc index 98c5f74..4177ef5 100644 --- a/gfx/canvas_win.cc +++ b/gfx/canvas_skia_win.cc @@ -42,7 +42,7 @@ int ComputeFormatFlags(int flags, const std::wstring& text) { if (!(flags & (gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::TEXT_ALIGN_RIGHT | gfx::Canvas::TEXT_ALIGN_LEFT))) { - flags |= gfx::Canvas::DefaultCanvasTextAlignment(); + flags |= gfx::CanvasSkia::DefaultCanvasTextAlignment(); } // horizontal alignment @@ -125,20 +125,20 @@ int ComputeFormatFlags(int flags, const std::wstring& text) { namespace gfx { -Canvas::Canvas(int width, int height, bool is_opaque) +CanvasSkia::CanvasSkia(int width, int height, bool is_opaque) : skia::PlatformCanvas(width, height, is_opaque) { } -Canvas::Canvas() : skia::PlatformCanvas() { +CanvasSkia::CanvasSkia() : skia::PlatformCanvas() { } -Canvas::~Canvas() { +CanvasSkia::~CanvasSkia() { } // static -void Canvas::SizeStringInt(const std::wstring& text, - const gfx::Font& font, - int* width, int* height, int flags) { +void CanvasSkia::SizeStringInt(const std::wstring& text, + const gfx::Font& font, + int* width, int* height, int flags) { // Clamp the max amount of text we'll measure to 2K. When the string is // actually drawn, it will be clipped to whatever size box is provided, and // the time to do that doesn't depend on the length being clipped off. @@ -173,9 +173,9 @@ void Canvas::SizeStringInt(const std::wstring& text, *height = r.bottom; } -void Canvas::DrawStringInt(const std::wstring& text, HFONT font, - const SkColor& color, int x, int y, int w, int h, - int flags) { +void CanvasSkia::DrawStringInt(const std::wstring& text, HFONT font, + const SkColor& color, int x, int y, int w, int h, + int flags) { if (!IntersectsClipRectInt(x, y, w, h)) return; @@ -208,10 +208,10 @@ void Canvas::DrawStringInt(const std::wstring& text, HFONT font, getTopPlatformDevice().makeOpaque(x, y, w, h); } -void Canvas::DrawStringInt(const std::wstring& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h, int flags) { +void CanvasSkia::DrawStringInt(const std::wstring& text, + const gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h, int flags) { DrawStringInt(text, font.hfont(), color, x, y, w, h, flags); } @@ -242,19 +242,19 @@ static bool pixelShouldGetHalo(const SkBitmap& bitmap, int x, int y, return false; } -void Canvas::DrawStringWithHalo(const std::wstring& text, - const gfx::Font& font, - const SkColor& text_color, - const SkColor& halo_color_in, - int x, int y, int w, int h, - int flags) { +void CanvasSkia::DrawStringWithHalo(const std::wstring& text, + const gfx::Font& font, + const SkColor& text_color, + const SkColor& halo_color_in, + int x, int y, int w, int h, + int flags) { // Some callers will have semitransparent halo colors, which we don't handle // (since the resulting image can have 1-bit transparency only). SkColor halo_color = halo_color_in | 0xFF000000; // Create a temporary buffer filled with the halo color. It must leave room // for the 1-pixel border around the text. - Canvas text_canvas(w + 2, h + 2, true); + CanvasSkia text_canvas(w + 2, h + 2, true); SkPaint bkgnd_paint; bkgnd_paint.setColor(halo_color); text_canvas.FillRectInt(0, 0, w + 2, h + 2, bkgnd_paint); diff --git a/gfx/gfx.gyp b/gfx/gfx.gyp index 54d6833..c0d4000 100644 --- a/gfx/gfx.gyp +++ b/gfx/gfx.gyp @@ -62,13 +62,14 @@ 'sources': [ 'blit.cc', 'blit.h', - 'canvas.cc', 'canvas.h', 'canvas_2.h', - 'canvas_linux.cc', - 'canvas_mac.mm', - 'canvas_paint.h', - 'canvas_win.cc', + 'canvas_skia.h', + 'canvas_skia.cc', + 'canvas_skia_linux.cc', + 'canvas_skia_mac.mm', + 'canvas_skia_paint.h', + 'canvas_skia_win.cc', 'codec/jpeg_codec.cc', 'codec/jpeg_codec.h', 'codec/png_codec.cc', @@ -79,7 +80,6 @@ 'font.h', 'font_gtk.cc', 'font_mac.mm', - 'font_skia.cc', 'font_win.cc', 'gfx_paths.cc', 'gfx_paths.h', @@ -123,6 +123,7 @@ '../build/linux/system.gyp:fontconfig', ], 'sources': [ + 'font_skia.cc', 'gtk_native_view_id_manager.cc', 'gtk_native_view_id_manager.h', 'gtk_util.cc', diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index d0adb838..de31f02 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -469,6 +469,7 @@ void MenuController::OnMouseDragged(SubmenuView* source, gfx::Point press_loc(press_pt_); View::ConvertPointToScreen(source->GetScrollViewContainer(), &press_loc); View::ConvertPointToView(NULL, item, &press_loc); + // TODO(beng): Convert to CanvasSkia gfx::Canvas canvas(item->width(), item->height(), false); item->Paint(&canvas, true); diff --git a/views/controls/menu/menu_win.cc b/views/controls/menu/menu_win.cc index b941788..5c976d5 100644 --- a/views/controls/menu/menu_win.cc +++ b/views/controls/menu/menu_win.cc @@ -13,7 +13,7 @@ #include "base/logging.h" #include "base/stl_util-inl.h" #include "base/string_util.h" -#include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "gfx/font.h" #include "gfx/rect.h" #include "views/accelerator.h" @@ -184,7 +184,7 @@ class MenuHostWindow : public app::WindowImpl { // Draw the icon after the label, otherwise it would be covered // by the label. if (data->icon.width() != 0 && data->icon.height() != 0) { - gfx::Canvas canvas(data->icon.width(), data->icon.height(), false); + gfx::CanvasSkia canvas(data->icon.width(), data->icon.height(), false); canvas.drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); canvas.DrawBitmapInt(data->icon, 0, 0); canvas.getTopPlatformDevice().drawToHDC(hDC, lpdis->rcItem.left + diff --git a/views/controls/menu/native_menu_win.cc b/views/controls/menu/native_menu_win.cc index 0881ab5..cc528e3 100644 --- a/views/controls/menu/native_menu_win.cc +++ b/views/controls/menu/native_menu_win.cc @@ -9,7 +9,7 @@ #include "base/keyboard_codes.h" #include "base/logging.h" #include "base/stl_util-inl.h" -#include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "gfx/font.h" #include "third_party/skia/include/core/SkBitmap.h" #include "views/accelerator.h" @@ -223,7 +223,7 @@ class NativeMenuWin::MenuHostWindow { // by the label. SkBitmap icon; if (data->native_menu_win->model_->GetIconAt(data->model_index, &icon)) { - gfx::Canvas canvas(icon.width(), icon.height(), false); + gfx::CanvasSkia canvas(icon.width(), icon.height(), false); canvas.drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); canvas.DrawBitmapInt(icon, 0, 0); canvas.getTopPlatformDevice().drawToHDC(dc, diff --git a/views/controls/table/native_table_win.cc b/views/controls/table/native_table_win.cc index d34856f..f0b0659 100644 --- a/views/controls/table/native_table_win.cc +++ b/views/controls/table/native_table_win.cc @@ -12,7 +12,7 @@ #include "app/table_model.h" #include "base/logging.h" #include "base/win_util.h" -#include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "gfx/favicon_size.h" #include "gfx/icon_util.h" #include "skia/ext/skia_utils_win.h" @@ -389,7 +389,7 @@ void NativeTableWin::CreateNativeControl() { // We create 2 phony images because we are going to switch images at every // refresh in order to force a refresh of the icon area (somehow the clip // rect does not include the icon). - gfx::Canvas canvas(kImageSize, kImageSize, false); + gfx::CanvasSkia canvas(kImageSize, kImageSize, false); // Make the background completely transparent. canvas.drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); HICON empty_icon = @@ -508,8 +508,8 @@ LRESULT NativeTableWin::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) { client_rect.top += content_offset_; // Make sure the region need to paint is visible. if (IntersectRect(&intersection, &icon_rect, &client_rect)) { - gfx::Canvas canvas(icon_rect.right - icon_rect.left, - icon_rect.bottom - icon_rect.top, false); + gfx::CanvasSkia canvas(icon_rect.right - icon_rect.left, + icon_rect.bottom - icon_rect.top, false); // It seems the state in nmcd.uItemState is not correct. // We'll retrieve it explicitly. diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc index 2363985..75425c2 100644 --- a/views/controls/table/table_view.cc +++ b/views/controls/table/table_view.cc @@ -834,7 +834,7 @@ HWND TableView::CreateNativeControl(HWND parent_container) { // We create 2 phony images because we are going to switch images at every // refresh in order to force a refresh of the icon area (somehow the clip // rect does not include the icon). - gfx::Canvas canvas(kImageSize, kImageSize, false); + gfx::CanvasSkia canvas(kImageSize, kImageSize, false); // Make the background completely transparent. canvas.drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); HICON empty_icon = @@ -1153,7 +1153,7 @@ void TableView::PaintAltText() { HDC dc = GetDC(GetNativeControlHWND()); gfx::Font font = GetAltTextFont(); gfx::Rect bounds = GetAltTextBounds(); - gfx::Canvas canvas(bounds.width(), bounds.height(), false); + gfx::CanvasSkia canvas(bounds.width(), bounds.height(), false); // Pad by 1 for halo. canvas.DrawStringWithHalo(alt_text_, font, SK_ColorDKGRAY, SK_ColorWHITE, 1, 1, bounds.width() - 2, bounds.height() - 2, @@ -1236,8 +1236,8 @@ LRESULT TableView::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) { client_rect.top += content_offset_; // Make sure the region need to paint is visible. if (IntersectRect(&intersection, &icon_rect, &client_rect)) { - gfx::Canvas canvas(icon_rect.right - icon_rect.left, - icon_rect.bottom - icon_rect.top, false); + gfx::CanvasSkia canvas(icon_rect.right - icon_rect.left, + icon_rect.bottom - icon_rect.top, false); // It seems the state in nmcd.uItemState is not correct. // We'll retrieve it explicitly. diff --git a/views/controls/textfield/gtk_views_entry.cc b/views/controls/textfield/gtk_views_entry.cc index 037e902d..a068009 100644 --- a/views/controls/textfield/gtk_views_entry.cc +++ b/views/controls/textfield/gtk_views_entry.cc @@ -5,7 +5,7 @@ #include "views/controls/textfield/gtk_views_entry.h" #include "base/utf_string_conversions.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "gfx/insets.h" #include "gfx/skia_utils_gtk.h" #include "views/controls/textfield/native_textfield_gtk.h" @@ -28,7 +28,7 @@ static gint gtk_views_entry_expose_event(GtkWidget *widget, if (host && event->window == entry->text_area && !host->textfield()->text_to_display_when_empty().empty() && g_utf8_strlen(gtk_entry_get_text(entry), -1) == 0) { - gfx::CanvasPaint canvas(event); + gfx::CanvasSkiaPaint canvas(event); if (!canvas.is_empty()) { gfx::Insets insets = views::NativeTextfieldGtk::GetEntryInnerBorder(entry); diff --git a/views/controls/textfield/gtk_views_textview.cc b/views/controls/textfield/gtk_views_textview.cc index e285ad9..da43d93 100644 --- a/views/controls/textfield/gtk_views_textview.cc +++ b/views/controls/textfield/gtk_views_textview.cc @@ -5,7 +5,7 @@ #include "views/controls/textfield/gtk_views_textview.h" #include "base/utf_string_conversions.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "gfx/insets.h" #include "gfx/skia_utils_gtk.h" #include "views/controls/textfield/native_textfield_gtk.h" @@ -43,7 +43,7 @@ static gint gtk_views_textview_expose_event(GtkWidget *widget, if (host && event->window == text_window && !host->textfield()->text_to_display_when_empty().empty() && gtk_text_iter_equal(&start, &end)) { - gfx::CanvasPaint canvas(event); + gfx::CanvasSkiaPaint canvas(event); if (!canvas.is_empty()) { gfx::Insets insets = views::NativeTextfieldGtk::GetTextViewInnerBorder(text_view); diff --git a/views/controls/tree/tree_view.cc b/views/controls/tree/tree_view.cc index b544abc..799d89a 100644 --- a/views/controls/tree/tree_view.cc +++ b/views/controls/tree/tree_view.cc @@ -13,8 +13,8 @@ #include "base/keyboard_codes.h" #include "base/stl_util-inl.h" #include "base/win_util.h" -#include "gfx/canvas.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia.h" +#include "gfx/canvas_skia_paint.h" #include "gfx/favicon_size.h" #include "gfx/icon_util.h" #include "gfx/point.h" @@ -688,7 +688,7 @@ HIMAGELIST TreeView::CreateImageList() { // IDR_FOLDER_CLOSED if they aren't already. if (model_images[i].width() != width || model_images[i].height() != height) { - gfx::Canvas canvas(width, height, false); + gfx::CanvasSkia canvas(width, height, false); // Make the background completely transparent. canvas.drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); @@ -739,16 +739,16 @@ LRESULT CALLBACK TreeView::TreeWndProc(HWND window, return 1; case WM_PAINT: { - gfx::CanvasPaint canvas(window); + gfx::CanvasSkiaPaint canvas(window); if (canvas.isEmpty()) return 0; HDC dc = canvas.beginPlatformPaint(); if (base::i18n::IsRTL()) { - // gfx::Canvas ends up configuring the DC with a mode of GM_ADVANCED. - // For some reason a graphics mode of ADVANCED triggers all the text - // to be mirrored when RTL. Set the mode back to COMPATIBLE and - // explicitly set the layout. Additionally SetWorldTransform and + // gfx::CanvasSkia ends up configuring the DC with a mode of + // GM_ADVANCED. For some reason a graphics mode of ADVANCED triggers + // all the text to be mirrored when RTL. Set the mode back to COMPATIBLE + // and explicitly set the layout. Additionally SetWorldTransform and // COMPATIBLE don't play nicely together. We need to use // SetViewportOrgEx when using a mode of COMPATIBLE. // diff --git a/views/drag_utils.cc b/views/drag_utils.cc index 73ecedb..8fbd79a 100644 --- a/views/drag_utils.cc +++ b/views/drag_utils.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "base/utf_string_conversions.h" #include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "gfx/font.h" #include "googleurl/src/gurl.h" #include "grit/app_resources.h" @@ -48,6 +49,7 @@ void SetURLAndDragImage(const GURL& url, button.SetBounds(0, 0, prefsize.width(), prefsize.height()); // Render the image. + // TODO(beng): Convert to CanvasSkia gfx::Canvas canvas(prefsize.width(), prefsize.height(), false); button.Paint(&canvas, true); SetDragImageOnDataObject(canvas, prefsize, @@ -68,6 +70,7 @@ void CreateDragImageForFile(const FilePath::StringType& file_name, // Add +2 here to allow room for the halo. const int height = font.height() + icon->height() + kLinkDragImageVPadding + 2; + // TODO(beng): Convert to CanvasSkia gfx::Canvas canvas(width, height, false /* translucent */); // Paint the icon. diff --git a/views/widget/root_view_gtk.cc b/views/widget/root_view_gtk.cc index 75438fb..b2103e1 100644 --- a/views/widget/root_view_gtk.cc +++ b/views/widget/root_view_gtk.cc @@ -7,7 +7,7 @@ #include <gtk/gtk.h> #include "base/logging.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "views/widget/widget_gtk.h" namespace views { @@ -20,7 +20,7 @@ void RootView::OnPaint(GdkEventExpose* event) { } gfx::Rect scheduled_dirty_rect = GetScheduledPaintRectConstrainedToSize(); gfx::Rect expose_rect = gfx::Rect(event->area); - gfx::CanvasPaint canvas(event); + gfx::CanvasSkiaPaint canvas(event); bool invoked_process_paint = false; if (!canvas.is_empty()) { canvas.set_composite_alpha(widget->is_transparent()); diff --git a/views/widget/root_view_win.cc b/views/widget/root_view_win.cc index 49717e1..3c9706d 100644 --- a/views/widget/root_view_win.cc +++ b/views/widget/root_view_win.cc @@ -9,7 +9,8 @@ #include "app/os_exchange_data_provider_win.h" #include "base/base_drag_source.h" #include "base/logging.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_2.h" +#include "gfx/canvas_skia.h" namespace views { diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index 332365a..7705784 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -10,6 +10,7 @@ #include "base/string_util.h" #include "base/win_util.h" #include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "gfx/native_theme_win.h" #include "gfx/path.h" #include "views/accessibility/view_accessibility.h" diff --git a/views/window/window_win.cc b/views/window/window_win.cc index c9efbff..4381e74 100644 --- a/views/window/window_win.cc +++ b/views/window/window_win.cc @@ -13,7 +13,7 @@ #include "app/win_util.h" #include "base/i18n/rtl.h" #include "base/win_util.h" -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #include "gfx/font.h" #include "gfx/icon_util.h" #include "gfx/path.h" @@ -938,12 +938,13 @@ void WindowWin::OnNCPaint(HRGN rgn) { root_view->SchedulePaint(gfx::Rect(dirty_region), false); - // gfx::CanvasPaints destructor does the actual painting. As such, wrap the - // following in a block to force paint to occur so that we can release the dc. + // gfx::CanvasSkiaPaint's destructor does the actual painting. As such, wrap + // the following in a block to force paint to occur so that we can release + // the dc. { - gfx::CanvasPaint canvas(dc, opaque(), dirty_region.left, dirty_region.top, - dirty_region.Width(), dirty_region.Height()); - + gfx::CanvasSkiaPaint canvas(dc, opaque(), dirty_region.left, + dirty_region.top, dirty_region.Width(), + dirty_region.Height()); root_view->ProcessPaint(&canvas); } |