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

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

Issue 7622002: Revert 96327 - Switch over to using SkRegions to calculate dirty areas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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/capturer_mac.cc ('k') | remoting/host/capturer_win.cc » ('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 "remoting/host/capturer.h" 5 #include "remoting/host/capturer.h"
6 6
7 #include <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 8
9 #include <iostream> 9 #include <iostream>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "remoting/base/types.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace remoting { 16 namespace remoting {
16 17
17 class CapturerMacTest : public testing::Test { 18 class CapturerMacTest : public testing::Test {
18 protected: 19 protected:
19 virtual void SetUp() { 20 virtual void SetUp() {
20 capturer_.reset(Capturer::Create()); 21 capturer_.reset(Capturer::Create());
21 } 22 }
22 23
23 void AddDirtyRect() { 24 void AddDirtyRect() {
24 SkIRect rect = SkIRect::MakeXYWH(0, 0, 10, 10); 25 rects_.insert(gfx::Rect(0, 0, 10, 10));
25 region_.op(rect, SkRegion::kUnion_Op);
26 } 26 }
27 27
28 scoped_ptr<Capturer> capturer_; 28 scoped_ptr<Capturer> capturer_;
29 SkRegion region_; 29 InvalidRects rects_;
30 }; 30 };
31 31
32 // CapturerCallback1 verifies that the whole screen is initially dirty. 32 // CapturerCallback1 verifies that the whole screen is initially dirty.
33 class CapturerCallback1 { 33 class CapturerCallback1 {
34 public: 34 public:
35 CapturerCallback1() { } 35 CapturerCallback1() { }
36 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data); 36 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data);
37 37
38 private: 38 private:
39 DISALLOW_COPY_AND_ASSIGN(CapturerCallback1); 39 DISALLOW_COPY_AND_ASSIGN(CapturerCallback1);
40 }; 40 };
41 41
42 void CapturerCallback1::CaptureDoneCallback( 42 void CapturerCallback1::CaptureDoneCallback(
43 scoped_refptr<CaptureData> capture_data) { 43 scoped_refptr<CaptureData> capture_data) {
44 CGDirectDisplayID mainDevice = CGMainDisplayID(); 44 CGDirectDisplayID mainDevice = CGMainDisplayID();
45 int width = CGDisplayPixelsWide(mainDevice); 45 int width = CGDisplayPixelsWide(mainDevice);
46 int height = CGDisplayPixelsHigh(mainDevice); 46 int height = CGDisplayPixelsHigh(mainDevice);
47 SkRegion initial_region(SkIRect::MakeXYWH(0, 0, width, height)); 47 InvalidRects initial_rect;
48 EXPECT_EQ(initial_region, capture_data->dirty_region()); 48 initial_rect.insert(gfx::Rect(0, 0, width, height));
49 EXPECT_EQ(initial_rect, capture_data->dirty_rects());
49 } 50 }
50 51
51 // CapturerCallback2 verifies that a rectangle explicitly marked as dirty is 52 // CapturerCallback2 verifies that a rectangle explicitly marked as dirty is
52 // propagated correctly. 53 // propagated correctly.
53 class CapturerCallback2 { 54 class CapturerCallback2 {
54 public: 55 public:
55 explicit CapturerCallback2(const SkRegion& expected_dirty_region) 56 explicit CapturerCallback2(const InvalidRects& expected_dirty_rects)
56 : expected_dirty_region_(expected_dirty_region) { } 57 : expected_dirty_rects_(expected_dirty_rects) { }
57 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data); 58 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data);
58 59
59 protected: 60 protected:
60 SkRegion expected_dirty_region_; 61 InvalidRects expected_dirty_rects_;
61 62
62 private: 63 private:
63 DISALLOW_COPY_AND_ASSIGN(CapturerCallback2); 64 DISALLOW_COPY_AND_ASSIGN(CapturerCallback2);
64 }; 65 };
65 66
66 void CapturerCallback2::CaptureDoneCallback( 67 void CapturerCallback2::CaptureDoneCallback(
67 scoped_refptr<CaptureData> capture_data) { 68 scoped_refptr<CaptureData> capture_data) {
68 CGDirectDisplayID mainDevice = CGMainDisplayID(); 69 CGDirectDisplayID mainDevice = CGMainDisplayID();
69 int width = CGDisplayPixelsWide(mainDevice); 70 int width = CGDisplayPixelsWide(mainDevice);
70 int height = CGDisplayPixelsHigh(mainDevice); 71 int height = CGDisplayPixelsHigh(mainDevice);
71 72
72 EXPECT_EQ(expected_dirty_region_, capture_data->dirty_region()); 73 EXPECT_EQ(expected_dirty_rects_, capture_data->dirty_rects());
73 EXPECT_EQ(width, capture_data->size().width()); 74 EXPECT_EQ(width, capture_data->size().width());
74 EXPECT_EQ(height, capture_data->size().height()); 75 EXPECT_EQ(height, capture_data->size().height());
75 const DataPlanes &planes = capture_data->data_planes(); 76 const DataPlanes &planes = capture_data->data_planes();
76 EXPECT_TRUE(planes.data[0] != NULL); 77 EXPECT_TRUE(planes.data[0] != NULL);
77 EXPECT_TRUE(planes.data[1] == NULL); 78 EXPECT_TRUE(planes.data[1] == NULL);
78 EXPECT_TRUE(planes.data[2] == NULL); 79 EXPECT_TRUE(planes.data[2] == NULL);
79 // Depending on the capture method, the screen may be flipped or not, so 80 // Depending on the capture method, the screen may be flipped or not, so
80 // the stride may be positive or negative. 81 // the stride may be positive or negative.
81 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width), 82 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width),
82 abs(planes.strides[0])); 83 abs(planes.strides[0]));
83 EXPECT_EQ(0, planes.strides[1]); 84 EXPECT_EQ(0, planes.strides[1]);
84 EXPECT_EQ(0, planes.strides[2]); 85 EXPECT_EQ(0, planes.strides[2]);
85 } 86 }
86 87
87 TEST_F(CapturerMacTest, Capture) { 88 TEST_F(CapturerMacTest, Capture) {
88 SCOPED_TRACE(""); 89 SCOPED_TRACE("");
89 // Check that we get an initial full-screen updated. 90 // Check that we get an initial full-screen updated.
90 CapturerCallback1 callback1; 91 CapturerCallback1 callback1;
91 capturer_->CaptureInvalidRegion( 92 capturer_->CaptureInvalidRects(
92 NewCallback(&callback1, &CapturerCallback1::CaptureDoneCallback)); 93 NewCallback(&callback1, &CapturerCallback1::CaptureDoneCallback));
93 // Check that subsequent dirty rects are propagated correctly. 94 // Check that subsequent dirty rects are propagated correctly.
94 AddDirtyRect(); 95 AddDirtyRect();
95 CapturerCallback2 callback2(region_); 96 CapturerCallback2 callback2(rects_);
96 capturer_->InvalidateRegion(region_); 97 capturer_->InvalidateRects(rects_);
97 capturer_->CaptureInvalidRegion( 98 capturer_->CaptureInvalidRects(
98 NewCallback(&callback2, &CapturerCallback2::CaptureDoneCallback)); 99 NewCallback(&callback2, &CapturerCallback2::CaptureDoneCallback));
99 } 100 }
100 101
101 } // namespace remoting 102 } // namespace remoting
102 103
103 namespace gfx { 104 namespace gfx {
104 105
105 std::ostream& operator<<(std::ostream& out, const SkRegion& region) { 106 std::ostream& operator<<(std::ostream& out,
106 out << "SkRegion("; 107 const remoting::InvalidRects& rects) {
107 for (SkRegion::Iterator i(region); !i.done(); i.next()) { 108 for (remoting::InvalidRects::const_iterator i = rects.begin();
108 const SkIRect& r = i.rect(); 109 i != rects.end();
109 out << "(" << r.fLeft << "," << r.fTop << "," 110 ++i) {
110 << r.fRight << "," << r.fBottom << ")"; 111 out << *i << std::endl;
111 } 112 }
112 out << ")";
113 return out; 113 return out;
114 } 114 }
115 115
116 } // namespace gfx 116 } // namespace gfx
OLDNEW
« no previous file with comments | « remoting/host/capturer_mac.cc ('k') | remoting/host/capturer_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698