OLD | NEW |
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/font_config_ipc_linux.h" | 5 #include "content/common/font_config_ipc_linux.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
11 #include <sys/socket.h> | 11 #include <sys/socket.h> |
12 #include <sys/stat.h> | 12 #include <sys/stat.h> |
13 #include <sys/uio.h> | 13 #include <sys/uio.h> |
14 #include <unistd.h> | 14 #include <unistd.h> |
15 | 15 |
16 #include <functional> | 16 #include <functional> |
17 #include <memory> | 17 #include <memory> |
18 | 18 |
19 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
20 #include "base/files/memory_mapped_file.h" | 20 #include "base/files/memory_mapped_file.h" |
21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
22 #include "base/pickle.h" | 22 #include "base/pickle.h" |
23 #include "base/posix/unix_domain_socket_linux.h" | 23 #include "base/posix/unix_domain_socket_linux.h" |
24 #include "base/threading/thread_restrictions.h" | 24 #include "base/threading/thread_restrictions.h" |
25 #include "base/trace_event/trace_event.h" | 25 #include "base/trace_event/trace_event.h" |
26 #include "skia/ext/refptr.h" | |
27 #include "skia/ext/skia_utils_base.h" | 26 #include "skia/ext/skia_utils_base.h" |
28 #include "third_party/skia/include/core/SkData.h" | 27 #include "third_party/skia/include/core/SkData.h" |
| 28 #include "third_party/skia/include/core/SkRefCnt.h" |
29 #include "third_party/skia/include/core/SkStream.h" | 29 #include "third_party/skia/include/core/SkStream.h" |
30 #include "third_party/skia/include/core/SkTypeface.h" | 30 #include "third_party/skia/include/core/SkTypeface.h" |
31 | 31 |
32 namespace content { | 32 namespace content { |
33 | 33 |
34 std::size_t SkFontConfigInterfaceFontIdentityHash::operator()( | 34 std::size_t SkFontConfigInterfaceFontIdentityHash::operator()( |
35 const SkFontConfigInterface::FontIdentity& sp) const { | 35 const SkFontConfigInterface::FontIdentity& sp) const { |
36 std::hash<std::string> stringhash; | 36 std::hash<std::string> stringhash; |
37 std::hash<int> inthash; | 37 std::hash<int> inthash; |
38 size_t r = inthash(sp.fID); | 38 size_t r = inthash(sp.fID); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 delete static_cast<base::MemoryMappedFile*>(context); | 116 delete static_cast<base::MemoryMappedFile*>(context); |
117 } | 117 } |
118 | 118 |
119 SkMemoryStream* FontConfigIPC::mapFileDescriptorToStream(int fd) { | 119 SkMemoryStream* FontConfigIPC::mapFileDescriptorToStream(int fd) { |
120 std::unique_ptr<base::MemoryMappedFile> mapped_font_file( | 120 std::unique_ptr<base::MemoryMappedFile> mapped_font_file( |
121 new base::MemoryMappedFile); | 121 new base::MemoryMappedFile); |
122 base::ThreadRestrictions::ScopedAllowIO allow_mmap; | 122 base::ThreadRestrictions::ScopedAllowIO allow_mmap; |
123 mapped_font_file->Initialize(base::File(fd)); | 123 mapped_font_file->Initialize(base::File(fd)); |
124 DCHECK(mapped_font_file->IsValid()); | 124 DCHECK(mapped_font_file->IsValid()); |
125 | 125 |
126 auto data = skia::AdoptRef( | 126 sk_sp<SkData> data = |
127 SkData::NewWithProc(mapped_font_file->data(), mapped_font_file->length(), | 127 SkData::MakeWithProc(mapped_font_file->data(), mapped_font_file->length(), |
128 &DestroyMemoryMappedFile, mapped_font_file.get())); | 128 &DestroyMemoryMappedFile, mapped_font_file.get()); |
129 if (!data) | 129 if (!data) |
130 return nullptr; | 130 return nullptr; |
131 ignore_result(mapped_font_file.release()); // Ownership transferred to SkDataB | 131 ignore_result(mapped_font_file.release()); // Ownership transferred to SkDataB |
132 return new SkMemoryStream(data.get()); | 132 return new SkMemoryStream(std::move(data)); |
133 } | 133 } |
134 | 134 |
135 SkStreamAsset* FontConfigIPC::openStream(const FontIdentity& identity) { | 135 SkStreamAsset* FontConfigIPC::openStream(const FontIdentity& identity) { |
136 TRACE_EVENT0("sandbox_ipc", "FontConfigIPC::openStream"); | 136 TRACE_EVENT0("sandbox_ipc", "FontConfigIPC::openStream"); |
137 | 137 |
138 base::Pickle request; | 138 base::Pickle request; |
139 request.WriteInt(METHOD_OPEN); | 139 request.WriteInt(METHOD_OPEN); |
140 request.WriteUInt32(identity.fID); | 140 request.WriteUInt32(identity.fID); |
141 | 141 |
142 int result_fd = -1; | 142 int result_fd = -1; |
(...skipping 18 matching lines...) Expand all Loading... |
161 SkTypeface* FontConfigIPC::createTypeface( | 161 SkTypeface* FontConfigIPC::createTypeface( |
162 const SkFontConfigInterface::FontIdentity& identity) { | 162 const SkFontConfigInterface::FontIdentity& identity) { |
163 base::AutoLock lock(lock_); | 163 base::AutoLock lock(lock_); |
164 auto mapped_typefaces_it = mapped_typefaces_.Get(identity); | 164 auto mapped_typefaces_it = mapped_typefaces_.Get(identity); |
165 if (mapped_typefaces_it != mapped_typefaces_.end()) | 165 if (mapped_typefaces_it != mapped_typefaces_.end()) |
166 return SkSafeRef(mapped_typefaces_it->second.get()); | 166 return SkSafeRef(mapped_typefaces_it->second.get()); |
167 | 167 |
168 SkStreamAsset* typeface_stream = openStream(identity); | 168 SkStreamAsset* typeface_stream = openStream(identity); |
169 if (!typeface_stream) | 169 if (!typeface_stream) |
170 return nullptr; | 170 return nullptr; |
171 skia::RefPtr<SkTypeface> typeface_from_stream = skia::AdoptRef( | 171 sk_sp<SkTypeface> typeface_from_stream( |
172 SkTypeface::CreateFromStream(typeface_stream, identity.fTTCIndex)); | 172 SkTypeface::CreateFromStream(typeface_stream, identity.fTTCIndex)); |
173 auto mapped_typefaces_insert_it = | 173 auto mapped_typefaces_insert_it = |
174 mapped_typefaces_.Put(identity, typeface_from_stream); | 174 mapped_typefaces_.Put(identity, typeface_from_stream); |
175 return SkSafeRef(mapped_typefaces_insert_it->second.get()); | 175 return SkSafeRef(mapped_typefaces_insert_it->second.get()); |
176 } | 176 } |
177 | 177 |
178 } // namespace content | 178 } // namespace content |
OLD | NEW |