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

Unified Diff: include/core/SkTypes.h

Issue 1666203002: Move Google3-specific stack limitation logic to template classes. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Fix GLPtr(Alias). Created 4 years, 10 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/gpu/gl/GrGLInterface.h » ('j') | no next file with comments »
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..4592168bd4d6da020179236511f439cd5cd30937 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.
« no previous file with comments | « no previous file | include/gpu/gl/GrGLInterface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698