• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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_x11.h"
6 
7 #include <X11/Xlib.h>
8 #include <X11/Xregion.h>
9 #include <X11/Xutil.h>
10 
11 #include "base/memory/scoped_ptr.h"
12 #include "third_party/skia/include/core/SkRegion.h"
13 #include "ui/gfx/path.h"
14 
15 namespace gfx {
16 
CreateRegionFromSkRegion(const SkRegion & region)17 Region CreateRegionFromSkRegion(const SkRegion& region) {
18   Region result = XCreateRegion();
19 
20   for (SkRegion::Iterator i(region); !i.done(); i.next()) {
21     XRectangle rect;
22     rect.x = i.rect().x();
23     rect.y = i.rect().y();
24     rect.width = i.rect().width();
25     rect.height = i.rect().height();
26     XUnionRectWithRegion(&rect, result, result);
27   }
28 
29   return result;
30 }
31 
CreateRegionFromSkPath(const SkPath & path)32 Region CreateRegionFromSkPath(const SkPath& path) {
33   int point_count = path.getPoints(NULL, 0);
34   scoped_ptr<SkPoint[]> points(new SkPoint[point_count]);
35   path.getPoints(points.get(), point_count);
36   scoped_ptr<XPoint[]> x11_points(new XPoint[point_count]);
37   for (int i = 0; i < point_count; ++i) {
38     x11_points[i].x = SkScalarRoundToInt(points[i].fX);
39     x11_points[i].y = SkScalarRoundToInt(points[i].fY);
40   }
41 
42   return XPolygonRegion(x11_points.get(), point_count, EvenOddRule);
43 }
44 
45 }  // namespace gfx
46