From f49c75a8f1eacf8e6cb19ce0dcc1cc9bcbf1f96e Mon Sep 17 00:00:00 2001 From: benjaminwagner Date: Fri, 5 Feb 2016 07:02:38 -0800 Subject: Move Google3-specific stack limitation logic to template classes. Remove #ifdefs in other files. Reapplies https://codereview.chromium.org/1656143003; removing the implicit constructors for GLPtr and GLPtrAlias resolves the build issue on Android. Also reverts https://codereview.chromium.org/1663013004 Does not change the public API. TBR=reed GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1666203002 Review URL: https://codereview.chromium.org/1666203002 --- include/core/SkTypes.h | 51 ++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'include/core/SkTypes.h') diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index 0d31efc6cc..4592168bd4 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -606,17 +606,16 @@ private: #define SkAutoMalloc(...) SK_REQUIRE_LOCAL_VAR(SkAutoMalloc) /** - * Manage an allocated block of memory. If the requested size is <= kSize, then - * the allocation will come from the stack rather than the heap. This object - * is the sole manager of the lifetime of the block, so the caller must not - * call sk_free() or delete on the block. + * Manage an allocated block of memory. If the requested size is <= kSizeRequested (or slightly + * more), then the allocation will come from the stack rather than the heap. This object is the + * sole manager of the lifetime of the block, so the caller must not call sk_free() or delete on + * the block. */ -template class SkAutoSMalloc : SkNoncopyable { +template class SkAutoSMalloc : SkNoncopyable { public: /** - * Creates initially empty storage. get() returns a ptr, but it is to - * a zero-byte allocation. Must call reset(size) to return an allocated - * block. + * Creates initially empty storage. get() returns a ptr, but it is to a zero-byte allocation. + * Must call reset(size) to return an allocated block. */ SkAutoSMalloc() { fPtr = fStorage; @@ -624,9 +623,8 @@ public: } /** - * Allocate a block of the specified size. If size <= kSize, then the - * allocation will come from the stack, otherwise it will be dynamically - * allocated. + * Allocate a block of the specified size. If size <= kSizeRequested (or slightly more), then + * the allocation will come from the stack, otherwise it will be dynamically allocated. */ explicit SkAutoSMalloc(size_t size) { fPtr = fStorage; @@ -635,8 +633,8 @@ public: } /** - * Free the allocated block (if any). If the block was small enought to - * have been allocated on the stack (size <= kSize) then this does nothing. + * Free the allocated block (if any). If the block was small enough to have been allocated on + * the stack, then this does nothing. */ ~SkAutoSMalloc() { if (fPtr != (void*)fStorage) { @@ -645,18 +643,16 @@ public: } /** - * Return the allocated block. May return non-null even if the block is - * of zero size. Since this may be on the stack or dynamically allocated, - * the caller must not call sk_free() on it, but must rely on SkAutoSMalloc - * to manage it. + * Return the allocated block. May return non-null even if the block is of zero size. Since + * this may be on the stack or dynamically allocated, the caller must not call sk_free() on it, + * but must rely on SkAutoSMalloc to manage it. */ void* get() const { return fPtr; } /** - * Return a new block of the requested size, freeing (as necessary) any - * previously allocated block. As with the constructor, if size <= kSize - * then the return block may be allocated locally, rather than from the - * heap. + * Return a new block of the requested size, freeing (as necessary) any previously allocated + * block. As with the constructor, if size <= kSizeRequested (or slightly more) then the return + * block may be allocated locally, rather than from the heap. */ void* reset(size_t size, SkAutoMalloc::OnShrink shrink = SkAutoMalloc::kAlloc_OnShrink, @@ -686,9 +682,20 @@ public: } private: + // Align up to 32 bits. + static const size_t kSizeAlign4 = SkAlign4(kSizeRequested); +#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 kSize = kSizeRequested > kMaxBytes ? kMaxBytes : kSizeAlign4; +#else + static const size_t kSize = kSizeAlign4; +#endif + void* fPtr; size_t fSize; // can be larger than the requested size (see kReuse) - uint32_t fStorage[(kSize + 3) >> 2]; + uint32_t fStorage[kSize >> 2]; }; // Can't guard the constructor because it's a template class. -- cgit v1.2.3