Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: ui/gfx/path_win_unittest.cc

Issue 169223002: Revert of Fix CreateHRGNFromSkPath to support arbitrary SkPaths. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/path_win.cc ('k') | ui/ui_unittests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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_win.h"
6
7 #include <algorithm>
8 #include <vector>
9
10 #include "base/logging.h"
11 #include "base/win/scoped_gdi_object.h"
12 #include "skia/ext/skia_utils_win.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/skia/include/core/SkPath.h"
15 #include "third_party/skia/include/core/SkRegion.h"
16
17 namespace gfx {
18 namespace {
19
20 std::vector<SkIRect> GetRectsFromHRGN(HRGN region) {
21 // Determine the size of output buffer required to receive the region.
22 DWORD bytes_size = GetRegionData(region, 0, NULL);
23 CHECK(bytes_size != 0);
24
25 // Fetch the Windows RECTs that comprise the region.
26 std::vector<char> buffer(bytes_size);;
27 LPRGNDATA region_data = reinterpret_cast<LPRGNDATA>(buffer.data());
28 DWORD result = GetRegionData(region, bytes_size, region_data);
29 CHECK(result == bytes_size);
30
31 // Pull out the rectangles into a SkIRect vector to pass to setRects().
32 const LPRECT rects = reinterpret_cast<LPRECT>(&region_data->Buffer[0]);
33 std::vector<SkIRect> sk_rects(region_data->rdh.nCount);
34 std::transform(rects, rects + region_data->rdh.nCount,
35 sk_rects.begin(), skia::RECTToSkIRect);
36
37 return sk_rects;
38 }
39
40 TEST(PathWinTest, BasicSkPathToHRGN) {
41 SkPath path;
42 path.moveTo(0.0f, 0.0f);
43 path.rLineTo(100.0f, 0.0f);
44 path.rLineTo(0.0f, 100.0f);
45 path.rLineTo(-100.0f, 0.0f);
46 path.rLineTo(0.0f, -100.0f);
47 base::win::ScopedRegion region(CreateHRGNFromSkPath(path));
48 std::vector<SkIRect> result = GetRectsFromHRGN(region);
49 EXPECT_EQ(1U, result.size());
50 EXPECT_EQ(0, result[0].left());
51 EXPECT_EQ(0, result[0].top());
52 EXPECT_EQ(100, result[0].right());
53 EXPECT_EQ(100, result[0].bottom());
54 }
55
56 TEST(PathWinTest, NonContiguousSkPathToHRGN) {
57 SkPath path;
58 path.moveTo(0.0f, 0.0f);
59 path.rLineTo(100.0f, 0.0f);
60 path.rLineTo(0.0f, 100.0f);
61 path.rLineTo(-100.0f, 0.0f);
62 path.rLineTo(0.0f, -100.0f);
63 path.moveTo(150.0f, 0.0f);
64 path.rLineTo(100.0f, 0.0f);
65 path.rLineTo(0.0f, 100.0f);
66 path.rLineTo(-100.0f, 0.0f);
67 path.rLineTo(0.0f, -100.0f);
68 base::win::ScopedRegion region(CreateHRGNFromSkPath(path));
69 std::vector<SkIRect> result = GetRectsFromHRGN(region);
70 EXPECT_EQ(2U, result.size());
71 EXPECT_EQ(0, result[0].left());
72 EXPECT_EQ(0, result[0].top());
73 EXPECT_EQ(100, result[0].right());
74 EXPECT_EQ(100, result[0].bottom());
75 EXPECT_EQ(150, result[1].left());
76 EXPECT_EQ(0, result[1].top());
77 EXPECT_EQ(250, result[1].right());
78 EXPECT_EQ(100, result[1].bottom());
79 }
80
81 } // namespace
82 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/path_win.cc ('k') | ui/ui_unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698