chromeos: bluetooth: add BluetoothInputClient
[chromium-blink-merge.git] / skia / ext / skia_utils_win.cc
blob4988a3a8c8a0f09e5ba0228d491943dd01e806f7
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.
5 #include "skia/ext/skia_utils_win.h"
7 #include <windows.h>
9 #include "third_party/skia/include/core/SkRect.h"
10 #include "third_party/skia/include/effects/SkGradientShader.h"
12 namespace {
14 template <bool>
15 struct CompileAssert {
18 #undef COMPILE_ASSERT
19 #define COMPILE_ASSERT(expr, msg) \
20 typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
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);
26 COMPILE_ASSERT(sizeof(RECT().left) == sizeof(SkIRect().fLeft), o5);
27 COMPILE_ASSERT(sizeof(RECT().top) == sizeof(SkIRect().fTop), o6);
28 COMPILE_ASSERT(sizeof(RECT().right) == sizeof(SkIRect().fRight), o7);
29 COMPILE_ASSERT(sizeof(RECT().bottom) == sizeof(SkIRect().fBottom), o8);
30 COMPILE_ASSERT(sizeof(RECT) == sizeof(SkIRect), o9);
32 } // namespace
34 namespace skia {
36 POINT SkPointToPOINT(const SkPoint& point) {
37 POINT win_point = { SkScalarRound(point.fX), SkScalarRound(point.fY) };
38 return win_point;
41 SkRect RECTToSkRect(const RECT& rect) {
42 SkRect sk_rect = { SkIntToScalar(rect.left), SkIntToScalar(rect.top),
43 SkIntToScalar(rect.right), SkIntToScalar(rect.bottom) };
44 return sk_rect;
47 SkColor COLORREFToSkColor(COLORREF color) {
48 #ifndef _MSC_VER
49 return SkColorSetRGB(GetRValue(color), GetGValue(color), GetBValue(color));
50 #else
51 // ARGB = 0xFF000000 | ((0BGR -> RGB0) >> 8)
52 return 0xFF000000u | (_byteswap_ulong(color) >> 8);
53 #endif
56 COLORREF SkColorToCOLORREF(SkColor color) {
57 // Currently, Alpha is always 255 or the color is 0 so there is no need to
58 // demultiply the channels. If this DCHECK() is ever hit, the full
59 // (SkColorGetX(color) * 255 / a) will have to be added in the conversion.
60 SkASSERT((0xFF == SkColorGetA(color)) || (0 == color));
61 #ifndef _MSC_VER
62 return RGB(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color));
63 #else
64 // 0BGR = ((ARGB -> BGRA) >> 8)
65 return (_byteswap_ulong(color) >> 8);
66 #endif
69 } // namespace skia