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

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

Issue 2249703002: add gm that exercises compose shader allocations (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 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 | « gm/composeshader.cpp ('k') | no next file » | 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 2014 Google, Inc 2 * Copyright 2014 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 SkSmallAllocator_DEFINED 8 #ifndef SkSmallAllocator_DEFINED
9 #define SkSmallAllocator_DEFINED 9 #define SkSmallAllocator_DEFINED
10 10
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 */ 73 */
74 template<typename T> void* reserveT(size_t storageRequired = sizeof(T)) { 74 template<typename T> void* reserveT(size_t storageRequired = sizeof(T)) {
75 SkASSERT(fNumObjects < kMaxObjects); 75 SkASSERT(fNumObjects < kMaxObjects);
76 SkASSERT(storageRequired >= sizeof(T)); 76 SkASSERT(storageRequired >= sizeof(T));
77 if (kMaxObjects == fNumObjects) { 77 if (kMaxObjects == fNumObjects) {
78 return nullptr; 78 return nullptr;
79 } 79 }
80 const size_t storageRemaining = sizeof(fStorage) - fStorageUsed; 80 const size_t storageRemaining = sizeof(fStorage) - fStorageUsed;
81 Rec* rec = &fRecs[fNumObjects]; 81 Rec* rec = &fRecs[fNumObjects];
82 if (storageRequired > storageRemaining) { 82 if (storageRequired > storageRemaining) {
83 // Allocate on the heap. Ideally we want to avoid this situation, 83 // Allocate on the heap. Ideally we want to avoid this situation.
84 // but we're not sure we can catch all callers, so handle it but 84
85 // assert false in debug mode. 85 // With the gm composeshader_bitmap2, storage required is 4476
86 SkASSERT(false); 86 // and storage remaining is 3392. Increasing the base storage
87 // causes google 3 tests to fail.
88
87 rec->fStorageSize = 0; 89 rec->fStorageSize = 0;
88 rec->fHeapStorage = sk_malloc_throw(storageRequired); 90 rec->fHeapStorage = sk_malloc_throw(storageRequired);
89 rec->fObj = static_cast<void*>(rec->fHeapStorage); 91 rec->fObj = static_cast<void*>(rec->fHeapStorage);
90 } else { 92 } else {
91 // There is space in fStorage. 93 // There is space in fStorage.
92 rec->fStorageSize = storageRequired; 94 rec->fStorageSize = storageRequired;
93 rec->fHeapStorage = nullptr; 95 rec->fHeapStorage = nullptr;
94 rec->fObj = static_cast<void*>(fStorage.fBytes + fStorageUsed); 96 rec->fObj = static_cast<void*>(fStorage.fBytes + fStorageUsed);
95 fStorageUsed += storageRequired; 97 fStorageUsed += storageRequired;
96 } 98 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 }; 136 };
135 137
136 Storage fStorage; 138 Storage fStorage;
137 // Number of bytes used so far. 139 // Number of bytes used so far.
138 size_t fStorageUsed; 140 size_t fStorageUsed;
139 uint32_t fNumObjects; 141 uint32_t fNumObjects;
140 Rec fRecs[kMaxObjects]; 142 Rec fRecs[kMaxObjects];
141 }; 143 };
142 144
143 #endif // SkSmallAllocator_DEFINED 145 #endif // SkSmallAllocator_DEFINED
OLDNEW
« no previous file with comments | « gm/composeshader.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698