OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "gfx/canvas_skia.h" | 5 #include "gfx/canvas.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "gfx/canvas.h" |
11 #include "gfx/font.h" | 12 #include "gfx/font.h" |
12 #include "gfx/rect.h" | 13 #include "gfx/rect.h" |
13 #include "third_party/skia/include/core/SkShader.h" | 14 #include "third_party/skia/include/core/SkShader.h" |
14 | 15 |
15 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
16 #include "gfx/canvas_skia_paint.h" | 17 #include "gfx/canvas_skia_paint.h" |
17 #endif | 18 #endif |
18 | 19 |
19 namespace gfx { | 20 namespace gfx { |
20 | 21 |
21 SkBitmap CanvasSkia::ExtractBitmap() const { | |
22 const SkBitmap& device_bitmap = getDevice()->accessBitmap(false); | |
23 | |
24 // Make a bitmap to return, and a canvas to draw into it. We don't just want | |
25 // to call extractSubset or the copy constructor, since we want an actual copy | |
26 // of the bitmap. | |
27 SkBitmap result; | |
28 device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); | |
29 return result; | |
30 } | |
31 | |
32 bool CanvasSkia::GetClipRect(gfx::Rect* r) { | 22 bool CanvasSkia::GetClipRect(gfx::Rect* r) { |
33 SkRect clip; | 23 SkRect clip; |
34 if (!getClipBounds(&clip)) { | 24 if (!getClipBounds(&clip)) { |
35 if (r) | 25 if (r) |
36 r->SetRect(0, 0, 0, 0); | 26 r->SetRect(0, 0, 0, 0); |
37 return false; | 27 return false; |
38 } | 28 } |
39 r->SetRect(SkScalarRound(clip.fLeft), SkScalarRound(clip.fTop), | 29 r->SetRect(SkScalarRound(clip.fLeft), SkScalarRound(clip.fTop), |
40 SkScalarRound(clip.fRight - clip.fLeft), | 30 SkScalarRound(clip.fRight - clip.fLeft), |
41 SkScalarRound(clip.fBottom - clip.fTop)); | 31 SkScalarRound(clip.fBottom - clip.fTop)); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 // CreateBitmapShader returns a Shader with a reference count of one, we | 256 // CreateBitmapShader returns a Shader with a reference count of one, we |
267 // need to unref after paint takes ownership of the shader. | 257 // need to unref after paint takes ownership of the shader. |
268 shader->unref(); | 258 shader->unref(); |
269 save(); | 259 save(); |
270 translate(SkIntToScalar(dest_x - src_x), SkIntToScalar(dest_y - src_y)); | 260 translate(SkIntToScalar(dest_x - src_x), SkIntToScalar(dest_y - src_y)); |
271 ClipRectInt(src_x, src_y, w, h); | 261 ClipRectInt(src_x, src_y, w, h); |
272 drawPaint(paint); | 262 drawPaint(paint); |
273 restore(); | 263 restore(); |
274 } | 264 } |
275 | 265 |
276 CanvasSkia* CanvasSkia::AsCanvasSkia() { | 266 SkBitmap CanvasSkia::ExtractBitmap() const { |
277 return this; | 267 const SkBitmap& device_bitmap = getDevice()->accessBitmap(false); |
278 } | |
279 | 268 |
280 const CanvasSkia* CanvasSkia::AsCanvasSkia() const { | 269 // Make a bitmap to return, and a canvas to draw into it. We don't just want |
281 return this; | 270 // to call extractSubset or the copy constuctor, since we want an actual copy |
| 271 // of the bitmap. |
| 272 SkBitmap result; |
| 273 device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); |
| 274 return result; |
282 } | 275 } |
283 | 276 |
284 // static | 277 // static |
285 int CanvasSkia::DefaultCanvasTextAlignment() { | 278 int CanvasSkia::DefaultCanvasTextAlignment() { |
286 if (!base::i18n::IsRTL()) | 279 if (!base::i18n::IsRTL()) |
287 return gfx::Canvas::TEXT_ALIGN_LEFT; | 280 return gfx::Canvas::TEXT_ALIGN_LEFT; |
288 return gfx::Canvas::TEXT_ALIGN_RIGHT; | 281 return gfx::Canvas::TEXT_ALIGN_RIGHT; |
289 } | 282 } |
290 | 283 |
291 //////////////////////////////////////////////////////////////////////////////// | 284 //////////////////////////////////////////////////////////////////////////////// |
292 // Canvas, public: | 285 // Canvas2, public: |
293 | 286 |
294 Canvas* Canvas::CreateCanvas() { | 287 Canvas2* Canvas2::CreateCanvas() { |
295 return new CanvasSkia; | 288 return new Canvas; |
296 } | 289 } |
297 | 290 |
298 Canvas* Canvas::CreateCanvas(int width, int height, bool is_opaque) { | 291 Canvas2* Canvas2::CreateCanvas(int width, int height, bool is_opaque) { |
299 return new CanvasSkia(width, height, is_opaque); | 292 return new Canvas(width, height, is_opaque); |
300 } | 293 } |
301 | 294 |
302 #if defined(OS_WIN) | 295 #if defined(OS_WIN) |
303 // TODO(beng): move to canvas_win.cc, etc. | 296 // TODO(beng): move to canvas_win.cc, etc. |
304 class CanvasPaintWin : public CanvasSkiaPaint, public CanvasPaint { | 297 class CanvasPaintWin : public CanvasSkiaPaint, public CanvasPaint2 { |
305 public: | 298 public: |
306 CanvasPaintWin(gfx::NativeView view) : CanvasSkiaPaint(view) {} | 299 CanvasPaintWin(gfx::NativeView view) : CanvasSkiaPaint(view) {} |
307 | 300 |
308 // Overridden from CanvasPaint2: | 301 // Overridden from CanvasPaint2: |
309 virtual bool IsValid() const { | 302 virtual bool IsValid() const { |
310 return isEmpty(); | 303 return isEmpty(); |
311 } | 304 } |
312 | 305 |
313 virtual gfx::Rect GetInvalidRect() const { | 306 virtual gfx::Rect GetInvalidRect() const { |
314 return gfx::Rect(paintStruct().rcPaint); | 307 return gfx::Rect(paintStruct().rcPaint); |
315 } | 308 } |
316 | 309 |
317 virtual Canvas* AsCanvas() { | 310 virtual Canvas2* AsCanvas2() { |
318 return this; | 311 return this; |
319 } | 312 } |
320 }; | 313 }; |
321 #endif | 314 #endif |
322 | 315 |
323 CanvasPaint* CanvasPaint::CreateCanvasPaint(gfx::NativeView view) { | 316 CanvasPaint2* CanvasPaint2::CreateCanvasPaint(gfx::NativeView view) { |
324 #if defined(OS_WIN) | 317 #if defined(OS_WIN) |
325 return new CanvasPaintWin(view); | 318 return new CanvasPaintWin(view); |
326 #else | 319 #else |
327 return NULL; | 320 return NULL; |
328 #endif | 321 #endif |
329 } | 322 } |
330 | 323 |
331 } // namespace gfx | 324 } // namespace gfx |
OLD | NEW |