[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 71c6ea9 | 2012-09-17 19:33:13 | [diff] [blame] | 5 | #include "ui/gfx/path_win.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 7 | #include <memory> |
| 8 | |
[email protected] | 21ed140d | 2013-11-08 06:08:35 | [diff] [blame] | 9 | #include "base/win/scoped_gdi_object.h" |
| 10 | #include "third_party/skia/include/core/SkRegion.h" |
[email protected] | 71c6ea9 | 2012-09-17 19:33:13 | [diff] [blame] | 11 | #include "ui/gfx/path.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | |
| 13 | namespace gfx { |
| 14 | |
[email protected] | 21ed140d | 2013-11-08 06:08:35 | [diff] [blame] | 15 | HRGN CreateHRGNFromSkRegion(const SkRegion& region) { |
| 16 | base::win::ScopedRegion temp(::CreateRectRgn(0, 0, 0, 0)); |
| 17 | base::win::ScopedRegion result(::CreateRectRgn(0, 0, 0, 0)); |
| 18 | |
| 19 | for (SkRegion::Iterator i(region); !i.done(); i.next()) { |
| 20 | const SkIRect& rect = i.rect(); |
anpol | 280746c | 2015-12-18 08:39:03 | [diff] [blame] | 21 | ::SetRectRgn(temp.get(), |
| 22 | rect.left(), rect.top(), rect.right(), rect.bottom()); |
| 23 | ::CombineRgn(result.get(), result.get(), temp.get(), RGN_OR); |
[email protected] | 21ed140d | 2013-11-08 06:08:35 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | return result.release(); |
| 27 | } |
| 28 | |
[email protected] | 71c6ea9 | 2012-09-17 19:33:13 | [diff] [blame] | 29 | HRGN CreateHRGNFromSkPath(const SkPath& path) { |
alex-ac | 2cb37ad8 | 2014-11-13 18:03:29 | [diff] [blame] | 30 | SkRegion clip_region; |
| 31 | clip_region.setRect(path.getBounds().round()); |
| 32 | SkRegion region; |
| 33 | region.setPath(path, clip_region); |
| 34 | return CreateHRGNFromSkRegion(region); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 35 | } |
| 36 | |
[email protected] | 42b4c09 | 2009-03-02 11:24:03 | [diff] [blame] | 37 | } // namespace gfx |