Add a parameter GR_ALWAYS_ALLOCATE_ON_HEAP to allow for only ever creating temporary buffers on the heap instead of allowing stack allocation
Unfortunately this can't be a GR_GL_* config like we'd discussed because there are SkAutoSMalloc buffers that are built outside of gl/
R=bsalomon@google.com, bsalomon
BUG=skia:
Author: george@mozilla.com
Review URL: https://codereview.chromium.org/459263003
diff --git a/include/gpu/GrConfig.h b/include/gpu/GrConfig.h
index c0d90a3..80897a0 100644
--- a/include/gpu/GrConfig.h
+++ b/include/gpu/GrConfig.h
@@ -232,4 +232,16 @@
#define GR_STROKE_PATH_RENDERING 0
#endif
+/**
+ * GR_ALWAYS_ALLOCATE_ON_HEAP determines whether various temporary buffers created
+ * in the GPU backend are always allocated on the heap or are allowed to be
+ * allocated on the stack for smaller memory requests.
+ *
+ * This is only used for memory buffers that are created and then passed through to the
+ * 3D API (e.g. as texture or geometry data)
+ */
+#if !defined(GR_ALWAYS_ALLOCATE_ON_HEAP)
+ #define GR_ALWAYS_ALLOCATE_ON_HEAP 0
+#endif
+
#endif
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h
index 41cc7ea..22b2e22 100644
--- a/include/gpu/GrTypes.h
+++ b/include/gpu/GrTypes.h
@@ -708,4 +708,20 @@
///////////////////////////////////////////////////////////////////////////////
+#if GR_ALWAYS_ALLOCATE_ON_HEAP
+ #define GrAutoMallocBaseType SkAutoMalloc
+#else
+ #define GrAutoMallocBaseType SkAutoSMalloc<S>
+#endif
+
+template <size_t S> class GrAutoMalloc : public GrAutoMallocBaseType {
+public:
+ GrAutoMalloc() : INHERITED() {}
+ explicit GrAutoMalloc(size_t size) : INHERITED(size) {}
+ virtual ~GrAutoMalloc() {}
+private:
+ typedef GrAutoMallocBaseType INHERITED;
+};
+
+#undef GrAutoMallocBaseType
#endif
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index caf16e8..830d06b 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -385,7 +385,7 @@
SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig));
size_t bpp = GrBytesPerPixel(desc.fConfig);
- SkAutoSMalloc<128*128*4> stretchedPixels(bpp * rtDesc.fWidth * rtDesc.fHeight);
+ GrAutoMalloc<128*128*4> stretchedPixels(bpp * rtDesc.fWidth * rtDesc.fHeight);
stretch_image(stretchedPixels.get(), rtDesc.fWidth, rtDesc.fHeight,
srcData, desc.fWidth, desc.fHeight, bpp);
diff --git a/src/gpu/GrTextStrike.cpp b/src/gpu/GrTextStrike.cpp
index 9f9ea13..5606fe3 100644
--- a/src/gpu/GrTextStrike.cpp
+++ b/src/gpu/GrTextStrike.cpp
@@ -306,7 +306,8 @@
int bytesPerPixel = GrMaskFormatBytesPerPixel(fMaskFormat);
size_t size = glyph->fBounds.area() * bytesPerPixel;
- SkAutoSMalloc<1024> storage(size);
+ GrAutoMalloc<1024> storage(size);
+
if (fUseDistanceField) {
if (!scaler->getPackedGlyphDFImage(glyph->fPackedID, glyph->width(),
glyph->height(),
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index ed8279d..7131cfa 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -578,7 +578,7 @@
size_t trimRowBytes = width * bpp;
// in case we need a temporary, trimmed copy of the src pixels
- SkAutoSMalloc<128 * 128> tempStorage;
+ GrAutoMalloc<128 * 128> tempStorage;
// We currently lazily create MIPMAPs when the we see a draw with
// GrTextureParams::kMipMap_FilterMode. Using texture storage requires that the
@@ -1666,7 +1666,7 @@
// determine if GL can read using the passed rowBytes or if we need
// a scratch buffer.
- SkAutoSMalloc<32 * sizeof(GrColor)> scratch;
+ GrAutoMalloc<32 * sizeof(GrColor)> scratch;
if (rowBytes != tightRowBytes) {
if (this->glCaps().packRowLengthSupport()) {
SkASSERT(!(rowBytes % sizeof(GrColor)));