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

Side by Side Diff: skia/images/SkMMapStream.cpp

Issue 113827: Remove the remainder of the skia source code from the Chromium repo.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « skia/images/SkImageRef_GlobalPool.cpp ('k') | skia/images/SkMovie.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include "SkMMapStream.h"
2
3 #include <unistd.h>
4 #include <sys/mman.h>
5 #include <fcntl.h>
6 #include <errno.h>
7
8 SkMMAPStream::SkMMAPStream(const char filename[])
9 {
10 fFildes = -1; // initialize to failure case
11
12 int fildes = open(filename, O_RDONLY);
13 if (fildes < 0)
14 {
15 SkDEBUGF(("---- failed to open(%s) for mmap stream error=%d\n", filename , errno));
16 return;
17 }
18
19 off_t size = lseek(fildes, 0, SEEK_END); // find the file size
20 if (size == -1)
21 {
22 SkDEBUGF(("---- failed to lseek(%s) for mmap stream error=%d\n", filenam e, errno));
23 close(fildes);
24 return;
25 }
26 (void)lseek(fildes, 0, SEEK_SET); // restore file offset to beginning
27
28 void* addr = mmap(NULL, size, PROT_READ, MAP_SHARED, fildes, 0);
29 if (MAP_FAILED == addr)
30 {
31 SkDEBUGF(("---- failed to mmap(%s) for mmap stream error=%d\n", filename , errno));
32 close(fildes);
33 return;
34 }
35
36 this->INHERITED::setMemory(addr, size);
37
38 fFildes = fildes;
39 fAddr = addr;
40 fSize = size;
41 }
42
43 SkMMAPStream::~SkMMAPStream()
44 {
45 this->closeMMap();
46 }
47
48 void SkMMAPStream::setMemory(const void* data, size_t length)
49 {
50 this->closeMMap();
51 this->INHERITED::setMemory(data, length);
52 }
53
54 void SkMMAPStream::closeMMap()
55 {
56 if (fFildes >= 0)
57 {
58 munmap(fAddr, fSize);
59 close(fFildes);
60 fFildes = -1;
61 }
62 }
63
OLDNEW
« no previous file with comments | « skia/images/SkImageRef_GlobalPool.cpp ('k') | skia/images/SkMovie.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698