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

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: Add more tests. Fix windows without mask. Created 6 years, 2 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
« no previous file with comments | « ui/gfx/path_win.cc ('k') | no next file » | 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 // Copyright (c) 2014 Yandex LLC. All rights reserved.
5 // Author: Aleksandr Derbenev <alex-ac@yandex-team.ru>
Wez 2014/10/23 18:50:05 You'll need to remove this, since you're contribut
alex-ac 2014/10/24 07:05:11 Sorry, It's a copy-paste artifact.
6
7 #include "base/win/scoped_gdi_object.h"
8 #include "skia/ext/skia_utils_win.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/skia/include/core/SkRRect.h"
11 #include "ui/gfx/path.h"
12 #include "ui/gfx/path_win.h"
13
14 namespace {
15
16 std::vector<SkIRect> GetRectsFromHRGN(HRGN region) {
Wez 2014/10/23 18:50:05 nit: for readability, suggest blank line between t
alex-ac 2014/10/24 07:05:11 Done.
17 // Determine the size of output buffer required to receive the region.
18 DWORD bytes_size = GetRegionData(region, 0, NULL);
19 CHECK(bytes_size != 0);
Wez 2014/10/23 18:50:05 CHECK_NE, here and below.
alex-ac 2014/10/24 07:05:11 Done.
20 // Fetch the Windows RECTs that comprise the region.
21 std::vector<char> buffer(bytes_size);;
Wez 2014/10/23 18:50:05 nit: duplicate ;
alex-ac 2014/10/24 07:05:10 Done.
22 LPRGNDATA region_data = reinterpret_cast<LPRGNDATA>(buffer.data());
23 DWORD result = GetRegionData(region, bytes_size, region_data);
24 CHECK(result == bytes_size);
25 // Pull out the rectangles into a SkIRect vector to pass to setRects().
Wez 2014/10/23 18:50:05 nit: ... to return to caller.
alex-ac 2014/10/24 07:05:10 Done.
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,
Wez 2014/10/23 18:50:05 nit: why not rects.begin(), rects.end()?
alex-ac 2014/10/24 07:05:10 'rects' is an array it hasn't got begin() and end(
Wez 2014/10/24 23:07:20 Acknowledged.
29 sk_rects.begin(), skia::RECTToSkIRect);
30 return sk_rects;
31 }
32
33 } // namespace
34
35 // Test that rectangle with round corners stil has _round_ corners after
Wez 2014/10/23 18:50:05 nit: why the _emphasis_ on the second round?
alex-ac 2014/10/24 07:05:11 Done.
36 // converting from SkPath to the HRGN.
37 // Old implementation of the CreateHRGNFromSkPath operates with polygons and
38 // can't make round corners.
Wez 2014/10/23 18:50:05 nit: this comment re old implementation adds nothi
alex-ac 2014/10/24 07:05:10 Done.
39 TEST(CreateHRGNFromSkPathTest, RoundCornerTest) {
40 const SkIRect rects[] = {
41 { 17, 0, 33, 1},
42 { 12, 1, 38, 2},
43 { 11, 2, 39, 3},
44 { 9, 3, 41, 4},
45 { 8, 4, 42, 5},
46 { 6, 5, 44, 6},
47 { 5, 6, 45, 8},
48 { 4, 8, 46, 9},
49 { 3, 9, 47, 11},
50 { 2, 11, 48, 12},
51 { 1, 12, 49, 17},
52 { 0, 17, 50, 33},
53 { 1, 33, 49, 38},
54 { 2, 38, 48, 39},
55 { 3, 39, 47, 41},
56 { 4, 41, 46, 42},
57 { 5, 42, 45, 44},
58 { 6, 44, 44, 45},
59 { 8, 45, 42, 46},
60 { 9, 46, 41, 47},
61 { 11, 47, 39, 48},
62 { 12, 48, 38, 49},
63 { 17, 49, 33, 50},
64 };
65
66 gfx::Path path;
67 SkRRect rrect;
68 rrect.setRectXY(SkRect::MakeWH(50, 50), 20, 20);
69 path.addRRect(rrect);
70 base::win::ScopedRegion region(gfx::CreateHRGNFromSkPath(path));
71 const std::vector<SkIRect>& region_rects = GetRectsFromHRGN(region);
72 EXPECT_EQ(arraysize(rects), region_rects.size());
73 for (size_t i = 0; i < arraysize(rects) && i < region_rects.size(); ++i)
74 EXPECT_EQ(rects[i], region_rects[i]);
75 }
76
77 TEST(CreateHRGNFromSkPathTest, NonContiguousPath) {
Wez 2014/10/23 18:50:05 nit: Include a one-line comment to explain what th
alex-ac 2014/10/24 07:05:10 Done.
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 TEST(CreateHRGNFromSkPathTest, EmptyPath) {
95 gfx::Path path;
96 EXPECT_EQ(NULL, gfx::CreateHRGNFromSkPath(path));
Wez 2014/10/23 18:50:05 This test is wrong; an empty path should return a
alex-ac 2014/10/24 07:05:10 There are many NonClientFrameView implementations
Wez 2014/10/24 23:07:20 There are only actually four calls to the API, tho
97 }
98
OLDNEW
« no previous file with comments | « ui/gfx/path_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698