OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/path_win.h" | 5 #include "ui/gfx/path_win.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/win/scoped_gdi_object.h" | 8 #include "base/win/scoped_gdi_object.h" |
9 #include "third_party/skia/include/core/SkRegion.h" | 9 #include "third_party/skia/include/core/SkRegion.h" |
10 #include "ui/gfx/path.h" | 10 #include "ui/gfx/path.h" |
11 | 11 |
12 namespace gfx { | 12 namespace gfx { |
13 | 13 |
14 HRGN CreateHRGNFromSkRegion(const SkRegion& region) { | 14 HRGN CreateHRGNFromSkRegion(const SkRegion& region) { |
15 base::win::ScopedRegion temp(::CreateRectRgn(0, 0, 0, 0)); | 15 base::win::ScopedRegion temp(::CreateRectRgn(0, 0, 0, 0)); |
16 base::win::ScopedRegion result(::CreateRectRgn(0, 0, 0, 0)); | 16 base::win::ScopedRegion result(::CreateRectRgn(0, 0, 0, 0)); |
17 | 17 |
18 for (SkRegion::Iterator i(region); !i.done(); i.next()) { | 18 for (SkRegion::Iterator i(region); !i.done(); i.next()) { |
19 const SkIRect& rect = i.rect(); | 19 const SkIRect& rect = i.rect(); |
20 ::SetRectRgn(temp, rect.left(), rect.top(), rect.right(), rect.bottom()); | 20 ::SetRectRgn(temp, rect.left(), rect.top(), rect.right(), rect.bottom()); |
21 ::CombineRgn(result, result, temp, RGN_OR); | 21 ::CombineRgn(result, result, temp, RGN_OR); |
22 } | 22 } |
23 | 23 |
24 return result.release(); | 24 return result.release(); |
25 } | 25 } |
26 | 26 |
27 HRGN CreateHRGNFromSkPath(const SkPath& path) { | 27 HRGN CreateHRGNFromSkPath(const SkPath& path) { |
28 int point_count = path.getPoints(NULL, 0); | 28 SkRegion clip(SkIRect::MakeLTRB(INT_MIN, INT_MIN, INT_MAX, INT_MAX)); |
29 scoped_ptr<SkPoint[]> points(new SkPoint[point_count]); | 29 SkRegion region; |
30 path.getPoints(points.get(), point_count); | 30 region.setPath(path, clip); |
31 scoped_ptr<POINT[]> windows_points(new POINT[point_count]); | 31 return CreateHRGNFromSkRegion(region); |
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); | |
35 } | |
36 | |
37 return ::CreatePolygonRgn(windows_points.get(), point_count, ALTERNATE); | |
38 } | 32 } |
39 | 33 |
40 // See path_aura.cc for Aura definition of these methods: | 34 // See path_aura.cc for Aura definition of these methods: |
41 #if !defined(USE_AURA) | 35 #if !defined(USE_AURA) |
42 | 36 |
43 NativeRegion Path::CreateNativeRegion() const { | 37 NativeRegion Path::CreateNativeRegion() const { |
44 return CreateHRGNFromSkPath(*this); | 38 return CreateHRGNFromSkPath(*this); |
45 } | 39 } |
46 | 40 |
47 // static | 41 // static |
(...skipping 13 matching lines...) Expand all Loading... |
61 // static | 55 // static |
62 NativeRegion Path::SubtractRegion(NativeRegion r1, NativeRegion r2) { | 56 NativeRegion Path::SubtractRegion(NativeRegion r1, NativeRegion r2) { |
63 HRGN dest = CreateRectRgn(0, 0, 1, 1); | 57 HRGN dest = CreateRectRgn(0, 0, 1, 1); |
64 CombineRgn(dest, r1, r2, RGN_DIFF); | 58 CombineRgn(dest, r1, r2, RGN_DIFF); |
65 return dest; | 59 return dest; |
66 } | 60 } |
67 | 61 |
68 #endif | 62 #endif |
69 | 63 |
70 } // namespace gfx | 64 } // namespace gfx |
OLD | NEW |