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"
12 void ParamTraits
<webrtc::DesktopVector
>::Write(Message
* m
,
13 const webrtc::DesktopVector
& p
) {
19 bool ParamTraits
<webrtc::DesktopVector
>::Read(const Message
* m
,
21 webrtc::DesktopVector
* r
) {
23 if (!m
->ReadInt(iter
, &x
) || !m
->ReadInt(iter
, &y
))
25 *r
= webrtc::DesktopVector(x
, y
);
30 void ParamTraits
<webrtc::DesktopVector
>::Log(const webrtc::DesktopVector
& p
,
32 l
->append(base::StringPrintf("webrtc::DesktopVector(%d, %d)",
37 void ParamTraits
<webrtc::DesktopSize
>::Write(Message
* m
,
38 const webrtc::DesktopSize
& p
) {
39 m
->WriteInt(p
.width());
40 m
->WriteInt(p
.height());
44 bool ParamTraits
<webrtc::DesktopSize
>::Read(const Message
* m
,
46 webrtc::DesktopSize
* r
) {
48 if (!m
->ReadInt(iter
, &width
) || !m
->ReadInt(iter
, &height
))
50 *r
= webrtc::DesktopSize(width
, height
);
55 void ParamTraits
<webrtc::DesktopSize
>::Log(const webrtc::DesktopSize
& p
,
57 l
->append(base::StringPrintf("webrtc::DesktopSize(%d, %d)",
58 p
.width(), p
.height()));
62 void ParamTraits
<webrtc::DesktopRect
>::Write(Message
* m
,
63 const webrtc::DesktopRect
& p
) {
64 m
->WriteInt(p
.left());
66 m
->WriteInt(p
.right());
67 m
->WriteInt(p
.bottom());
71 bool ParamTraits
<webrtc::DesktopRect
>::Read(const Message
* m
,
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
)) {
79 *r
= webrtc::DesktopRect::MakeLTRB(left
, top
, right
, bottom
);
84 void ParamTraits
<webrtc::DesktopRect
>::Log(const webrtc::DesktopRect
& p
,
86 l
->append(base::StringPrintf("webrtc::DesktopRect(%d, %d, %d, %d)",
87 p
.left(), p
.top(), p
.right(), p
.bottom()));
91 void ParamTraits
<remoting::ScreenResolution
>::Write(
93 const remoting::ScreenResolution
& p
) {
94 ParamTraits
<webrtc::DesktopSize
>::Write(m
, p
.dimensions());
95 ParamTraits
<webrtc::DesktopVector
>::Write(m
, p
.dpi());
99 bool ParamTraits
<remoting::ScreenResolution
>::Read(
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
)) {
109 if (size
.width() < 0 || size
.height() < 0 ||
110 dpi
.x() < 0 || dpi
.y() < 0) {
113 *r
= remoting::ScreenResolution(size
, dpi
);
118 void ParamTraits
<remoting::ScreenResolution
>::Log(
119 const remoting::ScreenResolution
& p
,
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()));