| 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 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 9 | 9 |
| 10 namespace IPC { | 10 namespace IPC { |
| 11 | 11 |
| 12 // static | 12 // static |
| 13 void ParamTraits<webrtc::DesktopVector>::Write(Message* m, | 13 void ParamTraits<webrtc::DesktopVector>::Write(Message* m, |
| 14 const webrtc::DesktopVector& p) { | 14 const webrtc::DesktopVector& p) { |
| 15 m->WriteInt(p.x()); | 15 m->WriteInt(p.x()); |
| 16 m->WriteInt(p.y()); | 16 m->WriteInt(p.y()); |
| 17 } | 17 } |
| 18 | 18 |
| 19 // static | 19 // static |
| 20 bool ParamTraits<webrtc::DesktopVector>::Read(const Message* m, | 20 bool ParamTraits<webrtc::DesktopVector>::Read(const Message* m, |
| 21 PickleIterator* iter, | 21 PickleIterator* iter, |
| 22 webrtc::DesktopVector* r) { | 22 webrtc::DesktopVector* r) { |
| 23 int x, y; | 23 int x, y; |
| 24 if (!iter->ReadInt(&x) || !iter->ReadInt(&y)) | 24 if (!m->ReadInt(iter, &x) || !m->ReadInt(iter, &y)) |
| 25 return false; | 25 return false; |
| 26 *r = webrtc::DesktopVector(x, y); | 26 *r = webrtc::DesktopVector(x, y); |
| 27 return true; | 27 return true; |
| 28 } | 28 } |
| 29 | 29 |
| 30 // static | 30 // static |
| 31 void ParamTraits<webrtc::DesktopVector>::Log(const webrtc::DesktopVector& p, | 31 void ParamTraits<webrtc::DesktopVector>::Log(const webrtc::DesktopVector& p, |
| 32 std::string* l) { | 32 std::string* l) { |
| 33 l->append(base::StringPrintf("webrtc::DesktopVector(%d, %d)", | 33 l->append(base::StringPrintf("webrtc::DesktopVector(%d, %d)", |
| 34 p.x(), p.y())); | 34 p.x(), p.y())); |
| 35 } | 35 } |
| 36 | 36 |
| 37 // static | 37 // static |
| 38 void ParamTraits<webrtc::DesktopSize>::Write(Message* m, | 38 void ParamTraits<webrtc::DesktopSize>::Write(Message* m, |
| 39 const webrtc::DesktopSize& p) { | 39 const webrtc::DesktopSize& p) { |
| 40 m->WriteInt(p.width()); | 40 m->WriteInt(p.width()); |
| 41 m->WriteInt(p.height()); | 41 m->WriteInt(p.height()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // static | 44 // static |
| 45 bool ParamTraits<webrtc::DesktopSize>::Read(const Message* m, | 45 bool ParamTraits<webrtc::DesktopSize>::Read(const Message* m, |
| 46 PickleIterator* iter, | 46 PickleIterator* iter, |
| 47 webrtc::DesktopSize* r) { | 47 webrtc::DesktopSize* r) { |
| 48 int width, height; | 48 int width, height; |
| 49 if (!iter->ReadInt(&width) || !iter->ReadInt(&height)) | 49 if (!m->ReadInt(iter, &width) || !m->ReadInt(iter, &height)) |
| 50 return false; | 50 return false; |
| 51 *r = webrtc::DesktopSize(width, height); | 51 *r = webrtc::DesktopSize(width, height); |
| 52 return true; | 52 return true; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // static | 55 // static |
| 56 void ParamTraits<webrtc::DesktopSize>::Log(const webrtc::DesktopSize& p, | 56 void ParamTraits<webrtc::DesktopSize>::Log(const webrtc::DesktopSize& p, |
| 57 std::string* l) { | 57 std::string* l) { |
| 58 l->append(base::StringPrintf("webrtc::DesktopSize(%d, %d)", | 58 l->append(base::StringPrintf("webrtc::DesktopSize(%d, %d)", |
| 59 p.width(), p.height())); | 59 p.width(), p.height())); |
| 60 } | 60 } |
| 61 | 61 |
| 62 // static | 62 // static |
| 63 void ParamTraits<webrtc::DesktopRect>::Write(Message* m, | 63 void ParamTraits<webrtc::DesktopRect>::Write(Message* m, |
| 64 const webrtc::DesktopRect& p) { | 64 const webrtc::DesktopRect& p) { |
| 65 m->WriteInt(p.left()); | 65 m->WriteInt(p.left()); |
| 66 m->WriteInt(p.top()); | 66 m->WriteInt(p.top()); |
| 67 m->WriteInt(p.right()); | 67 m->WriteInt(p.right()); |
| 68 m->WriteInt(p.bottom()); | 68 m->WriteInt(p.bottom()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // static | 71 // static |
| 72 bool ParamTraits<webrtc::DesktopRect>::Read(const Message* m, | 72 bool ParamTraits<webrtc::DesktopRect>::Read(const Message* m, |
| 73 PickleIterator* iter, | 73 PickleIterator* iter, |
| 74 webrtc::DesktopRect* r) { | 74 webrtc::DesktopRect* r) { |
| 75 int left, right, top, bottom; | 75 int left, right, top, bottom; |
| 76 if (!iter->ReadInt(&left) || !iter->ReadInt(&top) || | 76 if (!m->ReadInt(iter, &left) || !m->ReadInt(iter, &top) || |
| 77 !iter->ReadInt(&right) || !iter->ReadInt(&bottom)) { | 77 !m->ReadInt(iter, &right) || !m->ReadInt(iter, &bottom)) { |
| 78 return false; | 78 return false; |
| 79 } | 79 } |
| 80 *r = webrtc::DesktopRect::MakeLTRB(left, top, right, bottom); | 80 *r = webrtc::DesktopRect::MakeLTRB(left, top, right, bottom); |
| 81 return true; | 81 return true; |
| 82 } | 82 } |
| 83 | 83 |
| 84 // static | 84 // static |
| 85 void ParamTraits<webrtc::DesktopRect>::Log(const webrtc::DesktopRect& p, | 85 void ParamTraits<webrtc::DesktopRect>::Log(const webrtc::DesktopRect& p, |
| 86 std::string* l) { | 86 std::string* l) { |
| 87 l->append(base::StringPrintf("webrtc::DesktopRect(%d, %d, %d, %d)", | 87 l->append(base::StringPrintf("webrtc::DesktopRect(%d, %d, %d, %d)", |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 size.width() <= 0 || size.width() > (SHRT_MAX / 2) || | 119 size.width() <= 0 || size.width() > (SHRT_MAX / 2) || |
| 120 size.height() <= 0 || size.height() > (SHRT_MAX / 2)) { | 120 size.height() <= 0 || size.height() > (SHRT_MAX / 2)) { |
| 121 return false; | 121 return false; |
| 122 } | 122 } |
| 123 | 123 |
| 124 const int expected_length = | 124 const int expected_length = |
| 125 size.width() * size.height() * webrtc::DesktopFrame::kBytesPerPixel; | 125 size.width() * size.height() * webrtc::DesktopFrame::kBytesPerPixel; |
| 126 | 126 |
| 127 const char* data; | 127 const char* data; |
| 128 int data_length; | 128 int data_length; |
| 129 if (!iter->ReadData(&data, &data_length) || data_length != expected_length) | 129 if (!m->ReadData(iter, &data, &data_length) || |
| 130 data_length != expected_length) { |
| 130 return false; | 131 return false; |
| 132 } |
| 131 | 133 |
| 132 webrtc::DesktopVector hotspot; | 134 webrtc::DesktopVector hotspot; |
| 133 if (!ParamTraits<webrtc::DesktopVector>::Read(m, iter, &hotspot)) | 135 if (!ParamTraits<webrtc::DesktopVector>::Read(m, iter, &hotspot)) |
| 134 return false; | 136 return false; |
| 135 | 137 |
| 136 webrtc::BasicDesktopFrame* image = new webrtc::BasicDesktopFrame(size); | 138 webrtc::BasicDesktopFrame* image = new webrtc::BasicDesktopFrame(size); |
| 137 memcpy(image->data(), data, data_length); | 139 memcpy(image->data(), data, data_length); |
| 138 | 140 |
| 139 r->set_image(image); | 141 r->set_image(image); |
| 140 r->set_hotspot(hotspot); | 142 r->set_hotspot(hotspot); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 void ParamTraits<remoting::ScreenResolution>::Log( | 185 void ParamTraits<remoting::ScreenResolution>::Log( |
| 184 const remoting::ScreenResolution& p, | 186 const remoting::ScreenResolution& p, |
| 185 std::string* l) { | 187 std::string* l) { |
| 186 l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)", | 188 l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)", |
| 187 p.dimensions().width(), p.dimensions().height(), | 189 p.dimensions().width(), p.dimensions().height(), |
| 188 p.dpi().x(), p.dpi().y())); | 190 p.dpi().x(), p.dpi().y())); |
| 189 } | 191 } |
| 190 | 192 |
| 191 } // namespace IPC | 193 } // namespace IPC |
| 192 | 194 |
| OLD | NEW |