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/rect.h" | 14 #include "ui/gfx/geometry/quad_f.h" |
15 #include "ui/gfx/rect_f.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 16 #include "ui/gfx/geometry/rect_f.h" |
16 #include "ui/gfx/transform.h" | 17 #include "ui/gfx/transform.h" |
17 | 18 |
18 namespace gfx { | 19 namespace gfx { |
19 | 20 |
20 SkRect RectToSkRect(const Rect& rect) { | 21 SkRect RectToSkRect(const Rect& rect) { |
21 SkRect r; | 22 SkRect r; |
22 r.iset(rect.x(), rect.y(), rect.right(), rect.bottom()); | 23 r.iset(rect.x(), rect.y(), rect.right(), rect.bottom()); |
23 return r; | 24 return r; |
24 } | 25 } |
25 | 26 |
(...skipping 12 matching lines...) Expand all Loading... |
38 SkFloatToScalar(rect.height())); | 39 SkFloatToScalar(rect.height())); |
39 } | 40 } |
40 | 41 |
41 RectF SkRectToRectF(const SkRect& rect) { | 42 RectF SkRectToRectF(const SkRect& rect) { |
42 return RectF(SkScalarToFloat(rect.x()), | 43 return RectF(SkScalarToFloat(rect.x()), |
43 SkScalarToFloat(rect.y()), | 44 SkScalarToFloat(rect.y()), |
44 SkScalarToFloat(rect.width()), | 45 SkScalarToFloat(rect.width()), |
45 SkScalarToFloat(rect.height())); | 46 SkScalarToFloat(rect.height())); |
46 } | 47 } |
47 | 48 |
| 49 SkSize SizeFToSkSize(const SizeF& size) { |
| 50 return SkSize::Make(SkFloatToScalar(size.width()), |
| 51 SkFloatToScalar(size.height())); |
| 52 } |
| 53 |
| 54 SizeF SkSizeToSizeF(const SkSize& size) { |
| 55 return SizeF(SkScalarToFloat(size.width()), SkScalarToFloat(size.height())); |
| 56 } |
| 57 |
48 void TransformToFlattenedSkMatrix(const gfx::Transform& transform, | 58 void TransformToFlattenedSkMatrix(const gfx::Transform& transform, |
49 SkMatrix* flattened) { | 59 SkMatrix* flattened) { |
50 // Convert from 4x4 to 3x3 by dropping the third row and column. | 60 // Convert from 4x4 to 3x3 by dropping the third row and column. |
51 flattened->set(0, SkMScalarToScalar(transform.matrix().get(0, 0))); | 61 flattened->set(0, SkMScalarToScalar(transform.matrix().get(0, 0))); |
52 flattened->set(1, SkMScalarToScalar(transform.matrix().get(0, 1))); | 62 flattened->set(1, SkMScalarToScalar(transform.matrix().get(0, 1))); |
53 flattened->set(2, SkMScalarToScalar(transform.matrix().get(0, 3))); | 63 flattened->set(2, SkMScalarToScalar(transform.matrix().get(0, 3))); |
54 flattened->set(3, SkMScalarToScalar(transform.matrix().get(1, 0))); | 64 flattened->set(3, SkMScalarToScalar(transform.matrix().get(1, 0))); |
55 flattened->set(4, SkMScalarToScalar(transform.matrix().get(1, 1))); | 65 flattened->set(4, SkMScalarToScalar(transform.matrix().get(1, 1))); |
56 flattened->set(5, SkMScalarToScalar(transform.matrix().get(1, 3))); | 66 flattened->set(5, SkMScalarToScalar(transform.matrix().get(1, 3))); |
57 flattened->set(6, SkMScalarToScalar(transform.matrix().get(3, 0))); | 67 flattened->set(6, SkMScalarToScalar(transform.matrix().get(3, 0))); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 102 } |
93 | 103 |
94 void ConvertSkiaToRGBA(const unsigned char* skia, | 104 void ConvertSkiaToRGBA(const unsigned char* skia, |
95 int pixel_width, | 105 int pixel_width, |
96 unsigned char* rgba) { | 106 unsigned char* rgba) { |
97 int total_length = pixel_width * 4; | 107 int total_length = pixel_width * 4; |
98 for (int i = 0; i < total_length; i += 4) { | 108 for (int i = 0; i < total_length; i += 4) { |
99 const uint32_t pixel_in = *reinterpret_cast<const uint32_t*>(&skia[i]); | 109 const uint32_t pixel_in = *reinterpret_cast<const uint32_t*>(&skia[i]); |
100 | 110 |
101 // Pack the components here. | 111 // Pack the components here. |
102 int alpha = SkGetPackedA32(pixel_in); | 112 SkAlpha alpha = SkGetPackedA32(pixel_in); |
103 if (alpha != 0 && alpha != 255) { | 113 if (alpha != 0 && alpha != 255) { |
104 SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel_in); | 114 SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel_in); |
105 rgba[i + 0] = SkColorGetR(unmultiplied); | 115 rgba[i + 0] = SkColorGetR(unmultiplied); |
106 rgba[i + 1] = SkColorGetG(unmultiplied); | 116 rgba[i + 1] = SkColorGetG(unmultiplied); |
107 rgba[i + 2] = SkColorGetB(unmultiplied); | 117 rgba[i + 2] = SkColorGetB(unmultiplied); |
108 rgba[i + 3] = alpha; | 118 rgba[i + 3] = alpha; |
109 } else { | 119 } else { |
110 rgba[i + 0] = SkGetPackedR32(pixel_in); | 120 rgba[i + 0] = SkGetPackedR32(pixel_in); |
111 rgba[i + 1] = SkGetPackedG32(pixel_in); | 121 rgba[i + 1] = SkGetPackedG32(pixel_in); |
112 rgba[i + 2] = SkGetPackedB32(pixel_in); | 122 rgba[i + 2] = SkGetPackedB32(pixel_in); |
113 rgba[i + 3] = alpha; | 123 rgba[i + 3] = alpha; |
114 } | 124 } |
115 } | 125 } |
116 } | 126 } |
117 | 127 |
| 128 void QuadFToSkPoints(const gfx::QuadF& quad, SkPoint points[4]) { |
| 129 points[0] = SkPoint::Make(quad.p1().x(), quad.p1().y()); |
| 130 points[1] = SkPoint::Make(quad.p2().x(), quad.p2().y()); |
| 131 points[2] = SkPoint::Make(quad.p3().x(), quad.p3().y()); |
| 132 points[3] = SkPoint::Make(quad.p4().x(), quad.p4().y()); |
| 133 } |
| 134 |
118 } // namespace gfx | 135 } // namespace gfx |
OLD | NEW |