blob: 2149aad2fd03812fd0352839004226131c185d63 [file] [log] [blame]
[email protected]42b4c092009-03-02 11:24:031// Copyright (c) 2006-2008 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
[email protected]5c7293a2010-03-17 06:40:575#include "gfx/path.h"
[email protected]42b4c092009-03-02 11:24:036
7#include <gdk/gdk.h>
8
9#include "base/scoped_ptr.h"
[email protected]9513f2042009-08-19 03:37:0010#include "base/command_line.h"
[email protected]42b4c092009-03-02 11:24:0311
12namespace gfx {
13
[email protected]a3406972009-11-04 05:05:4814GdkRegion* Path::CreateNativeRegion() const {
[email protected]42b4c092009-03-02 11:24:0315 int point_count = getPoints(NULL, 0);
[email protected]9513f2042009-08-19 03:37:0016 if (point_count <= 1) {
17 // NOTE: ideally this would return gdk_empty_region, but that returns a
18 // region with nothing in it.
19 return NULL;
20 }
21
[email protected]42b4c092009-03-02 11:24:0322 scoped_array<SkPoint> points(new SkPoint[point_count]);
23 getPoints(points.get(), point_count);
24
25 scoped_array<GdkPoint> gdk_points(new GdkPoint[point_count]);
26 for (int i = 0; i < point_count; ++i) {
27 gdk_points[i].x = SkScalarRound(points[i].fX);
28 gdk_points[i].y = SkScalarRound(points[i].fY);
29 }
30
31 return gdk_region_polygon(gdk_points.get(), point_count, GDK_EVEN_ODD_RULE);
32}
33
[email protected]a3406972009-11-04 05:05:4834// static
35NativeRegion Path::IntersectRegions(NativeRegion r1, NativeRegion r2) {
36 GdkRegion* copy = gdk_region_copy(r1);
37 gdk_region_intersect(copy, r2);
38 return copy;
39}
40
41// static
42NativeRegion Path::CombineRegions(NativeRegion r1, NativeRegion r2) {
43 GdkRegion* copy = gdk_region_copy(r1);
44 gdk_region_union(copy, r2);
45 return copy;
46}
47
48// static
49NativeRegion Path::SubtractRegion(NativeRegion r1, NativeRegion r2) {
50 GdkRegion* copy = gdk_region_copy(r1);
51 gdk_region_subtract(copy, r2);
52 return copy;
53}
54
[email protected]42b4c092009-03-02 11:24:0355} // namespace gfx