aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkTypes.h
diff options
context:
space:
mode:
authorGravatar benjaminwagner <benjaminwagner@google.com>2016-02-05 07:02:38 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-05 07:02:38 -0800
commitf49c75a8f1eacf8e6cb19ce0dcc1cc9bcbf1f96e (patch)
tree54f07f63610fd7533a92fce949b97531a6cf875c /include/core/SkTypes.h
parent001cc1f41be1e6fce39f0cc1426a1497909d91cd (diff)
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
Diffstat (limited to 'include/core/SkTypes.h')
-rw-r--r--include/core/SkTypes.h51
1 files changed, 29 insertions, 22 deletions
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 <size_t kSize> class SkAutoSMalloc : SkNoncopyable {
+template <size_t kSizeRequested> 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.