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

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: CreateHRGNFromSkPath can return empty region now. 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
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"
11
12 namespace {
13
14 std::vector<SkIRect> GetRectsFromHRGN(HRGN region) {
15
Wez 2014/10/27 20:28:39 nit: no need for this blank line
alex-ac 2014/10/28 10:38:35 Done.
16 // Determine the size of output buffer required to receive the region.
17 DWORD bytes_size = GetRegionData(region, 0, NULL);
18 CHECK_NE(0, bytes_size);
19
20 // Fetch the Windows RECTs that comprise the region.
21 std::vector<char> buffer(bytes_size);
22 LPRGNDATA region_data = reinterpret_cast<LPRGNDATA>(buffer.data());
23 DWORD result = GetRegionData(region, bytes_size, region_data);
24 CHECK_EQ(bytes_size, result);
25
26 // Pull out the rectangles into a SkIRect vector to return to caller.
27 const LPRECT rects = reinterpret_cast<LPRECT>(&region_data->Buffer[0]);
28 std::vector<SkIRect> sk_rects(region_data->rdh.nCount);
29 std::transform(rects, rects + region_data->rdh.nCount,
30 sk_rects.begin(), skia::RECTToSkIRect);
Wez 2014/10/27 20:28:39 nit: suggest blank line here
alex-ac 2014/10/28 10:38:35 Done.
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 non contiguous path is translated to region correctly.
Wez 2014/10/27 20:28:39 Suggest: Check that a path enclosing two non-adjac
alex-ac 2014/10/28 10:38:35 Done.
77 TEST(CreateHRGNFromSkPathTest, NonContiguousPath) {
78 const SkIRect rects[] = {
79 { 0, 0, 50, 50},
80 { 100, 100, 150, 150},
81 };
82
83 gfx::Path path;
84 for (const SkIRect& rect : rects) {
85 path.addRect(SkRect::Make(rect));
86 }
87 base::win::ScopedRegion region(gfx::CreateHRGNFromSkPath(path));
88 const std::vector<SkIRect>& region_rects = GetRectsFromHRGN(region);
89 EXPECT_EQ(arraysize(rects), region_rects.size());
90 for (size_t i = 0; i < arraysize(rects) && i < region_rects.size(); ++i)
91 EXPECT_EQ(rects[i], region_rects[i]);
92 }
93
94 // Check that empty region is returned for empty path.
95 TEST(CreateHRGNFromSkPathTest, EmptyPath) {
96 gfx::Path path;
97 base::win::ScopedRegion empty_region(::CreateRectRgn(0, 0, 0, 0));
98 base::win::ScopedRegion region(gfx::CreateHRGNFromSkPath(path));
99 EXPECT_TRUE(::EqualRgn(empty_region, region));
100 }
101
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698