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 |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 // Verifies that a rectangle explicitly marked as dirty is propagated | 29 // Verifies that a rectangle explicitly marked as dirty is propagated |
30 // correctly. | 30 // correctly. |
31 void CaptureDoneCallback2(scoped_refptr<ScreenCaptureData> capture_data); | 31 void CaptureDoneCallback2(scoped_refptr<ScreenCaptureData> capture_data); |
32 | 32 |
33 protected: | 33 protected: |
34 virtual void SetUp() OVERRIDE { | 34 virtual void SetUp() OVERRIDE { |
35 capturer_ = ScreenCapturer::Create(); | 35 capturer_ = ScreenCapturer::Create(); |
36 } | 36 } |
37 | 37 |
38 void AddDirtyRect() { | |
39 SkIRect rect = SkIRect::MakeXYWH(0, 0, 10, 10); | |
40 region_.op(rect, SkRegion::kUnion_Op); | |
41 } | |
42 | |
43 scoped_ptr<ScreenCapturer> capturer_; | 38 scoped_ptr<ScreenCapturer> capturer_; |
44 MockScreenCapturerDelegate delegate_; | 39 MockScreenCapturerDelegate delegate_; |
45 SkRegion region_; | |
46 }; | 40 }; |
47 | 41 |
48 void ScreenCapturerMacTest::CaptureDoneCallback1( | 42 void ScreenCapturerMacTest::CaptureDoneCallback1( |
49 scoped_refptr<ScreenCaptureData> capture_data) { | 43 scoped_refptr<ScreenCaptureData> capture_data) { |
50 CGDirectDisplayID mainDevice = CGMainDisplayID(); | 44 CGDirectDisplayID mainDevice = CGMainDisplayID(); |
51 int width = CGDisplayPixelsWide(mainDevice); | 45 int width = CGDisplayPixelsWide(mainDevice); |
52 int height = CGDisplayPixelsHigh(mainDevice); | 46 int height = CGDisplayPixelsHigh(mainDevice); |
53 SkRegion initial_region(SkIRect::MakeXYWH(0, 0, width, height)); | 47 SkRegion initial_region(SkIRect::MakeXYWH(0, 0, width, height)); |
54 EXPECT_EQ(initial_region, capture_data->dirty_region()); | 48 EXPECT_EQ(initial_region, capture_data->dirty_region()); |
55 } | 49 } |
56 | 50 |
57 void ScreenCapturerMacTest::CaptureDoneCallback2( | 51 void ScreenCapturerMacTest::CaptureDoneCallback2( |
58 scoped_refptr<ScreenCaptureData> capture_data) { | 52 scoped_refptr<ScreenCaptureData> capture_data) { |
59 CGDirectDisplayID mainDevice = CGMainDisplayID(); | 53 CGDirectDisplayID mainDevice = CGMainDisplayID(); |
60 int width = CGDisplayPixelsWide(mainDevice); | 54 int width = CGDisplayPixelsWide(mainDevice); |
61 int height = CGDisplayPixelsHigh(mainDevice); | 55 int height = CGDisplayPixelsHigh(mainDevice); |
62 | 56 |
63 EXPECT_EQ(region_, capture_data->dirty_region()); | |
64 EXPECT_EQ(width, capture_data->size().width()); | 57 EXPECT_EQ(width, capture_data->size().width()); |
65 EXPECT_EQ(height, capture_data->size().height()); | 58 EXPECT_EQ(height, capture_data->size().height()); |
66 EXPECT_TRUE(capture_data->data() != NULL); | 59 EXPECT_TRUE(capture_data->data() != NULL); |
67 // Depending on the capture method, the screen may be flipped or not, so | 60 // Depending on the capture method, the screen may be flipped or not, so |
68 // the stride may be positive or negative. | 61 // the stride may be positive or negative. |
69 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width), | 62 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width), |
70 abs(capture_data->stride())); | 63 abs(capture_data->stride())); |
71 } | 64 } |
72 | 65 |
73 TEST_F(ScreenCapturerMacTest, Capture) { | 66 TEST_F(ScreenCapturerMacTest, Capture) { |
74 EXPECT_CALL(delegate_, OnCaptureCompleted(_)) | 67 EXPECT_CALL(delegate_, OnCaptureCompleted(_)) |
75 .Times(2) | 68 .Times(2) |
76 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback1)) | 69 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback1)) |
77 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback2)); | 70 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback2)); |
78 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_)) | 71 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_)) |
79 .Times(AnyNumber()); | 72 .Times(AnyNumber()); |
80 | 73 |
81 EXPECT_CALL(delegate_, CreateSharedBuffer(_)) | 74 EXPECT_CALL(delegate_, CreateSharedBuffer(_)) |
82 .Times(AnyNumber()) | 75 .Times(AnyNumber()) |
83 .WillRepeatedly(Return(scoped_refptr<SharedBuffer>())); | 76 .WillRepeatedly(Return(scoped_refptr<SharedBuffer>())); |
84 | 77 |
85 SCOPED_TRACE(""); | 78 SCOPED_TRACE(""); |
86 capturer_->Start(&delegate_); | 79 capturer_->Start(&delegate_); |
87 | 80 |
88 // Check that we get an initial full-screen updated. | 81 // Check that we get an initial full-screen updated. |
89 capturer_->CaptureFrame(); | 82 capturer_->CaptureFrame(); |
90 | 83 |
91 // Check that subsequent dirty rects are propagated correctly. | 84 // Check that subsequent dirty rects are propagated correctly. |
92 AddDirtyRect(); | |
93 capturer_->InvalidateRegion(region_); | |
94 capturer_->CaptureFrame(); | 85 capturer_->CaptureFrame(); |
95 capturer_->Stop(); | |
96 } | 86 } |
97 | 87 |
98 } // namespace media | 88 } // namespace media |
99 | 89 |
100 namespace gfx { | 90 namespace gfx { |
101 | 91 |
102 std::ostream& operator<<(std::ostream& out, const SkRegion& region) { | 92 std::ostream& operator<<(std::ostream& out, const SkRegion& region) { |
103 out << "SkRegion("; | 93 out << "SkRegion("; |
104 for (SkRegion::Iterator i(region); !i.done(); i.next()) { | 94 for (SkRegion::Iterator i(region); !i.done(); i.next()) { |
105 const SkIRect& r = i.rect(); | 95 const SkIRect& r = i.rect(); |
106 out << "(" << r.fLeft << "," << r.fTop << "," | 96 out << "(" << r.fLeft << "," << r.fTop << "," |
107 << r.fRight << "," << r.fBottom << ")"; | 97 << r.fRight << "," << r.fBottom << ")"; |
108 } | 98 } |
109 out << ")"; | 99 out << ")"; |
110 return out; | 100 return out; |
111 } | 101 } |
112 | 102 |
113 } // namespace gfx | 103 } // namespace gfx |
OLD | NEW |