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

Side by Side Diff: tests/TileGridTest.cpp

Issue 197813011: Fix result order reliance (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 9 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 | « no previous file | 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
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkTileGrid.h" 10 #include "SkTileGrid.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 SkIRect rect2 = SkIRect::MakeXYWH(11, 11, 1, 1); 57 SkIRect rect2 = SkIRect::MakeXYWH(11, 11, 1, 1);
58 SkTileGrid grid(2, 2, info, SkTileGridNextDatum<SkPictureStateTree::Draw>); 58 SkTileGrid grid(2, 2, info, SkTileGridNextDatum<SkPictureStateTree::Draw>);
59 grid.insert(&rect1, rect1, true); 59 grid.insert(&rect1, rect1, true);
60 grid.insert(&rect2, rect2, true); 60 grid.insert(&rect2, rect2, true);
61 61
62 // Test parts of top-left tile 62 // Test parts of top-left tile
63 { 63 {
64 SkTDArray<void*> rects; 64 SkTDArray<void*> rects;
65 grid.search(query(0.0f, 0.0f, 1.0f, 1.0f), &rects); 65 grid.search(query(0.0f, 0.0f, 1.0f, 1.0f), &rects);
66 REPORTER_ASSERT(reporter, 1 == rects.count()); 66 REPORTER_ASSERT(reporter, 1 == rects.count());
67 REPORTER_ASSERT(reporter, &rect1 == rects[0]); 67 REPORTER_ASSERT(reporter, rects.find(&rect1) >= 0);
68 } 68 }
69 { 69 {
70 SkTDArray<void*> rects; 70 SkTDArray<void*> rects;
71 grid.search(query(7.99f, 7.99f, 1.0f, 1.0f), &rects); 71 grid.search(query(7.99f, 7.99f, 1.0f, 1.0f), &rects);
72 REPORTER_ASSERT(reporter, 1 == rects.count()); 72 REPORTER_ASSERT(reporter, 1 == rects.count());
73 REPORTER_ASSERT(reporter, &rect1 == rects[0]); 73 REPORTER_ASSERT(reporter, rects.find(&rect1) >= 0);
74 } 74 }
75 // Corner overlap 75 // Corner overlap
76 { 76 {
77 SkTDArray<void*> rects; 77 SkTDArray<void*> rects;
78 grid.search(query(9.5f, 9.5f, 1.0f, 1.0f), &rects); 78 grid.search(query(9.5f, 9.5f, 1.0f, 1.0f), &rects);
79 REPORTER_ASSERT(reporter, 2 == rects.count()); 79 REPORTER_ASSERT(reporter, 2 == rects.count());
80 REPORTER_ASSERT(reporter, &rect1 == rects[0]); 80 REPORTER_ASSERT(reporter, rects.find(&rect1) >= 0);
81 REPORTER_ASSERT(reporter, &rect2 == rects[1]); 81 REPORTER_ASSERT(reporter, rects.find(&rect2) >= 0);
82 } 82 }
83 // Intersect bottom right tile, but does not overlap rect 2 83 // Intersect bottom right tile, but does not overlap rect 2
84 { 84 {
85 SkTDArray<void*> rects; 85 SkTDArray<void*> rects;
86 grid.search(query(16.0f, 16.0f, 1.0f, 1.0f), &rects); 86 grid.search(query(16.0f, 16.0f, 1.0f, 1.0f), &rects);
87 REPORTER_ASSERT(reporter, 1 == rects.count()); 87 REPORTER_ASSERT(reporter, 1 == rects.count());
88 REPORTER_ASSERT(reporter, &rect2 == rects[0]); 88 REPORTER_ASSERT(reporter, rects.find(&rect2) >= 0);
89 } 89 }
90 // Out of bounds queries, snap to border tiles 90 // Out of bounds queries, snap to border tiles
91 { 91 {
92 SkTDArray<void*> rects; 92 SkTDArray<void*> rects;
93 grid.search(query(-2.0f, 0.0f, 1.0f, 1.0f), &rects); 93 grid.search(query(-2.0f, 0.0f, 1.0f, 1.0f), &rects);
94 REPORTER_ASSERT(reporter, 1 == rects.count()); 94 REPORTER_ASSERT(reporter, 1 == rects.count());
95 REPORTER_ASSERT(reporter, &rect1 == rects[0]); 95 REPORTER_ASSERT(reporter, rects.find(&rect1) >= 0);
96 } 96 }
97 { 97 {
98 SkTDArray<void*> rects; 98 SkTDArray<void*> rects;
99 grid.search(query(0.0f, -2.0f, 1.0f, 1.0f), &rects); 99 grid.search(query(0.0f, -2.0f, 1.0f, 1.0f), &rects);
100 REPORTER_ASSERT(reporter, 1 == rects.count()); 100 REPORTER_ASSERT(reporter, 1 == rects.count());
101 REPORTER_ASSERT(reporter, &rect1 == rects[0]); 101 REPORTER_ASSERT(reporter, rects.find(&rect1) >= 0);
102 } 102 }
103 { 103 {
104 SkTDArray<void*> rects; 104 SkTDArray<void*> rects;
105 grid.search(query(22.0f, 16.0f, 1.0f, 1.0f), &rects); 105 grid.search(query(22.0f, 16.0f, 1.0f, 1.0f), &rects);
106 REPORTER_ASSERT(reporter, 1 == rects.count()); 106 REPORTER_ASSERT(reporter, 1 == rects.count());
107 REPORTER_ASSERT(reporter, &rect2 == rects[0]); 107 REPORTER_ASSERT(reporter, rects.find(&rect2) >= 0);
108 } 108 }
109 { 109 {
110 SkTDArray<void*> rects; 110 SkTDArray<void*> rects;
111 grid.search(query(16.0f, 22.0f, 1.0f, 1.0f), &rects); 111 grid.search(query(16.0f, 22.0f, 1.0f, 1.0f), &rects);
112 REPORTER_ASSERT(reporter, 1 == rects.count()); 112 REPORTER_ASSERT(reporter, 1 == rects.count());
113 REPORTER_ASSERT(reporter, &rect2 == rects[0]); 113 REPORTER_ASSERT(reporter, rects.find(&rect2) >= 0);
114 } 114 }
115 } 115 }
116 116
117 DEF_TEST(TileGrid_OverlapOffsetQueryAlignment, reporter) { 117 DEF_TEST(TileGrid_OverlapOffsetQueryAlignment, reporter) {
118 // Use SkTileGridPicture to generate a SkTileGrid with a helper 118 // Use SkTileGridPicture to generate a SkTileGrid with a helper
119 SkTileGridPicture::TileGridInfo info; 119 SkTileGridPicture::TileGridInfo info;
120 info.fMargin.set(1, 1); 120 info.fMargin.set(1, 1);
121 info.fOffset.set(-1, -1); 121 info.fOffset.set(-1, -1);
122 info.fTileInterval.set(8, 8); 122 info.fTileInterval.set(8, 8);
123 123
124 // rect landing entirely in top left tile 124 // rect landing entirely in top left tile
125 SkIRect rect1 = SkIRect::MakeXYWH(0, 0, 1, 1); 125 SkIRect rect1 = SkIRect::MakeXYWH(0, 0, 1, 1);
126 // rect landing entirely in center tile 126 // rect landing entirely in center tile
127 SkIRect rect2 = SkIRect::MakeXYWH(12, 12, 1, 1); 127 SkIRect rect2 = SkIRect::MakeXYWH(12, 12, 1, 1);
128 // rect landing entirely in bottomright tile 128 // rect landing entirely in bottomright tile
129 SkIRect rect3 = SkIRect::MakeXYWH(19, 19, 1, 1); 129 SkIRect rect3 = SkIRect::MakeXYWH(19, 19, 1, 1);
130 SkTileGrid grid(3, 3, info, SkTileGridNextDatum<SkPictureStateTree::Draw>); 130 SkTileGrid grid(3, 3, info, SkTileGridNextDatum<SkPictureStateTree::Draw>);
131 grid.insert(&rect1, rect1, true); 131 grid.insert(&rect1, rect1, true);
132 grid.insert(&rect2, rect2, true); 132 grid.insert(&rect2, rect2, true);
133 grid.insert(&rect3, rect3, true); 133 grid.insert(&rect3, rect3, true);
134 134
135 // Test parts of top-left tile 135 // Test parts of top-left tile
136 { 136 {
137 // The offset should cancel the top and left borders of the top left til e 137 // The offset should cancel the top and left borders of the top left til e
138 // So a look-up at interval 0-10 should be grid aligned, 138 // So a look-up at interval 0-10 should be grid aligned,
139 SkTDArray<void*> rects; 139 SkTDArray<void*> rects;
140 grid.search(query(0.0f, 0.0f, 10.0f, 10.0f), &rects); 140 grid.search(query(0.0f, 0.0f, 10.0f, 10.0f), &rects);
141 REPORTER_ASSERT(reporter, 1 == rects.count()); 141 REPORTER_ASSERT(reporter, 1 == rects.count());
142 REPORTER_ASSERT(reporter, &rect1 == rects[0]); 142 REPORTER_ASSERT(reporter, rects.find(&rect1) >= 0);
143 } 143 }
144 { 144 {
145 // Encroaching border by one pixel 145 // Encroaching border by one pixel
146 SkTDArray<void*> rects; 146 SkTDArray<void*> rects;
147 grid.search(query(0.0f, 0.0f, 11.0f, 11.0f), &rects); 147 grid.search(query(0.0f, 0.0f, 11.0f, 11.0f), &rects);
148 REPORTER_ASSERT(reporter, 2 == rects.count()); 148 REPORTER_ASSERT(reporter, 2 == rects.count());
149 REPORTER_ASSERT(reporter, &rect1 == rects[0]); 149 REPORTER_ASSERT(reporter, rects.find(&rect1) >= 0);
150 REPORTER_ASSERT(reporter, &rect2 == rects[1]); 150 REPORTER_ASSERT(reporter, rects.find(&rect2) >= 0);
151 } 151 }
152 { 152 {
153 // Tile stride is 8 (tileWidth - 2 * border pixels 153 // Tile stride is 8 (tileWidth - 2 * border pixels
154 // so translating by 8, should make query grid-aligned 154 // so translating by 8, should make query grid-aligned
155 // with middle tile. 155 // with middle tile.
156 SkTDArray<void*> rects; 156 SkTDArray<void*> rects;
157 grid.search(query(8.0f, 8.0f, 10.0f, 10.0f), &rects); 157 grid.search(query(8.0f, 8.0f, 10.0f, 10.0f), &rects);
158 REPORTER_ASSERT(reporter, 1 == rects.count()); 158 REPORTER_ASSERT(reporter, 1 == rects.count());
159 REPORTER_ASSERT(reporter, &rect2 == rects[0]); 159 REPORTER_ASSERT(reporter, rects.find(&rect2) >= 0);
160 } 160 }
161 { 161 {
162 SkTDArray<void*> rects; 162 SkTDArray<void*> rects;
163 grid.search(query(7.9f, 7.9f, 10.0f, 10.0f), &rects); 163 grid.search(query(7.9f, 7.9f, 10.0f, 10.0f), &rects);
164 REPORTER_ASSERT(reporter, 2 == rects.count()); 164 REPORTER_ASSERT(reporter, 2 == rects.count());
165 REPORTER_ASSERT(reporter, &rect1 == rects[0]); 165 REPORTER_ASSERT(reporter, rects.find(&rect1) >= 0);
166 REPORTER_ASSERT(reporter, &rect2 == rects[1]); 166 REPORTER_ASSERT(reporter, rects.find(&rect2) >= 0);
167 } 167 }
168 { 168 {
169 SkTDArray<void*> rects; 169 SkTDArray<void*> rects;
170 grid.search(query(8.1f, 8.1f, 10.0f, 10.0f), &rects); 170 grid.search(query(8.1f, 8.1f, 10.0f, 10.0f), &rects);
171 REPORTER_ASSERT(reporter, 2 == rects.count()); 171 REPORTER_ASSERT(reporter, 2 == rects.count());
172 REPORTER_ASSERT(reporter, &rect2 == rects[0]); 172 REPORTER_ASSERT(reporter, rects.find(&rect2) >= 0);
173 REPORTER_ASSERT(reporter, &rect3 == rects[1]); 173 REPORTER_ASSERT(reporter, rects.find(&rect3) >= 0);
174 } 174 }
175 { 175 {
176 // Regression test for crbug.com/234688 176 // Regression test for crbug.com/234688
177 // Once the 2x2 device region is inset by margin, it yields an empty 177 // Once the 2x2 device region is inset by margin, it yields an empty
178 // adjusted region, sitting right on top of the tile boundary. 178 // adjusted region, sitting right on top of the tile boundary.
179 SkTDArray<void*> rects; 179 SkTDArray<void*> rects;
180 grid.search(query(8.0f, 8.0f, 2.0f, 2.0f), &rects); 180 grid.search(query(8.0f, 8.0f, 2.0f, 2.0f), &rects);
181 // This test passes by not asserting. We do not validate the rects recor ded 181 // This test passes by not asserting. We do not validate the rects recor ded
182 // because the result is numerically unstable (floating point equality). 182 // because the result is numerically unstable (floating point equality).
183 // The content of any one of the four tiles of the tilegrid would be a v alid 183 // The content of any one of the four tiles of the tilegrid would be a v alid
(...skipping 23 matching lines...) Expand all
207 verifyTileHits(reporter, SkIRect::MakeXYWH(10, 10, 1, 1), kBottomRight_Tile , 1); 207 verifyTileHits(reporter, SkIRect::MakeXYWH(10, 10, 1, 1), kBottomRight_Tile , 1);
208 verifyTileHits(reporter, SkIRect::MakeXYWH(17, 17, 1, 1), kBottomRight_Tile , 1); 208 verifyTileHits(reporter, SkIRect::MakeXYWH(17, 17, 1, 1), kBottomRight_Tile , 1);
209 209
210 // BBoxes that overlap tiles 210 // BBoxes that overlap tiles
211 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 1), kTopLeft_Tile | kT opRight_Tile); 211 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 1), kTopLeft_Tile | kT opRight_Tile);
212 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 1, 10), kTopLeft_Tile | 212 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 1, 10), kTopLeft_Tile |
213 kBottomLeft_Tile); 213 kBottomLeft_Tile);
214 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 10), kAll_Tile); 214 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 10), kAll_Tile);
215 verifyTileHits(reporter, SkIRect::MakeXYWH(-10, -10, 40, 40), kAll_Tile); 215 verifyTileHits(reporter, SkIRect::MakeXYWH(-10, -10, 40, 40), kAll_Tile);
216 } 216 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698