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

Side by Side Diff: src/core/SkDescriptor.h

Issue 1041953002: Switch to one single bitmap text blob cache allocation (Closed) Base URL: https://skia.googlesource.com/skia.git@bmptext2
Patch Set: more tidying Created 5 years, 8 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkDescriptor_DEFINED 10 #ifndef SkDescriptor_DEFINED
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 127 }
128 128
129 // private so no one can create one except our factories 129 // private so no one can create one except our factories
130 SkDescriptor() {} 130 SkDescriptor() {}
131 }; 131 };
132 132
133 #include "SkScalerContext.h" 133 #include "SkScalerContext.h"
134 134
135 class SkAutoDescriptor : SkNoncopyable { 135 class SkAutoDescriptor : SkNoncopyable {
136 public: 136 public:
137 SkAutoDescriptor() : fDesc(NULL) {}
137 SkAutoDescriptor(size_t size) { 138 SkAutoDescriptor(size_t size) {
138 if (size <= sizeof(fStorage)) { 139 this->reset(size);
139 fDesc = (SkDescriptor*)(void*)fStorage;
140 } else {
141 fDesc = SkDescriptor::Alloc(size);
142 }
143 } 140 }
144 141
145 ~SkAutoDescriptor() { 142 ~SkAutoDescriptor() {
146 if (fDesc != (SkDescriptor*)(void*)fStorage) { 143 if (fDesc != (SkDescriptor*)(void*)fStorage) {
147 SkDescriptor::Free(fDesc); 144 SkDescriptor::Free(fDesc);
148 } 145 }
149 } 146 }
150 147
151 SkDescriptor* getDesc() const { return fDesc; } 148 void reset(size_t size) {
149 if (size <= sizeof(fStorage)) {
bsalomon 2015/03/31 21:19:10 don't you need to free the old one here?
joshualitt 2015/04/01 13:21:17 Acknowledged.
150 fDesc = (SkDescriptor*)(void*)fStorage;
151 } else {
152 fDesc = SkDescriptor::Alloc(size);
153 }
154 }
155
156 SkDescriptor* getDesc() const { SkASSERT(fDesc); return fDesc; }
152 private: 157 private:
153 enum { 158 enum {
154 kStorageSize = sizeof(SkDescriptor) 159 kStorageSize = sizeof(SkDescriptor)
155 + sizeof(SkDescriptor::Entry) + sizeof(SkScalerContext:: Rec) // for rec 160 + sizeof(SkDescriptor::Entry) + sizeof(SkScalerContext:: Rec) // for rec
156 + sizeof(SkDescriptor::Entry) + sizeof(void*) // for typeface 161 + sizeof(SkDescriptor::Entry) + sizeof(void*) // for typeface
157 + 32 // slop for occational small extras 162 + 32 // slop for occational small extras
158 }; 163 };
159 SkDescriptor* fDesc; 164 SkDescriptor* fDesc;
160 uint32_t fStorage[(kStorageSize + 3) >> 2]; 165 uint32_t fStorage[(kStorageSize + 3) >> 2];
161 }; 166 };
162 #define SkAutoDescriptor(...) SK_REQUIRE_LOCAL_VAR(SkAutoDescriptor) 167 #define SkAutoDescriptor(...) SK_REQUIRE_LOCAL_VAR(SkAutoDescriptor)
163 168
164 169
165 #endif 170 #endif
OLDNEW
« no previous file with comments | « include/core/SkPaint.h ('k') | src/core/SkPaint.cpp » ('j') | src/core/SkPaint.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698