diff options
author | twiz@chromium.org <twiz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-26 14:28:35 +0000 |
---|---|---|
committer | twiz@chromium.org <twiz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-26 14:28:35 +0000 |
commit | 62f2e80c79f7d660d7871b14287cef9082fcc32f (patch) | |
tree | 310edb9b2c0aa8409defc654979719cb4d8a4059 /chrome | |
parent | c89b244483969aa8859a1d4bb3396f6ceb54f875 (diff) | |
download | chromium_src-62f2e80c79f7d660d7871b14287cef9082fcc32f.zip chromium_src-62f2e80c79f7d660d7871b14287cef9082fcc32f.tar.gz chromium_src-62f2e80c79f7d660d7871b14287cef9082fcc32f.tar.bz2 |
This change implements a first pass in the effort to remove the dependency of PlatformDevice within Chrome. The Skia library now provides multiple back-ends for the SkDevice class, so PlatformDevice's inheritance of SkDevice, and the assumption of instances of PlatformDevice limits the use of these new back-ends.
A new set of helper functions is provided for the PlatformDevice entry points. Upon construction of a PlatformDevice, a pointer to the interface is cached in the parent SkDevice's SkMetaData. The new helper functions forward calls to the interface cached in the metadata.
BUG=NONE
TEST=NONE
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=86625
Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=86625
Review URL: http://codereview.chromium.org/7019013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/aeropeek_manager.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_tabs_module.cc | 2 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_win.cc | 32 | ||||
-rw-r--r-- | chrome/browser/tab_contents/thumbnail_generator.cc | 3 | ||||
-rw-r--r-- | chrome/browser/tab_contents/thumbnail_generator_unittest.cc | 16 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc | 3 | ||||
-rw-r--r-- | chrome/browser/ui/views/omnibox/omnibox_view_win.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/views/tabs/dragged_tab_view.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/views/tabs/native_view_photobooth_win.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/views/theme_helpers.cc | 16 | ||||
-rw-r--r-- | chrome/renderer/chrome_render_view_observer.cc | 13 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_linux.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_win.cc | 6 | ||||
-rw-r--r-- | chrome/renderer/safe_browsing/phishing_thumbnailer.cc | 6 |
14 files changed, 54 insertions, 57 deletions
diff --git a/chrome/browser/aeropeek_manager.cc b/chrome/browser/aeropeek_manager.cc index e81ea50..79107e1 100644 --- a/chrome/browser/aeropeek_manager.cc +++ b/chrome/browser/aeropeek_manager.cc @@ -1244,7 +1244,7 @@ bool AeroPeekManager::GetTabPreview(int tab_id, SkBitmap* preview) { &canvas)) return false; - const SkBitmap& bitmap = canvas.getTopPlatformDevice().accessBitmap(false); + const SkBitmap& bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); bitmap.copyTo(preview, SkBitmap::kARGB_8888_Config); return true; } diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc index 139d55b..2bb87d9 100644 --- a/chrome/browser/extensions/extension_tabs_module.cc +++ b/chrome/browser/extensions/extension_tabs_module.cc @@ -1205,7 +1205,7 @@ bool CaptureVisibleTabFunction::CaptureSnapshotFromBackingStore( VLOG(1) << "captureVisibleTab() got image from backing store."; SendResultFromBitmap( - temp_canvas.getTopPlatformDevice().accessBitmap(false)); + skia::GetTopDevice(temp_canvas)->accessBitmap(false)); return true; } diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.cc b/chrome/browser/renderer_host/render_widget_host_view_win.cc index 407bc1d3..b8e12cf 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_win.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc @@ -169,20 +169,22 @@ void DrawDeemphasized(const SkColor& color, HDC backing_store_dc, HDC paint_dc) { gfx::CanvasSkia canvas(paint_rect.width(), paint_rect.height(), true); - HDC dc = canvas.beginPlatformPaint(); - BitBlt(dc, - 0, - 0, - paint_rect.width(), - paint_rect.height(), - backing_store_dc, - paint_rect.x(), - paint_rect.y(), - SRCCOPY); - canvas.endPlatformPaint(); + { + skia::ScopedPlatformPaint scoped_platform_paint(&canvas); + HDC dc = scoped_platform_paint.GetPlatformSurface(); + BitBlt(dc, + 0, + 0, + paint_rect.width(), + paint_rect.height(), + backing_store_dc, + paint_rect.x(), + paint_rect.y(), + SRCCOPY); + } canvas.FillRectInt(color, 0, 0, paint_rect.width(), paint_rect.height()); - canvas.getTopPlatformDevice().drawToHDC(paint_dc, paint_rect.x(), - paint_rect.y(), NULL); + skia::DrawToNativeContext(&canvas, paint_dc, paint_rect.x(), + paint_rect.y(), NULL); } // The plugin wrapper window which lives in the browser process has this proc @@ -961,8 +963,8 @@ void RenderWidgetHostViewWin::DrawBackground(const RECT& dirty_rect, dc_rect.right - dc_rect.left, dc_rect.bottom - dc_rect.top); - canvas.getTopPlatformDevice().drawToHDC(*dc, dirty_rect.left, - dirty_rect.top, NULL); + skia::DrawToNativeContext(&canvas, *dc, dirty_rect.left, dirty_rect.top, + NULL); } else { HBRUSH white_brush = reinterpret_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); dc->FillRect(&dirty_rect, white_brush); diff --git a/chrome/browser/tab_contents/thumbnail_generator.cc b/chrome/browser/tab_contents/thumbnail_generator.cc index 76e15ca..257d2bd 100644 --- a/chrome/browser/tab_contents/thumbnail_generator.cc +++ b/chrome/browser/tab_contents/thumbnail_generator.cc @@ -21,7 +21,6 @@ #include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_service.h" #include "googleurl/src/gurl.h" -#include "skia/ext/bitmap_platform_device.h" #include "skia/ext/image_operations.h" #include "skia/ext/platform_canvas.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -80,7 +79,7 @@ SkBitmap GetBitmapForBackingStore( if (!backing_store->CopyFromBackingStore(gfx::Rect(backing_store->size()), &temp_canvas)) return result; - const SkBitmap& bmp = temp_canvas.getTopPlatformDevice().accessBitmap(false); + const SkBitmap& bmp = skia::GetTopDevice(temp_canvas)->accessBitmap(false); // Check if a clipped thumbnail is requested. if (options & ThumbnailGenerator::kClippedThumbnail) { diff --git a/chrome/browser/tab_contents/thumbnail_generator_unittest.cc b/chrome/browser/tab_contents/thumbnail_generator_unittest.cc index 93a43f2..1c8ba8c 100644 --- a/chrome/browser/tab_contents/thumbnail_generator_unittest.cc +++ b/chrome/browser/tab_contents/thumbnail_generator_unittest.cc @@ -103,11 +103,11 @@ class ThumbnailGeneratorTest : public testing::Test { transport_dib_->GetPlatformCanvas(kBitmapWidth, kBitmapHeight)); switch (type) { case TRANSPORT_BLACK: - canvas->getTopPlatformDevice().accessBitmap(true).eraseARGB( + skia::GetTopDevice(*canvas)->accessBitmap(true).eraseARGB( 0xFF, 0, 0, 0); break; case TRANSPORT_WHITE: - canvas->getTopPlatformDevice().accessBitmap(true).eraseARGB( + skia::GetTopDevice(*canvas)->accessBitmap(true).eraseARGB( 0xFF, 0xFF, 0xFF, 0xFF); break; case TRANSPORT_OTHER: @@ -211,7 +211,7 @@ TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) { // Fill all pixesl in black. canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); - SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); + SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); // The thumbnail should deserve the highest boring score. EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); } @@ -227,7 +227,7 @@ TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_TwoColors) { // Fill the left half pixels in white. canvas.FillRectInt(kWhite, 0, 0, kSize.width() / 2, kSize.height()); - SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); + SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); ASSERT_EQ(kSize.width(), bitmap.width()); ASSERT_EQ(kSize.height(), bitmap.height()); // The thumbnail should be less boring because two colors are used. @@ -237,7 +237,7 @@ TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_TwoColors) { TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_TallerThanWide) { // The input bitmap is vertically long. gfx::CanvasSkia canvas(40, 90, true); - const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); + const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); // The desired size is square. ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; @@ -253,7 +253,7 @@ TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_TallerThanWide) { TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_WiderThanTall) { // The input bitmap is horizontally long. gfx::CanvasSkia canvas(90, 40, true); - const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); + const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); // The desired size is square. ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; @@ -269,7 +269,7 @@ TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_WiderThanTall) { TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NotClipped) { // The input bitmap is square. gfx::CanvasSkia canvas(40, 40, true); - const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); + const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); // The desired size is square. ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; @@ -285,7 +285,7 @@ TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NotClipped) { TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NonSquareOutput) { // The input bitmap is square. gfx::CanvasSkia canvas(40, 40, true); - const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); + const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); // The desired size is horizontally long. ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; diff --git a/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc index 9394154..95336a1 100644 --- a/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc +++ b/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc @@ -655,7 +655,8 @@ SkBitmap TabRendererGtk::PaintBitmap() { cairo_surface_t* TabRendererGtk::PaintToSurface() { gfx::CanvasSkia canvas(width(), height(), false); Paint(&canvas); - return cairo_surface_reference(cairo_get_target(canvas.beginPlatformPaint())); + return cairo_surface_reference(cairo_get_target( + skia::BeginPlatformPaint(&canvas))); } void TabRendererGtk::SchedulePaint() { diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc index 0817323..70f6443 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc @@ -2315,7 +2315,7 @@ void OmniboxViewWin::DrawSlashForInsecureScheme(HDC hdc, } // Now copy what we drew to the target HDC. - canvas.getTopPlatformDevice().drawToHDC(hdc, + skia::DrawToNativeContext(&canvas, hdc, scheme_rect.left + canvas_paint_clip_rect.left - canvas_clip_rect.left, std::max(scheme_rect.top, client_rect.top) + canvas_paint_clip_rect.top - canvas_clip_rect.top, &canvas_paint_clip_rect); diff --git a/chrome/browser/ui/views/tabs/dragged_tab_view.cc b/chrome/browser/ui/views/tabs/dragged_tab_view.cc index daed0e3..eff832e 100644 --- a/chrome/browser/ui/views/tabs/dragged_tab_view.cc +++ b/chrome/browser/ui/views/tabs/dragged_tab_view.cc @@ -135,7 +135,7 @@ void DraggedTabView::PaintDetachedView(gfx::Canvas* canvas) { gfx::Size ps = GetPreferredSize(); gfx::CanvasSkia scale_canvas(ps.width(), ps.height(), false); SkBitmap& bitmap_device = const_cast<SkBitmap&>( - scale_canvas.getTopPlatformDevice().accessBitmap(true)); + skia::GetTopDevice(scale_canvas)->accessBitmap(true)); bitmap_device.eraseARGB(0, 0, 0, 0); int tab_height = renderer_bounds_.back().height(); diff --git a/chrome/browser/ui/views/tabs/native_view_photobooth_win.cc b/chrome/browser/ui/views/tabs/native_view_photobooth_win.cc index 4bfd3609..c545d44 100644 --- a/chrome/browser/ui/views/tabs/native_view_photobooth_win.cc +++ b/chrome/browser/ui/views/tabs/native_view_photobooth_win.cc @@ -110,9 +110,9 @@ 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()); + skia::MakeOpaque(canvas->AsCanvasSkia(), target_bounds.x(), + target_bounds.y(), target_bounds.width(), + target_bounds.height()); ReleaseDC(current_hwnd_, source_dc); canvas->EndPlatformPaint(); } diff --git a/chrome/browser/ui/views/theme_helpers.cc b/chrome/browser/ui/views/theme_helpers.cc index 4b0f6b3..1708049 100644 --- a/chrome/browser/ui/views/theme_helpers.cc +++ b/chrome/browser/ui/views/theme_helpers.cc @@ -9,7 +9,6 @@ #include <atltheme.h> #include "base/logging.h" -#include "skia/ext/bitmap_platform_device_win.h" #include "third_party/skia/include/effects/SkGradientShader.h" #include "ui/gfx/canvas_skia.h" @@ -32,10 +31,10 @@ void GetRebarGradientColors(int width, int x1, int x2, // On Windows XP+, if using a Theme, we can ask the theme to render the // gradient for us. if (!theme.IsThemeNull()) { - HDC dc = canvas.beginPlatformPaint(); + skia::ScopedPlatformPaint scoped_platform_paint(&canvas); + HDC dc = scoped_platform_paint.GetPlatformSurface(); RECT rect = { 0, 0, width, 1 }; theme.DrawThemeBackground(dc, 0, 0, &rect, NULL); - canvas.endPlatformPaint(); } else { // On Windows 2000 or Windows XP+ with the Classic theme selected, we need // to build our own gradient using system colors. @@ -64,11 +63,12 @@ void GetRebarGradientColors(int width, int x1, int x2, // Extract the color values from the selected pixels // The | in the following operations forces the alpha to 0xFF. This is // needed as windows sets the alpha to 0 when it renders. - skia::BitmapPlatformDevice& device = - static_cast<skia::BitmapPlatformDevice&>( - canvas.getTopPlatformDevice()); - *c1 = 0xFF000000 | device.getColorAt(x1, 0); - *c2 = 0xFF000000 | device.getColorAt(x2, 0); + SkDevice* device = skia::GetTopDevice(canvas); + const SkBitmap& bitmap = device->accessBitmap(false); + SkAutoLockPixels lock(bitmap); + + *c1 = 0xFF000000 | bitmap.getColor(x1, 0); + *c2 = 0xFF000000 | bitmap.getColor(x2, 0); } void GetDarkLineColor(SkColor* dark_color) { diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc index 113dc62..9c19c19 100644 --- a/chrome/renderer/chrome_render_view_observer.cc +++ b/chrome/renderer/chrome_render_view_observer.cc @@ -26,7 +26,6 @@ #include "content/renderer/content_renderer_client.h" #include "googleurl/src/gurl.h" #include "net/base/data_url.h" -#include "skia/ext/bitmap_platform_device.h" #include "skia/ext/image_operations.h" #include "skia/ext/platform_canvas.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" @@ -595,10 +594,9 @@ bool ChromeRenderViewObserver::CaptureFrameThumbnail(WebView* view, if (!PaintViewIntoCanvas(view, canvas)) return false; - skia::BitmapPlatformDevice& device = - static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); + SkDevice* device = skia::GetTopDevice(canvas); - const SkBitmap& src_bmp = device.accessBitmap(false); + const SkBitmap& src_bmp = device->accessBitmap(false); SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) }; float dest_aspect = dest_rect.width() / dest_rect.height(); @@ -633,7 +631,7 @@ bool ChromeRenderViewObserver::CaptureFrameThumbnail(WebView* view, score->at_top = (view->mainFrame()->scrollOffset().height == 0); SkBitmap subset; - device.accessBitmap(false).extractSubset(&subset, src_rect); + device->accessBitmap(false).extractSubset(&subset, src_rect); // First do a fast downsample by powers of two to get close to the final size. SkBitmap downsampled_subset = @@ -659,10 +657,9 @@ bool ChromeRenderViewObserver::CaptureSnapshot(WebView* view, if (!PaintViewIntoCanvas(view, canvas)) return false; - skia::BitmapPlatformDevice& device = - static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); + SkDevice* device = skia::GetTopDevice(canvas); - const SkBitmap& bitmap = device.accessBitmap(false); + const SkBitmap& bitmap = device->accessBitmap(false); if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)) return false; diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc index c5e8e5a..a5eabfd 100644 --- a/chrome/renderer/print_web_view_helper_linux.cc +++ b/chrome/renderer/print_web_view_helper_linux.cc @@ -220,7 +220,7 @@ void PrintWebViewHelper::PrintPageInternal( gfx::Rect content_area(margin_left_in_points, margin_top_in_points, content_width_in_points, content_height_in_points); - skia::PlatformDevice* device = metafile->StartPageForVectorCanvas( + SkDevice* device = metafile->StartPageForVectorCanvas( page_size, content_area, 1.0f); if (!device) return; diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc index 4151818..5b502c4 100644 --- a/chrome/renderer/print_web_view_helper_win.cc +++ b/chrome/renderer/print_web_view_helper_win.cc @@ -81,7 +81,7 @@ void PrintWebViewHelper::PrintPageInternal( scoped_ptr<Metafile> metafile(new printing::NativeMetafile); metafile->Init(); DCHECK(metafile->context()); - skia::PlatformDevice::InitializeDC(metafile->context()); + skia::InitializeDC(metafile->context()); int page_number = params.page_number; @@ -228,7 +228,7 @@ void PrintWebViewHelper::RenderPage( static_cast<int>(margin_top_in_points), static_cast<int>(content_width_in_points), static_cast<int>(content_height_in_points)); - skia::PlatformDevice* device = (*metafile)->StartPageForVectorCanvas( + SkDevice* device = (*metafile)->StartPageForVectorCanvas( page_size, content_area, frame->getPrintPageShrink(page_number)); DCHECK(device); // The printPage method may take a reference to the canvas we pass down, so it @@ -290,7 +290,7 @@ void PrintWebViewHelper::RenderPage( metafile2->Init(); HDC hdc = metafile2->context(); DCHECK(hdc); - skia::PlatformDevice::InitializeDC(hdc); + skia::InitializeDC(hdc); RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT(); // Process the old metafile, placing all non-AlphaBlend calls into the diff --git a/chrome/renderer/safe_browsing/phishing_thumbnailer.cc b/chrome/renderer/safe_browsing/phishing_thumbnailer.cc index 3235ea3..e8a3b4f 100644 --- a/chrome/renderer/safe_browsing/phishing_thumbnailer.cc +++ b/chrome/renderer/safe_browsing/phishing_thumbnailer.cc @@ -8,7 +8,6 @@ #include "base/metrics/histogram.h" #include "base/time.h" #include "content/renderer/render_view.h" -#include "skia/ext/bitmap_platform_device.h" #include "skia/ext/image_operations.h" #include "skia/ext/platform_canvas.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -53,12 +52,11 @@ SkBitmap GrabPhishingThumbnail(RenderView* render_view, view->paint(webkit_glue::ToWebCanvas(&canvas), WebRect(0, 0, view_size.width(), view_size.height())); - skia::BitmapPlatformDevice& device = - static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); + SkDevice* device = skia::GetTopDevice(canvas); // Now resize the thumbnail to the right size. Note: it is important that we // use this resize algorithm here. - const SkBitmap& bitmap = device.accessBitmap(false); + const SkBitmap& bitmap = device->accessBitmap(false); SkBitmap thumbnail = skia::ImageOperations::Resize( bitmap, skia::ImageOperations::RESIZE_LANCZOS3, |