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