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

Side by Side Diff: remoting/host/differ_unittest.cc

Issue 7491070: Switch over to using SkRegions to calculate dirty areas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed up shared lib compile Created 9 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/differ.cc ('k') | remoting/host/host_mock_objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) {
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
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 |region| contains a rectangle defined by |x|, |y|, |width| and
127 // and |height|. 145 // |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.
129 void CheckDirtyRect(const InvalidRects& rects, int x, int y, 147 bool CheckDirtyRegionContainsRect(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 = dirty.isRect();
148 CheckDirtyRect(*dirty.get(), x_origin, y_origin, width, height); 170 if (is_good) {
171 is_good = CheckDirtyRegionContainsRect(dirty, x_origin, y_origin,
172 width, height);
173 }
174 return is_good;
149 } 175 }
150 176
151 // The differ class we're testing. 177 // The differ class we're testing.
152 scoped_ptr<Differ> differ_; 178 scoped_ptr<Differ> differ_;
153 179
154 // Screen/buffer info. 180 // Screen/buffer info.
155 int width_; 181 int width_;
156 int height_; 182 int height_;
157 int bytes_per_pixel_; 183 int bytes_per_pixel_;
158 int stride_; 184 int stride_;
(...skipping 30 matching lines...) Expand all
189 InitDiffer(kScreenWidth, kScreenHeight); 215 InitDiffer(kScreenWidth, kScreenHeight);
190 ClearDiffInfo(); 216 ClearDiffInfo();
191 217
192 // Update a pixel in each block. 218 // Update a pixel in each block.
193 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { 219 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) {
194 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { 220 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) {
195 WriteBlockPixel(curr_.get(), x, y, 10, 10, 0xff00ff); 221 WriteBlockPixel(curr_.get(), x, y, 10, 10, 0xff00ff);
196 } 222 }
197 } 223 }
198 224
199 differ_->MarkDirtyBlocks(prev_.get(), curr_.get()); 225 MarkDirtyBlocks(prev_.get(), curr_.get());
200 226
201 // Make sure each block is marked as dirty. 227 // Make sure each block is marked as dirty.
202 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { 228 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) {
203 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { 229 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) {
204 EXPECT_EQ(1, GetDiffInfo(x, y)) 230 EXPECT_EQ(1, GetDiffInfo(x, y))
205 << "when x = " << x << ", and y = " << y; 231 << "when x = " << x << ", and y = " << y;
206 } 232 }
207 } 233 }
208 } 234 }
209 235
210 TEST_F(DifferTest, MarkDirtyBlocks_Sampling) { 236 TEST_F(DifferTest, MarkDirtyBlocks_Sampling) {
211 InitDiffer(kScreenWidth, kScreenHeight); 237 InitDiffer(kScreenWidth, kScreenHeight);
212 ClearDiffInfo(); 238 ClearDiffInfo();
213 239
214 // Update some pixels in image. 240 // Update some pixels in image.
215 WriteBlockPixel(curr_.get(), 1, 0, 10, 10, 0xff00ff); 241 WriteBlockPixel(curr_.get(), 1, 0, 10, 10, 0xff00ff);
216 WriteBlockPixel(curr_.get(), 2, 1, 10, 10, 0xff00ff); 242 WriteBlockPixel(curr_.get(), 2, 1, 10, 10, 0xff00ff);
217 WriteBlockPixel(curr_.get(), 0, 2, 10, 10, 0xff00ff); 243 WriteBlockPixel(curr_.get(), 0, 2, 10, 10, 0xff00ff);
218 244
219 differ_->MarkDirtyBlocks(prev_.get(), curr_.get()); 245 MarkDirtyBlocks(prev_.get(), curr_.get());
220 246
221 // Make sure corresponding blocks are updated. 247 // Make sure corresponding blocks are updated.
222 EXPECT_EQ(0, GetDiffInfo(0, 0)); 248 EXPECT_EQ(0, GetDiffInfo(0, 0));
223 EXPECT_EQ(0, GetDiffInfo(0, 1)); 249 EXPECT_EQ(0, GetDiffInfo(0, 1));
224 EXPECT_EQ(1, GetDiffInfo(0, 2)); 250 EXPECT_EQ(1, GetDiffInfo(0, 2));
225 EXPECT_EQ(1, GetDiffInfo(1, 0)); 251 EXPECT_EQ(1, GetDiffInfo(1, 0));
226 EXPECT_EQ(0, GetDiffInfo(1, 1)); 252 EXPECT_EQ(0, GetDiffInfo(1, 1));
227 EXPECT_EQ(0, GetDiffInfo(1, 2)); 253 EXPECT_EQ(0, GetDiffInfo(1, 2));
228 EXPECT_EQ(0, GetDiffInfo(2, 0)); 254 EXPECT_EQ(0, GetDiffInfo(2, 0));
229 EXPECT_EQ(1, GetDiffInfo(2, 1)); 255 EXPECT_EQ(1, GetDiffInfo(2, 1));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 InitDiffer(kPartialScreenWidth, kPartialScreenHeight); 303 InitDiffer(kPartialScreenWidth, kPartialScreenHeight);
278 ClearDiffInfo(); 304 ClearDiffInfo();
279 305
280 // Update the first pixel in each block. 306 // Update the first pixel in each block.
281 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { 307 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) {
282 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { 308 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) {
283 WriteBlockPixel(curr_.get(), x, y, 0, 0, 0xff00ff); 309 WriteBlockPixel(curr_.get(), x, y, 0, 0, 0xff00ff);
284 } 310 }
285 } 311 }
286 312
287 differ_->MarkDirtyBlocks(prev_.get(), curr_.get()); 313 MarkDirtyBlocks(prev_.get(), curr_.get());
288 314
289 // Make sure each block is marked as dirty. 315 // Make sure each block is marked as dirty.
290 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { 316 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) {
291 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { 317 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) {
292 EXPECT_EQ(1, GetDiffInfo(x, y)) 318 EXPECT_EQ(1, GetDiffInfo(x, y))
293 << "when x = " << x << ", and y = " << y; 319 << "when x = " << x << ", and y = " << y;
294 } 320 }
295 } 321 }
296 } 322 }
297 323
298 TEST_F(DifferTest, Partial_BorderPixel) { 324 TEST_F(DifferTest, Partial_BorderPixel) {
299 InitDiffer(kPartialScreenWidth, kPartialScreenHeight); 325 InitDiffer(kPartialScreenWidth, kPartialScreenHeight);
300 ClearDiffInfo(); 326 ClearDiffInfo();
301 327
302 // Update the right/bottom border pixels. 328 // Update the right/bottom border pixels.
303 for (int y = 0; y < height_; y++) { 329 for (int y = 0; y < height_; y++) {
304 WritePixel(curr_.get(), width_ - 1, y, 0xff00ff); 330 WritePixel(curr_.get(), width_ - 1, y, 0xff00ff);
305 } 331 }
306 for (int x = 0; x < width_; x++) { 332 for (int x = 0; x < width_; x++) {
307 WritePixel(curr_.get(), x, height_ - 1, 0xff00ff); 333 WritePixel(curr_.get(), x, height_ - 1, 0xff00ff);
308 } 334 }
309 335
310 differ_->MarkDirtyBlocks(prev_.get(), curr_.get()); 336 MarkDirtyBlocks(prev_.get(), curr_.get());
311 337
312 // Make sure last (partial) block in each row/column is marked as dirty. 338 // Make sure last (partial) block in each row/column is marked as dirty.
313 int x_last = GetDiffInfoWidth() - 2; 339 int x_last = GetDiffInfoWidth() - 2;
314 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { 340 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) {
315 EXPECT_EQ(1, GetDiffInfo(x_last, y)) 341 EXPECT_EQ(1, GetDiffInfo(x_last, y))
316 << "when x = " << x_last << ", and y = " << y; 342 << "when x = " << x_last << ", and y = " << y;
317 } 343 }
318 int y_last = GetDiffInfoHeight() - 2; 344 int y_last = GetDiffInfoHeight() - 2;
319 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { 345 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) {
320 EXPECT_EQ(1, GetDiffInfo(x, y_last)) 346 EXPECT_EQ(1, GetDiffInfo(x, y_last))
(...skipping 15 matching lines...) Expand all
336 // | | | | _ | 362 // | | | | _ |
337 // +---+---+---+---+ 363 // +---+---+---+---+
338 // | | | | _ | 364 // | | | | _ |
339 // +---+---+---+---+ 365 // +---+---+---+---+
340 // | | | | _ | 366 // | | | | _ |
341 // +---+---+---+---+ 367 // +---+---+---+---+
342 // | _ | _ | _ | _ | 368 // | _ | _ | _ | _ |
343 // +---+---+---+---+ 369 // +---+---+---+---+
344 ClearDiffInfo(); 370 ClearDiffInfo();
345 371
346 scoped_ptr<InvalidRects> dirty(new InvalidRects()); 372 SkRegion dirty;
347 differ_->MergeBlocks(dirty.get()); 373 MergeBlocks(&dirty);
348 374
349 EXPECT_EQ(0UL, dirty->size()); 375 EXPECT_TRUE(dirty.isEmpty());
350 } 376 }
351 377
352 TEST_F(DifferTest, MergeBlocks_SingleBlock) { 378 TEST_F(DifferTest, MergeBlocks_SingleBlock) {
353 InitDiffer(kScreenWidth, kScreenHeight); 379 InitDiffer(kScreenWidth, kScreenHeight);
354 // Mark a single block and make sure that there is a single merged 380 // Mark a single block and make sure that there is a single merged
355 // rect with the correct bounds. 381 // rect with the correct bounds.
356 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { 382 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) {
357 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { 383 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) {
358 MarkBlocksAndCheckMerge(x, y, 1, 1); 384 ASSERT_TRUE(MarkBlocksAndCheckMerge(x, y, 1, 1)) << "x: " << x
385 << "y: " << y;
359 } 386 }
360 } 387 }
361 } 388 }
362 389
363 TEST_F(DifferTest, MergeBlocks_BlockRow) { 390 TEST_F(DifferTest, MergeBlocks_BlockRow) {
364 InitDiffer(kScreenWidth, kScreenHeight); 391 InitDiffer(kScreenWidth, kScreenHeight);
365 392
366 // +---+---+---+---+ 393 // +---+---+---+---+
367 // | X | X | | _ | 394 // | X | X | | _ |
368 // +---+---+---+---+ 395 // +---+---+---+---+
369 // | | | | _ | 396 // | | | | _ |
370 // +---+---+---+---+ 397 // +---+---+---+---+
371 // | | | | _ | 398 // | | | | _ |
372 // +---+---+---+---+ 399 // +---+---+---+---+
373 // | _ | _ | _ | _ | 400 // | _ | _ | _ | _ |
374 // +---+---+---+---+ 401 // +---+---+---+---+
375 MarkBlocksAndCheckMerge(0, 0, 2, 1); 402 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 0, 2, 1));
376 403
377 // +---+---+---+---+ 404 // +---+---+---+---+
378 // | | | | _ | 405 // | | | | _ |
379 // +---+---+---+---+ 406 // +---+---+---+---+
380 // | X | X | X | _ | 407 // | X | X | X | _ |
381 // +---+---+---+---+ 408 // +---+---+---+---+
382 // | | | | _ | 409 // | | | | _ |
383 // +---+---+---+---+ 410 // +---+---+---+---+
384 // | _ | _ | _ | _ | 411 // | _ | _ | _ | _ |
385 // +---+---+---+---+ 412 // +---+---+---+---+
386 MarkBlocksAndCheckMerge(0, 1, 3, 1); 413 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 1, 3, 1));
387 414
388 // +---+---+---+---+ 415 // +---+---+---+---+
389 // | | | | _ | 416 // | | | | _ |
390 // +---+---+---+---+ 417 // +---+---+---+---+
391 // | | | | _ | 418 // | | | | _ |
392 // +---+---+---+---+ 419 // +---+---+---+---+
393 // | | X | X | _ | 420 // | | X | X | _ |
394 // +---+---+---+---+ 421 // +---+---+---+---+
395 // | _ | _ | _ | _ | 422 // | _ | _ | _ | _ |
396 // +---+---+---+---+ 423 // +---+---+---+---+
397 MarkBlocksAndCheckMerge(1, 2, 2, 1); 424 ASSERT_TRUE(MarkBlocksAndCheckMerge(1, 2, 2, 1));
398 } 425 }
399 426
400 TEST_F(DifferTest, MergeBlocks_BlockColumn) { 427 TEST_F(DifferTest, MergeBlocks_BlockColumn) {
401 InitDiffer(kScreenWidth, kScreenHeight); 428 InitDiffer(kScreenWidth, kScreenHeight);
402 429
403 // +---+---+---+---+ 430 // +---+---+---+---+
404 // | X | | | _ | 431 // | X | | | _ |
405 // +---+---+---+---+ 432 // +---+---+---+---+
406 // | X | | | _ | 433 // | X | | | _ |
407 // +---+---+---+---+ 434 // +---+---+---+---+
408 // | | | | _ | 435 // | | | | _ |
409 // +---+---+---+---+ 436 // +---+---+---+---+
410 // | _ | _ | _ | _ | 437 // | _ | _ | _ | _ |
411 // +---+---+---+---+ 438 // +---+---+---+---+
412 MarkBlocksAndCheckMerge(0, 0, 1, 2); 439 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 0, 1, 2));
413 440
414 // +---+---+---+---+ 441 // +---+---+---+---+
415 // | | | | _ | 442 // | | | | _ |
416 // +---+---+---+---+ 443 // +---+---+---+---+
417 // | | X | | _ | 444 // | | X | | _ |
418 // +---+---+---+---+ 445 // +---+---+---+---+
419 // | | X | | _ | 446 // | | X | | _ |
420 // +---+---+---+---+ 447 // +---+---+---+---+
421 // | _ | _ | _ | _ | 448 // | _ | _ | _ | _ |
422 // +---+---+---+---+ 449 // +---+---+---+---+
423 MarkBlocksAndCheckMerge(1, 1, 1, 2); 450 ASSERT_TRUE(MarkBlocksAndCheckMerge(1, 1, 1, 2));
424 451
425 // +---+---+---+---+ 452 // +---+---+---+---+
426 // | | | X | _ | 453 // | | | X | _ |
427 // +---+---+---+---+ 454 // +---+---+---+---+
428 // | | | X | _ | 455 // | | | X | _ |
429 // +---+---+---+---+ 456 // +---+---+---+---+
430 // | | | X | _ | 457 // | | | X | _ |
431 // +---+---+---+---+ 458 // +---+---+---+---+
432 // | _ | _ | _ | _ | 459 // | _ | _ | _ | _ |
433 // +---+---+---+---+ 460 // +---+---+---+---+
434 MarkBlocksAndCheckMerge(2, 0, 1, 3); 461 ASSERT_TRUE(MarkBlocksAndCheckMerge(2, 0, 1, 3));
435 } 462 }
436 463
437 TEST_F(DifferTest, MergeBlocks_BlockRect) { 464 TEST_F(DifferTest, MergeBlocks_BlockRect) {
438 InitDiffer(kScreenWidth, kScreenHeight); 465 InitDiffer(kScreenWidth, kScreenHeight);
439 466
440 // +---+---+---+---+ 467 // +---+---+---+---+
441 // | X | X | | _ | 468 // | X | X | | _ |
442 // +---+---+---+---+ 469 // +---+---+---+---+
443 // | X | X | | _ | 470 // | X | X | | _ |
444 // +---+---+---+---+ 471 // +---+---+---+---+
445 // | | | | _ | 472 // | | | | _ |
446 // +---+---+---+---+ 473 // +---+---+---+---+
447 // | _ | _ | _ | _ | 474 // | _ | _ | _ | _ |
448 // +---+---+---+---+ 475 // +---+---+---+---+
449 MarkBlocksAndCheckMerge(0, 0, 2, 2); 476 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 0, 2, 2));
450 477
451 // +---+---+---+---+ 478 // +---+---+---+---+
452 // | | | | _ | 479 // | | | | _ |
453 // +---+---+---+---+ 480 // +---+---+---+---+
454 // | | X | X | _ | 481 // | | X | X | _ |
455 // +---+---+---+---+ 482 // +---+---+---+---+
456 // | | X | X | _ | 483 // | | X | X | _ |
457 // +---+---+---+---+ 484 // +---+---+---+---+
458 // | _ | _ | _ | _ | 485 // | _ | _ | _ | _ |
459 // +---+---+---+---+ 486 // +---+---+---+---+
460 MarkBlocksAndCheckMerge(1, 1, 2, 2); 487 ASSERT_TRUE(MarkBlocksAndCheckMerge(1, 1, 2, 2));
461 488
462 // +---+---+---+---+ 489 // +---+---+---+---+
463 // | | X | X | _ | 490 // | | X | X | _ |
464 // +---+---+---+---+ 491 // +---+---+---+---+
465 // | | X | X | _ | 492 // | | X | X | _ |
466 // +---+---+---+---+ 493 // +---+---+---+---+
467 // | | X | X | _ | 494 // | | X | X | _ |
468 // +---+---+---+---+ 495 // +---+---+---+---+
469 // | _ | _ | _ | _ | 496 // | _ | _ | _ | _ |
470 // +---+---+---+---+ 497 // +---+---+---+---+
471 MarkBlocksAndCheckMerge(1, 0, 2, 3); 498 ASSERT_TRUE(MarkBlocksAndCheckMerge(1, 0, 2, 3));
472 499
473 // +---+---+---+---+ 500 // +---+---+---+---+
474 // | | | | _ | 501 // | | | | _ |
475 // +---+---+---+---+ 502 // +---+---+---+---+
476 // | X | X | X | _ | 503 // | X | X | X | _ |
477 // +---+---+---+---+ 504 // +---+---+---+---+
478 // | X | X | X | _ | 505 // | X | X | X | _ |
479 // +---+---+---+---+ 506 // +---+---+---+---+
480 // | _ | _ | _ | _ | 507 // | _ | _ | _ | _ |
481 // +---+---+---+---+ 508 // +---+---+---+---+
482 MarkBlocksAndCheckMerge(0, 1, 3, 2); 509 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 1, 3, 2));
483 510
484 // +---+---+---+---+ 511 // +---+---+---+---+
485 // | X | X | X | _ | 512 // | X | X | X | _ |
486 // +---+---+---+---+ 513 // +---+---+---+---+
487 // | X | X | X | _ | 514 // | X | X | X | _ |
488 // +---+---+---+---+ 515 // +---+---+---+---+
489 // | X | X | X | _ | 516 // | X | X | X | _ |
490 // +---+---+---+---+ 517 // +---+---+---+---+
491 // | _ | _ | _ | _ | 518 // | _ | _ | _ | _ |
492 // +---+---+---+---+ 519 // +---+---+---+---+
493 MarkBlocksAndCheckMerge(0, 0, 3, 3); 520 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 0, 3, 3));
494 } 521 }
495 522
496 // This tests marked regions that require more than 1 single dirty rect. 523 // This tests marked regions that require more than 1 single dirty rect.
497 // The exact rects returned depend on the current implementation, so these 524 // The exact rects returned depend on the current implementation, so these
498 // may need to be updated if we modify how we merge blocks. 525 // may need to be updated if we modify how we merge blocks.
499 TEST_F(DifferTest, MergeBlocks_MultiRect) { 526 TEST_F(DifferTest, MergeBlocks_MultiRect) {
500 InitDiffer(kScreenWidth, kScreenHeight); 527 InitDiffer(kScreenWidth, kScreenHeight);
501 scoped_ptr<InvalidRects> dirty; 528 SkRegion dirty;
502 529
503 // +---+---+---+---+ +---+---+---+ 530 // +---+---+---+---+ +---+---+---+
504 // | | X | | _ | | | 0 | | 531 // | | X | | _ | | | 0 | |
505 // +---+---+---+---+ +---+---+---+ 532 // +---+---+---+---+ +---+---+---+
506 // | X | | | _ | | 1 | | | 533 // | X | | | _ | | 1 | | |
507 // +---+---+---+---+ => +---+---+---+ 534 // +---+---+---+---+ => +---+---+---+
508 // | | | X | _ | | | | 2 | 535 // | | | X | _ | | | | 2 |
509 // +---+---+---+---+ +---+---+---+ 536 // +---+---+---+---+ +---+---+---+
510 // | _ | _ | _ | _ | 537 // | _ | _ | _ | _ |
511 // +---+---+---+---+ 538 // +---+---+---+---+
512 ClearDiffInfo(); 539 ClearDiffInfo();
513 MarkBlocks(1, 0, 1, 1); 540 MarkBlocks(1, 0, 1, 1);
514 MarkBlocks(0, 1, 1, 1); 541 MarkBlocks(0, 1, 1, 1);
515 MarkBlocks(2, 2, 1, 1); 542 MarkBlocks(2, 2, 1, 1);
516 543
517 dirty.reset(new InvalidRects()); 544 dirty.setEmpty();
518 differ_->MergeBlocks(dirty.get()); 545 MergeBlocks(&dirty);
519 546
520 ASSERT_EQ(3UL, dirty->size()); 547 ASSERT_EQ(3, RegionRectCount(dirty));
521 CheckDirtyRect(*dirty.get(), 1, 0, 1, 1); 548 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 1, 0, 1, 1));
522 CheckDirtyRect(*dirty.get(), 0, 1, 1, 1); 549 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 1, 1));
523 CheckDirtyRect(*dirty.get(), 2, 2, 1, 1); 550 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 2, 1, 1));
524 551
525 // +---+---+---+---+ +---+---+---+ 552 // +---+---+---+---+ +---+---+---+
526 // | | | X | _ | | | | 0 | 553 // | | | X | _ | | | | 0 |
527 // +---+---+---+---+ +---+---+ + 554 // +---+---+---+---+ +---+---+---+
528 // | X | X | X | _ | | 1 1 | 0 | 555 // | X | X | X | _ | | 1 1 1 |
529 // +---+---+---+---+ => + + + 556 // +---+---+---+---+ => + +
530 // | X | X | X | _ | | 1 1 | 0 | 557 // | X | X | X | _ | | 1 1 1 |
531 // +---+---+---+---+ +---+---+---+ 558 // +---+---+---+---+ +---+---+---+
532 // | _ | _ | _ | _ | 559 // | _ | _ | _ | _ |
533 // +---+---+---+---+ 560 // +---+---+---+---+
534 ClearDiffInfo(); 561 ClearDiffInfo();
535 MarkBlocks(2, 0, 1, 3); 562 MarkBlocks(2, 0, 1, 1);
536 MarkBlocks(0, 1, 2, 2); 563 MarkBlocks(0, 1, 3, 2);
537 564
538 dirty.reset(new InvalidRects()); 565 dirty.setEmpty();
539 differ_->MergeBlocks(dirty.get()); 566 MergeBlocks(&dirty);
540 567
541 ASSERT_EQ(2UL, dirty->size()); 568 ASSERT_EQ(2, RegionRectCount(dirty));
542 CheckDirtyRect(*dirty.get(), 2, 0, 1, 3); 569 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 0, 1, 1));
543 CheckDirtyRect(*dirty.get(), 0, 1, 2, 2); 570 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 3, 2));
544 571
545 // +---+---+---+---+ +---+---+---+ 572 // +---+---+---+---+ +---+---+---+
546 // | | | | _ | | | | | 573 // | | | | _ | | | | |
547 // +---+---+---+---+ +---+---+---+ 574 // +---+---+---+---+ +---+---+---+
548 // | X | | X | _ | | 0 | | 1 | 575 // | X | | X | _ | | 0 | | 1 |
549 // +---+---+---+---+ => + +---+ + 576 // +---+---+---+---+ => + +---+ +
550 // | X | X | X | _ | | 0 | 2 | 1 | 577 // | X | X | X | _ | | 2 | 2 | 2 |
551 // +---+---+---+---+ +---+---+---+ 578 // +---+---+---+---+ +---+---+---+
552 // | _ | _ | _ | _ | 579 // | _ | _ | _ | _ |
553 // +---+---+---+---+ 580 // +---+---+---+---+
554 ClearDiffInfo(); 581 ClearDiffInfo();
555 MarkBlocks(0, 1, 1, 1); 582 MarkBlocks(0, 1, 1, 1);
556 MarkBlocks(2, 1, 1, 1); 583 MarkBlocks(2, 1, 1, 1);
557 MarkBlocks(0, 2, 3, 1); 584 MarkBlocks(0, 2, 3, 1);
558 585
559 dirty.reset(new InvalidRects()); 586 dirty.setEmpty();
560 differ_->MergeBlocks(dirty.get()); 587 MergeBlocks(&dirty);
561 588
562 ASSERT_EQ(3UL, dirty->size()); 589 ASSERT_EQ(3, RegionRectCount(dirty));
563 CheckDirtyRect(*dirty.get(), 0, 1, 1, 2); 590 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 1, 1));
564 CheckDirtyRect(*dirty.get(), 2, 1, 1, 2); 591 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 1, 1, 1));
565 CheckDirtyRect(*dirty.get(), 1, 2, 1, 1); 592 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 2, 3, 1));
566 593
567 // +---+---+---+---+ +---+---+---+ 594 // +---+---+---+---+ +---+---+---+
568 // | X | X | X | _ | | 0 0 0 | 595 // | X | X | X | _ | | 0 0 0 |
569 // +---+---+---+---+ +---+---+---+ 596 // +---+---+---+---+ +---+---+---+
570 // | X | | X | _ | | 1 | | 2 | 597 // | X | | X | _ | | 1 | | 2 |
571 // +---+---+---+---+ => + +---+ + 598 // +---+---+---+---+ => + +---+ +
572 // | X | X | X | _ | | 1 | 3 | 2 | 599 // | X | X | X | _ | | 3 | 3 | 3 |
573 // +---+---+---+---+ +---+---+---+ 600 // +---+---+---+---+ +---+---+---+
574 // | _ | _ | _ | _ | 601 // | _ | _ | _ | _ |
575 // +---+---+---+---+ 602 // +---+---+---+---+
576 ClearDiffInfo(); 603 ClearDiffInfo();
577 MarkBlocks(0, 0, 3, 1); 604 MarkBlocks(0, 0, 3, 1);
578 MarkBlocks(0, 1, 1, 1); 605 MarkBlocks(0, 1, 1, 1);
579 MarkBlocks(2, 1, 1, 1); 606 MarkBlocks(2, 1, 1, 1);
580 MarkBlocks(0, 2, 3, 1); 607 MarkBlocks(0, 2, 3, 1);
581 608
582 dirty.reset(new InvalidRects()); 609 dirty.setEmpty();
583 differ_->MergeBlocks(dirty.get()); 610 MergeBlocks(&dirty);
584 611
585 ASSERT_EQ(4UL, dirty->size()); 612 ASSERT_EQ(4, RegionRectCount(dirty));
586 CheckDirtyRect(*dirty.get(), 0, 0, 3, 1); 613 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 0, 3, 1));
587 CheckDirtyRect(*dirty.get(), 0, 1, 1, 2); 614 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 1, 1));
588 CheckDirtyRect(*dirty.get(), 2, 1, 1, 2); 615 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 1, 1, 1));
589 CheckDirtyRect(*dirty.get(), 1, 2, 1, 1); 616 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 2, 3, 1));
590 617
591 // +---+---+---+---+ +---+---+---+ 618 // +---+---+---+---+ +---+---+---+
592 // | X | X | | _ | | 0 0 | | 619 // | X | X | | _ | | 0 0 | |
593 // +---+---+---+---+ + +---+ 620 // +---+---+---+---+ + +---+
594 // | X | X | | _ | | 0 0 | | 621 // | X | X | | _ | | 0 0 | |
595 // +---+---+---+---+ => +---+---+---+ 622 // +---+---+---+---+ => +---+---+---+
596 // | | X | | _ | | | 1 | | 623 // | | X | | _ | | | 1 | |
597 // +---+---+---+---+ +---+---+---+ 624 // +---+---+---+---+ +---+---+---+
598 // | _ | _ | _ | _ | 625 // | _ | _ | _ | _ |
599 // +---+---+---+---+ 626 // +---+---+---+---+
600 ClearDiffInfo(); 627 ClearDiffInfo();
601 MarkBlocks(0, 0, 2, 2); 628 MarkBlocks(0, 0, 2, 2);
602 MarkBlocks(1, 2, 1, 1); 629 MarkBlocks(1, 2, 1, 1);
603 630
604 dirty.reset(new InvalidRects()); 631 dirty.setEmpty();
605 differ_->MergeBlocks(dirty.get()); 632 MergeBlocks(&dirty);
606 633
607 ASSERT_EQ(2UL, dirty->size()); 634 ASSERT_EQ(2, RegionRectCount(dirty));
608 CheckDirtyRect(*dirty.get(), 0, 0, 2, 2); 635 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 0, 2, 2));
609 CheckDirtyRect(*dirty.get(), 1, 2, 1, 1); 636 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 1, 2, 1, 1));
610 } 637 }
611 638
612 } // namespace remoting 639 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/differ.cc ('k') | remoting/host/host_mock_objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698