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/canvas_skia.h" | 5 #include "ui/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 "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
12 #include "third_party/skia/include/effects/SkGradientShader.h" | 12 #include "third_party/skia/include/effects/SkGradientShader.h" |
13 #include "ui/gfx/brush.h" | 13 #include "ui/gfx/brush.h" |
14 #include "ui/gfx/font.h" | 14 #include "ui/gfx/font.h" |
15 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
| 16 #include "ui/gfx/canvas.h" |
16 #include "ui/gfx/skia_util.h" | 17 #include "ui/gfx/skia_util.h" |
17 #include "ui/gfx/transform.h" | 18 #include "ui/gfx/transform.h" |
18 | 19 |
19 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
20 #include "ui/gfx/canvas_skia_paint.h" | 21 #include "ui/gfx/canvas_skia_paint.h" |
21 #endif | 22 #endif |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // A platform wrapper for a Skia shader that makes sure the underlying | 26 // A platform wrapper for a Skia shader that makes sure the underlying |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 79 |
79 // static | 80 // static |
80 int CanvasSkia::GetStringWidth(const string16& text, const gfx::Font& font) { | 81 int CanvasSkia::GetStringWidth(const string16& text, const gfx::Font& font) { |
81 int width = 0, height = 0; | 82 int width = 0, height = 0; |
82 CanvasSkia::SizeStringInt(text, font, &width, &height, Canvas::NO_ELLIPSIS); | 83 CanvasSkia::SizeStringInt(text, font, &width, &height, Canvas::NO_ELLIPSIS); |
83 return width; | 84 return width; |
84 } | 85 } |
85 | 86 |
86 // static | 87 // static |
87 int CanvasSkia::DefaultCanvasTextAlignment() { | 88 int CanvasSkia::DefaultCanvasTextAlignment() { |
88 if (!base::i18n::IsRTL()) | 89 return base::i18n::IsRTL() ? Canvas::TEXT_ALIGN_RIGHT |
89 return gfx::Canvas::TEXT_ALIGN_LEFT; | 90 : Canvas::TEXT_ALIGN_LEFT; |
90 return gfx::Canvas::TEXT_ALIGN_RIGHT; | |
91 } | 91 } |
92 | 92 |
93 SkBitmap CanvasSkia::ExtractBitmap() const { | 93 SkBitmap CanvasSkia::ExtractBitmap() const { |
94 const SkBitmap& device_bitmap = canvas_->getDevice()->accessBitmap(false); | 94 const SkBitmap& device_bitmap = canvas_->getDevice()->accessBitmap(false); |
95 | 95 |
96 // Make a bitmap to return, and a canvas to draw into it. We don't just want | 96 // Make a bitmap to return, and a canvas to draw into it. We don't just want |
97 // to call extractSubset or the copy constructor, since we want an actual copy | 97 // to call extractSubset or the copy constructor, since we want an actual copy |
98 // of the bitmap. | 98 // of the bitmap. |
99 SkBitmap result; | 99 SkBitmap result; |
100 device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); | 100 device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 // CanvasSkia, private: | 383 // CanvasSkia, private: |
384 | 384 |
385 bool CanvasSkia::IntersectsClipRectInt(int x, int y, int w, int h) { | 385 bool CanvasSkia::IntersectsClipRectInt(int x, int y, int w, int h) { |
386 SkRect clip; | 386 SkRect clip; |
387 return canvas_->getClipBounds(&clip) && | 387 return canvas_->getClipBounds(&clip) && |
388 clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), | 388 clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), |
389 SkIntToScalar(y + h)); | 389 SkIntToScalar(y + h)); |
390 } | 390 } |
391 | 391 |
392 } // namespace gfx | 392 } // namespace gfx |
OLD | NEW |