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

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 build. 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 "ui/gfx/path_win.h"
6
7 #include <algorithm>
8 #include <vector>
9
10 #include "base/win/scoped_gdi_object.h"
11 #include "skia/ext/skia_utils_win.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/skia/include/core/SkRRect.h"
14 #include "ui/gfx/path.h"
15
16 namespace gfx {
17
18 namespace {
19
20 // Get rectangles from the |region| and convert them to SkIRect.
21 std::vector<SkIRect> GetRectsFromHRGN(HRGN region) {
22 // Determine the size of output buffer required to receive the region.
23 DWORD bytes_size = GetRegionData(region, 0, NULL);
24 CHECK_NE((DWORD)0, bytes_size);
25
26 // Fetch the Windows RECTs that comprise the region.
27 std::vector<char> buffer(bytes_size);
28 LPRGNDATA region_data = reinterpret_cast<LPRGNDATA>(buffer.data());
29 DWORD result = GetRegionData(region, bytes_size, region_data);
30 CHECK_EQ(bytes_size, result);
31
32 // Pull out the rectangles into a SkIRect vector to return to caller.
33 const LPRECT rects = reinterpret_cast<LPRECT>(&region_data->Buffer[0]);
34 std::vector<SkIRect> sk_rects(region_data->rdh.nCount);
35 std::transform(rects, rects + region_data->rdh.nCount,
36 sk_rects.begin(), skia::RECTToSkIRect);
37
38 return sk_rects;
39 }
40
41 } // namespace
42
43 // Test that rectangle with round corners stil has round corners after
44 // converting from SkPath to the HRGN.
45 TEST(CreateHRGNFromSkPathTest, RoundCornerTest) {
46 const SkIRect rects[] = {
47 { 17, 0, 33, 1},
48 { 12, 1, 38, 2},
49 { 11, 2, 39, 3},
50 { 9, 3, 41, 4},
51 { 8, 4, 42, 5},
52 { 6, 5, 44, 6},
53 { 5, 6, 45, 8},
54 { 4, 8, 46, 9},
55 { 3, 9, 47, 11},
56 { 2, 11, 48, 12},
57 { 1, 12, 49, 17},
58 { 0, 17, 50, 33},
59 { 1, 33, 49, 38},
60 { 2, 38, 48, 39},
61 { 3, 39, 47, 41},
62 { 4, 41, 46, 42},
63 { 5, 42, 45, 44},
64 { 6, 44, 44, 45},
65 { 8, 45, 42, 46},
66 { 9, 46, 41, 47},
67 { 11, 47, 39, 48},
68 { 12, 48, 38, 49},
69 { 17, 49, 33, 50},
70 };
71
72 Path path;
73 SkRRect rrect;
74 rrect.setRectXY(SkRect::MakeWH(50, 50), 20, 20);
75 path.addRRect(rrect);
76 base::win::ScopedRegion region(CreateHRGNFromSkPath(path));
77 const std::vector<SkIRect>& region_rects = GetRectsFromHRGN(region);
78 EXPECT_EQ(arraysize(rects), region_rects.size());
79 for (size_t i = 0; i < arraysize(rects) && i < region_rects.size(); ++i)
80 EXPECT_EQ(rects[i], region_rects[i]);
81 }
82
83 // Check that a path enclosing two non-adjacent areas is correctly translated
84 // to a non-contiguous region.
85 TEST(CreateHRGNFromSkPathTest, NonContiguousPath) {
86 const SkIRect rects[] = {
87 { 0, 0, 50, 50},
88 { 100, 100, 150, 150},
89 };
90
91 Path path;
92 for (const SkIRect& rect : rects) {
93 path.addRect(SkRect::Make(rect));
94 }
95 base::win::ScopedRegion region(CreateHRGNFromSkPath(path));
96 const std::vector<SkIRect>& region_rects = GetRectsFromHRGN(region);
97 ASSERT_EQ(arraysize(rects), region_rects.size());
98 for (size_t i = 0; i < arraysize(rects); ++i)
99 EXPECT_EQ(rects[i], region_rects[i]);
100 }
101
102 // Check that empty region is returned for empty path.
103 TEST(CreateHRGNFromSkPathTest, EmptyPath) {
104 Path path;
105 base::win::ScopedRegion empty_region(::CreateRectRgn(0, 0, 0, 0));
106 base::win::ScopedRegion region(CreateHRGNFromSkPath(path));
107 EXPECT_TRUE(::EqualRgn(empty_region, region));
108 }
109
110 } // namespace gfx
111
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