OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/gfx/ipc/gfx_param_traits.h" | 5 #include "ui/gfx/ipc/gfx_param_traits.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "third_party/skia/include/core/SkBitmap.h" | 9 #include "third_party/skia/include/core/SkBitmap.h" |
10 #include "ui/gfx/rect.h" | 10 #include "ui/gfx/rect.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 namespace IPC { | 52 namespace IPC { |
53 | 53 |
54 void ParamTraits<gfx::Point>::Write(Message* m, const gfx::Point& p) { | 54 void ParamTraits<gfx::Point>::Write(Message* m, const gfx::Point& p) { |
55 m->WriteInt(p.x()); | 55 m->WriteInt(p.x()); |
56 m->WriteInt(p.y()); | 56 m->WriteInt(p.y()); |
57 } | 57 } |
58 | 58 |
59 bool ParamTraits<gfx::Point>::Read(const Message* m, PickleIterator* iter, | 59 bool ParamTraits<gfx::Point>::Read(const Message* m, PickleIterator* iter, |
60 gfx::Point* r) { | 60 gfx::Point* r) { |
61 int x, y; | 61 int x, y; |
62 if (!iter->ReadInt(&x) || | 62 if (!m->ReadInt(iter, &x) || |
63 !iter->ReadInt(&y)) | 63 !m->ReadInt(iter, &y)) |
64 return false; | 64 return false; |
65 r->set_x(x); | 65 r->set_x(x); |
66 r->set_y(y); | 66 r->set_y(y); |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 void ParamTraits<gfx::Point>::Log(const gfx::Point& p, std::string* l) { | 70 void ParamTraits<gfx::Point>::Log(const gfx::Point& p, std::string* l) { |
71 l->append(base::StringPrintf("(%d, %d)", p.x(), p.y())); | 71 l->append(base::StringPrintf("(%d, %d)", p.x(), p.y())); |
72 } | 72 } |
73 | 73 |
(...skipping 22 matching lines...) Expand all Loading... |
96 DCHECK_GE(p.width(), 0); | 96 DCHECK_GE(p.width(), 0); |
97 DCHECK_GE(p.height(), 0); | 97 DCHECK_GE(p.height(), 0); |
98 int values[2] = { p.width(), p.height() }; | 98 int values[2] = { p.width(), p.height() }; |
99 m->WriteBytes(&values, sizeof(int) * 2); | 99 m->WriteBytes(&values, sizeof(int) * 2); |
100 } | 100 } |
101 | 101 |
102 bool ParamTraits<gfx::Size>::Read(const Message* m, | 102 bool ParamTraits<gfx::Size>::Read(const Message* m, |
103 PickleIterator* iter, | 103 PickleIterator* iter, |
104 gfx::Size* r) { | 104 gfx::Size* r) { |
105 const char* char_values; | 105 const char* char_values; |
106 if (!iter->ReadBytes(&char_values, sizeof(int) * 2)) | 106 if (!m->ReadBytes(iter, &char_values, sizeof(int) * 2)) |
107 return false; | 107 return false; |
108 const int* values = reinterpret_cast<const int*>(char_values); | 108 const int* values = reinterpret_cast<const int*>(char_values); |
109 if (values[0] < 0 || values[1] < 0) | 109 if (values[0] < 0 || values[1] < 0) |
110 return false; | 110 return false; |
111 r->set_width(values[0]); | 111 r->set_width(values[0]); |
112 r->set_height(values[1]); | 112 r->set_height(values[1]); |
113 return true; | 113 return true; |
114 } | 114 } |
115 | 115 |
116 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { | 116 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { |
117 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); | 117 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); |
118 } | 118 } |
119 | 119 |
120 void ParamTraits<gfx::SizeF>::Write(Message* m, const gfx::SizeF& p) { | 120 void ParamTraits<gfx::SizeF>::Write(Message* m, const gfx::SizeF& p) { |
121 float values[2] = { p.width(), p.height() }; | 121 float values[2] = { p.width(), p.height() }; |
122 m->WriteBytes(&values, sizeof(float) * 2); | 122 m->WriteBytes(&values, sizeof(float) * 2); |
123 } | 123 } |
124 | 124 |
125 bool ParamTraits<gfx::SizeF>::Read(const Message* m, | 125 bool ParamTraits<gfx::SizeF>::Read(const Message* m, |
126 PickleIterator* iter, | 126 PickleIterator* iter, |
127 gfx::SizeF* r) { | 127 gfx::SizeF* r) { |
128 const char* char_values; | 128 const char* char_values; |
129 if (!iter->ReadBytes(&char_values, sizeof(float) * 2)) | 129 if (!m->ReadBytes(iter, &char_values, sizeof(float) * 2)) |
130 return false; | 130 return false; |
131 const float* values = reinterpret_cast<const float*>(char_values); | 131 const float* values = reinterpret_cast<const float*>(char_values); |
132 r->set_width(values[0]); | 132 r->set_width(values[0]); |
133 r->set_height(values[1]); | 133 r->set_height(values[1]); |
134 return true; | 134 return true; |
135 } | 135 } |
136 | 136 |
137 void ParamTraits<gfx::SizeF>::Log(const gfx::SizeF& p, std::string* l) { | 137 void ParamTraits<gfx::SizeF>::Log(const gfx::SizeF& p, std::string* l) { |
138 l->append(base::StringPrintf("(%f, %f)", p.width(), p.height())); | 138 l->append(base::StringPrintf("(%f, %f)", p.width(), p.height())); |
139 } | 139 } |
140 | 140 |
141 void ParamTraits<gfx::Vector2d>::Write(Message* m, const gfx::Vector2d& p) { | 141 void ParamTraits<gfx::Vector2d>::Write(Message* m, const gfx::Vector2d& p) { |
142 int values[2] = { p.x(), p.y() }; | 142 int values[2] = { p.x(), p.y() }; |
143 m->WriteBytes(&values, sizeof(int) * 2); | 143 m->WriteBytes(&values, sizeof(int) * 2); |
144 } | 144 } |
145 | 145 |
146 bool ParamTraits<gfx::Vector2d>::Read(const Message* m, | 146 bool ParamTraits<gfx::Vector2d>::Read(const Message* m, |
147 PickleIterator* iter, | 147 PickleIterator* iter, |
148 gfx::Vector2d* r) { | 148 gfx::Vector2d* r) { |
149 const char* char_values; | 149 const char* char_values; |
150 if (!iter->ReadBytes(&char_values, sizeof(int) * 2)) | 150 if (!m->ReadBytes(iter, &char_values, sizeof(int) * 2)) |
151 return false; | 151 return false; |
152 const int* values = reinterpret_cast<const int*>(char_values); | 152 const int* values = reinterpret_cast<const int*>(char_values); |
153 r->set_x(values[0]); | 153 r->set_x(values[0]); |
154 r->set_y(values[1]); | 154 r->set_y(values[1]); |
155 return true; | 155 return true; |
156 } | 156 } |
157 | 157 |
158 void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) { | 158 void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) { |
159 l->append(base::StringPrintf("(%d, %d)", v.x(), v.y())); | 159 l->append(base::StringPrintf("(%d, %d)", v.x(), v.y())); |
160 } | 160 } |
161 | 161 |
162 void ParamTraits<gfx::Vector2dF>::Write(Message* m, const gfx::Vector2dF& p) { | 162 void ParamTraits<gfx::Vector2dF>::Write(Message* m, const gfx::Vector2dF& p) { |
163 float values[2] = { p.x(), p.y() }; | 163 float values[2] = { p.x(), p.y() }; |
164 m->WriteBytes(&values, sizeof(float) * 2); | 164 m->WriteBytes(&values, sizeof(float) * 2); |
165 } | 165 } |
166 | 166 |
167 bool ParamTraits<gfx::Vector2dF>::Read(const Message* m, | 167 bool ParamTraits<gfx::Vector2dF>::Read(const Message* m, |
168 PickleIterator* iter, | 168 PickleIterator* iter, |
169 gfx::Vector2dF* r) { | 169 gfx::Vector2dF* r) { |
170 const char* char_values; | 170 const char* char_values; |
171 if (!iter->ReadBytes(&char_values, sizeof(float) * 2)) | 171 if (!m->ReadBytes(iter, &char_values, sizeof(float) * 2)) |
172 return false; | 172 return false; |
173 const float* values = reinterpret_cast<const float*>(char_values); | 173 const float* values = reinterpret_cast<const float*>(char_values); |
174 r->set_x(values[0]); | 174 r->set_x(values[0]); |
175 r->set_y(values[1]); | 175 r->set_y(values[1]); |
176 return true; | 176 return true; |
177 } | 177 } |
178 | 178 |
179 void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) { | 179 void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) { |
180 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); | 180 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); |
181 } | 181 } |
182 | 182 |
183 void ParamTraits<gfx::Rect>::Write(Message* m, const gfx::Rect& p) { | 183 void ParamTraits<gfx::Rect>::Write(Message* m, const gfx::Rect& p) { |
184 int values[4] = { p.x(), p.y(), p.width(), p.height() }; | 184 int values[4] = { p.x(), p.y(), p.width(), p.height() }; |
185 m->WriteBytes(&values, sizeof(int) * 4); | 185 m->WriteBytes(&values, sizeof(int) * 4); |
186 } | 186 } |
187 | 187 |
188 bool ParamTraits<gfx::Rect>::Read(const Message* m, | 188 bool ParamTraits<gfx::Rect>::Read(const Message* m, |
189 PickleIterator* iter, | 189 PickleIterator* iter, |
190 gfx::Rect* r) { | 190 gfx::Rect* r) { |
191 const char* char_values; | 191 const char* char_values; |
192 if (!iter->ReadBytes(&char_values, sizeof(int) * 4)) | 192 if (!m->ReadBytes(iter, &char_values, sizeof(int) * 4)) |
193 return false; | 193 return false; |
194 const int* values = reinterpret_cast<const int*>(char_values); | 194 const int* values = reinterpret_cast<const int*>(char_values); |
195 if (values[2] < 0 || values[3] < 0) | 195 if (values[2] < 0 || values[3] < 0) |
196 return false; | 196 return false; |
197 r->SetRect(values[0], values[1], values[2], values[3]); | 197 r->SetRect(values[0], values[1], values[2], values[3]); |
198 return true; | 198 return true; |
199 } | 199 } |
200 | 200 |
201 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { | 201 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { |
202 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), | 202 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), |
203 p.width(), p.height())); | 203 p.width(), p.height())); |
204 } | 204 } |
205 | 205 |
206 void ParamTraits<gfx::RectF>::Write(Message* m, const gfx::RectF& p) { | 206 void ParamTraits<gfx::RectF>::Write(Message* m, const gfx::RectF& p) { |
207 float values[4] = { p.x(), p.y(), p.width(), p.height() }; | 207 float values[4] = { p.x(), p.y(), p.width(), p.height() }; |
208 m->WriteBytes(&values, sizeof(float) * 4); | 208 m->WriteBytes(&values, sizeof(float) * 4); |
209 } | 209 } |
210 | 210 |
211 bool ParamTraits<gfx::RectF>::Read(const Message* m, | 211 bool ParamTraits<gfx::RectF>::Read(const Message* m, |
212 PickleIterator* iter, | 212 PickleIterator* iter, |
213 gfx::RectF* r) { | 213 gfx::RectF* r) { |
214 const char* char_values; | 214 const char* char_values; |
215 if (!iter->ReadBytes(&char_values, sizeof(float) * 4)) | 215 if (!m->ReadBytes(iter, &char_values, sizeof(float) * 4)) |
216 return false; | 216 return false; |
217 const float* values = reinterpret_cast<const float*>(char_values); | 217 const float* values = reinterpret_cast<const float*>(char_values); |
218 r->SetRect(values[0], values[1], values[2], values[3]); | 218 r->SetRect(values[0], values[1], values[2], values[3]); |
219 return true; | 219 return true; |
220 } | 220 } |
221 | 221 |
222 void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) { | 222 void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) { |
223 l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(), | 223 l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(), |
224 p.width(), p.height())); | 224 p.width(), p.height())); |
225 } | 225 } |
226 | 226 |
227 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { | 227 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { |
228 size_t fixed_size = sizeof(SkBitmap_Data); | 228 size_t fixed_size = sizeof(SkBitmap_Data); |
229 SkBitmap_Data bmp_data; | 229 SkBitmap_Data bmp_data; |
230 bmp_data.InitSkBitmapDataForTransfer(p); | 230 bmp_data.InitSkBitmapDataForTransfer(p); |
231 m->WriteData(reinterpret_cast<const char*>(&bmp_data), | 231 m->WriteData(reinterpret_cast<const char*>(&bmp_data), |
232 static_cast<int>(fixed_size)); | 232 static_cast<int>(fixed_size)); |
233 size_t pixel_size = p.getSize(); | 233 size_t pixel_size = p.getSize(); |
234 SkAutoLockPixels p_lock(p); | 234 SkAutoLockPixels p_lock(p); |
235 m->WriteData(reinterpret_cast<const char*>(p.getPixels()), | 235 m->WriteData(reinterpret_cast<const char*>(p.getPixels()), |
236 static_cast<int>(pixel_size)); | 236 static_cast<int>(pixel_size)); |
237 } | 237 } |
238 | 238 |
239 bool ParamTraits<SkBitmap>::Read(const Message* m, | 239 bool ParamTraits<SkBitmap>::Read(const Message* m, |
240 PickleIterator* iter, | 240 PickleIterator* iter, |
241 SkBitmap* r) { | 241 SkBitmap* r) { |
242 const char* fixed_data; | 242 const char* fixed_data; |
243 int fixed_data_size = 0; | 243 int fixed_data_size = 0; |
244 if (!iter->ReadData(&fixed_data, &fixed_data_size) || | 244 if (!m->ReadData(iter, &fixed_data, &fixed_data_size) || |
245 (fixed_data_size <= 0)) { | 245 (fixed_data_size <= 0)) { |
246 NOTREACHED(); | 246 NOTREACHED(); |
247 return false; | 247 return false; |
248 } | 248 } |
249 if (fixed_data_size != sizeof(SkBitmap_Data)) | 249 if (fixed_data_size != sizeof(SkBitmap_Data)) |
250 return false; // Message is malformed. | 250 return false; // Message is malformed. |
251 | 251 |
252 const char* variable_data; | 252 const char* variable_data; |
253 int variable_data_size = 0; | 253 int variable_data_size = 0; |
254 if (!iter->ReadData(&variable_data, &variable_data_size) || | 254 if (!m->ReadData(iter, &variable_data, &variable_data_size) || |
255 (variable_data_size < 0)) { | 255 (variable_data_size < 0)) { |
256 NOTREACHED(); | 256 NOTREACHED(); |
257 return false; | 257 return false; |
258 } | 258 } |
259 const SkBitmap_Data* bmp_data = | 259 const SkBitmap_Data* bmp_data = |
260 reinterpret_cast<const SkBitmap_Data*>(fixed_data); | 260 reinterpret_cast<const SkBitmap_Data*>(fixed_data); |
261 return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); | 261 return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); |
262 } | 262 } |
263 | 263 |
264 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) { | 264 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) { |
265 l->append("<SkBitmap>"); | 265 l->append("<SkBitmap>"); |
266 } | 266 } |
267 | 267 |
268 } // namespace IPC | 268 } // namespace IPC |
OLD | NEW |