blob: 7b70056d263f72deff5ba2be90c01d14a06dd9c1 [file] [log] [blame]
license.botf003cfe2008-08-24 09:55:55 +09001// 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.commit3f4a7322008-07-27 06:49:38 +09004
5#include "base/gfx/skia_utils.h"
6
7#include "base/logging.h"
8#include "SkRect.h"
9#include "SkGradientShader.h"
10
11namespace {
12
13COMPILE_ASSERT(offsetof(RECT, left) == offsetof(SkIRect, fLeft), o1);
14COMPILE_ASSERT(offsetof(RECT, top) == offsetof(SkIRect, fTop), o2);
15COMPILE_ASSERT(offsetof(RECT, right) == offsetof(SkIRect, fRight), o3);
16COMPILE_ASSERT(offsetof(RECT, bottom) == offsetof(SkIRect, fBottom), o4);
17COMPILE_ASSERT(sizeof(RECT().left) == sizeof(SkIRect().fLeft), o5);
18COMPILE_ASSERT(sizeof(RECT().top) == sizeof(SkIRect().fTop), o6);
19COMPILE_ASSERT(sizeof(RECT().right) == sizeof(SkIRect().fRight), o7);
20COMPILE_ASSERT(sizeof(RECT().bottom) == sizeof(SkIRect().fBottom), o8);
21COMPILE_ASSERT(sizeof(RECT) == sizeof(SkIRect), o9);
22
23} // namespace
24
25namespace gfx {
26
27POINT SkPointToPOINT(const SkPoint& point) {
28 POINT win_point = { SkScalarRound(point.fX), SkScalarRound(point.fY) };
29 return win_point;
30}
31
32SkRect 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
38SkShader* 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
52SkColor 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
61COLORREF 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.botf003cfe2008-08-24 09:55:55 +090075