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

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

Issue 651723003: Require SK_DECLARE_STATIC_LAZY_PTR is used in global scope. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: safe unref Created 6 years, 2 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/ports/SkRemotableFontMgr.h ('k') | src/core/SkFontHost.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 "SkLazyPtr.h" 9 #include "SkLazyPtr.h"
10 #include "SkOSFile.h" 10 #include "SkOSFile.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 char* storage = (char*)sk_malloc_throw(sizeof(SkData) + length); 85 char* storage = (char*)sk_malloc_throw(sizeof(SkData) + length);
86 SkData* data = new (storage) SkData(length); 86 SkData* data = new (storage) SkData(length);
87 if (srcOrNull) { 87 if (srcOrNull) {
88 memcpy(data->writable_data(), srcOrNull, length); 88 memcpy(data->writable_data(), srcOrNull, length);
89 } 89 }
90 return data; 90 return data;
91 } 91 }
92 92
93 /////////////////////////////////////////////////////////////////////////////// 93 ///////////////////////////////////////////////////////////////////////////////
94 94
95 SkData* SkData::NewEmptyImpl() { 95 // As a template argument these must have external linkage.
96 return new SkData(NULL, 0, NULL, NULL); 96 SkData* sk_new_empty_data() { return new SkData(NULL, 0, NULL, NULL); }
97 } 97 namespace { void sk_unref_data(SkData* ptr) { return SkSafeUnref(ptr); } }
98 98
99 void SkData::DeleteEmpty(SkData* ptr) { SkDELETE(ptr); } 99 SK_DECLARE_STATIC_LAZY_PTR(SkData, empty, sk_new_empty_data, sk_unref_data);
100 100
101 SkData* SkData::NewEmpty() { 101 SkData* SkData::NewEmpty() {
102 SK_DECLARE_STATIC_LAZY_PTR(SkData, empty, NewEmptyImpl, DeleteEmpty);
103 return SkRef(empty.get()); 102 return SkRef(empty.get());
104 } 103 }
105 104
106 // assumes fPtr was allocated via sk_malloc 105 // assumes fPtr was allocated via sk_malloc
107 static void sk_free_releaseproc(const void* ptr, size_t, void*) { 106 static void sk_free_releaseproc(const void* ptr, size_t, void*) {
108 sk_free((void*)ptr); 107 sk_free((void*)ptr);
109 } 108 }
110 109
111 SkData* SkData::NewFromMalloc(const void* data, size_t length) { 110 SkData* SkData::NewFromMalloc(const void* data, size_t length) {
112 return new SkData(data, length, sk_free_releaseproc, NULL); 111 return new SkData(data, length, sk_free_releaseproc, NULL);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 /////////////////////////////////////////////////////////////////////////////// 202 ///////////////////////////////////////////////////////////////////////////////
204 203
205 SkData* SkData::NewFromStream(SkStream* stream, size_t size) { 204 SkData* SkData::NewFromStream(SkStream* stream, size_t size) {
206 SkAutoDataUnref data(SkData::NewUninitialized(size)); 205 SkAutoDataUnref data(SkData::NewUninitialized(size));
207 if (stream->read(data->writable_data(), size) != size) { 206 if (stream->read(data->writable_data(), size) != size) {
208 return NULL; 207 return NULL;
209 } 208 }
210 return data.detach(); 209 return data.detach();
211 } 210 }
212 211
OLDNEW
« no previous file with comments | « include/ports/SkRemotableFontMgr.h ('k') | src/core/SkFontHost.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698