| 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/host/video_frame_capturer.h" | 5 #include "remoting/host/video_frame_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/base/capture_data.h" | 14 #include "remoting/base/capture_data.h" |
| 15 #include "remoting/host/host_mock_objects.h" |
| 15 #include "remoting/proto/control.pb.h" | 16 #include "remoting/proto/control.pb.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 19 using ::testing::_; |
| 20 using ::testing::AnyNumber; |
| 21 |
| 18 namespace remoting { | 22 namespace remoting { |
| 19 | 23 |
| 20 // Verify that the OS is at least Snow Leopard (10.6). | 24 // Verify that the OS is at least Snow Leopard (10.6). |
| 21 // Chromoting doesn't support 10.5 or earlier. | 25 // Chromoting doesn't support 10.5 or earlier. |
| 22 bool CheckSnowLeopard() { | 26 bool CheckSnowLeopard() { |
| 23 long minorVersion, majorVersion; | 27 long minorVersion, majorVersion; |
| 24 Gestalt(gestaltSystemVersionMajor, &majorVersion); | 28 Gestalt(gestaltSystemVersionMajor, &majorVersion); |
| 25 Gestalt(gestaltSystemVersionMinor, &minorVersion); | 29 Gestalt(gestaltSystemVersionMinor, &minorVersion); |
| 26 return majorVersion == 10 && minorVersion > 5; | 30 return majorVersion == 10 && minorVersion > 5; |
| 27 } | 31 } |
| 28 | 32 |
| 29 class VideoFrameCapturerMacTest : public testing::Test { | 33 class VideoFrameCapturerMacTest : public testing::Test { |
| 34 public: |
| 35 // Verifies that the whole screen is initially dirty. |
| 36 void CaptureDoneCallback1(scoped_refptr<CaptureData> capture_data); |
| 37 |
| 38 // Verifies that a rectangle explicitly marked as dirty is propagated |
| 39 // correctly. |
| 40 void CaptureDoneCallback2(scoped_refptr<CaptureData> capture_data); |
| 41 |
| 30 protected: | 42 protected: |
| 31 virtual void SetUp() OVERRIDE { | 43 virtual void SetUp() OVERRIDE { |
| 32 capturer_.reset(VideoFrameCapturer::Create()); | 44 capturer_.reset(VideoFrameCapturer::Create()); |
| 33 } | 45 } |
| 34 | 46 |
| 35 void AddDirtyRect() { | 47 void AddDirtyRect() { |
| 36 SkIRect rect = SkIRect::MakeXYWH(0, 0, 10, 10); | 48 SkIRect rect = SkIRect::MakeXYWH(0, 0, 10, 10); |
| 37 region_.op(rect, SkRegion::kUnion_Op); | 49 region_.op(rect, SkRegion::kUnion_Op); |
| 38 } | 50 } |
| 39 | 51 |
| 40 scoped_ptr<VideoFrameCapturer> capturer_; | 52 scoped_ptr<VideoFrameCapturer> capturer_; |
| 53 MockVideoFrameCapturerDelegate delegate_; |
| 41 SkRegion region_; | 54 SkRegion region_; |
| 42 }; | 55 }; |
| 43 | 56 |
| 44 // CapturerCallback1 verifies that the whole screen is initially dirty. | 57 void VideoFrameCapturerMacTest::CaptureDoneCallback1( |
| 45 class VideoFrameCapturerCallback1 { | |
| 46 public: | |
| 47 VideoFrameCapturerCallback1() {} | |
| 48 | |
| 49 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data); | |
| 50 | |
| 51 private: | |
| 52 DISALLOW_COPY_AND_ASSIGN(VideoFrameCapturerCallback1); | |
| 53 }; | |
| 54 | |
| 55 void VideoFrameCapturerCallback1::CaptureDoneCallback( | |
| 56 scoped_refptr<CaptureData> capture_data) { | 58 scoped_refptr<CaptureData> capture_data) { |
| 57 CGDirectDisplayID mainDevice = CGMainDisplayID(); | 59 CGDirectDisplayID mainDevice = CGMainDisplayID(); |
| 58 int width = CGDisplayPixelsWide(mainDevice); | 60 int width = CGDisplayPixelsWide(mainDevice); |
| 59 int height = CGDisplayPixelsHigh(mainDevice); | 61 int height = CGDisplayPixelsHigh(mainDevice); |
| 60 SkRegion initial_region(SkIRect::MakeXYWH(0, 0, width, height)); | 62 SkRegion initial_region(SkIRect::MakeXYWH(0, 0, width, height)); |
| 61 EXPECT_EQ(initial_region, capture_data->dirty_region()); | 63 EXPECT_EQ(initial_region, capture_data->dirty_region()); |
| 62 } | 64 } |
| 63 | 65 |
| 64 // VideoFrameCapturerCallback2 verifies that a rectangle explicitly marked as | 66 void VideoFrameCapturerMacTest::CaptureDoneCallback2( |
| 65 // dirty is propagated correctly. | |
| 66 class VideoFrameCapturerCallback2 { | |
| 67 public: | |
| 68 explicit VideoFrameCapturerCallback2(const SkRegion& expected_dirty_region) | |
| 69 : expected_dirty_region_(expected_dirty_region) {} | |
| 70 | |
| 71 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data); | |
| 72 | |
| 73 protected: | |
| 74 SkRegion expected_dirty_region_; | |
| 75 | |
| 76 private: | |
| 77 DISALLOW_COPY_AND_ASSIGN(VideoFrameCapturerCallback2); | |
| 78 }; | |
| 79 | |
| 80 void VideoFrameCapturerCallback2::CaptureDoneCallback( | |
| 81 scoped_refptr<CaptureData> capture_data) { | 67 scoped_refptr<CaptureData> capture_data) { |
| 82 CGDirectDisplayID mainDevice = CGMainDisplayID(); | 68 CGDirectDisplayID mainDevice = CGMainDisplayID(); |
| 83 int width = CGDisplayPixelsWide(mainDevice); | 69 int width = CGDisplayPixelsWide(mainDevice); |
| 84 int height = CGDisplayPixelsHigh(mainDevice); | 70 int height = CGDisplayPixelsHigh(mainDevice); |
| 85 | 71 |
| 86 EXPECT_EQ(expected_dirty_region_, capture_data->dirty_region()); | 72 EXPECT_EQ(region_, capture_data->dirty_region()); |
| 87 EXPECT_EQ(width, capture_data->size().width()); | 73 EXPECT_EQ(width, capture_data->size().width()); |
| 88 EXPECT_EQ(height, capture_data->size().height()); | 74 EXPECT_EQ(height, capture_data->size().height()); |
| 89 const DataPlanes &planes = capture_data->data_planes(); | 75 const DataPlanes &planes = capture_data->data_planes(); |
| 90 EXPECT_TRUE(planes.data[0] != NULL); | 76 EXPECT_TRUE(planes.data[0] != NULL); |
| 91 EXPECT_TRUE(planes.data[1] == NULL); | 77 EXPECT_TRUE(planes.data[1] == NULL); |
| 92 EXPECT_TRUE(planes.data[2] == NULL); | 78 EXPECT_TRUE(planes.data[2] == NULL); |
| 93 // Depending on the capture method, the screen may be flipped or not, so | 79 // Depending on the capture method, the screen may be flipped or not, so |
| 94 // the stride may be positive or negative. | 80 // the stride may be positive or negative. |
| 95 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width), | 81 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width), |
| 96 abs(planes.strides[0])); | 82 abs(planes.strides[0])); |
| 97 EXPECT_EQ(0, planes.strides[1]); | 83 EXPECT_EQ(0, planes.strides[1]); |
| 98 EXPECT_EQ(0, planes.strides[2]); | 84 EXPECT_EQ(0, planes.strides[2]); |
| 99 } | 85 } |
| 100 | 86 |
| 101 class CursorCallback { | |
| 102 public: | |
| 103 CursorCallback() {} | |
| 104 | |
| 105 void CursorShapeChangedCallback( | |
| 106 scoped_ptr<protocol::CursorShapeInfo> cursor_data); | |
| 107 | |
| 108 private: | |
| 109 DISALLOW_COPY_AND_ASSIGN(CursorCallback); | |
| 110 }; | |
| 111 | |
| 112 void CursorCallback::CursorShapeChangedCallback( | |
| 113 scoped_ptr<protocol::CursorShapeInfo> cursor_data) { | |
| 114 } | |
| 115 | |
| 116 TEST_F(VideoFrameCapturerMacTest, Capture) { | 87 TEST_F(VideoFrameCapturerMacTest, Capture) { |
| 117 if (!CheckSnowLeopard()) { | 88 if (!CheckSnowLeopard()) { |
| 118 return; | 89 return; |
| 119 } | 90 } |
| 120 | 91 |
| 92 EXPECT_CALL(delegate_, OnCaptureCompleted(_)) |
| 93 .Times(2) |
| 94 .WillOnce(Invoke(this, &VideoFrameCapturerMacTest::CaptureDoneCallback1)) |
| 95 .WillOnce(Invoke(this, &VideoFrameCapturerMacTest::CaptureDoneCallback2)); |
| 96 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_)) |
| 97 .Times(AnyNumber()); |
| 98 |
| 121 SCOPED_TRACE(""); | 99 SCOPED_TRACE(""); |
| 122 CursorCallback cursor_callback; | 100 capturer_->Start(&delegate_); |
| 123 capturer_->Start(base::Bind(&CursorCallback::CursorShapeChangedCallback, | 101 |
| 124 base::Unretained(&cursor_callback))); | |
| 125 // Check that we get an initial full-screen updated. | 102 // Check that we get an initial full-screen updated. |
| 126 VideoFrameCapturerCallback1 callback1; | 103 capturer_->CaptureInvalidRegion(); |
| 127 capturer_->CaptureInvalidRegion(base::Bind( | 104 |
| 128 &VideoFrameCapturerCallback1::CaptureDoneCallback, | |
| 129 base::Unretained(&callback1))); | |
| 130 // Check that subsequent dirty rects are propagated correctly. | 105 // Check that subsequent dirty rects are propagated correctly. |
| 131 AddDirtyRect(); | 106 AddDirtyRect(); |
| 132 VideoFrameCapturerCallback2 callback2(region_); | |
| 133 capturer_->InvalidateRegion(region_); | 107 capturer_->InvalidateRegion(region_); |
| 134 capturer_->CaptureInvalidRegion(base::Bind( | 108 capturer_->CaptureInvalidRegion(); |
| 135 &VideoFrameCapturerCallback2::CaptureDoneCallback, | |
| 136 base::Unretained(&callback2))); | |
| 137 capturer_->Stop(); | 109 capturer_->Stop(); |
| 138 } | 110 } |
| 139 | 111 |
| 140 } // namespace remoting | 112 } // namespace remoting |
| 141 | 113 |
| 142 namespace gfx { | 114 namespace gfx { |
| 143 | 115 |
| 144 std::ostream& operator<<(std::ostream& out, const SkRegion& region) { | 116 std::ostream& operator<<(std::ostream& out, const SkRegion& region) { |
| 145 out << "SkRegion("; | 117 out << "SkRegion("; |
| 146 for (SkRegion::Iterator i(region); !i.done(); i.next()) { | 118 for (SkRegion::Iterator i(region); !i.done(); i.next()) { |
| 147 const SkIRect& r = i.rect(); | 119 const SkIRect& r = i.rect(); |
| 148 out << "(" << r.fLeft << "," << r.fTop << "," | 120 out << "(" << r.fLeft << "," << r.fTop << "," |
| 149 << r.fRight << "," << r.fBottom << ")"; | 121 << r.fRight << "," << r.fBottom << ")"; |
| 150 } | 122 } |
| 151 out << ")"; | 123 out << ")"; |
| 152 return out; | 124 return out; |
| 153 } | 125 } |
| 154 | 126 |
| 155 } // namespace gfx | 127 } // namespace gfx |
| OLD | NEW |