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

Unified Diff: include/core/SkTypes.h

Issue 1656143003: Move Google3-specific stack limitation logic to template classes. Remove #ifdefs in other files. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | include/private/SkTemplates.h » ('j') | include/private/SkTemplates.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkTypes.h
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index 0d31efc6ccf7dd904dd7232b094aedaddbbc6870..d4405fbaa4a97d4f47ee17c554c88d3cf7abad54 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -620,7 +620,7 @@ public:
*/
SkAutoSMalloc() {
fPtr = fStorage;
- fSize = kSize;
+ fSize = kSizeAdj;
}
/**
@@ -630,7 +630,7 @@ public:
*/
explicit SkAutoSMalloc(size_t size) {
fPtr = fStorage;
- fSize = kSize;
+ fSize = kSizeAdj;
this->reset(size);
}
@@ -661,7 +661,7 @@ public:
void* reset(size_t size,
SkAutoMalloc::OnShrink shrink = SkAutoMalloc::kAlloc_OnShrink,
bool* didChangeAlloc = NULL) {
- size = (size < kSize) ? kSize : size;
+ size = (size < kSizeAdj) ? kSizeAdj : size;
bool alloc = size != fSize && (SkAutoMalloc::kAlloc_OnShrink == shrink || size > fSize);
if (didChangeAlloc) {
*didChangeAlloc = alloc;
@@ -671,7 +671,7 @@ public:
sk_free(fPtr);
}
- if (size == kSize) {
+ if (size == kSizeAdj) {
SkASSERT(fPtr != fStorage); // otherwise we lied when setting didChangeAlloc.
fPtr = fStorage;
} else {
@@ -680,15 +680,26 @@ public:
fSize = size;
}
- SkASSERT(fSize >= size && fSize >= kSize);
- SkASSERT((fPtr == fStorage) || fSize > kSize);
+ SkASSERT(fSize >= size && fSize >= kSizeAdj);
+ SkASSERT((fPtr == fStorage) || fSize > kSizeAdj);
return fPtr;
}
private:
+ // Align to 32 bits.
mtklein 2016/02/02 03:04:29 Can't hurt to write // Align up to 32 bits.
dogben 2016/02/02 19:39:34 Done.
+ static const size_t kSizeAlign32 = ((kSize + 3) >> 2) << 2;
mtklein 2016/02/02 03:04:29 We do have a nice little macro for this, static c
dogben 2016/02/02 19:39:34 Done, x2.
+#if defined(GOOGLE3)
+ // Stack frame size is limited for GOOGLE3. 4k is less than the actual max, but some functions
+ // have multiple large stack allocations.
+ static const size_t kMaxBytes = 4 * 1024;
+ static const size_t kSizeAdj = kSize > kMaxBytes ? kMaxBytes : kSizeAlign32;
+#else
+ static const size_t kSizeAdj = kSizeAlign32;
+#endif
+
void* fPtr;
size_t fSize; // can be larger than the requested size (see kReuse)
- uint32_t fStorage[(kSize + 3) >> 2];
+ uint32_t fStorage[kSizeAdj >> 2];
};
// Can't guard the constructor because it's a template class.
« no previous file with comments | « no previous file | include/private/SkTemplates.h » ('j') | include/private/SkTemplates.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698