OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromoting_param_traits.h" | 5 #include "remoting/host/chromoting_param_traits.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
8 | 9 |
9 namespace IPC { | 10 namespace IPC { |
10 | 11 |
11 // static | 12 // static |
12 void ParamTraits<webrtc::DesktopVector>::Write(Message* m, | 13 void ParamTraits<webrtc::DesktopVector>::Write(Message* m, |
13 const webrtc::DesktopVector& p) { | 14 const webrtc::DesktopVector& p) { |
14 m->WriteInt(p.x()); | 15 m->WriteInt(p.x()); |
15 m->WriteInt(p.y()); | 16 m->WriteInt(p.y()); |
16 } | 17 } |
17 | 18 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 82 } |
82 | 83 |
83 // static | 84 // static |
84 void ParamTraits<webrtc::DesktopRect>::Log(const webrtc::DesktopRect& p, | 85 void ParamTraits<webrtc::DesktopRect>::Log(const webrtc::DesktopRect& p, |
85 std::string* l) { | 86 std::string* l) { |
86 l->append(base::StringPrintf("webrtc::DesktopRect(%d, %d, %d, %d)", | 87 l->append(base::StringPrintf("webrtc::DesktopRect(%d, %d, %d, %d)", |
87 p.left(), p.top(), p.right(), p.bottom())); | 88 p.left(), p.top(), p.right(), p.bottom())); |
88 } | 89 } |
89 | 90 |
90 // static | 91 // static |
| 92 void ParamTraits<webrtc::MouseCursor>::Write( |
| 93 Message* m, |
| 94 const webrtc::MouseCursor& p) { |
| 95 ParamTraits<webrtc::DesktopSize>::Write(m, p.image()->size()); |
| 96 |
| 97 // Data is serialized in such a way that size is exactly width * height * |
| 98 // |kBytesPerPixel|. |
| 99 std::string data; |
| 100 uint8_t* current_row = p.image()->data(); |
| 101 for (int y = 0; y < p.image()->size().height(); ++y) { |
| 102 data.append(current_row, |
| 103 current_row + p.image()->size().width() * |
| 104 webrtc::DesktopFrame::kBytesPerPixel); |
| 105 current_row += p.image()->stride(); |
| 106 } |
| 107 m->WriteData(reinterpret_cast<const char*>(p.image()->data()), data.size()); |
| 108 |
| 109 ParamTraits<webrtc::DesktopVector>::Write(m, p.hotspot()); |
| 110 } |
| 111 |
| 112 // static |
| 113 bool ParamTraits<webrtc::MouseCursor>::Read( |
| 114 const Message* m, |
| 115 PickleIterator* iter, |
| 116 webrtc::MouseCursor* r) { |
| 117 webrtc::DesktopSize size; |
| 118 if (!ParamTraits<webrtc::DesktopSize>::Read(m, iter, &size) || |
| 119 size.width() <= 0 || size.width() > (SHRT_MAX / 2) || |
| 120 size.height() <= 0 || size.height() > (SHRT_MAX / 2)) { |
| 121 return false; |
| 122 } |
| 123 |
| 124 const int expected_length = |
| 125 size.width() * size.height() * webrtc::DesktopFrame::kBytesPerPixel; |
| 126 |
| 127 const char* data; |
| 128 int data_length; |
| 129 if (!m->ReadData(iter, &data, &data_length) || |
| 130 data_length != expected_length) { |
| 131 return false; |
| 132 } |
| 133 |
| 134 webrtc::DesktopVector hotspot; |
| 135 if (!ParamTraits<webrtc::DesktopVector>::Read(m, iter, &hotspot)) |
| 136 return false; |
| 137 |
| 138 webrtc::BasicDesktopFrame* image = new webrtc::BasicDesktopFrame(size); |
| 139 memcpy(image->data(), data, data_length); |
| 140 |
| 141 r->set_image(image); |
| 142 r->set_hotspot(hotspot); |
| 143 return true; |
| 144 } |
| 145 |
| 146 // static |
| 147 void ParamTraits<webrtc::MouseCursor>::Log( |
| 148 const webrtc::MouseCursor& p, |
| 149 std::string* l) { |
| 150 l->append(base::StringPrintf( |
| 151 "webrtc::DesktopRect{image(%d, %d), hotspot(%d, %d)}", |
| 152 p.image()->size().width(), p.image()->size().height(), |
| 153 p.hotspot().x(), p.hotspot().y())); |
| 154 } |
| 155 |
| 156 |
| 157 // static |
91 void ParamTraits<remoting::ScreenResolution>::Write( | 158 void ParamTraits<remoting::ScreenResolution>::Write( |
92 Message* m, | 159 Message* m, |
93 const remoting::ScreenResolution& p) { | 160 const remoting::ScreenResolution& p) { |
94 ParamTraits<webrtc::DesktopSize>::Write(m, p.dimensions()); | 161 ParamTraits<webrtc::DesktopSize>::Write(m, p.dimensions()); |
95 ParamTraits<webrtc::DesktopVector>::Write(m, p.dpi()); | 162 ParamTraits<webrtc::DesktopVector>::Write(m, p.dpi()); |
96 } | 163 } |
97 | 164 |
98 // static | 165 // static |
99 bool ParamTraits<remoting::ScreenResolution>::Read( | 166 bool ParamTraits<remoting::ScreenResolution>::Read( |
100 const Message* m, | 167 const Message* m, |
(...skipping 17 matching lines...) Expand all Loading... |
118 void ParamTraits<remoting::ScreenResolution>::Log( | 185 void ParamTraits<remoting::ScreenResolution>::Log( |
119 const remoting::ScreenResolution& p, | 186 const remoting::ScreenResolution& p, |
120 std::string* l) { | 187 std::string* l) { |
121 l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)", | 188 l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)", |
122 p.dimensions().width(), p.dimensions().height(), | 189 p.dimensions().width(), p.dimensions().height(), |
123 p.dpi().x(), p.dpi().y())); | 190 p.dpi().x(), p.dpi().y())); |
124 } | 191 } |
125 | 192 |
126 } // namespace IPC | 193 } // namespace IPC |
127 | 194 |
OLD | NEW |