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( | |
|
Cris Neckar
2013/12/11 20:59:40
This just reads as strange. I would get rid of the
Sergey Ulanov
2013/12/11 21:16:37
webrtc::MouseCursor is immutable and it doesn't ha
Cris Neckar
2013/12/11 21:47:12
What is the scope of this object exactly? I assume
dcaiafa
2014/01/23 19:15:39
MouseCursor is now mutable so I removed the hack.
| |
| 93 Message* m, | |
| 94 const scoped_ptr<webrtc::MouseCursor>& p) { | |
| 95 CHECK(p.get()); | |
| 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; | |
| 124 } | |
| 125 | |
| 126 const int expected_length = | |
| 127 size.width() * size.height() * webrtc::DesktopFrame::kBytesPerPixel; | |
| 128 | |
| 129 const char* data; | |
| 130 int data_length; | |
| 131 if (!m->ReadData(iter, &data, &data_length) || | |
| 132 data_length != expected_length) { | |
| 133 return false; | |
| 134 } | |
| 135 | |
| 136 webrtc::DesktopVector hotspot; | |
| 137 if (!ParamTraits<webrtc::DesktopVector>::Read(m, iter, &hotspot)) | |
| 138 return false; | |
| 139 | |
| 140 webrtc::BasicDesktopFrame* image = new webrtc::BasicDesktopFrame(size); | |
| 141 memcpy(image->data(), data, data_length); | |
| 142 r->reset(new webrtc::MouseCursor(image, hotspot)); | |
| 143 return true; | |
| 144 } | |
| 145 | |
| 146 // static | |
| 147 void ParamTraits<scoped_ptr<webrtc::MouseCursor>>::Log( | |
| 148 const scoped_ptr<webrtc::MouseCursor>& p, | |
| 149 std::string* l) { | |
| 150 CHECK(p.get()); | |
| 151 l->append(base::StringPrintf( | |
| 152 "webrtc::DesktopRect{image(%d, %d), hotspot(%d, %d)}", | |
| 153 p->image().size().width(), p->image().size().height(), | |
| 154 p->hotspot().x(), p->hotspot().y())); | |
| 155 } | |
| 156 | |
| 157 | |
| 158 // static | |
| 91 void ParamTraits<remoting::ScreenResolution>::Write( | 159 void ParamTraits<remoting::ScreenResolution>::Write( |
| 92 Message* m, | 160 Message* m, |
| 93 const remoting::ScreenResolution& p) { | 161 const remoting::ScreenResolution& p) { |
| 94 ParamTraits<webrtc::DesktopSize>::Write(m, p.dimensions()); | 162 ParamTraits<webrtc::DesktopSize>::Write(m, p.dimensions()); |
| 95 ParamTraits<webrtc::DesktopVector>::Write(m, p.dpi()); | 163 ParamTraits<webrtc::DesktopVector>::Write(m, p.dpi()); |
| 96 } | 164 } |
| 97 | 165 |
| 98 // static | 166 // static |
| 99 bool ParamTraits<remoting::ScreenResolution>::Read( | 167 bool ParamTraits<remoting::ScreenResolution>::Read( |
| 100 const Message* m, | 168 const Message* m, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 118 void ParamTraits<remoting::ScreenResolution>::Log( | 186 void ParamTraits<remoting::ScreenResolution>::Log( |
| 119 const remoting::ScreenResolution& p, | 187 const remoting::ScreenResolution& p, |
| 120 std::string* l) { | 188 std::string* l) { |
| 121 l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)", | 189 l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)", |
| 122 p.dimensions().width(), p.dimensions().height(), | 190 p.dimensions().width(), p.dimensions().height(), |
| 123 p.dpi().x(), p.dpi().y())); | 191 p.dpi().x(), p.dpi().y())); |
| 124 } | 192 } |
| 125 | 193 |
| 126 } // namespace IPC | 194 } // namespace IPC |
| 127 | 195 |
| OLD | NEW |