Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / skia / ext / skia_utils_win.cc
blob3089b242c2626febb0a485c5dd8ff50c138c558b
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 <stddef.h>
8 #include <windows.h>
10 #include "third_party/skia/include/core/SkRect.h"
11 #include "third_party/skia/include/core/SkTypes.h"
12 #include "third_party/skia/include/effects/SkGradientShader.h"
14 namespace {
16 static_assert(offsetof(RECT, left) == offsetof(SkIRect, fLeft), "o1");
17 static_assert(offsetof(RECT, top) == offsetof(SkIRect, fTop), "o2");
18 static_assert(offsetof(RECT, right) == offsetof(SkIRect, fRight), "o3");
19 static_assert(offsetof(RECT, bottom) == offsetof(SkIRect, fBottom), "o4");
20 static_assert(sizeof(RECT().left) == sizeof(SkIRect().fLeft), "o5");
21 static_assert(sizeof(RECT().top) == sizeof(SkIRect().fTop), "o6");
22 static_assert(sizeof(RECT().right) == sizeof(SkIRect().fRight), "o7");
23 static_assert(sizeof(RECT().bottom) == sizeof(SkIRect().fBottom), "o8");
24 static_assert(sizeof(RECT) == sizeof(SkIRect), "o9");
26 } // namespace
28 namespace skia {
30 POINT SkPointToPOINT(const SkPoint& point) {
31 POINT win_point = {
32 SkScalarRoundToInt(point.fX), SkScalarRoundToInt(point.fY)
34 return win_point;
37 SkRect RECTToSkRect(const RECT& rect) {
38 SkRect sk_rect = { SkIntToScalar(rect.left), SkIntToScalar(rect.top),
39 SkIntToScalar(rect.right), SkIntToScalar(rect.bottom) };
40 return sk_rect;
43 SkColor COLORREFToSkColor(COLORREF color) {
44 #ifndef _MSC_VER
45 return SkColorSetRGB(GetRValue(color), GetGValue(color), GetBValue(color));
46 #else
47 // ARGB = 0xFF000000 | ((0BGR -> RGB0) >> 8)
48 return 0xFF000000u | (_byteswap_ulong(color) >> 8);
49 #endif
52 COLORREF SkColorToCOLORREF(SkColor color) {
53 #ifndef _MSC_VER
54 return RGB(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color));
55 #else
56 // 0BGR = ((ARGB -> BGRA) >> 8)
57 return (_byteswap_ulong(color) >> 8);
58 #endif
61 } // namespace skia