Chromium Code Reviews| Index: content/common/fontmgr_messages.cc |
| =================================================================== |
| --- content/common/fontmgr_messages.cc (revision 0) |
| +++ content/common/fontmgr_messages.cc (working copy) |
| @@ -0,0 +1,173 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/common/fontmgr_messages.h" |
| + |
| +#include "skia/ext/refptr.h" |
| +#include "third_party/skia/include/core/SkDataTable.h" |
| +#include "third_party/skia/include/core/SkStream.h" |
| +#include "third_party/skia/include/core/SkString.h" |
| +#include "third_party/skia/include/ports/SkFontMgr_indirect.h" |
| +#include "third_party/skia/include/ports/SkFontStyle.h" |
| + |
| +namespace IPC { |
| +//SkString |
| +void ParamTraits<SkString>::Write(Message* m, const param_type& p) { |
| + m->WriteData(p.c_str(), static_cast<int>(p.size())); |
| +} |
| + |
| +bool ParamTraits<SkString>::Read( |
| + const Message* m, PickleIterator* iter, param_type* r) |
| +{ |
| + const char* data; |
| + int len; |
| + if (!m->ReadData(iter, &data, &len)) |
| + return false; |
| + |
| + r->set(data, len); |
| + return true; |
| +} |
| + |
| +void ParamTraits<SkString>::Log(const param_type& p, std::string* l) { |
| + *l = p.c_str(); |
| +} |
| + |
| +//skia::RefPtr<SkDataTable> |
| +void ParamTraits<skia::RefPtr<SkDataTable> >::Write( |
| + Message* m, const param_type& p) |
| +{ |
| + int count = p->count(); |
| + m->WriteInt(count); |
| + for (int i = 0; i < count; ++i) { |
| + m->WriteData(reinterpret_cast<const char *>(p->at(i)), p->atSize(i)); |
| + } |
| +} |
| + |
| +bool ParamTraits<skia::RefPtr<SkDataTable> >::Read( |
| + const Message* m, PickleIterator* iter, param_type* r) |
| +{ |
| + int count; |
| + if (!m->ReadLength(iter, &count)) |
| + return false; |
| + |
| + SkDataTableBuilder builder(1024); |
| + for (int i = 0; i < count; ++i) { |
| + const char* data; |
| + int len; |
| + if (!m->ReadData(iter, &data, &len)) |
| + return false; |
| + |
| + builder.append(data, len); |
| + } |
| + |
| + *r = skia::AdoptRef(builder.detachDataTable()); |
| + return true; |
| +} |
| + |
| +void ParamTraits<skia::RefPtr<SkDataTable> >::Log(const param_type& p, |
| + std::string* l) { |
| + *l = "SkDataTable"; |
| +} |
| + |
| +//skia::RefPtr<SkRemotableFontIdentitySet> |
| +void ParamTraits<skia::RefPtr<SkRemotableFontIdentitySet> >::Write( |
| + Message* m, const param_type& p) |
| +{ |
| + m->WriteData(reinterpret_cast<const char*>(p->fData), |
| + static_cast<int>(p->fCount * sizeof(SkFontIdentity))); |
| +} |
| + |
| +bool ParamTraits<skia::RefPtr<SkRemotableFontIdentitySet> >::Read( |
| + const Message* m, PickleIterator* iter, param_type* r) |
| +{ |
| + const char* data; |
| + int len; |
| + if (!m->ReadData(iter, &data, &len)) |
| + return false; |
| + |
| + int count = len / sizeof(SkFontIdentity); |
| + *r = skia::AdoptRef(new SkRemotableFontIdentitySet(count)); |
| + memcpy((*r)->fData, data, len); |
| + return true; |
| +} |
| + |
| +void ParamTraits<skia::RefPtr<SkRemotableFontIdentitySet> >::Log( |
| + const param_type& p, std::string* l) |
| +{ |
| + *l = "SkRemotableFontIdentitySet"; |
| +} |
| + |
| +//skia::RefPtr<SkStream> |
| +void ParamTraits<skia::RefPtr<SkStream> >::Write( |
| + Message* m, const param_type& p) |
| +{ |
| + if (!p->hasLength()) { |
| + m->WriteData(NULL, 0); |
|
brettw
2014/03/11 21:38:15
You have some 4-space indents floating around.
bungeman-chromium
2014/03/13 22:33:31
Done.
|
| + } |
| + int size = p->getLength(); |
| + const void* data = p->getMemoryBase(); |
| + if (data) { |
| + m->WriteData(reinterpret_cast<const char*>(data), static_cast<int>(size)); |
| + return; |
| + } |
| + |
| + // TODO: avoid this silly copy? |
| + void* copy = malloc(size); |
| + p->read(copy, size); |
| + m->WriteData(reinterpret_cast<const char*>(copy), static_cast<int>(size)); |
| + free(copy); |
| +} |
| + |
| +bool ParamTraits<skia::RefPtr<SkStream> >::Read( |
| + const Message* m, PickleIterator* iter, param_type* r) |
| +{ |
| + const char* data; |
| + int len; |
| + if (!m->ReadData(iter, &data, &len)) |
| + return false; |
| + |
| + *r = skia::AdoptRef(new SkMemoryStream(data, len, true)); |
| + return true; |
| +} |
| + |
| +void ParamTraits<skia::RefPtr<SkStream> >::Log( |
| + const param_type& p, std::string* l) |
| +{ |
| + *l = "stream"; |
| +} |
| + |
| +//SkFontStyle |
| +void ParamTraits<SkFontStyle>::Write(Message* m, const param_type& p) { |
| + m->WriteInt(p.weight()); |
| + m->WriteInt(p.width()); |
| + m->WriteInt(p.slant()); |
| +} |
| + |
| +bool ParamTraits<SkFontStyle>::Read( |
| + const Message* m, PickleIterator* iter, param_type* r) |
| +{ |
| + int weight; |
| + if (!ReadParam(m, iter, &weight)) |
| + return false; |
| + |
| + int width; |
| + if (!ReadParam(m, iter, &width)) |
| + return false; |
| + |
| + int slant; |
| + if (!ReadParam(m, iter, &slant)) |
| + return false; |
| + |
| + // TODO: trait these as enums |
| + *r = SkFontStyle((SkFontStyle::Weight)weight, |
| + (SkFontStyle::Width)width, |
| + (SkFontStyle::Slant)slant); |
| + return true; |
| +} |
| + |
| +void ParamTraits<SkFontStyle>::Log(const param_type& p, std::string* l) { |
| + *l = p.weight(); |
| +} |
| + |
| +} // namespace IPC |