OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 SkCanvas *src_canvas, | 119 SkCanvas *src_canvas, |
120 const Point& src_origin) { | 120 const Point& src_origin) { |
121 DCHECK(skia::SupportsPlatformPaint(dst_canvas)); | 121 DCHECK(skia::SupportsPlatformPaint(dst_canvas)); |
122 DCHECK(skia::SupportsPlatformPaint(src_canvas)); | 122 DCHECK(skia::SupportsPlatformPaint(src_canvas)); |
123 BlitContextToContext(skia::BeginPlatformPaint(dst_canvas), dst_rect, | 123 BlitContextToContext(skia::BeginPlatformPaint(dst_canvas), dst_rect, |
124 skia::BeginPlatformPaint(src_canvas), src_origin); | 124 skia::BeginPlatformPaint(src_canvas), src_origin); |
125 skia::EndPlatformPaint(src_canvas); | 125 skia::EndPlatformPaint(src_canvas); |
126 skia::EndPlatformPaint(dst_canvas); | 126 skia::EndPlatformPaint(dst_canvas); |
127 } | 127 } |
128 | 128 |
129 #if defined(OS_WIN) && !defined(USE_AURA) | |
130 | |
131 void ScrollCanvas(SkCanvas* canvas, | |
132 const gfx::Rect& clip, | |
133 const gfx::Point& amount) { | |
134 DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff. | |
135 DCHECK(skia::SupportsPlatformPaint(canvas)); | |
136 skia::ScopedPlatformPaint scoped_platform_paint(canvas); | |
137 HDC hdc = scoped_platform_paint.GetPlatformSurface(); | |
138 | |
139 RECT damaged_rect; | |
140 RECT r = clip.ToRECT(); | |
141 ScrollDC(hdc, amount.x(), amount.y(), NULL, &r, NULL, &damaged_rect); | |
142 } | |
143 | |
144 #elif defined(OS_POSIX) || defined(USE_AURA) | |
145 // Cairo has no nice scroll function so we do our own. On Mac it's possible to | |
146 // use platform scroll code, but it's complex so we just use the same path | |
147 // here. Either way it will be software-only, so it shouldn't matter much. | |
148 | |
149 void ScrollCanvas(SkCanvas* canvas, | 129 void ScrollCanvas(SkCanvas* canvas, |
150 const gfx::Rect& in_clip, | 130 const gfx::Rect& in_clip, |
151 const gfx::Point& amount) { | 131 const gfx::Point& amount) { |
152 DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff. | 132 DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff. |
| 133 #if defined(OS_WIN) |
| 134 // If we have a PlatformCanvas, we should use ScrollDC. Otherwise, fall |
| 135 // through to the software implementation. |
| 136 if (skia::SupportsPlatformPaint(canvas)) { |
| 137 skia::ScopedPlatformPaint scoped_platform_paint(canvas); |
| 138 HDC hdc = scoped_platform_paint.GetPlatformSurface(); |
| 139 |
| 140 RECT damaged_rect; |
| 141 RECT r = in_clip.ToRECT(); |
| 142 ScrollDC(hdc, amount.x(), amount.y(), NULL, &r, NULL, &damaged_rect); |
| 143 return; |
| 144 } |
| 145 #endif // defined(OS_WIN) |
| 146 // For non-windows, always do scrolling in software. |
| 147 // Cairo has no nice scroll function so we do our own. On Mac it's possible to |
| 148 // use platform scroll code, but it's complex so we just use the same path |
| 149 // here. Either way it will be software-only, so it shouldn't matter much. |
153 SkBitmap& bitmap = const_cast<SkBitmap&>( | 150 SkBitmap& bitmap = const_cast<SkBitmap&>( |
154 skia::GetTopDevice(*canvas)->accessBitmap(true)); | 151 skia::GetTopDevice(*canvas)->accessBitmap(true)); |
155 SkAutoLockPixels lock(bitmap); | 152 SkAutoLockPixels lock(bitmap); |
156 | 153 |
157 // We expect all coords to be inside the canvas, so clip here. | 154 // We expect all coords to be inside the canvas, so clip here. |
158 gfx::Rect clip = in_clip.Intersect( | 155 gfx::Rect clip = in_clip.Intersect( |
159 gfx::Rect(0, 0, bitmap.width(), bitmap.height())); | 156 gfx::Rect(0, 0, bitmap.width(), bitmap.height())); |
160 | 157 |
161 // Compute the set of pixels we'll actually end up painting. | 158 // Compute the set of pixels we'll actually end up painting. |
162 gfx::Rect dest_rect = clip; | 159 gfx::Rect dest_rect = clip; |
(...skipping 26 matching lines...) Expand all Loading... |
189 // to-top, but have to be careful about the order for copying each row. | 186 // to-top, but have to be careful about the order for copying each row. |
190 // Fortunately, memmove already handles this for us. | 187 // Fortunately, memmove already handles this for us. |
191 for (int y = 0; y < dest_rect.height(); y++) { | 188 for (int y = 0; y < dest_rect.height(); y++) { |
192 memmove(bitmap.getAddr32(dest_rect.x(), dest_rect.y() + y), | 189 memmove(bitmap.getAddr32(dest_rect.x(), dest_rect.y() + y), |
193 bitmap.getAddr32(src_rect.x(), src_rect.y() + y), | 190 bitmap.getAddr32(src_rect.x(), src_rect.y() + y), |
194 row_bytes); | 191 row_bytes); |
195 } | 192 } |
196 } | 193 } |
197 } | 194 } |
198 | 195 |
199 #endif | |
200 | |
201 } // namespace gfx | 196 } // namespace gfx |
OLD | NEW |