OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/gfx/skia_utils_mac.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "SkMatrix.h" | |
9 #include "SkRect.h" | |
10 | |
11 namespace gfx { | |
12 | |
13 CGAffineTransform SkMatrixToCGAffineTransform(const SkMatrix& matrix) { | |
14 // CGAffineTransforms don't support perspective transforms, so make sure | |
15 // we don't get those. | |
16 DCHECK(matrix[SkMatrix::kMPersp0] == 0.0f); | |
17 DCHECK(matrix[SkMatrix::kMPersp1] == 0.0f); | |
18 DCHECK(matrix[SkMatrix::kMPersp2] == 1.0f); | |
19 | |
20 return CGAffineTransformMake(matrix[SkMatrix::kMScaleX], | |
21 matrix[SkMatrix::kMSkewY], | |
22 matrix[SkMatrix::kMSkewX], | |
23 matrix[SkMatrix::kMScaleY], | |
24 matrix[SkMatrix::kMTransX], | |
25 matrix[SkMatrix::kMTransY]); | |
26 } | |
27 | |
28 SkIRect CGRectToSkIRect(const CGRect& rect) { | |
29 SkIRect sk_rect = { | |
30 SkScalarRound(rect.origin.x), | |
31 SkScalarRound(rect.origin.y), | |
32 SkScalarRound(rect.origin.x + rect.size.width), | |
33 SkScalarRound(rect.origin.y + rect.size.height) | |
34 }; | |
35 return sk_rect; | |
36 } | |
37 | |
38 SkRect CGRectToSkRect(const CGRect& rect) { | |
39 SkRect sk_rect = { | |
40 rect.origin.x, | |
41 rect.origin.y, | |
42 rect.origin.x + rect.size.width, | |
43 rect.origin.y + rect.size.height, | |
44 }; | |
45 return sk_rect; | |
46 } | |
47 | |
48 CGRect SkIRectToCGRect(const SkIRect& rect) { | |
49 CGRect cg_rect = { | |
50 { rect.fLeft, rect.fTop }, | |
51 { rect.fRight - rect.fLeft, rect.fBottom - rect.fTop } | |
52 }; | |
53 return cg_rect; | |
54 } | |
55 | |
56 CGRect SkRectToCGRect(const SkRect& rect) { | |
57 CGRect cg_rect = { | |
58 { rect.fLeft, rect.fTop }, | |
59 { rect.fRight - rect.fLeft, rect.fBottom - rect.fTop } | |
60 }; | |
61 return cg_rect; | |
62 } | |
63 | |
64 // Converts CGColorRef to the ARGB layout Skia expects. | |
65 SkColor CGColorRefToSkColor(CGColorRef color) { | |
66 DCHECK(CGColorGetNumberOfComponents(color) == 4); | |
67 const CGFloat *components = CGColorGetComponents(color); | |
68 return SkColorSetARGB(SkScalarRound(255.0 * components[3]), // alpha | |
69 SkScalarRound(255.0 * components[0]), // red | |
70 SkScalarRound(255.0 * components[1]), // green | |
71 SkScalarRound(255.0 * components[2])); // blue | |
72 } | |
73 | |
74 // Converts ARGB to CGColorRef. | |
75 CGColorRef SkColorToCGColorRef(SkColor color) { | |
76 return CGColorCreateGenericRGB(SkColorGetR(color) / 255.0, | |
77 SkColorGetG(color) / 255.0, | |
78 SkColorGetB(color) / 255.0, | |
79 SkColorGetA(color) / 255.0); | |
80 } | |
81 | |
82 } // namespace gfx | |
83 | |
OLD | NEW |