Chromium Code Reviews| Index: remoting/host/chromoting_param_traits.cc |
| diff --git a/remoting/host/chromoting_param_traits.cc b/remoting/host/chromoting_param_traits.cc |
| index 8b10a7f764308bca6d501b4399a94be2f7891ea4..074bbf9513e30c22b285686d840ae9b611886ca7 100644 |
| --- a/remoting/host/chromoting_param_traits.cc |
| +++ b/remoting/host/chromoting_param_traits.cc |
| @@ -5,6 +5,7 @@ |
| #include "remoting/host/chromoting_param_traits.h" |
| #include "base/strings/stringprintf.h" |
| +#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| namespace IPC { |
| @@ -88,6 +89,71 @@ void ParamTraits<webrtc::DesktopRect>::Log(const webrtc::DesktopRect& p, |
| } |
| // static |
| +void ParamTraits<scoped_ptr<webrtc::MouseCursor>>::Write( |
| + Message* m, |
| + const scoped_ptr<webrtc::MouseCursor>& p) { |
| + CHECK(p.get()); |
|
Sergey Ulanov
2013/12/10 03:09:35
Why do you need this CHECK()?
dcaiafa
2013/12/10 23:07:36
Because the scoped_ptr could be NULL. E.g.: Send(n
Sergey Ulanov
2013/12/11 00:55:59
right. My point was that scoped_ptr<>::operator->(
|
| + |
| + ParamTraits<webrtc::DesktopSize>::Write(m, p->image().size()); |
| + |
| + // Data is serialized in such a way that size is exactly width * height * |
| + // |kBytesPerPixel|. |
| + std::string data; |
| + uint8_t* current_row = p->image().data(); |
| + for (int y = 0; y < p->image().size().height(); ++y) { |
| + data.append(current_row, |
| + current_row + p->image().size().width() * |
| + webrtc::DesktopFrame::kBytesPerPixel); |
| + current_row += p->image().stride(); |
| + } |
| + m->WriteData(reinterpret_cast<const char*>(p->image().data()), data.size()); |
| + |
| + ParamTraits<webrtc::DesktopVector>::Write(m, p->hotspot()); |
| +} |
| + |
| +// static |
| +bool ParamTraits<scoped_ptr<webrtc::MouseCursor>>::Read( |
| + const Message* m, |
| + PickleIterator* iter, |
| + scoped_ptr<webrtc::MouseCursor>* r) { |
| + webrtc::DesktopSize size; |
| + if (!ParamTraits<webrtc::DesktopSize>::Read(m, iter, &size) || |
| + size.width() <= 0 || size.width() > (SHRT_MAX / 2) || |
| + size.height() <= 0 || size.height() > (SHRT_MAX / 2)) |
| + return false; |
|
Sergey Ulanov
2013/12/10 03:09:35
nit: add {} because the condition doesn't fit one
dcaiafa
2013/12/10 23:07:36
Done.
|
| + |
| + const int expected_length = |
| + size.width() * size.height() * webrtc::DesktopFrame::kBytesPerPixel; |
| + |
| + const char* data; |
| + int data_length; |
| + if (!m->ReadData(iter, &data, &data_length) || |
| + data_length != expected_length) |
| + return false; |
| + |
| + webrtc::DesktopVector hotspot; |
| + if (!ParamTraits<webrtc::DesktopVector>::Read(m, iter, &hotspot)) |
| + return false; |
| + |
| + webrtc::BasicDesktopFrame* image = new webrtc::BasicDesktopFrame(size); |
| + memcpy(image->data(), data, data_length); |
| + r->reset(new webrtc::MouseCursor(image, hotspot)); |
| + return true; |
| +} |
| + |
| +// static |
| +void ParamTraits<scoped_ptr<webrtc::MouseCursor>>::Log( |
| + const scoped_ptr<webrtc::MouseCursor>& p, |
| + std::string* l) { |
| + CHECK(p.get()); |
| + l->append(base::StringPrintf( |
| + "webrtc::DesktopRect{image(%d, %d), hotspot(%d, %d)}", |
| + p->image().size().width(), p->image().size().height(), |
| + p->hotspot().x(), p->hotspot().y())); |
| +} |
| + |
| + |
| +// static |
| void ParamTraits<remoting::ScreenResolution>::Write( |
| Message* m, |
| const remoting::ScreenResolution& p) { |