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

Unified Diff: src/core/SkData.cpp

Issue 15298009: Change SkStream. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Clean up, address comments. Created 7 years, 7 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 | « include/core/SkStream.h ('k') | src/core/SkFDStream.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkData.cpp
===================================================================
--- src/core/SkData.cpp (revision 9222)
+++ src/core/SkData.cpp (working copy)
@@ -9,16 +9,6 @@
#include "SkFlattenableBuffers.h"
#include "SkOSFile.h"
-#if SK_MMAP_SUPPORT
- #include <unistd.h>
- #include <sys/mman.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <unistd.h>
-#else
- #include <io.h>
-#endif
-
SK_DEFINE_INST_COUNT(SkData)
SkData::SkData(const void* ptr, size_t size, ReleaseProc proc, void* context) {
@@ -92,96 +82,27 @@
return new SkData(data, length, proc, context);
}
-// assumes context is a SkData
-static void sk_dataref_releaseproc(const void*, size_t, void* context) {
- SkData* src = reinterpret_cast<SkData*>(context);
- src->unref();
+// assumes fPtr was allocated with sk_fmmap
+static void sk_mmap_releaseproc(const void* addr, size_t length, void*) {
+ sk_fmunmap(addr, length);
}
-#if SK_MMAP_SUPPORT
-
-static void sk_munmap_releaseproc(const void* addr, size_t length, void*) {
- munmap(const_cast<void*>(addr), length);
-}
-
SkData* SkData::NewFromFILE(SkFILE* f) {
- size_t size = sk_fgetsize(f);
- if (0 == size) {
- return NULL;
- }
-
- int fd = fileno((FILE*)f);
- if (fd < 0) {
- return NULL;
- }
-
- void* addr = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
- if (MAP_FAILED == addr) {
- return NULL;
- }
-
- return SkData::NewWithProc(addr, size, sk_munmap_releaseproc, NULL);
-}
-
-#elif defined(SK_BUILD_FOR_WIN32)
-
-template <typename HandleType, HandleType InvalidValue, BOOL (WINAPI * Close)(HandleType)>
-class SkAutoTHandle : SkNoncopyable {
-public:
- SkAutoTHandle(HandleType handle) : fHandle(handle) { }
- ~SkAutoTHandle() { Close(fHandle); }
- operator HandleType() { return fHandle; }
- bool isValid() { return InvalidValue != fHandle; }
-private:
- HandleType fHandle;
-};
-typedef SkAutoTHandle<HANDLE, INVALID_HANDLE_VALUE, CloseHandle> SkAutoWinFile;
-typedef SkAutoTHandle<HANDLE, NULL, CloseHandle> SkAutoWinMMap;
-
-static void sk_munmap_releaseproc(const void* addr, size_t, void*) {
- UnmapViewOfFile(addr);
-}
-
-SkData* SkData::NewFromFILE(SkFILE* f) {
- size_t size = sk_fgetsize(f);
- if (0 == size) {
- return NULL;
- }
-
- int fileno = _fileno((FILE*)f);
- if (fileno < 0) {
- return NULL;
- }
-
- HANDLE file = (HANDLE)_get_osfhandle(fileno);
- if (INVALID_HANDLE_VALUE == file) {
- return NULL;
- }
-
- SkAutoWinMMap mmap(CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL));
- if (!mmap.isValid()) {
- //TODO: use SK_TRACEHR(GetLastError(), "Could not create file mapping.") to report.
- return NULL;
- }
-
- // Eventually call UnmapViewOfFile
- void* addr = MapViewOfFile(mmap, FILE_MAP_READ, 0, 0, 0);
+ size_t size;
+ void* addr = sk_fmmap(f, &size);
if (NULL == addr) {
- //TODO: use SK_TRACEHR(GetLastError(), "Could not map view of file.") to report.
return NULL;
}
- return SkData::NewWithProc(addr, size, sk_munmap_releaseproc, NULL);
+ return SkData::NewWithProc(addr, size, sk_mmap_releaseproc, NULL);
}
-#else
-
-SkData* SkData::NewFromFILE(SkFILE* f) {
- return NULL;
+// assumes context is a SkData
+static void sk_dataref_releaseproc(const void*, size_t, void* context) {
+ SkData* src = reinterpret_cast<SkData*>(context);
+ src->unref();
}
-#endif
-
SkData* SkData::NewSubset(const SkData* src, size_t offset, size_t length) {
/*
We could, if we wanted/need to, just make a deep copy of src's data,
« no previous file with comments | « include/core/SkStream.h ('k') | src/core/SkFDStream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698