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

Side by Side Diff: include/core/SkData.h

Issue 1193553002: simplify release-proc for SkData, removing unneeded size param (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | src/core/SkData.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 #ifndef SkData_DEFINED 8 #ifndef SkData_DEFINED
9 #define SkData_DEFINED 9 #define SkData_DEFINED
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 size_t copyRange(size_t offset, size_t length, void* buffer) const; 64 size_t copyRange(size_t offset, size_t length, void* buffer) const;
65 65
66 /** 66 /**
67 * Returns true if these two objects have the same length and contents, 67 * Returns true if these two objects have the same length and contents,
68 * effectively returning 0 == memcmp(...) 68 * effectively returning 0 == memcmp(...)
69 */ 69 */
70 bool equals(const SkData* other) const; 70 bool equals(const SkData* other) const;
71 71
72 /** 72 /**
73 * Function that, if provided, will be called when the SkData goes out 73 * Function that, if provided, will be called when the SkData goes out
74 * of scope, allowing for custom allocation/freeing of the data. 74 * of scope, allowing for custom allocation/freeing of the data's contents.
75 */ 75 */
76 typedef void (*ReleaseProc)(const void* ptr, size_t length, void* context); 76 typedef void (*ReleaseProc)(const void* ptr, void* context);
77 77
78 /** 78 /**
79 * Create a new dataref by copying the specified data 79 * Create a new dataref by copying the specified data
80 */ 80 */
81 static SkData* NewWithCopy(const void* data, size_t length); 81 static SkData* NewWithCopy(const void* data, size_t length);
82 82
83 /** 83 /**
84 * Create a new data with uninitialized contents. The caller should call wr itable_data() 84 * Create a new data with uninitialized contents. The caller should call wr itable_data()
85 * to write into the buffer, but this must be done before another ref() is made. 85 * to write into the buffer, but this must be done before another ref() is made.
86 */ 86 */
87 static SkData* NewUninitialized(size_t length); 87 static SkData* NewUninitialized(size_t length);
88 88
89 /** 89 /**
90 * Create a new dataref by copying the specified c-string 90 * Create a new dataref by copying the specified c-string
91 * (a null-terminated array of bytes). The returned SkData will have size() 91 * (a null-terminated array of bytes). The returned SkData will have size()
92 * equal to strlen(cstr) + 1. If cstr is NULL, it will be treated the same 92 * equal to strlen(cstr) + 1. If cstr is NULL, it will be treated the same
93 * as "". 93 * as "".
94 */ 94 */
95 static SkData* NewWithCString(const char cstr[]); 95 static SkData* NewWithCString(const char cstr[]);
96 96
97 /** 97 /**
98 * Create a new dataref, taking the data ptr as is, and using the 98 * Create a new dataref, taking the ptr as is, and using the
99 * releaseproc to free it. The proc may be NULL. 99 * releaseproc to free it. The proc may be NULL.
100 */ 100 */
101 static SkData* NewWithProc(const void* data, size_t length, ReleaseProc proc , void* context); 101 static SkData* NewWithProc(const void* ptr, size_t length, ReleaseProc proc, void* context);
102
103 #ifdef SK_SUPPORT_LEGACY_DATARELEASEPROC_PARAMS
104 // This variant is temporary.
105 // Its signature is meant to match an older version of the API
106 typedef void (*LegacyReleaseProc)(const void* ptr, size_t size, void* ctx);
107 static SkData* NewWithProc(const void* ptr, size_t length, LegacyReleaseProc proc, void* ctx);
108 #endif
102 109
103 /** 110 /**
104 * Call this when the data parameter is already const and will outlive the lifetime of the 111 * Call this when the data parameter is already const and will outlive the lifetime of the
105 * SkData. Suitable for with const globals. 112 * SkData. Suitable for with const globals.
106 */ 113 */
107 static SkData* NewWithoutCopy(const void* data, size_t length) { 114 static SkData* NewWithoutCopy(const void* data, size_t length) {
108 return NewWithProc(data, length, NULL, NULL); 115 return NewWithProc(data, length, DummyReleaseProc, NULL);
109 } 116 }
110 117
111 /** 118 /**
112 * Create a new dataref from a pointer allocated by malloc. The Data object 119 * Create a new dataref from a pointer allocated by malloc. The Data object
113 * takes ownership of that allocation, and will handling calling sk_free. 120 * takes ownership of that allocation, and will handling calling sk_free.
114 */ 121 */
115 static SkData* NewFromMalloc(const void* data, size_t length); 122 static SkData* NewFromMalloc(const void* data, size_t length);
116 123
117 /** 124 /**
118 * Create a new dataref the file with the specified path. 125 * Create a new dataref the file with the specified path.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 160
154 /** 161 /**
155 * Returns a new empty dataref (or a reference to a shared empty dataref). 162 * Returns a new empty dataref (or a reference to a shared empty dataref).
156 * New or shared, the caller must see that unref() is eventually called. 163 * New or shared, the caller must see that unref() is eventually called.
157 */ 164 */
158 static SkData* NewEmpty(); 165 static SkData* NewEmpty();
159 166
160 private: 167 private:
161 ReleaseProc fReleaseProc; 168 ReleaseProc fReleaseProc;
162 void* fReleaseProcContext; 169 void* fReleaseProcContext;
170 #ifdef SK_SUPPORT_LEGACY_DATARELEASEPROC_PARAMS
171 LegacyReleaseProc fLegacyReleaseProc;
172 #endif
163 173
164 void* fPtr; 174 void* fPtr;
165 size_t fSize; 175 size_t fSize;
166 176
177 #ifdef SK_SUPPORT_LEGACY_DATARELEASEPROC_PARAMS
178 SkData(const void* ptr, size_t size, ReleaseProc, void* context, LegacyRelea seProc = NULL);
179 #else
167 SkData(const void* ptr, size_t size, ReleaseProc, void* context); 180 SkData(const void* ptr, size_t size, ReleaseProc, void* context);
181 #endif
168 SkData(size_t size); // inplace new/delete 182 SkData(size_t size); // inplace new/delete
169 virtual ~SkData(); 183 virtual ~SkData();
170 184
171 185
172 // Objects of this type are sometimes created in a custom fashion using sk_m alloc_throw and 186 // Objects of this type are sometimes created in a custom fashion using sk_m alloc_throw and
173 // therefore must be sk_freed. We overload new to also call sk_malloc_throw so that memory 187 // therefore must be sk_freed. We overload new to also call sk_malloc_throw so that memory
174 // can be unconditionally released using sk_free in an overloaded delete. Ov erloading regular 188 // can be unconditionally released using sk_free in an overloaded delete. Ov erloading regular
175 // new means we must also overload placement new. 189 // new means we must also overload placement new.
176 void* operator new(size_t size) { return sk_malloc_throw(size); } 190 void* operator new(size_t size) { return sk_malloc_throw(size); }
177 void* operator new(size_t, void* p) { return p; } 191 void* operator new(size_t, void* p) { return p; }
178 void operator delete(void* p) { sk_free(p); } 192 void operator delete(void* p) { sk_free(p); }
179 193
180 // Called the first time someone calls NewEmpty to initialize the singleton. 194 // Called the first time someone calls NewEmpty to initialize the singleton.
181 friend SkData* sk_new_empty_data(); 195 friend SkData* sk_new_empty_data();
182 196
183 // shared internal factory 197 // shared internal factory
184 static SkData* PrivateNewWithCopy(const void* srcOrNull, size_t length); 198 static SkData* PrivateNewWithCopy(const void* srcOrNull, size_t length);
185 199
200 static void DummyReleaseProc(const void*, void*) {}
201
186 typedef SkRefCnt INHERITED; 202 typedef SkRefCnt INHERITED;
187 }; 203 };
188 204
189 /** Typedef of SkAutoTUnref<SkData> for automatically unref-ing a SkData. */ 205 /** Typedef of SkAutoTUnref<SkData> for automatically unref-ing a SkData. */
190 typedef SkAutoTUnref<SkData> SkAutoDataUnref; 206 typedef SkAutoTUnref<SkData> SkAutoDataUnref;
191 207
192 #endif 208 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698