Chromium Code Reviews| Index: content/common/font_config_ipc_linux.cc |
| =================================================================== |
| --- content/common/font_config_ipc_linux.cc (revision 188729) |
| +++ content/common/font_config_ipc_linux.cc (working copy) |
| @@ -6,10 +6,13 @@ |
| #include <errno.h> |
| #include <fcntl.h> |
| +#include <sys/mman.h> |
| #include <sys/socket.h> |
| +#include <sys/stat.h> |
| #include <sys/uio.h> |
| #include <unistd.h> |
| +#include "base/file_util.h" |
| #include "base/pickle.h" |
| #include "base/posix/unix_domain_socket_linux.h" |
| #include "skia/ext/skia_utils_base.h" |
| @@ -17,6 +20,66 @@ |
| namespace content { |
| +// Takes "ownership" of the file descriptor, and will close() it. |
| +class SkFileDescriptorStream : public SkStream { |
|
jln (very slow on Chromium)
2013/03/18 18:25:37
General nit: why are you using a 4 spaces indent?
reed1
2013/03/18 18:42:35
Done.
|
| + public: |
| + SkFileDescriptorStream(int fd) { |
| + memory_ = NULL; |
|
jln (very slow on Chromium)
2013/03/18 18:25:37
You don't want to use an initialization list inste
reed1
2013/03/18 18:42:35
Done.
|
| + offset_ = 0; |
| + |
| + // this ensures that if we fail in the constructor, we will safely |
|
jln (very slow on Chromium)
2013/03/18 18:25:37
Nit: s/this/This
reed1
2013/03/18 18:42:35
Done.
|
| + // ignore all subsequent calls to read() because we will always trim |
|
jln (very slow on Chromium)
2013/03/18 18:25:37
I don't think this currently works. You just do re
|
| + // the requested size down to 0 |
|
jln (very slow on Chromium)
2013/03/18 18:25:37
Nit: final "."
reed1
2013/03/18 18:42:35
Done.
|
| + length_ = 0; |
| + |
| + struct stat st; |
| + if (fstat(fd, &st)) |
|
jln (very slow on Chromium)
2013/03/18 18:25:37
close the fd here as well ?
reed1
2013/03/18 18:42:35
Done.
|
| + return; |
| + |
| + void* memory = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); |
| + DCHECK(!HANDLE_EINTR(close(fd))); |
| + if (memory == MAP_FAILED) |
| + return; |
| + |
| + memory_ = reinterpret_cast<uint8_t*>(memory); |
| + length_ = st.st_size; |
| + } |
| + |
| + virtual ~SkFileDescriptorStream() { |
|
jln (very slow on Chromium)
2013/03/18 18:25:37
This works, because length == 0 will make the kern
reed1
2013/03/18 18:42:35
Done.
|
| + munmap(const_cast<uint8_t*>(memory_), length_); |
| + } |
| + |
| + virtual bool rewind() OVERRIDE { |
| + offset_ = 0; |
| + return true; |
| + } |
| + |
| + // SkStream implementation. |
| + virtual size_t read(void* buffer, size_t size) OVERRIDE { |
| + if (!buffer && !size) { |
| + // This is request for the length of the stream. |
| + return length_; |
| + } |
| + |
| + size_t remaining = length_ - offset_; |
| + if (size > remaining) |
| + size = remaining; |
| + if (buffer) |
|
jln (very slow on Chromium)
2013/03/18 18:25:37
Shouldn't we just CHECK buffer at the start of thi
reed1
2013/03/18 18:42:35
buffer == NULL is defined to mean "skip", so it is
|
| + memcpy(buffer, memory_ + offset_, size); |
| + |
| + offset_ += size; |
| + return size; |
| + } |
| + |
| + virtual const void* getMemoryBase() OVERRIDE { |
| + return memory_; |
| + } |
| + |
| + private: |
| + const uint8_t* memory_; |
| + size_t offset_, length_; |
| +}; |
| + |
| FontConfigIPC::FontConfigIPC(int fd) |
| : fd_(fd) { |
| } |
| @@ -97,7 +160,7 @@ |
| return NULL; |
| } |
| - return new SkFDStream(result_fd, true); |
| + return new SkFileDescriptorStream(result_fd); |
| } |
| } // namespace content |