OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "remoting/host/differ.h" | 6 #include "remoting/host/differ.h" |
7 #include "remoting/host/differ_block.h" | 7 #include "remoting/host/differ_block.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
9 | 9 |
10 namespace remoting { | 10 namespace remoting { |
(...skipping 26 matching lines...) Expand all Loading... | |
37 memset(prev_.get(), 0, buffer_size_); | 37 memset(prev_.get(), 0, buffer_size_); |
38 | 38 |
39 curr_.reset(new uint8[buffer_size_]); | 39 curr_.reset(new uint8[buffer_size_]); |
40 memset(curr_.get(), 0, buffer_size_); | 40 memset(curr_.get(), 0, buffer_size_); |
41 } | 41 } |
42 | 42 |
43 void ClearBuffer(uint8* buffer) { | 43 void ClearBuffer(uint8* buffer) { |
44 memset(buffer, 0, buffer_size_); | 44 memset(buffer, 0, buffer_size_); |
45 } | 45 } |
46 | 46 |
47 // Here in DifferTest so that tests can access private methods of Differ. | |
48 void MarkDirtyBlocks(const void* prev_buffer, const void* curr_buffer) { | |
49 differ_->MarkDirtyBlocks(prev_buffer, curr_buffer); | |
50 } | |
51 | |
52 void MergeBlocks(SkRegion* dirty) { | |
53 differ_->MergeBlocks(dirty); | |
54 } | |
55 | |
56 // Convenience method to count rectangles in a region. | |
57 int RegionRectCount(const SkRegion& region) { | |
Wez
2011/08/08 20:49:34
SkRegion really doesn't have a method to query the
dmac
2011/08/10 20:30:36
Nope
| |
58 int count = 0; | |
59 for(SkRegion::Iterator iter(region); !iter.done(); iter.next()) { | |
60 ++count; | |
61 } | |
62 return count; | |
63 } | |
64 | |
47 // Convenience wrapper for Differ's DiffBlock that calculates the appropriate | 65 // Convenience wrapper for Differ's DiffBlock that calculates the appropriate |
48 // offset to the start of the desired block. | 66 // offset to the start of the desired block. |
49 DiffInfo DiffBlock(int block_x, int block_y) { | 67 DiffInfo DiffBlock(int block_x, int block_y) { |
50 // Offset from upper-left of buffer to upper-left of requested block. | 68 // Offset from upper-left of buffer to upper-left of requested block. |
51 int block_offset = ((block_y * stride_) + (block_x * bytes_per_pixel_)) | 69 int block_offset = ((block_y * stride_) + (block_x * bytes_per_pixel_)) |
52 * kBlockSize; | 70 * kBlockSize; |
53 return BlockDifference(prev_.get() + block_offset, | 71 return BlockDifference(prev_.get() + block_offset, |
54 curr_.get() + block_offset, | 72 curr_.get() + block_offset, |
55 stride_); | 73 stride_); |
56 } | 74 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 | 134 |
117 // Mark the range of blocks specified. | 135 // Mark the range of blocks specified. |
118 void MarkBlocks(int x_origin, int y_origin, int width, int height) { | 136 void MarkBlocks(int x_origin, int y_origin, int width, int height) { |
119 for (int y = 0; y < height; y++) { | 137 for (int y = 0; y < height; y++) { |
120 for (int x = 0; x < width; x++) { | 138 for (int x = 0; x < width; x++) { |
121 SetDiffInfo(x_origin + x, y_origin + y, 1); | 139 SetDiffInfo(x_origin + x, y_origin + y, 1); |
122 } | 140 } |
123 } | 141 } |
124 } | 142 } |
125 | 143 |
126 // Verify that the given dirty rect matches the expected |x|, |y|, |width| | 144 // Verify that the given dirty region matches the expected |x|, |y|, |width| |
127 // and |height|. | 145 // and |height|. |
128 // |x|, |y|, |width| and |height| are specified in block (not pixel) units. | 146 // |x|, |y|, |width| and |height| are specified in block (not pixel) units. |
Wez
2011/08/08 20:49:34
Update this comment, and the method name, to refle
dmac
2011/08/10 20:30:36
It is used in different ways below, but I did upda
| |
129 void CheckDirtyRect(const InvalidRects& rects, int x, int y, | 147 bool CheckDirtyRegion(const SkRegion& region, int x, int y, |
130 int width, int height) { | 148 int width, int height) { |
131 gfx::Rect r(x * kBlockSize, y * kBlockSize, | 149 SkIRect r = SkIRect::MakeXYWH(x * kBlockSize, y * kBlockSize, |
132 width * kBlockSize, height * kBlockSize); | 150 width * kBlockSize, height * kBlockSize); |
133 EXPECT_TRUE(rects.find(r) != rects.end()); | 151 bool found = false; |
152 for (SkRegion::Iterator i(region); !found && !i.done(); i.next()) { | |
153 found = (i.rect() == r); | |
154 } | |
155 return found; | |
134 } | 156 } |
135 | 157 |
136 // Mark the range of blocks specified and then verify that they are | 158 // Mark the range of blocks specified and then verify that they are |
137 // merged correctly. | 159 // merged correctly. |
138 // Only one rectangular region of blocks can be checked with this routine. | 160 // Only one rectangular region of blocks can be checked with this routine. |
139 void MarkBlocksAndCheckMerge(int x_origin, int y_origin, | 161 bool MarkBlocksAndCheckMerge(int x_origin, int y_origin, |
140 int width, int height) { | 162 int width, int height) { |
141 ClearDiffInfo(); | 163 ClearDiffInfo(); |
142 MarkBlocks(x_origin, y_origin, width, height); | 164 MarkBlocks(x_origin, y_origin, width, height); |
143 | 165 |
144 scoped_ptr<InvalidRects> dirty(new InvalidRects()); | 166 SkRegion dirty; |
145 differ_->MergeBlocks(dirty.get()); | 167 MergeBlocks(&dirty); |
146 | 168 |
147 ASSERT_EQ(1UL, dirty->size()); | 169 bool is_good = RegionRectCount(dirty) == 1; |
Wez
2011/08/08 20:49:34
Simpler to use isComplex() and get rid of RegionRe
dmac
2011/08/10 20:30:36
RegionRectCount is used elsewhere, but I did get r
| |
148 CheckDirtyRect(*dirty.get(), x_origin, y_origin, width, height); | 170 if (is_good) { |
171 is_good = CheckDirtyRegion(dirty, x_origin, y_origin, width, height); | |
172 } | |
173 return is_good; | |
149 } | 174 } |
150 | 175 |
151 // The differ class we're testing. | 176 // The differ class we're testing. |
152 scoped_ptr<Differ> differ_; | 177 scoped_ptr<Differ> differ_; |
153 | 178 |
154 // Screen/buffer info. | 179 // Screen/buffer info. |
155 int width_; | 180 int width_; |
156 int height_; | 181 int height_; |
157 int bytes_per_pixel_; | 182 int bytes_per_pixel_; |
158 int stride_; | 183 int stride_; |
(...skipping 30 matching lines...) Expand all Loading... | |
189 InitDiffer(kScreenWidth, kScreenHeight); | 214 InitDiffer(kScreenWidth, kScreenHeight); |
190 ClearDiffInfo(); | 215 ClearDiffInfo(); |
191 | 216 |
192 // Update a pixel in each block. | 217 // Update a pixel in each block. |
193 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { | 218 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { |
194 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { | 219 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { |
195 WriteBlockPixel(curr_.get(), x, y, 10, 10, 0xff00ff); | 220 WriteBlockPixel(curr_.get(), x, y, 10, 10, 0xff00ff); |
196 } | 221 } |
197 } | 222 } |
198 | 223 |
199 differ_->MarkDirtyBlocks(prev_.get(), curr_.get()); | 224 MarkDirtyBlocks(prev_.get(), curr_.get()); |
200 | 225 |
201 // Make sure each block is marked as dirty. | 226 // Make sure each block is marked as dirty. |
202 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { | 227 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { |
203 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { | 228 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { |
204 EXPECT_EQ(1, GetDiffInfo(x, y)) | 229 EXPECT_EQ(1, GetDiffInfo(x, y)) |
205 << "when x = " << x << ", and y = " << y; | 230 << "when x = " << x << ", and y = " << y; |
206 } | 231 } |
207 } | 232 } |
208 } | 233 } |
209 | 234 |
210 TEST_F(DifferTest, MarkDirtyBlocks_Sampling) { | 235 TEST_F(DifferTest, MarkDirtyBlocks_Sampling) { |
211 InitDiffer(kScreenWidth, kScreenHeight); | 236 InitDiffer(kScreenWidth, kScreenHeight); |
212 ClearDiffInfo(); | 237 ClearDiffInfo(); |
213 | 238 |
214 // Update some pixels in image. | 239 // Update some pixels in image. |
215 WriteBlockPixel(curr_.get(), 1, 0, 10, 10, 0xff00ff); | 240 WriteBlockPixel(curr_.get(), 1, 0, 10, 10, 0xff00ff); |
216 WriteBlockPixel(curr_.get(), 2, 1, 10, 10, 0xff00ff); | 241 WriteBlockPixel(curr_.get(), 2, 1, 10, 10, 0xff00ff); |
217 WriteBlockPixel(curr_.get(), 0, 2, 10, 10, 0xff00ff); | 242 WriteBlockPixel(curr_.get(), 0, 2, 10, 10, 0xff00ff); |
218 | 243 |
219 differ_->MarkDirtyBlocks(prev_.get(), curr_.get()); | 244 MarkDirtyBlocks(prev_.get(), curr_.get()); |
220 | 245 |
221 // Make sure corresponding blocks are updated. | 246 // Make sure corresponding blocks are updated. |
222 EXPECT_EQ(0, GetDiffInfo(0, 0)); | 247 EXPECT_EQ(0, GetDiffInfo(0, 0)); |
223 EXPECT_EQ(0, GetDiffInfo(0, 1)); | 248 EXPECT_EQ(0, GetDiffInfo(0, 1)); |
224 EXPECT_EQ(1, GetDiffInfo(0, 2)); | 249 EXPECT_EQ(1, GetDiffInfo(0, 2)); |
225 EXPECT_EQ(1, GetDiffInfo(1, 0)); | 250 EXPECT_EQ(1, GetDiffInfo(1, 0)); |
226 EXPECT_EQ(0, GetDiffInfo(1, 1)); | 251 EXPECT_EQ(0, GetDiffInfo(1, 1)); |
227 EXPECT_EQ(0, GetDiffInfo(1, 2)); | 252 EXPECT_EQ(0, GetDiffInfo(1, 2)); |
228 EXPECT_EQ(0, GetDiffInfo(2, 0)); | 253 EXPECT_EQ(0, GetDiffInfo(2, 0)); |
229 EXPECT_EQ(1, GetDiffInfo(2, 1)); | 254 EXPECT_EQ(1, GetDiffInfo(2, 1)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 InitDiffer(kPartialScreenWidth, kPartialScreenHeight); | 302 InitDiffer(kPartialScreenWidth, kPartialScreenHeight); |
278 ClearDiffInfo(); | 303 ClearDiffInfo(); |
279 | 304 |
280 // Update the first pixel in each block. | 305 // Update the first pixel in each block. |
281 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { | 306 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { |
282 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { | 307 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { |
283 WriteBlockPixel(curr_.get(), x, y, 0, 0, 0xff00ff); | 308 WriteBlockPixel(curr_.get(), x, y, 0, 0, 0xff00ff); |
284 } | 309 } |
285 } | 310 } |
286 | 311 |
287 differ_->MarkDirtyBlocks(prev_.get(), curr_.get()); | 312 MarkDirtyBlocks(prev_.get(), curr_.get()); |
288 | 313 |
289 // Make sure each block is marked as dirty. | 314 // Make sure each block is marked as dirty. |
290 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { | 315 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { |
291 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { | 316 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { |
292 EXPECT_EQ(1, GetDiffInfo(x, y)) | 317 EXPECT_EQ(1, GetDiffInfo(x, y)) |
293 << "when x = " << x << ", and y = " << y; | 318 << "when x = " << x << ", and y = " << y; |
294 } | 319 } |
295 } | 320 } |
296 } | 321 } |
297 | 322 |
298 TEST_F(DifferTest, Partial_BorderPixel) { | 323 TEST_F(DifferTest, Partial_BorderPixel) { |
299 InitDiffer(kPartialScreenWidth, kPartialScreenHeight); | 324 InitDiffer(kPartialScreenWidth, kPartialScreenHeight); |
300 ClearDiffInfo(); | 325 ClearDiffInfo(); |
301 | 326 |
302 // Update the right/bottom border pixels. | 327 // Update the right/bottom border pixels. |
303 for (int y = 0; y < height_; y++) { | 328 for (int y = 0; y < height_; y++) { |
304 WritePixel(curr_.get(), width_ - 1, y, 0xff00ff); | 329 WritePixel(curr_.get(), width_ - 1, y, 0xff00ff); |
305 } | 330 } |
306 for (int x = 0; x < width_; x++) { | 331 for (int x = 0; x < width_; x++) { |
307 WritePixel(curr_.get(), x, height_ - 1, 0xff00ff); | 332 WritePixel(curr_.get(), x, height_ - 1, 0xff00ff); |
308 } | 333 } |
309 | 334 |
310 differ_->MarkDirtyBlocks(prev_.get(), curr_.get()); | 335 MarkDirtyBlocks(prev_.get(), curr_.get()); |
311 | 336 |
312 // Make sure last (partial) block in each row/column is marked as dirty. | 337 // Make sure last (partial) block in each row/column is marked as dirty. |
313 int x_last = GetDiffInfoWidth() - 2; | 338 int x_last = GetDiffInfoWidth() - 2; |
314 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { | 339 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { |
315 EXPECT_EQ(1, GetDiffInfo(x_last, y)) | 340 EXPECT_EQ(1, GetDiffInfo(x_last, y)) |
316 << "when x = " << x_last << ", and y = " << y; | 341 << "when x = " << x_last << ", and y = " << y; |
317 } | 342 } |
318 int y_last = GetDiffInfoHeight() - 2; | 343 int y_last = GetDiffInfoHeight() - 2; |
319 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { | 344 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { |
320 EXPECT_EQ(1, GetDiffInfo(x, y_last)) | 345 EXPECT_EQ(1, GetDiffInfo(x, y_last)) |
(...skipping 15 matching lines...) Expand all Loading... | |
336 // | | | | _ | | 361 // | | | | _ | |
337 // +---+---+---+---+ | 362 // +---+---+---+---+ |
338 // | | | | _ | | 363 // | | | | _ | |
339 // +---+---+---+---+ | 364 // +---+---+---+---+ |
340 // | | | | _ | | 365 // | | | | _ | |
341 // +---+---+---+---+ | 366 // +---+---+---+---+ |
342 // | _ | _ | _ | _ | | 367 // | _ | _ | _ | _ | |
343 // +---+---+---+---+ | 368 // +---+---+---+---+ |
344 ClearDiffInfo(); | 369 ClearDiffInfo(); |
345 | 370 |
346 scoped_ptr<InvalidRects> dirty(new InvalidRects()); | 371 SkRegion dirty; |
347 differ_->MergeBlocks(dirty.get()); | 372 MergeBlocks(&dirty); |
348 | 373 |
349 EXPECT_EQ(0UL, dirty->size()); | 374 EXPECT_EQ(0, RegionRectCount(dirty)); |
Wez
2011/08/08 20:49:34
EXPECT_TRUE(dirty.isEmpty());
dmac
2011/08/10 20:30:36
Done.
| |
350 } | 375 } |
351 | 376 |
352 TEST_F(DifferTest, MergeBlocks_SingleBlock) { | 377 TEST_F(DifferTest, MergeBlocks_SingleBlock) { |
353 InitDiffer(kScreenWidth, kScreenHeight); | 378 InitDiffer(kScreenWidth, kScreenHeight); |
354 // Mark a single block and make sure that there is a single merged | 379 // Mark a single block and make sure that there is a single merged |
355 // rect with the correct bounds. | 380 // rect with the correct bounds. |
356 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { | 381 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { |
357 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { | 382 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { |
358 MarkBlocksAndCheckMerge(x, y, 1, 1); | 383 ASSERT_TRUE(MarkBlocksAndCheckMerge(x, y, 1, 1)) << "x: " << x |
384 << "y: " << y; | |
359 } | 385 } |
360 } | 386 } |
361 } | 387 } |
362 | 388 |
363 TEST_F(DifferTest, MergeBlocks_BlockRow) { | 389 TEST_F(DifferTest, MergeBlocks_BlockRow) { |
364 InitDiffer(kScreenWidth, kScreenHeight); | 390 InitDiffer(kScreenWidth, kScreenHeight); |
365 | 391 |
366 // +---+---+---+---+ | 392 // +---+---+---+---+ |
367 // | X | X | | _ | | 393 // | X | X | | _ | |
368 // +---+---+---+---+ | 394 // +---+---+---+---+ |
369 // | | | | _ | | 395 // | | | | _ | |
370 // +---+---+---+---+ | 396 // +---+---+---+---+ |
371 // | | | | _ | | 397 // | | | | _ | |
372 // +---+---+---+---+ | 398 // +---+---+---+---+ |
373 // | _ | _ | _ | _ | | 399 // | _ | _ | _ | _ | |
374 // +---+---+---+---+ | 400 // +---+---+---+---+ |
375 MarkBlocksAndCheckMerge(0, 0, 2, 1); | 401 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 0, 2, 1)); |
376 | 402 |
377 // +---+---+---+---+ | 403 // +---+---+---+---+ |
378 // | | | | _ | | 404 // | | | | _ | |
379 // +---+---+---+---+ | 405 // +---+---+---+---+ |
380 // | X | X | X | _ | | 406 // | X | X | X | _ | |
381 // +---+---+---+---+ | 407 // +---+---+---+---+ |
382 // | | | | _ | | 408 // | | | | _ | |
383 // +---+---+---+---+ | 409 // +---+---+---+---+ |
384 // | _ | _ | _ | _ | | 410 // | _ | _ | _ | _ | |
385 // +---+---+---+---+ | 411 // +---+---+---+---+ |
386 MarkBlocksAndCheckMerge(0, 1, 3, 1); | 412 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 1, 3, 1)); |
387 | 413 |
388 // +---+---+---+---+ | 414 // +---+---+---+---+ |
389 // | | | | _ | | 415 // | | | | _ | |
390 // +---+---+---+---+ | 416 // +---+---+---+---+ |
391 // | | | | _ | | 417 // | | | | _ | |
392 // +---+---+---+---+ | 418 // +---+---+---+---+ |
393 // | | X | X | _ | | 419 // | | X | X | _ | |
394 // +---+---+---+---+ | 420 // +---+---+---+---+ |
395 // | _ | _ | _ | _ | | 421 // | _ | _ | _ | _ | |
396 // +---+---+---+---+ | 422 // +---+---+---+---+ |
397 MarkBlocksAndCheckMerge(1, 2, 2, 1); | 423 ASSERT_TRUE(MarkBlocksAndCheckMerge(1, 2, 2, 1)); |
398 } | 424 } |
399 | 425 |
400 TEST_F(DifferTest, MergeBlocks_BlockColumn) { | 426 TEST_F(DifferTest, MergeBlocks_BlockColumn) { |
401 InitDiffer(kScreenWidth, kScreenHeight); | 427 InitDiffer(kScreenWidth, kScreenHeight); |
402 | 428 |
403 // +---+---+---+---+ | 429 // +---+---+---+---+ |
404 // | X | | | _ | | 430 // | X | | | _ | |
405 // +---+---+---+---+ | 431 // +---+---+---+---+ |
406 // | X | | | _ | | 432 // | X | | | _ | |
407 // +---+---+---+---+ | 433 // +---+---+---+---+ |
408 // | | | | _ | | 434 // | | | | _ | |
409 // +---+---+---+---+ | 435 // +---+---+---+---+ |
410 // | _ | _ | _ | _ | | 436 // | _ | _ | _ | _ | |
411 // +---+---+---+---+ | 437 // +---+---+---+---+ |
412 MarkBlocksAndCheckMerge(0, 0, 1, 2); | 438 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 0, 1, 2)); |
413 | 439 |
414 // +---+---+---+---+ | 440 // +---+---+---+---+ |
415 // | | | | _ | | 441 // | | | | _ | |
416 // +---+---+---+---+ | 442 // +---+---+---+---+ |
417 // | | X | | _ | | 443 // | | X | | _ | |
418 // +---+---+---+---+ | 444 // +---+---+---+---+ |
419 // | | X | | _ | | 445 // | | X | | _ | |
420 // +---+---+---+---+ | 446 // +---+---+---+---+ |
421 // | _ | _ | _ | _ | | 447 // | _ | _ | _ | _ | |
422 // +---+---+---+---+ | 448 // +---+---+---+---+ |
423 MarkBlocksAndCheckMerge(1, 1, 1, 2); | 449 ASSERT_TRUE(MarkBlocksAndCheckMerge(1, 1, 1, 2)); |
424 | 450 |
425 // +---+---+---+---+ | 451 // +---+---+---+---+ |
426 // | | | X | _ | | 452 // | | | X | _ | |
427 // +---+---+---+---+ | 453 // +---+---+---+---+ |
428 // | | | X | _ | | 454 // | | | X | _ | |
429 // +---+---+---+---+ | 455 // +---+---+---+---+ |
430 // | | | X | _ | | 456 // | | | X | _ | |
431 // +---+---+---+---+ | 457 // +---+---+---+---+ |
432 // | _ | _ | _ | _ | | 458 // | _ | _ | _ | _ | |
433 // +---+---+---+---+ | 459 // +---+---+---+---+ |
434 MarkBlocksAndCheckMerge(2, 0, 1, 3); | 460 ASSERT_TRUE(MarkBlocksAndCheckMerge(2, 0, 1, 3)); |
435 } | 461 } |
436 | 462 |
437 TEST_F(DifferTest, MergeBlocks_BlockRect) { | 463 TEST_F(DifferTest, MergeBlocks_BlockRect) { |
438 InitDiffer(kScreenWidth, kScreenHeight); | 464 InitDiffer(kScreenWidth, kScreenHeight); |
439 | 465 |
440 // +---+---+---+---+ | 466 // +---+---+---+---+ |
441 // | X | X | | _ | | 467 // | X | X | | _ | |
442 // +---+---+---+---+ | 468 // +---+---+---+---+ |
443 // | X | X | | _ | | 469 // | X | X | | _ | |
444 // +---+---+---+---+ | 470 // +---+---+---+---+ |
445 // | | | | _ | | 471 // | | | | _ | |
446 // +---+---+---+---+ | 472 // +---+---+---+---+ |
447 // | _ | _ | _ | _ | | 473 // | _ | _ | _ | _ | |
448 // +---+---+---+---+ | 474 // +---+---+---+---+ |
449 MarkBlocksAndCheckMerge(0, 0, 2, 2); | 475 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 0, 2, 2)); |
450 | 476 |
451 // +---+---+---+---+ | 477 // +---+---+---+---+ |
452 // | | | | _ | | 478 // | | | | _ | |
453 // +---+---+---+---+ | 479 // +---+---+---+---+ |
454 // | | X | X | _ | | 480 // | | X | X | _ | |
455 // +---+---+---+---+ | 481 // +---+---+---+---+ |
456 // | | X | X | _ | | 482 // | | X | X | _ | |
457 // +---+---+---+---+ | 483 // +---+---+---+---+ |
458 // | _ | _ | _ | _ | | 484 // | _ | _ | _ | _ | |
459 // +---+---+---+---+ | 485 // +---+---+---+---+ |
460 MarkBlocksAndCheckMerge(1, 1, 2, 2); | 486 ASSERT_TRUE(MarkBlocksAndCheckMerge(1, 1, 2, 2)); |
461 | 487 |
462 // +---+---+---+---+ | 488 // +---+---+---+---+ |
463 // | | X | X | _ | | 489 // | | X | X | _ | |
464 // +---+---+---+---+ | 490 // +---+---+---+---+ |
465 // | | X | X | _ | | 491 // | | X | X | _ | |
466 // +---+---+---+---+ | 492 // +---+---+---+---+ |
467 // | | X | X | _ | | 493 // | | X | X | _ | |
468 // +---+---+---+---+ | 494 // +---+---+---+---+ |
469 // | _ | _ | _ | _ | | 495 // | _ | _ | _ | _ | |
470 // +---+---+---+---+ | 496 // +---+---+---+---+ |
471 MarkBlocksAndCheckMerge(1, 0, 2, 3); | 497 ASSERT_TRUE(MarkBlocksAndCheckMerge(1, 0, 2, 3)); |
472 | 498 |
473 // +---+---+---+---+ | 499 // +---+---+---+---+ |
474 // | | | | _ | | 500 // | | | | _ | |
475 // +---+---+---+---+ | 501 // +---+---+---+---+ |
476 // | X | X | X | _ | | 502 // | X | X | X | _ | |
477 // +---+---+---+---+ | 503 // +---+---+---+---+ |
478 // | X | X | X | _ | | 504 // | X | X | X | _ | |
479 // +---+---+---+---+ | 505 // +---+---+---+---+ |
480 // | _ | _ | _ | _ | | 506 // | _ | _ | _ | _ | |
481 // +---+---+---+---+ | 507 // +---+---+---+---+ |
482 MarkBlocksAndCheckMerge(0, 1, 3, 2); | 508 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 1, 3, 2)); |
483 | 509 |
484 // +---+---+---+---+ | 510 // +---+---+---+---+ |
485 // | X | X | X | _ | | 511 // | X | X | X | _ | |
486 // +---+---+---+---+ | 512 // +---+---+---+---+ |
487 // | X | X | X | _ | | 513 // | X | X | X | _ | |
488 // +---+---+---+---+ | 514 // +---+---+---+---+ |
489 // | X | X | X | _ | | 515 // | X | X | X | _ | |
490 // +---+---+---+---+ | 516 // +---+---+---+---+ |
491 // | _ | _ | _ | _ | | 517 // | _ | _ | _ | _ | |
492 // +---+---+---+---+ | 518 // +---+---+---+---+ |
493 MarkBlocksAndCheckMerge(0, 0, 3, 3); | 519 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 0, 3, 3)); |
494 } | 520 } |
495 | 521 |
496 // This tests marked regions that require more than 1 single dirty rect. | 522 // This tests marked regions that require more than 1 single dirty rect. |
497 // The exact rects returned depend on the current implementation, so these | 523 // The exact rects returned depend on the current implementation, so these |
498 // may need to be updated if we modify how we merge blocks. | 524 // may need to be updated if we modify how we merge blocks. |
499 TEST_F(DifferTest, MergeBlocks_MultiRect) { | 525 TEST_F(DifferTest, MergeBlocks_MultiRect) { |
500 InitDiffer(kScreenWidth, kScreenHeight); | 526 InitDiffer(kScreenWidth, kScreenHeight); |
501 scoped_ptr<InvalidRects> dirty; | 527 SkRegion dirty; |
502 | 528 |
503 // +---+---+---+---+ +---+---+---+ | 529 // +---+---+---+---+ +---+---+---+ |
504 // | | X | | _ | | | 0 | | | 530 // | | X | | _ | | | 0 | | |
505 // +---+---+---+---+ +---+---+---+ | 531 // +---+---+---+---+ +---+---+---+ |
506 // | X | | | _ | | 1 | | | | 532 // | X | | | _ | | 1 | | | |
507 // +---+---+---+---+ => +---+---+---+ | 533 // +---+---+---+---+ => +---+---+---+ |
508 // | | | X | _ | | | | 2 | | 534 // | | | X | _ | | | | 2 | |
509 // +---+---+---+---+ +---+---+---+ | 535 // +---+---+---+---+ +---+---+---+ |
510 // | _ | _ | _ | _ | | 536 // | _ | _ | _ | _ | |
511 // +---+---+---+---+ | 537 // +---+---+---+---+ |
512 ClearDiffInfo(); | 538 ClearDiffInfo(); |
513 MarkBlocks(1, 0, 1, 1); | 539 MarkBlocks(1, 0, 1, 1); |
514 MarkBlocks(0, 1, 1, 1); | 540 MarkBlocks(0, 1, 1, 1); |
515 MarkBlocks(2, 2, 1, 1); | 541 MarkBlocks(2, 2, 1, 1); |
516 | 542 |
517 dirty.reset(new InvalidRects()); | 543 dirty.setEmpty(); |
518 differ_->MergeBlocks(dirty.get()); | 544 MergeBlocks(&dirty); |
519 | 545 |
520 ASSERT_EQ(3UL, dirty->size()); | 546 ASSERT_EQ(3, RegionRectCount(dirty)); |
521 CheckDirtyRect(*dirty.get(), 1, 0, 1, 1); | 547 ASSERT_TRUE(CheckDirtyRegion(dirty, 1, 0, 1, 1)); |
522 CheckDirtyRect(*dirty.get(), 0, 1, 1, 1); | 548 ASSERT_TRUE(CheckDirtyRegion(dirty, 0, 1, 1, 1)); |
523 CheckDirtyRect(*dirty.get(), 2, 2, 1, 1); | 549 ASSERT_TRUE(CheckDirtyRegion(dirty, 2, 2, 1, 1)); |
Wez
2011/08/08 20:49:34
Clearer to restructure this to iterate over dirty
dmac
2011/08/10 20:30:36
I'm going to leave as is for right now. It keeps a
| |
524 | 550 |
525 // +---+---+---+---+ +---+---+---+ | 551 // +---+---+---+---+ +---+---+---+ |
526 // | | | X | _ | | | | 0 | | 552 // | | | X | _ | | | | 0 | |
527 // +---+---+---+---+ +---+---+ + | 553 // +---+---+---+---+ +---+---+---+ |
528 // | X | X | X | _ | | 1 1 | 0 | | 554 // | X | X | X | _ | | 1 1 1 | |
529 // +---+---+---+---+ => + + + | 555 // +---+---+---+---+ => + + |
530 // | X | X | X | _ | | 1 1 | 0 | | 556 // | X | X | X | _ | | 1 1 1 | |
531 // +---+---+---+---+ +---+---+---+ | 557 // +---+---+---+---+ +---+---+---+ |
532 // | _ | _ | _ | _ | | 558 // | _ | _ | _ | _ | |
533 // +---+---+---+---+ | 559 // +---+---+---+---+ |
534 ClearDiffInfo(); | 560 ClearDiffInfo(); |
535 MarkBlocks(2, 0, 1, 3); | 561 MarkBlocks(2, 0, 1, 1); |
536 MarkBlocks(0, 1, 2, 2); | 562 MarkBlocks(0, 1, 3, 2); |
537 | 563 |
538 dirty.reset(new InvalidRects()); | 564 dirty.setEmpty(); |
539 differ_->MergeBlocks(dirty.get()); | 565 MergeBlocks(&dirty); |
540 | 566 |
541 ASSERT_EQ(2UL, dirty->size()); | 567 ASSERT_EQ(2, RegionRectCount(dirty)); |
542 CheckDirtyRect(*dirty.get(), 2, 0, 1, 3); | 568 ASSERT_TRUE(CheckDirtyRegion(dirty, 2, 0, 1, 1)); |
543 CheckDirtyRect(*dirty.get(), 0, 1, 2, 2); | 569 ASSERT_TRUE(CheckDirtyRegion(dirty, 0, 1, 3, 2)); |
544 | 570 |
545 // +---+---+---+---+ +---+---+---+ | 571 // +---+---+---+---+ +---+---+---+ |
546 // | | | | _ | | | | | | 572 // | | | | _ | | | | | |
547 // +---+---+---+---+ +---+---+---+ | 573 // +---+---+---+---+ +---+---+---+ |
548 // | X | | X | _ | | 0 | | 1 | | 574 // | X | | X | _ | | 0 | | 1 | |
549 // +---+---+---+---+ => + +---+ + | 575 // +---+---+---+---+ => + +---+ + |
550 // | X | X | X | _ | | 0 | 2 | 1 | | 576 // | X | X | X | _ | | 2 | 2 | 2 | |
551 // +---+---+---+---+ +---+---+---+ | 577 // +---+---+---+---+ +---+---+---+ |
552 // | _ | _ | _ | _ | | 578 // | _ | _ | _ | _ | |
553 // +---+---+---+---+ | 579 // +---+---+---+---+ |
554 ClearDiffInfo(); | 580 ClearDiffInfo(); |
555 MarkBlocks(0, 1, 1, 1); | 581 MarkBlocks(0, 1, 1, 1); |
556 MarkBlocks(2, 1, 1, 1); | 582 MarkBlocks(2, 1, 1, 1); |
557 MarkBlocks(0, 2, 3, 1); | 583 MarkBlocks(0, 2, 3, 1); |
558 | 584 |
559 dirty.reset(new InvalidRects()); | 585 dirty.setEmpty(); |
560 differ_->MergeBlocks(dirty.get()); | 586 MergeBlocks(&dirty); |
561 | 587 |
562 ASSERT_EQ(3UL, dirty->size()); | 588 ASSERT_EQ(3, RegionRectCount(dirty)); |
563 CheckDirtyRect(*dirty.get(), 0, 1, 1, 2); | 589 ASSERT_TRUE(CheckDirtyRegion(dirty, 0, 1, 1, 1)); |
564 CheckDirtyRect(*dirty.get(), 2, 1, 1, 2); | 590 ASSERT_TRUE(CheckDirtyRegion(dirty, 2, 1, 1, 1)); |
565 CheckDirtyRect(*dirty.get(), 1, 2, 1, 1); | 591 ASSERT_TRUE(CheckDirtyRegion(dirty, 0, 2, 3, 1)); |
566 | 592 |
567 // +---+---+---+---+ +---+---+---+ | 593 // +---+---+---+---+ +---+---+---+ |
568 // | X | X | X | _ | | 0 0 0 | | 594 // | X | X | X | _ | | 0 0 0 | |
569 // +---+---+---+---+ +---+---+---+ | 595 // +---+---+---+---+ +---+---+---+ |
570 // | X | | X | _ | | 1 | | 2 | | 596 // | X | | X | _ | | 1 | | 2 | |
571 // +---+---+---+---+ => + +---+ + | 597 // +---+---+---+---+ => + +---+ + |
572 // | X | X | X | _ | | 1 | 3 | 2 | | 598 // | X | X | X | _ | | 3 | 3 | 3 | |
573 // +---+---+---+---+ +---+---+---+ | 599 // +---+---+---+---+ +---+---+---+ |
574 // | _ | _ | _ | _ | | 600 // | _ | _ | _ | _ | |
575 // +---+---+---+---+ | 601 // +---+---+---+---+ |
576 ClearDiffInfo(); | 602 ClearDiffInfo(); |
577 MarkBlocks(0, 0, 3, 1); | 603 MarkBlocks(0, 0, 3, 1); |
578 MarkBlocks(0, 1, 1, 1); | 604 MarkBlocks(0, 1, 1, 1); |
579 MarkBlocks(2, 1, 1, 1); | 605 MarkBlocks(2, 1, 1, 1); |
580 MarkBlocks(0, 2, 3, 1); | 606 MarkBlocks(0, 2, 3, 1); |
581 | 607 |
582 dirty.reset(new InvalidRects()); | 608 dirty.setEmpty(); |
583 differ_->MergeBlocks(dirty.get()); | 609 MergeBlocks(&dirty); |
584 | 610 |
585 ASSERT_EQ(4UL, dirty->size()); | 611 ASSERT_EQ(4, RegionRectCount(dirty)); |
586 CheckDirtyRect(*dirty.get(), 0, 0, 3, 1); | 612 ASSERT_TRUE(CheckDirtyRegion(dirty, 0, 0, 3, 1)); |
587 CheckDirtyRect(*dirty.get(), 0, 1, 1, 2); | 613 ASSERT_TRUE(CheckDirtyRegion(dirty, 0, 1, 1, 1)); |
588 CheckDirtyRect(*dirty.get(), 2, 1, 1, 2); | 614 ASSERT_TRUE(CheckDirtyRegion(dirty, 2, 1, 1, 1)); |
589 CheckDirtyRect(*dirty.get(), 1, 2, 1, 1); | 615 ASSERT_TRUE(CheckDirtyRegion(dirty, 0, 2, 3, 1)); |
590 | 616 |
591 // +---+---+---+---+ +---+---+---+ | 617 // +---+---+---+---+ +---+---+---+ |
592 // | X | X | | _ | | 0 0 | | | 618 // | X | X | | _ | | 0 0 | | |
593 // +---+---+---+---+ + +---+ | 619 // +---+---+---+---+ + +---+ |
594 // | X | X | | _ | | 0 0 | | | 620 // | X | X | | _ | | 0 0 | | |
595 // +---+---+---+---+ => +---+---+---+ | 621 // +---+---+---+---+ => +---+---+---+ |
596 // | | X | | _ | | | 1 | | | 622 // | | X | | _ | | | 1 | | |
597 // +---+---+---+---+ +---+---+---+ | 623 // +---+---+---+---+ +---+---+---+ |
598 // | _ | _ | _ | _ | | 624 // | _ | _ | _ | _ | |
599 // +---+---+---+---+ | 625 // +---+---+---+---+ |
600 ClearDiffInfo(); | 626 ClearDiffInfo(); |
601 MarkBlocks(0, 0, 2, 2); | 627 MarkBlocks(0, 0, 2, 2); |
602 MarkBlocks(1, 2, 1, 1); | 628 MarkBlocks(1, 2, 1, 1); |
603 | 629 |
604 dirty.reset(new InvalidRects()); | 630 dirty.setEmpty(); |
605 differ_->MergeBlocks(dirty.get()); | 631 MergeBlocks(&dirty); |
606 | 632 |
607 ASSERT_EQ(2UL, dirty->size()); | 633 ASSERT_EQ(2, RegionRectCount(dirty)); |
608 CheckDirtyRect(*dirty.get(), 0, 0, 2, 2); | 634 ASSERT_TRUE(CheckDirtyRegion(dirty, 0, 0, 2, 2)); |
609 CheckDirtyRect(*dirty.get(), 1, 2, 1, 1); | 635 ASSERT_TRUE(CheckDirtyRegion(dirty, 1, 2, 1, 1)); |
610 } | 636 } |
611 | 637 |
612 } // namespace remoting | 638 } // namespace remoting |
OLD | NEW |