Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 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 <string> | |
| 8 | |
| 9 #include "skia/ext/refptr.h" | |
| 10 #include "third_party/skia/include/core/SkDataTable.h" | |
| 11 #include "third_party/skia/include/core/SkStream.h" | |
| 12 #include "third_party/skia/include/core/SkString.h" | |
| 13 #include "third_party/skia/include/ports/SkFontStyle.h" | |
| 14 #include "third_party/skia/include/ports/SkRemotableFontMgr.h" | |
| 15 | |
| 16 namespace IPC { | |
| 17 | |
| 18 // skia::RefPtr<SkDataTable> | |
| 19 void ParamTraits<skia::RefPtr<SkDataTable> >::Write( | |
| 20 Message* m, | |
| 21 const param_type& p) { | |
| 22 if (!p) { | |
| 23 m->WriteInt(-1); | |
| 24 return; | |
| 25 } | |
| 26 | |
| 27 int count = p->count(); | |
| 28 m->WriteInt(count); | |
| 29 for (int i = 0; i < count; ++i) { | |
| 30 m->WriteData(reinterpret_cast<const char *>(p->at(i)), p->atSize(i)); | |
|
cpu_(ooo_6.6-7.5)
2014/03/26 20:02:38
we want to avoid this 'bag of bytes' approach to I
| |
| 31 } | |
| 32 } | |
| 33 | |
| 34 bool ParamTraits<skia::RefPtr<SkDataTable> >::Read( | |
| 35 const Message* m, | |
| 36 PickleIterator* iter, | |
| 37 param_type* r) { | |
| 38 int count; | |
| 39 if (!m->ReadInt(iter, &count)) | |
| 40 return false; | |
| 41 | |
| 42 if (count < 0) { | |
| 43 r->clear(); | |
| 44 return true; | |
| 45 } | |
| 46 | |
| 47 if (count == 0) { | |
| 48 *r = skia::AdoptRef(SkDataTable::NewEmpty()); | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 SkDataTableBuilder builder(1024); | |
|
cpu_(ooo_6.6-7.5)
2014/03/26 20:02:38
is there a limit in count? or the 1024 is just adv
| |
| 53 for (int i = 0; i < count; ++i) { | |
| 54 const char* data; | |
| 55 int len; | |
| 56 if (!m->ReadData(iter, &data, &len)) | |
| 57 return false; | |
| 58 | |
| 59 builder.append(data, len); | |
| 60 } | |
| 61 | |
| 62 *r = skia::AdoptRef(builder.detachDataTable()); | |
| 63 return true; | |
| 64 } | |
| 65 | |
| 66 void ParamTraits<skia::RefPtr<SkDataTable> >::Log( | |
| 67 const param_type& p, | |
| 68 std::string* l) { | |
| 69 l->append(base::StringPrintf("SkDataTable: %d", p->count())); | |
| 70 } | |
| 71 | |
| 72 // skia::RefPtr<SkRemotableFontIdentitySet> | |
| 73 void ParamTraits<skia::RefPtr<SkRemotableFontIdentitySet> >::Write( | |
| 74 Message* m, | |
| 75 const param_type& p) { | |
| 76 if (!p) { | |
| 77 m->WriteInt(-1); | |
| 78 return; | |
| 79 } | |
| 80 | |
| 81 int count = p->count(); | |
| 82 const void* data = reinterpret_cast<const void*>(&p->at(0)); | |
| 83 int length = static_cast<int>(count * sizeof(SkFontIdentity)); | |
| 84 count >= 0 && m->WriteInt(count) && m->WriteBytes(data, length); | |
|
cpu_(ooo_6.6-7.5)
2014/03/26 20:02:38
we don't use that style in chrome afaik.
| |
| 85 } | |
| 86 | |
| 87 bool ParamTraits<skia::RefPtr<SkRemotableFontIdentitySet> >::Read( | |
| 88 const Message* m, | |
| 89 PickleIterator* iter, | |
| 90 param_type* r) { | |
| 91 int count; | |
| 92 if (!m->ReadInt(iter, &count)) | |
| 93 return false; | |
| 94 | |
| 95 if (count < 0) { | |
|
cpu_(ooo_6.6-7.5)
2014/03/26 20:02:38
count = -1 ?
| |
| 96 r->clear(); | |
| 97 return true; | |
| 98 } | |
| 99 | |
| 100 int length = static_cast<int>(count * sizeof(SkFontIdentity)); | |
|
cpu_(ooo_6.6-7.5)
2014/03/26 20:02:38
potential integer overflow at the * step.
| |
| 101 const char* data; | |
| 102 if (!m->ReadBytes(iter, &data, length)) | |
| 103 return false; | |
| 104 | |
| 105 if (count == 0) { | |
| 106 *r = skia::AdoptRef(SkRemotableFontIdentitySet::NewEmpty()); | |
| 107 return true; | |
| 108 } | |
| 109 | |
| 110 SkFontIdentity* fontIds = NULL; | |
| 111 *r = skia::AdoptRef(new SkRemotableFontIdentitySet(count, &fontIds)); | |
| 112 memcpy(fontIds, data, length); | |
| 113 return true; | |
| 114 } | |
| 115 | |
| 116 void ParamTraits<skia::RefPtr<SkRemotableFontIdentitySet> >::Log( | |
| 117 const param_type& p, | |
| 118 std::string* l) { | |
| 119 l->append("SkRemotableFontIdentitySet"); | |
| 120 for (int i = 0; i < p->count(); ++i) { | |
| 121 LogParam(p->at(i), l); | |
| 122 } | |
| 123 } | |
| 124 | |
| 125 // skia::RefPtr<SkStreamAsset> | |
| 126 void ParamTraits<skia::RefPtr<SkStreamAsset> >::Write( | |
| 127 Message* m, | |
| 128 const param_type& p) { | |
| 129 if (!p) { | |
| 130 m->WriteInt(-1); | |
| 131 return; | |
| 132 } | |
| 133 | |
| 134 if (!p->hasLength()) { | |
| 135 m->WriteInt(0) && m->WriteBytes(NULL, 0); | |
|
cpu_(ooo_6.6-7.5)
2014/03/26 20:02:38
same comment here of line 84 and elsewhere.
| |
| 136 return; | |
| 137 } | |
| 138 | |
| 139 int length = p->getLength(); | |
| 140 const void* data = p->getMemoryBase(); | |
| 141 if (data) { | |
| 142 length >= 0 && m->WriteInt(length) && m->WriteBytes(data, length); | |
| 143 return; | |
| 144 } | |
| 145 | |
| 146 // TODO(bungeman): avoid this silly copy? | |
| 147 void* copy = malloc(length); | |
| 148 p->read(copy, length); | |
| 149 length >= 0 && m->WriteInt(length) && m->WriteBytes(data, length); | |
| 150 free(copy); | |
| 151 } | |
| 152 | |
| 153 bool ParamTraits<skia::RefPtr<SkStreamAsset> >::Read( | |
| 154 const Message* m, | |
| 155 PickleIterator* iter, | |
| 156 param_type* r) { | |
| 157 int length; | |
| 158 if (!m->ReadInt(iter, &length)) | |
| 159 return false; | |
| 160 | |
| 161 if (length < 0) { | |
| 162 r->clear(); | |
| 163 return true; | |
| 164 } | |
| 165 | |
| 166 const char* data; | |
| 167 if (!m->ReadBytes(iter, &data, length)) | |
| 168 return false; | |
| 169 | |
|
cpu_(ooo_6.6-7.5)
2014/03/26 20:02:38
same comment as line 30.
Since the fonts are sent
| |
| 170 *r = skia::AdoptRef(new SkMemoryStream(data, length, true)); | |
| 171 return true; | |
| 172 } | |
| 173 | |
| 174 void ParamTraits<skia::RefPtr<SkStreamAsset> >::Log( | |
| 175 const param_type& p, | |
| 176 std::string* l) { | |
| 177 l->append(base::StringPrintf("SkStreamAsset: %d", p->getLength())); | |
| 178 } | |
| 179 | |
| 180 // SkFontStyle | |
| 181 void ParamTraits<SkFontStyle>::Write(Message* m, const param_type& p) { | |
| 182 m->WriteInt(p.weight()); | |
| 183 m->WriteInt(p.width()); | |
| 184 m->WriteInt(p.slant()); | |
| 185 } | |
| 186 | |
| 187 bool ParamTraits<SkFontStyle>::Read( | |
| 188 const Message* m, | |
| 189 PickleIterator* iter, | |
| 190 param_type* r) { | |
| 191 int weight; | |
| 192 if (!m->ReadInt(iter, &weight)) | |
| 193 return false; | |
| 194 | |
| 195 int width; | |
| 196 if (!m->ReadInt(iter, &width)) | |
| 197 return false; | |
| 198 | |
| 199 int slant; | |
| 200 if (!m->ReadInt(iter, &slant)) | |
| 201 return false; | |
| 202 | |
| 203 *r = SkFontStyle(weight, width, (SkFontStyle::Slant)slant); | |
| 204 return true; | |
| 205 } | |
| 206 | |
| 207 void ParamTraits<SkFontStyle>::Log(const param_type& p, std::string* l) { | |
| 208 l->append(base::StringPrintf( | |
| 209 "SkFontStyle: weight:%d width:%d slant:%d", | |
| 210 p.weight(), p.width(), static_cast<int>(p.slant()))); | |
| 211 } | |
| 212 | |
| 213 } // namespace IPC | |
| OLD | NEW |