Roll third_party/android_tools to the latest: updated the support library to 19.0.1
[chromium-blink-merge.git] / remoting / host / chromoting_param_traits.cc
blob8b10a7f764308bca6d501b4399a94be2f7891ea4
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
3 // found in the LICENSE file.
5 #include "remoting/host/chromoting_param_traits.h"
7 #include "base/strings/stringprintf.h"
9 namespace IPC {
11 // static
12 void ParamTraits<webrtc::DesktopVector>::Write(Message* m,
13 const webrtc::DesktopVector& p) {
14 m->WriteInt(p.x());
15 m->WriteInt(p.y());
18 // static
19 bool ParamTraits<webrtc::DesktopVector>::Read(const Message* m,
20 PickleIterator* iter,
21 webrtc::DesktopVector* r) {
22 int x, y;
23 if (!m->ReadInt(iter, &x) || !m->ReadInt(iter, &y))
24 return false;
25 *r = webrtc::DesktopVector(x, y);
26 return true;
29 // static
30 void ParamTraits<webrtc::DesktopVector>::Log(const webrtc::DesktopVector& p,
31 std::string* l) {
32 l->append(base::StringPrintf("webrtc::DesktopVector(%d, %d)",
33 p.x(), p.y()));
36 // static
37 void ParamTraits<webrtc::DesktopSize>::Write(Message* m,
38 const webrtc::DesktopSize& p) {
39 m->WriteInt(p.width());
40 m->WriteInt(p.height());
43 // static
44 bool ParamTraits<webrtc::DesktopSize>::Read(const Message* m,
45 PickleIterator* iter,
46 webrtc::DesktopSize* r) {
47 int width, height;
48 if (!m->ReadInt(iter, &width) || !m->ReadInt(iter, &height))
49 return false;
50 *r = webrtc::DesktopSize(width, height);
51 return true;
54 // static
55 void ParamTraits<webrtc::DesktopSize>::Log(const webrtc::DesktopSize& p,
56 std::string* l) {
57 l->append(base::StringPrintf("webrtc::DesktopSize(%d, %d)",
58 p.width(), p.height()));
61 // static
62 void ParamTraits<webrtc::DesktopRect>::Write(Message* m,
63 const webrtc::DesktopRect& p) {
64 m->WriteInt(p.left());
65 m->WriteInt(p.top());
66 m->WriteInt(p.right());
67 m->WriteInt(p.bottom());
70 // static
71 bool ParamTraits<webrtc::DesktopRect>::Read(const Message* m,
72 PickleIterator* iter,
73 webrtc::DesktopRect* r) {
74 int left, right, top, bottom;
75 if (!m->ReadInt(iter, &left) || !m->ReadInt(iter, &top) ||
76 !m->ReadInt(iter, &right) || !m->ReadInt(iter, &bottom)) {
77 return false;
79 *r = webrtc::DesktopRect::MakeLTRB(left, top, right, bottom);
80 return true;
83 // static
84 void ParamTraits<webrtc::DesktopRect>::Log(const webrtc::DesktopRect& p,
85 std::string* l) {
86 l->append(base::StringPrintf("webrtc::DesktopRect(%d, %d, %d, %d)",
87 p.left(), p.top(), p.right(), p.bottom()));
90 // static
91 void ParamTraits<remoting::ScreenResolution>::Write(
92 Message* m,
93 const remoting::ScreenResolution& p) {
94 ParamTraits<webrtc::DesktopSize>::Write(m, p.dimensions());
95 ParamTraits<webrtc::DesktopVector>::Write(m, p.dpi());
98 // static
99 bool ParamTraits<remoting::ScreenResolution>::Read(
100 const Message* m,
101 PickleIterator* iter,
102 remoting::ScreenResolution* r) {
103 webrtc::DesktopSize size;
104 webrtc::DesktopVector dpi;
105 if (!ParamTraits<webrtc::DesktopSize>::Read(m, iter, &size) ||
106 !ParamTraits<webrtc::DesktopVector>::Read(m, iter, &dpi)) {
107 return false;
109 if (size.width() < 0 || size.height() < 0 ||
110 dpi.x() < 0 || dpi.y() < 0) {
111 return false;
113 *r = remoting::ScreenResolution(size, dpi);
114 return true;
117 // static
118 void ParamTraits<remoting::ScreenResolution>::Log(
119 const remoting::ScreenResolution& p,
120 std::string* l) {
121 l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)",
122 p.dimensions().width(), p.dimensions().height(),
123 p.dpi().x(), p.dpi().y()));
126 } // namespace IPC