Refactor HpackDecoder's public API to ease integration into SpdyFramer.
[chromium-blink-merge.git] / ui / gfx / path_x11.cc
blobdb99f0155dd3f00d63f3d9b770371d8843c2da2f
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/Xutil.h>
9 #include "base/memory/scoped_ptr.h"
10 #include "third_party/skia/include/core/SkRegion.h"
11 #include "ui/gfx/path.h"
13 namespace gfx {
15 Region CreateRegionFromSkRegion(const SkRegion& region) {
16 Region result = XCreateRegion();
18 for (SkRegion::Iterator i(region); !i.done(); i.next()) {
19 XRectangle rect;
20 rect.x = i.rect().x();
21 rect.y = i.rect().y();
22 rect.width = i.rect().width();
23 rect.height = i.rect().height();
24 XUnionRectWithRegion(&rect, result, result);
27 return result;
30 Region CreateRegionFromSkPath(const SkPath& path) {
31 int point_count = path.getPoints(NULL, 0);
32 scoped_ptr<SkPoint[]> points(new SkPoint[point_count]);
33 path.getPoints(points.get(), point_count);
34 scoped_ptr<XPoint[]> x11_points(new XPoint[point_count]);
35 for (int i = 0; i < point_count; ++i) {
36 x11_points[i].x = SkScalarRoundToInt(points[i].fX);
37 x11_points[i].y = SkScalarRoundToInt(points[i].fY);
40 return XPolygonRegion(x11_points.get(), point_count, EvenOddRule);
43 } // namespace gfx