summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-25 16:16:02 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-25 16:16:02 +0000
commitf2d4c672b6d6b80e376cff979b1ec28864b73fb6 (patch)
tree679a4a8178438947f2775a6d1ba5540be99ce00c
parent49578ea329dae7f711ca1cde1ecade01e19a4f1b (diff)
downloadchromium_src-f2d4c672b6d6b80e376cff979b1ec28864b73fb6.zip
chromium_src-f2d4c672b6d6b80e376cff979b1ec28864b73fb6.tar.gz
chromium_src-f2d4c672b6d6b80e376cff979b1ec28864b73fb6.tar.bz2
Revert 86625 - This change implements a first pass in the effort to remove the dependency of PlatformDevice within Chrome. The Skia library now provides multiple back-ends for the SkDevice class, so PlatformDevice's inheritance of SkDevice, and the assumption of instances of PlatformDevice limits the use of these new back-ends.
A new set of helper functions is provided for the PlatformDevice entry points. Upon construction of a PlatformDevice, a pointer to the interface is cached in the parent SkDevice's SkMetaData. The new helper functions forward calls to the interface cached in the metadata. BUG=NONE TEST=NONE Review URL: http://codereview.chromium.org/7019013 TBR=twiz@chromium.org Review URL: http://codereview.chromium.org/6987019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86629 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/aeropeek_manager.cc2
-rw-r--r--chrome/browser/extensions/extension_tabs_module.cc2
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_win.cc32
-rw-r--r--chrome/browser/tab_contents/thumbnail_generator.cc3
-rw-r--r--chrome/browser/tab_contents/thumbnail_generator_unittest.cc16
-rw-r--r--chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc3
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_win.cc2
-rw-r--r--chrome/browser/ui/views/tabs/dragged_tab_view.cc2
-rw-r--r--chrome/browser/ui/views/tabs/native_view_photobooth_win.cc6
-rw-r--r--chrome/browser/ui/views/theme_helpers.cc16
-rw-r--r--chrome/renderer/chrome_render_view_observer.cc13
-rw-r--r--chrome/renderer/print_web_view_helper_linux.cc2
-rw-r--r--chrome/renderer/print_web_view_helper_win.cc6
-rw-r--r--chrome/renderer/safe_browsing/phishing_thumbnailer.cc6
-rw-r--r--content/browser/renderer_host/backing_store_mac.mm4
-rw-r--r--content/browser/renderer_host/backing_store_skia.cc4
-rw-r--r--content/browser/renderer_host/backing_store_win.cc4
-rw-r--r--content/browser/renderer_host/backing_store_x.cc2
-rw-r--r--content/plugin/webplugin_proxy.cc2
-rw-r--r--content/renderer/render_widget.cc2
-rw-r--r--content/renderer/webplugin_delegate_proxy.cc21
-rw-r--r--ppapi/proxy/ppb_image_data_proxy.cc2
-rw-r--r--printing/emf_win.cc2
-rw-r--r--printing/emf_win.h2
-rw-r--r--printing/image_win.cc2
-rw-r--r--printing/metafile.h6
-rw-r--r--printing/pdf_metafile_cairo_linux.cc2
-rw-r--r--printing/pdf_metafile_cairo_linux.h3
-rw-r--r--printing/pdf_metafile_cg_mac.cc2
-rw-r--r--printing/pdf_metafile_cg_mac.h2
-rw-r--r--printing/pdf_metafile_skia.cc2
-rw-r--r--printing/pdf_metafile_skia.h3
-rw-r--r--printing/printed_document_win.cc2
-rw-r--r--printing/printing_context_win.cc4
-rw-r--r--skia/ext/bitmap_platform_device.cc2
-rw-r--r--skia/ext/bitmap_platform_device_linux.h2
-rw-r--r--skia/ext/bitmap_platform_device_mac.cc12
-rw-r--r--skia/ext/bitmap_platform_device_mac.h16
-rw-r--r--skia/ext/bitmap_platform_device_win.cc12
-rw-r--r--skia/ext/bitmap_platform_device_win.h13
-rw-r--r--skia/ext/canvas_paint_linux.h2
-rw-r--r--skia/ext/canvas_paint_mac.h2
-rw-r--r--skia/ext/canvas_paint_win.h5
-rw-r--r--skia/ext/platform_canvas.cc38
-rw-r--r--skia/ext/platform_canvas.h76
-rw-r--r--skia/ext/platform_canvas_linux.cc12
-rw-r--r--skia/ext/platform_canvas_mac.cc10
-rw-r--r--skia/ext/platform_canvas_unittest.cc44
-rw-r--r--skia/ext/platform_canvas_win.cc8
-rw-r--r--skia/ext/platform_device.cc74
-rw-r--r--skia/ext/platform_device.h75
-rw-r--r--skia/ext/platform_device_linux.cc9
-rw-r--r--skia/ext/platform_device_linux.h9
-rw-r--r--skia/ext/platform_device_mac.cc26
-rw-r--r--skia/ext/platform_device_mac.h11
-rw-r--r--skia/ext/platform_device_win.cc24
-rw-r--r--skia/ext/platform_device_win.h11
-rw-r--r--skia/ext/skia_utils_mac.mm4
-rw-r--r--skia/ext/vector_canvas.cc5
-rw-r--r--skia/ext/vector_canvas.h6
-rw-r--r--skia/ext/vector_canvas_unittest.cc12
-rw-r--r--skia/ext/vector_platform_device_emf_win.cc4
-rw-r--r--skia/ext/vector_platform_device_emf_win.h2
-rw-r--r--skia/ext/vector_platform_device_skia.cc8
-rw-r--r--skia/ext/vector_platform_device_skia.h2
-rw-r--r--skia/skia.gyp3
-rw-r--r--ui/base/clipboard/clipboard_linux.cc4
-rw-r--r--ui/base/clipboard/clipboard_mac.mm4
-rw-r--r--ui/base/clipboard/clipboard_win.cc4
-rw-r--r--ui/gfx/blit.cc25
-rw-r--r--ui/gfx/blit_unittest.cc4
-rw-r--r--ui/gfx/canvas_skia.cc4
-rw-r--r--ui/gfx/canvas_skia_linux.cc58
-rw-r--r--ui/gfx/canvas_skia_mac.mm4
-rw-r--r--ui/gfx/canvas_skia_win.cc70
-rw-r--r--ui/gfx/native_theme_win.cc5
-rw-r--r--views/controls/menu/menu_win.cc7
-rw-r--r--views/controls/menu/native_menu_win.cc6
-rw-r--r--views/controls/table/native_table_win.cc7
-rw-r--r--views/controls/table/table_view.cc9
-rw-r--r--views/controls/tree/tree_view.cc4
-rw-r--r--views/widget/native_widget_win.cc4
-rw-r--r--webkit/glue/webkit_glue.cc2
-rw-r--r--webkit/glue/webmediaplayer_impl.cc4
-rw-r--r--webkit/plugins/npapi/webplugin_delegate_impl_gtk.cc4
-rw-r--r--webkit/plugins/npapi/webplugin_delegate_impl_win.cc4
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc4
-rw-r--r--webkit/plugins/ppapi/ppb_image_data_impl.cc4
-rw-r--r--webkit/plugins/ppapi/ppb_pdf_impl.cc2
-rw-r--r--webkit/plugins/ppapi/ppb_scrollbar_impl.cc4
-rw-r--r--webkit/plugins/sad_plugin.cc5
-rw-r--r--webkit/tools/test_shell/mac/webwidget_host.mm6
-rw-r--r--webkit/tools/test_shell/test_shell_webthemecontrol.cc9
-rw-r--r--webkit/tools/test_shell/webwidget_host_gtk.cc3
-rw-r--r--webkit/tools/test_shell/webwidget_host_win.cc10
95 files changed, 437 insertions, 566 deletions
diff --git a/chrome/browser/aeropeek_manager.cc b/chrome/browser/aeropeek_manager.cc
index 79107e1..e81ea50 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 = skia::GetTopDevice(canvas)->accessBitmap(false);
+ const SkBitmap& bitmap = canvas.getTopPlatformDevice().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 2bb87d9..139d55b 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(
- skia::GetTopDevice(temp_canvas)->accessBitmap(false));
+ temp_canvas.getTopPlatformDevice().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 b8e12cf..407bc1d3 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_win.cc
+++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc
@@ -169,22 +169,20 @@ void DrawDeemphasized(const SkColor& color,
HDC backing_store_dc,
HDC paint_dc) {
gfx::CanvasSkia canvas(paint_rect.width(), paint_rect.height(), true);
- {
- 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);
- }
+ 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();
canvas.FillRectInt(color, 0, 0, paint_rect.width(), paint_rect.height());
- skia::DrawToNativeContext(&canvas, paint_dc, paint_rect.x(),
- paint_rect.y(), NULL);
+ canvas.getTopPlatformDevice().drawToHDC(paint_dc, paint_rect.x(),
+ paint_rect.y(), NULL);
}
// The plugin wrapper window which lives in the browser process has this proc
@@ -963,8 +961,8 @@ void RenderWidgetHostViewWin::DrawBackground(const RECT& dirty_rect,
dc_rect.right - dc_rect.left,
dc_rect.bottom - dc_rect.top);
- skia::DrawToNativeContext(&canvas, *dc, dirty_rect.left, dirty_rect.top,
- NULL);
+ canvas.getTopPlatformDevice().drawToHDC(*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 257d2bd..76e15ca 100644
--- a/chrome/browser/tab_contents/thumbnail_generator.cc
+++ b/chrome/browser/tab_contents/thumbnail_generator.cc
@@ -21,6 +21,7 @@
#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"
@@ -79,7 +80,7 @@ SkBitmap GetBitmapForBackingStore(
if (!backing_store->CopyFromBackingStore(gfx::Rect(backing_store->size()),
&temp_canvas))
return result;
- const SkBitmap& bmp = skia::GetTopDevice(temp_canvas)->accessBitmap(false);
+ const SkBitmap& bmp = temp_canvas.getTopPlatformDevice().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 1c8ba8c..93a43f2 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:
- skia::GetTopDevice(*canvas)->accessBitmap(true).eraseARGB(
+ canvas->getTopPlatformDevice().accessBitmap(true).eraseARGB(
0xFF, 0, 0, 0);
break;
case TRANSPORT_WHITE:
- skia::GetTopDevice(*canvas)->accessBitmap(true).eraseARGB(
+ canvas->getTopPlatformDevice().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 = skia::GetTopDevice(canvas)->accessBitmap(false);
+ SkBitmap bitmap = canvas.getTopPlatformDevice().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 = skia::GetTopDevice(canvas)->accessBitmap(false);
+ SkBitmap bitmap = canvas.getTopPlatformDevice().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 = skia::GetTopDevice(canvas)->accessBitmap(false);
+ const SkBitmap bitmap = canvas.getTopPlatformDevice().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 = skia::GetTopDevice(canvas)->accessBitmap(false);
+ const SkBitmap bitmap = canvas.getTopPlatformDevice().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 = skia::GetTopDevice(canvas)->accessBitmap(false);
+ const SkBitmap bitmap = canvas.getTopPlatformDevice().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 = skia::GetTopDevice(canvas)->accessBitmap(false);
+ const SkBitmap bitmap = canvas.getTopPlatformDevice().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 95336a1..9394154 100644
--- a/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc
+++ b/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc
@@ -655,8 +655,7 @@ SkBitmap TabRendererGtk::PaintBitmap() {
cairo_surface_t* TabRendererGtk::PaintToSurface() {
gfx::CanvasSkia canvas(width(), height(), false);
Paint(&canvas);
- return cairo_surface_reference(cairo_get_target(
- skia::BeginPlatformPaint(&canvas)));
+ return cairo_surface_reference(cairo_get_target(canvas.beginPlatformPaint()));
}
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 70f6443..0817323 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.
- skia::DrawToNativeContext(&canvas, hdc,
+ canvas.getTopPlatformDevice().drawToHDC(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 b9bc63e..4689239 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&>(
- skia::GetTopDevice(scale_canvas)->accessBitmap(true));
+ scale_canvas.getTopPlatformDevice().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 c545d44..4bfd3609 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.
- skia::MakeOpaque(canvas->AsCanvasSkia(), target_bounds.x(),
- target_bounds.y(), target_bounds.width(),
- target_bounds.height());
+ canvas->AsCanvasSkia()->getTopPlatformDevice().makeOpaque(
+ 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 1708049..4b0f6b3 100644
--- a/chrome/browser/ui/views/theme_helpers.cc
+++ b/chrome/browser/ui/views/theme_helpers.cc
@@ -9,6 +9,7 @@
#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"
@@ -31,10 +32,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()) {
- skia::ScopedPlatformPaint scoped_platform_paint(&canvas);
- HDC dc = scoped_platform_paint.GetPlatformSurface();
+ HDC dc = canvas.beginPlatformPaint();
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.
@@ -63,12 +64,11 @@ 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.
- 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);
+ skia::BitmapPlatformDevice& device =
+ static_cast<skia::BitmapPlatformDevice&>(
+ canvas.getTopPlatformDevice());
+ *c1 = 0xFF000000 | device.getColorAt(x1, 0);
+ *c2 = 0xFF000000 | device.getColorAt(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 9c19c19..113dc62 100644
--- a/chrome/renderer/chrome_render_view_observer.cc
+++ b/chrome/renderer/chrome_render_view_observer.cc
@@ -26,6 +26,7 @@
#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"
@@ -594,9 +595,10 @@ bool ChromeRenderViewObserver::CaptureFrameThumbnail(WebView* view,
if (!PaintViewIntoCanvas(view, canvas))
return false;
- SkDevice* device = skia::GetTopDevice(canvas);
+ skia::BitmapPlatformDevice& device =
+ static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
- 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();
@@ -631,7 +633,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 =
@@ -657,9 +659,10 @@ bool ChromeRenderViewObserver::CaptureSnapshot(WebView* view,
if (!PaintViewIntoCanvas(view, canvas))
return false;
- SkDevice* device = skia::GetTopDevice(canvas);
+ skia::BitmapPlatformDevice& device =
+ static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
- 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 a5eabfd..c5e8e5a 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);
- SkDevice* device = metafile->StartPageForVectorCanvas(
+ skia::PlatformDevice* 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 5b502c4..4151818 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::InitializeDC(metafile->context());
+ skia::PlatformDevice::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));
- SkDevice* device = (*metafile)->StartPageForVectorCanvas(
+ skia::PlatformDevice* 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::InitializeDC(hdc);
+ skia::PlatformDevice::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 e8a3b4f..3235ea3 100644
--- a/chrome/renderer/safe_browsing/phishing_thumbnailer.cc
+++ b/chrome/renderer/safe_browsing/phishing_thumbnailer.cc
@@ -8,6 +8,7 @@
#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"
@@ -52,11 +53,12 @@ SkBitmap GrabPhishingThumbnail(RenderView* render_view,
view->paint(webkit_glue::ToWebCanvas(&canvas),
WebRect(0, 0, view_size.width(), view_size.height()));
- SkDevice* device = skia::GetTopDevice(canvas);
+ skia::BitmapPlatformDevice& device =
+ static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
// 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 bc0e0c0..68da54e 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;
- skia::ScopedPlatformPaint scoped_platform_paint(output);
- CGContextRef temp_context = scoped_platform_paint.GetPlatformSurface();
+ CGContextRef temp_context = output->beginPlatformPaint();
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 8c79958..f756504 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 = skia::GetTopDevice(*p_canvas)->accessBitmap(false);
+ SkBitmap b = p_canvas->getTopPlatformDevice().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 = skia::GetTopDevice(*output)->accessBitmap(true);
+ SkBitmap bitmap = output->getTopPlatformDevice().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 49545d5..0a1645d7 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;
- skia::ScopedPlatformPaint scoped_platform_paint(output);
- HDC temp_dc = scoped_platform_paint.GetPlatformSurface();
+ HDC temp_dc = output->beginPlatformPaint();
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 7767c75..8561eab 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 = skia::GetTopDevice(*output)->accessBitmap(true);
+ SkBitmap bitmap = output->getTopPlatformDevice().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 014843f..e046f01 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 =
- skia::GetTopDevice(*background_canvas_)->accessBitmap(false);
+ background_canvas_->getTopPlatformDevice().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 7e98d18..98d6a4d 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?
- skia::GetTopDevice(*canvas)->accessBitmap(false);
+ canvas->getTopPlatformDevice().accessBitmap(false);
}
PaintDebugBorder(rect, canvas);
diff --git a/content/renderer/webplugin_delegate_proxy.cc b/content/renderer/webplugin_delegate_proxy.cc
index e6fa99f..91faa71 100644
--- a/content/renderer/webplugin_delegate_proxy.cc
+++ b/content/renderer/webplugin_delegate_proxy.cc
@@ -728,9 +728,7 @@ void WebPluginDelegateProxy::Paint(WebKit::WebCanvas* canvas,
// We're using the native OS APIs from here on out.
#if WEBKIT_USING_SKIA
- skia::ScopedPlatformPaint scoped_platform_paint(canvas);
- gfx::NativeDrawingContext context =
- scoped_platform_paint.GetPlatformSurface();
+ gfx::NativeDrawingContext context = skia::BeginPlatformPaint(canvas);
#elif WEBKIT_USING_CG
gfx::NativeDrawingContext context = canvas;
#endif
@@ -766,6 +764,10 @@ 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(
@@ -848,10 +850,8 @@ bool WebPluginDelegateProxy::BackgroundChanged(
int page_start_x = content_rect.x() - context_offset_x;
int page_start_y = content_rect.y() - context_offset_y;
- skia::ScopedPlatformPaint scoped_platform_paint(
- background_store_canvas_.get());
- CGContextRef bg_context = scoped_platform_paint.GetPlatformSurface();
-
+ CGContextRef bg_context =
+ background_store_canvas_->getTopPlatformDevice().GetBitmapContext();
DCHECK_EQ(CGBitmapContextGetBitsPerPixel(context),
CGBitmapContextGetBitsPerPixel(bg_context));
const unsigned char* bg_bytes = static_cast<const unsigned char*>(
@@ -869,10 +869,9 @@ bool WebPluginDelegateProxy::BackgroundChanged(
int page_start_x = static_cast<int>(page_x_double);
int page_start_y = static_cast<int>(page_y_double);
- skia::ScopedPlatformPaint scoped_platform_paint(
- background_store_canvas_.get());
- cairo_surface_t* bg_surface =cairo_get_target(
- scoped_platform_paint.GetPlatformSurface());
+ skia::PlatformDevice& device =
+ background_store_canvas_->getTopPlatformDevice();
+ cairo_surface_t* bg_surface = cairo_get_target(device.BeginPlatformPaint());
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 2117e82..767190b 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 =
- skia::GetTopDevice(*mapped_canvas_)->accessBitmap(true);
+ mapped_canvas_->getTopPlatformDevice().accessBitmap(true);
bitmap.lockPixels();
return bitmap.getAddr(0, 0);
diff --git a/printing/emf_win.cc b/printing/emf_win.cc
index 0f40496..40f4dc8 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;
}
-SkDevice* Emf::StartPageForVectorCanvas(
+skia::PlatformDevice* 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 f7e0ed5..02a1958 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 SkDevice* StartPageForVectorCanvas(
+ virtual skia::PlatformDevice* 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 de731e0..c9ad1fe 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::InitializeDC(hdc);
+ skia::PlatformDevice::InitializeDC(hdc);
bool success = metafile.Playback(hdc, NULL);
diff --git a/printing/metafile.h b/printing/metafile.h
index 84c0556..c155fbc 100644
--- a/printing/metafile.h
+++ b/printing/metafile.h
@@ -25,7 +25,9 @@ class Rect;
class Size;
}
-class SkDevice;
+namespace skia {
+class PlatformDevice;
+}
#if defined(OS_CHROMEOS)
namespace base {
@@ -54,7 +56,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 SkDevice* StartPageForVectorCanvas(
+ virtual skia::PlatformDevice* 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 5102a78..435a33c 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;
}
-SkDevice* PdfMetafileCairo::StartPageForVectorCanvas(
+skia::PlatformDevice* 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 6f07ae0..8badf5c 100644
--- a/printing/pdf_metafile_cairo_linux.h
+++ b/printing/pdf_metafile_cairo_linux.h
@@ -36,10 +36,9 @@ 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 SkDevice* StartPageForVectorCanvas(
+ virtual skia::PlatformDevice* 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 4668b2d..9320b9e 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;
}
-SkDevice* PdfMetafileCg::StartPageForVectorCanvas(
+skia::PlatformDevice* 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 5a7f56d..bffbce5 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 SkDevice* StartPageForVectorCanvas(
+ virtual skia::PlatformDevice* 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 f76eb70..80d4931 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);
}
-SkDevice* PdfMetafileSkia::StartPageForVectorCanvas(
+skia::PlatformDevice* 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 0ad2afb..3138114 100644
--- a/printing/pdf_metafile_skia.h
+++ b/printing/pdf_metafile_skia.h
@@ -29,11 +29,10 @@ class PdfMetafileSkia : public Metafile {
virtual bool Init();
virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size);
- virtual SkDevice* StartPageForVectorCanvas(
+ virtual skia::PlatformDevice* 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 ef0c686..cb25fdef 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::InitializeDC(context);
+ skia::PlatformDevice::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 07ac20b..fd0be8c 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.h"
+#include "skia/ext/platform_device_win.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::InitializeDC(context_);
+ skia::PlatformDevice::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 05037c6..bec8a63 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 927bd43..37695f1 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 8276545..543fc38 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::DrawToNativeContext(CGContextRef context, int x,
- int y, const CGRect* src_rect) {
+void BitmapPlatformDevice::DrawToContext(CGContextRef context, int x, int y,
+ const CGRect* src_rect) {
bool created_dc = false;
if (!data_->bitmap_context()) {
created_dc = true;
@@ -261,6 +261,14 @@ 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 565bbcf..f126adc 100644
--- a/skia/ext/bitmap_platform_device_mac.h
+++ b/skia/ext/bitmap_platform_device_mac.h
@@ -61,17 +61,19 @@ class BitmapPlatformDevice : public PlatformDevice {
// See warning for copy constructor above.
BitmapPlatformDevice& operator=(const BitmapPlatformDevice& other);
- // PlatformDevice overrides
virtual CGContextRef GetBitmapContext();
- 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();
-
- // SkDevice overrides
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 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);
+
protected:
// Reference counted data that can be shared between multiple devices. This
// allows copy constructors and operator= for devices to work properly. The
diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc
index dcc395d..5678b9b 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::DrawToNativeContext(HDC dc, int x, int y,
- const RECT* src_rect) {
+void BitmapPlatformDevice::drawToHDC(HDC dc, int x, int y,
+ const RECT* src_rect) {
bool created_dc = !data_->IsBitmapDCCreated();
HDC source_dc = BeginPlatformPaint();
@@ -275,6 +275,14 @@ void BitmapPlatformDevice::DrawToNativeContext(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 7197d16..7f901f5 100644
--- a/skia/ext/bitmap_platform_device_win.h
+++ b/skia/ext/bitmap_platform_device_win.h
@@ -69,21 +69,24 @@ 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 608350f..73d9617 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_ = BeginPlatformPaint(GetTopDevice(*this));
+ context_ = T::getTopPlatformDevice().BeginPlatformPaint();
}
cairo_t* context_;
diff --git a/skia/ext/canvas_paint_mac.h b/skia/ext/canvas_paint_mac.h
index c4f45b2..6cef9ba 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_ = GetBitmapContext(GetTopDevice(*this));
+ context_ = T::getTopPlatformDevice().GetBitmapContext();
}
CGContext* context_;
diff --git a/skia/ext/canvas_paint_win.h b/skia/ext/canvas_paint_win.h
index 5fe22fc..478f285 100644
--- a/skia/ext/canvas_paint_win.h
+++ b/skia/ext/canvas_paint_win.h
@@ -62,8 +62,9 @@ class CanvasPaintT : public T {
if (!isEmpty()) {
restoreToCount(1);
// Commit the drawing to the screen
- skia::DrawToNativeContext(this, paint_dc_, ps_.rcPaint.left,
- ps_.rcPaint.top, NULL);
+ getTopPlatformDevice().drawToHDC(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 c6fd17e..c48cce4 100644
--- a/skia/ext/platform_canvas.cc
+++ b/skia/ext/platform_canvas.cc
@@ -7,6 +7,14 @@
#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() {
@@ -21,6 +29,10 @@ SkDevice* PlatformCanvas::setBitmapDevice(const SkBitmap&) {
return NULL;
}
+PlatformDevice& PlatformCanvas::getTopPlatformDevice() const {
+ return *GetTopPlatformDevice(this);
+}
+
// static
size_t PlatformCanvas::StrideForWidth(unsigned width) {
return 4 * width;
@@ -39,32 +51,18 @@ 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 IsNativeFontRenderingAllowed after removing these
- // calls from WebKit.
- return IsNativeFontRenderingAllowed(GetTopDevice(*canvas));
+ // TODO(alokp): Rename PlatformDevice::IsNativeFontRenderingAllowed after
+ // removing these calls from WebKit.
+ return GetTopPlatformDevice(canvas)->IsNativeFontRenderingAllowed();
}
-PlatformSurface BeginPlatformPaint(SkCanvas* canvas) {
- return BeginPlatformPaint(GetTopDevice(*canvas));
+PlatformDevice::PlatformSurface BeginPlatformPaint(SkCanvas* canvas) {
+ return GetTopPlatformDevice(canvas)->BeginPlatformPaint();
}
void EndPlatformPaint(SkCanvas* canvas) {
- 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);
+ GetTopPlatformDevice(canvas)->EndPlatformPaint();
}
} // namespace skia
diff --git a/skia/ext/platform_canvas.h b/skia/ext/platform_canvas.h
index 58049e6..24f613a 100644
--- a/skia/ext/platform_canvas.h
+++ b/skia/ext/platform_canvas.h
@@ -63,6 +63,30 @@ 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.
@@ -85,26 +109,11 @@ 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.
@@ -115,45 +124,18 @@ 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.
-SK_API PlatformSurface BeginPlatformPaint(SkCanvas* canvas);
+//
+// Note: These functions will eventually replace
+// PlatformCanvas::beginPlatformPaint and PlatformCanvas::endPlatformPaint.
+SK_API PlatformDevice::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 ea0f0c8..c059544 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/bitmap_platform_device.h"
-#include "skia/ext/platform_device.h"
+#include "skia/ext/platform_device_linux.h"
+#include "skia/ext/bitmap_platform_device_linux.h"
#include "third_party/skia/include/core/SkTypes.h"
namespace skia {
@@ -33,4 +33,12 @@ 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 fba49f2..bf6843f 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.h"
+#include "skia/ext/bitmap_platform_device_mac.h"
#include "third_party/skia/include/core/SkTypes.h"
namespace skia {
@@ -49,4 +49,12 @@ 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 40cdc70..6e43be2 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) {
- SkDevice* device = skia::GetTopDevice(canvas);
- const SkBitmap& bitmap = device->accessBitmap(false);
+ PlatformDevice& device = canvas.getTopPlatformDevice();
+ 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) {
- SkDevice* device = skia::GetTopDevice(canvas);
- const SkBitmap& bitmap = device->accessBitmap(false);
+ PlatformDevice& device = canvas.getTopPlatformDevice();
+ const SkBitmap& bitmap = device.accessBitmap(false);
SkAutoLockPixels lock(bitmap);
// Check corner points first. They should be of canvas_color.
@@ -103,8 +103,7 @@ 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) {
- skia::ScopedPlatformPaint scoped_platform_paint(&canvas);
- HDC dc = scoped_platform_paint.GetPlatformSurface();
+ HDC dc = canvas.beginPlatformPaint();
RECT inner_rc;
inner_rc.left = x;
@@ -112,18 +111,21 @@ 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) {
- skia::ScopedPlatformPaint scoped_platform_paint(&canvas);
- CGContextRef context = scoped_platform_paint.GetPlatformSurface();
-
+ CGContextRef context = canvas.beginPlatformPaint();
+
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) {
@@ -242,7 +244,7 @@ TEST(PlatformCanvas, FillLayer) {
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
DrawNativeRect(canvas, 0, 0, 100, 100);
#if defined(OS_WIN)
- MakeOpaque(&canvas, 0, 0, 100, 100);
+ canvas.getTopPlatformDevice().makeOpaque(0, 0, 100, 100);
#endif
}
EXPECT_TRUE(VerifyBlackRect(canvas, kLayerX, kLayerY, kLayerW, kLayerH));
@@ -253,7 +255,8 @@ TEST(PlatformCanvas, FillLayer) {
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
#if defined(OS_WIN)
- MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH);
+ canvas.getTopPlatformDevice().makeOpaque(kInnerX, kInnerY,
+ kInnerW, kInnerH);
#endif
}
EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH));
@@ -266,7 +269,8 @@ TEST(PlatformCanvas, FillLayer) {
AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
DrawNativeRect(canvas, 0, 0, 100, 100);
#if defined(OS_WIN)
- MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH);
+ canvas.getTopPlatformDevice().makeOpaque(
+ kInnerX, kInnerY, kInnerW, kInnerH);
#endif
canvas.restore();
}
@@ -280,7 +284,7 @@ TEST(PlatformCanvas, FillLayer) {
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
DrawNativeRect(canvas, 0, 0, 100, 100);
#if defined(OS_WIN)
- MakeOpaque(&canvas, 0, 0, 100, 100);
+ canvas.getTopPlatformDevice().makeOpaque(0, 0, 100, 100);
#endif
}
canvas.restore();
@@ -301,7 +305,7 @@ TEST(PlatformCanvas, TranslateLayer) {
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
DrawNativeRect(canvas, 0, 0, 100, 100);
#if defined(OS_WIN)
- MakeOpaque(&canvas, 0, 0, 100, 100);
+ canvas.getTopPlatformDevice().makeOpaque(0, 0, 100, 100);
#endif
}
canvas.restore();
@@ -316,7 +320,8 @@ TEST(PlatformCanvas, TranslateLayer) {
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
#if defined(OS_WIN)
- MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH);
+ canvas.getTopPlatformDevice().makeOpaque(kInnerX, kInnerY,
+ kInnerW, kInnerH);
#endif
}
canvas.restore();
@@ -331,7 +336,8 @@ TEST(PlatformCanvas, TranslateLayer) {
canvas.translate(1, 1);
DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
#if defined(OS_WIN)
- MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH);
+ canvas.getTopPlatformDevice().makeOpaque(kInnerX, kInnerY,
+ kInnerW, kInnerH);
#endif
}
canvas.restore();
@@ -349,7 +355,8 @@ TEST(PlatformCanvas, TranslateLayer) {
AddClip(canvas, kInnerX + 1, kInnerY + 1, kInnerW - 1, kInnerH - 1);
DrawNativeRect(canvas, 0, 0, 100, 100);
#if defined(OS_WIN)
- MakeOpaque(&canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ canvas.getTopPlatformDevice().makeOpaque(kLayerX, kLayerY,
+ kLayerW, kLayerH);
#endif
}
canvas.restore();
@@ -377,7 +384,8 @@ TEST(PlatformCanvas, TranslateLayer) {
DrawNativeRect(canvas, 0, 0, 100, 100);
#if defined(OS_WIN)
- MakeOpaque(&canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ canvas.getTopPlatformDevice().makeOpaque(kLayerX, kLayerY,
+ kLayerW, kLayerH);
#endif
}
canvas.restore();
diff --git a/skia/ext/platform_canvas_win.cc b/skia/ext/platform_canvas_win.cc
index 116ba66..a6381ed 100644
--- a/skia/ext/platform_canvas_win.cc
+++ b/skia/ext/platform_canvas_win.cc
@@ -106,4 +106,12 @@ 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
deleted file mode 100644
index eff5d4f..0000000
--- a/skia/ext/platform_device.cc
+++ /dev/null
@@ -1,74 +0,0 @@
-// 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 4f876d9..971c0a7 100644
--- a/skia/ext/platform_device.h
+++ b/skia/ext/platform_device.h
@@ -10,81 +10,6 @@
// 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 675d19f..b943120 100644
--- a/skia/ext/platform_device_linux.cc
+++ b/skia/ext/platform_device_linux.cc
@@ -2,13 +2,12 @@
// 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 "skia/ext/platform_device_linux.h"
namespace skia {
PlatformDevice::PlatformDevice(const SkBitmap& bitmap)
: SkDevice(NULL, bitmap, /*isForLayer=*/false) {
- SetPlatformDevice(this, this);
}
bool PlatformDevice::IsNativeFontRenderingAllowed() {
@@ -19,10 +18,4 @@ 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 d10d795..718560c 100644
--- a/skia/ext/platform_device_linux.h
+++ b/skia/ext/platform_device_linux.h
@@ -6,9 +6,10 @@
#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.
@@ -25,12 +26,6 @@ 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 da66dbe..73e814e 100644
--- a/skia/ext/platform_device_mac.cc
+++ b/skia/ext/platform_device_mac.cc
@@ -2,8 +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.h"
-#include "skia/ext/bitmap_platform_device.h"
+#include "skia/ext/bitmap_platform_device_mac.h"
#import <ApplicationServices/ApplicationServices.h>
#include "skia/ext/skia_utils_mac.h"
@@ -14,17 +13,28 @@
namespace skia {
-CGContextRef GetBitmapContext(SkDevice* device) {
- PlatformDevice* platform_device = GetPlatformDevice(device);
- if (platform_device)
- return platform_device->GetBitmapContext();
+namespace {
- return NULL;
+// 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;
}
+} // 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 0aa8d9d..b65d791 100644
--- a/skia/ext/platform_device_mac.h
+++ b/skia/ext/platform_device_mac.h
@@ -17,10 +17,6 @@ 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
@@ -41,11 +37,8 @@ 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 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) { }
+ virtual void DrawToContext(CGContextRef context, int x, int y,
+ const CGRect* src_rect) = 0;
// 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 7fbb746..dd79ab3 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.h"
+#include "skia/ext/platform_device_win.h"
#include "skia/ext/skia_utils_win.h"
#include "third_party/skia/include/core/SkMatrix.h"
@@ -12,7 +12,17 @@
namespace skia {
-void InitializeDC(HDC context) {
+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) {
// 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
@@ -51,16 +61,6 @@ void 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 2452fc2..5523ef9 100644
--- a/skia/ext/platform_device_win.h
+++ b/skia/ext/platform_device_win.h
@@ -18,9 +18,6 @@ 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.
@@ -43,11 +40,10 @@ 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 DrawToNativeContext(HDC dc, int x, int y,
- const RECT* src_rect) = 0;
+ virtual void drawToHDC(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;
@@ -55,6 +51,9 @@ 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 3c955bb..ecb30ca 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<SkDevice> device(
+ scoped_ptr<skia::BitmapPlatformDevice> device(
skia::BitmapPlatformDevice::Create(NULL, width, height, false));
- CGContextRef context = skia::GetBitmapContext(device.get());
+ CGContextRef context = device->GetBitmapContext();
// 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 dbf303f..524ebbc 100644
--- a/skia/ext/vector_canvas.cc
+++ b/skia/ext/vector_canvas.cc
@@ -3,11 +3,10 @@
// found in the LICENSE file.
#include "skia/ext/vector_canvas.h"
-#include "third_party/skia/include/core/SkDevice.h"
namespace skia {
-VectorCanvas::VectorCanvas(SkDevice* device)
+VectorCanvas::VectorCanvas(PlatformDevice* device)
: PlatformCanvas(device->getDeviceFactory()) {
setDevice(device)->unref(); // Created with refcount 1, and setDevice refs.
}
@@ -31,7 +30,7 @@ SkDrawFilter* VectorCanvas::setDrawFilter(SkDrawFilter* filter) {
}
bool VectorCanvas::IsTopDeviceVectorial() const {
- return IsVectorial(GetTopDevice(*this));
+ return getTopPlatformDevice().IsVectorial();
}
} // namespace skia
diff --git a/skia/ext/vector_canvas.h b/skia/ext/vector_canvas.h
index aac0400..4b4419d 100644
--- a/skia/ext/vector_canvas.h
+++ b/skia/ext/vector_canvas.h
@@ -8,10 +8,10 @@
#include "skia/ext/platform_canvas.h"
-class SkDevice;
-
namespace skia {
+class PlatformDevice;
+
// This class is a specialization of the regular PlatformCanvas. It is designed
// to work with a VectorDevice to manage platform-specific drawing. It allows
// using both Skia operations and platform-specific operations. It *doesn't*
@@ -19,7 +19,7 @@ namespace skia {
class SK_API VectorCanvas : public PlatformCanvas {
public:
// Ownership of |device| is transfered to VectorCanvas.
- explicit VectorCanvas(SkDevice* device);
+ explicit VectorCanvas(PlatformDevice* 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 627c1d9..ec8fb38 100644
--- a/skia/ext/vector_canvas_unittest.cc
+++ b/skia/ext/vector_canvas_unittest.cc
@@ -96,11 +96,10 @@ class Image {
}
// Loads the image from a canvas.
- Image(skia::PlatformCanvas& canvas) : ignore_alpha_(true) {
+ Image(const skia::PlatformCanvas& canvas) : ignore_alpha_(true) {
// Use a different way to access the bitmap. The normal way would be to
// query the SkBitmap.
- skia::ScopedPlatformPaint scoped_platform_paint(&canvas);
- HDC context = scoped_platform_paint.GetPlatformSurface();
+ HDC context = canvas.beginPlatformPaint();
HGDIOBJ bitmap = GetCurrentObject(context, OBJ_BITMAP);
EXPECT_TRUE(bitmap != NULL);
// Initialize the clip region to the entire bitmap.
@@ -112,6 +111,7 @@ 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(skia::PlatformCanvas& canvas,
+ double ProcessCanvas(const 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(skia::PlatformCanvas& canvas,
+ double CompareImage(const 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(skia::PlatformCanvas& canvas,
+ void SaveImage(const 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 8b181bf..d13ee4d 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::DrawToNativeContext(HDC dc, int x, int y,
- const RECT* src_rect) {
+void VectorPlatformDeviceEmf::drawToHDC(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 1a27041..4662475 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 DrawToNativeContext(HDC dc, int x, int y, const RECT* src_rect);
+ virtual void drawToHDC(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 ab99873..9421b0b 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::DrawToNativeContext(HDC dc,
- int x,
- int y,
- const RECT* src_rect) {
+void VectorPlatformDeviceSkia::drawToHDC(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 4a126e5..53c711d 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 DrawToNativeContext(HDC dc, int x, int y, const RECT* src_rect);
+ virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect);
#endif
protected:
diff --git a/skia/skia.gyp b/skia/skia.gyp
index 1d0531b..a93d075 100644
--- a/skia/skia.gyp
+++ b/skia/skia.gyp
@@ -661,12 +661,11 @@
'ext/image_operations.cc',
'ext/image_operations.h',
'ext/SkThread_chrome.cc',
- 'ext/platform_canvas.cc',
'ext/platform_canvas.h',
+ 'ext/platform_canvas.cc',
'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 13cc759..883dcf5 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);
- skia::ScopedPlatformPaint scoped_platform_paint(&canvas);
- cairo_t* context = scoped_platform_paint.GetPlatformSurface();
+ cairo_t* context = canvas.beginPlatformPaint();
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 eb89565..63d456b 100644
--- a/ui/base/clipboard/clipboard_mac.mm
+++ b/ui/base/clipboard/clipboard_mac.mm
@@ -253,8 +253,7 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const {
int height = [image size].height;
gfx::CanvasSkia canvas(width, height, false);
- skia::ScopedPlatformPaint scoped_platform_paint(&canvas);
- CGContextRef gc = scoped_platform_paint.GetPlatformSurface();
+ CGContextRef gc = canvas.beginPlatformPaint();
NSGraphicsContext* cocoa_gc =
[NSGraphicsContext graphicsContextWithGraphicsPort:gc flipped:NO];
[NSGraphicsContext setCurrentContext:cocoa_gc];
@@ -263,6 +262,7 @@ 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 eb4f34b..013da58 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);
- skia::ScopedPlatformPaint scoped_platform_paint(&canvas);
- HDC destination_dc = scoped_platform_paint.GetPlatformSurface();
+ HDC destination_dc = canvas.beginPlatformPaint();
::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 a9eeef8..76411a3 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 = skia::GetTopDevice(canvas)->accessBitmap(false);
+ const SkBitmap& bitmap = canvas.getTopPlatformDevice().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(skia::BeginPlatformPaint(dst_canvas), dst_rect,
+ BlitContextToContext(dst_canvas->beginPlatformPaint(), dst_rect,
src_context, src_origin);
- skia::EndPlatformPaint(dst_canvas);
+ dst_canvas->endPlatformPaint();
}
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,
- skia::BeginPlatformPaint(src_canvas), src_origin);
- skia::EndPlatformPaint(src_canvas);
+ src_canvas->beginPlatformPaint(), src_origin);
+ src_canvas->endPlatformPaint();
}
void BlitCanvasToCanvas(skia::PlatformCanvas *dst_canvas,
const Rect& dst_rect,
skia::PlatformCanvas *src_canvas,
const Point& src_origin) {
- BlitContextToContext(skia::BeginPlatformPaint(dst_canvas), dst_rect,
- skia::BeginPlatformPaint(src_canvas), src_origin);
- skia::EndPlatformPaint(src_canvas);
- skia::EndPlatformPaint(dst_canvas);
+ BlitContextToContext(dst_canvas->beginPlatformPaint(), dst_rect,
+ src_canvas->beginPlatformPaint(), src_origin);
+ src_canvas->endPlatformPaint();
+ dst_canvas->endPlatformPaint();
}
#if defined(OS_WIN)
@@ -125,12 +125,13 @@ void ScrollCanvas(skia::PlatformCanvas* canvas,
const gfx::Rect& clip,
const gfx::Point& amount) {
DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff.
- skia::ScopedPlatformPaint scoped_platform_paint(canvas);
- HDC hdc = scoped_platform_paint.GetPlatformSurface();
+ HDC hdc = canvas->beginPlatformPaint();
RECT damaged_rect;
RECT r = clip.ToRECT();
ScrollDC(hdc, amount.x(), amount.y(), NULL, &r, NULL, &damaged_rect);
+
+ canvas->endPlatformPaint();
}
#elif defined(OS_POSIX)
@@ -143,7 +144,7 @@ void ScrollCanvas(skia::PlatformCanvas* canvas,
const gfx::Point& amount) {
DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff.
SkBitmap& bitmap = const_cast<SkBitmap&>(
- skia::GetTopDevice(*canvas)->accessBitmap(true));
+ canvas->getTopPlatformDevice().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 0a3217b..356c66f 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&>(
- skia::GetTopDevice(*canvas)->accessBitmap(true));
+ canvas->getTopPlatformDevice().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&>(
- skia::GetTopDevice(*canvas)->accessBitmap(true));
+ canvas->getTopPlatformDevice().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 3d88276..1cec581 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 skia::BeginPlatformPaint(this);
+ return beginPlatformPaint();
}
void CanvasSkia::EndPlatformPaint() {
- skia::EndPlatformPaint(this);
+ endPlatformPaint();
}
void CanvasSkia::Transform(const ui::Transform& transform) {
diff --git a/ui/gfx/canvas_skia_linux.cc b/ui/gfx/canvas_skia_linux.cc
index 1d5d298..796bfb8 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_ = skia::BeginPlatformPaint(canvas_);
+ cr_ = canvas_->beginPlatformPaint();
layout_ = pango_cairo_create_layout(cr_);
SetupPangoLayout(layout_, text, font, bounds_.width(), flags_);
@@ -246,10 +246,8 @@ 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) {
@@ -268,33 +266,32 @@ void DrawStringContext::DrawWithHalo(const SkColor& text_color,
text_canvas.FillRectInt(static_cast<SkColor>(0),
0, 0, bounds_.width() + 2, bounds_.height() + 2);
- {
- 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);
- }
+ 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();
const SkBitmap& text_bitmap = const_cast<SkBitmap&>(
- skia::GetTopDevice(text_canvas)->accessBitmap(false));
+ text_canvas.getTopPlatformDevice().accessBitmap(false));
canvas_->DrawBitmapInt(text_bitmap, text_x_ - 1, text_y_ - 1);
}
@@ -382,8 +379,7 @@ void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) {
return;
}
- skia::ScopedPlatformPaint scoped_platform_paint(this);
- cairo_t* cr = scoped_platform_paint.GetPlatformSurface();
+ cairo_t* cr = beginPlatformPaint();
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 1c78781..aacf100 100644
--- a/ui/gfx/canvas_skia_mac.mm
+++ b/ui/gfx/canvas_skia_mac.mm
@@ -48,8 +48,7 @@ void CanvasSkia::DrawStringInt(const string16& text,
if (!IntersectsClipRectInt(x, y, w, h))
return;
- skia::ScopedPlatformPaint scoped_platform_paint(this);
- CGContextRef context = scoped_platform_paint.GetPlatformSurface();
+ CGContextRef context = beginPlatformPaint();
CGContextSaveGState(context);
NSColor* ns_color = [NSColor colorWithDeviceRed:SkColorGetR(color) / 255.0
@@ -84,6 +83,7 @@ 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 67491fa..47d5cbb 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(SkDevice& bmp_device,
+void FadeBitmapRect(skia::BitmapPlatformDevice& bmp_device,
const gfx::Rect& rect,
bool fade_to_right) {
SkBitmap bmp = bmp_device.accessBitmap(true);
@@ -164,14 +164,14 @@ void FadeBitmapRect(SkDevice& 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(SkDevice& bmp_device,
+void DrawTextAndClearBackground(skia::BitmapPlatformDevice& 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 = skia::BeginPlatformPaint(&bmp_device);
+ HDC hdc = bmp_device.BeginPlatformPaint();
// Clear the background by filling with white.
HBRUSH fill_brush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
@@ -218,14 +218,14 @@ void DrawTextAndClearBackground(SkDevice& bmp_device,
}
}
- skia::EndPlatformPaint(&bmp_device);
+ bmp_device.EndPlatformPaint();
}
// 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,
- SkDevice& bmp_device,
+ skia::BitmapPlatformDevice& 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 = skia::BeginPlatformPaint(&bmp_device);
+ HDC bmp_hdc = bmp_device.BeginPlatformPaint();
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);
- skia::EndPlatformPaint(&bmp_device);
+ bmp_device.EndPlatformPaint();
}
enum PrimarySide {
@@ -347,20 +347,16 @@ 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;
- 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);
- }
+ 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();
// Restore the old font. This way we don't have to worry if the caller
// deletes the font and the DC lives longer.
@@ -369,8 +365,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.
- skia::MakeOpaque(this, clip.fLeft, clip.fTop, clip.width(),
- clip.height());
+ getTopPlatformDevice().makeOpaque(clip.fLeft, clip.fTop,
+ clip.width(), clip.height());
}
void CanvasSkia::DrawStringInt(const string16& text,
@@ -434,11 +430,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!
- skia::MakeOpaque(&text_canvas, 0, 0, w + 2, h + 2);
+ text_canvas.getTopPlatformDevice().makeOpaque(0, 0, w + 2, h + 2);
uint32_t halo_premul = SkPreMultiplyColor(halo_color);
SkBitmap& text_bitmap = const_cast<SkBitmap&>(
- skia::GetTopDevice(text_canvas)->accessBitmap(true));
+ text_canvas.getTopPlatformDevice().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++) {
@@ -557,23 +553,21 @@ void CanvasSkia::DrawFadeTruncatingString(
text_rect.set_width(text_rect.width() + offset_x);
// Create a temporary bitmap to draw the gradient to.
- scoped_ptr<SkDevice> gradient_bitmap(
+ scoped_ptr<skia::BitmapPlatformDevice> gradient_bitmap(
skia::BitmapPlatformDevice::create(
display_rect.width(), display_rect.height(), false, NULL));
DCHECK(gradient_bitmap.get());
- {
- 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);
- }
+ 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();
// Draw the solid part.
save(kClip_SaveFlag);
diff --git a/ui/gfx/native_theme_win.cc b/ui/gfx/native_theme_win.cc
index bb0ad558..ba33651 100644
--- a/ui/gfx/native_theme_win.cc
+++ b/ui/gfx/native_theme_win.cc
@@ -132,8 +132,7 @@ void NativeThemeWin::Paint(SkCanvas* canvas,
State state,
const gfx::Rect& rect,
const ExtraParams& extra) const {
- skia::ScopedPlatformPaint scoped_platform_paint(canvas);
- HDC hdc = scoped_platform_paint.GetPlatformSurface();
+ HDC hdc = skia::BeginPlatformPaint(canvas);
switch (part) {
case kCheckbox:
@@ -213,6 +212,8 @@ 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 c4b6635..bf5cd4a 100644
--- a/views/controls/menu/menu_win.cc
+++ b/views/controls/menu/menu_win.cc
@@ -188,10 +188,9 @@ 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);
- skia::DrawToNativeContext(
- &canvas, hDC, lpdis->rcItem.left + kItemLeftMargin,
- lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top -
- data->icon.height()) / 2, NULL);
+ canvas.getTopPlatformDevice().drawToHDC(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 6724891..0913a5f 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);
- skia::DrawToNativeContext(
- &canvas, dc, draw_item_struct->rcItem.left + kItemLeftMargin,
+ canvas.getTopPlatformDevice().drawToHDC(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.
- skia::DrawToNativeContext(&canvas, dc,
+ canvas.getTopPlatformDevice().drawToHDC(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 25ae1db..56b0c71 100644
--- a/views/controls/table/native_table_win.cc
+++ b/views/controls/table/native_table_win.cc
@@ -548,9 +548,10 @@ LRESULT NativeTableWin::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) {
(intersection.right - intersection.left);
to_draw.bottom = to_draw.top +
(intersection.bottom - intersection.top);
- skia::DrawToNativeContext(&canvas, draw_info->nmcd.hdc,
- intersection.left, intersection.top,
- &to_draw);
+ canvas.getTopPlatformDevice().drawToHDC(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 3a6aea6..4a3b1cb6 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());
- skia::DrawToNativeContext(&canvas, dc, bounds.x(), bounds.y(), NULL);
+ canvas.getTopPlatformDevice().drawToHDC(dc, bounds.x(), bounds.y(), NULL);
ReleaseDC(GetNativeControlHWND(), dc);
}
@@ -1273,9 +1273,10 @@ LRESULT TableView::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) {
(intersection.right - intersection.left);
to_draw.bottom = to_draw.top +
(intersection.bottom - intersection.top);
- skia::DrawToNativeContext(&canvas, draw_info->nmcd.hdc,
- intersection.left, intersection.top,
- &to_draw);
+ canvas.getTopPlatformDevice().drawToHDC(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 c084803..db75226 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 = skia::BeginPlatformPaint(&canvas);
+ HDC dc = canvas.beginPlatformPaint();
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);
}
- skia::EndPlatformPaint(&canvas);
+ canvas.endPlatformPaint();
return 0;
}
diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc
index f84bc97..6ca61bc 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 = skia::BeginPlatformPaint(layered_window_contents_.get());
+ HDC dib_dc = layered_window_contents_->beginPlatformPaint();
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);
- skia::EndPlatformPaint(layered_window_contents_.get());
+ layered_window_contents_->endPlatformPaint();
}
void NativeWidgetWin::ClientAreaSizeChanged() {
diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc
index 6e43e8b88..1593c35 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 skia::GetBitmapContext(skia::GetTopDevice(*canvas));
+ return canvas->getTopPlatformDevice().GetBitmapContext();
#else
NOTIMPLEMENTED();
return NULL;
diff --git a/webkit/glue/webmediaplayer_impl.cc b/webkit/glue/webmediaplayer_impl.cc
index a8fe341..8b83468 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::DrawToNativeContext(skia_canvas_.get(), canvas, 0, 0,
- &normalized_cgrect);
+ skia_canvas_->getTopPlatformDevice().DrawToContext(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 7e2f584..dc34edb 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;
- skia::ScopedPlatformPaint scoped_platform_paint(canvas);
- cairo_t* context = scoped_platform_paint.GetPlatformSurface();
+ cairo_t* context = skia::BeginPlatformPaint(canvas);
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 0b4b7ee..c055773 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_) {
- skia::ScopedPlatformPaint scoped_platform_paint(canvas);
- HDC hdc = scoped_platform_paint.GetPlatformSurface();
+ HDC hdc = skia::BeginPlatformPaint(canvas);
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 a8cd049..0da964a 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -1466,8 +1466,7 @@ bool PluginInstance::DrawJPEGToPlatformDC(
return false;
}
- skia::ScopedPlatformPaint scoped_platform_paint(canvas);
- HDC dc = scoped_platform_paint.GetPlatformSurface();
+ HDC dc = skia::BeginPlatformPaint(canvas);
// 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.
@@ -1486,6 +1485,7 @@ 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 2f722e0..9f5c15c 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 =
- skia::GetTopDevice(*mapped_canvas_)->accessBitmap(true);
+ mapped_canvas_->getTopPlatformDevice().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 &skia::GetTopDevice(*mapped_canvas_)->accessBitmap(false);
+ return &mapped_canvas_->getTopPlatformDevice().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 a8be7cd..f58b823 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&>(skia::GetTopDevice(*canvas)->accessBitmap(true));
+ const_cast<SkBitmap&>(canvas->getTopPlatformDevice().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 3820cca..904c804 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) {
- skia::MakeOpaque(canvas, gfx_rect.x(), gfx_rect.y(),
- gfx_rect.width(), gfx_rect.height());
+ canvas->getTopPlatformDevice().makeOpaque(
+ 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 b85d48a..c129d34 100644
--- a/webkit/plugins/sad_plugin.cc
+++ b/webkit/plugins/sad_plugin.cc
@@ -38,10 +38,9 @@ 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
- skia::ScopedPlatformPaint scoped_platform_paint(webcanvas);
- gfx::NativeDrawingContext context =
- scoped_platform_paint.GetPlatformSurface();
+ gfx::NativeDrawingContext context = skia::BeginPlatformPaint(webcanvas);
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 7610644..7677dbf 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 =
- skia::GetBitmapContext(skia::GetTopDevice(*canvas_));
+ canvas_->getTopPlatformDevice().GetBitmapContext();
[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 } };
- skia::DrawToNativeContext(canvas_.get(), context, 0,
- client_rect.height() - bitmap_height, &bitmap_rect);
+ canvas_->getTopPlatformDevice().DrawToContext(
+ 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 25cd94f..08ca901 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::ScopedPlatformPaint scoped_platform_paint(canvas_);
+ skia::BeginPlatformPaint(canvas_);
switch (type_) {
case kUnknown_Type:
NOTREACHED();
@@ -391,6 +391,7 @@ void Control::draw() {
}
markState();
+ skia::EndPlatformPaint(canvas_);
}
// Because rendering a text field is dependent on input
@@ -400,7 +401,7 @@ void Control::drawTextField(bool draw_edges, bool fill_content_area,
SkColor color) {
SkPaint paint;
- skia::ScopedPlatformPaint scoped_platform_paint(canvas_);
+ skia::BeginPlatformPaint(canvas_);
if (fill_content_area) {
paint.setColor(color);
paint.setStyle(SkPaint::kFill_Style);
@@ -413,13 +414,14 @@ void Control::drawTextField(bool draw_edges, bool fill_content_area,
}
markState();
+ skia::EndPlatformPaint(canvas_);
}
void
Control::drawProgressBar(const SkIRect& fill_rect) {
SkPaint paint;
- skia::ScopedPlatformPaint scoped_platform_paint(canvas_);
+ skia::BeginPlatformPaint(canvas_);
paint.setColor(bg_color_);
paint.setStyle(SkPaint::kFill_Style);
canvas_->drawIRect(irect_, paint);
@@ -432,6 +434,7 @@ 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 b16ea3b..bab38b3 100644
--- a/webkit/tools/test_shell/webwidget_host_gtk.cc
+++ b/webkit/tools/test_shell/webwidget_host_gtk.cc
@@ -402,8 +402,7 @@ void WebWidgetHost::Paint() {
gdk_window_begin_paint_rect(window, &grect);
// BitBlit to the gdk window.
- skia::ScopedPlatformPaint scoped_platform_paint(canvas_.get());
- cairo_t* source_surface = scoped_platform_paint.GetPlatformSurface();
+ cairo_t* source_surface = canvas_->beginPlatformPaint();
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 005c888..17d5ae1 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()) {
- skia::ScopedPlatformPaint scoped_platform_paint(canvas_.get());
- HDC hdc = scoped_platform_paint.GetPlatformSurface();
+ HDC hdc = canvas_->beginPlatformPaint();
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,8 +279,10 @@ void WebWidgetHost::Paint() {
// Paint to the screen
PAINTSTRUCT ps;
BeginPaint(view_, &ps);
- skia::DrawToNativeContext(canvas_.get(), ps.hdc, ps.rcPaint.left,
- ps.rcPaint.top, &ps.rcPaint);
+ canvas_->getTopPlatformDevice().drawToHDC(ps.hdc,
+ ps.rcPaint.left,
+ ps.rcPaint.top,
+ &ps.rcPaint);
EndPaint(view_, &ps);
// Draw children