diff options
95 files changed, 566 insertions, 437 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 4689239..b9bc63e 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, diff --git a/content/browser/renderer_host/backing_store_mac.mm b/content/browser/renderer_host/backing_store_mac.mm index 68da54e..bc0e0c0 100644 --- a/content/browser/renderer_host/backing_store_mac.mm +++ b/content/browser/renderer_host/backing_store_mac.mm @@ -123,14 +123,14 @@ bool BackingStoreMac::CopyFromBackingStore(const gfx::Rect& rect, if (!output->initialize(rect.width(), rect.height(), true)) return false; - CGContextRef temp_context = output->beginPlatformPaint(); + skia::ScopedPlatformPaint scoped_platform_paint(output); + CGContextRef temp_context = scoped_platform_paint.GetPlatformSurface(); CGContextSaveGState(temp_context); CGContextTranslateCTM(temp_context, 0.0, size().height()); CGContextScaleCTM(temp_context, 1.0, -1.0); CGContextDrawLayerAtPoint(temp_context, CGPointMake(rect.x(), rect.y()), cg_layer()); CGContextRestoreGState(temp_context); - output->endPlatformPaint(); return true; } diff --git a/content/browser/renderer_host/backing_store_skia.cc b/content/browser/renderer_host/backing_store_skia.cc index f756504..8c79958 100644 --- a/content/browser/renderer_host/backing_store_skia.cc +++ b/content/browser/renderer_host/backing_store_skia.cc @@ -72,7 +72,7 @@ void BackingStoreSkia::PaintToBackingStore( SkRect dstrect = SkRect::MakeXYWH( SkIntToScalar(copy_rect.x()), SkIntToScalar(copy_rect.y()), SkIntToScalar(w), SkIntToScalar(h)); - SkBitmap b = p_canvas->getTopPlatformDevice().accessBitmap(false); + SkBitmap b = skia::GetTopDevice(*p_canvas)->accessBitmap(false); canvas_.get()->drawBitmapRect(b, &srcrect, dstrect); } } @@ -95,7 +95,7 @@ bool BackingStoreSkia::CopyFromBackingStore(const gfx::Rect& rect, if (!output->initialize(width, height, true)) return false; - SkBitmap bitmap = output->getTopPlatformDevice().accessBitmap(true); + SkBitmap bitmap = skia::GetTopDevice(*output)->accessBitmap(true); SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); SkBitmap b; if (!canvas_->readPixels(skrect, &b)) diff --git a/content/browser/renderer_host/backing_store_win.cc b/content/browser/renderer_host/backing_store_win.cc index 0a1645d7..49545d5 100644 --- a/content/browser/renderer_host/backing_store_win.cc +++ b/content/browser/renderer_host/backing_store_win.cc @@ -158,10 +158,10 @@ bool BackingStoreWin::CopyFromBackingStore(const gfx::Rect& rect, if (!output->initialize(rect.width(), rect.height(), true)) return false; - HDC temp_dc = output->beginPlatformPaint(); + skia::ScopedPlatformPaint scoped_platform_paint(output); + HDC temp_dc = scoped_platform_paint.GetPlatformSurface(); BitBlt(temp_dc, 0, 0, rect.width(), rect.height(), hdc(), rect.x(), rect.y(), SRCCOPY); - output->endPlatformPaint(); return true; } diff --git a/content/browser/renderer_host/backing_store_x.cc b/content/browser/renderer_host/backing_store_x.cc index 8561eab..7767c75 100644 --- a/content/browser/renderer_host/backing_store_x.cc +++ b/content/browser/renderer_host/backing_store_x.cc @@ -375,7 +375,7 @@ bool BackingStoreX::CopyFromBackingStore(const gfx::Rect& rect, // it and copy each row out, only up to the pixels we're actually // using. This code assumes a visual mode where a pixel is // represented using a 32-bit unsigned int, with a byte per component. - SkBitmap bitmap = output->getTopPlatformDevice().accessBitmap(true); + SkBitmap bitmap = skia::GetTopDevice(*output)->accessBitmap(true); for (int y = 0; y < height; y++) { const uint32* src_row = reinterpret_cast<uint32*>( &image->data[image->bytes_per_line * y]); diff --git a/content/plugin/webplugin_proxy.cc b/content/plugin/webplugin_proxy.cc index e046f01..014843f 100644 --- a/content/plugin/webplugin_proxy.cc +++ b/content/plugin/webplugin_proxy.cc @@ -371,7 +371,7 @@ void WebPluginProxy::Paint(const gfx::Rect& rect) { // into (which is windowless_canvas_) so it can do blending. So we copy the // background bitmap into the windowless_canvas_. const SkBitmap& background_bitmap = - background_canvas_->getTopPlatformDevice().accessBitmap(false); + skia::GetTopDevice(*background_canvas_)->accessBitmap(false); windowless_canvas_->drawBitmap(background_bitmap, 0, 0); } else { // In non-transparent mode, the plugin doesn't care what's underneath, so we diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc index 98d6a4d..7e98d18 100644 --- a/content/renderer/render_widget.cc +++ b/content/renderer/render_widget.cc @@ -549,7 +549,7 @@ void RenderWidget::PaintRect(const gfx::Rect& rect, webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect); // Flush to underlying bitmap. TODO(darin): is this needed? - canvas->getTopPlatformDevice().accessBitmap(false); + skia::GetTopDevice(*canvas)->accessBitmap(false); } PaintDebugBorder(rect, canvas); diff --git a/content/renderer/webplugin_delegate_proxy.cc b/content/renderer/webplugin_delegate_proxy.cc index 91faa71..e6fa99f 100644 --- a/content/renderer/webplugin_delegate_proxy.cc +++ b/content/renderer/webplugin_delegate_proxy.cc @@ -728,7 +728,9 @@ void WebPluginDelegateProxy::Paint(WebKit::WebCanvas* canvas, // We're using the native OS APIs from here on out. #if WEBKIT_USING_SKIA - gfx::NativeDrawingContext context = skia::BeginPlatformPaint(canvas); + skia::ScopedPlatformPaint scoped_platform_paint(canvas); + gfx::NativeDrawingContext context = + scoped_platform_paint.GetPlatformSurface(); #elif WEBKIT_USING_CG gfx::NativeDrawingContext context = canvas; #endif @@ -764,10 +766,6 @@ void WebPluginDelegateProxy::Paint(WebKit::WebCanvas* canvas, invalidate_pending_ = false; Send(new PluginMsg_DidPaint(instance_id_)); } - -#if WEBKIT_USING_SKIA - skia::EndPlatformPaint(canvas); -#endif } bool WebPluginDelegateProxy::BackgroundChanged( @@ -850,8 +848,10 @@ bool WebPluginDelegateProxy::BackgroundChanged( int page_start_x = content_rect.x() - context_offset_x; int page_start_y = content_rect.y() - context_offset_y; - CGContextRef bg_context = - background_store_canvas_->getTopPlatformDevice().GetBitmapContext(); + skia::ScopedPlatformPaint scoped_platform_paint( + background_store_canvas_.get()); + CGContextRef bg_context = scoped_platform_paint.GetPlatformSurface(); + DCHECK_EQ(CGBitmapContextGetBitsPerPixel(context), CGBitmapContextGetBitsPerPixel(bg_context)); const unsigned char* bg_bytes = static_cast<const unsigned char*>( @@ -869,9 +869,10 @@ bool WebPluginDelegateProxy::BackgroundChanged( int page_start_x = static_cast<int>(page_x_double); int page_start_y = static_cast<int>(page_y_double); - skia::PlatformDevice& device = - background_store_canvas_->getTopPlatformDevice(); - cairo_surface_t* bg_surface = cairo_get_target(device.BeginPlatformPaint()); + skia::ScopedPlatformPaint scoped_platform_paint( + background_store_canvas_.get()); + cairo_surface_t* bg_surface =cairo_get_target( + scoped_platform_paint.GetPlatformSurface()); DCHECK_EQ(cairo_surface_get_type(bg_surface), CAIRO_SURFACE_TYPE_IMAGE); DCHECK_EQ(cairo_image_surface_get_format(bg_surface), CAIRO_FORMAT_ARGB32); cairo_surface_flush(bg_surface); diff --git a/ppapi/proxy/ppb_image_data_proxy.cc b/ppapi/proxy/ppb_image_data_proxy.cc index 767190b..2117e82 100644 --- a/ppapi/proxy/ppb_image_data_proxy.cc +++ b/ppapi/proxy/ppb_image_data_proxy.cc @@ -97,7 +97,7 @@ void* ImageData::Map() { return NULL; } const SkBitmap& bitmap = - mapped_canvas_->getTopPlatformDevice().accessBitmap(true); + skia::GetTopDevice(*mapped_canvas_)->accessBitmap(true); bitmap.lockPixels(); return bitmap.getAddr(0, 0); diff --git a/printing/emf_win.cc b/printing/emf_win.cc index 40f4dc8..0f40496 100644 --- a/printing/emf_win.cc +++ b/printing/emf_win.cc @@ -403,7 +403,7 @@ bool Emf::Record::SafePlayback(const XFORM* base_matrix) const { return res; } -skia::PlatformDevice* Emf::StartPageForVectorCanvas( +SkDevice* Emf::StartPageForVectorCanvas( const gfx::Size& page_size, const gfx::Rect& content_area, const float& scale_factor) { if (!StartPage(page_size, content_area, scale_factor)) diff --git a/printing/emf_win.h b/printing/emf_win.h index 02a1958..f7e0ed5 100644 --- a/printing/emf_win.h +++ b/printing/emf_win.h @@ -45,7 +45,7 @@ class Emf : public Metafile { virtual bool Init(); virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size); - virtual skia::PlatformDevice* StartPageForVectorCanvas( + virtual SkDevice* StartPageForVectorCanvas( const gfx::Size& page_size, const gfx::Rect& content_area, const float& scale_factor); // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls diff --git a/printing/image_win.cc b/printing/image_win.cc index c9ad1fe..de731e0 100644 --- a/printing/image_win.cc +++ b/printing/image_win.cc @@ -69,7 +69,7 @@ bool Image::LoadMetafile(const Metafile& metafile) { DCHECK(bitmap); DCHECK(SelectObject(hdc, bitmap)); - skia::PlatformDevice::InitializeDC(hdc); + skia::InitializeDC(hdc); bool success = metafile.Playback(hdc, NULL); diff --git a/printing/metafile.h b/printing/metafile.h index c155fbc..84c0556 100644 --- a/printing/metafile.h +++ b/printing/metafile.h @@ -25,9 +25,7 @@ class Rect; class Size; } -namespace skia { -class PlatformDevice; -} +class SkDevice; #if defined(OS_CHROMEOS) namespace base { @@ -56,7 +54,7 @@ class Metafile { // This method calls StartPage and then returns an appropriate // VectorPlatformDevice implementation bound to the context created by // StartPage or NULL on error. - virtual skia::PlatformDevice* StartPageForVectorCanvas( + virtual SkDevice* StartPageForVectorCanvas( const gfx::Size& page_size, const gfx::Rect& content_area, const float& scale_factor) = 0; diff --git a/printing/pdf_metafile_cairo_linux.cc b/printing/pdf_metafile_cairo_linux.cc index 435a33c..5102a78 100644 --- a/printing/pdf_metafile_cairo_linux.cc +++ b/printing/pdf_metafile_cairo_linux.cc @@ -118,7 +118,7 @@ bool PdfMetafileCairo::InitFromData(const void* src_buffer, return true; } -skia::PlatformDevice* PdfMetafileCairo::StartPageForVectorCanvas( +SkDevice* PdfMetafileCairo::StartPageForVectorCanvas( const gfx::Size& page_size, const gfx::Rect& content_area, const float& scale_factor) { if (!StartPage(page_size, content_area, scale_factor)) diff --git a/printing/pdf_metafile_cairo_linux.h b/printing/pdf_metafile_cairo_linux.h index 8badf5c..6f07ae0 100644 --- a/printing/pdf_metafile_cairo_linux.h +++ b/printing/pdf_metafile_cairo_linux.h @@ -36,9 +36,10 @@ class PdfMetafileCairo : public Metafile { // continues on the surface returned by a previous call to Init(). virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size); - virtual skia::PlatformDevice* StartPageForVectorCanvas( + virtual SkDevice* StartPageForVectorCanvas( const gfx::Size& page_size, const gfx::Rect& content_area, const float& scale_factor); + virtual bool StartPage(const gfx::Size& page_size, const gfx::Rect& content_area, const float& scale_factor); diff --git a/printing/pdf_metafile_cg_mac.cc b/printing/pdf_metafile_cg_mac.cc index 9320b9e..4668b2d 100644 --- a/printing/pdf_metafile_cg_mac.cc +++ b/printing/pdf_metafile_cg_mac.cc @@ -118,7 +118,7 @@ bool PdfMetafileCg::InitFromData(const void* src_buffer, return true; } -skia::PlatformDevice* PdfMetafileCg::StartPageForVectorCanvas( +SkDevice* PdfMetafileCg::StartPageForVectorCanvas( const gfx::Size& page_size, const gfx::Rect& content_area, const float& scale_factor) { NOTIMPLEMENTED(); diff --git a/printing/pdf_metafile_cg_mac.h b/printing/pdf_metafile_cg_mac.h index bffbce5..5a7f56d 100644 --- a/printing/pdf_metafile_cg_mac.h +++ b/printing/pdf_metafile_cg_mac.h @@ -35,7 +35,7 @@ class PdfMetafileCg : public Metafile, public base::ThreadChecker { virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size); // Not implemented on mac. - virtual skia::PlatformDevice* StartPageForVectorCanvas( + virtual SkDevice* StartPageForVectorCanvas( const gfx::Size& page_size, const gfx::Rect& content_area, const float& scale_factor); virtual bool StartPage(const gfx::Size& page_size, diff --git a/printing/pdf_metafile_skia.cc b/printing/pdf_metafile_skia.cc index 80d4931..f76eb70 100644 --- a/printing/pdf_metafile_skia.cc +++ b/printing/pdf_metafile_skia.cc @@ -36,7 +36,7 @@ bool PdfMetafileSkia::InitFromData(const void* src_buffer, return data_->pdf_stream_.write(src_buffer, src_buffer_size); } -skia::PlatformDevice* PdfMetafileSkia::StartPageForVectorCanvas( +SkDevice* PdfMetafileSkia::StartPageForVectorCanvas( const gfx::Size& page_size, const gfx::Rect& content_area, const float& scale_factor) { DCHECK(data_->current_page_.get() == NULL); diff --git a/printing/pdf_metafile_skia.h b/printing/pdf_metafile_skia.h index 3138114..0ad2afb 100644 --- a/printing/pdf_metafile_skia.h +++ b/printing/pdf_metafile_skia.h @@ -29,10 +29,11 @@ class PdfMetafileSkia : public Metafile { virtual bool Init(); virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size); - virtual skia::PlatformDevice* StartPageForVectorCanvas( + virtual SkDevice* StartPageForVectorCanvas( const gfx::Size& page_size, const gfx::Rect& content_area, const float& scale_factor); + virtual bool StartPage(const gfx::Size& page_size, const gfx::Rect& content_area, const float& scale_factor); diff --git a/printing/printed_document_win.cc b/printing/printed_document_win.cc index cb25fdef..ef0c686 100644 --- a/printing/printed_document_win.cc +++ b/printing/printed_document_win.cc @@ -98,7 +98,7 @@ void PrintedDocument::RenderPrintedPage( // the device context. int saved_state = SaveDC(context); DCHECK_NE(saved_state, 0); - skia::PlatformDevice::InitializeDC(context); + skia::InitializeDC(context); { // Save the state (again) to apply the necessary world transformation. int saved_state = SaveDC(context); diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc index fd0be8c..07ac20b 100644 --- a/printing/printing_context_win.cc +++ b/printing/printing_context_win.cc @@ -17,7 +17,7 @@ #include "printing/print_job_constants.h" #include "printing/print_settings_initializer_win.h" #include "printing/printed_document.h" -#include "skia/ext/platform_device_win.h" +#include "skia/ext/platform_device.h" using base::Time; @@ -549,7 +549,7 @@ bool PrintingContextWin::InitializeSettings(const DEVMODE& dev_mode, const PRINTPAGERANGE* ranges, int number_ranges, bool selection_only) { - skia::PlatformDevice::InitializeDC(context_); + skia::InitializeDC(context_); DCHECK(GetDeviceCaps(context_, CLIPCAPS)); DCHECK(GetDeviceCaps(context_, RASTERCAPS) & RC_STRETCHDIB); DCHECK(GetDeviceCaps(context_, RASTERCAPS) & RC_BITMAP64); diff --git a/skia/ext/bitmap_platform_device.cc b/skia/ext/bitmap_platform_device.cc index bec8a63..05037c6 100644 --- a/skia/ext/bitmap_platform_device.cc +++ b/skia/ext/bitmap_platform_device.cc @@ -40,7 +40,7 @@ bool Constrain(int available_size, int* position, int *size) { namespace skia { -void BitmapPlatformDevice::makeOpaque(int x, int y, int width, int height) { +void BitmapPlatformDevice::MakeOpaque(int x, int y, int width, int height) { const SkBitmap& bitmap = accessBitmap(true); SkASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); diff --git a/skia/ext/bitmap_platform_device_linux.h b/skia/ext/bitmap_platform_device_linux.h index 37695f1..927bd43 100644 --- a/skia/ext/bitmap_platform_device_linux.h +++ b/skia/ext/bitmap_platform_device_linux.h @@ -88,7 +88,7 @@ class BitmapPlatformDevice : public PlatformDevice { static BitmapPlatformDevice* Create(int width, int height, bool is_opaque, uint8_t* data); - virtual void makeOpaque(int x, int y, int width, int height); + virtual void MakeOpaque(int x, int y, int width, int height); // Overridden from SkDevice: virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, diff --git a/skia/ext/bitmap_platform_device_mac.cc b/skia/ext/bitmap_platform_device_mac.cc index 543fc38..8276545 100644 --- a/skia/ext/bitmap_platform_device_mac.cc +++ b/skia/ext/bitmap_platform_device_mac.cc @@ -226,8 +226,8 @@ void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform, data_->SetMatrixClip(transform, region); } -void BitmapPlatformDevice::DrawToContext(CGContextRef context, int x, int y, - const CGRect* src_rect) { +void BitmapPlatformDevice::DrawToNativeContext(CGContextRef context, int x, + int y, const CGRect* src_rect) { bool created_dc = false; if (!data_->bitmap_context()) { created_dc = true; @@ -261,14 +261,6 @@ bool BitmapPlatformDevice::IsVectorial() { return false; } -// Returns the color value at the specified location. -SkColor BitmapPlatformDevice::getColorAt(int x, int y) { - const SkBitmap& bitmap = accessBitmap(true); - SkAutoLockPixels lock(bitmap); - uint32_t* data = bitmap.getAddr32(0, 0); - return static_cast<SkColor>(data[x + y * width()]); -} - void BitmapPlatformDevice::onAccessBitmap(SkBitmap*) { // Not needed in CoreGraphics } diff --git a/skia/ext/bitmap_platform_device_mac.h b/skia/ext/bitmap_platform_device_mac.h index f126adc..565bbcf 100644 --- a/skia/ext/bitmap_platform_device_mac.h +++ b/skia/ext/bitmap_platform_device_mac.h @@ -61,18 +61,16 @@ class BitmapPlatformDevice : public PlatformDevice { // See warning for copy constructor above. BitmapPlatformDevice& operator=(const BitmapPlatformDevice& other); + // PlatformDevice overrides virtual CGContextRef GetBitmapContext(); - virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, - const SkClipStack&); - - virtual void DrawToContext(CGContextRef context, int x, int y, - const CGRect* src_rect); - virtual void makeOpaque(int x, int y, int width, int height); + virtual void DrawToNativeContext(CGContextRef context, int x, int y, + const CGRect* src_rect); + virtual void MakeOpaque(int x, int y, int width, int height); virtual bool IsVectorial(); - // Returns the color value at the specified location. This does not - // consider any transforms that may be set on the device. - SkColor getColorAt(int x, int y); + // SkDevice overrides + virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, + const SkClipStack&); protected: // Reference counted data that can be shared between multiple devices. This diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc index 5678b9b..dcc395d 100644 --- a/skia/ext/bitmap_platform_device_win.cc +++ b/skia/ext/bitmap_platform_device_win.cc @@ -220,8 +220,8 @@ void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform, data_->SetMatrixClip(transform, region); } -void BitmapPlatformDevice::drawToHDC(HDC dc, int x, int y, - const RECT* src_rect) { +void BitmapPlatformDevice::DrawToNativeContext(HDC dc, int x, int y, + const RECT* src_rect) { bool created_dc = !data_->IsBitmapDCCreated(); HDC source_dc = BeginPlatformPaint(); @@ -275,14 +275,6 @@ void BitmapPlatformDevice::drawToHDC(HDC dc, int x, int y, data_->ReleaseBitmapDC(); } -// Returns the color value at the specified location. -SkColor BitmapPlatformDevice::getColorAt(int x, int y) { - const SkBitmap& bitmap = accessBitmap(false); - SkAutoLockPixels lock(bitmap); - uint32_t* data = bitmap.getAddr32(0, 0); - return static_cast<SkColor>(data[x + y * width()]); -} - void BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) { // FIXME(brettw) OPTIMIZATION: We should only flush if we know a GDI // operation has occurred on our DC. diff --git a/skia/ext/bitmap_platform_device_win.h b/skia/ext/bitmap_platform_device_win.h index 7f901f5..7197d16 100644 --- a/skia/ext/bitmap_platform_device_win.h +++ b/skia/ext/bitmap_platform_device_win.h @@ -69,24 +69,21 @@ class SK_API BitmapPlatformDevice : public PlatformDevice { // See warning for copy constructor above. BitmapPlatformDevice& operator=(const BitmapPlatformDevice& other); + // PlatformDevice overrides // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The // bitmap DC is lazy created. virtual PlatformSurface BeginPlatformPaint(); virtual void EndPlatformPaint(); + virtual void DrawToNativeContext(HDC dc, int x, int y, const RECT* src_rect); + virtual void MakeOpaque(int x, int y, int width, int height); + virtual bool IsVectorial() { return false; } + // Loads the given transform and clipping region into the HDC. This is // overridden from SkDevice. virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, const SkClipStack&); - virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect); - virtual void makeOpaque(int x, int y, int width, int height); - virtual bool IsVectorial() { return false; } - - // Returns the color value at the specified location. This does not - // consider any transforms that may be set on the device. - SkColor getColorAt(int x, int y); - protected: // Flushes the Windows device context so that the pixel data can be accessed // directly by Skia. Overridden from SkDevice, this is called when Skia diff --git a/skia/ext/canvas_paint_linux.h b/skia/ext/canvas_paint_linux.h index 73d9617..608350f 100644 --- a/skia/ext/canvas_paint_linux.h +++ b/skia/ext/canvas_paint_linux.h @@ -92,7 +92,7 @@ class CanvasPaintT : public T { // surface. T::translate(-SkIntToScalar(bounds.x), -SkIntToScalar(bounds.y)); - context_ = T::getTopPlatformDevice().BeginPlatformPaint(); + context_ = BeginPlatformPaint(GetTopDevice(*this)); } cairo_t* context_; diff --git a/skia/ext/canvas_paint_mac.h b/skia/ext/canvas_paint_mac.h index 6cef9ba..c4f45b2 100644 --- a/skia/ext/canvas_paint_mac.h +++ b/skia/ext/canvas_paint_mac.h @@ -92,7 +92,7 @@ class CanvasPaintT : public T { T::translate(-SkDoubleToScalar(rectangle_.origin.x), -SkDoubleToScalar(rectangle_.origin.y)); - context_ = T::getTopPlatformDevice().GetBitmapContext(); + context_ = GetBitmapContext(GetTopDevice(*this)); } CGContext* context_; diff --git a/skia/ext/canvas_paint_win.h b/skia/ext/canvas_paint_win.h index 478f285..5fe22fc 100644 --- a/skia/ext/canvas_paint_win.h +++ b/skia/ext/canvas_paint_win.h @@ -62,9 +62,8 @@ class CanvasPaintT : public T { if (!isEmpty()) { restoreToCount(1); // Commit the drawing to the screen - getTopPlatformDevice().drawToHDC(paint_dc_, - ps_.rcPaint.left, ps_.rcPaint.top, - NULL); + skia::DrawToNativeContext(this, paint_dc_, ps_.rcPaint.left, + ps_.rcPaint.top, NULL); } if (for_paint_) EndPaint(hwnd_, &ps_); diff --git a/skia/ext/platform_canvas.cc b/skia/ext/platform_canvas.cc index c48cce4..c6fd17e 100644 --- a/skia/ext/platform_canvas.cc +++ b/skia/ext/platform_canvas.cc @@ -7,14 +7,6 @@ #include "skia/ext/bitmap_platform_device.h" #include "third_party/skia/include/core/SkTypes.h" -namespace { -skia::PlatformDevice* GetTopPlatformDevice(const SkCanvas* canvas) { - // All of our devices should be our special PlatformDevice. - SkCanvas::LayerIter iter(const_cast<SkCanvas*>(canvas), false); - return static_cast<skia::PlatformDevice*>(iter.device()); -} -} - namespace skia { PlatformCanvas::PlatformCanvas() { @@ -29,10 +21,6 @@ SkDevice* PlatformCanvas::setBitmapDevice(const SkBitmap&) { return NULL; } -PlatformDevice& PlatformCanvas::getTopPlatformDevice() const { - return *GetTopPlatformDevice(this); -} - // static size_t PlatformCanvas::StrideForWidth(unsigned width) { return 4 * width; @@ -51,18 +39,32 @@ SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque) { return new PlatformCanvas(width, height, is_opaque); } +SkDevice* GetTopDevice(const SkCanvas& canvas) { + SkCanvas::LayerIter iter(const_cast<SkCanvas*>(&canvas), false); + return iter.device(); +} + bool SupportsPlatformPaint(const SkCanvas* canvas) { - // TODO(alokp): Rename PlatformDevice::IsNativeFontRenderingAllowed after - // removing these calls from WebKit. - return GetTopPlatformDevice(canvas)->IsNativeFontRenderingAllowed(); + // TODO(alokp): Rename IsNativeFontRenderingAllowed after removing these + // calls from WebKit. + return IsNativeFontRenderingAllowed(GetTopDevice(*canvas)); } -PlatformDevice::PlatformSurface BeginPlatformPaint(SkCanvas* canvas) { - return GetTopPlatformDevice(canvas)->BeginPlatformPaint(); +PlatformSurface BeginPlatformPaint(SkCanvas* canvas) { + return BeginPlatformPaint(GetTopDevice(*canvas)); } void EndPlatformPaint(SkCanvas* canvas) { - GetTopPlatformDevice(canvas)->EndPlatformPaint(); + EndPlatformPaint(GetTopDevice(*canvas)); +} + +void DrawToNativeContext(SkCanvas* canvas, PlatformSurface context, int x, + int y, const PlatformRect* src_rect) { + DrawToNativeContext(GetTopDevice(*canvas), context, x, y, src_rect); +} + +void MakeOpaque(SkCanvas* canvas, int x, int y, int width, int height) { + MakeOpaque(GetTopDevice(*canvas), x, y, width, height); } } // namespace skia diff --git a/skia/ext/platform_canvas.h b/skia/ext/platform_canvas.h index 24f613a..58049e6 100644 --- a/skia/ext/platform_canvas.h +++ b/skia/ext/platform_canvas.h @@ -63,30 +63,6 @@ class SK_API PlatformCanvas : public SkCanvas { // Shared -------------------------------------------------------------------- - // These calls should surround calls to platform drawing routines, the - // surface returned here can be used with the native platform routines - // - // Call endPlatformPaint when you are done and want to use Skia operations - // after calling the platform-specific beginPlatformPaint; this will - // synchronize the bitmap to OS if necessary. - PlatformDevice::PlatformSurface beginPlatformPaint() const; - void endPlatformPaint() const; - - // Returns the platform device pointer of the topmost rect with a non-empty - // clip. In practice, this is usually either the top layer or nothing, since - // we usually set the clip to new layers when we make them. - // - // If there is no layer that is not all clipped out, this will return a - // dummy device so callers do not have to check. If you are concerned about - // performance, check the clip before doing any painting. - // - // This is different than SkCanvas' getDevice, because that returns the - // bottommost device. - // - // Danger: the resulting device should not be saved. It will be invalidated - // by the next call to save() or restore(). - PlatformDevice& getTopPlatformDevice() const; - // Return the stride (length of a line in bytes) for the given width. Because // we use 32-bits per pixel, this will be roughly 4*width. However, for // alignment reasons we may wish to increase that. @@ -109,11 +85,26 @@ class SK_API PlatformCanvas : public SkCanvas { // CoreGraphics. virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap); - // Disallow copy and assign. + // Disallow copy and assign PlatformCanvas(const PlatformCanvas&); PlatformCanvas& operator=(const PlatformCanvas&); }; +// Returns the SkDevice pointer of the topmost rect with a non-empty +// clip. In practice, this is usually either the top layer or nothing, since +// we usually set the clip to new layers when we make them. +// +// If there is no layer that is not all clipped out, this will return a +// dummy device so callers do not have to check. If you are concerned about +// performance, check the clip before doing any painting. +// +// This is different than SkCanvas' getDevice, because that returns the +// bottommost device. +// +// Danger: the resulting device should not be saved. It will be invalidated +// by the next call to save() or restore(). +SkDevice* GetTopDevice(const SkCanvas& canvas); + // Creates a canvas with raster bitmap backing. // Set is_opaque if you are going to erase the bitmap and not use // transparency: this will enable some optimizations. @@ -124,18 +115,45 @@ SK_API SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque); // return NULL PlatformSurface. SK_API bool SupportsPlatformPaint(const SkCanvas* canvas); +// Draws into the a native platform surface, |context|. Forwards to +// DrawToNativeContext on a PlatformDevice instance bound to the top device. +// If no PlatformDevice instance is bound, is a no-operation. +SK_API void DrawToNativeContext(SkCanvas* canvas, PlatformSurface context, + int x, int y, const PlatformRect* src_rect); + +// Sets the opacity of each pixel in the specified region to be opaque. +SK_API void MakeOpaque(SkCanvas* canvas, int x, int y, int width, int height); + // These calls should surround calls to platform drawing routines, the // surface returned here can be used with the native platform routines. // // Call EndPlatformPaint when you are done and want to use skia operations // after calling the platform-specific BeginPlatformPaint; this will // synchronize the bitmap to OS if necessary. -// -// Note: These functions will eventually replace -// PlatformCanvas::beginPlatformPaint and PlatformCanvas::endPlatformPaint. -SK_API PlatformDevice::PlatformSurface BeginPlatformPaint(SkCanvas* canvas); +SK_API PlatformSurface BeginPlatformPaint(SkCanvas* canvas); SK_API void EndPlatformPaint(SkCanvas* canvas); +// Helper class for pairing calls to BeginPlatformPaint and EndPlatformPaint. +// Upon construction invokes BeginPlatformPaint, and upon destruction invokes +// EndPlatformPaint. +class ScopedPlatformPaint { + public: + explicit ScopedPlatformPaint(SkCanvas* canvas) : canvas_(canvas) { + platform_surface_ = BeginPlatformPaint(canvas); + } + ~ScopedPlatformPaint() { EndPlatformPaint(canvas_); } + + // Returns the PlatformSurface to use for native platform drawing calls. + PlatformSurface GetPlatformSurface() { return platform_surface_; } + private: + SkCanvas* canvas_; + PlatformSurface platform_surface_; + + // Disallow copy and assign + ScopedPlatformPaint(const ScopedPlatformPaint&); + ScopedPlatformPaint& operator=(const ScopedPlatformPaint&); +}; + } // namespace skia #endif // SKIA_EXT_PLATFORM_CANVAS_H_ diff --git a/skia/ext/platform_canvas_linux.cc b/skia/ext/platform_canvas_linux.cc index c059544..ea0f0c8 100644 --- a/skia/ext/platform_canvas_linux.cc +++ b/skia/ext/platform_canvas_linux.cc @@ -6,8 +6,8 @@ #include <cairo/cairo.h> -#include "skia/ext/platform_device_linux.h" -#include "skia/ext/bitmap_platform_device_linux.h" +#include "skia/ext/bitmap_platform_device.h" +#include "skia/ext/platform_device.h" #include "third_party/skia/include/core/SkTypes.h" namespace skia { @@ -33,12 +33,4 @@ bool PlatformCanvas::initialize(int width, int height, bool is_opaque, width, height, is_opaque, data)); } -cairo_t* PlatformCanvas::beginPlatformPaint() const { - return getTopPlatformDevice().BeginPlatformPaint(); -} - -void PlatformCanvas::endPlatformPaint() const { - getTopPlatformDevice().EndPlatformPaint(); -} - } // namespace skia diff --git a/skia/ext/platform_canvas_mac.cc b/skia/ext/platform_canvas_mac.cc index bf6843f..fba49f2 100644 --- a/skia/ext/platform_canvas_mac.cc +++ b/skia/ext/platform_canvas_mac.cc @@ -4,7 +4,7 @@ #include "skia/ext/platform_canvas.h" -#include "skia/ext/bitmap_platform_device_mac.h" +#include "skia/ext/bitmap_platform_device.h" #include "third_party/skia/include/core/SkTypes.h" namespace skia { @@ -49,12 +49,4 @@ bool PlatformCanvas::initialize(CGContextRef context, context, width, height, is_opaque)); } -CGContextRef PlatformCanvas::beginPlatformPaint() const { - return getTopPlatformDevice().BeginPlatformPaint(); -} - -void PlatformCanvas::endPlatformPaint() const { - getTopPlatformDevice().EndPlatformPaint(); -} - } // namespace skia diff --git a/skia/ext/platform_canvas_unittest.cc b/skia/ext/platform_canvas_unittest.cc index 6e43be2..40cdc70 100644 --- a/skia/ext/platform_canvas_unittest.cc +++ b/skia/ext/platform_canvas_unittest.cc @@ -31,8 +31,8 @@ namespace { bool VerifyRect(const PlatformCanvas& canvas, uint32_t canvas_color, uint32_t rect_color, int x, int y, int w, int h) { - PlatformDevice& device = canvas.getTopPlatformDevice(); - const SkBitmap& bitmap = device.accessBitmap(false); + SkDevice* device = skia::GetTopDevice(canvas); + const SkBitmap& bitmap = device->accessBitmap(false); SkAutoLockPixels lock(bitmap); // For masking out the alpha values. @@ -70,8 +70,8 @@ bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) { bool VerifyRoundedRect(const PlatformCanvas& canvas, uint32_t canvas_color, uint32_t rect_color, int x, int y, int w, int h) { - PlatformDevice& device = canvas.getTopPlatformDevice(); - const SkBitmap& bitmap = device.accessBitmap(false); + SkDevice* device = skia::GetTopDevice(canvas); + const SkBitmap& bitmap = device->accessBitmap(false); SkAutoLockPixels lock(bitmap); // Check corner points first. They should be of canvas_color. @@ -103,7 +103,8 @@ bool VerifyCanvasColor(const PlatformCanvas& canvas, uint32_t canvas_color) { #if defined(OS_WIN) void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { - HDC dc = canvas.beginPlatformPaint(); + skia::ScopedPlatformPaint scoped_platform_paint(&canvas); + HDC dc = scoped_platform_paint.GetPlatformSurface(); RECT inner_rc; inner_rc.left = x; @@ -111,21 +112,18 @@ void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { inner_rc.right = x + w; inner_rc.bottom = y + h; FillRect(dc, &inner_rc, reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH))); - - canvas.endPlatformPaint(); } #elif defined(OS_MACOSX) void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { - CGContextRef context = canvas.beginPlatformPaint(); - + skia::ScopedPlatformPaint scoped_platform_paint(&canvas); + CGContextRef context = scoped_platform_paint.GetPlatformSurface(); + CGRect inner_rc = CGRectMake(x, y, w, h); // RGBA opaque black CGColorRef black = CGColorCreateGenericRGB(0.0, 0.0, 0.0, 1.0); CGContextSetFillColorWithColor(context, black); CGColorRelease(black); CGContextFillRect(context, inner_rc); - - canvas.endPlatformPaint(); } #else void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { @@ -244,7 +242,7 @@ TEST(PlatformCanvas, FillLayer) { LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); DrawNativeRect(canvas, 0, 0, 100, 100); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(0, 0, 100, 100); + MakeOpaque(&canvas, 0, 0, 100, 100); #endif } EXPECT_TRUE(VerifyBlackRect(canvas, kLayerX, kLayerY, kLayerW, kLayerH)); @@ -255,8 +253,7 @@ TEST(PlatformCanvas, FillLayer) { LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(kInnerX, kInnerY, - kInnerW, kInnerH); + MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH); #endif } EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH)); @@ -269,8 +266,7 @@ TEST(PlatformCanvas, FillLayer) { AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH); DrawNativeRect(canvas, 0, 0, 100, 100); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque( - kInnerX, kInnerY, kInnerW, kInnerH); + MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH); #endif canvas.restore(); } @@ -284,7 +280,7 @@ TEST(PlatformCanvas, FillLayer) { LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); DrawNativeRect(canvas, 0, 0, 100, 100); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(0, 0, 100, 100); + MakeOpaque(&canvas, 0, 0, 100, 100); #endif } canvas.restore(); @@ -305,7 +301,7 @@ TEST(PlatformCanvas, TranslateLayer) { LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); DrawNativeRect(canvas, 0, 0, 100, 100); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(0, 0, 100, 100); + MakeOpaque(&canvas, 0, 0, 100, 100); #endif } canvas.restore(); @@ -320,8 +316,7 @@ TEST(PlatformCanvas, TranslateLayer) { LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(kInnerX, kInnerY, - kInnerW, kInnerH); + MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH); #endif } canvas.restore(); @@ -336,8 +331,7 @@ TEST(PlatformCanvas, TranslateLayer) { canvas.translate(1, 1); DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(kInnerX, kInnerY, - kInnerW, kInnerH); + MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH); #endif } canvas.restore(); @@ -355,8 +349,7 @@ TEST(PlatformCanvas, TranslateLayer) { AddClip(canvas, kInnerX + 1, kInnerY + 1, kInnerW - 1, kInnerH - 1); DrawNativeRect(canvas, 0, 0, 100, 100); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(kLayerX, kLayerY, - kLayerW, kLayerH); + MakeOpaque(&canvas, kLayerX, kLayerY, kLayerW, kLayerH); #endif } canvas.restore(); @@ -384,8 +377,7 @@ TEST(PlatformCanvas, TranslateLayer) { DrawNativeRect(canvas, 0, 0, 100, 100); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(kLayerX, kLayerY, - kLayerW, kLayerH); + MakeOpaque(&canvas, kLayerX, kLayerY, kLayerW, kLayerH); #endif } canvas.restore(); diff --git a/skia/ext/platform_canvas_win.cc b/skia/ext/platform_canvas_win.cc index a6381ed..116ba66 100644 --- a/skia/ext/platform_canvas_win.cc +++ b/skia/ext/platform_canvas_win.cc @@ -106,12 +106,4 @@ bool PlatformCanvas::initialize(int width, width, height, is_opaque, shared_section)); } -HDC PlatformCanvas::beginPlatformPaint() const { - return getTopPlatformDevice().BeginPlatformPaint(); -} - -void PlatformCanvas::endPlatformPaint() const { - return getTopPlatformDevice().EndPlatformPaint(); -} - } // namespace skia diff --git a/skia/ext/platform_device.cc b/skia/ext/platform_device.cc new file mode 100644 index 0000000..eff5d4f --- /dev/null +++ b/skia/ext/platform_device.cc @@ -0,0 +1,74 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "skia/ext/platform_device.h" + +#include "third_party/skia/include/core/SkMetaData.h" + +namespace skia { + +namespace { +const char* kDevicePlatformBehaviour = "CrDevicePlatformBehaviour"; +} + +void SetPlatformDevice(SkDevice* device, PlatformDevice* platform_behaviour) { + SkMetaData& meta_data = device->getMetaData(); + meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour); +} + +PlatformDevice* GetPlatformDevice(SkDevice* device) { + SkMetaData& meta_data = device->getMetaData(); + PlatformDevice* device_behaviour = NULL; + if (meta_data.findPtr(kDevicePlatformBehaviour, + reinterpret_cast<void**>(&device_behaviour))) + return device_behaviour; + + return NULL; +} + +PlatformSurface BeginPlatformPaint(SkDevice* device) { + PlatformDevice* platform_device = GetPlatformDevice(device); + if (platform_device) + return platform_device->BeginPlatformPaint(); + + return 0; +} + +void EndPlatformPaint(SkDevice* device) { + PlatformDevice* platform_device = GetPlatformDevice(device); + if (platform_device) + return platform_device->EndPlatformPaint(); +} + +bool IsVectorial(SkDevice* device) { + PlatformDevice* platform_device = GetPlatformDevice(device); + if (platform_device) + return platform_device->IsVectorial(); + + return device->getDeviceCapabilities() & SkDevice::kVector_Capability; +} + +bool IsNativeFontRenderingAllowed(SkDevice* device) { + PlatformDevice* platform_device = GetPlatformDevice(device); + if (platform_device) + return platform_device->IsNativeFontRenderingAllowed(); + + return false; +} + +void DrawToNativeContext(SkDevice* device, PlatformSurface context, + int x, int y, const PlatformRect* src_rect) { + PlatformDevice* platform_device = GetPlatformDevice(device); + if (platform_device) + platform_device->DrawToNativeContext(context, x, y, src_rect); +} + +void MakeOpaque(SkDevice* device, int x, int y, int width, int height) { + PlatformDevice* platform_device = GetPlatformDevice(device); + if (platform_device) + platform_device->MakeOpaque(x, y, width, height); +} + +} // namespace skia + diff --git a/skia/ext/platform_device.h b/skia/ext/platform_device.h index 971c0a7..4f876d9 100644 --- a/skia/ext/platform_device.h +++ b/skia/ext/platform_device.h @@ -10,6 +10,81 @@ // header file for your platform. #if defined(WIN32) +#include <windows.h> +#endif + +#include "third_party/skia/include/core/SkPreConfig.h" +#include "third_party/skia/include/core/SkColor.h" + + +class SkDevice; +struct SkIRect; + +#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) +typedef struct _cairo cairo_t; +typedef struct _cairo_rectangle cairo_rectangle_t; +#elif defined(__APPLE__) +typedef struct CGContext* CGContextRef; +typedef struct CGRect CGRect; +#endif + +namespace skia { + +class PlatformDevice; + +#if defined(WIN32) +typedef HDC PlatformSurface; +typedef RECT PlatformRect; +#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) +typedef cairo_t* PlatformSurface; +typedef cairo_rectangle_t PlatformRect; +#elif defined(__APPLE__) +typedef CGContextRef PlatformSurface; +typedef CGRect PlatformRect; +#endif + +// The following routines provide accessor points for the functionality +// exported by the various PlatformDevice ports. The PlatformDevice, and +// BitmapPlatformDevice classes inherit directly from SkDevice, which is no +// longer a supported usage-pattern for skia. In preparation of the removal of +// these classes, all calls to PlatformDevice::* should be routed through these +// helper functions. + +// Bind a PlatformDevice instance, |platform_device| to |device|. Subsequent +// calls to the functions exported below will forward the request to the +// corresponding method on the bound PlatformDevice instance. If no +// PlatformDevice has been bound to the SkDevice passed, then the routines are +// NOPS. +SK_API void SetPlatformDevice(SkDevice* device, + PlatformDevice* platform_device); +SK_API PlatformDevice* GetPlatformDevice(SkDevice* device); + +// Returns if the preferred rendering engine is vectorial or bitmap based. +// Forwards to PlatformDevice::IsVectorial, if a PlatformDevice is bound, +// otherwise falls-back to the SkDevice::getDeviceCapabilities routine. +SK_API bool IsVectorial(SkDevice* device); + +// Returns if the native font rendering engine is allowed to render text to +// this device. +SK_API bool IsNativeFontRenderingAllowed(SkDevice* device); + +// Returns the PlatformSurface used for native rendering into the device. +SK_API PlatformSurface BeginPlatformPaint(SkDevice* device); + +// Finish a previous call to BeginPlatformPaint. +SK_API void EndPlatformPaint(SkDevice* device); + +// Draws to the given PlatformSurface, |context|. Forwards to the +// PlatformDevice bound to |device|. Otherwise is a NOP. +SK_API void DrawToNativeContext(SkDevice* device, PlatformSurface context, + int x, int y, const PlatformRect* src_rect); + +// Sets the opacity of each pixel in the specified region to be opaque. +SK_API void MakeOpaque(SkDevice* device, int x, int y, int width, int height); + +} // namespace skia + +#if defined(WIN32) #include "skia/ext/platform_device_win.h" #elif defined(__APPLE__) #include "skia/ext/platform_device_mac.h" diff --git a/skia/ext/platform_device_linux.cc b/skia/ext/platform_device_linux.cc index b943120..675d19f 100644 --- a/skia/ext/platform_device_linux.cc +++ b/skia/ext/platform_device_linux.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 "skia/ext/platform_device_linux.h" +#include "skia/ext/platform_device.h" namespace skia { PlatformDevice::PlatformDevice(const SkBitmap& bitmap) : SkDevice(NULL, bitmap, /*isForLayer=*/false) { + SetPlatformDevice(this, this); } bool PlatformDevice::IsNativeFontRenderingAllowed() { @@ -18,4 +19,10 @@ void PlatformDevice::EndPlatformPaint() { // We don't need to do anything on Linux here. } +void PlatformDevice::DrawToNativeContext(PlatformSurface surface, int x, int y, + const PlatformRect* src_rect) { + // Should never be called on Linux. + SkASSERT(false); +} + } // namespace skia diff --git a/skia/ext/platform_device_linux.h b/skia/ext/platform_device_linux.h index 718560c..d10d795 100644 --- a/skia/ext/platform_device_linux.h +++ b/skia/ext/platform_device_linux.h @@ -6,10 +6,9 @@ #define SKIA_EXT_PLATFORM_DEVICE_LINUX_H_ #pragma once +#include "skia/ext/platform_device.h" #include "third_party/skia/include/core/SkDevice.h" -typedef struct _cairo cairo_t; - namespace skia { // Blindly copying the mac hierarchy. @@ -26,6 +25,12 @@ class PlatformDevice : public SkDevice { virtual PlatformSurface BeginPlatformPaint() = 0; virtual void EndPlatformPaint(); + virtual void DrawToNativeContext(PlatformSurface surface, int x, int y, + const PlatformRect* src_rect ); + + // Sets the opacity of each pixel in the specified region to be opaque. + virtual void MakeOpaque(int x, int y, int width, int height) { } + protected: // Forwards |bitmap| to SkDevice's constructor. explicit PlatformDevice(const SkBitmap& bitmap); diff --git a/skia/ext/platform_device_mac.cc b/skia/ext/platform_device_mac.cc index 73e814e..da66dbe 100644 --- a/skia/ext/platform_device_mac.cc +++ b/skia/ext/platform_device_mac.cc @@ -2,7 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "skia/ext/bitmap_platform_device_mac.h" +#include "skia/ext/platform_device.h" +#include "skia/ext/bitmap_platform_device.h" #import <ApplicationServices/ApplicationServices.h> #include "skia/ext/skia_utils_mac.h" @@ -13,28 +14,17 @@ namespace skia { -namespace { +CGContextRef GetBitmapContext(SkDevice* device) { + PlatformDevice* platform_device = GetPlatformDevice(device); + if (platform_device) + return platform_device->GetBitmapContext(); -// Constrains position and size to fit within available_size. -bool constrain(int available_size, int* position, int *size) { - if (*position < 0) { - *size += *position; - *position = 0; - } - if (*size > 0 && *position < available_size) { - int overflow = (*position + *size) - available_size; - if (overflow > 0) { - *size -= overflow; - } - return true; - } - return false; + return NULL; } -} // namespace - PlatformDevice::PlatformDevice(const SkBitmap& bitmap) : SkDevice(NULL, bitmap, /*isForLayer=*/false) { + SetPlatformDevice(this, this); } bool PlatformDevice::IsNativeFontRenderingAllowed() { diff --git a/skia/ext/platform_device_mac.h b/skia/ext/platform_device_mac.h index b65d791..0aa8d9d 100644 --- a/skia/ext/platform_device_mac.h +++ b/skia/ext/platform_device_mac.h @@ -17,6 +17,10 @@ class SkRegion; namespace skia { +// Returns the CGContext that backing the SkDevice. Forwards to the bound +// PlatformDevice. Returns NULL if no PlatformDevice is bound. +CGContextRef GetBitmapContext(SkDevice* device); + // A device is basically a wrapper around SkBitmap that provides a surface for // SkCanvas to draw into. Our device provides a surface CoreGraphics can also // write to. It also provides functionality to play well with CG drawing @@ -37,8 +41,11 @@ class PlatformDevice : public SkDevice { // context, it will be more efficient if you don't free it until after this // call so it doesn't have to be created twice. If src_rect is null, then // the entirety of the source device will be copied. - virtual void DrawToContext(CGContextRef context, int x, int y, - const CGRect* src_rect) = 0; + virtual void DrawToNativeContext(CGContextRef context, int x, int y, + const CGRect* src_rect) = 0; + + // Sets the opacity of each pixel in the specified region to be opaque. + virtual void MakeOpaque(int x, int y, int width, int height) { } // Returns if the preferred rendering engine is vectorial or bitmap based. virtual bool IsVectorial() = 0; diff --git a/skia/ext/platform_device_win.cc b/skia/ext/platform_device_win.cc index dd79ab3..7fbb746 100644 --- a/skia/ext/platform_device_win.cc +++ b/skia/ext/platform_device_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 "skia/ext/platform_device_win.h" +#include "skia/ext/platform_device.h" #include "skia/ext/skia_utils_win.h" #include "third_party/skia/include/core/SkMatrix.h" @@ -12,17 +12,7 @@ namespace skia { -PlatformDevice::PlatformDevice(const SkBitmap& bitmap) - : SkDevice(NULL, bitmap, /*isForLayer=*/false) { -} - -void PlatformDevice::EndPlatformPaint() { - // We don't clear the DC here since it will be likely to be used again. - // Flushing will be done in onAccessBitmap. -} - -// static -void PlatformDevice::InitializeDC(HDC context) { +void InitializeDC(HDC context) { // Enables world transformation. // If the GM_ADVANCED graphics mode is set, GDI always draws arcs in the // counterclockwise direction in logical space. This is equivalent to the @@ -61,6 +51,16 @@ void PlatformDevice::InitializeDC(HDC context) { SkASSERT(res != 0); } +PlatformDevice::PlatformDevice(const SkBitmap& bitmap) + : SkDevice(NULL, bitmap, /*isForLayer=*/false) { + SetPlatformDevice(this, this); +} + +void PlatformDevice::EndPlatformPaint() { + // We don't clear the DC here since it will be likely to be used again. + // Flushing will be done in onAccessBitmap. +} + // static void PlatformDevice::LoadPathToDC(HDC context, const SkPath& path) { switch (path.getFillType()) { diff --git a/skia/ext/platform_device_win.h b/skia/ext/platform_device_win.h index 5523ef9..2452fc2 100644 --- a/skia/ext/platform_device_win.h +++ b/skia/ext/platform_device_win.h @@ -18,6 +18,9 @@ class SkRegion; namespace skia { +// Initializes the default settings and colors in a device context. +SK_API void InitializeDC(HDC context); + // A device is basically a wrapper around SkBitmap that provides a surface for // SkCanvas to draw into. Our device provides a surface Windows can also write // to. It also provides functionality to play well with GDI drawing functions. @@ -40,10 +43,11 @@ class SK_API PlatformDevice : public SkDevice { // be more efficient if you don't free it until after this call so it doesn't // have to be created twice. If src_rect is null, then the entirety of the // source device will be copied. - virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect) = 0; + virtual void DrawToNativeContext(HDC dc, int x, int y, + const RECT* src_rect) = 0; // Sets the opacity of each pixel in the specified region to be opaque. - virtual void makeOpaque(int x, int y, int width, int height) { } + virtual void MakeOpaque(int x, int y, int width, int height) { } // Returns if the preferred rendering engine is vectorial or bitmap based. virtual bool IsVectorial() = 0; @@ -51,9 +55,6 @@ class SK_API PlatformDevice : public SkDevice { // Returns if GDI is allowed to render text to this device. virtual bool IsNativeFontRenderingAllowed() { return true; } - // Initializes the default settings and colors in a device context. - static void InitializeDC(HDC context); - // Loads a SkPath into the GDI context. The path can there after be used for // clipping or as a stroke. static void LoadPathToDC(HDC context, const SkPath& path); diff --git a/skia/ext/skia_utils_mac.mm b/skia/ext/skia_utils_mac.mm index ecb30ca..3c955bb 100644 --- a/skia/ext/skia_utils_mac.mm +++ b/skia/ext/skia_utils_mac.mm @@ -193,10 +193,10 @@ SkBitmap CGImageToSkBitmap(CGImageRef image) { int width = CGImageGetWidth(image); int height = CGImageGetHeight(image); - scoped_ptr<skia::BitmapPlatformDevice> device( + scoped_ptr<SkDevice> device( skia::BitmapPlatformDevice::Create(NULL, width, height, false)); - CGContextRef context = device->GetBitmapContext(); + CGContextRef context = skia::GetBitmapContext(device.get()); // We need to invert the y-axis of the canvas so that Core Graphics drawing // happens right-side up. Skia has an upper-left origin and CG has a lower- diff --git a/skia/ext/vector_canvas.cc b/skia/ext/vector_canvas.cc index 524ebbc..dbf303f 100644 --- a/skia/ext/vector_canvas.cc +++ b/skia/ext/vector_canvas.cc @@ -3,10 +3,11 @@ // found in the LICENSE file. #include "skia/ext/vector_canvas.h" +#include "third_party/skia/include/core/SkDevice.h" namespace skia { -VectorCanvas::VectorCanvas(PlatformDevice* device) +VectorCanvas::VectorCanvas(SkDevice* device) : PlatformCanvas(device->getDeviceFactory()) { setDevice(device)->unref(); // Created with refcount 1, and setDevice refs. } @@ -30,7 +31,7 @@ SkDrawFilter* VectorCanvas::setDrawFilter(SkDrawFilter* filter) { } bool VectorCanvas::IsTopDeviceVectorial() const { - return getTopPlatformDevice().IsVectorial(); + return IsVectorial(GetTopDevice(*this)); } } // namespace skia diff --git a/skia/ext/vector_canvas.h b/skia/ext/vector_canvas.h index 4b4419d..aac0400 100644 --- a/skia/ext/vector_canvas.h +++ b/skia/ext/vector_canvas.h @@ -8,9 +8,9 @@ #include "skia/ext/platform_canvas.h" -namespace skia { +class SkDevice; -class PlatformDevice; +namespace skia { // This class is a specialization of the regular PlatformCanvas. It is designed // to work with a VectorDevice to manage platform-specific drawing. It allows @@ -19,7 +19,7 @@ class PlatformDevice; class SK_API VectorCanvas : public PlatformCanvas { public: // Ownership of |device| is transfered to VectorCanvas. - explicit VectorCanvas(PlatformDevice* device); + explicit VectorCanvas(SkDevice* device); virtual ~VectorCanvas(); virtual SkBounder* setBounder(SkBounder* bounder); diff --git a/skia/ext/vector_canvas_unittest.cc b/skia/ext/vector_canvas_unittest.cc index ec8fb38..627c1d9 100644 --- a/skia/ext/vector_canvas_unittest.cc +++ b/skia/ext/vector_canvas_unittest.cc @@ -96,10 +96,11 @@ class Image { } // Loads the image from a canvas. - Image(const skia::PlatformCanvas& canvas) : ignore_alpha_(true) { + Image(skia::PlatformCanvas& canvas) : ignore_alpha_(true) { // Use a different way to access the bitmap. The normal way would be to // query the SkBitmap. - HDC context = canvas.beginPlatformPaint(); + skia::ScopedPlatformPaint scoped_platform_paint(&canvas); + HDC context = scoped_platform_paint.GetPlatformSurface(); HGDIOBJ bitmap = GetCurrentObject(context, OBJ_BITMAP); EXPECT_TRUE(bitmap != NULL); // Initialize the clip region to the entire bitmap. @@ -111,7 +112,6 @@ class Image { size_t size = row_length_ * height_; data_.resize(size); memcpy(&*data_.begin(), bitmap_data.bmBits, size); - canvas.endPlatformPaint(); } // Loads the image from a canvas. @@ -267,7 +267,7 @@ class ImageTest : public testing::Test { // kGenerating value. Returns 0 on success or any positive value between ]0, // 100] on failure. The return value is the percentage of difference between // the image in the file and the image in the canvas. - double ProcessCanvas(const skia::PlatformCanvas& canvas, + double ProcessCanvas(skia::PlatformCanvas& canvas, FilePath::StringType filename) const { filename = filename + FILE_PATH_LITERAL(".png"); switch (action_) { @@ -286,7 +286,7 @@ class ImageTest : public testing::Test { // Compares the bitmap currently loaded in the context with the file. Returns // the percentage of pixel difference between both images, between 0 and 100. - double CompareImage(const skia::PlatformCanvas& canvas, + double CompareImage(skia::PlatformCanvas& canvas, const FilePath::StringType& filename) const { Image image1(canvas); Image image2(test_file(filename)); @@ -295,7 +295,7 @@ class ImageTest : public testing::Test { } // Saves the bitmap currently loaded in the context into the file. - void SaveImage(const skia::PlatformCanvas& canvas, + void SaveImage(skia::PlatformCanvas& canvas, const FilePath::StringType& filename) const { Image(canvas).SaveToFile(test_file(filename)); } diff --git a/skia/ext/vector_platform_device_emf_win.cc b/skia/ext/vector_platform_device_emf_win.cc index d13ee4d..8b181bf 100644 --- a/skia/ext/vector_platform_device_emf_win.cc +++ b/skia/ext/vector_platform_device_emf_win.cc @@ -435,8 +435,8 @@ void VectorPlatformDeviceEmf::setMatrixClip(const SkMatrix& transform, LoadClipRegion(); } -void VectorPlatformDeviceEmf::drawToHDC(HDC dc, int x, int y, - const RECT* src_rect) { +void VectorPlatformDeviceEmf::DrawToNativeContext(HDC dc, int x, int y, + const RECT* src_rect) { SkASSERT(false); } diff --git a/skia/ext/vector_platform_device_emf_win.h b/skia/ext/vector_platform_device_emf_win.h index 4662475..1a27041 100644 --- a/skia/ext/vector_platform_device_emf_win.h +++ b/skia/ext/vector_platform_device_emf_win.h @@ -73,7 +73,7 @@ class VectorPlatformDeviceEmf : public PlatformDevice { virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, const SkClipStack&); - virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect); + virtual void DrawToNativeContext(HDC dc, int x, int y, const RECT* src_rect); virtual bool IsVectorial() { return true; } void LoadClipRegion(); diff --git a/skia/ext/vector_platform_device_skia.cc b/skia/ext/vector_platform_device_skia.cc index 9421b0b..ab99873 100644 --- a/skia/ext/vector_platform_device_skia.cc +++ b/skia/ext/vector_platform_device_skia.cc @@ -209,10 +209,10 @@ void VectorPlatformDeviceSkia::drawDevice(const SkDraw& draw, } #if defined(OS_WIN) -void VectorPlatformDeviceSkia::drawToHDC(HDC dc, - int x, - int y, - const RECT* src_rect) { +void VectorPlatformDeviceSkia::DrawToNativeContext(HDC dc, + int x, + int y, + const RECT* src_rect) { SkASSERT(false); } #endif diff --git a/skia/ext/vector_platform_device_skia.h b/skia/ext/vector_platform_device_skia.h index 53c711d..4a126e5 100644 --- a/skia/ext/vector_platform_device_skia.h +++ b/skia/ext/vector_platform_device_skia.h @@ -84,7 +84,7 @@ class VectorPlatformDeviceSkia : public PlatformDevice { const SkPaint&); #if defined(OS_WIN) - virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect); + virtual void DrawToNativeContext(HDC dc, int x, int y, const RECT* src_rect); #endif protected: diff --git a/skia/skia.gyp b/skia/skia.gyp index a93d075..1d0531b 100644 --- a/skia/skia.gyp +++ b/skia/skia.gyp @@ -661,11 +661,12 @@ 'ext/image_operations.cc', 'ext/image_operations.h', 'ext/SkThread_chrome.cc', - 'ext/platform_canvas.h', 'ext/platform_canvas.cc', + 'ext/platform_canvas.h', 'ext/platform_canvas_linux.cc', 'ext/platform_canvas_mac.cc', 'ext/platform_canvas_win.cc', + 'ext/platform_device.cc', 'ext/platform_device.h', 'ext/platform_device_linux.cc', 'ext/platform_device_linux.h', diff --git a/ui/base/clipboard/clipboard_linux.cc b/ui/base/clipboard/clipboard_linux.cc index 883dcf5..13cc759 100644 --- a/ui/base/clipboard/clipboard_linux.cc +++ b/ui/base/clipboard/clipboard_linux.cc @@ -388,10 +388,10 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const { gfx::CanvasSkia canvas(gdk_pixbuf_get_width(pixbuf.get()), gdk_pixbuf_get_height(pixbuf.get()), false); - cairo_t* context = canvas.beginPlatformPaint(); + skia::ScopedPlatformPaint scoped_platform_paint(&canvas); + cairo_t* context = scoped_platform_paint.GetPlatformSurface(); gdk_cairo_set_source_pixbuf(context, pixbuf.get(), 0.0, 0.0); cairo_paint(context); - canvas.endPlatformPaint(); return canvas.ExtractBitmap(); } diff --git a/ui/base/clipboard/clipboard_mac.mm b/ui/base/clipboard/clipboard_mac.mm index 63d456b..eb89565 100644 --- a/ui/base/clipboard/clipboard_mac.mm +++ b/ui/base/clipboard/clipboard_mac.mm @@ -253,7 +253,8 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const { int height = [image size].height; gfx::CanvasSkia canvas(width, height, false); - CGContextRef gc = canvas.beginPlatformPaint(); + skia::ScopedPlatformPaint scoped_platform_paint(&canvas); + CGContextRef gc = scoped_platform_paint.GetPlatformSurface(); NSGraphicsContext* cocoa_gc = [NSGraphicsContext graphicsContextWithGraphicsPort:gc flipped:NO]; [NSGraphicsContext setCurrentContext:cocoa_gc]; @@ -262,7 +263,6 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const { operation:NSCompositeCopy fraction:1.0]; [NSGraphicsContext restoreGraphicsState]; - canvas.endPlatformPaint(); return canvas.ExtractBitmap(); } return SkBitmap(); diff --git a/ui/base/clipboard/clipboard_win.cc b/ui/base/clipboard/clipboard_win.cc index 013da58..eb4f34b 100644 --- a/ui/base/clipboard/clipboard_win.cc +++ b/ui/base/clipboard/clipboard_win.cc @@ -456,9 +456,9 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const { gfx::CanvasSkia canvas(width, height, false); - HDC destination_dc = canvas.beginPlatformPaint(); + skia::ScopedPlatformPaint scoped_platform_paint(&canvas); + HDC destination_dc = scoped_platform_paint.GetPlatformSurface(); ::BitBlt(destination_dc, 0, 0, width, height, source_dc, 0, 0, SRCCOPY); - canvas.endPlatformPaint(); return canvas.ExtractBitmap(); } diff --git a/ui/gfx/blit.cc b/ui/gfx/blit.cc index 76411a3..a9eeef8 100644 --- a/ui/gfx/blit.cc +++ b/ui/gfx/blit.cc @@ -35,7 +35,7 @@ bool HasClipOrTransform(const skia::PlatformCanvas& canvas) { // Now we know the clip is a regular rectangle, make sure it covers the // entire canvas. - const SkBitmap& bitmap = canvas.getTopPlatformDevice().accessBitmap(false); + const SkBitmap& bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); const SkIRect& clip_bounds = clip_region.getBounds(); if (clip_bounds.fLeft != 0 || clip_bounds.fTop != 0 || clip_bounds.fRight != bitmap.width() || @@ -95,9 +95,9 @@ void BlitContextToCanvas(skia::PlatformCanvas *dst_canvas, const Rect& dst_rect, NativeDrawingContext src_context, const Point& src_origin) { - BlitContextToContext(dst_canvas->beginPlatformPaint(), dst_rect, + BlitContextToContext(skia::BeginPlatformPaint(dst_canvas), dst_rect, src_context, src_origin); - dst_canvas->endPlatformPaint(); + skia::EndPlatformPaint(dst_canvas); } void BlitCanvasToContext(NativeDrawingContext dst_context, @@ -105,18 +105,18 @@ void BlitCanvasToContext(NativeDrawingContext dst_context, skia::PlatformCanvas *src_canvas, const Point& src_origin) { BlitContextToContext(dst_context, dst_rect, - src_canvas->beginPlatformPaint(), src_origin); - src_canvas->endPlatformPaint(); + skia::BeginPlatformPaint(src_canvas), src_origin); + skia::EndPlatformPaint(src_canvas); } void BlitCanvasToCanvas(skia::PlatformCanvas *dst_canvas, const Rect& dst_rect, skia::PlatformCanvas *src_canvas, const Point& src_origin) { - BlitContextToContext(dst_canvas->beginPlatformPaint(), dst_rect, - src_canvas->beginPlatformPaint(), src_origin); - src_canvas->endPlatformPaint(); - dst_canvas->endPlatformPaint(); + BlitContextToContext(skia::BeginPlatformPaint(dst_canvas), dst_rect, + skia::BeginPlatformPaint(src_canvas), src_origin); + skia::EndPlatformPaint(src_canvas); + skia::EndPlatformPaint(dst_canvas); } #if defined(OS_WIN) @@ -125,13 +125,12 @@ void ScrollCanvas(skia::PlatformCanvas* canvas, const gfx::Rect& clip, const gfx::Point& amount) { DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff. - HDC hdc = canvas->beginPlatformPaint(); + skia::ScopedPlatformPaint scoped_platform_paint(canvas); + HDC hdc = scoped_platform_paint.GetPlatformSurface(); RECT damaged_rect; RECT r = clip.ToRECT(); ScrollDC(hdc, amount.x(), amount.y(), NULL, &r, NULL, &damaged_rect); - - canvas->endPlatformPaint(); } #elif defined(OS_POSIX) @@ -144,7 +143,7 @@ void ScrollCanvas(skia::PlatformCanvas* canvas, const gfx::Point& amount) { DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff. SkBitmap& bitmap = const_cast<SkBitmap&>( - canvas->getTopPlatformDevice().accessBitmap(true)); + skia::GetTopDevice(*canvas)->accessBitmap(true)); SkAutoLockPixels lock(bitmap); // We expect all coords to be inside the canvas, so clip here. diff --git a/ui/gfx/blit_unittest.cc b/ui/gfx/blit_unittest.cc index 356c66f..0a3217b 100644 --- a/ui/gfx/blit_unittest.cc +++ b/ui/gfx/blit_unittest.cc @@ -20,7 +20,7 @@ namespace { template<int w, int h> void SetToCanvas(skia::PlatformCanvas* canvas, uint8 values[h][w]) { SkBitmap& bitmap = const_cast<SkBitmap&>( - canvas->getTopPlatformDevice().accessBitmap(true)); + skia::GetTopDevice(*canvas)->accessBitmap(true)); SkAutoLockPixels lock(bitmap); ASSERT_EQ(w, bitmap.width()); ASSERT_EQ(h, bitmap.height()); @@ -40,7 +40,7 @@ void SetToCanvas(skia::PlatformCanvas* canvas, uint8 values[h][w]) { template<int w, int h> void VerifyCanvasValues(skia::PlatformCanvas* canvas, uint8 values[h][w]) { SkBitmap& bitmap = const_cast<SkBitmap&>( - canvas->getTopPlatformDevice().accessBitmap(true)); + skia::GetTopDevice(*canvas)->accessBitmap(true)); SkAutoLockPixels lock(bitmap); ASSERT_EQ(w, bitmap.width()); ASSERT_EQ(h, bitmap.height()); diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc index 1cec581..3d88276 100644 --- a/ui/gfx/canvas_skia.cc +++ b/ui/gfx/canvas_skia.cc @@ -324,11 +324,11 @@ void CanvasSkia::TileImageInt(const SkBitmap& bitmap, } gfx::NativeDrawingContext CanvasSkia::BeginPlatformPaint() { - return beginPlatformPaint(); + return skia::BeginPlatformPaint(this); } void CanvasSkia::EndPlatformPaint() { - endPlatformPaint(); + skia::EndPlatformPaint(this); } void CanvasSkia::Transform(const ui::Transform& transform) { diff --git a/ui/gfx/canvas_skia_linux.cc b/ui/gfx/canvas_skia_linux.cc index 796bfb8..1d5d298 100644 --- a/ui/gfx/canvas_skia_linux.cc +++ b/ui/gfx/canvas_skia_linux.cc @@ -208,7 +208,7 @@ DrawStringContext::DrawStringContext(gfx::CanvasSkia* canvas, text_height_(0) { DCHECK(!bounds_.IsEmpty()); - cr_ = canvas_->beginPlatformPaint(); + cr_ = skia::BeginPlatformPaint(canvas_); layout_ = pango_cairo_create_layout(cr_); SetupPangoLayout(layout_, text, font, bounds_.width(), flags_); @@ -246,8 +246,10 @@ DrawStringContext::~DrawStringContext() { } cairo_restore(cr_); + skia::EndPlatformPaint(canvas_); + g_object_unref(layout_); - // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. + // NOTE: BeginPlatformPaint returned its surface, we shouldn't destroy it. } void DrawStringContext::Draw(const SkColor& text_color) { @@ -266,32 +268,33 @@ void DrawStringContext::DrawWithHalo(const SkColor& text_color, text_canvas.FillRectInt(static_cast<SkColor>(0), 0, 0, bounds_.width() + 2, bounds_.height() + 2); - cairo_t* text_cr = text_canvas.beginPlatformPaint(); - - cairo_move_to(text_cr, 2, 1); - pango_cairo_layout_path(text_cr, layout_); - - cairo_set_source_rgba(text_cr, - SkColorGetR(halo_color) / 255.0, - SkColorGetG(halo_color) / 255.0, - SkColorGetB(halo_color) / 255.0, - SkColorGetA(halo_color) / 255.0); - cairo_set_line_width(text_cr, 2.0); - cairo_set_line_join(text_cr, CAIRO_LINE_JOIN_ROUND); - cairo_stroke_preserve(text_cr); - - cairo_set_operator(text_cr, CAIRO_OPERATOR_SOURCE); - cairo_set_source_rgba(text_cr, - SkColorGetR(text_color) / 255.0, - SkColorGetG(text_color) / 255.0, - SkColorGetB(text_color) / 255.0, - SkColorGetA(text_color) / 255.0); - cairo_fill(text_cr); - - text_canvas.endPlatformPaint(); + { + skia::ScopedPlatformPaint scoped_platform_paint(&text_canvas); + cairo_t* text_cr = scoped_platform_paint.GetPlatformSurface(); + + cairo_move_to(text_cr, 2, 1); + pango_cairo_layout_path(text_cr, layout_); + + cairo_set_source_rgba(text_cr, + SkColorGetR(halo_color) / 255.0, + SkColorGetG(halo_color) / 255.0, + SkColorGetB(halo_color) / 255.0, + SkColorGetA(halo_color) / 255.0); + cairo_set_line_width(text_cr, 2.0); + cairo_set_line_join(text_cr, CAIRO_LINE_JOIN_ROUND); + cairo_stroke_preserve(text_cr); + + cairo_set_operator(text_cr, CAIRO_OPERATOR_SOURCE); + cairo_set_source_rgba(text_cr, + SkColorGetR(text_color) / 255.0, + SkColorGetG(text_color) / 255.0, + SkColorGetB(text_color) / 255.0, + SkColorGetA(text_color) / 255.0); + cairo_fill(text_cr); + } const SkBitmap& text_bitmap = const_cast<SkBitmap&>( - text_canvas.getTopPlatformDevice().accessBitmap(false)); + skia::GetTopDevice(text_canvas)->accessBitmap(false)); canvas_->DrawBitmapInt(text_bitmap, text_x_ - 1, text_y_ - 1); } @@ -379,7 +382,8 @@ void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { return; } - cairo_t* cr = beginPlatformPaint(); + skia::ScopedPlatformPaint scoped_platform_paint(this); + cairo_t* cr = scoped_platform_paint.GetPlatformSurface(); gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); cairo_paint(cr); } diff --git a/ui/gfx/canvas_skia_mac.mm b/ui/gfx/canvas_skia_mac.mm index aacf100..1c78781 100644 --- a/ui/gfx/canvas_skia_mac.mm +++ b/ui/gfx/canvas_skia_mac.mm @@ -48,7 +48,8 @@ void CanvasSkia::DrawStringInt(const string16& text, if (!IntersectsClipRectInt(x, y, w, h)) return; - CGContextRef context = beginPlatformPaint(); + skia::ScopedPlatformPaint scoped_platform_paint(this); + CGContextRef context = scoped_platform_paint.GetPlatformSurface(); CGContextSaveGState(context); NSColor* ns_color = [NSColor colorWithDeviceRed:SkColorGetR(color) / 255.0 @@ -83,7 +84,6 @@ void CanvasSkia::DrawStringInt(const string16& text, CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL)); CTFrameDraw(frame, context); CGContextRestoreGState(context); - endPlatformPaint(); } ui::TextureID CanvasSkia::GetTextureID() { diff --git a/ui/gfx/canvas_skia_win.cc b/ui/gfx/canvas_skia_win.cc index 47d5cbb..67491fa 100644 --- a/ui/gfx/canvas_skia_win.cc +++ b/ui/gfx/canvas_skia_win.cc @@ -138,7 +138,7 @@ int ComputeFormatFlags(int flags, const string16& text) { // Changes the alpha of the given bitmap. // If |fade_to_right| is true then the rect fades from opaque to clear, // otherwise the rect fades from clear to opaque. -void FadeBitmapRect(skia::BitmapPlatformDevice& bmp_device, +void FadeBitmapRect(SkDevice& bmp_device, const gfx::Rect& rect, bool fade_to_right) { SkBitmap bmp = bmp_device.accessBitmap(true); @@ -164,14 +164,14 @@ void FadeBitmapRect(skia::BitmapPlatformDevice& bmp_device, // this function draws black on white. It then uses the intensity of black // to determine how much alpha to use. The text is drawn in |gfx_text_rect| and // clipped to |gfx_draw_rect|. -void DrawTextAndClearBackground(skia::BitmapPlatformDevice& bmp_device, +void DrawTextAndClearBackground(SkDevice& bmp_device, HFONT font, COLORREF text_color, const string16& text, int flags, const gfx::Rect& gfx_text_rect, const gfx::Rect& gfx_draw_rect) { - HDC hdc = bmp_device.BeginPlatformPaint(); + HDC hdc = skia::BeginPlatformPaint(&bmp_device); // Clear the background by filling with white. HBRUSH fill_brush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); @@ -218,14 +218,14 @@ void DrawTextAndClearBackground(skia::BitmapPlatformDevice& bmp_device, } } - bmp_device.EndPlatformPaint(); + skia::EndPlatformPaint(&bmp_device); } // Draws the given text with a fade out gradient. |bmp_device| is a bitmap // that is used to temporary drawing. The text is drawn in |text_rect| and // clipped to |draw_rect|. void DrawTextGradientPart(HDC hdc, - skia::BitmapPlatformDevice& bmp_device, + SkDevice& bmp_device, const string16& text, const SkColor& color, HFONT font, @@ -238,11 +238,11 @@ void DrawTextGradientPart(HDC hdc, FadeBitmapRect(bmp_device, draw_rect, fade_to_right); BLENDFUNCTION blend = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA}; - HDC bmp_hdc = bmp_device.BeginPlatformPaint(); + HDC bmp_hdc = skia::BeginPlatformPaint(&bmp_device); AlphaBlend(hdc, draw_rect.x(), draw_rect.y(), draw_rect.width(), draw_rect.height(), bmp_hdc, draw_rect.x(), draw_rect.y(), draw_rect.width(), draw_rect.height(), blend); - bmp_device.EndPlatformPaint(); + skia::EndPlatformPaint(&bmp_device); } enum PrimarySide { @@ -347,16 +347,20 @@ void CanvasSkia::DrawStringInt(const string16& text, const int kMaxStringLength = 32768 - 1; // So the trailing \0 fits in 32K. string16 clamped_string(text.substr(0, kMaxStringLength)); - HDC dc = beginPlatformPaint(); - SetBkMode(dc, TRANSPARENT); - HFONT old_font = (HFONT)SelectObject(dc, font); - COLORREF brush_color = RGB(SkColorGetR(color), SkColorGetG(color), - SkColorGetB(color)); - SetTextColor(dc, brush_color); - - int f = ComputeFormatFlags(flags, clamped_string); - DoDrawText(dc, clamped_string, &text_bounds, f); - endPlatformPaint(); + HDC dc; + HFONT old_font; + { + skia::ScopedPlatformPaint scoped_platform_paint(this); + dc = scoped_platform_paint.GetPlatformSurface(); + SetBkMode(dc, TRANSPARENT); + old_font = (HFONT)SelectObject(dc, font); + COLORREF brush_color = RGB(SkColorGetR(color), SkColorGetG(color), + SkColorGetB(color)); + SetTextColor(dc, brush_color); + + int f = ComputeFormatFlags(flags, clamped_string); + DoDrawText(dc, clamped_string, &text_bounds, f); + } // Restore the old font. This way we don't have to worry if the caller // deletes the font and the DC lives longer. @@ -365,8 +369,8 @@ void CanvasSkia::DrawStringInt(const string16& text, // Windows will have cleared the alpha channel of the text we drew. Assume // we're drawing to an opaque surface, or at least the text rect area is // opaque. - getTopPlatformDevice().makeOpaque(clip.fLeft, clip.fTop, - clip.width(), clip.height()); + skia::MakeOpaque(this, clip.fLeft, clip.fTop, clip.width(), + clip.height()); } void CanvasSkia::DrawStringInt(const string16& text, @@ -430,11 +434,11 @@ void CanvasSkia::DrawStringWithHalo(const string16& text, // opaque. We have to do this first since pixelShouldGetHalo will check for // 0 to see if a pixel has been modified to transparent, and black text that // Windows draw will look transparent to it! - text_canvas.getTopPlatformDevice().makeOpaque(0, 0, w + 2, h + 2); + skia::MakeOpaque(&text_canvas, 0, 0, w + 2, h + 2); uint32_t halo_premul = SkPreMultiplyColor(halo_color); SkBitmap& text_bitmap = const_cast<SkBitmap&>( - text_canvas.getTopPlatformDevice().accessBitmap(true)); + skia::GetTopDevice(text_canvas)->accessBitmap(true)); for (int cur_y = 0; cur_y < h + 2; cur_y++) { uint32_t* text_row = text_bitmap.getAddr32(0, cur_y); for (int cur_x = 0; cur_x < w + 2; cur_x++) { @@ -553,21 +557,23 @@ void CanvasSkia::DrawFadeTruncatingString( text_rect.set_width(text_rect.width() + offset_x); // Create a temporary bitmap to draw the gradient to. - scoped_ptr<skia::BitmapPlatformDevice> gradient_bitmap( + scoped_ptr<SkDevice> gradient_bitmap( skia::BitmapPlatformDevice::create( display_rect.width(), display_rect.height(), false, NULL)); DCHECK(gradient_bitmap.get()); - HDC hdc = beginPlatformPaint(); - if (is_truncating_head) - DrawTextGradientPart(hdc, *gradient_bitmap, text, color, - font.GetNativeFont(), text_rect, head_part, is_rtl, - flags); - if (is_truncating_tail) - DrawTextGradientPart(hdc, *gradient_bitmap, text, color, - font.GetNativeFont(), text_rect, tail_part, !is_rtl, - flags); - endPlatformPaint(); + { + skia::ScopedPlatformPaint scoped_platform_paint(this); + HDC hdc = scoped_platform_paint.GetPlatformSurface(); + if (is_truncating_head) + DrawTextGradientPart(hdc, *gradient_bitmap, text, color, + font.GetNativeFont(), text_rect, head_part, is_rtl, + flags); + if (is_truncating_tail) + DrawTextGradientPart(hdc, *gradient_bitmap, text, color, + font.GetNativeFont(), text_rect, tail_part, !is_rtl, + flags); + } // Draw the solid part. save(kClip_SaveFlag); diff --git a/ui/gfx/native_theme_win.cc b/ui/gfx/native_theme_win.cc index ba33651..bb0ad558 100644 --- a/ui/gfx/native_theme_win.cc +++ b/ui/gfx/native_theme_win.cc @@ -132,7 +132,8 @@ void NativeThemeWin::Paint(SkCanvas* canvas, State state, const gfx::Rect& rect, const ExtraParams& extra) const { - HDC hdc = skia::BeginPlatformPaint(canvas); + skia::ScopedPlatformPaint scoped_platform_paint(canvas); + HDC hdc = scoped_platform_paint.GetPlatformSurface(); switch (part) { case kCheckbox: @@ -212,8 +213,6 @@ void NativeThemeWin::Paint(SkCanvas* canvas, // unsupported parts will DCHECK here. DCHECK(false); } - - skia::EndPlatformPaint(canvas); } HRESULT NativeThemeWin::PaintScrollbarArrow( diff --git a/views/controls/menu/menu_win.cc b/views/controls/menu/menu_win.cc index bf5cd4a..c4b6635 100644 --- a/views/controls/menu/menu_win.cc +++ b/views/controls/menu/menu_win.cc @@ -188,9 +188,10 @@ class MenuHostWindow : public ui::WindowImpl { gfx::CanvasSkia canvas(data->icon.width(), data->icon.height(), false); canvas.drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); canvas.DrawBitmapInt(data->icon, 0, 0); - canvas.getTopPlatformDevice().drawToHDC(hDC, lpdis->rcItem.left + - kItemLeftMargin, lpdis->rcItem.top + (lpdis->rcItem.bottom - - lpdis->rcItem.top - data->icon.height()) / 2, NULL); + skia::DrawToNativeContext( + &canvas, hDC, lpdis->rcItem.left + kItemLeftMargin, + lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - + data->icon.height()) / 2, NULL); } } else { diff --git a/views/controls/menu/native_menu_win.cc b/views/controls/menu/native_menu_win.cc index 0913a5f..6724891 100644 --- a/views/controls/menu/native_menu_win.cc +++ b/views/controls/menu/native_menu_win.cc @@ -250,8 +250,8 @@ class NativeMenuWin::MenuHostWindow { gfx::CanvasSkia canvas(icon.width(), icon.height(), false); canvas.drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); canvas.DrawBitmapInt(icon, 0, 0); - canvas.getTopPlatformDevice().drawToHDC(dc, - draw_item_struct->rcItem.left + kItemLeftMargin, + skia::DrawToNativeContext( + &canvas, dc, draw_item_struct->rcItem.left + kItemLeftMargin, draw_item_struct->rcItem.top + (draw_item_struct->rcItem.bottom - draw_item_struct->rcItem.top - icon.height()) / 2, NULL); } else if (type == ui::MenuModel::TYPE_CHECK && @@ -283,7 +283,7 @@ class NativeMenuWin::MenuHostWindow { &canvas, NativeTheme::kMenuCheck, state, bounds, extra); // Draw checkbox to menu. - canvas.getTopPlatformDevice().drawToHDC(dc, + skia::DrawToNativeContext(&canvas, dc, draw_item_struct->rcItem.left + kItemLeftMargin, draw_item_struct->rcItem.top + (draw_item_struct->rcItem.bottom - draw_item_struct->rcItem.top - config.check_height) / 2, NULL); diff --git a/views/controls/table/native_table_win.cc b/views/controls/table/native_table_win.cc index 56b0c71..25ae1db 100644 --- a/views/controls/table/native_table_win.cc +++ b/views/controls/table/native_table_win.cc @@ -548,10 +548,9 @@ LRESULT NativeTableWin::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) { (intersection.right - intersection.left); to_draw.bottom = to_draw.top + (intersection.bottom - intersection.top); - canvas.getTopPlatformDevice().drawToHDC(draw_info->nmcd.hdc, - intersection.left, - intersection.top, - &to_draw); + skia::DrawToNativeContext(&canvas, draw_info->nmcd.hdc, + intersection.left, intersection.top, + &to_draw); r = CDRF_SKIPDEFAULT; } } diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc index 4a3b1cb6..3a6aea6 100644 --- a/views/controls/table/table_view.cc +++ b/views/controls/table/table_view.cc @@ -1158,7 +1158,7 @@ void TableView::PaintAltText() { canvas.DrawStringWithHalo(alt_text_, font, SK_ColorDKGRAY, SK_ColorWHITE, 1, 1, bounds.width() - 2, bounds.height() - 2, gfx::CanvasSkia::DefaultCanvasTextAlignment()); - canvas.getTopPlatformDevice().drawToHDC(dc, bounds.x(), bounds.y(), NULL); + skia::DrawToNativeContext(&canvas, dc, bounds.x(), bounds.y(), NULL); ReleaseDC(GetNativeControlHWND(), dc); } @@ -1273,10 +1273,9 @@ LRESULT TableView::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) { (intersection.right - intersection.left); to_draw.bottom = to_draw.top + (intersection.bottom - intersection.top); - canvas.getTopPlatformDevice().drawToHDC(draw_info->nmcd.hdc, - intersection.left, - intersection.top, - &to_draw); + skia::DrawToNativeContext(&canvas, draw_info->nmcd.hdc, + intersection.left, intersection.top, + &to_draw); r = CDRF_SKIPDEFAULT; } } diff --git a/views/controls/tree/tree_view.cc b/views/controls/tree/tree_view.cc index db75226..c084803 100644 --- a/views/controls/tree/tree_view.cc +++ b/views/controls/tree/tree_view.cc @@ -755,7 +755,7 @@ LRESULT CALLBACK TreeView::TreeWndProc(HWND window, if (canvas.isEmpty()) return 0; - HDC dc = canvas.beginPlatformPaint(); + HDC dc = skia::BeginPlatformPaint(&canvas); if (base::i18n::IsRTL()) { // gfx::CanvasSkia ends up configuring the DC with a mode of // GM_ADVANCED. For some reason a graphics mode of ADVANCED triggers @@ -789,7 +789,7 @@ LRESULT CALLBACK TreeView::TreeWndProc(HWND window, // over we copy the right bits. SetViewportOrgEx(dc, 0, 0, NULL); } - canvas.endPlatformPaint(); + skia::EndPlatformPaint(&canvas); return 0; } diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc index 6ca61bc..f84bc97 100644 --- a/views/widget/native_widget_win.cc +++ b/views/widget/native_widget_win.cc @@ -1120,13 +1120,13 @@ void NativeWidgetWin::RedrawLayeredWindowContents() { GetWindowRect(&wr); SIZE size = {wr.right - wr.left, wr.bottom - wr.top}; POINT position = {wr.left, wr.top}; - HDC dib_dc = layered_window_contents_->beginPlatformPaint(); + HDC dib_dc = skia::BeginPlatformPaint(layered_window_contents_.get()); POINT zero = {0, 0}; BLENDFUNCTION blend = {AC_SRC_OVER, 0, layered_alpha_, AC_SRC_ALPHA}; UpdateLayeredWindow(hwnd(), NULL, &position, &size, dib_dc, &zero, RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); invalid_rect_.SetRect(0, 0, 0, 0); - layered_window_contents_->endPlatformPaint(); + skia::EndPlatformPaint(layered_window_contents_.get()); } void NativeWidgetWin::ClientAreaSizeChanged() { diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc index 1593c35..6e43e8b88 100644 --- a/webkit/glue/webkit_glue.cc +++ b/webkit/glue/webkit_glue.cc @@ -403,7 +403,7 @@ WebCanvas* ToWebCanvas(skia::PlatformCanvas* canvas) { #if WEBKIT_USING_SKIA return canvas; #elif WEBKIT_USING_CG - return canvas->getTopPlatformDevice().GetBitmapContext(); + return skia::GetBitmapContext(skia::GetTopDevice(*canvas)); #else NOTIMPLEMENTED(); return NULL; diff --git a/webkit/glue/webmediaplayer_impl.cc b/webkit/glue/webmediaplayer_impl.cc index 8b83468..a8fe341 100644 --- a/webkit/glue/webmediaplayer_impl.cc +++ b/webkit/glue/webmediaplayer_impl.cc @@ -687,8 +687,8 @@ void WebMediaPlayerImpl::paint(WebCanvas* canvas, // Copy the frame rendered to our temporary skia canvas onto the passed in // canvas. - skia_canvas_->getTopPlatformDevice().DrawToContext(canvas, 0, 0, - &normalized_cgrect); + skia::DrawToNativeContext(skia_canvas_.get(), canvas, 0, 0, + &normalized_cgrect); CGContextRestoreGState(canvas); #else diff --git a/webkit/plugins/npapi/webplugin_delegate_impl_gtk.cc b/webkit/plugins/npapi/webplugin_delegate_impl_gtk.cc index dc34edb..7e2f584 100644 --- a/webkit/plugins/npapi/webplugin_delegate_impl_gtk.cc +++ b/webkit/plugins/npapi/webplugin_delegate_impl_gtk.cc @@ -111,9 +111,9 @@ void WebPluginDelegateImpl::Paint(WebKit::WebCanvas* canvas, const gfx::Rect& rect) { if (!windowless_) return; - cairo_t* context = skia::BeginPlatformPaint(canvas); + skia::ScopedPlatformPaint scoped_platform_paint(canvas); + cairo_t* context = scoped_platform_paint.GetPlatformSurface(); WindowlessPaint(context, rect); - skia::EndPlatformPaint(canvas); } void WebPluginDelegateImpl::InstallMissingPlugin() { diff --git a/webkit/plugins/npapi/webplugin_delegate_impl_win.cc b/webkit/plugins/npapi/webplugin_delegate_impl_win.cc index c055773..0b4b7ee 100644 --- a/webkit/plugins/npapi/webplugin_delegate_impl_win.cc +++ b/webkit/plugins/npapi/webplugin_delegate_impl_win.cc @@ -465,9 +465,9 @@ void WebPluginDelegateImpl::PlatformDestroyInstance() { void WebPluginDelegateImpl::Paint(WebKit::WebCanvas* canvas, const gfx::Rect& rect) { if (windowless_) { - HDC hdc = skia::BeginPlatformPaint(canvas); + skia::ScopedPlatformPaint scoped_platform_paint(canvas); + HDC hdc = scoped_platform_paint.GetPlatformSurface(); WindowlessPaint(hdc, rect); - skia::EndPlatformPaint(canvas); } } diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 0da964a..a8cd049 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -1466,7 +1466,8 @@ bool PluginInstance::DrawJPEGToPlatformDC( return false; } - HDC dc = skia::BeginPlatformPaint(canvas); + skia::ScopedPlatformPaint scoped_platform_paint(canvas); + HDC dc = scoped_platform_paint.GetPlatformSurface(); // TODO(sanjeevr): This is a temporary hack. If we output a JPEG // to the EMF, the EnumEnhMetaFile call fails in the browser // process. The failure also happens if we output nothing here. @@ -1485,7 +1486,6 @@ bool PluginInstance::DrawJPEGToPlatformDC( &compressed_image.front(), reinterpret_cast<const BITMAPINFO*>(&bmi), DIB_RGB_COLORS, SRCCOPY); - skia::EndPlatformPaint(canvas); return true; } #endif // OS_WIN diff --git a/webkit/plugins/ppapi/ppb_image_data_impl.cc b/webkit/plugins/ppapi/ppb_image_data_impl.cc index 9f5c15c..2f722e0 100644 --- a/webkit/plugins/ppapi/ppb_image_data_impl.cc +++ b/webkit/plugins/ppapi/ppb_image_data_impl.cc @@ -106,7 +106,7 @@ void* PPB_ImageData_Impl::Map() { return NULL; } const SkBitmap& bitmap = - mapped_canvas_->getTopPlatformDevice().accessBitmap(true); + skia::GetTopDevice(*mapped_canvas_)->accessBitmap(true); // Our platform bitmaps are set to opaque by default, which we don't want. const_cast<SkBitmap&>(bitmap).setIsOpaque(false); @@ -129,7 +129,7 @@ int PPB_ImageData_Impl::GetSharedMemoryHandle(uint32* byte_count) const { const SkBitmap* PPB_ImageData_Impl::GetMappedBitmap() const { if (!mapped_canvas_.get()) return NULL; - return &mapped_canvas_->getTopPlatformDevice().accessBitmap(false); + return &skia::GetTopDevice(*mapped_canvas_)->accessBitmap(false); } void PPB_ImageData_Impl::Swap(PPB_ImageData_Impl* other) { diff --git a/webkit/plugins/ppapi/ppb_pdf_impl.cc b/webkit/plugins/ppapi/ppb_pdf_impl.cc index f58b823..a8be7cd 100644 --- a/webkit/plugins/ppapi/ppb_pdf_impl.cc +++ b/webkit/plugins/ppapi/ppb_pdf_impl.cc @@ -153,7 +153,7 @@ PP_Resource GetResourceImage(PP_Instance instance_id, skia::PlatformCanvas* canvas = image_data->mapped_canvas(); SkBitmap& ret_bitmap = - const_cast<SkBitmap&>(canvas->getTopPlatformDevice().accessBitmap(true)); + const_cast<SkBitmap&>(skia::GetTopDevice(*canvas)->accessBitmap(true)); if (!res_bitmap->copyTo(&ret_bitmap, SkBitmap::kARGB_8888_Config, NULL)) { return 0; } diff --git a/webkit/plugins/ppapi/ppb_scrollbar_impl.cc b/webkit/plugins/ppapi/ppb_scrollbar_impl.cc index 904c804..3820cca 100644 --- a/webkit/plugins/ppapi/ppb_scrollbar_impl.cc +++ b/webkit/plugins/ppapi/ppb_scrollbar_impl.cc @@ -178,8 +178,8 @@ bool PPB_Scrollbar_Impl::Paint(const PP_Rect* rect, PPB_ImageData_Impl* image) { #if defined(OS_WIN) if (base::win::GetVersion() == base::win::VERSION_XP) { - canvas->getTopPlatformDevice().makeOpaque( - gfx_rect.x(), gfx_rect.y(), gfx_rect.width(), gfx_rect.height()); + skia::MakeOpaque(canvas, gfx_rect.x(), gfx_rect.y(), + gfx_rect.width(), gfx_rect.height()); } #endif diff --git a/webkit/plugins/sad_plugin.cc b/webkit/plugins/sad_plugin.cc index c129d34..b85d48a 100644 --- a/webkit/plugins/sad_plugin.cc +++ b/webkit/plugins/sad_plugin.cc @@ -38,9 +38,10 @@ void PaintSadPlugin(WebKit::WebCanvas* webcanvas, // then copy that to the screen than to use the native APIs. The small speed // penalty is not important when drawing crashed plugins. #if WEBKIT_USING_SKIA - gfx::NativeDrawingContext context = skia::BeginPlatformPaint(webcanvas); + skia::ScopedPlatformPaint scoped_platform_paint(webcanvas); + gfx::NativeDrawingContext context = + scoped_platform_paint.GetPlatformSurface(); BlitCanvasToContext(context, plugin_rect, &canvas, gfx::Point(0, 0)); - skia::EndPlatformPaint(webcanvas); #elif WEBKIT_USING_CG BlitCanvasToContext(webcanvas, plugin_rect, &canvas, gfx::Point(0, 0)); #endif diff --git a/webkit/tools/test_shell/mac/webwidget_host.mm b/webkit/tools/test_shell/mac/webwidget_host.mm index 7677dbf..7610644 100644 --- a/webkit/tools/test_shell/mac/webwidget_host.mm +++ b/webkit/tools/test_shell/mac/webwidget_host.mm @@ -179,7 +179,7 @@ void WebWidgetHost::Paint() { // make sure webkit draws into our bitmap, not the window CGContextRef bitmap_context = - canvas_->getTopPlatformDevice().GetBitmapContext(); + skia::GetBitmapContext(skia::GetTopDevice(*canvas_)); [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort:bitmap_context flipped:YES]]; @@ -221,8 +221,8 @@ void WebWidgetHost::Paint() { int bitmap_width = CGBitmapContextGetWidth(bitmap_context); CGRect bitmap_rect = { { 0, 0 }, { bitmap_width, bitmap_height } }; - canvas_->getTopPlatformDevice().DrawToContext( - context, 0, client_rect.height() - bitmap_height, &bitmap_rect); + skia::DrawToNativeContext(canvas_.get(), context, 0, + client_rect.height() - bitmap_height, &bitmap_rect); [view_ unlockFocus]; } diff --git a/webkit/tools/test_shell/test_shell_webthemecontrol.cc b/webkit/tools/test_shell/test_shell_webthemecontrol.cc index 08ca901..25cd94f 100644 --- a/webkit/tools/test_shell/test_shell_webthemecontrol.cc +++ b/webkit/tools/test_shell/test_shell_webthemecontrol.cc @@ -246,7 +246,7 @@ void Control::draw() { // Indents for the the slider track. const int kSliderIndent = 2; - skia::BeginPlatformPaint(canvas_); + skia::ScopedPlatformPaint scoped_platform_paint(canvas_); switch (type_) { case kUnknown_Type: NOTREACHED(); @@ -391,7 +391,6 @@ void Control::draw() { } markState(); - skia::EndPlatformPaint(canvas_); } // Because rendering a text field is dependent on input @@ -401,7 +400,7 @@ void Control::drawTextField(bool draw_edges, bool fill_content_area, SkColor color) { SkPaint paint; - skia::BeginPlatformPaint(canvas_); + skia::ScopedPlatformPaint scoped_platform_paint(canvas_); if (fill_content_area) { paint.setColor(color); paint.setStyle(SkPaint::kFill_Style); @@ -414,14 +413,13 @@ void Control::drawTextField(bool draw_edges, bool fill_content_area, } markState(); - skia::EndPlatformPaint(canvas_); } void Control::drawProgressBar(const SkIRect& fill_rect) { SkPaint paint; - skia::BeginPlatformPaint(canvas_); + skia::ScopedPlatformPaint scoped_platform_paint(canvas_); paint.setColor(bg_color_); paint.setStyle(SkPaint::kFill_Style); canvas_->drawIRect(irect_, paint); @@ -434,7 +432,6 @@ Control::drawProgressBar(const SkIRect& fill_rect) { canvas_->drawIRect(tofill, paint); markState(); - skia::EndPlatformPaint(canvas_); } } // namespace TestShellWebTheme diff --git a/webkit/tools/test_shell/webwidget_host_gtk.cc b/webkit/tools/test_shell/webwidget_host_gtk.cc index bab38b3..b16ea3b 100644 --- a/webkit/tools/test_shell/webwidget_host_gtk.cc +++ b/webkit/tools/test_shell/webwidget_host_gtk.cc @@ -402,7 +402,8 @@ void WebWidgetHost::Paint() { gdk_window_begin_paint_rect(window, &grect); // BitBlit to the gdk window. - cairo_t* source_surface = canvas_->beginPlatformPaint(); + skia::ScopedPlatformPaint scoped_platform_paint(canvas_.get()); + cairo_t* source_surface = scoped_platform_paint.GetPlatformSurface(); cairo_t* cairo_drawable = gdk_cairo_create(window); cairo_set_source_surface(cairo_drawable, cairo_get_target(source_surface), 0, 0); diff --git a/webkit/tools/test_shell/webwidget_host_win.cc b/webkit/tools/test_shell/webwidget_host_win.cc index 17d5ae1..005c888 100644 --- a/webkit/tools/test_shell/webwidget_host_win.cc +++ b/webkit/tools/test_shell/webwidget_host_win.cc @@ -251,13 +251,13 @@ void WebWidgetHost::Paint() { // Scroll the canvas if necessary scroll_rect_ = client_rect.Intersect(scroll_rect_); if (!scroll_rect_.IsEmpty()) { - HDC hdc = canvas_->beginPlatformPaint(); + skia::ScopedPlatformPaint scoped_platform_paint(canvas_.get()); + HDC hdc = scoped_platform_paint.GetPlatformSurface(); RECT damaged_rect, r = scroll_rect_.ToRECT(); ScrollDC(hdc, scroll_dx_, scroll_dy_, NULL, &r, NULL, &damaged_rect); PaintRect(gfx::Rect(damaged_rect)); - canvas_->endPlatformPaint(); } ResetScrollRect(); @@ -279,10 +279,8 @@ void WebWidgetHost::Paint() { // Paint to the screen PAINTSTRUCT ps; BeginPaint(view_, &ps); - canvas_->getTopPlatformDevice().drawToHDC(ps.hdc, - ps.rcPaint.left, - ps.rcPaint.top, - &ps.rcPaint); + skia::DrawToNativeContext(canvas_.get(), ps.hdc, ps.rcPaint.left, + ps.rcPaint.top, &ps.rcPaint); EndPaint(view_, &ps); // Draw children |