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_skia.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/font.h" | 11 #include "gfx/font.h" |
12 #include "gfx/rect.h" | 12 #include "gfx/rect.h" |
13 #include "third_party/skia/include/core/SkShader.h" | 13 #include "third_party/skia/include/core/SkShader.h" |
14 | 14 |
15 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
16 #include "gfx/canvas_skia_paint.h" | 16 #include "gfx/canvas_skia_paint.h" |
17 #endif | 17 #endif |
18 | 18 |
19 namespace gfx { | 19 namespace gfx { |
20 | 20 |
| 21 //////////////////////////////////////////////////////////////////////////////// |
| 22 // CanvasSkia, public: |
| 23 |
| 24 // static |
| 25 int CanvasSkia::DefaultCanvasTextAlignment() { |
| 26 if (!base::i18n::IsRTL()) |
| 27 return gfx::Canvas::TEXT_ALIGN_LEFT; |
| 28 return gfx::Canvas::TEXT_ALIGN_RIGHT; |
| 29 } |
| 30 |
21 SkBitmap CanvasSkia::ExtractBitmap() const { | 31 SkBitmap CanvasSkia::ExtractBitmap() const { |
22 const SkBitmap& device_bitmap = getDevice()->accessBitmap(false); | 32 const SkBitmap& device_bitmap = getDevice()->accessBitmap(false); |
23 | 33 |
24 // Make a bitmap to return, and a canvas to draw into it. We don't just want | 34 // 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 | 35 // to call extractSubset or the copy constructor, since we want an actual copy |
26 // of the bitmap. | 36 // of the bitmap. |
27 SkBitmap result; | 37 SkBitmap result; |
28 device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); | 38 device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); |
29 return result; | 39 return result; |
30 } | 40 } |
(...skipping 16 matching lines...) Expand all Loading... |
47 SkIntToScalar(layer_bounds.y()), | 57 SkIntToScalar(layer_bounds.y()), |
48 SkIntToScalar(layer_bounds.right()), | 58 SkIntToScalar(layer_bounds.right()), |
49 SkIntToScalar(layer_bounds.bottom())); | 59 SkIntToScalar(layer_bounds.bottom())); |
50 saveLayerAlpha(&bounds, alpha); | 60 saveLayerAlpha(&bounds, alpha); |
51 } | 61 } |
52 | 62 |
53 void CanvasSkia::Restore() { | 63 void CanvasSkia::Restore() { |
54 restore(); | 64 restore(); |
55 } | 65 } |
56 | 66 |
57 bool CanvasSkia::GetClipRect(gfx::Rect* r) { | |
58 SkRect clip; | |
59 if (!getClipBounds(&clip)) { | |
60 if (r) | |
61 r->SetRect(0, 0, 0, 0); | |
62 return false; | |
63 } | |
64 r->SetRect(SkScalarRound(clip.fLeft), SkScalarRound(clip.fTop), | |
65 SkScalarRound(clip.fRight - clip.fLeft), | |
66 SkScalarRound(clip.fBottom - clip.fTop)); | |
67 return true; | |
68 } | |
69 | |
70 bool CanvasSkia::ClipRectInt(int x, int y, int w, int h) { | 67 bool CanvasSkia::ClipRectInt(int x, int y, int w, int h) { |
71 SkRect new_clip; | 68 SkRect new_clip; |
72 new_clip.set(SkIntToScalar(x), SkIntToScalar(y), | 69 new_clip.set(SkIntToScalar(x), SkIntToScalar(y), |
73 SkIntToScalar(x + w), SkIntToScalar(y + h)); | 70 SkIntToScalar(x + w), SkIntToScalar(y + h)); |
74 return clipRect(new_clip); | 71 return clipRect(new_clip); |
75 } | 72 } |
76 | 73 |
77 bool CanvasSkia::IntersectsClipRectInt(int x, int y, int w, int h) { | |
78 SkRect clip; | |
79 return getClipBounds(&clip) && | |
80 clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), | |
81 SkIntToScalar(y + h)); | |
82 } | |
83 | |
84 void CanvasSkia::TranslateInt(int x, int y) { | 74 void CanvasSkia::TranslateInt(int x, int y) { |
85 translate(SkIntToScalar(x), SkIntToScalar(y)); | 75 translate(SkIntToScalar(x), SkIntToScalar(y)); |
86 } | 76 } |
87 | 77 |
88 void CanvasSkia::ScaleInt(int x, int y) { | 78 void CanvasSkia::ScaleInt(int x, int y) { |
89 scale(SkIntToScalar(x), SkIntToScalar(y)); | 79 scale(SkIntToScalar(x), SkIntToScalar(y)); |
90 } | 80 } |
91 | 81 |
92 void CanvasSkia::FillRectInt(const SkColor& color, int x, int y, int w, int h) { | 82 void CanvasSkia::FillRectInt(const SkColor& color, int x, int y, int w, int h) { |
93 SkPaint paint; | 83 SkPaint paint; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 297 } |
308 | 298 |
309 CanvasSkia* CanvasSkia::AsCanvasSkia() { | 299 CanvasSkia* CanvasSkia::AsCanvasSkia() { |
310 return this; | 300 return this; |
311 } | 301 } |
312 | 302 |
313 const CanvasSkia* CanvasSkia::AsCanvasSkia() const { | 303 const CanvasSkia* CanvasSkia::AsCanvasSkia() const { |
314 return this; | 304 return this; |
315 } | 305 } |
316 | 306 |
317 // static | 307 //////////////////////////////////////////////////////////////////////////////// |
318 int CanvasSkia::DefaultCanvasTextAlignment() { | 308 // CanvasSkia, private: |
319 if (!base::i18n::IsRTL()) | 309 |
320 return gfx::Canvas::TEXT_ALIGN_LEFT; | 310 bool CanvasSkia::IntersectsClipRectInt(int x, int y, int w, int h) { |
321 return gfx::Canvas::TEXT_ALIGN_RIGHT; | 311 SkRect clip; |
| 312 return getClipBounds(&clip) && |
| 313 clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), |
| 314 SkIntToScalar(y + h)); |
322 } | 315 } |
323 | 316 |
324 //////////////////////////////////////////////////////////////////////////////// | 317 //////////////////////////////////////////////////////////////////////////////// |
325 // Canvas, public: | 318 // Canvas, public: |
326 | 319 |
327 Canvas* Canvas::CreateCanvas() { | 320 Canvas* Canvas::CreateCanvas() { |
328 return new CanvasSkia; | 321 return new CanvasSkia; |
329 } | 322 } |
330 | 323 |
331 Canvas* Canvas::CreateCanvas(int width, int height, bool is_opaque) { | 324 Canvas* Canvas::CreateCanvas(int width, int height, bool is_opaque) { |
(...skipping 23 matching lines...) Expand all Loading... |
355 | 348 |
356 CanvasPaint* CanvasPaint::CreateCanvasPaint(gfx::NativeView view) { | 349 CanvasPaint* CanvasPaint::CreateCanvasPaint(gfx::NativeView view) { |
357 #if defined(OS_WIN) | 350 #if defined(OS_WIN) |
358 return new CanvasPaintWin(view); | 351 return new CanvasPaintWin(view); |
359 #else | 352 #else |
360 return NULL; | 353 return NULL; |
361 #endif | 354 #endif |
362 } | 355 } |
363 | 356 |
364 } // namespace gfx | 357 } // namespace gfx |
OLD | NEW |