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

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: third attempt 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
« no previous file with comments | « include/core/SkPaint.h ('k') | src/core/SkPaint.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 /* 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(size_t size) { 137 SkAutoDescriptor() : fDesc(NULL) {}
138 SkAutoDescriptor(size_t size) : fDesc(NULL) { this->reset(size); }
139
140 ~SkAutoDescriptor() { this->free(); }
141
142 void reset(size_t size) {
143 this->free();
138 if (size <= sizeof(fStorage)) { 144 if (size <= sizeof(fStorage)) {
139 fDesc = (SkDescriptor*)(void*)fStorage; 145 fDesc = (SkDescriptor*)(void*)fStorage;
140 } else { 146 } else {
141 fDesc = SkDescriptor::Alloc(size); 147 fDesc = SkDescriptor::Alloc(size);
142 } 148 }
143 } 149 }
144 150
145 ~SkAutoDescriptor() { 151 SkDescriptor* getDesc() const { SkASSERT(fDesc); return fDesc; }
152 private:
153 void free() {
146 if (fDesc != (SkDescriptor*)(void*)fStorage) { 154 if (fDesc != (SkDescriptor*)(void*)fStorage) {
147 SkDescriptor::Free(fDesc); 155 SkDescriptor::Free(fDesc);
148 } 156 }
149 } 157 }
150 158
151 SkDescriptor* getDesc() const { return fDesc; }
152 private:
153 enum { 159 enum {
154 kStorageSize = sizeof(SkDescriptor) 160 kStorageSize = sizeof(SkDescriptor)
155 + sizeof(SkDescriptor::Entry) + sizeof(SkScalerContext:: Rec) // for rec 161 + sizeof(SkDescriptor::Entry) + sizeof(SkScalerContext:: Rec) // for rec
156 + sizeof(SkDescriptor::Entry) + sizeof(void*) // for typeface 162 + sizeof(SkDescriptor::Entry) + sizeof(void*) // for typeface
157 + 32 // slop for occational small extras 163 + 32 // slop for occational small extras
158 }; 164 };
159 SkDescriptor* fDesc; 165 SkDescriptor* fDesc;
160 uint32_t fStorage[(kStorageSize + 3) >> 2]; 166 uint32_t fStorage[(kStorageSize + 3) >> 2];
161 }; 167 };
162 #define SkAutoDescriptor(...) SK_REQUIRE_LOCAL_VAR(SkAutoDescriptor) 168 #define SkAutoDescriptor(...) SK_REQUIRE_LOCAL_VAR(SkAutoDescriptor)
163 169
164 170
165 #endif 171 #endif
OLDNEW
« no previous file with comments | « include/core/SkPaint.h ('k') | src/core/SkPaint.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698