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 12namespace { 13 14template <bool> 15struct CompileAssert { 16}; 17 18#undef COMPILE_ASSERT 19#define COMPILE_ASSERT(expr, msg) \ 20 typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] 21 22COMPILE_ASSERT(SK_OFFSETOF(RECT, left) == SK_OFFSETOF(SkIRect, fLeft), o1); 23COMPILE_ASSERT(SK_OFFSETOF(RECT, top) == SK_OFFSETOF(SkIRect, fTop), o2); 24COMPILE_ASSERT(SK_OFFSETOF(RECT, right) == SK_OFFSETOF(SkIRect, fRight), o3); 25COMPILE_ASSERT(SK_OFFSETOF(RECT, bottom) == SK_OFFSETOF(SkIRect, fBottom), o4); 26COMPILE_ASSERT(sizeof(RECT().left) == sizeof(SkIRect().fLeft), o5); 27COMPILE_ASSERT(sizeof(RECT().top) == sizeof(SkIRect().fTop), o6); 28COMPILE_ASSERT(sizeof(RECT().right) == sizeof(SkIRect().fRight), o7); 29COMPILE_ASSERT(sizeof(RECT().bottom) == sizeof(SkIRect().fBottom), o8); 30COMPILE_ASSERT(sizeof(RECT) == sizeof(SkIRect), o9); 31 32} // namespace 33 34namespace skia { 35 36POINT SkPointToPOINT(const SkPoint& point) { 37 POINT win_point = { SkScalarRound(point.fX), SkScalarRound(point.fY) }; 38 return win_point; 39} 40 41SkRect 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 47SkColor 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 56COLORREF 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