Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/common/fontmgr_messages.h" | |
| 6 | |
| 7 #include "skia/ext/refptr.h" | |
| 8 #include "third_party/skia/include/core/SkDataTable.h" | |
| 9 #include "third_party/skia/include/core/SkStream.h" | |
| 10 #include "third_party/skia/include/core/SkString.h" | |
| 11 #include "third_party/skia/include/ports/SkFontMgr_indirect.h" | |
| 12 #include "third_party/skia/include/ports/SkFontStyle.h" | |
| 13 | |
| 14 namespace IPC { | |
| 15 //SkString | |
| 16 void ParamTraits<SkString>::Write(Message* m, const param_type& p) { | |
| 17 m->WriteData(p.c_str(), static_cast<int>(p.size())); | |
| 18 } | |
| 19 | |
| 20 bool ParamTraits<SkString>::Read( | |
| 21 const Message* m, PickleIterator* iter, param_type* r) | |
| 22 { | |
| 23 const char* data; | |
| 24 int len; | |
| 25 if (!m->ReadData(iter, &data, &len)) | |
| 26 return false; | |
| 27 | |
| 28 r->set(data, len); | |
| 29 return true; | |
| 30 } | |
| 31 | |
| 32 void ParamTraits<SkString>::Log(const param_type& p, std::string* l) { | |
| 33 *l = p.c_str(); | |
| 34 } | |
| 35 | |
| 36 //skia::RefPtr<SkDataTable> | |
| 37 void ParamTraits<skia::RefPtr<SkDataTable> >::Write( | |
| 38 Message* m, const param_type& p) | |
| 39 { | |
| 40 int count = p->count(); | |
| 41 m->WriteInt(count); | |
| 42 for (int i = 0; i < count; ++i) { | |
| 43 m->WriteData(reinterpret_cast<const char *>(p->at(i)), p->atSize(i)); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 bool ParamTraits<skia::RefPtr<SkDataTable> >::Read( | |
| 48 const Message* m, PickleIterator* iter, param_type* r) | |
| 49 { | |
| 50 int count; | |
| 51 if (!m->ReadLength(iter, &count)) | |
| 52 return false; | |
| 53 | |
| 54 SkDataTableBuilder builder(1024); | |
| 55 for (int i = 0; i < count; ++i) { | |
| 56 const char* data; | |
| 57 int len; | |
| 58 if (!m->ReadData(iter, &data, &len)) | |
| 59 return false; | |
| 60 | |
| 61 builder.append(data, len); | |
| 62 } | |
| 63 | |
| 64 *r = skia::AdoptRef(builder.detachDataTable()); | |
| 65 return true; | |
| 66 } | |
| 67 | |
| 68 void ParamTraits<skia::RefPtr<SkDataTable> >::Log(const param_type& p, | |
| 69 std::string* l) { | |
| 70 *l = "SkDataTable"; | |
| 71 } | |
| 72 | |
| 73 //skia::RefPtr<SkRemotableFontIdentitySet> | |
| 74 void ParamTraits<skia::RefPtr<SkRemotableFontIdentitySet> >::Write( | |
| 75 Message* m, const param_type& p) | |
| 76 { | |
| 77 m->WriteData(reinterpret_cast<const char*>(p->fData), | |
| 78 static_cast<int>(p->fCount * sizeof(SkFontIdentity))); | |
| 79 } | |
| 80 | |
| 81 bool ParamTraits<skia::RefPtr<SkRemotableFontIdentitySet> >::Read( | |
| 82 const Message* m, PickleIterator* iter, param_type* r) | |
| 83 { | |
| 84 const char* data; | |
| 85 int len; | |
| 86 if (!m->ReadData(iter, &data, &len)) | |
| 87 return false; | |
| 88 | |
| 89 int count = len / sizeof(SkFontIdentity); | |
| 90 *r = skia::AdoptRef(new SkRemotableFontIdentitySet(count)); | |
| 91 memcpy((*r)->fData, data, len); | |
| 92 return true; | |
| 93 } | |
| 94 | |
| 95 void ParamTraits<skia::RefPtr<SkRemotableFontIdentitySet> >::Log( | |
| 96 const param_type& p, std::string* l) | |
| 97 { | |
| 98 *l = "SkRemotableFontIdentitySet"; | |
| 99 } | |
| 100 | |
| 101 //skia::RefPtr<SkStream> | |
| 102 void ParamTraits<skia::RefPtr<SkStream> >::Write( | |
| 103 Message* m, const param_type& p) | |
| 104 { | |
| 105 if (!p->hasLength()) { | |
| 106 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.
| |
| 107 } | |
| 108 int size = p->getLength(); | |
| 109 const void* data = p->getMemoryBase(); | |
| 110 if (data) { | |
| 111 m->WriteData(reinterpret_cast<const char*>(data), static_cast<int>(size)); | |
| 112 return; | |
| 113 } | |
| 114 | |
| 115 // TODO: avoid this silly copy? | |
| 116 void* copy = malloc(size); | |
| 117 p->read(copy, size); | |
| 118 m->WriteData(reinterpret_cast<const char*>(copy), static_cast<int>(size)); | |
| 119 free(copy); | |
| 120 } | |
| 121 | |
| 122 bool ParamTraits<skia::RefPtr<SkStream> >::Read( | |
| 123 const Message* m, PickleIterator* iter, param_type* r) | |
| 124 { | |
| 125 const char* data; | |
| 126 int len; | |
| 127 if (!m->ReadData(iter, &data, &len)) | |
| 128 return false; | |
| 129 | |
| 130 *r = skia::AdoptRef(new SkMemoryStream(data, len, true)); | |
| 131 return true; | |
| 132 } | |
| 133 | |
| 134 void ParamTraits<skia::RefPtr<SkStream> >::Log( | |
| 135 const param_type& p, std::string* l) | |
| 136 { | |
| 137 *l = "stream"; | |
| 138 } | |
| 139 | |
| 140 //SkFontStyle | |
| 141 void ParamTraits<SkFontStyle>::Write(Message* m, const param_type& p) { | |
| 142 m->WriteInt(p.weight()); | |
| 143 m->WriteInt(p.width()); | |
| 144 m->WriteInt(p.slant()); | |
| 145 } | |
| 146 | |
| 147 bool ParamTraits<SkFontStyle>::Read( | |
| 148 const Message* m, PickleIterator* iter, param_type* r) | |
| 149 { | |
| 150 int weight; | |
| 151 if (!ReadParam(m, iter, &weight)) | |
| 152 return false; | |
| 153 | |
| 154 int width; | |
| 155 if (!ReadParam(m, iter, &width)) | |
| 156 return false; | |
| 157 | |
| 158 int slant; | |
| 159 if (!ReadParam(m, iter, &slant)) | |
| 160 return false; | |
| 161 | |
| 162 // TODO: trait these as enums | |
| 163 *r = SkFontStyle((SkFontStyle::Weight)weight, | |
| 164 (SkFontStyle::Width)width, | |
| 165 (SkFontStyle::Slant)slant); | |
| 166 return true; | |
| 167 } | |
| 168 | |
| 169 void ParamTraits<SkFontStyle>::Log(const param_type& p, std::string* l) { | |
| 170 *l = p.weight(); | |
| 171 } | |
| 172 | |
| 173 } // namespace IPC | |
| OLD | NEW |