OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "remoting/capturer/video_frame_capturer.h" | |
6 | |
7 #include <ApplicationServices/ApplicationServices.h> | |
8 | |
9 #include <ostream> | |
10 | |
11 #include "base/bind.h" | |
12 #include "base/callback.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "remoting/capturer/capture_data.h" | |
15 #include "remoting/capturer/video_capturer_mock_objects.h" | |
16 #include "testing/gtest/include/gtest/gtest.h" | |
17 | |
18 using ::testing::_; | |
19 using ::testing::AnyNumber; | |
20 | |
21 namespace remoting { | |
22 | |
23 // Verify that the OS is at least Snow Leopard (10.6). | |
24 // Chromoting doesn't support 10.5 or earlier. | |
25 bool CheckSnowLeopard() { | |
26 long minorVersion, majorVersion; | |
27 Gestalt(gestaltSystemVersionMajor, &majorVersion); | |
28 Gestalt(gestaltSystemVersionMinor, &minorVersion); | |
29 return majorVersion == 10 && minorVersion > 5; | |
30 } | |
31 | |
32 class VideoFrameCapturerMacTest : public testing::Test { | |
33 public: | |
34 // Verifies that the whole screen is initially dirty. | |
35 void CaptureDoneCallback1(scoped_refptr<CaptureData> capture_data); | |
36 | |
37 // Verifies that a rectangle explicitly marked as dirty is propagated | |
38 // correctly. | |
39 void CaptureDoneCallback2(scoped_refptr<CaptureData> capture_data); | |
40 | |
41 protected: | |
42 virtual void SetUp() OVERRIDE { | |
43 capturer_ = VideoFrameCapturer::Create(); | |
44 } | |
45 | |
46 void AddDirtyRect() { | |
47 SkIRect rect = SkIRect::MakeXYWH(0, 0, 10, 10); | |
48 region_.op(rect, SkRegion::kUnion_Op); | |
49 } | |
50 | |
51 scoped_ptr<VideoFrameCapturer> capturer_; | |
52 MockVideoFrameCapturerDelegate delegate_; | |
53 SkRegion region_; | |
54 }; | |
55 | |
56 void VideoFrameCapturerMacTest::CaptureDoneCallback1( | |
57 scoped_refptr<CaptureData> capture_data) { | |
58 CGDirectDisplayID mainDevice = CGMainDisplayID(); | |
59 int width = CGDisplayPixelsWide(mainDevice); | |
60 int height = CGDisplayPixelsHigh(mainDevice); | |
61 SkRegion initial_region(SkIRect::MakeXYWH(0, 0, width, height)); | |
62 EXPECT_EQ(initial_region, capture_data->dirty_region()); | |
63 } | |
64 | |
65 void VideoFrameCapturerMacTest::CaptureDoneCallback2( | |
66 scoped_refptr<CaptureData> capture_data) { | |
67 CGDirectDisplayID mainDevice = CGMainDisplayID(); | |
68 int width = CGDisplayPixelsWide(mainDevice); | |
69 int height = CGDisplayPixelsHigh(mainDevice); | |
70 | |
71 EXPECT_EQ(region_, capture_data->dirty_region()); | |
72 EXPECT_EQ(width, capture_data->size().width()); | |
73 EXPECT_EQ(height, capture_data->size().height()); | |
74 EXPECT_TRUE(capture_data->data() != NULL); | |
75 // Depending on the capture method, the screen may be flipped or not, so | |
76 // the stride may be positive or negative. | |
77 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width), | |
78 abs(capture_data->stride())); | |
79 } | |
80 | |
81 TEST_F(VideoFrameCapturerMacTest, Capture) { | |
82 if (!CheckSnowLeopard()) { | |
83 return; | |
84 } | |
85 | |
86 EXPECT_CALL(delegate_, OnCaptureCompleted(_)) | |
87 .Times(2) | |
88 .WillOnce(Invoke(this, &VideoFrameCapturerMacTest::CaptureDoneCallback1)) | |
89 .WillOnce(Invoke(this, &VideoFrameCapturerMacTest::CaptureDoneCallback2)); | |
90 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_)) | |
91 .Times(AnyNumber()); | |
92 | |
93 SCOPED_TRACE(""); | |
94 capturer_->Start(&delegate_); | |
95 | |
96 // Check that we get an initial full-screen updated. | |
97 capturer_->CaptureFrame(); | |
98 | |
99 // Check that subsequent dirty rects are propagated correctly. | |
100 AddDirtyRect(); | |
101 capturer_->InvalidateRegion(region_); | |
102 capturer_->CaptureFrame(); | |
103 capturer_->Stop(); | |
104 } | |
105 | |
106 } // namespace remoting | |
107 | |
108 namespace gfx { | |
109 | |
110 std::ostream& operator<<(std::ostream& out, const SkRegion& region) { | |
111 out << "SkRegion("; | |
112 for (SkRegion::Iterator i(region); !i.done(); i.next()) { | |
113 const SkIRect& r = i.rect(); | |
114 out << "(" << r.fLeft << "," << r.fTop << "," | |
115 << r.fRight << "," << r.fBottom << ")"; | |
116 } | |
117 out << ")"; | |
118 return out; | |
119 } | |
120 | |
121 } // namespace gfx | |
OLD | NEW |