OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/gfx/blit.h" | 5 #include "ui/gfx/blit.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "skia/ext/platform_canvas.h" | 9 #include "skia/ext/platform_canvas.h" |
10 #include "ui/gfx/point.h" | 10 #include "ui/gfx/point.h" |
11 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
12 #include "ui/gfx/vector2d.h" | 12 #include "ui/gfx/vector2d.h" |
13 | 13 |
| 14 #if defined(USE_CAIRO) |
14 #if defined(OS_OPENBSD) | 15 #if defined(OS_OPENBSD) |
15 #include <cairo.h> | 16 #include <cairo.h> |
16 #elif defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 17 #elif defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
17 #include <cairo/cairo.h> | 18 #include <cairo/cairo.h> |
18 #endif | 19 #endif |
| 20 #endif |
19 | 21 |
20 #if defined(OS_MACOSX) | 22 #if defined(OS_MACOSX) |
21 #include "base/mac/scoped_cftyperef.h" | 23 #include "base/mac/scoped_cftyperef.h" |
22 #endif | 24 #endif |
23 | 25 |
24 namespace gfx { | 26 namespace gfx { |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 // Returns true if the given canvas has any part of itself clipped out or | 30 // Returns true if the given canvas has any part of itself clipped out or |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 CGFloat delta_y = flipped ? CGBitmapContextGetHeight(src_context) - | 71 CGFloat delta_y = flipped ? CGBitmapContextGetHeight(src_context) - |
70 transform.ty | 72 transform.ty |
71 : transform.ty; | 73 : transform.ty; |
72 src_rect.Offset(transform.tx, delta_y); | 74 src_rect.Offset(transform.tx, delta_y); |
73 | 75 |
74 base::ScopedCFTypeRef<CGImageRef> src_image( | 76 base::ScopedCFTypeRef<CGImageRef> src_image( |
75 CGBitmapContextCreateImage(src_context)); | 77 CGBitmapContextCreateImage(src_context)); |
76 base::ScopedCFTypeRef<CGImageRef> src_sub_image( | 78 base::ScopedCFTypeRef<CGImageRef> src_sub_image( |
77 CGImageCreateWithImageInRect(src_image, src_rect.ToCGRect())); | 79 CGImageCreateWithImageInRect(src_image, src_rect.ToCGRect())); |
78 CGContextDrawImage(dst_context, dst_rect.ToCGRect(), src_sub_image); | 80 CGContextDrawImage(dst_context, dst_rect.ToCGRect(), src_sub_image); |
79 #elif defined(OS_ANDROID) | 81 #elif defined(USE_CAIRO) |
80 NOTIMPLEMENTED(); | |
81 #else // Linux, BSD, others | |
82 // Only translations in the source context are supported; more complex | 82 // Only translations in the source context are supported; more complex |
83 // source context transforms will be ignored. | 83 // source context transforms will be ignored. |
84 cairo_save(dst_context); | 84 cairo_save(dst_context); |
85 double surface_x = src_origin.x(); | 85 double surface_x = src_origin.x(); |
86 double surface_y = src_origin.y(); | 86 double surface_y = src_origin.y(); |
87 cairo_user_to_device(src_context, &surface_x, &surface_y); | 87 cairo_user_to_device(src_context, &surface_x, &surface_y); |
88 cairo_set_source_surface(dst_context, cairo_get_target(src_context), | 88 cairo_set_source_surface(dst_context, cairo_get_target(src_context), |
89 dst_rect.x()-surface_x, dst_rect.y()-surface_y); | 89 dst_rect.x()-surface_x, dst_rect.y()-surface_y); |
90 cairo_rectangle(dst_context, dst_rect.x(), dst_rect.y(), | 90 cairo_rectangle(dst_context, dst_rect.x(), dst_rect.y(), |
91 dst_rect.width(), dst_rect.height()); | 91 dst_rect.width(), dst_rect.height()); |
92 cairo_clip(dst_context); | 92 cairo_clip(dst_context); |
93 cairo_paint(dst_context); | 93 cairo_paint(dst_context); |
94 cairo_restore(dst_context); | 94 cairo_restore(dst_context); |
| 95 #else |
| 96 NOTIMPLEMENTED(); |
95 #endif | 97 #endif |
96 } | 98 } |
97 | 99 |
98 void BlitContextToCanvas(SkCanvas *dst_canvas, | 100 void BlitContextToCanvas(SkCanvas *dst_canvas, |
99 const Rect& dst_rect, | 101 const Rect& dst_rect, |
100 NativeDrawingContext src_context, | 102 NativeDrawingContext src_context, |
101 const Point& src_origin) { | 103 const Point& src_origin) { |
102 DCHECK(skia::SupportsPlatformPaint(dst_canvas)); | 104 DCHECK(skia::SupportsPlatformPaint(dst_canvas)); |
103 BlitContextToContext(skia::BeginPlatformPaint(dst_canvas), dst_rect, | 105 BlitContextToContext(skia::BeginPlatformPaint(dst_canvas), dst_rect, |
104 src_context, src_origin); | 106 src_context, src_origin); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // Fortunately, memmove already handles this for us. | 187 // Fortunately, memmove already handles this for us. |
186 for (int y = 0; y < dest_rect.height(); y++) { | 188 for (int y = 0; y < dest_rect.height(); y++) { |
187 memmove(bitmap.getAddr32(dest_rect.x(), dest_rect.y() + y), | 189 memmove(bitmap.getAddr32(dest_rect.x(), dest_rect.y() + y), |
188 bitmap.getAddr32(src_rect.x(), src_rect.y() + y), | 190 bitmap.getAddr32(src_rect.x(), src_rect.y() + y), |
189 row_bytes); | 191 row_bytes); |
190 } | 192 } |
191 } | 193 } |
192 } | 194 } |
193 | 195 |
194 } // namespace gfx | 196 } // namespace gfx |
OLD | NEW |