Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: content/common/font_config_ipc_linux.cc

Issue 870133002: Move to SkStreamAsset for SkTypeface streams. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Covariance requires proof. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/common/font_config_ipc_linux.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <sys/mman.h> 9 #include <sys/mman.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
11 #include <sys/stat.h> 11 #include <sys/stat.h>
12 #include <sys/uio.h> 12 #include <sys/uio.h>
13 #include <unistd.h> 13 #include <unistd.h>
14 14
15 #include "base/debug/trace_event.h" 15 #include "base/debug/trace_event.h"
16 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
17 #include "base/pickle.h" 17 #include "base/pickle.h"
18 #include "base/posix/unix_domain_socket_linux.h" 18 #include "base/posix/unix_domain_socket_linux.h"
19 #include "skia/ext/refptr.h" 19 #include "skia/ext/refptr.h"
20 #include "skia/ext/skia_utils_base.h" 20 #include "skia/ext/skia_utils_base.h"
21 #include "third_party/skia/include/core/SkData.h" 21 #include "third_party/skia/include/core/SkData.h"
22 #include "third_party/skia/include/core/SkStream.h" 22 #include "third_party/skia/include/core/SkStream.h"
23 #include "third_party/skia/include/core/SkTypeface.h"
23 24
24 namespace content { 25 namespace content {
25 26
26 // Return a stream from the file descriptor, or NULL on failure. 27 // Return a stream from the file descriptor, or NULL on failure.
27 SkStream* StreamFromFD(int fd) { 28 SkStreamAsset* StreamFromFD(int fd) {
28 skia::RefPtr<SkData> data = skia::AdoptRef(SkData::NewFromFD(fd)); 29 skia::RefPtr<SkData> data = skia::AdoptRef(SkData::NewFromFD(fd));
29 if (!data) { 30 if (!data) {
30 return NULL; 31 return NULL;
31 } 32 }
32 return new SkMemoryStream(data.get()); 33 return new SkMemoryStream(data.get());
33 } 34 }
34 35
35 void CloseFD(int fd) { 36 void CloseFD(int fd) {
36 int err = IGNORE_EINTR(close(fd)); 37 int err = IGNORE_EINTR(close(fd));
37 DCHECK(!err); 38 DCHECK(!err);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 if (outFontIdentity) 88 if (outFontIdentity)
88 *outFontIdentity = reply_identity; 89 *outFontIdentity = reply_identity;
89 if (outFamilyName) 90 if (outFamilyName)
90 *outFamilyName = reply_family; 91 *outFamilyName = reply_family;
91 if (outStyle) 92 if (outStyle)
92 *outStyle = static_cast<SkTypeface::Style>(reply_style); 93 *outStyle = static_cast<SkTypeface::Style>(reply_style);
93 94
94 return true; 95 return true;
95 } 96 }
96 97
97 SkStream* FontConfigIPC::openStream(const FontIdentity& identity) { 98 SkStreamAsset* FontConfigIPC::openStream(const FontIdentity& identity) {
98 TRACE_EVENT0("sandbox_ipc", "FontConfigIPC::openStream"); 99 TRACE_EVENT0("sandbox_ipc", "FontConfigIPC::openStream");
99 Pickle request; 100 Pickle request;
100 request.WriteInt(METHOD_OPEN); 101 request.WriteInt(METHOD_OPEN);
101 request.WriteUInt32(identity.fID); 102 request.WriteUInt32(identity.fID);
102 103
103 int result_fd = -1; 104 int result_fd = -1;
104 uint8_t reply_buf[256]; 105 uint8_t reply_buf[256];
105 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf, 106 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf,
106 sizeof(reply_buf), 107 sizeof(reply_buf),
107 &result_fd, request); 108 &result_fd, request);
108 109
109 if (r == -1) 110 if (r == -1)
110 return NULL; 111 return NULL;
111 112
112 Pickle reply(reinterpret_cast<char*>(reply_buf), r); 113 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
113 bool result; 114 bool result;
114 PickleIterator iter(reply); 115 PickleIterator iter(reply);
115 if (!iter.ReadBool(&result) || !result) { 116 if (!iter.ReadBool(&result) || !result) {
116 if (result_fd) 117 if (result_fd)
117 CloseFD(result_fd); 118 CloseFD(result_fd);
118 return NULL; 119 return NULL;
119 } 120 }
120 121
121 SkStream* stream = StreamFromFD(result_fd); 122 SkStreamAsset* stream = StreamFromFD(result_fd);
122 CloseFD(result_fd); 123 CloseFD(result_fd);
123 return stream; 124 return stream;
124 } 125 }
125 126
126 } // namespace content 127 } // namespace content
127 128
OLDNEW
« no previous file with comments | « content/common/font_config_ipc_linux.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698