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

Side by Side Diff: media/video/capture/screen/differ_unittest.cc

Issue 13983010: Use webrtc::DesktopCapturer for screen capturer implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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
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 "media/video/capture/screen/differ.h" 6 #include "media/video/capture/screen/differ.h"
7 #include "media/video/capture/screen/differ_block.h" 7 #include "media/video/capture/screen/differ_block.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 9
10 namespace media { 10 namespace media {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 47 // Here in DifferTest so that tests can access private methods of Differ.
48 void MarkDirtyBlocks(const void* prev_buffer, const void* curr_buffer) { 48 void MarkDirtyBlocks(const void* prev_buffer, const void* curr_buffer) {
49 differ_->MarkDirtyBlocks(prev_buffer, curr_buffer); 49 differ_->MarkDirtyBlocks(prev_buffer, curr_buffer);
50 } 50 }
51 51
52 void MergeBlocks(SkRegion* dirty) { 52 void MergeBlocks(webrtc::DesktopRegion* dirty) {
53 differ_->MergeBlocks(dirty); 53 differ_->MergeBlocks(dirty);
54 } 54 }
55 55
56 // Convenience method to count rectangles in a region. 56 // Convenience method to count rectangles in a region.
57 int RegionRectCount(const SkRegion& region) { 57 int RegionRectCount(const webrtc::DesktopRegion& region) {
58 int count = 0; 58 int count = 0;
59 for(SkRegion::Iterator iter(region); !iter.done(); iter.next()) { 59 for(webrtc::DesktopRegion::Iterator iter(region);
alexeypa (please no reviews) 2013/05/08 22:24:59 nit: for (
Sergey Ulanov 2013/05/09 18:49:02 Done.
60 !iter.IsAtEnd(); iter.Advance()) {
60 ++count; 61 ++count;
61 } 62 }
62 return count; 63 return count;
63 } 64 }
64 65
65 // Convenience wrapper for Differ's DiffBlock that calculates the appropriate 66 // Convenience wrapper for Differ's DiffBlock that calculates the appropriate
66 // offset to the start of the desired block. 67 // offset to the start of the desired block.
67 DiffInfo DiffBlock(int block_x, int block_y) { 68 DiffInfo DiffBlock(int block_x, int block_y) {
68 // Offset from upper-left of buffer to upper-left of requested block. 69 // Offset from upper-left of buffer to upper-left of requested block.
69 int block_offset = ((block_y * stride_) + (block_x * bytes_per_pixel_)) 70 int block_offset = ((block_y * stride_) + (block_x * bytes_per_pixel_))
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 for (int y = 0; y < height; y++) { 138 for (int y = 0; y < height; y++) {
138 for (int x = 0; x < width; x++) { 139 for (int x = 0; x < width; x++) {
139 SetDiffInfo(x_origin + x, y_origin + y, 1); 140 SetDiffInfo(x_origin + x, y_origin + y, 1);
140 } 141 }
141 } 142 }
142 } 143 }
143 144
144 // Verify that |region| contains a rectangle defined by |x|, |y|, |width| and 145 // Verify that |region| contains a rectangle defined by |x|, |y|, |width| and
145 // |height|. 146 // |height|.
146 // |x|, |y|, |width| and |height| are specified in block (not pixel) units. 147 // |x|, |y|, |width| and |height| are specified in block (not pixel) units.
147 bool CheckDirtyRegionContainsRect(const SkRegion& region, int x, int y, 148 bool CheckDirtyRegionContainsRect(const webrtc::DesktopRegion& region,
149 int x, int y,
148 int width, int height) { 150 int width, int height) {
149 SkIRect r = SkIRect::MakeXYWH(x * kBlockSize, y * kBlockSize, 151 webrtc::DesktopRect r =
150 width * kBlockSize, height * kBlockSize); 152 webrtc::DesktopRect::MakeXYWH(x * kBlockSize, y * kBlockSize,
151 bool found = false; 153 width * kBlockSize, height * kBlockSize);
152 for (SkRegion::Iterator i(region); !found && !i.done(); i.next()) { 154 for (webrtc::DesktopRegion::Iterator i(region); !i.IsAtEnd(); i.Advance()) {
153 found = (i.rect() == r); 155 if (i.rect().equals(r))
156 return true;
154 } 157 }
155 return found; 158 return false;
156 } 159 }
157 160
158 // Mark the range of blocks specified and then verify that they are 161 // Mark the range of blocks specified and then verify that they are
159 // merged correctly. 162 // merged correctly.
160 // Only one rectangular region of blocks can be checked with this routine. 163 // Only one rectangular region of blocks can be checked with this routine.
161 bool MarkBlocksAndCheckMerge(int x_origin, int y_origin, 164 bool MarkBlocksAndCheckMerge(int x_origin, int y_origin,
162 int width, int height) { 165 int width, int height) {
163 ClearDiffInfo(); 166 ClearDiffInfo();
164 MarkBlocks(x_origin, y_origin, width, height); 167 MarkBlocks(x_origin, y_origin, width, height);
165 168
166 SkRegion dirty; 169 webrtc::DesktopRegion dirty;
167 MergeBlocks(&dirty); 170 MergeBlocks(&dirty);
168 171
169 bool is_good = dirty.isRect(); 172
170 if (is_good) { 173 webrtc::DesktopRect expected_rect = webrtc::DesktopRect::MakeXYWH(
171 is_good = CheckDirtyRegionContainsRect(dirty, x_origin, y_origin, 174 x_origin * kBlockSize, y_origin * kBlockSize,
172 width, height); 175 width * kBlockSize, height * kBlockSize);
173 } 176
174 return is_good; 177 // Verify that the region contains expected_rect and it's the only
178 // rectangle.
179 webrtc::DesktopRegion::Iterator it(dirty);
180 return !it.IsAtEnd() && expected_rect.equals(it.rect()) &&
181 (it.Advance(), it.IsAtEnd());
175 } 182 }
176 183
177 // The differ class we're testing. 184 // The differ class we're testing.
178 scoped_ptr<Differ> differ_; 185 scoped_ptr<Differ> differ_;
179 186
180 // Screen/buffer info. 187 // Screen/buffer info.
181 int width_; 188 int width_;
182 int height_; 189 int height_;
183 int bytes_per_pixel_; 190 int bytes_per_pixel_;
184 int stride_; 191 int stride_;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 // | | | | _ | 369 // | | | | _ |
363 // +---+---+---+---+ 370 // +---+---+---+---+
364 // | | | | _ | 371 // | | | | _ |
365 // +---+---+---+---+ 372 // +---+---+---+---+
366 // | | | | _ | 373 // | | | | _ |
367 // +---+---+---+---+ 374 // +---+---+---+---+
368 // | _ | _ | _ | _ | 375 // | _ | _ | _ | _ |
369 // +---+---+---+---+ 376 // +---+---+---+---+
370 ClearDiffInfo(); 377 ClearDiffInfo();
371 378
372 SkRegion dirty; 379 webrtc::DesktopRegion dirty;
373 MergeBlocks(&dirty); 380 MergeBlocks(&dirty);
374 381
375 EXPECT_TRUE(dirty.isEmpty()); 382 EXPECT_TRUE(dirty.is_empty());
376 } 383 }
377 384
378 TEST_F(DifferTest, MergeBlocks_SingleBlock) { 385 TEST_F(DifferTest, MergeBlocks_SingleBlock) {
379 InitDiffer(kScreenWidth, kScreenHeight); 386 InitDiffer(kScreenWidth, kScreenHeight);
380 // Mark a single block and make sure that there is a single merged 387 // Mark a single block and make sure that there is a single merged
381 // rect with the correct bounds. 388 // rect with the correct bounds.
382 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { 389 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) {
383 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { 390 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) {
384 ASSERT_TRUE(MarkBlocksAndCheckMerge(x, y, 1, 1)) << "x: " << x 391 ASSERT_TRUE(MarkBlocksAndCheckMerge(x, y, 1, 1)) << "x: " << x
385 << "y: " << y; 392 << "y: " << y;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 // | _ | _ | _ | _ | 525 // | _ | _ | _ | _ |
519 // +---+---+---+---+ 526 // +---+---+---+---+
520 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 0, 3, 3)); 527 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 0, 3, 3));
521 } 528 }
522 529
523 // This tests marked regions that require more than 1 single dirty rect. 530 // This tests marked regions that require more than 1 single dirty rect.
524 // The exact rects returned depend on the current implementation, so these 531 // The exact rects returned depend on the current implementation, so these
525 // may need to be updated if we modify how we merge blocks. 532 // may need to be updated if we modify how we merge blocks.
526 TEST_F(DifferTest, MergeBlocks_MultiRect) { 533 TEST_F(DifferTest, MergeBlocks_MultiRect) {
527 InitDiffer(kScreenWidth, kScreenHeight); 534 InitDiffer(kScreenWidth, kScreenHeight);
528 SkRegion dirty; 535 webrtc::DesktopRegion dirty;
529 536
530 // +---+---+---+---+ +---+---+---+ 537 // +---+---+---+---+ +---+---+---+
531 // | | X | | _ | | | 0 | | 538 // | | X | | _ | | | 0 | |
532 // +---+---+---+---+ +---+---+---+ 539 // +---+---+---+---+ +---+---+---+
533 // | X | | | _ | | 1 | | | 540 // | X | | | _ | | 1 | | |
534 // +---+---+---+---+ => +---+---+---+ 541 // +---+---+---+---+ => +---+---+---+
535 // | | | X | _ | | | | 2 | 542 // | | | X | _ | | | | 2 |
536 // +---+---+---+---+ +---+---+---+ 543 // +---+---+---+---+ +---+---+---+
537 // | _ | _ | _ | _ | 544 // | _ | _ | _ | _ |
538 // +---+---+---+---+ 545 // +---+---+---+---+
539 ClearDiffInfo(); 546 ClearDiffInfo();
540 MarkBlocks(1, 0, 1, 1); 547 MarkBlocks(1, 0, 1, 1);
541 MarkBlocks(0, 1, 1, 1); 548 MarkBlocks(0, 1, 1, 1);
542 MarkBlocks(2, 2, 1, 1); 549 MarkBlocks(2, 2, 1, 1);
543 550
544 dirty.setEmpty(); 551 dirty.Clear();
545 MergeBlocks(&dirty); 552 MergeBlocks(&dirty);
546 553
547 ASSERT_EQ(3, RegionRectCount(dirty)); 554 ASSERT_EQ(3, RegionRectCount(dirty));
548 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 1, 0, 1, 1)); 555 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 1, 0, 1, 1));
549 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 1, 1)); 556 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 1, 1));
550 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 2, 1, 1)); 557 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 2, 1, 1));
551 558
552 // +---+---+---+---+ +---+---+---+ 559 // +---+---+---+---+ +---+---+---+
553 // | | | X | _ | | | | 0 | 560 // | | | X | _ | | | | 0 |
554 // +---+---+---+---+ +---+---+---+ 561 // +---+---+---+---+ +---+---+ +
555 // | X | X | X | _ | | 1 1 1 | 562 // | X | X | X | _ | | 1 1 | 0 |
alexeypa (please no reviews) 2013/05/08 22:24:59 nit: What is the reason for changing the test case
556 // +---+---+---+---+ => + + 563 // +---+---+---+---+ => + | +
557 // | X | X | X | _ | | 1 1 1 | 564 // | X | X | X | _ | | 1 1 | 0 |
558 // +---+---+---+---+ +---+---+---+ 565 // +---+---+---+---+ +---+---+---+
559 // | _ | _ | _ | _ | 566 // | _ | _ | _ | _ |
560 // +---+---+---+---+ 567 // +---+---+---+---+
561 ClearDiffInfo(); 568 ClearDiffInfo();
562 MarkBlocks(2, 0, 1, 1); 569 MarkBlocks(2, 0, 1, 1);
563 MarkBlocks(0, 1, 3, 2); 570 MarkBlocks(0, 1, 3, 2);
564 571
565 dirty.setEmpty(); 572 dirty.Clear();
566 MergeBlocks(&dirty); 573 MergeBlocks(&dirty);
567 574
568 ASSERT_EQ(2, RegionRectCount(dirty)); 575 ASSERT_EQ(2, RegionRectCount(dirty));
569 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 0, 1, 1)); 576 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 0, 1, 3));
570 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 3, 2)); 577 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 2, 2));
571 578
572 // +---+---+---+---+ +---+---+---+ 579 // +---+---+---+---+ +---+---+---+
573 // | | | | _ | | | | | 580 // | | | | _ | | | | |
574 // +---+---+---+---+ +---+---+---+ 581 // +---+---+---+---+ +---+---+---+
575 // | X | | X | _ | | 0 | | 1 | 582 // | X | | X | _ | | 0 | | 1 |
576 // +---+---+---+---+ => + +---+ + 583 // +---+---+---+---+ => + +---+ +
577 // | X | X | X | _ | | 2 | 2 | 2 | 584 // | X | X | X | _ | | 0 | 2 | 1 |
578 // +---+---+---+---+ +---+---+---+ 585 // +---+---+---+---+ +---+---+---+
579 // | _ | _ | _ | _ | 586 // | _ | _ | _ | _ |
580 // +---+---+---+---+ 587 // +---+---+---+---+
581 ClearDiffInfo(); 588 ClearDiffInfo();
582 MarkBlocks(0, 1, 1, 1); 589 MarkBlocks(0, 1, 1, 1);
583 MarkBlocks(2, 1, 1, 1); 590 MarkBlocks(2, 1, 1, 1);
584 MarkBlocks(0, 2, 3, 1); 591 MarkBlocks(0, 2, 3, 1);
585 592
586 dirty.setEmpty(); 593 dirty.Clear();
587 MergeBlocks(&dirty); 594 MergeBlocks(&dirty);
588 595
589 ASSERT_EQ(3, RegionRectCount(dirty)); 596 ASSERT_EQ(3, RegionRectCount(dirty));
590 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 1, 1)); 597 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 1, 2));
591 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 1, 1, 1)); 598 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 1, 1, 2));
592 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 2, 3, 1)); 599 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 1, 2, 1, 1));
593 600
594 // +---+---+---+---+ +---+---+---+ 601 // +---+---+---+---+ +---+---+---+
595 // | X | X | X | _ | | 0 0 0 | 602 // | X | X | X | _ | | 0 0 0 |
596 // +---+---+---+---+ +---+---+---+ 603 // +---+---+---+---+ +---+---+---+
597 // | X | | X | _ | | 1 | | 2 | 604 // | X | | X | _ | | 1 | | 2 |
598 // +---+---+---+---+ => + +---+ + 605 // +---+---+---+---+ => + +---+ +
599 // | X | X | X | _ | | 3 | 3 | 3 | 606 // | X | X | X | _ | | 1 | 3 | 2 |
600 // +---+---+---+---+ +---+---+---+ 607 // +---+---+---+---+ +---+---+---+
601 // | _ | _ | _ | _ | 608 // | _ | _ | _ | _ |
602 // +---+---+---+---+ 609 // +---+---+---+---+
603 ClearDiffInfo(); 610 ClearDiffInfo();
604 MarkBlocks(0, 0, 3, 1); 611 MarkBlocks(0, 0, 3, 1);
605 MarkBlocks(0, 1, 1, 1); 612 MarkBlocks(0, 1, 1, 1);
606 MarkBlocks(2, 1, 1, 1); 613 MarkBlocks(2, 1, 1, 1);
607 MarkBlocks(0, 2, 3, 1); 614 MarkBlocks(0, 2, 3, 1);
608 615
609 dirty.setEmpty(); 616 dirty.Clear();
610 MergeBlocks(&dirty); 617 MergeBlocks(&dirty);
611 618
612 ASSERT_EQ(4, RegionRectCount(dirty)); 619 ASSERT_EQ(4, RegionRectCount(dirty));
613 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 0, 3, 1)); 620 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 0, 3, 1));
614 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 1, 1)); 621 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 1, 2));
615 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 1, 1, 1)); 622 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 1, 1, 2));
616 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 2, 3, 1)); 623 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 1, 2, 1, 1));
617 624
618 // +---+---+---+---+ +---+---+---+ 625 // +---+---+---+---+ +---+---+---+
619 // | X | X | | _ | | 0 0 | | 626 // | X | X | | _ | | 0 0 | |
620 // +---+---+---+---+ + +---+ 627 // +---+---+---+---+ + +---+
621 // | X | X | | _ | | 0 0 | | 628 // | X | X | | _ | | 0 0 | |
622 // +---+---+---+---+ => +---+---+---+ 629 // +---+---+---+---+ => +---+---+---+
623 // | | X | | _ | | | 1 | | 630 // | | X | | _ | | | 1 | |
624 // +---+---+---+---+ +---+---+---+ 631 // +---+---+---+---+ +---+---+---+
625 // | _ | _ | _ | _ | 632 // | _ | _ | _ | _ |
626 // +---+---+---+---+ 633 // +---+---+---+---+
627 ClearDiffInfo(); 634 ClearDiffInfo();
628 MarkBlocks(0, 0, 2, 2); 635 MarkBlocks(0, 0, 2, 2);
629 MarkBlocks(1, 2, 1, 1); 636 MarkBlocks(1, 2, 1, 1);
630 637
631 dirty.setEmpty(); 638 dirty.Clear();
632 MergeBlocks(&dirty); 639 MergeBlocks(&dirty);
633 640
634 ASSERT_EQ(2, RegionRectCount(dirty)); 641 ASSERT_EQ(2, RegionRectCount(dirty));
635 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 0, 2, 2)); 642 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 0, 2, 2));
636 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 1, 2, 1, 1)); 643 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 1, 2, 1, 1));
637 } 644 }
638 645
639 } // namespace media 646 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698