diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-24 23:52:00 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-24 23:52:00 +0000 |
commit | b0f1a563d2b0ff26b9a6ad81258e08b966c9149a (patch) | |
tree | 8a4fcddb3cbe92bc3ff11a23cc2fc6a8fb099186 | |
parent | 24fc19f3cff67e621cf9962eb135cfed4de7e65c (diff) | |
download | chromium_src-b0f1a563d2b0ff26b9a6ad81258e08b966c9149a.zip chromium_src-b0f1a563d2b0ff26b9a6ad81258e08b966c9149a.tar.gz chromium_src-b0f1a563d2b0ff26b9a6ad81258e08b966c9149a.tar.bz2 |
Revert 50784 - Canvas refactoring part 3.
- Replace Canvas instance users with CanvasSkia users.
- Rename Canvas2 to Canvas.
- Delete Canvas subclass of CanvasSkia.
This has created some ugliness around the fact that people that used SkCanvas methods on Canvas now have to go through AsCanvasSkia first. This is temporary ugliness that will be eradicated as I incrementally build out the new Canvas API.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2825018
TBR=ben@chromium.org
Review URL: http://codereview.chromium.org/2811032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50790 0039d316-1c4b-4281-b951-d872f2087c98
70 files changed, 509 insertions, 500 deletions
diff --git a/chrome/browser/chromeos/status/network_menu_button.cc b/chrome/browser/chromeos/status/network_menu_button.cc index f6213ec..09c84f3 100644 --- a/chrome/browser/chromeos/status/network_menu_button.cc +++ b/chrome/browser/chromeos/status/network_menu_button.cc @@ -12,7 +12,7 @@ #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/options/network_config_view.h" #include "chrome/browser/chromeos/status/status_area_host.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/skbitmap_operations.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -387,7 +387,7 @@ SkBitmap NetworkMenuButton::IconForDisplay(SkBitmap icon, SkBitmap badge) { static const int kBadgeX = 14; static const int kBadgeY = 14; - gfx::CanvasSkia canvas(kIconWidth, kIconHeight, false); + gfx::Canvas canvas(kIconWidth, kIconHeight, false); canvas.DrawBitmapInt(icon, kIconX, kIconY); if (!badge.empty()) canvas.DrawBitmapInt(badge, kBadgeX, kBadgeY); diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index 0042b75..0972ddc 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -27,7 +27,7 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/time_format.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/rect.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" @@ -225,7 +225,7 @@ void PaintDownloadProgress(gfx::Canvas* canvas, foreground_paint.setShader(shader); foreground_paint.setAntiAlias(true); shader->unref(); - canvas->AsCanvasSkia()->drawPath(path, foreground_paint); + canvas->drawPath(path, foreground_paint); return; } @@ -271,13 +271,12 @@ void PaintDownloadComplete(gfx::Canvas* canvas, SkIntToScalar(complete_bounds.y()), SkIntToScalar(complete_bounds.x() + complete_bounds.width()), SkIntToScalar(complete_bounds.y() + complete_bounds.height())); - canvas->AsCanvasSkia()->saveLayerAlpha( - &bounds, - static_cast<int>(255.0 * opacity), - SkCanvas::kARGB_ClipLayer_SaveFlag); - canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); + canvas->saveLayerAlpha(&bounds, + static_cast<int>(255.0 * opacity), + SkCanvas::kARGB_ClipLayer_SaveFlag); + canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); canvas->DrawBitmapInt(*complete, complete_bounds.x(), complete_bounds.y()); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } // Load a language dependent height so that the dangerous download confirmation diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc index 5bd5ec8..7ab29e6 100644 --- a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc @@ -619,13 +619,13 @@ void TabRendererGtk::Paint(gfx::Canvas* canvas) { } SkBitmap TabRendererGtk::PaintBitmap() { - gfx::CanvasSkia canvas(width(), height(), false); + gfx::Canvas canvas(width(), height(), false); Paint(&canvas); return canvas.ExtractBitmap(); } cairo_surface_t* TabRendererGtk::PaintToSurface() { - gfx::CanvasSkia canvas(width(), height(), false); + gfx::Canvas canvas(width(), height(), false); Paint(&canvas); return cairo_surface_reference(cairo_get_target(canvas.beginPlatformPaint())); } @@ -804,7 +804,7 @@ void TabRendererGtk::PaintIcon(gfx::Canvas* canvas) { if (loading_animation_.animation_state() != ANIMATION_NONE) { PaintLoadingAnimation(canvas); } else { - canvas->AsCanvasSkia()->save(); + canvas->save(); canvas->ClipRectInt(0, 0, width(), height() - kFavIconTitleSpacing); if (should_display_crashed_favicon_) { canvas->DrawBitmapInt(*crashed_fav_icon, 0, 0, @@ -818,9 +818,8 @@ void TabRendererGtk::PaintIcon(gfx::Canvas* canvas) { if (!data_.favicon.isNull()) { if (data_.is_default_favicon && theme_provider_->UseGtkTheme()) { GdkPixbuf* favicon = GtkThemeProvider::GetDefaultFavicon(true); - canvas->AsCanvasSkia()->DrawGdkPixbuf( - favicon, favicon_bounds_.x(), - favicon_bounds_.y() + fav_icon_hiding_offset_); + canvas->DrawGdkPixbuf(favicon, favicon_bounds_.x(), + favicon_bounds_.y() + fav_icon_hiding_offset_); } else { // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch // to using that class to render the favicon). @@ -834,7 +833,7 @@ void TabRendererGtk::PaintIcon(gfx::Canvas* canvas) { } } } - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } } @@ -848,13 +847,11 @@ void TabRendererGtk::PaintTabBackground(gfx::Canvas* canvas) { if (throb_value > 0) { SkRect bounds; bounds.set(0, 0, SkIntToScalar(width()), SkIntToScalar(height())); - canvas->AsCanvasSkia()->saveLayerAlpha( - &bounds, static_cast<int>(throb_value * 0xff), - SkCanvas::kARGB_ClipLayer_SaveFlag); - canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, - SkXfermode::kClear_Mode); + canvas->saveLayerAlpha(&bounds, static_cast<int>(throb_value * 0xff), + SkCanvas::kARGB_ClipLayer_SaveFlag); + canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); PaintActiveTabBackground(canvas); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } } } diff --git a/chrome/browser/renderer_host/render_widget_host_unittest.cc b/chrome/browser/renderer_host/render_widget_host_unittest.cc index 4ea8193..b6e4326 100644 --- a/chrome/browser/renderer_host/render_widget_host_unittest.cc +++ b/chrome/browser/renderer_host/render_widget_host_unittest.cc @@ -12,7 +12,7 @@ #include "chrome/browser/renderer_host/render_widget_host_painting_observer.h" #include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/common/render_messages.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "testing/gtest/include/gtest/gtest.h" using base::TimeDelta; @@ -406,7 +406,7 @@ TEST_F(RenderWidgetHostTest, Background) { host_->set_view(view.get()); // Create a checkerboard background to test with. - gfx::CanvasSkia canvas(4, 4, true); + gfx::Canvas canvas(4, 4, true); canvas.FillRectInt(SK_ColorBLACK, 0, 0, 2, 2); canvas.FillRectInt(SK_ColorWHITE, 2, 0, 2, 2); canvas.FillRectInt(SK_ColorWHITE, 0, 2, 2, 2); diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc index 17d243c..df9565c 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc @@ -15,6 +15,7 @@ #include "chrome/browser/autocomplete/autocomplete_popup_model.h" #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" @@ -272,7 +273,7 @@ AutocompleteResultView::~AutocompleteResultView() { void AutocompleteResultView::Paint(gfx::Canvas* canvas) { const ResultViewState state = GetState(); if (state != NORMAL) - canvas->AsCanvasSkia()->drawColor(GetColor(state, BACKGROUND)); + canvas->drawColor(GetColor(state, BACKGROUND)); // Paint the icon. canvas->DrawBitmapInt(*GetIcon(), MirroredLeftPointForRect(icon_bounds_), @@ -764,7 +765,8 @@ 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. - gfx::CanvasSkia contents_canvas(width(), height(), true); + // TODO(beng): Convert to CanvasSkia + gfx::Canvas contents_canvas(width(), height(), true); contents_canvas.drawColor(GetColor(NORMAL, BACKGROUND)); View::PaintChildren(&contents_canvas); // We want the contents background to be slightly transparent so we can see @@ -786,7 +788,7 @@ void AutocompletePopupContentsView::Paint(gfx::Canvas* canvas) { gfx::Path path; MakeContentsPath(&path, GetLocalBounds(false)); - canvas->AsCanvasSkia()->drawPath(path, paint); + canvas->drawPath(path, paint); // Now we paint the border, so it will be alpha-blended atop the contents. // This looks slightly better in the corners than drawing the contents atop @@ -933,9 +935,8 @@ void AutocompletePopupContentsView::MakeCanvasTransparent( // Allow the window blur effect to show through the popup background. SkAlpha alpha = GetThemeProvider()->ShouldUseNativeFrame() ? kGlassPopupAlpha : kOpaquePopupAlpha; - canvas->AsCanvasSkia()->drawColor( - SkColorSetA(GetColor(NORMAL, BACKGROUND), alpha), - SkXfermode::kDstIn_Mode); + canvas->drawColor(SkColorSetA(GetColor(NORMAL, BACKGROUND), alpha), + SkXfermode::kDstIn_Mode); } void AutocompletePopupContentsView::OpenIndex( diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc index e595529..0b97017 100644 --- a/chrome/browser/views/bookmark_bar_view.cc +++ b/chrome/browser/views/bookmark_bar_view.cc @@ -37,6 +37,7 @@ #include "chrome/common/notification_service.h" #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" @@ -242,7 +243,7 @@ class BookmarkFolderButton : public views::MenuButton { return disposition != CURRENT_TAB; } - virtual void Paint(gfx::Canvas* canvas) { + virtual void Paint(gfx::Canvas *canvas) { views::MenuButton::Paint(canvas, false); } @@ -1110,7 +1111,8 @@ void BookmarkBarView::WriteDragData(View* sender, for (int i = 0; i < GetBookmarkButtonCount(); ++i) { if (sender == GetBookmarkButton(i)) { views::TextButton* button = GetBookmarkButton(i); - gfx::CanvasSkia canvas(button->width(), button->height(), false); + // 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); diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc index 78cf623..e472de6 100644 --- a/chrome/browser/views/browser_actions_container.cc +++ b/chrome/browser/views/browser_actions_container.cc @@ -323,8 +323,8 @@ gfx::Canvas* BrowserActionView::GetIconWithBadge() { if (icon.isNull()) icon = button_->default_icon(); - gfx::Canvas* canvas = - new gfx::CanvasSkia(icon.width(), icon.height(), false); + // 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) { diff --git a/chrome/browser/views/bubble_border.cc b/chrome/browser/views/bubble_border.cc index e37f5fe..49c53b6 100644 --- a/chrome/browser/views/bubble_border.cc +++ b/chrome/browser/views/bubble_border.cc @@ -6,7 +6,7 @@ #include "app/resource_bundle.h" #include "base/logging.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/path.h" #include "grit/theme_resources.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -418,7 +418,7 @@ void BubbleBorder::DrawArrowInterior(gfx::Canvas* canvas, else path.lineTo(SkIntToScalar(tip_x + shift_x), SkIntToScalar(tip_y - shift_y)); path.close(); - canvas->AsCanvasSkia()->drawPath(path, paint); + canvas->drawPath(path, paint); } ///////////////////////// @@ -439,5 +439,5 @@ void BubbleBackground::Paint(gfx::Canvas* canvas, views::View* view) const { SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom())); SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius()); path.addRoundRect(rect, radius, radius); - canvas->AsCanvasSkia()->drawPath(path, paint); + canvas->drawPath(path, paint); } diff --git a/chrome/browser/views/create_application_shortcut_view.cc b/chrome/browser/views/create_application_shortcut_view.cc index b0a66b3..0d3f6e2 100644 --- a/chrome/browser/views/create_application_shortcut_view.cc +++ b/chrome/browser/views/create_application_shortcut_view.cc @@ -13,7 +13,7 @@ #include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/pref_names.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/codec/png_codec.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" @@ -169,8 +169,8 @@ void AppInfoView::Paint(gfx::Canvas* canvas) { border_paint.setAntiAlias(true); border_paint.setARGB(0xFF, 0xC8, 0xC8, 0xC8); - canvas->AsCanvasSkia()->drawRoundRect( - border_rect, SkIntToScalar(2), SkIntToScalar(2), border_paint); + canvas->drawRoundRect(border_rect, SkIntToScalar(2), SkIntToScalar(2), + border_paint); SkRect inner_rect = { border_rect.fLeft + SkDoubleToScalar(0.5), @@ -182,8 +182,8 @@ void AppInfoView::Paint(gfx::Canvas* canvas) { SkPaint inner_paint; inner_paint.setAntiAlias(true); inner_paint.setARGB(0xFF, 0xF8, 0xF8, 0xF8); - canvas->AsCanvasSkia()->drawRoundRect( - inner_rect, SkIntToScalar(1.5), SkIntToScalar(1.5), inner_paint); + canvas->drawRoundRect(inner_rect, SkIntToScalar(1.5), SkIntToScalar(1.5), + inner_paint); } }; // namespace diff --git a/chrome/browser/views/detachable_toolbar_view.cc b/chrome/browser/views/detachable_toolbar_view.cc index ba44f3d..2e3e457 100644 --- a/chrome/browser/views/detachable_toolbar_view.cc +++ b/chrome/browser/views/detachable_toolbar_view.cc @@ -6,7 +6,7 @@ #include "app/resource_bundle.h" #include "chrome/browser/browser_theme_provider.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/skia_util.h" #include "grit/theme_resources.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -70,7 +70,7 @@ void DetachableToolbarView::PaintContentAreaBackground( paint.setAntiAlias(true); paint.setColor(theme_provider->GetColor(BrowserThemeProvider::COLOR_TOOLBAR)); - canvas->AsCanvasSkia()->drawRoundRect( + canvas->drawRoundRect( rect, SkDoubleToScalar(roundness), SkDoubleToScalar(roundness), paint); } @@ -85,9 +85,9 @@ void DetachableToolbarView::PaintContentAreaBorder( border_paint.setAlpha(96); border_paint.setAntiAlias(true); - canvas->AsCanvasSkia()->drawRoundRect( - rect, SkDoubleToScalar(roundness), SkDoubleToScalar(roundness), - border_paint); + canvas->drawRoundRect(rect, + SkDoubleToScalar(roundness), + SkDoubleToScalar(roundness), border_paint); } // static @@ -106,7 +106,7 @@ void DetachableToolbarView::PaintVerticalDivider( SkIntToScalar(vertical_padding + 1), SkIntToScalar(x + 1), SkIntToScalar(height / 2) }; - canvas->AsCanvasSkia()->drawRect(rc, paint); + canvas->drawRect(rc, paint); // Draw the lower half of the divider. SkPaint paint_down; @@ -118,5 +118,5 @@ void DetachableToolbarView::PaintVerticalDivider( SkIntToScalar(height / 2), SkIntToScalar(x + 1), SkIntToScalar(height - vertical_padding) }; - canvas->AsCanvasSkia()->drawRect(rc_down, paint_down); + canvas->drawRect(rc_down, paint_down); } diff --git a/chrome/browser/views/download_item_view.cc b/chrome/browser/views/download_item_view.cc index edab6a5..d519783 100644 --- a/chrome/browser/views/download_item_view.cc +++ b/chrome/browser/views/download_item_view.cc @@ -20,7 +20,7 @@ #include "chrome/browser/download/download_item_model.h" #include "chrome/browser/download/download_util.h" #include "chrome/browser/views/download_shelf_view.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/color_utils.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -515,7 +515,7 @@ void DownloadItemView::Paint(gfx::Canvas* canvas) { // (hot_)body_image_set->bottom_left, and drop_down_image_set, // for RTL UI, we flip the canvas to draw those images mirrored. // Consequently, we do not need to mirror the x-axis of those images. - canvas->AsCanvasSkia()->save(); + canvas->save(); canvas->TranslateInt(width(), 0); canvas->ScaleInt(-1, 1); } @@ -536,10 +536,10 @@ void DownloadItemView::Paint(gfx::Canvas* canvas) { // Overlay our body hot state. if (body_hover_animation_->GetCurrentValue() > 0) { - canvas->AsCanvasSkia()->saveLayerAlpha(NULL, + canvas->saveLayerAlpha(NULL, static_cast<int>(body_hover_animation_->GetCurrentValue() * 255), SkCanvas::kARGB_NoClipLayer_SaveFlag); - canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); + canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); int x = kLeftPadding; PaintBitmaps(canvas, @@ -557,10 +557,10 @@ void DownloadItemView::Paint(gfx::Canvas* canvas) { hot_body_image_set_.bottom_right, x, box_y_, box_height_, hot_body_image_set_.top_right->width()); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); if (rtl_ui) { - canvas->AsCanvasSkia()->restore(); - canvas->AsCanvasSkia()->save(); + canvas->restore(); + canvas->save(); // Flip it for drawing drop-down images for RTL locales. canvas->TranslateInt(width(), 0); canvas->ScaleInt(-1, 1); @@ -578,19 +578,17 @@ void DownloadItemView::Paint(gfx::Canvas* canvas) { // Overlay our drop-down hot state. if (drop_hover_animation_->GetCurrentValue() > 0) { - canvas->AsCanvasSkia()->saveLayerAlpha( - NULL, + canvas->saveLayerAlpha(NULL, static_cast<int>(drop_hover_animation_->GetCurrentValue() * 255), SkCanvas::kARGB_NoClipLayer_SaveFlag); - canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, - SkXfermode::kClear_Mode); + canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); PaintBitmaps(canvas, drop_down_image_set->top, drop_down_image_set->center, drop_down_image_set->bottom, x, box_y_, box_height_, drop_down_image_set->top->width()); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } } @@ -598,7 +596,7 @@ void DownloadItemView::Paint(gfx::Canvas* canvas) { // Restore the canvas to avoid file name etc. text are drawn flipped. // Consequently, the x-axis of following canvas->DrawXXX() method should be // mirrored so the text and images are down in the right positions. - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } // Print the text, left aligned and always print the file extension. 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 aa072f6..0b66c13 100644 --- a/chrome/browser/views/extensions/browser_action_overflow_menu_controller.cc +++ b/chrome/browser/views/extensions/browser_action_overflow_menu_controller.cc @@ -13,7 +13,7 @@ #include "chrome/browser/views/extensions/browser_action_drag_data.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_action.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "views/controls/menu/menu_item_view.h" #include "views/controls/menu/menu_2.h" @@ -34,11 +34,11 @@ 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()), - canvas->AsCanvasSkia()->ExtractBitmap()); + canvas->ExtractBitmap()); // Set the tooltip for this item. std::wstring tooltip = UTF8ToWide( diff --git a/chrome/browser/views/extensions/extension_shelf.cc b/chrome/browser/views/extensions/extension_shelf.cc index 7bb5391..e06b494 100644 --- a/chrome/browser/views/extensions/extension_shelf.cc +++ b/chrome/browser/views/extensions/extension_shelf.cc @@ -24,7 +24,6 @@ #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" -#include "gfx/canvas_skia.h" #include "views/controls/label.h" #include "views/screen.h" #include "views/widget/root_view.h" @@ -943,15 +942,13 @@ void ExtensionShelf::InitBackground(gfx::Canvas* canvas) { for (int i = 0; i < count; ++i) { ExtensionView* view = ToolstripAtIndex(i)->view(); - const SkBitmap& background = - canvas->AsCanvasSkia()->getDevice()->accessBitmap(false); + const SkBitmap& background = canvas->getDevice()->accessBitmap(false); SkRect mapped_subset = background_rect; gfx::Rect view_bounds = view->bounds(); mapped_subset.offset(SkIntToScalar(view_bounds.x()), SkIntToScalar(view_bounds.y())); - bool result = - canvas->AsCanvasSkia()->getTotalMatrix().mapRect(&mapped_subset); + bool result = canvas->getTotalMatrix().mapRect(&mapped_subset); DCHECK(result); SkIRect isubset; diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index caca13a..343519e 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -49,7 +49,7 @@ #include "chrome/common/native_window_notification_source.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "grit/app_resources.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -221,12 +221,12 @@ class ResizeCorner : public views::View { if (rtl_dir) { canvas->TranslateInt(width(), 0); canvas->ScaleInt(-1, 1); - canvas->AsCanvasSkia()->save(); + canvas->save(); } canvas->DrawBitmapInt(*bitmap, width() - bitmap->width(), height() - bitmap->height()); if (rtl_dir) - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } static gfx::Size GetSize() { diff --git a/chrome/browser/views/frame/glass_browser_frame_view.cc b/chrome/browser/views/frame/glass_browser_frame_view.cc index b37552e..d65cbc3 100644 --- a/chrome/browser/views/frame/glass_browser_frame_view.cc +++ b/chrome/browser/views/frame/glass_browser_frame_view.cc @@ -12,7 +12,7 @@ #include "chrome/browser/views/tabs/side_tab_strip.h" #include "chrome/browser/views/tabs/tab.h" #include "chrome/browser/views/tabs/tab_strip.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/icon_util.h" #include "grit/app_resources.h" #include "grit/theme_resources.h" @@ -264,14 +264,14 @@ void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) { // Draw left edge. We explicitly set a clip as the image is bigger than just // the corner. - canvas->AsCanvasSkia()->save(); + canvas->save(); canvas->ClipRectInt(x - kNonClientBorderThickness, y - kNonClientBorderThickness, kNonClientBorderThickness, kNonClientBorderThickness); canvas->DrawBitmapInt(*toolbar_left, x - kNonClientBorderThickness, y - kNonClientBorderThickness); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); // Draw center edge. We need to draw a while line above the toolbar for the // image to overlay nicely. @@ -279,14 +279,14 @@ void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) { canvas->TileImageInt(*toolbar_center, x, y - kNonClientBorderThickness, w, toolbar_center->height()); // Right edge. Again, we have to clip because of image size. - canvas->AsCanvasSkia()->save(); + canvas->save(); canvas->ClipRectInt(x + w - kNonClientBorderThickness, y - kNonClientBorderThickness, kNonClientBorderThickness, kNonClientBorderThickness); canvas->DrawBitmapInt(*tp->GetBitmapNamed(IDR_CONTENT_TOP_RIGHT_CORNER), x + w, y); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } else { // Draw the toolbar background, setting src_y of the paint to the tab // strip height as the toolbar background begins at the top of the tabs. @@ -356,11 +356,11 @@ void GlassBrowserFrameView::PaintOTRAvatar(gfx::Canvas* canvas) { gfx::Point tabstrip_origin(browser_view_->tabstrip()->bounds().origin()); View::ConvertPointToView(frame_->GetWindow()->GetClientView(), this, &tabstrip_origin); - canvas->AsCanvasSkia()->save(); + canvas->save(); canvas->ClipRectInt(dst_x, 2, w, tabstrip_origin.y() - 4); canvas->DrawBitmapInt(otr_avatar_icon, src_x, src_y, w, h, dst_x, dst_y, w, h, false); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } else { canvas->DrawBitmapInt(otr_avatar_icon, src_x, src_y, w, h, dst_x, dst_y, w, h, false); diff --git a/chrome/browser/views/frame/opaque_browser_frame_view.cc b/chrome/browser/views/frame/opaque_browser_frame_view.cc index 227205f..d18375a 100644 --- a/chrome/browser/views/frame/opaque_browser_frame_view.cc +++ b/chrome/browser/views/frame/opaque_browser_frame_view.cc @@ -15,7 +15,7 @@ #include "chrome/browser/views/frame/browser_view.h" #include "chrome/browser/views/tabs/tab_strip.h" #include "chrome/browser/views/toolbar_view.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/font.h" #include "gfx/path.h" #include "grit/app_resources.h" @@ -382,10 +382,10 @@ void OpaqueBrowserFrameView::PaintChildren(gfx::Canvas* canvas) { continue; } if (child == otr_avatar_icon_) { - canvas->AsCanvasSkia()->save(); + canvas->save(); canvas->ClipRectInt(0, 2, width(), otr_avatar_icon_->height() - 10); child->ProcessPaint(canvas); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } else { child->ProcessPaint(canvas); } @@ -785,8 +785,8 @@ void OpaqueBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) { bounds.set(SkIntToScalar(x - kClientEdgeThickness), SkIntToScalar(y), SkIntToScalar(x + w + kClientEdgeThickness * 2), SkIntToScalar(y + h)); - canvas->AsCanvasSkia()->saveLayerAlpha(&bounds, 255); - canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); + canvas->saveLayerAlpha(&bounds, 255); + canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); SkColor theme_toolbar_color = tp->GetColor(BrowserThemeProvider::COLOR_TOOLBAR); @@ -836,7 +836,7 @@ void OpaqueBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) { toolbar_right_mask->height() - bottom_edge_height, toolbar_right_mask->width(), bottom_edge_height, right_x, bottom_y, toolbar_right_mask->width(), bottom_edge_height, false, paint); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); canvas->DrawBitmapInt(*toolbar_left, 0, 0, toolbar_left->width(), split_point, left_x, y, diff --git a/chrome/browser/views/fullscreen_exit_bubble.cc b/chrome/browser/views/fullscreen_exit_bubble.cc index e216bd2..c12326a 100644 --- a/chrome/browser/views/fullscreen_exit_bubble.cc +++ b/chrome/browser/views/fullscreen_exit_bubble.cc @@ -8,7 +8,7 @@ #include "app/resource_bundle.h" #include "base/keyboard_codes.h" #include "chrome/app/chrome_dll_resource.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "grit/generated_resources.h" #include "views/screen.h" #include "views/widget/root_view.h" @@ -92,7 +92,7 @@ void FullscreenExitBubble::FullscreenExitView::Paint(gfx::Canvas* canvas) { paint.setStyle(SkPaint::kFill_Style); paint.setFlags(SkPaint::kAntiAlias_Flag); paint.setColor(SK_ColorBLACK); - canvas->AsCanvasSkia()->drawPath(path, paint); + canvas->drawPath(path, paint); } diff --git a/chrome/browser/views/info_bubble.cc b/chrome/browser/views/info_bubble.cc index 34645a0..7f1b4f2 100644 --- a/chrome/browser/views/info_bubble.cc +++ b/chrome/browser/views/info_bubble.cc @@ -7,7 +7,7 @@ #include "base/keyboard_codes.h" #include "chrome/browser/window_sizer.h" #include "chrome/common/notification_service.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/color_utils.h" #include "gfx/path.h" #include "third_party/skia/include/core/SkPaint.h" @@ -114,7 +114,7 @@ void BorderContents::Paint(gfx::Canvas* canvas) { SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom())); SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius()); path.addRoundRect(rect, radius, radius); - canvas->AsCanvasSkia()->drawPath(path, paint); + canvas->drawPath(path, paint); // Now we paint the border, so it will be alpha-blended atop the contents. // This looks slightly better in the corners than drawing the contents atop diff --git a/chrome/browser/views/infobars/translate_infobar_base.cc b/chrome/browser/views/infobars/translate_infobar_base.cc index d344b88..aa89609 100644 --- a/chrome/browser/views/infobars/translate_infobar_base.cc +++ b/chrome/browser/views/infobars/translate_infobar_base.cc @@ -12,7 +12,7 @@ #include "chrome/browser/views/infobars/before_translate_infobar.h" #include "chrome/browser/views/infobars/translate_message_infobar.h" #include "chrome/browser/views/infobars/infobar_button_border.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "grit/app_resources.h" #include "views/controls/button/menu_button.h" #include "views/controls/image_view.h" @@ -148,12 +148,11 @@ void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas, const InfoBarBackground& background) { // Draw the background into an offscreen buffer with alpha value per animation // value, then blend it back into the current canvas. - canvas->AsCanvasSkia()->saveLayerAlpha( - NULL, static_cast<int>(animation_value * 255), - SkCanvas::kARGB_NoClipLayer_SaveFlag); - canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); + canvas->saveLayerAlpha(NULL, static_cast<int>(animation_value * 255), + SkCanvas::kARGB_NoClipLayer_SaveFlag); + canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); background.Paint(canvas, this); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } // TranslateInfoBarDelegate views specific method: diff --git a/chrome/browser/views/infobars/translate_infobars.cc b/chrome/browser/views/infobars/translate_infobars.cc index e395c39..08d4a0f 100644 --- a/chrome/browser/views/infobars/translate_infobars.cc +++ b/chrome/browser/views/infobars/translate_infobars.cc @@ -19,7 +19,7 @@ #include "chrome/browser/translate/page_translated_details.h" #include "chrome/browser/views/infobars/infobar_button_border.h" #include "chrome/browser/views/infobars/infobar_text_button.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "grit/app_resources.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" @@ -757,12 +757,11 @@ void TranslateInfoBar::FadeBackground(gfx::Canvas* canvas, double animation_value, TranslateInfoBarDelegate::TranslateState state) { // Draw background into an offscreen buffer with alpha value per animation // value, then blend it back into the current canvas. - canvas->AsCanvasSkia()->saveLayerAlpha( - NULL, static_cast<int>(animation_value * 255), + canvas->saveLayerAlpha(NULL, static_cast<int>(animation_value * 255), SkCanvas::kARGB_NoClipLayer_SaveFlag); - canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); + canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); GetBackground(state)->Paint(canvas, this); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } inline TranslateInfoBarDelegate* TranslateInfoBar::GetDelegate() const { diff --git a/chrome/browser/views/list_background.h b/chrome/browser/views/list_background.h index fb10067..ba8317a 100644 --- a/chrome/browser/views/list_background.h +++ b/chrome/browser/views/list_background.h @@ -5,7 +5,7 @@ #ifndef CHROME_BROWSER_VIEWS_LIST_BACKGROUND_H_ #define CHROME_BROWSER_VIEWS_LIST_BACKGROUND_H_ -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/native_theme_win.h" #include "views/background.h" @@ -22,10 +22,10 @@ class ListBackground : public views::Background { virtual ~ListBackground() {} virtual void Paint(gfx::Canvas* canvas, views::View* view) const { - HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint(); + HDC dc = canvas->beginPlatformPaint(); RECT native_lb = view->GetLocalBounds(true).ToRECT(); gfx::NativeTheme::instance()->PaintListBackground(dc, true, &native_lb); - canvas->AsCanvasSkia()->endPlatformPaint(); + canvas->endPlatformPaint(); } private: diff --git a/chrome/browser/views/location_bar/location_bar_view.cc b/chrome/browser/views/location_bar/location_bar_view.cc index 09c1007..77a459f 100644 --- a/chrome/browser/views/location_bar/location_bar_view.cc +++ b/chrome/browser/views/location_bar/location_bar_view.cc @@ -27,7 +27,7 @@ #include "chrome/browser/views/location_bar/page_action_with_badge_view.h" #include "chrome/browser/views/location_bar/selected_keyword_view.h" #include "chrome/browser/views/location_bar/star_view.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/color_utils.h" #include "gfx/skia_util.h" #include "grit/generated_resources.h" @@ -556,8 +556,7 @@ void LocationBarView::Paint(gfx::Canvas* canvas) { // below, and all our other bubbles. const SkScalar radius(SkIntToScalar(BubbleBorder::GetCornerRadius())); bounds.Inset(kEdgeThickness, 0); - canvas->AsCanvasSkia()->drawRoundRect(gfx::RectToSkRect(bounds), radius, - radius, paint); + canvas->drawRoundRect(gfx::RectToSkRect(bounds), radius, radius, paint); } else { canvas->FillRectInt(color, bounds.x(), bounds.y(), bounds.width(), bounds.height()); diff --git a/chrome/browser/views/notifications/balloon_view.cc b/chrome/browser/views/notifications/balloon_view.cc index 68c6570..2c362d0 100644 --- a/chrome/browser/views/notifications/balloon_view.cc +++ b/chrome/browser/views/notifications/balloon_view.cc @@ -22,7 +22,7 @@ #include "chrome/common/notification_details.h" #include "chrome/common/notification_source.h" #include "chrome/common/notification_type.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/insets.h" #include "gfx/native_widget_types.h" #include "grit/generated_resources.h" @@ -466,7 +466,7 @@ void BalloonViewImpl::Paint(gfx::Canvas* canvas) { SkPaint paint; paint.setAntiAlias(true); paint.setColor(kControlBarBackgroundColor); - canvas->AsCanvasSkia()->drawPath(path, paint); + canvas->drawPath(path, paint); // Draw a 1-pixel gray line between the content and the menu bar. int line_width = GetTotalWidth() - kLeftMargin - kRightMargin; diff --git a/chrome/browser/views/options/advanced_contents_view.cc b/chrome/browser/views/options/advanced_contents_view.cc index 88dc660..b8b88cb 100644 --- a/chrome/browser/views/options/advanced_contents_view.cc +++ b/chrome/browser/views/options/advanced_contents_view.cc @@ -40,7 +40,7 @@ #include "chrome/browser/views/options/fonts_languages_window_view.h" #include "chrome/browser/views/restart_message_box.h" #include "chrome/common/pref_names.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/native_theme_win.h" #include "grit/app_resources.h" #include "grit/chromium_strings.h" @@ -135,12 +135,12 @@ void FileDisplayArea::SetFile(const FilePath& file_path) { } void FileDisplayArea::Paint(gfx::Canvas* canvas) { - HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint(); + HDC dc = canvas->beginPlatformPaint(); RECT rect = { 0, 0, width(), height() }; gfx::NativeTheme::instance()->PaintTextField( dc, EP_EDITTEXT, ETS_READONLY, 0, &rect, skia::SkColorToCOLORREF(text_field_background_color_), true, true); - canvas->AsCanvasSkia()->endPlatformPaint(); + canvas->endPlatformPaint(); // Mirror left point for icon_bounds_ to draw icon in RTL locales correctly. canvas->DrawBitmapInt(default_folder_icon_, MirroredLeftPointForRect(icon_bounds_), diff --git a/chrome/browser/views/options/fonts_page_view.cc b/chrome/browser/views/options/fonts_page_view.cc index df5b832..4fd923e 100644 --- a/chrome/browser/views/options/fonts_page_view.cc +++ b/chrome/browser/views/options/fonts_page_view.cc @@ -21,7 +21,7 @@ #include "chrome/browser/profile.h" #include "chrome/browser/shell_dialogs.h" #include "chrome/common/pref_names.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/font.h" #include "gfx/native_theme_win.h" #include "grit/generated_resources.h" @@ -96,12 +96,12 @@ void FontDisplayView::SetFontType(const std::wstring& font_name, } void FontDisplayView::Paint(gfx::Canvas* canvas) { - HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint(); + HDC dc = canvas->beginPlatformPaint(); RECT rect = { 0, 0, width(), height() }; gfx::NativeTheme::instance()->PaintTextField( dc, EP_BACKGROUND, EBS_NORMAL, 0, &rect, ::GetSysColor(COLOR_3DFACE), true, true); - canvas->AsCanvasSkia()->endPlatformPaint(); + canvas->endPlatformPaint(); } void FontDisplayView::Layout() { diff --git a/chrome/browser/views/sad_tab_view.cc b/chrome/browser/views/sad_tab_view.cc index e02d975..fbaa37d5 100644 --- a/chrome/browser/views/sad_tab_view.cc +++ b/chrome/browser/views/sad_tab_view.cc @@ -57,8 +57,9 @@ void SadTabView::Paint(gfx::Canvas* canvas) { kBackgroundColor, kBackgroundEndColor))->safeUnref(); paint.setStyle(SkPaint::kFill_Style); - canvas->AsCanvasSkia()->drawRectCoords( - 0, 0, SkIntToScalar(width()), SkIntToScalar(height()), paint); + canvas->drawRectCoords(0, 0, + SkIntToScalar(width()), SkIntToScalar(height()), + paint); canvas->DrawBitmapInt(*sad_tab_bitmap_, icon_bounds_.x(), icon_bounds_.y()); diff --git a/chrome/browser/views/status_bubble_views.cc b/chrome/browser/views/status_bubble_views.cc index 71be04d..5026c49 100644 --- a/chrome/browser/views/status_bubble_views.cc +++ b/chrome/browser/views/status_bubble_views.cc @@ -14,7 +14,7 @@ #include "base/message_loop.h" #include "base/string_util.h" #include "chrome/browser/browser_theme_provider.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/point.h" #include "googleurl/src/gurl.h" #include "grit/generated_resources.h" @@ -414,7 +414,7 @@ void StatusBubbleViews::StatusView::Paint(gfx::Canvas* canvas) { SkPaint shadow_paint; shadow_paint.setFlags(SkPaint::kAntiAlias_Flag); shadow_paint.setColor(kShadowColor); - canvas->AsCanvasSkia()->drawPath(shadow_path, shadow_paint); + canvas->drawPath(shadow_path, shadow_paint); // Draw the bubble. rect.set(SkIntToScalar(kShadowThickness), @@ -423,7 +423,7 @@ void StatusBubbleViews::StatusView::Paint(gfx::Canvas* canvas) { SkIntToScalar(height - kShadowThickness)); SkPath path; path.addRoundRect(rect, rad, SkPath::kCW_Direction); - canvas->AsCanvasSkia()->drawPath(path, paint); + canvas->drawPath(path, paint); // Draw highlight text and then the text body. In order to make sure the text // is aligned to the right on RTL UIs, we mirror the text bounds if the diff --git a/chrome/browser/views/tabs/base_tab.cc b/chrome/browser/views/tabs/base_tab.cc index 58e853f..04124ed 100644 --- a/chrome/browser/views/tabs/base_tab.cc +++ b/chrome/browser/views/tabs/base_tab.cc @@ -17,7 +17,7 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/views/tabs/tab_controller.h" #include "chrome/common/chrome_switches.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/favicon_size.h" #include "gfx/font.h" #include "gfx/skbitmap_operations.h" @@ -437,7 +437,7 @@ void BaseTab::PaintIcon(gfx::Canvas* canvas, int x, int y) { image_size, favicon_x, dst_y, image_size, image_size, false); } else { - canvas->AsCanvasSkia()->save(); + canvas->save(); canvas->ClipRectInt(0, 0, width(), height()); if (should_display_crashed_favicon_) { canvas->DrawBitmapInt(*crashed_fav_icon, 0, 0, @@ -460,7 +460,7 @@ void BaseTab::PaintIcon(gfx::Canvas* canvas, int x, int y) { true); } } - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } } diff --git a/chrome/browser/views/tabs/dragged_tab_controller.cc b/chrome/browser/views/tabs/dragged_tab_controller.cc index 5778f0b..bb97cd6 100644 --- a/chrome/browser/views/tabs/dragged_tab_controller.cc +++ b/chrome/browser/views/tabs/dragged_tab_controller.cc @@ -30,7 +30,7 @@ #include "chrome/browser/views/tabs/tab.h" #include "chrome/browser/views/tabs/tab_strip.h" #include "chrome/common/notification_service.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "grit/theme_resources.h" #include "third_party/skia/include/core/SkBitmap.h" #include "views/event.h" @@ -85,9 +85,8 @@ class DockView : public views::View { SkPaint paint; paint.setColor(SkColorSetRGB(108, 108, 108)); paint.setStyle(SkPaint::kFill_Style); - canvas->AsCanvasSkia()->drawRoundRect( - outer_rect, SkIntToScalar(kRoundedRectRadius), - SkIntToScalar(kRoundedRectRadius), paint); + canvas->drawRoundRect(outer_rect, SkIntToScalar(kRoundedRectRadius), + SkIntToScalar(kRoundedRectRadius), paint); ResourceBundle& rb = ResourceBundle::GetSharedInstance(); @@ -97,7 +96,7 @@ class DockView : public views::View { bool rtl_ui = base::i18n::IsRTL(); if (rtl_ui) { // Flip canvas to draw the mirrored tab images for RTL UI. - canvas->AsCanvasSkia()->save(); + canvas->save(); canvas->TranslateInt(width(), 0); canvas->ScaleInt(-1, 1); } @@ -171,7 +170,7 @@ class DockView : public views::View { break; } if (rtl_ui) - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } private: diff --git a/chrome/browser/views/tabs/dragged_tab_view.cc b/chrome/browser/views/tabs/dragged_tab_view.cc index e0b13a1..e5c55a4 100644 --- a/chrome/browser/views/tabs/dragged_tab_view.cc +++ b/chrome/browser/views/tabs/dragged_tab_view.cc @@ -5,6 +5,7 @@ #include "chrome/browser/views/tabs/dragged_tab_view.h" #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,7 +186,8 @@ void DraggedTabView::PaintAttachedTab(gfx::Canvas* canvas) { void DraggedTabView::PaintDetachedView(gfx::Canvas* canvas) { gfx::Size ps = GetPreferredSize(); - gfx::CanvasSkia scale_canvas(ps.width(), ps.height(), false); + // 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)); bitmap_device.eraseARGB(0, 0, 0, 0); @@ -227,7 +229,7 @@ void DraggedTabView::PaintDetachedView(gfx::Canvas* canvas) { rc.fTop = 0; rc.fRight = SkIntToScalar(ps.width()); rc.fBottom = SkIntToScalar(ps.height()); - canvas->AsCanvasSkia()->drawRect(rc, paint); + canvas->drawRect(rc, paint); } void DraggedTabView::PaintFocusRect(gfx::Canvas* canvas) { diff --git a/chrome/browser/views/tabs/native_view_photobooth_win.cc b/chrome/browser/views/tabs/native_view_photobooth_win.cc index 1eb3125..8920a9b 100644 --- a/chrome/browser/views/tabs/native_view_photobooth_win.cc +++ b/chrome/browser/views/tabs/native_view_photobooth_win.cc @@ -5,7 +5,7 @@ #include "chrome/browser/views/tabs/native_view_photobooth_win.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/point.h" #include "third_party/skia/include/core/SkBitmap.h" #include "views/widget/widget_win.h" @@ -100,7 +100,7 @@ void NativeViewPhotoboothWin::PaintScreenshotIntoCanvas( // Transfer the contents of the layered capture window to the screen-shot // canvas' DIB. - HDC target_dc = canvas->AsCanvasSkia()->beginPlatformPaint(); + HDC target_dc = canvas->beginPlatformPaint(); HDC source_dc = GetDC(current_hwnd_); RECT window_rect = {0}; GetWindowRect(current_hwnd_, &window_rect); @@ -109,11 +109,12 @@ void NativeViewPhotoboothWin::PaintScreenshotIntoCanvas( SRCCOPY); // Windows screws up the alpha channel on all text it draws, and so we need // to call makeOpaque _after_ the blit to correct for this. - canvas->AsCanvasSkia()->getTopPlatformDevice().makeOpaque( - target_bounds.x(), target_bounds.y(), target_bounds.width(), - target_bounds.height()); + canvas->getTopPlatformDevice().makeOpaque(target_bounds.x(), + target_bounds.y(), + target_bounds.width(), + target_bounds.height()); ReleaseDC(current_hwnd_, source_dc); - canvas->AsCanvasSkia()->endPlatformPaint(); + canvas->endPlatformPaint(); } /////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/views/tabs/side_tab.cc b/chrome/browser/views/tabs/side_tab.cc index 05036d6..c2448d2 100644 --- a/chrome/browser/views/tabs/side_tab.cc +++ b/chrome/browser/views/tabs/side_tab.cc @@ -8,7 +8,7 @@ #include "app/theme_provider.h" #include "base/logging.h" #include "base/utf_string_conversions.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/favicon_size.h" #include "gfx/path.h" #include "gfx/skia_util.h" @@ -91,20 +91,18 @@ void SideTab::Paint(gfx::Canvas* canvas) { paint.setAntiAlias(true); SkRect border_rect = { SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(width()), SkIntToScalar(height()) }; - canvas->AsCanvasSkia()->drawRoundRect(border_rect, - SkIntToScalar(kRoundRectRadius), - SkIntToScalar(kRoundRectRadius), - paint); + canvas->drawRoundRect(border_rect, SkIntToScalar(kRoundRectRadius), + SkIntToScalar(kRoundRectRadius), paint); } if (ShouldShowIcon()) { if (data().phantom) { SkRect bounds; bounds.set(0, 0, SkIntToScalar(width()), SkIntToScalar(height())); - canvas->AsCanvasSkia()->saveLayerAlpha( - &bounds, kPhantomTabIconAlpha, SkCanvas::kARGB_ClipLayer_SaveFlag); + canvas->saveLayerAlpha(&bounds, kPhantomTabIconAlpha, + SkCanvas::kARGB_ClipLayer_SaveFlag); PaintIcon(canvas, icon_bounds_.x(), icon_bounds_.y()); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } else { PaintIcon(canvas, icon_bounds_.x(), icon_bounds_.y()); } diff --git a/chrome/browser/views/tabs/tab.cc b/chrome/browser/views/tabs/tab.cc index 82ab751..afb7f6a 100644 --- a/chrome/browser/views/tabs/tab.cc +++ b/chrome/browser/views/tabs/tab.cc @@ -13,6 +13,7 @@ #include "base/utf_string_conversions.h" #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" @@ -381,20 +382,18 @@ void Tab::PaintTabBackground(gfx::Canvas* canvas) { if (throb_value > 0) { SkRect bounds; bounds.set(0, 0, SkIntToScalar(width()), SkIntToScalar(height())); - canvas->AsCanvasSkia()->saveLayerAlpha( - &bounds, static_cast<int>(throb_value * 0xff), - SkCanvas::kARGB_ClipLayer_SaveFlag); - canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, - SkXfermode::kClear_Mode); + canvas->saveLayerAlpha(&bounds, static_cast<int>(throb_value * 0xff), + SkCanvas::kARGB_ClipLayer_SaveFlag); + canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); PaintActiveTabBackground(canvas); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } } } void Tab::PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas) { // Render the inactive tab background. We'll use this for clipping. - gfx::CanvasSkia background_canvas(width(), height(), false); + gfx::Canvas background_canvas(width(), height(), false); PaintInactiveTabBackground(&background_canvas); SkBitmap background_image = background_canvas.ExtractBitmap(); @@ -438,10 +437,10 @@ void Tab::PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas) { // And then the gradient on top of that. if (mini_title_animation_->current_part_index() == 2) { - canvas->AsCanvasSkia()->saveLayerAlpha( - NULL, mini_title_animation_->CurrentValueBetween(255, 0)); + canvas->saveLayerAlpha(NULL, + mini_title_animation_->CurrentValueBetween(255, 0)); canvas->DrawBitmapInt(hover_image, 0, 0); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } else { canvas->DrawBitmapInt(hover_image, 0, 0); } diff --git a/chrome/browser/views/tabs/tab_strip.cc b/chrome/browser/views/tabs/tab_strip.cc index 2d54f66..b8aecf5 100644 --- a/chrome/browser/views/tabs/tab_strip.cc +++ b/chrome/browser/views/tabs/tab_strip.cc @@ -18,7 +18,7 @@ #include "chrome/browser/views/tabs/tab.h" #include "chrome/browser/views/tabs/tab_strip_controller.h" #include "chrome/common/pref_names.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/path.h" #include "gfx/size.h" #include "grit/generated_resources.h" @@ -294,31 +294,31 @@ void TabStrip::PaintChildren(gfx::Canvas* canvas) { if (HasPhantomTabs()) { SkRect bounds; bounds.set(0, 0, SkIntToScalar(width()), SkIntToScalar(height())); - canvas->AsCanvasSkia()->saveLayerAlpha( - &bounds, kPhantomTabAlpha, SkCanvas::kARGB_ClipLayer_SaveFlag); - canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); + canvas->saveLayerAlpha(&bounds, kPhantomTabAlpha, + SkCanvas::kARGB_ClipLayer_SaveFlag); + canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); for (int i = tab_count() - 1; i >= 0; --i) { Tab* tab = GetTabAtTabDataIndex(i); if (tab->data().phantom) tab->ProcessPaint(canvas); } - canvas->AsCanvasSkia()->restore(); + canvas->restore(); - canvas->AsCanvasSkia()->saveLayerAlpha( - &bounds, kPhantomTabIconAlpha, SkCanvas::kARGB_ClipLayer_SaveFlag); - canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); + canvas->saveLayerAlpha(&bounds, kPhantomTabIconAlpha, + SkCanvas::kARGB_ClipLayer_SaveFlag); + canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); for (int i = tab_count() - 1; i >= 0; --i) { Tab* tab = GetTabAtTabDataIndex(i); if (tab->data().phantom) { - canvas->AsCanvasSkia()->save(); + canvas->save(); canvas->ClipRectInt(tab->MirroredX(), tab->y(), tab->width(), tab->height()); canvas->TranslateInt(tab->MirroredX(), tab->y()); tab->PaintIcon(canvas); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } } - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } Tab* selected_tab = NULL; diff --git a/chrome/browser/views/theme_install_bubble_view.cc b/chrome/browser/views/theme_install_bubble_view.cc index 4e54812..43871b1 100644 --- a/chrome/browser/views/theme_install_bubble_view.cc +++ b/chrome/browser/views/theme_install_bubble_view.cc @@ -7,7 +7,6 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "gfx/canvas_skia.h" #include "grit/generated_resources.h" #include "views/widget/widget.h" @@ -126,7 +125,7 @@ void ThemeInstallBubbleView::Paint(gfx::Canvas* canvas) { SkIntToScalar(height())); SkPath path; path.addRoundRect(rect, rad, SkPath::kCW_Direction); - canvas->AsCanvasSkia()->drawPath(path, paint); + canvas->drawPath(path, paint); int text_width = views::Label::font().GetStringWidth(text_); gfx::Rect body_bounds(kTextHorizPadding / 2, 0, text_width, height()); diff --git a/chrome/common/extensions/extension_action.cc b/chrome/common/extensions/extension_action.cc index 9951ba6..d86b1f9 100644 --- a/chrome/common/extensions/extension_action.cc +++ b/chrome/common/extensions/extension_action.cc @@ -9,7 +9,7 @@ #include "app/resource_bundle.h" #include "base/utf_string_conversions.h" #include "chrome/app/chrome_dll_resource.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/font.h" #include "gfx/rect.h" #include "grit/app_resources.h" @@ -118,7 +118,7 @@ void ExtensionAction::PaintBadge(gfx::Canvas* canvas, if (SkColorGetA(background_color) == 0x00) background_color = SkColorSetARGB(255, 218, 0, 24); // Default badge color. - canvas->AsCanvasSkia()->save(); + canvas->save(); SkPaint* text_paint = GetTextPaint(); text_paint->setColor(text_color); @@ -158,8 +158,7 @@ void ExtensionAction::PaintBadge(gfx::Canvas* canvas, rect_paint.setStyle(SkPaint::kFill_Style); rect_paint.setAntiAlias(true); rect_paint.setColor(background_color); - canvas->AsCanvasSkia()->drawRoundRect(rect, SkIntToScalar(2), SkIntToScalar(2), - rect_paint); + canvas->drawRoundRect(rect, SkIntToScalar(2), SkIntToScalar(2), rect_paint); // Overlay the gradient. It is stretchy, so we do this in three parts. ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); @@ -170,24 +169,24 @@ void ExtensionAction::PaintBadge(gfx::Canvas* canvas, SkBitmap* gradient_center = resource_bundle.GetBitmapNamed( IDR_BROWSER_ACTION_BADGE_CENTER); - canvas->AsCanvasSkia()->drawBitmap(*gradient_left, rect.fLeft, rect.fTop); + canvas->drawBitmap(*gradient_left, rect.fLeft, rect.fTop); canvas->TileImageInt(*gradient_center, SkScalarFloor(rect.fLeft) + gradient_left->width(), SkScalarFloor(rect.fTop), SkScalarFloor(rect.width()) - gradient_left->width() - gradient_right->width(), SkScalarFloor(rect.height())); - canvas->AsCanvasSkia()->drawBitmap(*gradient_right, + canvas->drawBitmap(*gradient_right, rect.fRight - SkIntToScalar(gradient_right->width()), rect.fTop); // Finally, draw the text centered within the badge. We set a clip in case the // text was too large. rect.fLeft += kPadding; rect.fRight -= kPadding; - canvas->AsCanvasSkia()->clipRect(rect); - canvas->AsCanvasSkia()->drawText(text.c_str(), text.size(), - rect.fLeft + (rect.width() - text_width) / 2, - rect.fTop + kTextSize + kTopTextPadding, - *text_paint); - canvas->AsCanvasSkia()->restore(); + canvas->clipRect(rect); + canvas->drawText(text.c_str(), text.size(), + rect.fLeft + (rect.width() - text_width) / 2, + rect.fTop + kTextSize + kTopTextPadding, + *text_paint); + canvas->restore(); } diff --git a/gfx/canvas.h b/gfx/canvas.h index d66db03..589d77d 100644 --- a/gfx/canvas.h +++ b/gfx/canvas.h @@ -5,195 +5,27 @@ #ifndef GFX_CANVAS_H_ #define GFX_CANVAS_H_ -#include <string> - -#include "gfx/native_widget_types.h" -// TODO(beng): remove this include when we no longer depend on SkTypes. -#include "skia/ext/platform_canvas.h" +#include "gfx/canvas_skia.h" namespace gfx { -class CanvasSkia; -class Font; -class Rect; - -// TODO(beng): documentation. -class Canvas { +// Temporary compatibility shim, remove once Canvas2->Canvas. +class Canvas : public CanvasSkia { public: - // Specifies the alignment for text rendered with the DrawStringInt method. - enum { - TEXT_ALIGN_LEFT = 1, - TEXT_ALIGN_CENTER = 2, - TEXT_ALIGN_RIGHT = 4, - TEXT_VALIGN_TOP = 8, - TEXT_VALIGN_MIDDLE = 16, - TEXT_VALIGN_BOTTOM = 32, - - // Specifies the text consists of multiple lines. - MULTI_LINE = 64, - - // By default DrawStringInt does not process the prefix ('&') character - // specially. That is, the string "&foo" is rendered as "&foo". When - // rendering text from a resource that uses the prefix character for - // mnemonics, the prefix should be processed and can be rendered as an - // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX). - SHOW_PREFIX = 128, - HIDE_PREFIX = 256, - - // Prevent ellipsizing - NO_ELLIPSIS = 512, - - // Specifies if words can be split by new lines. - // This only works with MULTI_LINE. - CHARACTER_BREAK = 1024, - - // Instructs DrawStringInt() to render the text using RTL directionality. - // In most cases, passing this flag is not necessary because information - // about the text directionality is going to be embedded within the string - // in the form of special Unicode characters. However, we don't insert - // directionality characters into strings if the locale is LTR because some - // platforms (for example, an English Windows XP with no RTL fonts - // installed) don't support these characters. Thus, this flag should be - // used to render text using RTL directionality when the locale is LTR. - FORCE_RTL_DIRECTIONALITY = 2048, - }; - - virtual ~Canvas() {} - - // Creates an empty canvas. Must be initialized before it can be used. - static Canvas* CreateCanvas(); - - // Creates a canvas with the specified size. - static Canvas* CreateCanvas(int width, int height, bool is_opaque); - - // Retrieves the clip rectangle and sets it in the specified rectangle if any. - // Returns true if the clip rect is non-empty. - virtual bool GetClipRect(gfx::Rect* clip_rect) = 0; - - // Wrapper function that takes integer arguments. - // Returns true if the clip is non-empty. - // See clipRect for specifics. - virtual bool ClipRectInt(int x, int y, int w, int h) = 0; - - // Test whether the provided rectangle intersects the current clip rect. - virtual bool IntersectsClipRectInt(int x, int y, int w, int h) = 0; - - // Wrapper function that takes integer arguments. - // See translate() for specifics. - virtual void TranslateInt(int x, int y) = 0; - - // Wrapper function that takes integer arguments. - // See scale() for specifics. - virtual void ScaleInt(int x, int y) = 0; - - // Fills the given rectangle with the given paint's parameters. - virtual void FillRectInt(int x, int y, int w, int h, - const SkPaint& paint) = 0; - - // Fills the specified region with the specified color using a transfer - // mode of SkXfermode::kSrcOver_Mode. - virtual void FillRectInt(const SkColor& color, int x, int y, int w, - int h) = 0; - - // Draws a single pixel rect in the specified region with the specified - // color, using a transfer mode of SkXfermode::kSrcOver_Mode. - // - // NOTE: if you need a single pixel line, use DraLineInt. - virtual void DrawRectInt(const SkColor& color, int x, int y, int w, - int h) = 0; - - // Draws a single pixel rect in the specified region with the specified - // color and transfer mode. - // - // NOTE: if you need a single pixel line, use DraLineInt. - virtual void DrawRectInt(const SkColor& color, int x, int y, int w, int h, - SkXfermode::Mode mode) = 0; - - // Draws a single pixel line with the specified color. - virtual void DrawLineInt(const SkColor& color, int x1, int y1, int x2, - int y2) = 0; - - // Draws a bitmap with the origin at the specified location. The upper left - // corner of the bitmap is rendered at the specified location. - virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y) = 0; - - // Draws a bitmap with the origin at the specified location, using the - // specified paint. The upper left corner of the bitmap is rendered at the - // specified location. - virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y, - const SkPaint& paint) = 0; - - // Draws a portion of a bitmap in the specified location. The src parameters - // correspond to the region of the bitmap to draw in the region defined - // by the dest coordinates. - // - // If the width or height of the source differs from that of the destination, - // the bitmap will be scaled. When scaling down, it is highly recommended - // that you call buildMipMap(false) on your bitmap to ensure that it has - // a mipmap, which will result in much higher-quality output. Set |filter| - // to use filtering for bitmaps, otherwise the nearest-neighbor algorithm - // is used for resampling. - // - // An optional custom SkPaint can be provided. - 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) = 0; - 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) = 0; - - // 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. - virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, - const SkColor& color, int x, int y, int w, - int h) = 0; - virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, - const SkColor& color, - const gfx::Rect& display_rect) = 0; - - // Draws text with the specified color, font and location. The last argument - // specifies flags for how the text should be rendered. It can be one of - // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT. - virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, - const SkColor& color, int x, int y, int w, int h, - int flags) = 0; - - // Draws a dotted gray rectangle used for focus purposes. - virtual void DrawFocusRect(int x, int y, int width, int height) = 0; - - // Tiles the image in the specified region. - virtual void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, - int h) = 0; - virtual void TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, - int dest_x, int dest_y, int w, int h) = 0; - - // TODO(beng): remove this once we don't need to use any skia-specific methods - // through this interface. - // A quick and dirty way to obtain the underlying SkCanvas. - virtual CanvasSkia* AsCanvasSkia() { return NULL; } - virtual const CanvasSkia* AsCanvasSkia() const { return NULL; } -}; - -class CanvasPaint { - public: - virtual ~CanvasPaint() {} - - // Creates a canvas that paints to |view| when it is destroyed. The canvas is - // sized to the client area of |view|. - static CanvasPaint* CreateCanvasPaint(gfx::NativeView view); - - // Returns true if the canvas has an invalid rect that needs to be repainted. - virtual bool IsValid() const = 0; - - // Returns the rectangle that is invalid. - virtual gfx::Rect GetInvalidRect() const = 0; - - // Returns the underlying Canvas. - virtual Canvas* AsCanvas() = 0; + Canvas(int width, int height, bool is_opaque) + : CanvasSkia(width, height, is_opaque) { + } + Canvas() : CanvasSkia() {} + + // Overridden from Canvas2: + Canvas* AsCanvas() { + return this; + } + + private: + DISALLOW_COPY_AND_ASSIGN(Canvas); }; -} // namespace gfx; +} #endif // GFX_CANVAS_H_ diff --git a/gfx/canvas_2.h b/gfx/canvas_2.h new file mode 100644 index 0000000..bf7e244 --- /dev/null +++ b/gfx/canvas_2.h @@ -0,0 +1,201 @@ +// 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_2_H_ +#define GFX_CANVAS_2_H_ + +#include <string> + +#include "gfx/native_widget_types.h" +// TODO(beng): remove this include when we no longer depend on SkTypes. +#include "skia/ext/platform_canvas.h" + +namespace gfx { + +class Canvas; +class Font; +class Rect; + +// TODO(beng): documentation. +class Canvas2 { + public: + // Specifies the alignment for text rendered with the DrawStringInt method. + enum { + TEXT_ALIGN_LEFT = 1, + TEXT_ALIGN_CENTER = 2, + TEXT_ALIGN_RIGHT = 4, + TEXT_VALIGN_TOP = 8, + TEXT_VALIGN_MIDDLE = 16, + TEXT_VALIGN_BOTTOM = 32, + + // Specifies the text consists of multiple lines. + MULTI_LINE = 64, + + // By default DrawStringInt does not process the prefix ('&') character + // specially. That is, the string "&foo" is rendered as "&foo". When + // rendering text from a resource that uses the prefix character for + // mnemonics, the prefix should be processed and can be rendered as an + // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX). + SHOW_PREFIX = 128, + HIDE_PREFIX = 256, + + // Prevent ellipsizing + NO_ELLIPSIS = 512, + + // Specifies if words can be split by new lines. + // This only works with MULTI_LINE. + CHARACTER_BREAK = 1024, + + // Instructs DrawStringInt() to render the text using RTL directionality. + // In most cases, passing this flag is not necessary because information + // about the text directionality is going to be embedded within the string + // in the form of special Unicode characters. However, we don't insert + // directionality characters into strings if the locale is LTR because some + // platforms (for example, an English Windows XP with no RTL fonts + // installed) don't support these characters. Thus, this flag should be + // used to render text using RTL directionality when the locale is LTR. + FORCE_RTL_DIRECTIONALITY = 2048, + }; + + virtual ~Canvas2() {} + + // Creates an empty canvas. Must be initialized before it can be used. + static Canvas2* CreateCanvas(); + + // Creates a canvas with the specified size. + static Canvas2* CreateCanvas(int width, int height, bool is_opaque); + + // Retrieves the clip rectangle and sets it in the specified rectangle if any. + // Returns true if the clip rect is non-empty. + virtual bool GetClipRect(gfx::Rect* clip_rect) = 0; + + // Wrapper function that takes integer arguments. + // Returns true if the clip is non-empty. + // See clipRect for specifics. + virtual bool ClipRectInt(int x, int y, int w, int h) = 0; + + // Test whether the provided rectangle intersects the current clip rect. + virtual bool IntersectsClipRectInt(int x, int y, int w, int h) = 0; + + // Wrapper function that takes integer arguments. + // See translate() for specifics. + virtual void TranslateInt(int x, int y) = 0; + + // Wrapper function that takes integer arguments. + // See scale() for specifics. + virtual void ScaleInt(int x, int y) = 0; + + // Fills the given rectangle with the given paint's parameters. + virtual void FillRectInt(int x, int y, int w, int h, + const SkPaint& paint) = 0; + + // Fills the specified region with the specified color using a transfer + // mode of SkXfermode::kSrcOver_Mode. + virtual void FillRectInt(const SkColor& color, int x, int y, int w, + int h) = 0; + + // Draws a single pixel rect in the specified region with the specified + // color, using a transfer mode of SkXfermode::kSrcOver_Mode. + // + // NOTE: if you need a single pixel line, use DraLineInt. + virtual void DrawRectInt(const SkColor& color, int x, int y, int w, + int h) = 0; + + // Draws a single pixel rect in the specified region with the specified + // color and transfer mode. + // + // NOTE: if you need a single pixel line, use DraLineInt. + virtual void DrawRectInt(const SkColor& color, int x, int y, int w, int h, + SkXfermode::Mode mode) = 0; + + // Draws a single pixel line with the specified color. + virtual void DrawLineInt(const SkColor& color, int x1, int y1, int x2, + int y2) = 0; + + // Draws a bitmap with the origin at the specified location. The upper left + // corner of the bitmap is rendered at the specified location. + virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y) = 0; + + // Draws a bitmap with the origin at the specified location, using the + // specified paint. The upper left corner of the bitmap is rendered at the + // specified location. + virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y, + const SkPaint& paint) = 0; + + // Draws a portion of a bitmap in the specified location. The src parameters + // correspond to the region of the bitmap to draw in the region defined + // by the dest coordinates. + // + // If the width or height of the source differs from that of the destination, + // the bitmap will be scaled. When scaling down, it is highly recommended + // that you call buildMipMap(false) on your bitmap to ensure that it has + // a mipmap, which will result in much higher-quality output. Set |filter| + // to use filtering for bitmaps, otherwise the nearest-neighbor algorithm + // is used for resampling. + // + // An optional custom SkPaint can be provided. + 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) = 0; + 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) = 0; + + // 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. + virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, + const SkColor& color, int x, int y, int w, + int h) = 0; + virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, + const SkColor& color, + const gfx::Rect& display_rect) = 0; + + // Draws text with the specified color, font and location. The last argument + // specifies flags for how the text should be rendered. It can be one of + // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT. + virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, + const SkColor& color, int x, int y, int w, int h, + int flags) = 0; + + // Draws a dotted gray rectangle used for focus purposes. + virtual void DrawFocusRect(int x, int y, int width, int height) = 0; + + // Tiles the image in the specified region. + virtual void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, + int h) = 0; + virtual void TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, + int dest_x, int dest_y, int w, int h) = 0; + + // Extracts a bitmap from the contents of this canvas. + virtual SkBitmap ExtractBitmap() const = 0; + + // TODO(beng): remove this once we don't need to use any skia-specific methods + // through this interface. + // A quick and dirty way to obtain the underlying SkCanvas. + virtual Canvas* AsCanvas() { return NULL; } +}; + +class CanvasPaint2 { + public: + virtual ~CanvasPaint2() {} + + // Creates a canvas that paints to |view| when it is destroyed. The canvas is + // sized to the client area of |view|. + static CanvasPaint2* CreateCanvasPaint(gfx::NativeView view); + + // Returns true if the canvas has an invalid rect that needs to be repainted. + virtual bool IsValid() const = 0; + + // Returns the rectangle that is invalid. + virtual gfx::Rect GetInvalidRect() const = 0; + + // Returns the underlying Canvas2. + virtual Canvas2* AsCanvas2() = 0; +}; + +} // namespace gfx; + +#endif // GFX_CANVAS_2_H_ diff --git a/gfx/canvas_skia.cc b/gfx/canvas_skia.cc index 8fb752de..8fa763a 100644 --- a/gfx/canvas_skia.cc +++ b/gfx/canvas_skia.cc @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include <limits> #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" @@ -18,17 +19,6 @@ namespace gfx { -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 - // to call extractSubset or the copy constructor, since we want an actual copy - // of the bitmap. - SkBitmap result; - device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); - return result; -} - bool CanvasSkia::GetClipRect(gfx::Rect* r) { SkRect clip; if (!getClipBounds(&clip)) { @@ -273,12 +263,15 @@ void CanvasSkia::TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, restore(); } -CanvasSkia* CanvasSkia::AsCanvasSkia() { - return this; -} +SkBitmap CanvasSkia::ExtractBitmap() const { + const SkBitmap& device_bitmap = getDevice()->accessBitmap(false); -const CanvasSkia* CanvasSkia::AsCanvasSkia() const { - return this; + // Make a bitmap to return, and a canvas to draw into it. We don't just want + // to call extractSubset or the copy constuctor, since we want an actual copy + // of the bitmap. + SkBitmap result; + device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); + return result; } // static @@ -289,19 +282,19 @@ int CanvasSkia::DefaultCanvasTextAlignment() { } //////////////////////////////////////////////////////////////////////////////// -// Canvas, public: +// Canvas2, public: -Canvas* Canvas::CreateCanvas() { - return new CanvasSkia; +Canvas2* Canvas2::CreateCanvas() { + return new Canvas; } -Canvas* Canvas::CreateCanvas(int width, int height, bool is_opaque) { - return new CanvasSkia(width, height, is_opaque); +Canvas2* Canvas2::CreateCanvas(int width, int height, bool is_opaque) { + return new Canvas(width, height, is_opaque); } #if defined(OS_WIN) // TODO(beng): move to canvas_win.cc, etc. -class CanvasPaintWin : public CanvasSkiaPaint, public CanvasPaint { +class CanvasPaintWin : public CanvasSkiaPaint, public CanvasPaint2 { public: CanvasPaintWin(gfx::NativeView view) : CanvasSkiaPaint(view) {} @@ -314,13 +307,13 @@ class CanvasPaintWin : public CanvasSkiaPaint, public CanvasPaint { return gfx::Rect(paintStruct().rcPaint); } - virtual Canvas* AsCanvas() { + virtual Canvas2* AsCanvas2() { return this; } }; #endif -CanvasPaint* CanvasPaint::CreateCanvasPaint(gfx::NativeView view) { +CanvasPaint2* CanvasPaint2::CreateCanvasPaint(gfx::NativeView view) { #if defined(OS_WIN) return new CanvasPaintWin(view); #else diff --git a/gfx/canvas_skia.h b/gfx/canvas_skia.h index cae4ac1..9a976fd 100644 --- a/gfx/canvas_skia.h +++ b/gfx/canvas_skia.h @@ -6,7 +6,7 @@ #define GFX_CANVAS_SKIA_H_ #include "base/basictypes.h" -#include "gfx/canvas.h" +#include "gfx/canvas_2.h" #include "skia/ext/platform_canvas.h" #if defined(OS_POSIX) && !defined(OS_MACOSX) @@ -33,7 +33,7 @@ class Canvas; // the variant that does not take a SkXfermode::Mode uses a transfer mode // of kSrcOver_Mode. class CanvasSkia : public skia::PlatformCanvas, - public Canvas { + public Canvas2 { public: // Creates an empty Canvas. Callers must use initialize before using the // canvas. @@ -76,9 +76,6 @@ class CanvasSkia : public skia::PlatformCanvas, int x, int y, int w, int h, int flags); #endif - // Extracts a bitmap from the contents of this canvas. - SkBitmap ExtractBitmap() const; - // Overridden from Canvas2: virtual bool GetClipRect(gfx::Rect* clip_rect); virtual bool ClipRectInt(int x, int y, int w, int h); @@ -118,8 +115,7 @@ class CanvasSkia : public skia::PlatformCanvas, 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 CanvasSkia* AsCanvasSkia(); - virtual const CanvasSkia* AsCanvasSkia() const; + virtual SkBitmap ExtractBitmap() const; private: #if defined(OS_WIN) diff --git a/gfx/canvas_skia_linux.cc b/gfx/canvas_skia_linux.cc index 680476f..59e0e29 100644 --- a/gfx/canvas_skia_linux.cc +++ b/gfx/canvas_skia_linux.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include <cairo/cairo.h> #include <gtk/gtk.h> diff --git a/gfx/canvas_skia_mac.mm b/gfx/canvas_skia_mac.mm index 7836869..29102fd 100644 --- a/gfx/canvas_skia_mac.mm +++ b/gfx/canvas_skia_mac.mm @@ -4,7 +4,7 @@ #import <Cocoa/Cocoa.h> -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "base/scoped_cftyperef.h" #include "base/sys_string_conversions.h" diff --git a/gfx/canvas_skia_paint.h b/gfx/canvas_skia_paint.h index ac11ff0..4e6f768 100644 --- a/gfx/canvas_skia_paint.h +++ b/gfx/canvas_skia_paint.h @@ -5,7 +5,7 @@ #ifndef GFX_CANVAS_SKIA_PAINT_H_ #define GFX_CANVAS_SKIA_PAINT_H_ -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "skia/ext/canvas_paint.h" // Define a gfx::CanvasSkiaPaint type that wraps our gfx::Canvas like the @@ -13,7 +13,7 @@ namespace gfx { -typedef skia::CanvasPaintT<CanvasSkia> CanvasSkiaPaint; +typedef skia::CanvasPaintT<Canvas> CanvasSkiaPaint; } // namespace gfx diff --git a/gfx/canvas_skia_win.cc b/gfx/canvas_skia_win.cc index f3c5f8f..4177ef5 100644 --- a/gfx/canvas_skia_win.cc +++ b/gfx/canvas_skia_win.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include <limits> diff --git a/gfx/font_mac.mm b/gfx/font_mac.mm index e569a35..f964d94 100644 --- a/gfx/font_mac.mm +++ b/gfx/font_mac.mm @@ -9,7 +9,7 @@ #include "base/logging.h" #include "base/scoped_nsobject.h" #include "base/sys_string_conversions.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" namespace gfx { @@ -60,8 +60,7 @@ int Font::ave_char_width() const { int Font::GetStringWidth(const std::wstring& text) const { int width = 0, height = 0; - CanvasSkia::SizeStringInt(text, *this, &width, &height, - gfx::Canvas::NO_ELLIPSIS); + Canvas::SizeStringInt(text, *this, &width, &height, gfx::Canvas::NO_ELLIPSIS); return width; } diff --git a/gfx/font_skia.cc b/gfx/font_skia.cc index 0289cdb..97a3c85 100644 --- a/gfx/font_skia.cc +++ b/gfx/font_skia.cc @@ -11,7 +11,7 @@ #include "base/logging.h" #include "base/string_piece.h" #include "base/sys_string_conversions.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/core/SkPaint.h" @@ -177,8 +177,7 @@ void Font::PaintSetup(SkPaint* paint) const { int Font::GetStringWidth(const std::wstring& text) const { int width = 0, height = 0; - CanvasSkia::SizeStringInt(text, *this, &width, &height, - gfx::Canvas::NO_ELLIPSIS); + Canvas::SizeStringInt(text, *this, &width, &height, gfx::Canvas::NO_ELLIPSIS); return width; } diff --git a/gfx/font_win.cc b/gfx/font_win.cc index f9b7243..4d4d28e 100644 --- a/gfx/font_win.cc +++ b/gfx/font_win.cc @@ -12,7 +12,7 @@ #include "base/logging.h" #include "base/string_util.h" #include "base/win_util.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" namespace gfx { @@ -171,8 +171,7 @@ Font Font::DeriveFont(int size_delta, int style) const { int Font::GetStringWidth(const std::wstring& text) const { int width = 0, height = 0; - CanvasSkia::SizeStringInt(text, *this, &width, &height, - gfx::Canvas::NO_ELLIPSIS); + Canvas::SizeStringInt(text, *this, &width, &height, gfx::Canvas::NO_ELLIPSIS); return width; } diff --git a/gfx/gfx.gyp b/gfx/gfx.gyp index 592901c..c0d4000 100644 --- a/gfx/gfx.gyp +++ b/gfx/gfx.gyp @@ -63,6 +63,7 @@ 'blit.cc', 'blit.h', 'canvas.h', + 'canvas_2.h', 'canvas_skia.h', 'canvas_skia.cc', 'canvas_skia_linux.cc', diff --git a/views/background.cc b/views/background.cc index f135138..a791f7f 100644 --- a/views/background.cc +++ b/views/background.cc @@ -5,7 +5,7 @@ #include "views/background.h" #include "base/logging.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/color_utils.h" #include "skia/ext/skia_utils_win.h" #include "third_party/skia/include/core/SkPaint.h" @@ -25,7 +25,7 @@ class SolidBackground : public Background { void Paint(gfx::Canvas* canvas, View* view) const { // Fill the background. Note that we don't constrain to the bounds as // canvas is already clipped for us. - canvas->AsCanvasSkia()->drawColor(get_color()); + canvas->drawColor(get_color()); } private: diff --git a/views/controls/button/text_button.cc b/views/controls/button/text_button.cc index f2b7613..98c69fe 100644 --- a/views/controls/button/text_button.cc +++ b/views/controls/button/text_button.cc @@ -8,7 +8,7 @@ #include "app/throb_animation.h" #include "app/resource_bundle.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "views/controls/button/button.h" #include "views/event.h" #include "grit/app_resources.h" @@ -256,13 +256,12 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) { if (show_highlighted_ && hover_animation_->is_animating()) { // Draw the hover bitmap into an offscreen buffer, then blend it // back into the current canvas. - canvas->AsCanvasSkia()->saveLayerAlpha(NULL, + canvas->saveLayerAlpha(NULL, static_cast<int>(hover_animation_->GetCurrentValue() * 255), SkCanvas::kARGB_NoClipLayer_SaveFlag); - canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, - SkXfermode::kClear_Mode); + canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); PaintBorder(canvas); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } else if ((show_highlighted_ && (state_ == BS_HOT || state_ == BS_PUSHED)) || (state_ == BS_NORMAL && normal_has_border_)) { @@ -331,17 +330,19 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) { else text_color = color_; - int draw_string_flags = gfx::CanvasSkia::DefaultCanvasTextAlignment() | + int draw_string_flags = gfx::Canvas::DefaultCanvasTextAlignment() | PrefixTypeToCanvasType(prefix_type_); if (for_drag) { #if defined(OS_WIN) // TODO(erg): Either port DrawStringWithHalo to linux or find an // alternative here. - canvas->AsCanvasSkia()->DrawStringWithHalo( - text_, font_, text_color, color_highlight_, text_bounds.x(), - text_bounds.y(), text_bounds.width(), text_bounds.height(), - draw_string_flags); + canvas->DrawStringWithHalo(text_, font_, text_color, color_highlight_, + text_bounds.x(), + text_bounds.y(), + text_bounds.width(), + text_bounds.height(), + draw_string_flags); #else canvas->DrawStringInt(text_, font_, @@ -380,7 +381,7 @@ void TextButton::UpdateColor() { void TextButton::UpdateTextSize() { int width = 0, height = 0; - gfx::CanvasSkia::SizeStringInt( + gfx::Canvas::SizeStringInt( text_, font_, &width, &height, gfx::Canvas::NO_ELLIPSIS | PrefixTypeToCanvasType(prefix_type_)); text_size_.SetSize(width, font_.height()); diff --git a/views/controls/label.cc b/views/controls/label.cc index d30a62b..88a755d 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -13,7 +13,7 @@ #include "base/i18n/rtl.h" #include "base/logging.h" #include "base/utf_string_conversions.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/color_utils.h" #include "gfx/font.h" #include "gfx/insets.h" @@ -67,7 +67,7 @@ int Label::GetHeightForWidth(int w) { w = std::max(0, w - GetInsets().width()); int h = font_.height(); - gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, ComputeMultiLineFlags()); + gfx::Canvas::SizeStringInt(text_, font_, &w, &h, ComputeMultiLineFlags()); return h + GetInsets().height(); } @@ -388,7 +388,7 @@ gfx::Size Label::GetTextSize() const { int flags = ComputeMultiLineFlags(); if (!is_multi_line_) flags |= gfx::Canvas::NO_ELLIPSIS; - gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags); + gfx::Canvas::SizeStringInt(text_, font_, &w, &h, flags); text_size_.SetSize(w, h); text_size_valid_ = true; } diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index 955451a..de31f02 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -9,7 +9,7 @@ #include "base/i18n/rtl.h" #include "base/keyboard_codes.h" #include "base/time.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "views/controls/button/menu_button.h" #include "views/controls/menu/menu_scroll_view_container.h" #include "views/controls/menu/submenu_view.h" @@ -470,7 +470,7 @@ void MenuController::OnMouseDragged(SubmenuView* source, View::ConvertPointToScreen(source->GetScrollViewContainer(), &press_loc); View::ConvertPointToView(NULL, item, &press_loc); // TODO(beng): Convert to CanvasSkia - gfx::CanvasSkia canvas(item->width(), item->height(), false); + gfx::Canvas canvas(item->width(), item->height(), false); item->Paint(&canvas, true); OSExchangeData data; diff --git a/views/controls/menu/menu_item_view_gtk.cc b/views/controls/menu/menu_item_view_gtk.cc index db21e01..f3e7556 100644 --- a/views/controls/menu/menu_item_view_gtk.cc +++ b/views/controls/menu/menu_item_view_gtk.cc @@ -5,7 +5,7 @@ #include "views/controls/menu/menu_item_view.h" #include "app/resource_bundle.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/favicon_size.h" #include "grit/app_resources.h" #include "third_party/skia/include/effects/SkGradientShader.h" @@ -70,8 +70,7 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { // only need the background when we want it to look different, as when we're // selected. if (render_selection) - canvas->AsCanvasSkia()->drawColor(kSelectedBackgroundColor, - SkXfermode::kSrc_Mode); + canvas->drawColor(kSelectedBackgroundColor, SkXfermode::kSrc_Mode); // Render the check. if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) { @@ -104,13 +103,13 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { paint.setShader(shader); shader->unref(); int radius = kIndicatorSize / 2; - canvas->AsCanvasSkia()->drawCircle(radius, radius, radius, paint); + canvas->drawCircle(radius, radius, radius, paint); paint.setStrokeWidth(SkIntToScalar(0)); paint.setShader(NULL); paint.setStyle(SkPaint::kStroke_Style); paint.setColor(kBaseStroke); - canvas->AsCanvasSkia()->drawCircle(radius, radius, radius, paint); + canvas->drawCircle(radius, radius, radius, paint); if (GetDelegate()->IsItemChecked(GetCommand())) { SkPoint selected_gradient_points[2]; @@ -126,15 +125,13 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { paint.setShader(shader); shader->unref(); paint.setStyle(SkPaint::kFill_Style); - canvas->AsCanvasSkia()->drawCircle(radius, radius, - kSelectedIndicatorSize / 2, paint); + canvas->drawCircle(radius, radius, kSelectedIndicatorSize / 2, paint); paint.setStrokeWidth(SkIntToScalar(0)); paint.setShader(NULL); paint.setStyle(SkPaint::kStroke_Style); paint.setColor(kIndicatorStroke); - canvas->AsCanvasSkia()->drawCircle(radius, radius, - kSelectedIndicatorSize / 2, paint); + canvas->drawCircle(radius, radius, kSelectedIndicatorSize / 2, paint); } canvas->TranslateInt( diff --git a/views/controls/menu/menu_item_view_win.cc b/views/controls/menu/menu_item_view_win.cc index b491092..2ac0921 100644 --- a/views/controls/menu/menu_item_view_win.cc +++ b/views/controls/menu/menu_item_view_win.cc @@ -8,7 +8,7 @@ #include <Vssym32.h> #include "app/l10n_util.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/native_theme_win.h" #include "grit/app_strings.h" #include "views/controls/menu/menu_config.h" @@ -34,7 +34,7 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { GetChildViewCount() == 0); int state = render_selection ? MPI_HOT : (IsEnabled() ? MPI_NORMAL : MPI_DISABLED); - HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint(); + HDC dc = canvas->beginPlatformPaint(); // The gutter is rendered before the background. if (config.render_gutter && !for_drag) { @@ -87,10 +87,10 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { // foreground and background colors are for the text to draw the correct // halo. Instead, just draw black on white, which will look good in most // cases. - canvas->AsCanvasSkia()->DrawStringWithHalo( - GetTitle(), font, 0x00000000, 0xFFFFFFFF, text_bounds.x(), - text_bounds.y(), text_bounds.width(), text_bounds.height(), - GetRootMenuItem()->GetDrawStringFlags()); + canvas->DrawStringWithHalo(GetTitle(), font, 0x00000000, 0xFFFFFFFF, + text_bounds.x(), text_bounds.y(), + text_bounds.width(), text_bounds.height(), + GetRootMenuItem()->GetDrawStringFlags()); } else { canvas->DrawStringInt(GetTitle(), font, fg_color, text_bounds.x(), text_bounds.y(), text_bounds.width(), @@ -131,7 +131,7 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { NativeTheme::MENU, dc, MENU_POPUPSUBMENU, state_id, &arrow_rect, arrow_direction, render_selection); } - canvas->AsCanvasSkia()->endPlatformPaint(); + canvas->endPlatformPaint(); } void MenuItemView::PaintCheck(HDC dc, int state_id, diff --git a/views/controls/menu/menu_scroll_view_container.cc b/views/controls/menu/menu_scroll_view_container.cc index d3a7ae8..b538f5b 100644 --- a/views/controls/menu/menu_scroll_view_container.cc +++ b/views/controls/menu/menu_scroll_view_container.cc @@ -10,7 +10,7 @@ #include <Vssym32.h> #endif -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/color_utils.h" #include "views/border.h" #include "third_party/skia/include/effects/SkGradientShader.h" @@ -83,14 +83,14 @@ class MenuScrollButton : public View { const MenuConfig& config = MenuConfig::instance(); #if defined(OS_WIN) - HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint(); + HDC dc = canvas->beginPlatformPaint(); // The background. RECT item_bounds = { 0, 0, width(), height() }; NativeTheme::instance()->PaintMenuItemBackground( NativeTheme::MENU, dc, MENU_POPUPITEM, MPI_NORMAL, false, &item_bounds); - canvas->AsCanvasSkia()->endPlatformPaint(); + canvas->endPlatformPaint(); SkColor arrow_color = color_utils::GetSysSkColor(COLOR_MENUTEXT); #else @@ -185,11 +185,11 @@ void MenuScrollViewContainer::PaintBackground(gfx::Canvas* canvas) { } #if defined(OS_WIN) - HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint(); + HDC dc = canvas->beginPlatformPaint(); RECT bounds = {0, 0, width(), height()}; NativeTheme::instance()->PaintMenuBackground( NativeTheme::MENU, dc, MENU_POPUPBACKGROUND, 0, &bounds); - canvas->AsCanvasSkia()->endPlatformPaint(); + canvas->endPlatformPaint(); #elif defined(OS_CHROMEOS) static const SkColor kGradientColors[2] = { SK_ColorWHITE, @@ -220,8 +220,7 @@ void MenuScrollViewContainer::PaintBackground(gfx::Canvas* canvas) { canvas->FillRectInt(0, 0, width(), height(), paint); #else // This is the same as COLOR_TOOLBAR. - canvas->AsCanvasSkia()->drawColor(SkColorSetRGB(210, 225, 246), - SkXfermode::kSrc_Mode); + canvas->drawColor(SkColorSetRGB(210, 225, 246), SkXfermode::kSrc_Mode); #endif } diff --git a/views/controls/menu/menu_separator_win.cc b/views/controls/menu/menu_separator_win.cc index ed3f34f..58e2bb4 100644 --- a/views/controls/menu/menu_separator_win.cc +++ b/views/controls/menu/menu_separator_win.cc @@ -8,7 +8,7 @@ #include <uxtheme.h> #include <Vssym32.h> -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/native_theme_win.h" #include "views/controls/menu/menu_config.h" #include "views/controls/menu/menu_item_view.h" @@ -20,7 +20,7 @@ void MenuSeparator::Paint(gfx::Canvas* canvas) { // The gutter is rendered before the background. int start_x = 0; int start_y = height() / 3; - HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint(); + HDC dc = canvas->beginPlatformPaint(); if (config.render_gutter) { // If render_gutter is true, we're on Vista and need to render the // gutter, then indent the separator from the gutter. @@ -36,7 +36,7 @@ void MenuSeparator::Paint(gfx::Canvas* canvas) { RECT separator_bounds = { start_x, start_y, width(), height() }; gfx::NativeTheme::instance()->PaintMenuSeparator( dc, MENU_POPUPSEPARATOR, MPI_NORMAL, &separator_bounds); - canvas->AsCanvasSkia()->endPlatformPaint(); + canvas->endPlatformPaint(); } gfx::Size MenuSeparator::GetPreferredSize() { diff --git a/views/controls/progress_bar.cc b/views/controls/progress_bar.cc index 1006acd..19f10c5 100644 --- a/views/controls/progress_bar.cc +++ b/views/controls/progress_bar.cc @@ -10,7 +10,7 @@ #include "app/resource_bundle.h" #include "base/logging.h" #include "base/string_util.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/color_utils.h" #include "gfx/font.h" #include "gfx/insets.h" @@ -75,7 +75,7 @@ static void FillRoundRect(gfx::Canvas* canvas, } else { paint.setColor(gradient_start_color); } - canvas->AsCanvasSkia()->drawPath(path, paint); + canvas->drawPath(path, paint); } static void StrokeRoundRect(gfx::Canvas* canvas, @@ -92,7 +92,7 @@ static void StrokeRoundRect(gfx::Canvas* canvas, paint.setStyle(SkPaint::kStroke_Style); paint.setFlags(SkPaint::kAntiAlias_Flag); paint.setStrokeWidth(SkIntToScalar(stroke_width)); - canvas->AsCanvasSkia()->drawPath(path, paint); + canvas->drawPath(path, paint); } } // anonymous namespace diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.cc b/views/controls/tabbed_pane/native_tabbed_pane_win.cc index 832d4a2..87f2ebb 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_win.cc +++ b/views/controls/tabbed_pane/native_tabbed_pane_win.cc @@ -10,7 +10,7 @@ #include "app/resource_bundle.h" #include "base/logging.h" #include "base/stl_util-inl.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/font.h" #include "gfx/native_theme_win.h" #include "views/controls/tabbed_pane/tabbed_pane.h" @@ -36,10 +36,10 @@ class TabBackground : public Background { virtual ~TabBackground() {} virtual void Paint(gfx::Canvas* canvas, View* view) const { - HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint(); + HDC dc = canvas->beginPlatformPaint(); RECT r = {0, 0, view->width(), view->height()}; gfx::NativeTheme::instance()->PaintTabPanelBackground(dc, &r); - canvas->AsCanvasSkia()->endPlatformPaint(); + canvas->endPlatformPaint(); } private: diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc index 8b86a6e..75425c2 100644 --- a/views/controls/table/table_view.cc +++ b/views/controls/table/table_view.cc @@ -16,7 +16,7 @@ #include "base/i18n/rtl.h" #include "base/string_util.h" #include "base/win_util.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/favicon_size.h" #include "gfx/font.h" #include "gfx/icon_util.h" @@ -1157,7 +1157,7 @@ void TableView::PaintAltText() { // Pad by 1 for halo. canvas.DrawStringWithHalo(alt_text_, font, SK_ColorDKGRAY, SK_ColorWHITE, 1, 1, bounds.width() - 2, bounds.height() - 2, - gfx::CanvasSkia::DefaultCanvasTextAlignment()); + gfx::Canvas::DefaultCanvasTextAlignment()); canvas.getTopPlatformDevice().drawToHDC(dc, bounds.x(), bounds.y(), NULL); ReleaseDC(GetNativeControlHWND(), dc); } diff --git a/views/drag_utils.cc b/views/drag_utils.cc index 0b5ffa0..8fbd79a 100644 --- a/views/drag_utils.cc +++ b/views/drag_utils.cc @@ -10,6 +10,7 @@ #include "base/file_util.h" #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" @@ -48,7 +49,8 @@ void SetURLAndDragImage(const GURL& url, button.SetBounds(0, 0, prefsize.width(), prefsize.height()); // Render the image. - gfx::CanvasSkia canvas(prefsize.width(), prefsize.height(), false); + // TODO(beng): Convert to CanvasSkia + gfx::Canvas canvas(prefsize.width(), prefsize.height(), false); button.Paint(&canvas, true); SetDragImageOnDataObject(canvas, prefsize, gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data); @@ -68,7 +70,8 @@ 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; - gfx::CanvasSkia canvas(width, height, false /* translucent */); + // TODO(beng): Convert to CanvasSkia + gfx::Canvas canvas(width, height, false /* translucent */); // Paint the icon. canvas.DrawBitmapInt(*icon, (width - icon->width()) / 2, 0); diff --git a/views/drag_utils_win.cc b/views/drag_utils_win.cc index 3c951ed..74663a6 100644 --- a/views/drag_utils_win.cc +++ b/views/drag_utils_win.cc @@ -10,7 +10,7 @@ #include "app/os_exchange_data.h" #include "app/os_exchange_data_provider_win.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/gdi_util.h" namespace drag_utils { @@ -47,7 +47,7 @@ static HBITMAP CreateBitmapFromCanvas(const gfx::Canvas& canvas, HDC compatible_dc = CreateCompatibleDC(screen_dc); HGDIOBJ old_object = SelectObject(compatible_dc, bitmap); BitBlt(compatible_dc, 0, 0, width, height, - canvas.AsCanvasSkia()->getTopPlatformDevice().getBitmapDC(), + canvas.getTopPlatformDevice().getBitmapDC(), 0, 0, SRCCOPY); SelectObject(compatible_dc, old_object); ReleaseDC(NULL, compatible_dc); diff --git a/views/painter.cc b/views/painter.cc index c368a0a..1c354da 100644 --- a/views/painter.cc +++ b/views/painter.cc @@ -7,7 +7,6 @@ #include "app/resource_bundle.h" #include "base/logging.h" #include "gfx/canvas.h" -#include "gfx/canvas_skia.h" #include "gfx/insets.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/effects/SkGradientShader.h" @@ -44,9 +43,8 @@ class GradientPainter : public Painter { // Need to unref shader, otherwise never deleted. s->unref(); - canvas->AsCanvasSkia()->drawRectCoords( - SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(w), SkIntToScalar(h), - paint); + canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), + SkIntToScalar(w), SkIntToScalar(h), paint); } private: @@ -148,10 +146,10 @@ void Painter::PaintPainterAt(int x, int y, int w, int h, DCHECK(canvas && painter); if (w < 0 || h < 0) return; - canvas->AsCanvasSkia()->save(); + canvas->save(); canvas->TranslateInt(x, y); painter->Paint(w, h, canvas); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } // static diff --git a/views/view.cc b/views/view.cc index e2d4e43..d8ba4c3 100644 --- a/views/view.cc +++ b/views/view.cc @@ -14,7 +14,7 @@ #include "base/message_loop.h" #include "base/scoped_handle.h" #include "base/utf_string_conversions.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/path.h" #include "third_party/skia/include/core/SkShader.h" #include "views/background.h" @@ -378,7 +378,7 @@ void View::ProcessPaint(gfx::Canvas* canvas) { return; // We're going to modify the canvas, save it's state first. - canvas->AsCanvasSkia()->save(); + canvas->save(); // Paint this View and its children, setting the clip rect to the bounds // of this View and translating the origin to the local bounds' top left @@ -393,7 +393,7 @@ void View::ProcessPaint(gfx::Canvas* canvas) { canvas->TranslateInt(MirroredX(), y()); // Save the state again, so that any changes don't effect PaintChildren. - canvas->AsCanvasSkia()->save(); + canvas->save(); // If the View we are about to paint requested the canvas to be flipped, we // should change the transform appropriately. @@ -401,7 +401,7 @@ void View::ProcessPaint(gfx::Canvas* canvas) { if (flip_canvas) { canvas->TranslateInt(width(), 0); canvas->ScaleInt(-1, 1); - canvas->AsCanvasSkia()->save(); + canvas->save(); } Paint(canvas); @@ -410,14 +410,14 @@ void View::ProcessPaint(gfx::Canvas* canvas) { // we don't pass the canvas with the mirrored transform to Views that // didn't request the canvas to be flipped. if (flip_canvas) - canvas->AsCanvasSkia()->restore(); + canvas->restore(); - canvas->AsCanvasSkia()->restore(); + canvas->restore(); PaintChildren(canvas); } // Restore the canvas's original transform. - canvas->AsCanvasSkia()->restore(); + canvas->restore(); } void View::PaintNow() { diff --git a/views/view_text_utils.cc b/views/view_text_utils.cc index ea1bba7..1fb39d3 100644 --- a/views/view_text_utils.cc +++ b/views/view_text_utils.cc @@ -9,7 +9,7 @@ #include "base/i18n/word_iterator.h" #include "base/logging.h" #include "base/utf_string_conversions.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/color_utils.h" #include "gfx/size.h" #include "views/controls/label.h" @@ -118,7 +118,7 @@ void DrawTextStartingFrom(gfx::Canvas* canvas, word = text; // Draw the whole text at once. int w = font.GetStringWidth(word), h = font.height(); - gfx::CanvasSkia::SizeStringInt(word, font, &w, &h, flags); + canvas->SizeStringInt(word, font, &w, &h, flags); // If we exceed the boundaries, we need to wrap. WrapIfWordDoesntFit(w, font.height(), position, bounds); @@ -132,7 +132,7 @@ void DrawTextStartingFrom(gfx::Canvas* canvas, // left of the LTR string. if (ltr_within_rtl && word[word.size() - 1] == L' ') { int space_w = font.GetStringWidth(L" "), space_h = font.height(); - gfx::CanvasSkia::SizeStringInt(L" ", font, &space_w, &space_h, flags); + canvas->SizeStringInt(L" ", font, &space_w, &space_h, flags); x += space_w; } } diff --git a/views/view_unittest.cc b/views/view_unittest.cc index 8d6ad8e..b5e1091 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -8,7 +8,7 @@ #include "base/keyboard_codes.h" #include "base/message_loop.h" #include "base/string_util.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/path.h" #include "testing/gtest/include/gtest/gtest.h" #include "views/background.h" @@ -81,7 +81,7 @@ void PaintRootView(views::RootView* root, bool empty_paint) { // User isn't logged in, so that PaintNow will generate an empty rectangle. // Invoke paint directly. gfx::Rect paint_rect = root->GetScheduledPaintRect(); - gfx::CanvasSkia canvas(paint_rect.width(), paint_rect.height(), true); + gfx::Canvas canvas(paint_rect.width(), paint_rect.height(), true); canvas.TranslateInt(-paint_rect.x(), -paint_rect.y()); canvas.ClipRectInt(0, 0, paint_rect.width(), paint_rect.height()); root->ProcessPaint(&canvas); diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc index d67f5e3..ff08d29 100644 --- a/views/widget/root_view.cc +++ b/views/widget/root_view.cc @@ -10,7 +10,7 @@ #include "base/keyboard_codes.h" #include "base/logging.h" #include "base/message_loop.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "views/fill_layout.h" #include "views/focus/view_storage.h" #include "views/widget/widget.h" @@ -173,10 +173,10 @@ void RootView::ProcessPaint(gfx::Canvas* canvas) { return; // Clear the background. - canvas->AsCanvasSkia()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); + canvas->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); // Save the current transforms. - canvas->AsCanvasSkia()->save(); + canvas->save(); // Set the clip rect according to the invalid rect. int clip_x = invalid_rect_.x() + x(); @@ -188,7 +188,7 @@ void RootView::ProcessPaint(gfx::Canvas* canvas) { View::ProcessPaint(canvas); // Restore the previous transform - canvas->AsCanvasSkia()->restore(); + canvas->restore(); ClearPaintRect(); } diff --git a/views/widget/root_view_win.cc b/views/widget/root_view_win.cc index ab885d0..3c9706d 100644 --- a/views/widget/root_view_win.cc +++ b/views/widget/root_view_win.cc @@ -9,6 +9,7 @@ #include "app/os_exchange_data_provider_win.h" #include "base/base_drag_source.h" #include "base/logging.h" +#include "gfx/canvas_2.h" #include "gfx/canvas_skia.h" namespace views { @@ -24,12 +25,12 @@ void RootView::OnPaint(HWND hwnd) { RECT win_version = original_dirty_region.ToRECT(); InvalidateRect(hwnd, &win_version, FALSE); } - scoped_ptr<gfx::CanvasPaint> canvas( - gfx::CanvasPaint::CreateCanvasPaint(hwnd)); + scoped_ptr<gfx::CanvasPaint2> canvas( + gfx::CanvasPaint2::CreateCanvasPaint(hwnd)); if (!canvas->IsValid()) { SchedulePaint(canvas->GetInvalidRect(), false); if (NeedsPainting(false)) - ProcessPaint(canvas->AsCanvas()); + ProcessPaint(canvas->AsCanvas2()->AsCanvas()); } } diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index 5948bfd..7705784 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -9,6 +9,7 @@ #include "app/win_util.h" #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" @@ -1121,9 +1122,9 @@ Window* WidgetWin::GetWindowImpl(HWND hwnd) { } void WidgetWin::SizeContents(const gfx::Size& window_size) { - contents_.reset(new gfx::CanvasSkia(window_size.width(), - window_size.height(), - false)); + contents_.reset(new gfx::Canvas(window_size.width(), + window_size.height(), + false)); } void WidgetWin::PaintLayeredWindow() { diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h index 866cc70..98da389 100644 --- a/views/widget/widget_win.h +++ b/views/widget/widget_win.h @@ -20,7 +20,7 @@ #include "views/widget/widget.h" namespace gfx { -class CanvasSkia; +class Canvas; class Rect; } @@ -533,7 +533,7 @@ class WidgetWin : public app::WindowImpl, // A canvas that contains the window contents in the case of a layered // window. - scoped_ptr<gfx::CanvasSkia> contents_; + scoped_ptr<gfx::Canvas> contents_; // Whether or not the window should delete itself when it is destroyed. // Set this to false via its setter for stack allocated instances. diff --git a/views/window/dialog_client_view.cc b/views/window/dialog_client_view.cc index 4f40987..8b32d63 100644 --- a/views/window/dialog_client_view.cc +++ b/views/window/dialog_client_view.cc @@ -17,7 +17,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/keyboard_codes.h" -#include "gfx/canvas_skia.h" +#include "gfx/canvas.h" #include "gfx/font.h" #include "grit/app_strings.h" #include "views/controls/button/native_button.h" @@ -418,7 +418,7 @@ void DialogClientView::PaintSizeBox(gfx::Canvas* canvas) { if (window()->GetDelegate()->CanResize() || window()->GetDelegate()->CanMaximize()) { #if defined(OS_WIN) - HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint(); + HDC dc = canvas->beginPlatformPaint(); SIZE gripper_size = { 0, 0 }; gfx::NativeTheme::instance()->GetThemePartSize( gfx::NativeTheme::STATUS, dc, SP_GRIPPER, 1, NULL, TS_TRUE, @@ -434,7 +434,7 @@ void DialogClientView::PaintSizeBox(gfx::Canvas* canvas) { RECT native_bounds = size_box_bounds_.ToRECT(); gfx::NativeTheme::instance()->PaintStatusGripper( dc, SP_PANE, 1, 0, &native_bounds); - canvas->AsCanvasSkia()->endPlatformPaint(); + canvas->endPlatformPaint(); #else NOTIMPLEMENTED(); // TODO(port): paint size box |