summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-03 20:48:29 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-03 20:48:29 +0000
commit90d22e2aeeedb9e3084fba0773b6ca713021765b (patch)
treeea968c9a2c1d6d07a1bd0f2e508bda5029fc20a4 /skia
parentfc78fd42b81a97d3d15419e679f3ff9e0f470d9c (diff)
downloadchromium_src-90d22e2aeeedb9e3084fba0773b6ca713021765b.zip
chromium_src-90d22e2aeeedb9e3084fba0773b6ca713021765b.tar.gz
chromium_src-90d22e2aeeedb9e3084fba0773b6ca713021765b.tar.bz2
Move base/gfx/skia_util to skia/ext/skia_util_win.
In a later pass, I will separate off the cross-platform part of this file into skia/ext/skia_util (only one function). Review URL: http://codereview.chromium.org/13101 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6306 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/SConscript1
-rw-r--r--skia/ext/platform_device_win.cc2
-rw-r--r--skia/ext/skia_utils_win.cc75
-rw-r--r--skia/ext/skia_utils_win.h56
-rw-r--r--skia/ext/vector_device.cc2
-rw-r--r--skia/skia.vcproj8
6 files changed, 142 insertions, 2 deletions
diff --git a/skia/SConscript b/skia/SConscript
index 6006e6f..8733d466 100644
--- a/skia/SConscript
+++ b/skia/SConscript
@@ -183,6 +183,7 @@ if env['PLATFORM'] == 'win32':
input_files.append('ext/bitmap_platform_device_win.cc')
input_files.append('ext/platform_canvas_win.cc')
input_files.append('ext/platform_device_win.cc')
+ input_files.append('ext/skia_utils_win.cc")
input_files.append('ext/vector_canvas.cc')
input_files.append('ext/vector_device.cc')
diff --git a/skia/ext/platform_device_win.cc b/skia/ext/platform_device_win.cc
index 15201c0..a712791 100644
--- a/skia/ext/platform_device_win.cc
+++ b/skia/ext/platform_device_win.cc
@@ -5,7 +5,7 @@
#include "skia/ext/platform_device_win.h"
#include "base/logging.h"
-#include "base/gfx/skia_utils.h"
+#include "skia/ext/skia_utils_win.h"
#include "SkMatrix.h"
#include "SkPath.h"
#include "SkRegion.h"
diff --git a/skia/ext/skia_utils_win.cc b/skia/ext/skia_utils_win.cc
new file mode 100644
index 0000000..dcac26f
--- /dev/null
+++ b/skia/ext/skia_utils_win.cc
@@ -0,0 +1,75 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "skia/ext/skia_utils_win.h"
+
+#include "base/logging.h"
+#include "SkRect.h"
+#include "SkGradientShader.h"
+
+namespace {
+
+COMPILE_ASSERT(offsetof(RECT, left) == offsetof(SkIRect, fLeft), o1);
+COMPILE_ASSERT(offsetof(RECT, top) == offsetof(SkIRect, fTop), o2);
+COMPILE_ASSERT(offsetof(RECT, right) == offsetof(SkIRect, fRight), o3);
+COMPILE_ASSERT(offsetof(RECT, bottom) == offsetof(SkIRect, fBottom), o4);
+COMPILE_ASSERT(sizeof(RECT().left) == sizeof(SkIRect().fLeft), o5);
+COMPILE_ASSERT(sizeof(RECT().top) == sizeof(SkIRect().fTop), o6);
+COMPILE_ASSERT(sizeof(RECT().right) == sizeof(SkIRect().fRight), o7);
+COMPILE_ASSERT(sizeof(RECT().bottom) == sizeof(SkIRect().fBottom), o8);
+COMPILE_ASSERT(sizeof(RECT) == sizeof(SkIRect), o9);
+
+} // namespace
+
+namespace gfx {
+
+POINT SkPointToPOINT(const SkPoint& point) {
+ POINT win_point = { SkScalarRound(point.fX), SkScalarRound(point.fY) };
+ return win_point;
+}
+
+SkRect RECTToSkRect(const RECT& rect) {
+ SkRect sk_rect = { SkIntToScalar(rect.left), SkIntToScalar(rect.top),
+ SkIntToScalar(rect.right), SkIntToScalar(rect.bottom) };
+ return sk_rect;
+}
+
+SkShader* CreateGradientShader(int start_point,
+ int end_point,
+ SkColor start_color,
+ SkColor end_color) {
+ SkColor grad_colors[2] = { start_color, end_color};
+ SkPoint grad_points[2];
+ grad_points[0].set(SkIntToScalar(0), SkIntToScalar(start_point));
+ grad_points[1].set(SkIntToScalar(0), SkIntToScalar(end_point));
+
+ return SkGradientShader::CreateLinear(
+ grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode);
+}
+
+
+SkColor COLORREFToSkColor(COLORREF color) {
+#ifndef _MSC_VER
+ return SkColorSetRGB(GetRValue(color), GetGValue(color), GetBValue(color));
+#else
+ // ARGB = 0xFF000000 | ((0BGR -> RGB0) >> 8)
+ return 0xFF000000u | (_byteswap_ulong(color) >> 8);
+#endif
+}
+
+COLORREF SkColorToCOLORREF(SkColor color) {
+ // Currently, Alpha is always 255 or the color is 0 so there is no need to
+ // demultiply the channels. If this DCHECK() is ever hit, the full
+ // (SkColorGetX(color) * 255 / a) will have to be added in the conversion.
+ DCHECK((0xFF == SkColorGetA(color)) || (0 == color));
+#ifndef _MSC_VER
+ return RGB(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color));
+#else
+ // 0BGR = ((ARGB -> BGRA) >> 8)
+ return (_byteswap_ulong(color) >> 8);
+#endif
+}
+
+} // namespace gfx
+
diff --git a/skia/ext/skia_utils_win.h b/skia/ext/skia_utils_win.h
new file mode 100644
index 0000000..4ad7910
--- /dev/null
+++ b/skia/ext/skia_utils_win.h
@@ -0,0 +1,56 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_GFX_SKIA_UTILS_WIN_H_
+#define BASE_GFX_SKIA_UTILS_WIN_H_
+
+#include "SkColor.h"
+#include "SkShader.h"
+
+struct SkIRect;
+struct SkPoint;
+struct SkRect;
+typedef unsigned long DWORD;
+typedef DWORD COLORREF;
+typedef struct tagPOINT POINT;
+typedef struct tagRECT RECT;
+
+namespace gfx {
+
+// Converts a Skia point to a Windows POINT.
+POINT SkPointToPOINT(const SkPoint& point);
+
+// Converts a Windows RECT to a Skia rect.
+SkRect RECTToSkRect(const RECT& rect);
+
+// Converts a Windows RECT to a Skia rect.
+// Both use same in-memory format. Verified by COMPILE_ASSERT() in
+// skia_utils.cc.
+inline const SkIRect& RECTToSkIRect(const RECT& rect) {
+ return reinterpret_cast<const SkIRect&>(rect);
+}
+
+// Converts a Skia rect to a Windows RECT.
+// Both use same in-memory format. Verified by COMPILE_ASSERT() in
+// skia_utils.cc.
+inline const RECT& SkIRectToRECT(const SkIRect& rect) {
+ return reinterpret_cast<const RECT&>(rect);
+}
+
+// Creates a vertical gradient shader. The caller owns the shader.
+SkShader* CreateGradientShader(int start_point,
+ int end_point,
+ SkColor start_color,
+ SkColor end_color);
+
+// Converts COLORREFs (0BGR) to the ARGB layout Skia expects.
+SkColor COLORREFToSkColor(COLORREF color);
+
+// Converts ARGB to COLORREFs (0BGR).
+COLORREF SkColorToCOLORREF(SkColor color);
+
+} // namespace gfx
+
+#endif // SKIA_EXT_SKIA_UTILS_WIN_H_
+
diff --git a/skia/ext/vector_device.cc b/skia/ext/vector_device.cc
index a587e0c..32449ad 100644
--- a/skia/ext/vector_device.cc
+++ b/skia/ext/vector_device.cc
@@ -5,9 +5,9 @@
#include "skia/ext/vector_device.h"
#include "base/gfx/gdi_util.h"
-#include "base/gfx/skia_utils.h"
#include "base/logging.h"
#include "base/scoped_handle.h"
+#include "skia/ext/skia_utils_win.h"
#include "SkUtils.h"
diff --git a/skia/skia.vcproj b/skia/skia.vcproj
index 93988ad..b44b455 100644
--- a/skia/skia.vcproj
+++ b/skia/skia.vcproj
@@ -1361,6 +1361,14 @@
>
</File>
<File
+ RelativePath=".\ext\skia_utils_win.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\ext\skia_utils_win.h"
+ >
+ </File>
+ <File
RelativePath=".\ext\vector_canvas.cc"
>
</File>