summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-24 20:35:28 +0000
committerpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-24 20:35:28 +0000
commitc9e8ab9fa9097f33c892e6d806729ec35586bfe1 (patch)
tree280ced941be30dd03106b673c91e557e5c5f16dc /base
parent43e29a8583ae1f4696f0bfa58f3d256f5ac36759 (diff)
downloadchromium_src-c9e8ab9fa9097f33c892e6d806729ec35586bfe1.zip
chromium_src-c9e8ab9fa9097f33c892e6d806729ec35586bfe1.tar.gz
chromium_src-c9e8ab9fa9097f33c892e6d806729ec35586bfe1.tar.bz2
Refactor blits to be more cross-platform.
Review URL: http://codereview.chromium.org/159190 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21565 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.gyp2
-rw-r--r--base/gfx/blit.cc87
-rw-r--r--base/gfx/blit.h47
3 files changed, 136 insertions, 0 deletions
diff --git a/base/base.gyp b/base/base.gyp
index e281a43..8aa8a3a 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -538,6 +538,8 @@
'type': '<(library)',
'msvs_guid': 'A508ADD3-CECE-4E0F-8448-2F5E454DF551',
'sources': [
+ 'gfx/blit.cc',
+ 'gfx/blit.h',
'gfx/gdi_util.cc',
'gfx/gdi_util.h',
'gfx/gtk_native_view_id_manager.cc',
diff --git a/base/gfx/blit.cc b/base/gfx/blit.cc
new file mode 100644
index 0000000..2965c4c
--- /dev/null
+++ b/base/gfx/blit.cc
@@ -0,0 +1,87 @@
+// Copyright (c) 2009 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 "base/gfx/blit.h"
+
+#if defined(OS_LINUX)
+#include <cairo/cairo.h>
+#endif
+
+#include "base/gfx/point.h"
+#include "base/gfx/rect.h"
+#if defined(OS_MACOSX)
+#include "base/scoped_cftyperef.h"
+#endif
+#include "skia/ext/platform_canvas.h"
+#include "skia/ext/platform_device.h"
+
+namespace gfx {
+
+void BlitContextToContext(NativeDrawingContext dst_context,
+ const Rect& dst_rect,
+ NativeDrawingContext src_context,
+ const Point& src_origin) {
+#if defined(OS_WIN)
+ BitBlt(dst_context, dst_rect.x(), dst_rect.y(),
+ dst_rect.width(), dst_rect.height(),
+ src_context, src_origin.x(), src_origin.y(), SRCCOPY);
+#elif defined(OS_MACOSX)
+ Rect src_rect(src_origin, dst_rect.size());
+ scoped_cftyperef<CGImageRef>
+ src_image(CGBitmapContextCreateImage(src_context));
+ scoped_cftyperef<CGImageRef> src_sub_image(
+ CGImageCreateWithImageInRect(src_image, src_rect.ToCGRect()));
+ CGContextDrawImage(dst_context, dst_rect.ToCGRect(), src_sub_image);
+#elif defined(OS_LINUX)
+ cairo_save(dst_context);
+ double surface_x = src_origin.x();
+ double surface_y = src_origin.y();
+ cairo_user_to_device(src_context, &surface_x, &surface_y);
+ cairo_set_source_surface(dst_context, cairo_get_target(src_context),
+ dst_rect.x()-surface_x, dst_rect.y()-surface_y);
+ cairo_rectangle(dst_context, dst_rect.x(), dst_rect.y(),
+ dst_rect.width(), dst_rect.height());
+ cairo_clip(dst_context);
+ cairo_paint(dst_context);
+ cairo_restore(dst_context);
+#endif
+}
+
+static NativeDrawingContext GetContextFromCanvas(
+ skia::PlatformCanvas *canvas) {
+ skia::PlatformDevice& device = canvas->getTopPlatformDevice();
+#if defined(OS_WIN)
+ return device.getBitmapDC();
+#elif defined(OS_MACOSX)
+ return device.GetBitmapContext();
+#elif defined(OS_LINUX)
+ return device.beginPlatformPaint();
+#endif
+}
+
+void BlitContextToCanvas(skia::PlatformCanvas *dst_canvas,
+ const Rect& dst_rect,
+ NativeDrawingContext src_context,
+ const Point& src_origin) {
+ BlitContextToContext(GetContextFromCanvas(dst_canvas), dst_rect,
+ src_context, src_origin);
+}
+
+void BlitCanvasToContext(NativeDrawingContext dst_context,
+ const Rect& dst_rect,
+ skia::PlatformCanvas *src_canvas,
+ const Point& src_origin) {
+ BlitContextToContext(dst_context, dst_rect,
+ GetContextFromCanvas(src_canvas), src_origin);
+}
+
+void BlitCanvasToCanvas(skia::PlatformCanvas *dst_canvas,
+ const Rect& dst_rect,
+ skia::PlatformCanvas *src_canvas,
+ const Point& src_origin) {
+ BlitContextToContext(GetContextFromCanvas(dst_canvas), dst_rect,
+ GetContextFromCanvas(src_canvas), src_origin);
+}
+
+} // namespace gfx
diff --git a/base/gfx/blit.h b/base/gfx/blit.h
new file mode 100644
index 0000000..25f7a5e
--- /dev/null
+++ b/base/gfx/blit.h
@@ -0,0 +1,47 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_GFX_BLIT_H_
+#define BASE_GFX_BLIT_H_
+
+#include "base/gfx/native_widget_types.h"
+#include "base/gfx/point.h"
+#include "base/gfx/rect.h"
+
+namespace skia {
+class PlatformCanvas;
+} // namespace skia
+
+namespace gfx {
+
+class Point;
+class Rect;
+
+// Blits a rectangle from the source context into the destination context.
+void BlitContextToContext(NativeDrawingContext dst_context,
+ const Rect& dst_rect,
+ NativeDrawingContext src_context,
+ const Point& src_origin);
+
+// Blits a rectangle from the source context into the destination canvas.
+void BlitContextToCanvas(skia::PlatformCanvas *dst_canvas,
+ const Rect& dst_rect,
+ NativeDrawingContext src_context,
+ const Point& src_origin);
+
+// Blits a rectangle from the source canvas into the destination context.
+void BlitCanvasToContext(NativeDrawingContext dst_context,
+ const Rect& dst_rect,
+ skia::PlatformCanvas *src_canvas,
+ const Point& src_origin);
+
+// Blits a rectangle from the source canvas into the destination canvas.
+void BlitCanvasToCanvas(skia::PlatformCanvas *dst_canvas,
+ const Rect& dst_rect,
+ skia::PlatformCanvas *src_canvas,
+ const Point& src_origin);
+
+} // namespace gfx
+
+#endif // BASE_GFX_BLIT_H_