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> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 FontConfigIPC::FontConfigIPC(int fd) | 57 FontConfigIPC::FontConfigIPC(int fd) |
58 : fd_(fd) | 58 : fd_(fd) |
59 , mapped_typefaces_(kMaxMappedTypefaces) { | 59 , mapped_typefaces_(kMaxMappedTypefaces) { |
60 } | 60 } |
61 | 61 |
62 FontConfigIPC::~FontConfigIPC() { | 62 FontConfigIPC::~FontConfigIPC() { |
63 CloseFD(fd_); | 63 CloseFD(fd_); |
64 } | 64 } |
65 | 65 |
66 bool FontConfigIPC::matchFamilyName(const char familyName[], | 66 bool FontConfigIPC::matchFamilyName(const char familyName[], |
67 SkTypeface::Style requestedStyle, | 67 SkFontStyle requestedStyle, |
68 FontIdentity* outFontIdentity, | 68 FontIdentity* outFontIdentity, |
69 SkString* outFamilyName, | 69 SkString* outFamilyName, |
70 SkTypeface::Style* outStyle) { | 70 SkFontStyle* outStyle) { |
71 TRACE_EVENT0("sandbox_ipc", "FontConfigIPC::matchFamilyName"); | 71 TRACE_EVENT0("sandbox_ipc", "FontConfigIPC::matchFamilyName"); |
72 size_t familyNameLen = familyName ? strlen(familyName) : 0; | 72 size_t familyNameLen = familyName ? strlen(familyName) : 0; |
73 if (familyNameLen > kMaxFontFamilyLength) | 73 if (familyNameLen > kMaxFontFamilyLength) |
74 return false; | 74 return false; |
75 | 75 |
76 base::Pickle request; | 76 base::Pickle request; |
77 request.WriteInt(METHOD_MATCH); | 77 request.WriteInt(METHOD_MATCH); |
78 request.WriteData(familyName, familyNameLen); | 78 request.WriteData(familyName, familyNameLen); |
79 request.WriteUInt32(requestedStyle); | 79 skia::WriteSkFontStyle(&request, requestedStyle); |
80 | 80 |
81 uint8_t reply_buf[2048]; | 81 uint8_t reply_buf[2048]; |
82 const ssize_t r = base::UnixDomainSocket::SendRecvMsg( | 82 const ssize_t r = base::UnixDomainSocket::SendRecvMsg( |
83 fd_, reply_buf, sizeof(reply_buf), NULL, request); | 83 fd_, reply_buf, sizeof(reply_buf), NULL, request); |
84 if (r == -1) | 84 if (r == -1) |
85 return false; | 85 return false; |
86 | 86 |
87 base::Pickle reply(reinterpret_cast<char*>(reply_buf), r); | 87 base::Pickle reply(reinterpret_cast<char*>(reply_buf), r); |
88 base::PickleIterator iter(reply); | 88 base::PickleIterator iter(reply); |
89 bool result; | 89 bool result; |
90 if (!iter.ReadBool(&result)) | 90 if (!iter.ReadBool(&result)) |
91 return false; | 91 return false; |
92 if (!result) | 92 if (!result) |
93 return false; | 93 return false; |
94 | 94 |
95 SkString reply_family; | 95 SkString reply_family; |
96 FontIdentity reply_identity; | 96 FontIdentity reply_identity; |
97 uint32_t reply_style; | 97 SkFontStyle reply_style; |
98 if (!skia::ReadSkString(&iter, &reply_family) || | 98 if (!skia::ReadSkString(&iter, &reply_family) || |
99 !skia::ReadSkFontIdentity(&iter, &reply_identity) || | 99 !skia::ReadSkFontIdentity(&iter, &reply_identity) || |
100 !iter.ReadUInt32(&reply_style)) { | 100 !skia::ReadSkFontStyle(&iter, &reply_style)) { |
101 return false; | 101 return false; |
102 } | 102 } |
103 | 103 |
104 if (outFontIdentity) | 104 if (outFontIdentity) |
105 *outFontIdentity = reply_identity; | 105 *outFontIdentity = reply_identity; |
106 if (outFamilyName) | 106 if (outFamilyName) |
107 *outFamilyName = reply_family; | 107 *outFamilyName = reply_family; |
108 if (outStyle) | 108 if (outStyle) |
109 *outStyle = static_cast<SkTypeface::Style>(reply_style); | 109 *outStyle = reply_style; |
dcheng
2016/04/12 00:01:24
I don't think I conveyed my intent clearly: if the
bungeman-chromium
2016/04/12 16:35:36
This is a hard sell to Skia though. The uint32_t c
| |
110 | 110 |
111 return true; | 111 return true; |
112 } | 112 } |
113 | 113 |
114 static void DestroyMemoryMappedFile(const void*, void* context) { | 114 static void DestroyMemoryMappedFile(const void*, void* context) { |
115 base::ThreadRestrictions::ScopedAllowIO allow_munmap; | 115 base::ThreadRestrictions::ScopedAllowIO allow_munmap; |
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) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 if (!typeface_stream) | 169 if (!typeface_stream) |
170 return nullptr; | 170 return nullptr; |
171 skia::RefPtr<SkTypeface> typeface_from_stream = skia::AdoptRef( | 171 skia::RefPtr<SkTypeface> typeface_from_stream = skia::AdoptRef( |
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 |