Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: remoting/host/capturer_mac_unittest.cc

Issue 7491070: Switch over to using SkRegions to calculate dirty areas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clean up comments Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/capturer.h" 5 #include "remoting/host/capturer.h"
6 6
7 #include <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 8
9 #include <iostream> 9 #include <iostream>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "remoting/base/types.h"
14 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
15 14
16 namespace remoting { 15 namespace remoting {
17 16
18 class CapturerMacTest : public testing::Test { 17 class CapturerMacTest : public testing::Test {
19 protected: 18 protected:
20 virtual void SetUp() { 19 virtual void SetUp() {
21 capturer_.reset(Capturer::Create()); 20 capturer_.reset(Capturer::Create());
22 } 21 }
23 22
24 void AddDirtyRect() { 23 void AddDirtyRect() {
25 rects_.insert(gfx::Rect(0, 0, 10, 10)); 24 SkIRect rect = SkIRect::MakeXYWH(0, 0, 10, 10);
25 region_.op(rect, SkRegion::kUnion_Op);
26 } 26 }
27 27
28 scoped_ptr<Capturer> capturer_; 28 scoped_ptr<Capturer> capturer_;
29 InvalidRects rects_; 29 SkRegion region_;
30 }; 30 };
31 31
32 // CapturerCallback1 verifies that the whole screen is initially dirty. 32 // CapturerCallback1 verifies that the whole screen is initially dirty.
33 class CapturerCallback1 { 33 class CapturerCallback1 {
34 public: 34 public:
35 CapturerCallback1() { } 35 CapturerCallback1() { }
36 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data); 36 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data);
37 37
38 private: 38 private:
39 DISALLOW_COPY_AND_ASSIGN(CapturerCallback1); 39 DISALLOW_COPY_AND_ASSIGN(CapturerCallback1);
40 }; 40 };
41 41
42 void CapturerCallback1::CaptureDoneCallback( 42 void CapturerCallback1::CaptureDoneCallback(
43 scoped_refptr<CaptureData> capture_data) { 43 scoped_refptr<CaptureData> capture_data) {
44 CGDirectDisplayID mainDevice = CGMainDisplayID(); 44 CGDirectDisplayID mainDevice = CGMainDisplayID();
45 int width = CGDisplayPixelsWide(mainDevice); 45 int width = CGDisplayPixelsWide(mainDevice);
46 int height = CGDisplayPixelsHigh(mainDevice); 46 int height = CGDisplayPixelsHigh(mainDevice);
47 InvalidRects initial_rect; 47 SkRegion initial_region(SkIRect::MakeXYWH(0, 0, width, height));
48 initial_rect.insert(gfx::Rect(0, 0, width, height)); 48 EXPECT_EQ(initial_region, capture_data->dirty_region());
49 EXPECT_EQ(initial_rect, capture_data->dirty_rects());
50 } 49 }
51 50
52 // CapturerCallback2 verifies that a rectangle explicitly marked as dirty is 51 // CapturerCallback2 verifies that a rectangle explicitly marked as dirty is
53 // propagated correctly. 52 // propagated correctly.
54 class CapturerCallback2 { 53 class CapturerCallback2 {
55 public: 54 public:
56 explicit CapturerCallback2(const InvalidRects& expected_dirty_rects) 55 explicit CapturerCallback2(const SkRegion& expected_dirty_region)
57 : expected_dirty_rects_(expected_dirty_rects) { } 56 : expected_dirty_region_(expected_dirty_region) { }
58 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data); 57 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data);
59 58
60 protected: 59 protected:
61 InvalidRects expected_dirty_rects_; 60 SkRegion expected_dirty_region_;
62 61
63 private: 62 private:
64 DISALLOW_COPY_AND_ASSIGN(CapturerCallback2); 63 DISALLOW_COPY_AND_ASSIGN(CapturerCallback2);
65 }; 64 };
66 65
67 void CapturerCallback2::CaptureDoneCallback( 66 void CapturerCallback2::CaptureDoneCallback(
68 scoped_refptr<CaptureData> capture_data) { 67 scoped_refptr<CaptureData> capture_data) {
69 CGDirectDisplayID mainDevice = CGMainDisplayID(); 68 CGDirectDisplayID mainDevice = CGMainDisplayID();
70 int width = CGDisplayPixelsWide(mainDevice); 69 int width = CGDisplayPixelsWide(mainDevice);
71 int height = CGDisplayPixelsHigh(mainDevice); 70 int height = CGDisplayPixelsHigh(mainDevice);
72 71
73 EXPECT_EQ(expected_dirty_rects_, capture_data->dirty_rects()); 72 EXPECT_EQ(expected_dirty_region_, capture_data->dirty_region());
74 EXPECT_EQ(width, capture_data->size().width()); 73 EXPECT_EQ(width, capture_data->size().width());
75 EXPECT_EQ(height, capture_data->size().height()); 74 EXPECT_EQ(height, capture_data->size().height());
76 const DataPlanes &planes = capture_data->data_planes(); 75 const DataPlanes &planes = capture_data->data_planes();
77 EXPECT_TRUE(planes.data[0] != NULL); 76 EXPECT_TRUE(planes.data[0] != NULL);
78 EXPECT_TRUE(planes.data[1] == NULL); 77 EXPECT_TRUE(planes.data[1] == NULL);
79 EXPECT_TRUE(planes.data[2] == NULL); 78 EXPECT_TRUE(planes.data[2] == NULL);
80 // 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
81 // the stride may be positive or negative. 80 // the stride may be positive or negative.
82 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width), 81 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width),
83 abs(planes.strides[0])); 82 abs(planes.strides[0]));
84 EXPECT_EQ(0, planes.strides[1]); 83 EXPECT_EQ(0, planes.strides[1]);
85 EXPECT_EQ(0, planes.strides[2]); 84 EXPECT_EQ(0, planes.strides[2]);
86 } 85 }
87 86
88 TEST_F(CapturerMacTest, Capture) { 87 TEST_F(CapturerMacTest, Capture) {
89 SCOPED_TRACE(""); 88 SCOPED_TRACE("");
90 // Check that we get an initial full-screen updated. 89 // Check that we get an initial full-screen updated.
91 CapturerCallback1 callback1; 90 CapturerCallback1 callback1;
92 capturer_->CaptureInvalidRects( 91 capturer_->CaptureInvalidRegion(
93 NewCallback(&callback1, &CapturerCallback1::CaptureDoneCallback)); 92 NewCallback(&callback1, &CapturerCallback1::CaptureDoneCallback));
94 // Check that subsequent dirty rects are propagated correctly. 93 // Check that subsequent dirty rects are propagated correctly.
95 AddDirtyRect(); 94 AddDirtyRect();
96 CapturerCallback2 callback2(rects_); 95 CapturerCallback2 callback2(region_);
97 capturer_->InvalidateRects(rects_); 96 capturer_->InvalidateRegion(region_);
98 capturer_->CaptureInvalidRects( 97 capturer_->CaptureInvalidRegion(
99 NewCallback(&callback2, &CapturerCallback2::CaptureDoneCallback)); 98 NewCallback(&callback2, &CapturerCallback2::CaptureDoneCallback));
100 } 99 }
101 100
102 } // namespace remoting 101 } // namespace remoting
103 102
104 namespace gfx { 103 namespace gfx {
105 104
106 std::ostream& operator<<(std::ostream& out, 105 std::ostream& operator<<(std::ostream& out, const SkRegion& region) {
Wez 2011/08/08 20:49:34 Is there not already such an override?
dmac 2011/08/10 20:30:36 Not that I am aware of. There is a "tostring" but
107 const remoting::InvalidRects& rects) { 106 out << "SkRegion(";
108 for (remoting::InvalidRects::const_iterator i = rects.begin(); 107 for (SkRegion::Iterator i(region); !i.done(); i.next()) {
109 i != rects.end(); 108 const SkIRect& r = i.rect();
110 ++i) { 109 out << "(" << r.fLeft << "," << r.fTop << ","
111 out << *i << std::endl; 110 << r.fRight << "," << r.fBottom << ")";
112 } 111 }
112 out << ")";
113 return out; 113 return out;
114 } 114 }
115 115
116 } // namespace gfx 116 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698