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/skia_util.h" | 5 #include "ui/gfx/skia_util.h" |
6 | 6 |
7 #include "base/i18n/char_iterator.h" | 7 #include "base/i18n/char_iterator.h" |
8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
9 #include "third_party/skia/include/core/SkColorFilter.h" | 9 #include "third_party/skia/include/core/SkColorFilter.h" |
10 #include "third_party/skia/include/core/SkColorPriv.h" | 10 #include "third_party/skia/include/core/SkColorPriv.h" |
11 #include "third_party/skia/include/core/SkUnPreMultiply.h" | 11 #include "third_party/skia/include/core/SkUnPreMultiply.h" |
12 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 12 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
13 #include "third_party/skia/include/effects/SkGradientShader.h" | 13 #include "third_party/skia/include/effects/SkGradientShader.h" |
14 #include "third_party/skia/include/effects/SkLayerDrawLooper.h" | 14 #include "third_party/skia/include/effects/SkLayerDrawLooper.h" |
15 #include "ui/gfx/image/image_skia_rep.h" | 15 #include "ui/gfx/image/image_skia_rep.h" |
16 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 17 #include "ui/gfx/rect_f.h" |
17 #include "ui/gfx/shadow_value.h" | 18 #include "ui/gfx/shadow_value.h" |
18 | 19 |
19 namespace gfx { | 20 namespace gfx { |
20 | 21 |
21 SkRect RectToSkRect(const Rect& rect) { | 22 SkRect RectToSkRect(const Rect& rect) { |
22 SkRect r; | 23 SkRect r; |
23 r.iset(rect.x(), rect.y(), rect.right(), rect.bottom()); | 24 r.iset(rect.x(), rect.y(), rect.right(), rect.bottom()); |
24 return r; | 25 return r; |
25 } | 26 } |
26 | 27 |
27 SkIRect RectToSkIRect(const Rect& rect) { | 28 SkIRect RectToSkIRect(const Rect& rect) { |
28 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); | 29 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); |
29 } | 30 } |
30 | 31 |
31 Rect SkRectToRect(const SkRect& rect) { | |
32 return Rect(static_cast<int>(rect.left()), | |
33 static_cast<int>(rect.top()), | |
34 static_cast<int>(rect.width()), | |
35 static_cast<int>(rect.height())); | |
36 } | |
37 | |
38 Rect SkIRectToRect(const SkIRect& rect) { | 32 Rect SkIRectToRect(const SkIRect& rect) { |
39 return Rect(rect.x(), rect.y(), rect.width(), rect.height()); | 33 return Rect(rect.x(), rect.y(), rect.width(), rect.height()); |
40 } | 34 } |
41 | 35 |
| 36 SkRect RectFToSkRect(const RectF& rect) { |
| 37 return SkRect::MakeXYWH(SkFloatToScalar(rect.x()), |
| 38 SkFloatToScalar(rect.y()), |
| 39 SkFloatToScalar(rect.width()), |
| 40 SkFloatToScalar(rect.height())); |
| 41 } |
| 42 |
| 43 RectF SkRectToRectF(const SkRect& rect) { |
| 44 return RectF(SkScalarToFloat(rect.x()), |
| 45 SkScalarToFloat(rect.y()), |
| 46 SkScalarToFloat(rect.width()), |
| 47 SkScalarToFloat(rect.height())); |
| 48 } |
| 49 |
| 50 |
42 SkShader* CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, | 51 SkShader* CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, |
43 SkShader::TileMode tile_mode, | 52 SkShader::TileMode tile_mode, |
44 const SkMatrix& local_matrix) { | 53 const SkMatrix& local_matrix) { |
45 SkShader* shader = SkShader::CreateBitmapShader(image_rep.sk_bitmap(), | 54 SkShader* shader = SkShader::CreateBitmapShader(image_rep.sk_bitmap(), |
46 tile_mode, tile_mode); | 55 tile_mode, tile_mode); |
47 SkScalar scale_x = local_matrix.getScaleX(); | 56 SkScalar scale_x = local_matrix.getScaleX(); |
48 SkScalar scale_y = local_matrix.getScaleY(); | 57 SkScalar scale_y = local_matrix.getScaleY(); |
49 SkScalar bitmap_scale = SkFloatToScalar(image_rep.GetScale()); | 58 SkScalar bitmap_scale = SkFloatToScalar(image_rep.GetScale()); |
50 | 59 |
51 // Unscale matrix by |bitmap_scale| such that the bitmap is drawn at the | 60 // Unscale matrix by |bitmap_scale| such that the bitmap is drawn at the |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 } else { | 198 } else { |
190 rgba[i + 0] = SkGetPackedR32(pixel_in); | 199 rgba[i + 0] = SkGetPackedR32(pixel_in); |
191 rgba[i + 1] = SkGetPackedG32(pixel_in); | 200 rgba[i + 1] = SkGetPackedG32(pixel_in); |
192 rgba[i + 2] = SkGetPackedB32(pixel_in); | 201 rgba[i + 2] = SkGetPackedB32(pixel_in); |
193 rgba[i + 3] = alpha; | 202 rgba[i + 3] = alpha; |
194 } | 203 } |
195 } | 204 } |
196 } | 205 } |
197 | 206 |
198 } // namespace gfx | 207 } // namespace gfx |
OLD | NEW |