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. 4 5 #include "skia/ext/skia_utils_win.h" 6 7 #include <windows.h> 8 9 #include "third_party/skia/include/core/SkRect.h" 10 #include "third_party/skia/include/effects/SkGradientShader.h" 11 12 namespace { 13 14 template <bool> 15 struct CompileAssert { 16 }; 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); 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); 31 32 } // namespace 33 34 namespace skia { 35 36 POINT SkPointToPOINT(const SkPoint& point) { 37 POINT win_point = { SkScalarRound(point.fX), SkScalarRound(point.fY) }; 38 return win_point; 39 } 40 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; 45 } 46 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 54 } 55 56 COLORREF SkColorToCOLORREF(SkColor color) { 57 #ifndef _MSC_VER 58 return RGB(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color)); 59 #else 60 // 0BGR = ((ARGB -> BGRA) >> 8) 61 return (_byteswap_ulong(color) >> 8); 62 #endif 63 } 64 65 } // namespace skia 66 67