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

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

Issue 132803005: SkOnce: add option to call another cleanup function once at exit. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add static Created 6 years, 11 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 | « include/core/SkPathRef.h ('k') | src/core/SkPathRef.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 30 matching lines...) Expand all
41 length = available; 41 length = available;
42 } 42 }
43 SkASSERT(length > 0); 43 SkASSERT(length > 0);
44 44
45 memcpy(buffer, this->bytes() + offset, length); 45 memcpy(buffer, this->bytes() + offset, length);
46 return length; 46 return length;
47 } 47 }
48 48
49 /////////////////////////////////////////////////////////////////////////////// 49 ///////////////////////////////////////////////////////////////////////////////
50 50
51 void SkData::NewEmptyImpl(SkData** empty) { 51 static SkData* gEmptyDataRef = NULL;
52 *empty = new SkData(NULL, 0, NULL, NULL); 52 static void cleanup_gEmptyDataRef() { gEmptyDataRef->unref(); }
53
54 void SkData::NewEmptyImpl(int) {
55 gEmptyDataRef = new SkData(NULL, 0, NULL, NULL);
53 } 56 }
54 57
55 SkData* SkData::NewEmpty() { 58 SkData* SkData::NewEmpty() {
56 static SkData* gEmptyRef;
57 SK_DECLARE_STATIC_ONCE(once); 59 SK_DECLARE_STATIC_ONCE(once);
58 SkOnce(&once, SkData::NewEmptyImpl, &gEmptyRef); 60 SkOnce(&once, SkData::NewEmptyImpl, 0, cleanup_gEmptyDataRef);
59 gEmptyRef->ref(); 61 gEmptyDataRef->ref();
60 return gEmptyRef; 62 return gEmptyDataRef;
61 } 63 }
62 64
63 // assumes fPtr was allocated via sk_malloc 65 // assumes fPtr was allocated via sk_malloc
64 static void sk_free_releaseproc(const void* ptr, size_t, void*) { 66 static void sk_free_releaseproc(const void* ptr, size_t, void*) {
65 sk_free((void*)ptr); 67 sk_free((void*)ptr);
66 } 68 }
67 69
68 SkData* SkData::NewFromMalloc(const void* data, size_t length) { 70 SkData* SkData::NewFromMalloc(const void* data, size_t length) {
69 return new SkData(data, length, sk_free_releaseproc, NULL); 71 return new SkData(data, length, sk_free_releaseproc, NULL);
70 } 72 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 SkData* SkData::NewWithCString(const char cstr[]) { 152 SkData* SkData::NewWithCString(const char cstr[]) {
151 size_t size; 153 size_t size;
152 if (NULL == cstr) { 154 if (NULL == cstr) {
153 cstr = ""; 155 cstr = "";
154 size = 1; 156 size = 1;
155 } else { 157 } else {
156 size = strlen(cstr) + 1; 158 size = strlen(cstr) + 1;
157 } 159 }
158 return NewWithCopy(cstr, size); 160 return NewWithCopy(cstr, size);
159 } 161 }
OLDNEW
« no previous file with comments | « include/core/SkPathRef.h ('k') | src/core/SkPathRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698