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

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

Issue 101973005: SkDecodingImageGenerator now uses SkStreamRewindable (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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
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"
11 #include "SkOnce.h" 11 #include "SkOnce.h"
12 #include "SkStream.h"
12 13
13 SkData::SkData(const void* ptr, size_t size, ReleaseProc proc, void* context) { 14 SkData::SkData(const void* ptr, size_t size, ReleaseProc proc, void* context) {
14 fPtr = ptr; 15 fPtr = ptr;
15 fSize = size; 16 fSize = size;
16 fReleaseProc = proc; 17 fReleaseProc = proc;
17 fReleaseProcContext = context; 18 fReleaseProcContext = context;
18 } 19 }
19 20
20 SkData::~SkData() { 21 SkData::~SkData() {
21 if (fReleaseProc) { 22 if (fReleaseProc) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 SkData* SkData::NewWithCopy(const void* data, size_t length) { 73 SkData* SkData::NewWithCopy(const void* data, size_t length) {
73 if (0 == length) { 74 if (0 == length) {
74 return SkData::NewEmpty(); 75 return SkData::NewEmpty();
75 } 76 }
76 77
77 void* copy = sk_malloc_throw(length); // balanced in sk_free_releaseproc 78 void* copy = sk_malloc_throw(length); // balanced in sk_free_releaseproc
78 memcpy(copy, data, length); 79 memcpy(copy, data, length);
79 return new SkData(copy, length, sk_free_releaseproc, NULL); 80 return new SkData(copy, length, sk_free_releaseproc, NULL);
80 } 81 }
81 82
83 SkData* SkData::NewWithCopyFromStream(SkStreamRewindable* stream) {
84 if (!stream->hasLength()) {
85 return NULL;
86 }
87 size_t length = stream->getLength();
88 if (0 == length) {
89 return NULL;
90 }
91 void* buffer = sk_malloc_flags(length, 0);
92 if (NULL == buffer) {
93 return NULL;
94 }
95 if (!stream->rewind()) {
96 sk_free(buffer);
97 return NULL;
98 }
99 SkAssertResult(stream->read(buffer, length) == length);
100 return new SkData(buffer, length, sk_free_releaseproc, NULL);
101 }
102
103
82 SkData* SkData::NewWithProc(const void* data, size_t length, 104 SkData* SkData::NewWithProc(const void* data, size_t length,
83 ReleaseProc proc, void* context) { 105 ReleaseProc proc, void* context) {
84 return new SkData(data, length, proc, context); 106 return new SkData(data, length, proc, context);
85 } 107 }
86 108
87 // assumes fPtr was allocated with sk_fmmap 109 // assumes fPtr was allocated with sk_fmmap
88 static void sk_mmap_releaseproc(const void* addr, size_t length, void*) { 110 static void sk_mmap_releaseproc(const void* addr, size_t length, void*) {
89 sk_fmunmap(addr, length); 111 sk_fmunmap(addr, length);
90 } 112 }
91 113
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 SkData* SkData::NewWithCString(const char cstr[]) { 172 SkData* SkData::NewWithCString(const char cstr[]) {
151 size_t size; 173 size_t size;
152 if (NULL == cstr) { 174 if (NULL == cstr) {
153 cstr = ""; 175 cstr = "";
154 size = 1; 176 size = 1;
155 } else { 177 } else {
156 size = strlen(cstr) + 1; 178 size = strlen(cstr) + 1;
157 } 179 }
158 return NewWithCopy(cstr, size); 180 return NewWithCopy(cstr, size);
159 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698