OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 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 "base/gfx/skia_utils.h" | 5 #include <windows.h> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "skia/ext/skia_utils_win.h" |
| 8 |
8 #include "SkRect.h" | 9 #include "SkRect.h" |
9 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 COMPILE_ASSERT(offsetof(RECT, left) == offsetof(SkIRect, fLeft), o1); | 14 // Compiler assert from base/logging.h |
14 COMPILE_ASSERT(offsetof(RECT, top) == offsetof(SkIRect, fTop), o2); | 15 template <bool> |
15 COMPILE_ASSERT(offsetof(RECT, right) == offsetof(SkIRect, fRight), o3); | 16 struct CompileAssert { |
16 COMPILE_ASSERT(offsetof(RECT, bottom) == offsetof(SkIRect, fBottom), o4); | 17 }; |
| 18 #undef COMPILE_ASSERT |
| 19 #define COMPILE_ASSERT(expr, msg) \ |
| 20 typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] |
| 21 |
| 22 COMPILE_ASSERT(SK_OFFSETOF(RECT, left) == SK_OFFSETOF(SkIRect, fLeft), o1); |
| 23 COMPILE_ASSERT(SK_OFFSETOF(RECT, top) == SK_OFFSETOF(SkIRect, fTop), o2); |
| 24 COMPILE_ASSERT(SK_OFFSETOF(RECT, right) == SK_OFFSETOF(SkIRect, fRight), o3); |
| 25 COMPILE_ASSERT(SK_OFFSETOF(RECT, bottom) == SK_OFFSETOF(SkIRect, fBottom), o4); |
17 COMPILE_ASSERT(sizeof(RECT().left) == sizeof(SkIRect().fLeft), o5); | 26 COMPILE_ASSERT(sizeof(RECT().left) == sizeof(SkIRect().fLeft), o5); |
18 COMPILE_ASSERT(sizeof(RECT().top) == sizeof(SkIRect().fTop), o6); | 27 COMPILE_ASSERT(sizeof(RECT().top) == sizeof(SkIRect().fTop), o6); |
19 COMPILE_ASSERT(sizeof(RECT().right) == sizeof(SkIRect().fRight), o7); | 28 COMPILE_ASSERT(sizeof(RECT().right) == sizeof(SkIRect().fRight), o7); |
20 COMPILE_ASSERT(sizeof(RECT().bottom) == sizeof(SkIRect().fBottom), o8); | 29 COMPILE_ASSERT(sizeof(RECT().bottom) == sizeof(SkIRect().fBottom), o8); |
21 COMPILE_ASSERT(sizeof(RECT) == sizeof(SkIRect), o9); | 30 COMPILE_ASSERT(sizeof(RECT) == sizeof(SkIRect), o9); |
22 | 31 |
23 } // namespace | 32 } // namespace |
24 | 33 |
25 namespace gfx { | 34 namespace skia { |
26 | 35 |
27 POINT SkPointToPOINT(const SkPoint& point) { | 36 POINT SkPointToPOINT(const SkPoint& point) { |
28 POINT win_point = { SkScalarRound(point.fX), SkScalarRound(point.fY) }; | 37 POINT win_point = { SkScalarRound(point.fX), SkScalarRound(point.fY) }; |
29 return win_point; | 38 return win_point; |
30 } | 39 } |
31 | 40 |
32 SkRect RECTToSkRect(const RECT& rect) { | 41 SkRect RECTToSkRect(const RECT& rect) { |
33 SkRect sk_rect = { SkIntToScalar(rect.left), SkIntToScalar(rect.top), | 42 SkRect sk_rect = { SkIntToScalar(rect.left), SkIntToScalar(rect.top), |
34 SkIntToScalar(rect.right), SkIntToScalar(rect.bottom) }; | 43 SkIntToScalar(rect.right), SkIntToScalar(rect.bottom) }; |
35 return sk_rect; | 44 return sk_rect; |
36 } | 45 } |
37 | 46 |
38 SkShader* CreateGradientShader(int start_point, | |
39 int end_point, | |
40 SkColor start_color, | |
41 SkColor end_color) { | |
42 SkColor grad_colors[2] = { start_color, end_color}; | |
43 SkPoint grad_points[2]; | |
44 grad_points[0].set(SkIntToScalar(0), SkIntToScalar(start_point)); | |
45 grad_points[1].set(SkIntToScalar(0), SkIntToScalar(end_point)); | |
46 | |
47 return SkGradientShader::CreateLinear( | |
48 grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode); | |
49 } | |
50 | |
51 | |
52 SkColor COLORREFToSkColor(COLORREF color) { | 47 SkColor COLORREFToSkColor(COLORREF color) { |
53 #ifndef _MSC_VER | |
54 return SkColorSetRGB(GetRValue(color), GetGValue(color), GetBValue(color)); | 48 return SkColorSetRGB(GetRValue(color), GetGValue(color), GetBValue(color)); |
55 #else | |
56 // ARGB = 0xFF000000 | ((0BGR -> RGB0) >> 8) | |
57 return 0xFF000000u | (_byteswap_ulong(color) >> 8); | |
58 #endif | |
59 } | 49 } |
60 | 50 |
61 COLORREF SkColorToCOLORREF(SkColor color) { | 51 COLORREF SkColorToCOLORREF(SkColor color) { |
62 // Currently, Alpha is always 255 or the color is 0 so there is no need to | 52 // Currently, Alpha is always 255 or the color is 0 so there is no need to |
63 // demultiply the channels. If this DCHECK() is ever hit, the full | 53 // demultiply the channels. If this is needed, (SkColorGetX(color) * 255 / a) |
64 // (SkColorGetX(color) * 255 / a) will have to be added in the conversion. | 54 // will have to be added in the conversion. |
65 DCHECK((0xFF == SkColorGetA(color)) || (0 == color)); | |
66 #ifndef _MSC_VER | |
67 return RGB(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color)); | 55 return RGB(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color)); |
68 #else | |
69 // 0BGR = ((ARGB -> BGRA) >> 8) | |
70 return (_byteswap_ulong(color) >> 8); | |
71 #endif | |
72 } | 56 } |
73 | 57 |
74 } // namespace gfx | 58 } // namespace skia |
75 | 59 |
OLD | NEW |