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

Side by Side Diff: src/core/SkData.cpp

Issue 15941025: Add SkData::NewFromFD. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Remove an indentation level. Created 7 years, 6 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 | « include/core/SkTemplates.h ('k') | src/ports/SkDebug_brew.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkData.h" 8 #include "SkData.h"
9 #include "SkFlattenableBuffers.h" 9 #include "SkFlattenableBuffers.h"
10 #include "SkOSFile.h" 10 #include "SkOSFile.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 SkData* SkData::NewFromFILE(SkFILE* f) { 90 SkData* SkData::NewFromFILE(SkFILE* f) {
91 size_t size; 91 size_t size;
92 void* addr = sk_fmmap(f, &size); 92 void* addr = sk_fmmap(f, &size);
93 if (NULL == addr) { 93 if (NULL == addr) {
94 return NULL; 94 return NULL;
95 } 95 }
96 96
97 return SkData::NewWithProc(addr, size, sk_mmap_releaseproc, NULL); 97 return SkData::NewWithProc(addr, size, sk_mmap_releaseproc, NULL);
98 } 98 }
99 99
100 SkData* SkData::NewFromFD(int fd) {
101 size_t size;
102 void* addr = sk_fdmmap(fd, &size);
103 if (NULL == addr) {
104 return NULL;
105 }
106
107 return SkData::NewWithProc(addr, size, sk_mmap_releaseproc, NULL);
108 }
109
100 // assumes context is a SkData 110 // assumes context is a SkData
101 static void sk_dataref_releaseproc(const void*, size_t, void* context) { 111 static void sk_dataref_releaseproc(const void*, size_t, void* context) {
102 SkData* src = reinterpret_cast<SkData*>(context); 112 SkData* src = reinterpret_cast<SkData*>(context);
103 src->unref(); 113 src->unref();
104 } 114 }
105 115
106 SkData* SkData::NewSubset(const SkData* src, size_t offset, size_t length) { 116 SkData* SkData::NewSubset(const SkData* src, size_t offset, size_t length) {
107 /* 117 /*
108 We could, if we wanted/need to, just make a deep copy of src's data, 118 We could, if we wanted/need to, just make a deep copy of src's data,
109 rather than referencing it. This would duplicate the storage (of the 119 rather than referencing it. This would duplicate the storage (of the
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 319 }
310 320
311 SkDataSet* SkDataSet::NewEmpty() { 321 SkDataSet* SkDataSet::NewEmpty() {
312 static SkDataSet* gEmptySet; 322 static SkDataSet* gEmptySet;
313 if (NULL == gEmptySet) { 323 if (NULL == gEmptySet) {
314 gEmptySet = SkNEW_ARGS(SkDataSet, (NULL, 0)); 324 gEmptySet = SkNEW_ARGS(SkDataSet, (NULL, 0));
315 } 325 }
316 gEmptySet->ref(); 326 gEmptySet->ref();
317 return gEmptySet; 327 return gEmptySet;
318 } 328 }
OLDNEW
« no previous file with comments | « include/core/SkTemplates.h ('k') | src/ports/SkDebug_brew.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698