SkTypes.h : move SkAutoMalloc into SkAutoMalloc.h
authorHal Canary <halcanary@google.com>
Wed, 11 Jan 2017 17:44:43 +0000 (12:44 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 11 Jan 2017 18:55:34 +0000 (18:55 +0000)
  * SkAutoFree moved to SkTemplates.h (now implmented with unique_ptr).

  * SkAutoMalloc and SkAutoSMalloc moved to SkAutoMalloc.h

  * "SkAutoFree X(sk_malloc_throw(N));" --> "SkAutoMalloc X(N);"

Revert "Revert 'SkTypes.h : move SkAutoMalloc into SkAutoMalloc.h'"
This reverts commit c456b73fef9589bbdc5eb83eaa83e53c357bb3da.

Change-Id: Ie2c1a17c20134b8ceab85a68b3ae3e61c24fbaab
Reviewed-on: https://skia-review.googlesource.com/6886
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>

55 files changed:
bench/AndroidCodecBench.h
bench/CodecBench.h
bench/ColorCodecBench.h
bench/nanobench.cpp
dm/DMSrcSink.cpp
gm/drawatlas.cpp
include/core/SkShader.h
include/core/SkTypes.h
include/private/SkAutoMalloc.h [new file with mode: 0644]
include/private/SkTemplates.h
src/core/SkAAClip.h
src/core/SkBlitter.h
src/core/SkColorSpace_ICC.cpp
src/core/SkDistanceFieldGen.cpp
src/core/SkFontStream.cpp
src/core/SkICC.cpp
src/core/SkLinearBitmapPipeline_sample.h
src/core/SkMaskFilter.cpp
src/core/SkPictureData.cpp
src/core/SkScalerContext.cpp
src/core/SkScan_AAAPath.cpp
src/effects/gradients/SkGradientShaderPriv.h
src/gpu/GrDistanceFieldGenFromVector.cpp
src/gpu/GrYUVProvider.cpp
src/gpu/SkGr.cpp
src/gpu/gl/GrGLGpu.cpp
src/gpu/gl/builders/GrGLProgramBuilder.cpp
src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
src/gpu/ops/GrAADistanceFieldPathRenderer.cpp
src/gpu/ops/GrMSAAPathRenderer.cpp
src/gpu/text/GrAtlasGlyphCache.cpp
src/gpu/vk/GrVkBackendContext.cpp
src/gpu/vk/GrVkPipelineStateDataManager.h
src/pipe/SkPipeCanvas.cpp
src/ports/SkFontConfigInterface_direct.cpp
src/ports/SkFontHost_FreeType.cpp
src/ports/SkFontHost_mac.cpp
src/ports/SkImageEncoder_WIC.cpp
tests/CodecTest.cpp
tests/ColorFilterTest.cpp
tests/FontHostTest.cpp
tests/FrontBufferedStreamTest.cpp
tests/MallocPixelRefTest.cpp
tests/PaintBreakTextTest.cpp
tests/PaintTest.cpp
tests/PathTest.cpp
tests/RegionTest.cpp
tests/StreamTest.cpp
tests/Writer32Test.cpp
tests/YUVTest.cpp
third_party/ktx/ktx.cpp
tools/SkShaper_harfbuzz.cpp
tools/debugger/SkDrawCommand.cpp
tools/viewer/sk_app/VulkanWindowContext.cpp
tools/viewer/sk_app/win/RasterWindowContext_win.cpp

index 8cdd7fe..528ecab 100644 (file)
@@ -9,6 +9,7 @@
 #define AndroidCodecBench_DEFINED
 
 #include "Benchmark.h"
+#include "SkAutoMalloc.h"
 #include "SkData.h"
 #include "SkImageInfo.h"
 #include "SkRefCnt.h"
index 5b4db24..dc44704 100644 (file)
@@ -9,6 +9,7 @@
 #define CodecBench_DEFINED
 
 #include "Benchmark.h"
+#include "SkAutoMalloc.h"
 #include "SkData.h"
 #include "SkImageInfo.h"
 #include "SkRefCnt.h"
index 9159bcf..e5048f8 100644 (file)
@@ -9,6 +9,7 @@
 #define ColorCodecBench_DEFINED
 
 #include "Benchmark.h"
+#include "SkAutoMalloc.h"
 #include "SkData.h"
 #include "SkImageInfo.h"
 
index c9456db..34aaee8 100644 (file)
@@ -25,8 +25,9 @@
 #include "Stats.h"
 
 #include "SkAndroidCodec.h"
-#include "SkBitmapRegionDecoder.h"
+#include "SkAutoMalloc.h"
 #include "SkBBoxHierarchy.h"
+#include "SkBitmapRegionDecoder.h"
 #include "SkCanvas.h"
 #include "SkCodec.h"
 #include "SkCommonFlags.h"
 #include "SkOSPath.h"
 #include "SkPictureRecorder.h"
 #include "SkPictureUtils.h"
+#include "SkSVGDOM.h"
+#include "SkScan.h"
 #include "SkString.h"
 #include "SkSurface.h"
-#include "SkSVGDOM.h"
 #include "SkTaskGroup.h"
 #include "SkThreadUtils.h"
 #include "ThermalManager.h"
-#include "SkScan.h"
 
 #include <stdlib.h>
 
index 594a4b7..cea87f7 100644 (file)
@@ -8,11 +8,12 @@
 #include "DMSrcSink.h"
 #include "Resources.h"
 #include "SkAndroidCodec.h"
+#include "SkAutoMalloc.h"
 #include "SkCodec.h"
 #include "SkCodecImageGenerator.h"
 #include "SkColorSpace.h"
-#include "SkColorSpace_XYZ.h"
 #include "SkColorSpaceXform.h"
+#include "SkColorSpace_XYZ.h"
 #include "SkCommonFlags.h"
 #include "SkData.h"
 #include "SkDebugCanvas.h"
 #include "SkRecorder.h"
 #include "SkSVGCanvas.h"
 #include "SkStream.h"
-#include "SkTLogic.h"
 #include "SkSwizzler.h"
-#include <functional>
+#include "SkTLogic.h"
 #include <cmath>
+#include <functional>
 
 #if defined(SK_BUILD_FOR_WIN)
     #include "SkAutoCoInitialize.h"
index c098e15..2526177 100644 (file)
@@ -6,6 +6,8 @@
  */
 
 #include "gm.h"
+
+#include "SkAutoMalloc.h"
 #include "SkCanvas.h"
 #include "SkRSXform.h"
 #include "SkSurface.h"
index 6d24c1a..0519fe1 100644 (file)
 #include "SkPaint.h"
 #include "../gpu/GrColor.h"
 
+#ifdef GOOGLE3
+#include "../private/SkAutoMalloc.h"
+#endif
+
 class SkColorFilter;
 class SkColorSpace;
 class SkFallbackAlloc;
index 2cc4b9c..f9e1a05 100644 (file)
@@ -509,222 +509,6 @@ private:
     SkNoncopyable& operator=(const SkNoncopyable&);
 };
 
-class SkAutoFree : SkNoncopyable {
-public:
-    SkAutoFree() : fPtr(NULL) {}
-    explicit SkAutoFree(void* ptr) : fPtr(ptr) {}
-    ~SkAutoFree() { sk_free(fPtr); }
-
-    /** Return the currently allocate buffer, or null
-    */
-    void* get() const { return fPtr; }
-
-    /** Assign a new ptr allocated with sk_malloc (or null), and return the
-        previous ptr. Note it is the caller's responsibility to sk_free the
-        returned ptr.
-    */
-    void* set(void* ptr) {
-        void* prev = fPtr;
-        fPtr = ptr;
-        return prev;
-    }
-
-    /** Transfer ownership of the current ptr to the caller, setting the
-        internal reference to null. Note the caller is reponsible for calling
-        sk_free on the returned address.
-    */
-    void* release() { return this->set(NULL); }
-
-    /** Free the current buffer, and set the internal reference to NULL. Same
-        as calling sk_free(release())
-    */
-    void reset() {
-        sk_free(fPtr);
-        fPtr = NULL;
-    }
-
-private:
-    void* fPtr;
-    // illegal
-    SkAutoFree(const SkAutoFree&);
-    SkAutoFree& operator=(const SkAutoFree&);
-};
-#define SkAutoFree(...) SK_REQUIRE_LOCAL_VAR(SkAutoFree)
-
-/**
- *  Manage an allocated block of heap memory. 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, unless release() was called.
- */
-class SkAutoMalloc : SkNoncopyable {
-public:
-    explicit SkAutoMalloc(size_t size = 0) {
-        fPtr = size ? sk_malloc_throw(size) : NULL;
-        fSize = size;
-    }
-
-    ~SkAutoMalloc() {
-        sk_free(fPtr);
-    }
-
-    /**
-     *  Passed to reset to specify what happens if the requested size is smaller
-     *  than the current size (and the current block was dynamically allocated).
-     */
-    enum OnShrink {
-        /**
-         *  If the requested size is smaller than the current size, and the
-         *  current block is dynamically allocated, free the old block and
-         *  malloc a new block of the smaller size.
-         */
-        kAlloc_OnShrink,
-
-        /**
-         *  If the requested size is smaller than the current size, and the
-         *  current block is dynamically allocated, just return the old
-         *  block.
-         */
-        kReuse_OnShrink
-    };
-
-    /**
-     *  Reallocates the block to a new size. The ptr may or may not change.
-     */
-    void* reset(size_t size = 0, OnShrink shrink = kAlloc_OnShrink,  bool* didChangeAlloc = NULL) {
-        if (size == fSize || (kReuse_OnShrink == shrink && size < fSize)) {
-            if (didChangeAlloc) {
-                *didChangeAlloc = false;
-            }
-            return fPtr;
-        }
-
-        sk_free(fPtr);
-        fPtr = size ? sk_malloc_throw(size) : NULL;
-        fSize = size;
-        if (didChangeAlloc) {
-            *didChangeAlloc = true;
-        }
-
-        return fPtr;
-    }
-
-    /**
-     *  Return the allocated block.
-     */
-    void* get() { return fPtr; }
-    const void* get() const { return fPtr; }
-
-   /** Transfer ownership of the current ptr to the caller, setting the
-       internal reference to null. Note the caller is reponsible for calling
-       sk_free on the returned address.
-    */
-    void* release() {
-        void* ptr = fPtr;
-        fPtr = NULL;
-        fSize = 0;
-        return ptr;
-    }
-
-private:
-    void*   fPtr;
-    size_t  fSize;  // can be larger than the requested size (see kReuse)
-};
-#define SkAutoMalloc(...) SK_REQUIRE_LOCAL_VAR(SkAutoMalloc)
-
-/**
- *  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 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.
-     */
-    SkAutoSMalloc() {
-        fPtr = fStorage;
-        fSize = kSize;
-    }
-
-    /**
-     *  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;
-        fSize = kSize;
-        this->reset(size);
-    }
-
-    /**
-     *  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) {
-            sk_free(fPtr);
-        }
-    }
-
-    /**
-     *  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 <= 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,
-                bool* didChangeAlloc = NULL) {
-        size = (size < kSize) ? kSize : size;
-        bool alloc = size != fSize && (SkAutoMalloc::kAlloc_OnShrink == shrink || size > fSize);
-        if (didChangeAlloc) {
-            *didChangeAlloc = alloc;
-        }
-        if (alloc) {
-            if (fPtr != (void*)fStorage) {
-                sk_free(fPtr);
-            }
-
-            if (size == kSize) {
-                SkASSERT(fPtr != fStorage); // otherwise we lied when setting didChangeAlloc.
-                fPtr = fStorage;
-            } else {
-                fPtr = sk_malloc_flags(size, SK_MALLOC_THROW | SK_MALLOC_TEMP);
-            }
-
-            fSize = size;
-        }
-        SkASSERT(fSize >= size && fSize >= kSize);
-        SkASSERT((fPtr == fStorage) || fSize > kSize);
-        return fPtr;
-    }
-
-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 >> 2];
-};
-// Can't guard the constructor because it's a template class.
-
 #endif /* C++ */
 
 #endif
diff --git a/include/private/SkAutoMalloc.h b/include/private/SkAutoMalloc.h
new file mode 100644 (file)
index 0000000..7be8825
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkAutoMalloc_DEFINED
+#define SkAutoMalloc_DEFINED
+
+#include "SkTypes.h"
+
+#include <memory>
+
+/**
+ *  Manage an allocated block of heap memory. 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, unless release() was called.
+ */
+class SkAutoMalloc : SkNoncopyable {
+public:
+    explicit SkAutoMalloc(size_t size = 0)
+        : fPtr(size ? sk_malloc_throw(size) : nullptr), fSize(size) {}
+
+    /**
+     *  Passed to reset to specify what happens if the requested size is smaller
+     *  than the current size (and the current block was dynamically allocated).
+     */
+    enum OnShrink {
+        /**
+         *  If the requested size is smaller than the current size, and the
+         *  current block is dynamically allocated, free the old block and
+         *  malloc a new block of the smaller size.
+         */
+        kAlloc_OnShrink,
+
+        /**
+         *  If the requested size is smaller than the current size, and the
+         *  current block is dynamically allocated, just return the old
+         *  block.
+         */
+        kReuse_OnShrink
+    };
+
+    /**
+     *  Reallocates the block to a new size. The ptr may or may not change.
+     */
+    void* reset(size_t size = 0, OnShrink shrink = kAlloc_OnShrink) {
+        if (size != fSize && (size > fSize || kReuse_OnShrink != shrink)) {
+            fPtr.reset(size ? sk_malloc_throw(size) : nullptr);
+            fSize = size;
+        }
+        return fPtr.get();
+    }
+
+    /**
+     *  Return the allocated block.
+     */
+    void* get() { return fPtr.get(); }
+    const void* get() const { return fPtr.get(); }
+
+   /** Transfer ownership of the current ptr to the caller, setting the
+       internal reference to null. Note the caller is reponsible for calling
+       sk_free on the returned address.
+    */
+    void* release() {
+        fSize = 0;
+        return fPtr.release();
+    }
+
+private:
+    struct WrapFree {
+        void operator()(void* p) { sk_free(p); }
+    };
+    std::unique_ptr<void, WrapFree> fPtr;
+    size_t fSize;  // can be larger than the requested size (see kReuse)
+};
+#define SkAutoMalloc(...) SK_REQUIRE_LOCAL_VAR(SkAutoMalloc)
+
+/**
+ *  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 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.
+     */
+    SkAutoSMalloc() {
+        fPtr = fStorage;
+        fSize = kSize;
+    }
+
+    /**
+     *  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;
+        fSize = kSize;
+        this->reset(size);
+    }
+
+    /**
+     *  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) {
+            sk_free(fPtr);
+        }
+    }
+
+    /**
+     *  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 <= 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,
+                bool* didChangeAlloc = nullptr) {
+        size = (size < kSize) ? kSize : size;
+        bool alloc = size != fSize && (SkAutoMalloc::kAlloc_OnShrink == shrink || size > fSize);
+        if (didChangeAlloc) {
+            *didChangeAlloc = alloc;
+        }
+        if (alloc) {
+            if (fPtr != (void*)fStorage) {
+                sk_free(fPtr);
+            }
+
+            if (size == kSize) {
+                SkASSERT(fPtr != fStorage); // otherwise we lied when setting didChangeAlloc.
+                fPtr = fStorage;
+            } else {
+                fPtr = sk_malloc_flags(size, SK_MALLOC_THROW | SK_MALLOC_TEMP);
+            }
+
+            fSize = size;
+        }
+        SkASSERT(fSize >= size && fSize >= kSize);
+        SkASSERT((fPtr == fStorage) || fSize > kSize);
+        return fPtr;
+    }
+
+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 >> 2];
+};
+// Can't guard the constructor because it's a template class.
+
+#endif
index 5c6403d..f50af8b 100644 (file)
@@ -462,4 +462,6 @@ private:
     SkAlignedSStorage<sizeof(T)*N> fStorage;
 };
 
+using SkAutoFree = std::unique_ptr<void, SkFunctionWrapper<void, void, sk_free>>;
+
 #endif
index 7b29ef1..c94756f 100644 (file)
@@ -8,6 +8,7 @@
 #ifndef SkAAClip_DEFINED
 #define SkAAClip_DEFINED
 
+#include "SkAutoMalloc.h"
 #include "SkBlitter.h"
 #include "SkRegion.h"
 
index f03a308..fd6ca8c 100644 (file)
@@ -8,12 +8,12 @@
 #ifndef SkBlitter_DEFINED
 #define SkBlitter_DEFINED
 
+#include "SkAutoMalloc.h"
 #include "SkBitmapProcShader.h"
 #include "SkColor.h"
 #include "SkRect.h"
 #include "SkRegion.h"
 #include "SkShader.h"
-#include "SkTypes.h"
 
 class SkMatrix;
 class SkPaint;
index 29291a3..ff4b901 100644 (file)
@@ -5,11 +5,12 @@
  * found in the LICENSE file.
  */
 
+#include "SkAutoMalloc.h"
 #include "SkColorSpace.h"
+#include "SkColorSpacePriv.h"
 #include "SkColorSpace_A2B.h"
 #include "SkColorSpace_Base.h"
 #include "SkColorSpace_XYZ.h"
-#include "SkColorSpacePriv.h"
 #include "SkEndian.h"
 #include "SkFixed.h"
 #include "SkICCPriv.h"
index 7e4675b..f227d6a 100644 (file)
@@ -5,8 +5,10 @@
  * found in the LICENSE file.
  */
 
+#include "SkAutoMalloc.h"
 #include "SkDistanceFieldGen.h"
 #include "SkPoint.h"
+#include "SkTemplates.h"
 
 struct DFData {
     float   fAlpha;      // alpha value of source texel
index b2ffe8d..e9f23f9 100644 (file)
@@ -5,6 +5,7 @@
  * found in the LICENSE file.
  */
 
+#include "SkAutoMalloc.h"
 #include "SkEndian.h"
 #include "SkFontStream.h"
 #include "SkStream.h"
index b47cc71..6b09f29 100644 (file)
@@ -5,6 +5,7 @@
  * found in the LICENSE file.
  */
 
+#include "SkAutoMalloc.h"
 #include "SkColorSpace_Base.h"
 #include "SkColorSpace_XYZ.h"
 #include "SkColorSpacePriv.h"
index 8e53136..0bfe8f2 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <tuple>
 
+#include "SkAutoMalloc.h"
 #include "SkColor.h"
 #include "SkColorPriv.h"
 #include "SkFixed.h"
index 85ee38d..8ad13aa 100644 (file)
@@ -5,15 +5,15 @@
  * found in the LICENSE file.
  */
 
-
 #include "SkMaskFilter.h"
+
+#include "SkAutoMalloc.h"
 #include "SkBlitter.h"
-#include "SkDraw.h"
 #include "SkCachedData.h"
+#include "SkDraw.h"
 #include "SkPath.h"
-#include "SkRasterClip.h"
 #include "SkRRect.h"
-#include "SkTypes.h"
+#include "SkRasterClip.h"
 
 #if SK_SUPPORT_GPU
 #include "GrTexture.h"
index 1aff1e4..9780b7d 100644 (file)
@@ -4,7 +4,10 @@
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+
 #include <new>
+
+#include "SkAutoMalloc.h"
 #include "SkImageGenerator.h"
 #include "SkPictureData.h"
 #include "SkPictureRecord.h"
index c06222d..4835b52 100644 (file)
@@ -5,8 +5,9 @@
  * found in the LICENSE file.
  */
 
-
 #include "SkScalerContext.h"
+
+#include "SkAutoMalloc.h"
 #include "SkAutoPixmapStorage.h"
 #include "SkColorPriv.h"
 #include "SkDescriptor.h"
 #include "SkMaskFilter.h"
 #include "SkMaskGamma.h"
 #include "SkMatrix22.h"
-#include "SkReadBuffer.h"
-#include "SkWriteBuffer.h"
 #include "SkPathEffect.h"
-#include "SkRasterizer.h"
 #include "SkRasterClip.h"
+#include "SkRasterizer.h"
+#include "SkReadBuffer.h"
 #include "SkStroke.h"
 #include "SkStrokeRec.h"
+#include "SkWriteBuffer.h"
 
 #define ComputeBWRowBytes(width)        (((unsigned)(width) + 7) >> 3)
 
index f96e7b9..8c0a748 100644 (file)
@@ -5,10 +5,11 @@
  * found in the LICENSE file.
  */
 
+#include "SkAnalyticEdge.h"
 #include "SkAntiRun.h"
+#include "SkAutoMalloc.h"
 #include "SkBlitter.h"
 #include "SkEdge.h"
-#include "SkAnalyticEdge.h"
 #include "SkEdgeBuilder.h"
 #include "SkGeometry.h"
 #include "SkPath.h"
@@ -17,8 +18,8 @@
 #include "SkRegion.h"
 #include "SkScan.h"
 #include "SkScanPriv.h"
-#include "SkTemplates.h"
 #include "SkTSort.h"
+#include "SkTemplates.h"
 #include "SkUtils.h"
 
 ///////////////////////////////////////////////////////////////////////////////
index 4b7bbb0..48ccbd5 100644 (file)
 
 #include "SkGradientBitmapCache.h"
 #include "SkGradientShader.h"
+
+#include "SkAutoMalloc.h"
 #include "SkClampRange.h"
 #include "SkColorPriv.h"
 #include "SkColorSpace.h"
-#include "SkReadBuffer.h"
-#include "SkWriteBuffer.h"
 #include "SkMallocPixelRef.h"
-#include "SkUtils.h"
-#include "SkShader.h"
 #include "SkOnce.h"
+#include "SkReadBuffer.h"
+#include "SkShader.h"
+#include "SkUtils.h"
+#include "SkWriteBuffer.h"
 
 #if SK_SUPPORT_GPU
     #define GR_GL_USE_ACCURATE_HARD_STOP_GRADIENTS 1
index 8179500..4a509e6 100644 (file)
@@ -7,12 +7,14 @@
 
 #include "SkDistanceFieldGen.h"
 #include "GrDistanceFieldGenFromVector.h"
-#include "SkMatrix.h"
-#include "SkPoint.h"
+
+#include "GrConfig.h"
+#include "GrPathUtils.h"
+#include "SkAutoMalloc.h"
 #include "SkGeometry.h"
+#include "SkMatrix.h"
 #include "SkPathOps.h"
-#include "GrPathUtils.h"
-#include "GrConfig.h"
+#include "SkPoint.h"
 
 /**
  * If a scanline (a row of texel) cross from the kRight_SegSide
index 6fbad18..9f88c72 100644 (file)
@@ -11,6 +11,7 @@
 #include "effects/GrGammaEffect.h"
 #include "effects/GrYUVEffect.h"
 
+#include "SkAutoMalloc.h"
 #include "SkCachedData.h"
 #include "SkRefCnt.h"
 #include "SkResourceCache.h"
index 9d6072c..c1a4160 100644 (file)
@@ -5,7 +5,6 @@
  * found in the LICENSE file.
  */
 
-
 #include "SkGr.h"
 #include "SkGrPriv.h"
 
 #include "GrXferProcessor.h"
 #include "GrYUVProvider.h"
 
+#include "SkAutoMalloc.h"
 #include "SkBlendModePriv.h"
+#include "SkCanvas.h"
 #include "SkColorFilter.h"
 #include "SkConfig8888.h"
-#include "SkCanvas.h"
 #include "SkData.h"
 #include "SkMaskFilter.h"
 #include "SkMessageBus.h"
 #include "SkMipMap.h"
-#include "SkPixelRef.h"
 #include "SkPM4fPriv.h"
+#include "SkPixelRef.h"
 #include "SkResourceCache.h"
 #include "SkTemplates.h"
 #include "SkYUVPlanesCache.h"
index 74e5258..95a01ab 100644 (file)
@@ -6,31 +6,33 @@
  */
 
 #include "GrGLGpu.h"
+
+#include "../private/GrGLSL.h"
+#include "GrFixedClip.h"
 #include "GrGLBuffer.h"
 #include "GrGLGpuCommandBuffer.h"
 #include "GrGLStencilAttachment.h"
 #include "GrGLTextureRenderTarget.h"
-#include "GrFixedClip.h"
 #include "GrGpuResourcePriv.h"
 #include "GrMesh.h"
-#include "GrPipeline.h"
 #include "GrPLSGeometryProcessor.h"
+#include "GrPipeline.h"
 #include "GrRenderTargetPriv.h"
 #include "GrShaderCaps.h"
 #include "GrSurfacePriv.h"
 #include "GrTexturePriv.h"
 #include "GrTypes.h"
-#include "builders/GrGLShaderStringBuilder.h"
-#include "glsl/GrGLSLPLSPathRendering.h"
-#include "instanced/GLInstancedRendering.h"
+#include "SkAutoMalloc.h"
 #include "SkMakeUnique.h"
 #include "SkMipMap.h"
 #include "SkPixmap.h"
-#include "SkStrokeRec.h"
 #include "SkSLCompiler.h"
+#include "SkStrokeRec.h"
 #include "SkTemplates.h"
 #include "SkTypes.h"
-#include "../private/GrGLSL.h"
+#include "builders/GrGLShaderStringBuilder.h"
+#include "glsl/GrGLSLPLSPathRendering.h"
+#include "instanced/GLInstancedRendering.h"
 
 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X)
index 045593f..c3e81fb 100644 (file)
@@ -14,6 +14,7 @@
 #include "GrShaderCaps.h"
 #include "GrSwizzle.h"
 #include "GrTexture.h"
+#include "SkAutoMalloc.h"
 #include "SkTraceEvent.h"
 #include "gl/GrGLGpu.h"
 #include "gl/GrGLProgram.h"
index df44edd..6c719fe 100644 (file)
@@ -6,11 +6,12 @@
  */
 
 #include "GrGLShaderStringBuilder.h"
-#include "gl/GrGLGpu.h"
-#include "gl/GrGLSLPrettyPrint.h"
-#include "SkTraceEvent.h"
+#include "SkAutoMalloc.h"
 #include "SkSLCompiler.h"
 #include "SkSLGLSLCodeGenerator.h"
+#include "SkTraceEvent.h"
+#include "gl/GrGLGpu.h"
+#include "gl/GrGLSLPrettyPrint.h"
 #include "ir/SkSLProgram.h"
 
 #define GL_CALL(X) GR_GL_CALL(gpu->glInterface(), X)
index c9b30f5..616b69f 100644 (file)
@@ -21,6 +21,7 @@
 #include "ops/GrMeshDrawOp.h"
 
 #include "SkPathOps.h"
+#include "SkAutoMalloc.h"
 #include "SkDistanceFieldGen.h"
 #include "GrDistanceFieldGenFromVector.h"
 
index cc6781c..53e4690 100644 (file)
@@ -16,6 +16,7 @@
 #include "GrPathStencilSettings.h"
 #include "GrPathUtils.h"
 #include "GrPipelineBuilder.h"
+#include "SkAutoMalloc.h"
 #include "SkGeometry.h"
 #include "SkTraceEvent.h"
 #include "gl/GrGLVaryingHandler.h"
@@ -346,7 +347,7 @@ private:
 
         MSAAQuadVertices quads;
         size_t quadVertexStride = sizeof(MSAAQuadVertices::Vertex);
-        SkAutoFree quadVertexPtr(sk_malloc_throw(fMaxQuadVertices * quadVertexStride));
+        SkAutoMalloc quadVertexPtr(fMaxQuadVertices * quadVertexStride);
         quads.vertices = (MSAAQuadVertices::Vertex*) quadVertexPtr.get();
         quads.nextVertex = quads.vertices;
         SkDEBUGCODE(quads.verticesEnd = quads.vertices + fMaxQuadVertices;)
@@ -369,7 +370,7 @@ private:
         SkAutoFree quadIndexPtr;
         if (fIsIndexed) {
             quads.indices = (uint16_t*)sk_malloc_throw(3 * fMaxQuadVertices * sizeof(uint16_t));
-            quadIndexPtr.set(quads.indices);
+            quadIndexPtr.reset(quads.indices);
             quads.nextIndex = quads.indices;
         } else {
             quads.indices = nullptr;
index 5d85f49..e51f6cc 100644 (file)
@@ -11,6 +11,7 @@
 #include "GrRectanizer.h"
 #include "GrResourceProvider.h"
 #include "GrSurfacePriv.h"
+#include "SkAutoMalloc.h"
 #include "SkString.h"
 
 #include "SkDistanceFieldGen.h"
index 93ae01f..5a9de04 100644 (file)
@@ -5,6 +5,7 @@
  * found in the LICENSE file.
  */
 
+#include "SkAutoMalloc.h"
 #include "vk/GrVkBackendContext.h"
 #include "vk/GrVkExtensions.h"
 #include "vk/GrVkInterface.h"
index 312c6c6..4a061a6 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "glsl/GrGLSLProgramDataManager.h"
 
+#include "SkAutoMalloc.h"
 #include "vk/GrVkUniformHandler.h"
 
 class GrVkGpu;
index 33b58a4..e707f0d 100644 (file)
@@ -5,15 +5,16 @@
  * found in the LICENSE file.
  */
 
-#include "SkPathEffect.h"
+#include "SkAutoMalloc.h"
 #include "SkColorFilter.h"
 #include "SkDrawLooper.h"
 #include "SkImageFilter.h"
 #include "SkMaskFilter.h"
+#include "SkPathEffect.h"
 #include "SkPipeCanvas.h"
 #include "SkPipeFormat.h"
-#include "SkRasterizer.h"
 #include "SkRSXform.h"
+#include "SkRasterizer.h"
 #include "SkShader.h"
 #include "SkStream.h"
 #include "SkTextBlob.h"
index df68fae..c1a73e6 100644 (file)
@@ -7,6 +7,7 @@
 
 /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */
 
+#include "SkAutoMalloc.h"
 #include "SkBuffer.h"
 #include "SkDataTable.h"
 #include "SkFixed.h"
@@ -19,7 +20,6 @@
 #include "SkTDArray.h"
 #include "SkTemplates.h"
 #include "SkTypeface.h"
-#include "SkTypes.h"
 
 #include <fontconfig/fontconfig.h>
 #include <unistd.h>
index 15bc14d..47790f3 100644 (file)
@@ -25,7 +25,6 @@
 #include "SkStream.h"
 #include "SkString.h"
 #include "SkTemplates.h"
-#include "SkTypes.h"
 #include <memory>
 
 #if defined(SK_CAN_USE_DLOPEN)
index 274c925..ce48954 100644 (file)
@@ -20,6 +20,7 @@
 #endif
 
 #include "SkAdvancedTypefaceMetrics.h"
+#include "SkAutoMalloc.h"
 #include "SkCGUtils.h"
 #include "SkColorPriv.h"
 #include "SkDescriptor.h"
index 52f4599..6bc8b54 100644 (file)
 #undef INT64_MAX
 #undef UINT64_MAX
 
-#include <wincodec.h>
 #include "SkAutoCoInitialize.h"
+#include "SkAutoMalloc.h"
 #include "SkBitmap.h"
 #include "SkImageEncoderPriv.h"
 #include "SkIStream.h"
+#include "SkImageEncoder.h"
 #include "SkStream.h"
 #include "SkTScopedComPtr.h"
 #include "SkUnPreMultiply.h"
+#include <wincodec.h>
 
 //All Windows SDKs back to XPSP2 export the CLSID_WICImagingFactory symbol.
 //In the Windows8 SDK the CLSID_WICImagingFactory symbol is still exported
index 01e9cc4..0f6d54c 100644 (file)
@@ -8,18 +8,19 @@
 #include "FakeStreams.h"
 #include "Resources.h"
 #include "SkAndroidCodec.h"
+#include "SkAutoMalloc.h"
 #include "SkBitmap.h"
 #include "SkCodec.h"
 #include "SkCodecImageGenerator.h"
 #include "SkColorSpace_XYZ.h"
 #include "SkData.h"
-#include "SkImageEncoder.h"
 #include "SkFrontBufferedStream.h"
+#include "SkImageEncoder.h"
 #include "SkMD5.h"
+#include "SkPngChunkReader.h"
 #include "SkRandom.h"
 #include "SkStream.h"
 #include "SkStreamPriv.h"
-#include "SkPngChunkReader.h"
 #include "Test.h"
 
 #include "png.h"
index ad2dd0f..b6456a6 100644 (file)
@@ -5,10 +5,12 @@
  * found in the LICENSE file.
  */
 
+#include "SkAutoMalloc.h"
 #include "SkColor.h"
 #include "SkColorFilter.h"
 #include "SkColorPriv.h"
 #include "SkLumaColorFilter.h"
+#include "SkRandom.h"
 #include "SkReadBuffer.h"
 #include "SkWriteBuffer.h"
 #include "SkRandom.h"
index 55c5244..3d54c57 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "Resources.h"
+#include "SkAutoMalloc.h"
 #include "SkEndian.h"
 #include "SkFontStream.h"
 #include "SkOSFile.h"
index a386274..69ff488 100644 (file)
@@ -5,12 +5,12 @@
  * found in the LICENSE file.
  */
 
+#include "SkAutoMalloc.h"
 #include "SkBitmap.h"
 #include "SkCodec.h"
 #include "SkFrontBufferedStream.h"
 #include "SkRefCnt.h"
 #include "SkStream.h"
-#include "SkTypes.h"
 #include "Test.h"
 
 static void test_read(skiatest::Reporter* reporter, SkStream* bufferedStream,
index 09e1b93..7e2bece 100644 (file)
@@ -5,6 +5,7 @@
  * found in the LICENSE file.
  */
 
+#include "SkAutoMalloc.h"
 #include "SkData.h"
 #include "SkMallocPixelRef.h"
 #include "Test.h"
index 474bbf6..b716c60 100644 (file)
@@ -5,6 +5,7 @@
  * found in the LICENSE file.
  */
 
+#include "SkAutoMalloc.h"
 #include "SkPaint.h"
 #include "Test.h"
 
index 76bfb02..55a82a7 100644 (file)
@@ -5,6 +5,7 @@
  * found in the LICENSE file.
  */
 
+#include "SkAutoMalloc.h"
 #include "SkBlurMask.h"
 #include "SkBlurMaskFilter.h"
 #include "SkLayerDrawLooper.h"
index 2059c36..0ace812 100644 (file)
@@ -5,14 +5,14 @@
  * found in the LICENSE file.
  */
 
-#include <cmath>
+#include "SkAutoMalloc.h"
 #include "SkCanvas.h"
 #include "SkGeometry.h"
 #include "SkPaint.h"
 #include "SkParse.h"
 #include "SkParsePath.h"
-#include "SkPathPriv.h"
 #include "SkPathEffect.h"
+#include "SkPathPriv.h"
 #include "SkRRect.h"
 #include "SkRandom.h"
 #include "SkReader32.h"
@@ -20,9 +20,9 @@
 #include "SkStream.h"
 #include "SkStrokeRec.h"
 #include "SkSurface.h"
-#include "SkTypes.h"
 #include "SkWriter32.h"
 #include "Test.h"
+#include <cmath>
 
 static void set_radii(SkVector radii[4], int index, float rad) {
     sk_bzero(radii, sizeof(SkVector) * 4);
index 4a96056..1720822 100644 (file)
@@ -5,6 +5,7 @@
  * found in the LICENSE file.
  */
 
+#include "SkAutoMalloc.h"
 #include "SkPath.h"
 #include "SkRandom.h"
 #include "SkRegion.h"
index ff23ca2..fba09c9 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "Resources.h"
+#include "SkAutoMalloc.h"
 #include "SkData.h"
 #include "SkFrontBufferedStream.h"
 #include "SkOSFile.h"
index 3eab94c..6cb79f8 100644 (file)
@@ -5,6 +5,7 @@
  * found in the LICENSE file.
  */
 
+#include "SkAutoMalloc.h"
 #include "SkRandom.h"
 #include "SkReader32.h"
 #include "SkWriter32.h"
index 913997b..0c31c09 100644 (file)
@@ -5,8 +5,9 @@
  * found in the LICENSE file.
  */
 
-#include "SkCodec.h"
 #include "Resources.h"
+#include "SkAutoMalloc.h"
+#include "SkCodec.h"
 #include "SkStream.h"
 #include "SkTemplates.h"
 #include "SkYUVSizeInfo.h"
index ba3ba1f..a65c6f2 100644 (file)
@@ -6,9 +6,11 @@
  */
 
 #include "ktx.h"
+
+#include "SkAutoMalloc.h"
 #include "SkBitmap.h"
-#include "SkStream.h"
 #include "SkEndian.h"
+#include "SkStream.h"
 
 #include "gl/GrGLDefines.h"
 #include "GrConfig.h"
index 2c4d211..9c7d69e 100644 (file)
@@ -28,10 +28,9 @@ std::unique_ptr<hb_blob_t, HBFBlobDel> stream_to_blob(std::unique_ptr<SkStreamAs
                                   [](void* p) { delete (SkStreamAsset*)p; }));
     } else {
         // SkDebugf("Extra SkStreamAsset copy\n");
-        SkAutoMalloc autoMalloc(size);
-        asset->read(autoMalloc.get(), size);
-        void* ptr = autoMalloc.get();
-        blob.reset(hb_blob_create((char*)autoMalloc.release(), SkToUInt(size),
+        void* ptr = size ? sk_malloc_throw(size) : nullptr;
+        asset->read(ptr, size);
+        blob.reset(hb_blob_create((char*)ptr, SkToUInt(size),
                                   HB_MEMORY_MODE_READONLY, ptr, sk_free));
     }
     SkASSERT(blob);
index 4eaf2ea..6dea988 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "png.h"
 
+#include "SkAutoMalloc.h"
 #include "SkBlurMaskFilter.h"
 #include "SkColorFilter.h"
 #include "SkDashPathEffect.h"
@@ -704,7 +705,7 @@ void SkDrawCommand::WritePNG(const uint8_t* rgba, unsigned width, unsigned heigh
 bool SkDrawCommand::flatten(const SkImage& image, Json::Value* target,
                             UrlDataManager& urlDataManager) {
     size_t rowBytes = 4 * image.width();
-    SkAutoFree buffer(sk_malloc_throw(rowBytes * image.height()));
+    SkAutoMalloc buffer(rowBytes * image.height());
     SkImageInfo dstInfo = SkImageInfo::Make(image.width(), image.height(),
                                             kN32_SkColorType, kPremul_SkAlphaType);
     if (!image.readPixels(dstInfo, buffer.get(), rowBytes, 0, 0)) {
index c8335d2..4802e21 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "GrContext.h"
 #include "GrRenderTarget.h"
+#include "SkAutoMalloc.h"
 #include "SkSurface.h"
 #include "VulkanWindowContext.h"
 
index ca738db..96fe8f2 100644 (file)
@@ -5,9 +5,10 @@
  * found in the LICENSE file.
  */
 
-#include "WindowContextFactory_win.h"
 #include "../RasterWindowContext.h"
+#include "SkAutoMalloc.h"
 #include "SkSurface.h"
+#include "WindowContextFactory_win.h"
 
 #include <Windows.h>