Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / gfx / path_win.cc
blobb28ea7a2c7bf02e99a501c4f9351d199fe6beed5
1 // Copyright (c) 2011 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 "ui/gfx/path_win.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/win/scoped_gdi_object.h"
9 #include "third_party/skia/include/core/SkRegion.h"
10 #include "ui/gfx/path.h"
12 namespace gfx {
14 HRGN CreateHRGNFromSkRegion(const SkRegion& region) {
15 base::win::ScopedRegion temp(::CreateRectRgn(0, 0, 0, 0));
16 base::win::ScopedRegion result(::CreateRectRgn(0, 0, 0, 0));
18 for (SkRegion::Iterator i(region); !i.done(); i.next()) {
19 const SkIRect& rect = i.rect();
20 ::SetRectRgn(temp, rect.left(), rect.top(), rect.right(), rect.bottom());
21 ::CombineRgn(result, result, temp, RGN_OR);
24 return result.release();
27 HRGN CreateHRGNFromSkPath(const SkPath& path) {
28 int point_count = path.getPoints(NULL, 0);
29 scoped_ptr<SkPoint[]> points(new SkPoint[point_count]);
30 path.getPoints(points.get(), point_count);
31 scoped_ptr<POINT[]> windows_points(new POINT[point_count]);
32 for (int i = 0; i < point_count; ++i) {
33 windows_points[i].x = SkScalarRoundToInt(points[i].fX);
34 windows_points[i].y = SkScalarRoundToInt(points[i].fY);
37 return ::CreatePolygonRgn(windows_points.get(), point_count, ALTERNATE);
40 // See path_aura.cc for Aura definition of these methods:
41 #if !defined(USE_AURA)
43 NativeRegion Path::CreateNativeRegion() const {
44 return CreateHRGNFromSkPath(*this);
47 // static
48 NativeRegion Path::IntersectRegions(NativeRegion r1, NativeRegion r2) {
49 HRGN dest = CreateRectRgn(0, 0, 1, 1);
50 CombineRgn(dest, r1, r2, RGN_AND);
51 return dest;
54 // static
55 NativeRegion Path::CombineRegions(NativeRegion r1, NativeRegion r2) {
56 HRGN dest = CreateRectRgn(0, 0, 1, 1);
57 CombineRgn(dest, r1, r2, RGN_OR);
58 return dest;
61 // static
62 NativeRegion Path::SubtractRegion(NativeRegion r1, NativeRegion r2) {
63 HRGN dest = CreateRectRgn(0, 0, 1, 1);
64 CombineRgn(dest, r1, r2, RGN_DIFF);
65 return dest;
68 #endif
70 } // namespace gfx