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 "skia/ext/platform_device.h" | 10 #include "skia/ext/platform_device.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 bool HasClipOrTransform(const skia::PlatformCanvas& canvas) { | 28 bool HasClipOrTransform(const skia::PlatformCanvas& canvas) { |
29 if (!canvas.getTotalMatrix().isIdentity()) | 29 if (!canvas.getTotalMatrix().isIdentity()) |
30 return true; | 30 return true; |
31 | 31 |
32 const SkRegion& clip_region = canvas.getTotalClip(); | 32 const SkRegion& clip_region = canvas.getTotalClip(); |
33 if (clip_region.isEmpty() || clip_region.isComplex()) | 33 if (clip_region.isEmpty() || clip_region.isComplex()) |
34 return true; | 34 return true; |
35 | 35 |
36 // Now we know the clip is a regular rectangle, make sure it covers the | 36 // Now we know the clip is a regular rectangle, make sure it covers the |
37 // entire canvas. | 37 // entire canvas. |
38 const SkBitmap& bitmap = canvas.getTopPlatformDevice().accessBitmap(false); | 38 const SkBitmap& bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); |
39 const SkIRect& clip_bounds = clip_region.getBounds(); | 39 const SkIRect& clip_bounds = clip_region.getBounds(); |
40 if (clip_bounds.fLeft != 0 || clip_bounds.fTop != 0 || | 40 if (clip_bounds.fLeft != 0 || clip_bounds.fTop != 0 || |
41 clip_bounds.fRight != bitmap.width() || | 41 clip_bounds.fRight != bitmap.width() || |
42 clip_bounds.fBottom != bitmap.height()) | 42 clip_bounds.fBottom != bitmap.height()) |
43 return true; | 43 return true; |
44 | 44 |
45 return false; | 45 return false; |
46 } | 46 } |
47 | 47 |
48 } // namespace | 48 } // namespace |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 cairo_clip(dst_context); | 88 cairo_clip(dst_context); |
89 cairo_paint(dst_context); | 89 cairo_paint(dst_context); |
90 cairo_restore(dst_context); | 90 cairo_restore(dst_context); |
91 #endif | 91 #endif |
92 } | 92 } |
93 | 93 |
94 void BlitContextToCanvas(skia::PlatformCanvas *dst_canvas, | 94 void BlitContextToCanvas(skia::PlatformCanvas *dst_canvas, |
95 const Rect& dst_rect, | 95 const Rect& dst_rect, |
96 NativeDrawingContext src_context, | 96 NativeDrawingContext src_context, |
97 const Point& src_origin) { | 97 const Point& src_origin) { |
98 BlitContextToContext(dst_canvas->beginPlatformPaint(), dst_rect, | 98 BlitContextToContext(skia::BeginPlatformPaint(dst_canvas), dst_rect, |
99 src_context, src_origin); | 99 src_context, src_origin); |
100 dst_canvas->endPlatformPaint(); | 100 skia::EndPlatformPaint(dst_canvas); |
101 } | 101 } |
102 | 102 |
103 void BlitCanvasToContext(NativeDrawingContext dst_context, | 103 void BlitCanvasToContext(NativeDrawingContext dst_context, |
104 const Rect& dst_rect, | 104 const Rect& dst_rect, |
105 skia::PlatformCanvas *src_canvas, | 105 skia::PlatformCanvas *src_canvas, |
106 const Point& src_origin) { | 106 const Point& src_origin) { |
107 BlitContextToContext(dst_context, dst_rect, | 107 BlitContextToContext(dst_context, dst_rect, |
108 src_canvas->beginPlatformPaint(), src_origin); | 108 skia::BeginPlatformPaint(src_canvas), src_origin); |
109 src_canvas->endPlatformPaint(); | 109 skia::EndPlatformPaint(src_canvas); |
110 } | 110 } |
111 | 111 |
112 void BlitCanvasToCanvas(skia::PlatformCanvas *dst_canvas, | 112 void BlitCanvasToCanvas(skia::PlatformCanvas *dst_canvas, |
113 const Rect& dst_rect, | 113 const Rect& dst_rect, |
114 skia::PlatformCanvas *src_canvas, | 114 skia::PlatformCanvas *src_canvas, |
115 const Point& src_origin) { | 115 const Point& src_origin) { |
116 BlitContextToContext(dst_canvas->beginPlatformPaint(), dst_rect, | 116 BlitContextToContext(skia::BeginPlatformPaint(dst_canvas), dst_rect, |
117 src_canvas->beginPlatformPaint(), src_origin); | 117 skia::BeginPlatformPaint(src_canvas), src_origin); |
118 src_canvas->endPlatformPaint(); | 118 skia::EndPlatformPaint(src_canvas); |
119 dst_canvas->endPlatformPaint(); | 119 skia::EndPlatformPaint(dst_canvas); |
120 } | 120 } |
121 | 121 |
122 #if defined(OS_WIN) | 122 #if defined(OS_WIN) |
123 | 123 |
124 void ScrollCanvas(skia::PlatformCanvas* canvas, | 124 void ScrollCanvas(skia::PlatformCanvas* canvas, |
125 const gfx::Rect& clip, | 125 const gfx::Rect& clip, |
126 const gfx::Point& amount) { | 126 const gfx::Point& amount) { |
127 DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff. | 127 DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff. |
128 HDC hdc = canvas->beginPlatformPaint(); | 128 skia::ScopedPlatformPaint scoped_platform_paint(canvas); |
| 129 HDC hdc = scoped_platform_paint.GetPlatformSurface(); |
129 | 130 |
130 RECT damaged_rect; | 131 RECT damaged_rect; |
131 RECT r = clip.ToRECT(); | 132 RECT r = clip.ToRECT(); |
132 ScrollDC(hdc, amount.x(), amount.y(), NULL, &r, NULL, &damaged_rect); | 133 ScrollDC(hdc, amount.x(), amount.y(), NULL, &r, NULL, &damaged_rect); |
133 | |
134 canvas->endPlatformPaint(); | |
135 } | 134 } |
136 | 135 |
137 #elif defined(OS_POSIX) | 136 #elif defined(OS_POSIX) |
138 // Cairo has no nice scroll function so we do our own. On Mac it's possible to | 137 // Cairo has no nice scroll function so we do our own. On Mac it's possible to |
139 // use platform scroll code, but it's complex so we just use the same path | 138 // use platform scroll code, but it's complex so we just use the same path |
140 // here. Either way it will be software-only, so it shouldn't matter much. | 139 // here. Either way it will be software-only, so it shouldn't matter much. |
141 | 140 |
142 void ScrollCanvas(skia::PlatformCanvas* canvas, | 141 void ScrollCanvas(skia::PlatformCanvas* canvas, |
143 const gfx::Rect& in_clip, | 142 const gfx::Rect& in_clip, |
144 const gfx::Point& amount) { | 143 const gfx::Point& amount) { |
145 DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff. | 144 DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff. |
146 SkBitmap& bitmap = const_cast<SkBitmap&>( | 145 SkBitmap& bitmap = const_cast<SkBitmap&>( |
147 canvas->getTopPlatformDevice().accessBitmap(true)); | 146 skia::GetTopDevice(*canvas)->accessBitmap(true)); |
148 SkAutoLockPixels lock(bitmap); | 147 SkAutoLockPixels lock(bitmap); |
149 | 148 |
150 // We expect all coords to be inside the canvas, so clip here. | 149 // We expect all coords to be inside the canvas, so clip here. |
151 gfx::Rect clip = in_clip.Intersect( | 150 gfx::Rect clip = in_clip.Intersect( |
152 gfx::Rect(0, 0, bitmap.width(), bitmap.height())); | 151 gfx::Rect(0, 0, bitmap.width(), bitmap.height())); |
153 | 152 |
154 // Compute the set of pixels we'll actually end up painting. | 153 // Compute the set of pixels we'll actually end up painting. |
155 gfx::Rect dest_rect = clip; | 154 gfx::Rect dest_rect = clip; |
156 dest_rect.Offset(amount); | 155 dest_rect.Offset(amount); |
157 dest_rect = dest_rect.Intersect(clip); | 156 dest_rect = dest_rect.Intersect(clip); |
(...skipping 27 matching lines...) Expand all Loading... |
185 memmove(bitmap.getAddr32(dest_rect.x(), dest_rect.y() + y), | 184 memmove(bitmap.getAddr32(dest_rect.x(), dest_rect.y() + y), |
186 bitmap.getAddr32(src_rect.x(), src_rect.y() + y), | 185 bitmap.getAddr32(src_rect.x(), src_rect.y() + y), |
187 row_bytes); | 186 row_bytes); |
188 } | 187 } |
189 } | 188 } |
190 } | 189 } |
191 | 190 |
192 #endif | 191 #endif |
193 | 192 |
194 } // namespace gfx | 193 } // namespace gfx |
OLD | NEW |