blob: be5d9e22ecba77e3749f2d0f89c078923b98678d [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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.
4
5#include "ui/gfx/path_win.h"
6
7#include "base/memory/scoped_ptr.h"
8#include "ui/gfx/path.h"
9
10namespace gfx {
11
12HRGN CreateHRGNFromSkPath(const SkPath& path) {
13 int point_count = path.getPoints(NULL, 0);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000014 scoped_ptr<SkPoint[]> points(new SkPoint[point_count]);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000015 path.getPoints(points.get(), point_count);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000016 scoped_ptr<POINT[]> windows_points(new POINT[point_count]);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000017 for (int i = 0; i < point_count; ++i) {
18 windows_points[i].x = SkScalarRound(points[i].fX);
19 windows_points[i].y = SkScalarRound(points[i].fY);
20 }
21
22 return ::CreatePolygonRgn(windows_points.get(), point_count, ALTERNATE);
23}
24
25// See path_aura.cc for Aura definition of these methods:
26#if !defined(USE_AURA)
27
28NativeRegion Path::CreateNativeRegion() const {
29 return CreateHRGNFromSkPath(*this);
30}
31
32// static
33NativeRegion Path::IntersectRegions(NativeRegion r1, NativeRegion r2) {
34 HRGN dest = CreateRectRgn(0, 0, 1, 1);
35 CombineRgn(dest, r1, r2, RGN_AND);
36 return dest;
37}
38
39// static
40NativeRegion Path::CombineRegions(NativeRegion r1, NativeRegion r2) {
41 HRGN dest = CreateRectRgn(0, 0, 1, 1);
42 CombineRgn(dest, r1, r2, RGN_OR);
43 return dest;
44}
45
46// static
47NativeRegion Path::SubtractRegion(NativeRegion r1, NativeRegion r2) {
48 HRGN dest = CreateRectRgn(0, 0, 1, 1);
49 CombineRgn(dest, r1, r2, RGN_DIFF);
50 return dest;
51}
52
53#endif
54
55} // namespace gfx