Exclude TrayIMETest.PerformActionOnDetailedView under valgrind, where it crashes.
[chromium-blink-merge.git] / ui / gfx / path_x11.cc
blobcaea2ec12e6eef417c64d6efeb67bebd066a61a2
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.
5 #include "ui/gfx/path_x11.h"
7 #include <X11/Xlib.h>
8 #include <X11/Xregion.h>
9 #include <X11/Xutil.h>
11 #include "base/memory/scoped_ptr.h"
12 #include "third_party/skia/include/core/SkRegion.h"
13 #include "ui/gfx/path.h"
15 namespace gfx {
17 Region CreateRegionFromSkRegion(const SkRegion& region) {
18 Region result = XCreateRegion();
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);
29 return result;
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);
42 return XPolygonRegion(x11_points.get(), point_count, EvenOddRule);
45 } // namespace gfx