Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: content/common/cc_messages.cc

Issue 21271002: Added SkImageFilter serialization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Skia API changes Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/common/cc_messages.h" 5 #include "content/common/cc_messages.h"
6 6
7 #include "base/command_line.h"
7 #include "cc/output/compositor_frame.h" 8 #include "cc/output/compositor_frame.h"
8 #include "cc/output/filter_operations.h" 9 #include "cc/output/filter_operations.h"
9 #include "content/public/common/common_param_traits.h" 10 #include "content/public/common/common_param_traits.h"
11 #include "content/public/common/content_switches.h"
12 #include "third_party/skia/include/core/SkData.h"
13 #include "third_party/skia/include/core/SkFlattenableSerialization.h"
10 #include "ui/gfx/transform.h" 14 #include "ui/gfx/transform.h"
11 15
12 namespace IPC { 16 namespace IPC {
13 17
14 void ParamTraits<cc::FilterOperation>::Write( 18 void ParamTraits<cc::FilterOperation>::Write(
15 Message* m, const param_type& p) { 19 Message* m, const param_type& p) {
16 WriteParam(m, p.type()); 20 WriteParam(m, p.type());
17 switch (p.type()) { 21 switch (p.type()) {
18 case cc::FilterOperation::GRAYSCALE: 22 case cc::FilterOperation::GRAYSCALE:
19 case cc::FilterOperation::SEPIA: 23 case cc::FilterOperation::SEPIA:
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 const param_type& p, std::string* l) { 182 const param_type& p, std::string* l) {
179 l->append("("); 183 l->append("(");
180 for (std::size_t i = 0; i < p.size(); ++i) { 184 for (std::size_t i = 0; i < p.size(); ++i) {
181 if (i) 185 if (i)
182 l->append(", "); 186 l->append(", ");
183 LogParam(p.at(i), l); 187 LogParam(p.at(i), l);
184 } 188 }
185 l->append(")"); 189 l->append(")");
186 } 190 }
187 191
192 void ParamTraits<skia::RefPtr<SkImageFilter> >::Write(
193 Message* m, const param_type& p) {
194 SkImageFilter* filter = p.get();
195 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
196 if (filter && command_line.HasSwitch(switches::kAllowFiltersOverIPC)) {
197 skia::RefPtr<SkData> data = skia::AdoptRef(SkSerializeFlattenable(filter));
198 m->WriteData(static_cast<const char*>(data->data()), data->size());
199 } else {
200 m->WriteData(0, 0);
201 }
202 }
203
204 bool ParamTraits<skia::RefPtr<SkImageFilter> >::Read(
205 const Message* m, PickleIterator* iter, param_type* r) {
206 const char* data = 0;
207 int length = 0;
208 if (!m->ReadData(iter, &data, &length))
209 return false;
210 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
211 if ((length > 0) && command_line.HasSwitch(switches::kAllowFiltersOverIPC)) {
212 SkFlattenable* flattenable = SkDeserializeFlattenable(data, length);
213 *r = skia::AdoptRef(static_cast<SkImageFilter*>(flattenable));
piman 2013/08/09 17:38:24 Even after we make the deserialization safe in Ski
214 } else {
215 r->clear();
216 }
217 return true;
218 }
219
220 void ParamTraits<skia::RefPtr<SkImageFilter> >::Log(
221 const param_type& p, std::string* l) {
222 l->append("(");
223 LogParam(p.get() ? p->countInputs() : 0, l);
224 l->append(")");
225 }
226
188 void ParamTraits<gfx::Transform>::Write( 227 void ParamTraits<gfx::Transform>::Write(
189 Message* m, const param_type& p) { 228 Message* m, const param_type& p) {
190 WriteParam(m, p.matrix().getDouble(0, 0)); 229 WriteParam(m, p.matrix().getDouble(0, 0));
191 WriteParam(m, p.matrix().getDouble(1, 0)); 230 WriteParam(m, p.matrix().getDouble(1, 0));
192 WriteParam(m, p.matrix().getDouble(2, 0)); 231 WriteParam(m, p.matrix().getDouble(2, 0));
193 WriteParam(m, p.matrix().getDouble(3, 0)); 232 WriteParam(m, p.matrix().getDouble(3, 0));
194 WriteParam(m, p.matrix().getDouble(0, 1)); 233 WriteParam(m, p.matrix().getDouble(0, 1));
195 WriteParam(m, p.matrix().getDouble(1, 1)); 234 WriteParam(m, p.matrix().getDouble(1, 1));
196 WriteParam(m, p.matrix().getDouble(2, 1)); 235 WriteParam(m, p.matrix().getDouble(2, 1));
197 WriteParam(m, p.matrix().getDouble(3, 1)); 236 WriteParam(m, p.matrix().getDouble(3, 1));
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 l->append(", ["); 746 l->append(", [");
708 for (size_t i = 0; i < p.render_pass_list.size(); ++i) { 747 for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
709 if (i) 748 if (i)
710 l->append(", "); 749 l->append(", ");
711 LogParam(*p.render_pass_list[i], l); 750 LogParam(*p.render_pass_list[i], l);
712 } 751 }
713 l->append("])"); 752 l->append("])");
714 } 753 }
715 754
716 } // namespace IPC 755 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698