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 "third_party/skia/include/core/SkBitmap.h" | 7 #include "third_party/skia/include/core/SkBitmap.h" |
8 #include "third_party/skia/include/core/SkColorFilter.h" | 8 #include "third_party/skia/include/core/SkColorFilter.h" |
9 #include "third_party/skia/include/core/SkColorPriv.h" | 9 #include "third_party/skia/include/core/SkColorPriv.h" |
10 #include "third_party/skia/include/core/SkUnPreMultiply.h" | 10 #include "third_party/skia/include/core/SkUnPreMultiply.h" |
11 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 11 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
12 #include "third_party/skia/include/effects/SkGradientShader.h" | 12 #include "third_party/skia/include/effects/SkGradientShader.h" |
13 #include "third_party/skia/include/effects/SkLayerDrawLooper.h" | 13 #include "third_party/skia/include/effects/SkLayerDrawLooper.h" |
14 #include "ui/gfx/image/image_skia_rep.h" | 14 #include "ui/gfx/image/image_skia_rep.h" |
15 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
16 #include "ui/gfx/rect_f.h" | 16 #include "ui/gfx/rect_f.h" |
17 #include "ui/gfx/shadow_value.h" | 17 #include "ui/gfx/shadow_value.h" |
| 18 #include "ui/gfx/transform.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) { |
(...skipping 11 matching lines...) Expand all Loading... |
39 SkFloatToScalar(rect.height())); | 40 SkFloatToScalar(rect.height())); |
40 } | 41 } |
41 | 42 |
42 RectF SkRectToRectF(const SkRect& rect) { | 43 RectF SkRectToRectF(const SkRect& rect) { |
43 return RectF(SkScalarToFloat(rect.x()), | 44 return RectF(SkScalarToFloat(rect.x()), |
44 SkScalarToFloat(rect.y()), | 45 SkScalarToFloat(rect.y()), |
45 SkScalarToFloat(rect.width()), | 46 SkScalarToFloat(rect.width()), |
46 SkScalarToFloat(rect.height())); | 47 SkScalarToFloat(rect.height())); |
47 } | 48 } |
48 | 49 |
| 50 void TransformToFlattenedSkMatrix(const gfx::Transform& transform, |
| 51 SkMatrix* flattened) { |
| 52 // Convert from 4x4 to 3x3 by dropping the third row and column. |
| 53 flattened->set(0, SkDoubleToScalar(transform.matrix().getDouble(0, 0))); |
| 54 flattened->set(1, SkDoubleToScalar(transform.matrix().getDouble(0, 1))); |
| 55 flattened->set(2, SkDoubleToScalar(transform.matrix().getDouble(0, 3))); |
| 56 flattened->set(3, SkDoubleToScalar(transform.matrix().getDouble(1, 0))); |
| 57 flattened->set(4, SkDoubleToScalar(transform.matrix().getDouble(1, 1))); |
| 58 flattened->set(5, SkDoubleToScalar(transform.matrix().getDouble(1, 3))); |
| 59 flattened->set(6, SkDoubleToScalar(transform.matrix().getDouble(3, 0))); |
| 60 flattened->set(7, SkDoubleToScalar(transform.matrix().getDouble(3, 1))); |
| 61 flattened->set(8, SkDoubleToScalar(transform.matrix().getDouble(3, 3))); |
| 62 } |
49 | 63 |
50 skia::RefPtr<SkShader> CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, | 64 skia::RefPtr<SkShader> CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, |
51 SkShader::TileMode tile_mode, | 65 SkShader::TileMode tile_mode, |
52 const SkMatrix& local_matrix) { | 66 const SkMatrix& local_matrix) { |
53 skia::RefPtr<SkShader> shader = skia::AdoptRef(SkShader::CreateBitmapShader( | 67 skia::RefPtr<SkShader> shader = skia::AdoptRef(SkShader::CreateBitmapShader( |
54 image_rep.sk_bitmap(), tile_mode, tile_mode)); | 68 image_rep.sk_bitmap(), tile_mode, tile_mode)); |
55 SkScalar scale_x = local_matrix.getScaleX(); | 69 SkScalar scale_x = local_matrix.getScaleX(); |
56 SkScalar scale_y = local_matrix.getScaleY(); | 70 SkScalar scale_y = local_matrix.getScaleY(); |
57 SkScalar bitmap_scale = SkFloatToScalar(image_rep.GetScale()); | 71 SkScalar bitmap_scale = SkFloatToScalar(image_rep.GetScale()); |
58 | 72 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } else { | 175 } else { |
162 rgba[i + 0] = SkGetPackedR32(pixel_in); | 176 rgba[i + 0] = SkGetPackedR32(pixel_in); |
163 rgba[i + 1] = SkGetPackedG32(pixel_in); | 177 rgba[i + 1] = SkGetPackedG32(pixel_in); |
164 rgba[i + 2] = SkGetPackedB32(pixel_in); | 178 rgba[i + 2] = SkGetPackedB32(pixel_in); |
165 rgba[i + 3] = alpha; | 179 rgba[i + 3] = alpha; |
166 } | 180 } |
167 } | 181 } |
168 } | 182 } |
169 | 183 |
170 } // namespace gfx | 184 } // namespace gfx |
OLD | NEW |