license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 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. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
| 5 | #include "base/gfx/skia_utils.h" |
| 6 | |
| 7 | #include "base/logging.h" |
| 8 | #include "SkRect.h" |
| 9 | #include "SkGradientShader.h" |
| 10 | |
| 11 | namespace { |
| 12 | |
| 13 | COMPILE_ASSERT(offsetof(RECT, left) == offsetof(SkIRect, fLeft), o1); |
| 14 | COMPILE_ASSERT(offsetof(RECT, top) == offsetof(SkIRect, fTop), o2); |
| 15 | COMPILE_ASSERT(offsetof(RECT, right) == offsetof(SkIRect, fRight), o3); |
| 16 | COMPILE_ASSERT(offsetof(RECT, bottom) == offsetof(SkIRect, fBottom), o4); |
| 17 | COMPILE_ASSERT(sizeof(RECT().left) == sizeof(SkIRect().fLeft), o5); |
| 18 | COMPILE_ASSERT(sizeof(RECT().top) == sizeof(SkIRect().fTop), o6); |
| 19 | COMPILE_ASSERT(sizeof(RECT().right) == sizeof(SkIRect().fRight), o7); |
| 20 | COMPILE_ASSERT(sizeof(RECT().bottom) == sizeof(SkIRect().fBottom), o8); |
| 21 | COMPILE_ASSERT(sizeof(RECT) == sizeof(SkIRect), o9); |
| 22 | |
| 23 | } // namespace |
| 24 | |
| 25 | namespace gfx { |
| 26 | |
| 27 | POINT SkPointToPOINT(const SkPoint& point) { |
| 28 | POINT win_point = { SkScalarRound(point.fX), SkScalarRound(point.fY) }; |
| 29 | return win_point; |
| 30 | } |
| 31 | |
| 32 | SkRect RECTToSkRect(const RECT& rect) { |
| 33 | SkRect sk_rect = { SkIntToScalar(rect.left), SkIntToScalar(rect.top), |
| 34 | SkIntToScalar(rect.right), SkIntToScalar(rect.bottom) }; |
| 35 | return sk_rect; |
| 36 | } |
| 37 | |
| 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) { |
| 53 | #ifndef _MSC_VER |
| 54 | 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 | } |
| 60 | |
| 61 | COLORREF SkColorToCOLORREF(SkColor color) { |
| 62 | // 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 |
| 64 | // (SkColorGetX(color) * 255 / a) 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)); |
| 68 | #else |
| 69 | // 0BGR = ((ARGB -> BGRA) >> 8) |
| 70 | return (_byteswap_ulong(color) >> 8); |
| 71 | #endif |
| 72 | } |
| 73 | |
| 74 | } // namespace gfx |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 75 | |