Chromium Code Reviews| 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<scoped_ptr<webrtc::MouseCursor>>::Write( | |
| 93 Message* m, | |
| 94 const scoped_ptr<webrtc::MouseCursor>& p) { | |
| 95 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->(
| |
| 96 | |
| 97 ParamTraits<webrtc::DesktopSize>::Write(m, p->image().size()); | |
| 98 | |
| 99 // Data is serialized in such a way that size is exactly width * height * | |
| 100 // |kBytesPerPixel|. | |
| 101 std::string data; | |
| 102 uint8_t* current_row = p->image().data(); | |
| 103 for (int y = 0; y < p->image().size().height(); ++y) { | |
| 104 data.append(current_row, | |
| 105 current_row + p->image().size().width() * | |
| 106 webrtc::DesktopFrame::kBytesPerPixel); | |
| 107 current_row += p->image().stride(); | |
| 108 } | |
| 109 m->WriteData(reinterpret_cast<const char*>(p->image().data()), data.size()); | |
| 110 | |
| 111 ParamTraits<webrtc::DesktopVector>::Write(m, p->hotspot()); | |
| 112 } | |
| 113 | |
| 114 // static | |
| 115 bool ParamTraits<scoped_ptr<webrtc::MouseCursor>>::Read( | |
| 116 const Message* m, | |
| 117 PickleIterator* iter, | |
| 118 scoped_ptr<webrtc::MouseCursor>* r) { | |
| 119 webrtc::DesktopSize size; | |
| 120 if (!ParamTraits<webrtc::DesktopSize>::Read(m, iter, &size) || | |
| 121 size.width() <= 0 || size.width() > (SHRT_MAX / 2) || | |
| 122 size.height() <= 0 || size.height() > (SHRT_MAX / 2)) | |
| 123 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.
| |
| 124 | |
| 125 const int expected_length = | |
| 126 size.width() * size.height() * webrtc::DesktopFrame::kBytesPerPixel; | |
| 127 | |
| 128 const char* data; | |
| 129 int data_length; | |
| 130 if (!m->ReadData(iter, &data, &data_length) || | |
| 131 data_length != expected_length) | |
| 132 return false; | |
| 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 r->reset(new webrtc::MouseCursor(image, hotspot)); | |
| 141 return true; | |
| 142 } | |
| 143 | |
| 144 // static | |
| 145 void ParamTraits<scoped_ptr<webrtc::MouseCursor>>::Log( | |
| 146 const scoped_ptr<webrtc::MouseCursor>& p, | |
| 147 std::string* l) { | |
| 148 CHECK(p.get()); | |
| 149 l->append(base::StringPrintf( | |
| 150 "webrtc::DesktopRect{image(%d, %d), hotspot(%d, %d)}", | |
| 151 p->image().size().width(), p->image().size().height(), | |
| 152 p->hotspot().x(), p->hotspot().y())); | |
| 153 } | |
| 154 | |
| 155 | |
| 156 // static | |
| 91 void ParamTraits<remoting::ScreenResolution>::Write( | 157 void ParamTraits<remoting::ScreenResolution>::Write( |
| 92 Message* m, | 158 Message* m, |
| 93 const remoting::ScreenResolution& p) { | 159 const remoting::ScreenResolution& p) { |
| 94 ParamTraits<webrtc::DesktopSize>::Write(m, p.dimensions()); | 160 ParamTraits<webrtc::DesktopSize>::Write(m, p.dimensions()); |
| 95 ParamTraits<webrtc::DesktopVector>::Write(m, p.dpi()); | 161 ParamTraits<webrtc::DesktopVector>::Write(m, p.dpi()); |
| 96 } | 162 } |
| 97 | 163 |
| 98 // static | 164 // static |
| 99 bool ParamTraits<remoting::ScreenResolution>::Read( | 165 bool ParamTraits<remoting::ScreenResolution>::Read( |
| 100 const Message* m, | 166 const Message* m, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 118 void ParamTraits<remoting::ScreenResolution>::Log( | 184 void ParamTraits<remoting::ScreenResolution>::Log( |
| 119 const remoting::ScreenResolution& p, | 185 const remoting::ScreenResolution& p, |
| 120 std::string* l) { | 186 std::string* l) { |
| 121 l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)", | 187 l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)", |
| 122 p.dimensions().width(), p.dimensions().height(), | 188 p.dimensions().width(), p.dimensions().height(), |
| 123 p.dpi().x(), p.dpi().y())); | 189 p.dpi().x(), p.dpi().y())); |
| 124 } | 190 } |
| 125 | 191 |
| 126 } // namespace IPC | 192 } // namespace IPC |
| 127 | 193 |
| OLD | NEW |