OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/gfx/blit.h" | 5 #include "base/gfx/blit.h" |
6 | 6 |
7 #if defined(OS_LINUX) | 7 #if defined(USE_X11) |
8 #include <cairo/cairo.h> | 8 #include <cairo/cairo.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "base/gfx/point.h" | 11 #include "base/gfx/point.h" |
12 #include "base/gfx/rect.h" | 12 #include "base/gfx/rect.h" |
13 #if defined(OS_MACOSX) | 13 #if defined(OS_MACOSX) |
14 #include "base/scoped_cftyperef.h" | 14 #include "base/scoped_cftyperef.h" |
15 #endif | 15 #endif |
16 #include "skia/ext/platform_canvas.h" | 16 #include "skia/ext/platform_canvas.h" |
17 #include "skia/ext/platform_device.h" | 17 #include "skia/ext/platform_device.h" |
(...skipping 20 matching lines...) Expand all Loading... |
38 CGFloat delta_y = flipped ? CGBitmapContextGetHeight(src_context) - | 38 CGFloat delta_y = flipped ? CGBitmapContextGetHeight(src_context) - |
39 transform.ty | 39 transform.ty |
40 : transform.ty; | 40 : transform.ty; |
41 src_rect.Offset(transform.tx, delta_y); | 41 src_rect.Offset(transform.tx, delta_y); |
42 | 42 |
43 scoped_cftyperef<CGImageRef> | 43 scoped_cftyperef<CGImageRef> |
44 src_image(CGBitmapContextCreateImage(src_context)); | 44 src_image(CGBitmapContextCreateImage(src_context)); |
45 scoped_cftyperef<CGImageRef> src_sub_image( | 45 scoped_cftyperef<CGImageRef> src_sub_image( |
46 CGImageCreateWithImageInRect(src_image, src_rect.ToCGRect())); | 46 CGImageCreateWithImageInRect(src_image, src_rect.ToCGRect())); |
47 CGContextDrawImage(dst_context, dst_rect.ToCGRect(), src_sub_image); | 47 CGContextDrawImage(dst_context, dst_rect.ToCGRect(), src_sub_image); |
48 #elif defined(OS_LINUX) | 48 #elif defined(USE_X11) |
49 // Only translations in the source context are supported; more complex | 49 // Only translations in the source context are supported; more complex |
50 // source context transforms will be ignored. | 50 // source context transforms will be ignored. |
51 cairo_save(dst_context); | 51 cairo_save(dst_context); |
52 double surface_x = src_origin.x(); | 52 double surface_x = src_origin.x(); |
53 double surface_y = src_origin.y(); | 53 double surface_y = src_origin.y(); |
54 cairo_user_to_device(src_context, &surface_x, &surface_y); | 54 cairo_user_to_device(src_context, &surface_x, &surface_y); |
55 cairo_set_source_surface(dst_context, cairo_get_target(src_context), | 55 cairo_set_source_surface(dst_context, cairo_get_target(src_context), |
56 dst_rect.x()-surface_x, dst_rect.y()-surface_y); | 56 dst_rect.x()-surface_x, dst_rect.y()-surface_y); |
57 cairo_rectangle(dst_context, dst_rect.x(), dst_rect.y(), | 57 cairo_rectangle(dst_context, dst_rect.x(), dst_rect.y(), |
58 dst_rect.width(), dst_rect.height()); | 58 dst_rect.width(), dst_rect.height()); |
59 cairo_clip(dst_context); | 59 cairo_clip(dst_context); |
60 cairo_paint(dst_context); | 60 cairo_paint(dst_context); |
61 cairo_restore(dst_context); | 61 cairo_restore(dst_context); |
62 #endif | 62 #endif |
63 } | 63 } |
64 | 64 |
65 static NativeDrawingContext GetContextFromCanvas( | 65 static NativeDrawingContext GetContextFromCanvas( |
66 skia::PlatformCanvas *canvas) { | 66 skia::PlatformCanvas *canvas) { |
67 skia::PlatformDevice& device = canvas->getTopPlatformDevice(); | 67 skia::PlatformDevice& device = canvas->getTopPlatformDevice(); |
68 #if defined(OS_WIN) | 68 #if defined(OS_WIN) |
69 return device.getBitmapDC(); | 69 return device.getBitmapDC(); |
70 #elif defined(OS_MACOSX) | 70 #elif defined(OS_MACOSX) |
71 return device.GetBitmapContext(); | 71 return device.GetBitmapContext(); |
72 #elif defined(OS_LINUX) | 72 #elif defined(USE_X11) |
73 return device.beginPlatformPaint(); | 73 return device.beginPlatformPaint(); |
74 #endif | 74 #endif |
75 } | 75 } |
76 | 76 |
77 void BlitContextToCanvas(skia::PlatformCanvas *dst_canvas, | 77 void BlitContextToCanvas(skia::PlatformCanvas *dst_canvas, |
78 const Rect& dst_rect, | 78 const Rect& dst_rect, |
79 NativeDrawingContext src_context, | 79 NativeDrawingContext src_context, |
80 const Point& src_origin) { | 80 const Point& src_origin) { |
81 BlitContextToContext(GetContextFromCanvas(dst_canvas), dst_rect, | 81 BlitContextToContext(GetContextFromCanvas(dst_canvas), dst_rect, |
82 src_context, src_origin); | 82 src_context, src_origin); |
83 } | 83 } |
84 | 84 |
85 void BlitCanvasToContext(NativeDrawingContext dst_context, | 85 void BlitCanvasToContext(NativeDrawingContext dst_context, |
86 const Rect& dst_rect, | 86 const Rect& dst_rect, |
87 skia::PlatformCanvas *src_canvas, | 87 skia::PlatformCanvas *src_canvas, |
88 const Point& src_origin) { | 88 const Point& src_origin) { |
89 BlitContextToContext(dst_context, dst_rect, | 89 BlitContextToContext(dst_context, dst_rect, |
90 GetContextFromCanvas(src_canvas), src_origin); | 90 GetContextFromCanvas(src_canvas), src_origin); |
91 } | 91 } |
92 | 92 |
93 void BlitCanvasToCanvas(skia::PlatformCanvas *dst_canvas, | 93 void BlitCanvasToCanvas(skia::PlatformCanvas *dst_canvas, |
94 const Rect& dst_rect, | 94 const Rect& dst_rect, |
95 skia::PlatformCanvas *src_canvas, | 95 skia::PlatformCanvas *src_canvas, |
96 const Point& src_origin) { | 96 const Point& src_origin) { |
97 BlitContextToContext(GetContextFromCanvas(dst_canvas), dst_rect, | 97 BlitContextToContext(GetContextFromCanvas(dst_canvas), dst_rect, |
98 GetContextFromCanvas(src_canvas), src_origin); | 98 GetContextFromCanvas(src_canvas), src_origin); |
99 } | 99 } |
100 | 100 |
101 } // namespace gfx | 101 } // namespace gfx |
OLD | NEW |