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/host/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/base/capture_data.h" |
| 15 #include "remoting/proto/control.pb.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 |
| 18 namespace remoting { |
| 19 |
| 20 // Verify that the OS is at least Snow Leopard (10.6). |
| 21 // Chromoting doesn't support 10.5 or earlier. |
| 22 bool CheckSnowLeopard() { |
| 23 long minorVersion, majorVersion; |
| 24 Gestalt(gestaltSystemVersionMajor, &majorVersion); |
| 25 Gestalt(gestaltSystemVersionMinor, &minorVersion); |
| 26 return majorVersion == 10 && minorVersion > 5; |
| 27 } |
| 28 |
| 29 class VideoFrameCapturerMacTest : public testing::Test { |
| 30 protected: |
| 31 virtual void SetUp() OVERRIDE { |
| 32 capturer_.reset(VideoFrameCapturer::Create()); |
| 33 } |
| 34 |
| 35 void AddDirtyRect() { |
| 36 SkIRect rect = SkIRect::MakeXYWH(0, 0, 10, 10); |
| 37 region_.op(rect, SkRegion::kUnion_Op); |
| 38 } |
| 39 |
| 40 scoped_ptr<VideoFrameCapturer> capturer_; |
| 41 SkRegion region_; |
| 42 }; |
| 43 |
| 44 // CapturerCallback1 verifies that the whole screen is initially dirty. |
| 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) { |
| 57 CGDirectDisplayID mainDevice = CGMainDisplayID(); |
| 58 int width = CGDisplayPixelsWide(mainDevice); |
| 59 int height = CGDisplayPixelsHigh(mainDevice); |
| 60 SkRegion initial_region(SkIRect::MakeXYWH(0, 0, width, height)); |
| 61 EXPECT_EQ(initial_region, capture_data->dirty_region()); |
| 62 } |
| 63 |
| 64 // VideoFrameCapturerCallback2 verifies that a rectangle explicitly marked as |
| 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) { |
| 82 CGDirectDisplayID mainDevice = CGMainDisplayID(); |
| 83 int width = CGDisplayPixelsWide(mainDevice); |
| 84 int height = CGDisplayPixelsHigh(mainDevice); |
| 85 |
| 86 EXPECT_EQ(expected_dirty_region_, capture_data->dirty_region()); |
| 87 EXPECT_EQ(width, capture_data->size().width()); |
| 88 EXPECT_EQ(height, capture_data->size().height()); |
| 89 const DataPlanes &planes = capture_data->data_planes(); |
| 90 EXPECT_TRUE(planes.data[0] != NULL); |
| 91 EXPECT_TRUE(planes.data[1] == NULL); |
| 92 EXPECT_TRUE(planes.data[2] == NULL); |
| 93 // Depending on the capture method, the screen may be flipped or not, so |
| 94 // the stride may be positive or negative. |
| 95 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width), |
| 96 abs(planes.strides[0])); |
| 97 EXPECT_EQ(0, planes.strides[1]); |
| 98 EXPECT_EQ(0, planes.strides[2]); |
| 99 } |
| 100 |
| 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) { |
| 117 if (!CheckSnowLeopard()) { |
| 118 return; |
| 119 } |
| 120 |
| 121 SCOPED_TRACE(""); |
| 122 CursorCallback cursor_callback; |
| 123 capturer_->Start(base::Bind(&CursorCallback::CursorShapeChangedCallback, |
| 124 base::Unretained(&cursor_callback))); |
| 125 // Check that we get an initial full-screen updated. |
| 126 VideoFrameCapturerCallback1 callback1; |
| 127 capturer_->CaptureInvalidRegion(base::Bind( |
| 128 &VideoFrameCapturerCallback1::CaptureDoneCallback, |
| 129 base::Unretained(&callback1))); |
| 130 // Check that subsequent dirty rects are propagated correctly. |
| 131 AddDirtyRect(); |
| 132 VideoFrameCapturerCallback2 callback2(region_); |
| 133 capturer_->InvalidateRegion(region_); |
| 134 capturer_->CaptureInvalidRegion(base::Bind( |
| 135 &VideoFrameCapturerCallback2::CaptureDoneCallback, |
| 136 base::Unretained(&callback2))); |
| 137 capturer_->Stop(); |
| 138 } |
| 139 |
| 140 } // namespace remoting |
| 141 |
| 142 namespace gfx { |
| 143 |
| 144 std::ostream& operator<<(std::ostream& out, const SkRegion& region) { |
| 145 out << "SkRegion("; |
| 146 for (SkRegion::Iterator i(region); !i.done(); i.next()) { |
| 147 const SkIRect& r = i.rect(); |
| 148 out << "(" << r.fLeft << "," << r.fTop << "," |
| 149 << r.fRight << "," << r.fBottom << ")"; |
| 150 } |
| 151 out << ")"; |
| 152 return out; |
| 153 } |
| 154 |
| 155 } // namespace gfx |
OLD | NEW |