| 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/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 CapturerMacTest : public testing::Test { | |
| 30 protected: | |
| 31 virtual void SetUp() { | |
| 32 capturer_.reset(Capturer::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<Capturer> capturer_; | |
| 41 SkRegion region_; | |
| 42 }; | |
| 43 | |
| 44 // CapturerCallback1 verifies that the whole screen is initially dirty. | |
| 45 class CapturerCallback1 { | |
| 46 public: | |
| 47 CapturerCallback1() { } | |
| 48 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data); | |
| 49 | |
| 50 private: | |
| 51 DISALLOW_COPY_AND_ASSIGN(CapturerCallback1); | |
| 52 }; | |
| 53 | |
| 54 void CapturerCallback1::CaptureDoneCallback( | |
| 55 scoped_refptr<CaptureData> capture_data) { | |
| 56 CGDirectDisplayID mainDevice = CGMainDisplayID(); | |
| 57 int width = CGDisplayPixelsWide(mainDevice); | |
| 58 int height = CGDisplayPixelsHigh(mainDevice); | |
| 59 SkRegion initial_region(SkIRect::MakeXYWH(0, 0, width, height)); | |
| 60 EXPECT_EQ(initial_region, capture_data->dirty_region()); | |
| 61 } | |
| 62 | |
| 63 // CapturerCallback2 verifies that a rectangle explicitly marked as dirty is | |
| 64 // propagated correctly. | |
| 65 class CapturerCallback2 { | |
| 66 public: | |
| 67 explicit CapturerCallback2(const SkRegion& expected_dirty_region) | |
| 68 : expected_dirty_region_(expected_dirty_region) { } | |
| 69 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data); | |
| 70 | |
| 71 protected: | |
| 72 SkRegion expected_dirty_region_; | |
| 73 | |
| 74 private: | |
| 75 DISALLOW_COPY_AND_ASSIGN(CapturerCallback2); | |
| 76 }; | |
| 77 | |
| 78 void CapturerCallback2::CaptureDoneCallback( | |
| 79 scoped_refptr<CaptureData> capture_data) { | |
| 80 CGDirectDisplayID mainDevice = CGMainDisplayID(); | |
| 81 int width = CGDisplayPixelsWide(mainDevice); | |
| 82 int height = CGDisplayPixelsHigh(mainDevice); | |
| 83 | |
| 84 EXPECT_EQ(expected_dirty_region_, capture_data->dirty_region()); | |
| 85 EXPECT_EQ(width, capture_data->size().width()); | |
| 86 EXPECT_EQ(height, capture_data->size().height()); | |
| 87 const DataPlanes &planes = capture_data->data_planes(); | |
| 88 EXPECT_TRUE(planes.data[0] != NULL); | |
| 89 EXPECT_TRUE(planes.data[1] == NULL); | |
| 90 EXPECT_TRUE(planes.data[2] == NULL); | |
| 91 // Depending on the capture method, the screen may be flipped or not, so | |
| 92 // the stride may be positive or negative. | |
| 93 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width), | |
| 94 abs(planes.strides[0])); | |
| 95 EXPECT_EQ(0, planes.strides[1]); | |
| 96 EXPECT_EQ(0, planes.strides[2]); | |
| 97 } | |
| 98 | |
| 99 class CursorCallback { | |
| 100 public: | |
| 101 CursorCallback() { } | |
| 102 void CursorShapeChangedCallback( | |
| 103 scoped_ptr<protocol::CursorShapeInfo> cursor_data); | |
| 104 | |
| 105 private: | |
| 106 DISALLOW_COPY_AND_ASSIGN(CursorCallback); | |
| 107 }; | |
| 108 | |
| 109 void CursorCallback::CursorShapeChangedCallback( | |
| 110 scoped_ptr<protocol::CursorShapeInfo> cursor_data) { | |
| 111 } | |
| 112 | |
| 113 TEST_F(CapturerMacTest, Capture) { | |
| 114 if (!CheckSnowLeopard()) { | |
| 115 return; | |
| 116 } | |
| 117 | |
| 118 SCOPED_TRACE(""); | |
| 119 CursorCallback cursor_callback; | |
| 120 capturer_->Start(base::Bind(&CursorCallback::CursorShapeChangedCallback, | |
| 121 base::Unretained(&cursor_callback))); | |
| 122 // Check that we get an initial full-screen updated. | |
| 123 CapturerCallback1 callback1; | |
| 124 capturer_->CaptureInvalidRegion(base::Bind( | |
| 125 &CapturerCallback1::CaptureDoneCallback, base::Unretained(&callback1))); | |
| 126 // Check that subsequent dirty rects are propagated correctly. | |
| 127 AddDirtyRect(); | |
| 128 CapturerCallback2 callback2(region_); | |
| 129 capturer_->InvalidateRegion(region_); | |
| 130 capturer_->CaptureInvalidRegion(base::Bind( | |
| 131 &CapturerCallback2::CaptureDoneCallback, base::Unretained(&callback2))); | |
| 132 capturer_->Stop(); | |
| 133 } | |
| 134 | |
| 135 } // namespace remoting | |
| 136 | |
| 137 namespace gfx { | |
| 138 | |
| 139 std::ostream& operator<<(std::ostream& out, const SkRegion& region) { | |
| 140 out << "SkRegion("; | |
| 141 for (SkRegion::Iterator i(region); !i.done(); i.next()) { | |
| 142 const SkIRect& r = i.rect(); | |
| 143 out << "(" << r.fLeft << "," << r.fTop << "," | |
| 144 << r.fRight << "," << r.fBottom << ")"; | |
| 145 } | |
| 146 out << ")"; | |
| 147 return out; | |
| 148 } | |
| 149 | |
| 150 } // namespace gfx | |
| OLD | NEW |