OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/gfx/blit.h" |
| 6 |
| 7 #if defined(OS_LINUX) |
| 8 #include <cairo/cairo.h> |
| 9 #endif |
| 10 |
| 11 #include "base/gfx/point.h" |
| 12 #include "base/gfx/rect.h" |
| 13 #if defined(OS_MACOSX) |
| 14 #include "base/scoped_cftyperef.h" |
| 15 #endif |
| 16 #include "skia/ext/platform_canvas.h" |
| 17 #include "skia/ext/platform_device.h" |
| 18 |
| 19 namespace gfx { |
| 20 |
| 21 void BlitContextToContext(NativeDrawingContext dst_context, |
| 22 const Rect& dst_rect, |
| 23 NativeDrawingContext src_context, |
| 24 const Point& src_origin) { |
| 25 #if defined(OS_WIN) |
| 26 BitBlt(dst_context, dst_rect.x(), dst_rect.y(), |
| 27 dst_rect.width(), dst_rect.height(), |
| 28 src_context, src_origin.x(), src_origin.y(), SRCCOPY); |
| 29 #elif defined(OS_MACOSX) |
| 30 Rect src_rect(src_origin, dst_rect.size()); |
| 31 scoped_cftyperef<CGImageRef> |
| 32 src_image(CGBitmapContextCreateImage(src_context)); |
| 33 scoped_cftyperef<CGImageRef> src_sub_image( |
| 34 CGImageCreateWithImageInRect(src_image, src_rect.ToCGRect())); |
| 35 CGContextDrawImage(dst_context, dst_rect.ToCGRect(), src_sub_image); |
| 36 #elif defined(OS_LINUX) |
| 37 cairo_save(dst_context); |
| 38 double surface_x = src_origin.x(); |
| 39 double surface_y = src_origin.y(); |
| 40 cairo_user_to_device(src_context, &surface_x, &surface_y); |
| 41 cairo_set_source_surface(dst_context, cairo_get_target(src_context), |
| 42 dst_rect.x()-surface_x, dst_rect.y()-surface_y); |
| 43 cairo_rectangle(dst_context, dst_rect.x(), dst_rect.y(), |
| 44 dst_rect.width(), dst_rect.height()); |
| 45 cairo_clip(dst_context); |
| 46 cairo_paint(dst_context); |
| 47 cairo_restore(dst_context); |
| 48 #endif |
| 49 } |
| 50 |
| 51 static NativeDrawingContext GetContextFromCanvas( |
| 52 skia::PlatformCanvas *canvas) { |
| 53 skia::PlatformDevice& device = canvas->getTopPlatformDevice(); |
| 54 #if defined(OS_WIN) |
| 55 return device.getBitmapDC(); |
| 56 #elif defined(OS_MACOSX) |
| 57 return device.GetBitmapContext(); |
| 58 #elif defined(OS_LINUX) |
| 59 return device.beginPlatformPaint(); |
| 60 #endif |
| 61 } |
| 62 |
| 63 void BlitContextToCanvas(skia::PlatformCanvas *dst_canvas, |
| 64 const Rect& dst_rect, |
| 65 NativeDrawingContext src_context, |
| 66 const Point& src_origin) { |
| 67 BlitContextToContext(GetContextFromCanvas(dst_canvas), dst_rect, |
| 68 src_context, src_origin); |
| 69 } |
| 70 |
| 71 void BlitCanvasToContext(NativeDrawingContext dst_context, |
| 72 const Rect& dst_rect, |
| 73 skia::PlatformCanvas *src_canvas, |
| 74 const Point& src_origin) { |
| 75 BlitContextToContext(dst_context, dst_rect, |
| 76 GetContextFromCanvas(src_canvas), src_origin); |
| 77 } |
| 78 |
| 79 void BlitCanvasToCanvas(skia::PlatformCanvas *dst_canvas, |
| 80 const Rect& dst_rect, |
| 81 skia::PlatformCanvas *src_canvas, |
| 82 const Point& src_origin) { |
| 83 BlitContextToContext(GetContextFromCanvas(dst_canvas), dst_rect, |
| 84 GetContextFromCanvas(src_canvas), src_origin); |
| 85 } |
| 86 |
| 87 } // namespace gfx |
OLD | NEW |