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

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

Issue 673623002: Fix regions generation on windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix review issues. Created 6 years, 1 month 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
« no previous file with comments | « ui/gfx/path_win.cc ('k') | ui/views/win/hwnd_message_handler.cc » ('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 2014 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 "base/win/scoped_gdi_object.h"
6 #include "skia/ext/skia_utils_win.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/skia/include/core/SkRRect.h"
9 #include "ui/gfx/path.h"
10 #include "ui/gfx/path_win.h"
Alexei Svitkine (slow) 2014/10/28 13:21:02 Nit: This should be first include followed by an e
alex-ac 2014/10/28 13:32:57 Done.
11
12 namespace {
13
14 std::vector<SkIRect> GetRectsFromHRGN(HRGN region) {
Alexei Svitkine (slow) 2014/10/28 13:21:02 Add a comment explaining what this method does.
alex-ac 2014/10/28 13:32:57 Done.
15 // Determine the size of output buffer required to receive the region.
16 DWORD bytes_size = GetRegionData(region, 0, NULL);
17 CHECK_NE(0, bytes_size);
18
19 // Fetch the Windows RECTs that comprise the region.
20 std::vector<char> buffer(bytes_size);
21 LPRGNDATA region_data = reinterpret_cast<LPRGNDATA>(buffer.data());
22 DWORD result = GetRegionData(region, bytes_size, region_data);
23 CHECK_EQ(bytes_size, result);
24
25 // Pull out the rectangles into a SkIRect vector to return to caller.
26 const LPRECT rects = reinterpret_cast<LPRECT>(&region_data->Buffer[0]);
27 std::vector<SkIRect> sk_rects(region_data->rdh.nCount);
28 std::transform(rects, rects + region_data->rdh.nCount,
Alexei Svitkine (slow) 2014/10/28 13:21:02 Nit: Please run git cl lint and include the std li
alex-ac 2014/10/28 13:32:57 Done.
29 sk_rects.begin(), skia::RECTToSkIRect);
30
31 return sk_rects;
32 }
33
34 } // namespace
35
36 // Test that rectangle with round corners stil has round corners after
37 // converting from SkPath to the HRGN.
38 TEST(CreateHRGNFromSkPathTest, RoundCornerTest) {
39 const SkIRect rects[] = {
40 { 17, 0, 33, 1},
41 { 12, 1, 38, 2},
42 { 11, 2, 39, 3},
43 { 9, 3, 41, 4},
44 { 8, 4, 42, 5},
45 { 6, 5, 44, 6},
46 { 5, 6, 45, 8},
47 { 4, 8, 46, 9},
48 { 3, 9, 47, 11},
49 { 2, 11, 48, 12},
50 { 1, 12, 49, 17},
51 { 0, 17, 50, 33},
52 { 1, 33, 49, 38},
53 { 2, 38, 48, 39},
54 { 3, 39, 47, 41},
55 { 4, 41, 46, 42},
56 { 5, 42, 45, 44},
57 { 6, 44, 44, 45},
58 { 8, 45, 42, 46},
59 { 9, 46, 41, 47},
60 { 11, 47, 39, 48},
61 { 12, 48, 38, 49},
62 { 17, 49, 33, 50},
63 };
64
65 gfx::Path path;
66 SkRRect rrect;
67 rrect.setRectXY(SkRect::MakeWH(50, 50), 20, 20);
68 path.addRRect(rrect);
69 base::win::ScopedRegion region(gfx::CreateHRGNFromSkPath(path));
70 const std::vector<SkIRect>& region_rects = GetRectsFromHRGN(region);
71 EXPECT_EQ(arraysize(rects), region_rects.size());
72 for (size_t i = 0; i < arraysize(rects) && i < region_rects.size(); ++i)
73 EXPECT_EQ(rects[i], region_rects[i]);
74 }
75
76 // Check that a path enclosing two non-adjacent areas is correctly translated
77 // to a non-contiguous region.
78 TEST(CreateHRGNFromSkPathTest, NonContiguousPath) {
79 const SkIRect rects[] = {
80 { 0, 0, 50, 50},
81 { 100, 100, 150, 150},
82 };
83
84 gfx::Path path;
Alexei Svitkine (slow) 2014/10/28 13:21:02 Put the test inside the gfx namespace and remove t
alex-ac 2014/10/28 13:32:57 Done.
85 for (const SkIRect& rect : rects) {
86 path.addRect(SkRect::Make(rect));
87 }
88 base::win::ScopedRegion region(gfx::CreateHRGNFromSkPath(path));
89 const std::vector<SkIRect>& region_rects = GetRectsFromHRGN(region);
90 EXPECT_EQ(arraysize(rects), region_rects.size());
91 for (size_t i = 0; i < arraysize(rects) && i < region_rects.size(); ++i)
Alexei Svitkine (slow) 2014/10/28 13:21:02 Nit: Change the EXPECT_EQ above to ASSERT_EQ and t
alex-ac 2014/10/28 13:32:57 Done.
92 EXPECT_EQ(rects[i], region_rects[i]);
93 }
94
95 // Check that empty region is returned for empty path.
96 TEST(CreateHRGNFromSkPathTest, EmptyPath) {
97 gfx::Path path;
98 base::win::ScopedRegion empty_region(::CreateRectRgn(0, 0, 0, 0));
99 base::win::ScopedRegion region(gfx::CreateHRGNFromSkPath(path));
100 EXPECT_TRUE(::EqualRgn(empty_region, region));
101 }
102
OLDNEW
« no previous file with comments | « ui/gfx/path_win.cc ('k') | ui/views/win/hwnd_message_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698