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

Unified Diff: src/core/SkStream.cpp

Issue 14336003: Move MMap to SkData. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Work on Linux. Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkData.cpp ('k') | src/ports/SkOSFile_stdio.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkStream.cpp
===================================================================
--- src/core/SkStream.cpp (revision 8838)
+++ src/core/SkStream.cpp (working copy)
@@ -13,14 +13,6 @@
#include "SkString.h"
#include "SkOSFile.h"
-#if SK_MMAP_SUPPORT
- #include <unistd.h>
- #include <sys/mman.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <unistd.h>
-#endif
-
SK_DEFINE_INST_COUNT(SkStream)
SK_DEFINE_INST_COUNT(SkWStream)
SK_DEFINE_INST_COUNT(SkFILEStream)
@@ -796,46 +788,22 @@
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
-static bool mmap_filename(const char path[], void** addrPtr, size_t* sizePtr) {
-#if SK_MMAP_SUPPORT
- int fd = open(path, O_RDONLY);
- if (fd < 0) {
- return false;
- }
- off_t offset = lseek(fd, 0, SEEK_END); // find the file size
- if (offset == -1) {
- close(fd);
- return false;
+static SkData* mmap_filename(const char path[]) {
reed1 2013/04/24 19:07:49 A nice illustration of the utility of SkData::NewF
+ SkFILE* file = sk_fopen(path, kRead_SkFILE_Flag);
+ if (NULL == file) {
+ return NULL;
}
- (void)lseek(fd, 0, SEEK_SET); // restore file offset to beginning
- // to avoid a 64bit->32bit warning, I explicitly create a size_t size
- size_t size = static_cast<size_t>(offset);
-
- void* addr = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
- close(fd);
-
- if (MAP_FAILED == addr) {
- return false;
- }
-
- *addrPtr = addr;
- *sizePtr = size;
- return true;
-#else
- return false;
-#endif
+ SkData* data = SkData::NewFromFILE(file);
+ sk_fclose(file);
+ return data;
}
SkStream* SkStream::NewFromFile(const char path[]) {
- void* addr;
- size_t size;
- if (mmap_filename(path, &addr, &size)) {
- SkAutoTUnref<SkData> data(SkData::NewFromMMap(addr, size));
- if (data.get()) {
- return SkNEW_ARGS(SkMemoryStream, (data.get()));
- }
+ SkAutoTUnref<SkData> data(mmap_filename(path));
+ if (data.get()) {
+ return SkNEW_ARGS(SkMemoryStream, (data.get()));
}
// If we get here, then our attempt at using mmap failed, so try normal
« no previous file with comments | « src/core/SkData.cpp ('k') | src/ports/SkOSFile_stdio.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698