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 "media/video/capture/screen/screen_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 "media/video/capture/screen/mac/desktop_configuration.h" | 14 #include "media/video/capture/screen/mac/desktop_configuration.h" |
15 #include "media/video/capture/screen/screen_capture_data.h" | |
16 #include "media/video/capture/screen/screen_capturer_mock_objects.h" | 15 #include "media/video/capture/screen/screen_capturer_mock_objects.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 18 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
| 19 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
18 | 20 |
19 using ::testing::_; | 21 using ::testing::_; |
20 using ::testing::AnyNumber; | 22 using ::testing::AnyNumber; |
21 using ::testing::Return; | 23 using ::testing::Return; |
22 | 24 |
23 namespace media { | 25 namespace media { |
24 | 26 |
25 class ScreenCapturerMacTest : public testing::Test { | 27 class ScreenCapturerMacTest : public testing::Test { |
26 public: | 28 public: |
27 // Verifies that the whole screen is initially dirty. | 29 // Verifies that the whole screen is initially dirty. |
28 void CaptureDoneCallback1(scoped_refptr<ScreenCaptureData> capture_data); | 30 void CaptureDoneCallback1(webrtc::DesktopFrame* frame); |
29 | 31 |
30 // Verifies that a rectangle explicitly marked as dirty is propagated | 32 // Verifies that a rectangle explicitly marked as dirty is propagated |
31 // correctly. | 33 // correctly. |
32 void CaptureDoneCallback2(scoped_refptr<ScreenCaptureData> capture_data); | 34 void CaptureDoneCallback2(webrtc::DesktopFrame* frame); |
33 | 35 |
34 protected: | 36 protected: |
35 virtual void SetUp() OVERRIDE { | 37 virtual void SetUp() OVERRIDE { |
36 capturer_ = ScreenCapturer::Create(); | 38 capturer_ = ScreenCapturer::Create(); |
37 } | 39 } |
38 | 40 |
39 scoped_ptr<ScreenCapturer> capturer_; | 41 scoped_ptr<ScreenCapturer> capturer_; |
40 MockScreenCapturerDelegate delegate_; | 42 MockScreenCapturerCallback callback_; |
41 }; | 43 }; |
42 | 44 |
43 void ScreenCapturerMacTest::CaptureDoneCallback1( | 45 void ScreenCapturerMacTest::CaptureDoneCallback1( |
44 scoped_refptr<ScreenCaptureData> capture_data) { | 46 webrtc::DesktopFrame* frame) { |
| 47 scoped_ptr<webrtc::DesktopFrame> owned_frame(frame); |
| 48 |
45 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent( | 49 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent( |
46 MacDesktopConfiguration::BottomLeftOrigin); | 50 MacDesktopConfiguration::BottomLeftOrigin); |
47 int width = config.pixel_bounds.width(); | |
48 int height = config.pixel_bounds.height(); | |
49 SkRegion initial_region(SkIRect::MakeXYWH(0, 0, width, height)); | |
50 | 51 |
51 EXPECT_EQ(initial_region, capture_data->dirty_region()); | 52 // Verify that the region contains full frame. |
| 53 webrtc::DesktopRegion::Iterator it(frame->updated_region()); |
| 54 EXPECT_TRUE(!it.IsAtEnd() && it.rect().equals(config.pixel_bounds)); |
52 } | 55 } |
53 | 56 |
54 void ScreenCapturerMacTest::CaptureDoneCallback2( | 57 void ScreenCapturerMacTest::CaptureDoneCallback2( |
55 scoped_refptr<ScreenCaptureData> capture_data) { | 58 webrtc::DesktopFrame* frame) { |
| 59 scoped_ptr<webrtc::DesktopFrame> owned_frame(frame); |
| 60 |
56 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent( | 61 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent( |
57 MacDesktopConfiguration::BottomLeftOrigin); | 62 MacDesktopConfiguration::BottomLeftOrigin); |
58 int width = config.pixel_bounds.width(); | 63 int width = config.pixel_bounds.width(); |
59 int height = config.pixel_bounds.height(); | 64 int height = config.pixel_bounds.height(); |
60 | 65 |
61 EXPECT_EQ(width, capture_data->size().width()); | 66 EXPECT_EQ(width, frame->size().width()); |
62 EXPECT_EQ(height, capture_data->size().height()); | 67 EXPECT_EQ(height, frame->size().height()); |
63 EXPECT_TRUE(capture_data->data() != NULL); | 68 EXPECT_TRUE(frame->data() != NULL); |
64 // Depending on the capture method, the screen may be flipped or not, so | 69 // Depending on the capture method, the screen may be flipped or not, so |
65 // the stride may be positive or negative. | 70 // the stride may be positive or negative. |
66 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width), | 71 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width), |
67 abs(capture_data->stride())); | 72 abs(frame->stride())); |
68 } | 73 } |
69 | 74 |
70 TEST_F(ScreenCapturerMacTest, Capture) { | 75 TEST_F(ScreenCapturerMacTest, Capture) { |
71 EXPECT_CALL(delegate_, OnCaptureCompleted(_)) | 76 EXPECT_CALL(callback_, OnCaptureCompleted(_)) |
72 .Times(2) | 77 .Times(2) |
73 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback1)) | 78 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback1)) |
74 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback2)); | 79 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback2)); |
75 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_)) | |
76 .Times(AnyNumber()); | |
77 | 80 |
78 EXPECT_CALL(delegate_, CreateSharedBuffer(_)) | 81 EXPECT_CALL(callback_, CreateSharedMemory(_)) |
79 .Times(AnyNumber()) | 82 .Times(AnyNumber()) |
80 .WillRepeatedly(Return(scoped_refptr<SharedBuffer>())); | 83 .WillRepeatedly(Return(static_cast<webrtc::SharedMemory*>(NULL))); |
81 | 84 |
82 SCOPED_TRACE(""); | 85 SCOPED_TRACE(""); |
83 capturer_->Start(&delegate_); | 86 capturer_->Start(&callback_); |
84 | 87 |
85 // Check that we get an initial full-screen updated. | 88 // Check that we get an initial full-screen updated. |
86 capturer_->CaptureFrame(); | 89 capturer_->Capture(webrtc::DesktopRegion()); |
87 | 90 |
88 // Check that subsequent dirty rects are propagated correctly. | 91 // Check that subsequent dirty rects are propagated correctly. |
89 capturer_->CaptureFrame(); | 92 capturer_->Capture(webrtc::DesktopRegion()); |
90 } | 93 } |
91 | 94 |
92 } // namespace media | 95 } // namespace media |
93 | |
94 namespace gfx { | |
95 | |
96 std::ostream& operator<<(std::ostream& out, const SkRegion& region) { | |
97 out << "SkRegion("; | |
98 for (SkRegion::Iterator i(region); !i.done(); i.next()) { | |
99 const SkIRect& r = i.rect(); | |
100 out << "(" << r.fLeft << "," << r.fTop << "," | |
101 << r.fRight << "," << r.fBottom << ")"; | |
102 } | |
103 out << ")"; | |
104 return out; | |
105 } | |
106 | |
107 } // namespace gfx | |
OLD | NEW |