Switch SkAutoMalloc to SkAutoTMalloc to avoid cast
authorscroggo <scroggo@google.com>
Thu, 10 Dec 2015 18:44:13 +0000 (10:44 -0800)
committerCommit bot <commit-bot@chromium.org>
Thu, 10 Dec 2015 18:44:13 +0000 (10:44 -0800)
Make SkAutoTMalloc's interface look more like SkAutoMalloc:
- add free(), which does what you expect
- make reset() return a pointer fPtr

No public API changes (SkAutoTMalloc is in include/private)

BUG=skia:2148

Review URL: https://codereview.chromium.org/1516833003

25 files changed:
bench/ColorCubeBench.cpp
gm/colorcube.cpp
gm/etc1bitmap.cpp
include/effects/SkColorCubeFilter.h
include/private/SkTemplates.h
samplecode/SampleApp.cpp
samplecode/SampleFilterFuzz.cpp
src/codec/SkCodec_libpng.cpp
src/codec/SkJpegCodec.cpp
src/codec/SkJpegCodec.h
src/codec/SkSampledCodec.cpp
src/codec/SkWebpCodec.cpp
src/core/SkBitmap.cpp
src/core/SkDraw.cpp
src/effects/SkColorCubeFilter.cpp
src/images/SkImageDecoder_libgif.cpp
src/images/SkImageDecoder_libjpeg.cpp
src/images/SkImageDecoder_libpng.cpp
src/images/SkImageDecoder_libwebp.cpp
src/svg/parser/SkSVG.cpp
tests/ARGBImageEncoderTest.cpp
tests/BitmapCopyTest.cpp
tests/CanvasTest.cpp
tests/TextureCompressionTest.cpp
tests/Writer32Test.cpp

index 55d1726..6c5a16d 100644 (file)
@@ -8,6 +8,7 @@
 #include "SkCanvas.h"
 #include "SkColorCubeFilter.h"
 #include "SkGradientShader.h"
+#include "SkTemplates.h"
 
 class ColorCubeBench : public Benchmark {
     SkISize fSize;
@@ -75,8 +76,8 @@ private:
         fCubeData = SkData::NewUninitialized(sizeof(SkColor) *
             fCubeDimension * fCubeDimension * fCubeDimension);
         SkColor* pixels = (SkColor*)(fCubeData->writable_data());
-        SkAutoMalloc lutMemory(fCubeDimension);
-        uint8_t* lut = (uint8_t*)lutMemory.get();
+        SkAutoTMalloc<uint8_t> lutMemory(fCubeDimension);
+        uint8_t* lut = lutMemory.get();
         const int maxIndex = fCubeDimension - 1;
         for (int i = 0; i < fCubeDimension; ++i) {
             // Make an invert lut, but the content of
index 519f88a..fa9eea9 100644 (file)
@@ -9,6 +9,7 @@
 #include "SkColorCubeFilter.h"
 #include "SkData.h"
 #include "SkGradientShader.h"
+#include "SkTemplates.h"
 
 namespace skiagm {
 
@@ -72,10 +73,10 @@ protected:
     void make_3Dlut(SkData** data, int size, bool invR, bool invG, bool invB) {
         *data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size);
         SkColor* pixels = (SkColor*)((*data)->writable_data());
-        SkAutoMalloc lutMemory(size);
-        SkAutoMalloc invLutMemory(size);
-        uint8_t* lut = (uint8_t*)lutMemory.get();
-        uint8_t* invLut = (uint8_t*)invLutMemory.get();
+        SkAutoTMalloc<uint8_t> lutMemory(size);
+        SkAutoTMalloc<uint8_t> invLutMemory(size);
+        uint8_t* lut = lutMemory.get();
+        uint8_t* invLut = invLutMemory.get();
         const int maxIndex = size - 1;
         for (int i = 0; i < size; i++) {
             lut[i] = (i * 255) / maxIndex;
index bbe7561..d9b08d1 100644 (file)
@@ -13,6 +13,7 @@
 #include "SkImageGenerator.h"
 #include "SkImageDecoder.h"
 #include "SkOSFile.h"
+#include "SkTemplates.h"
 
 #ifndef SK_IGNORE_ETC1_SUPPORT
 
@@ -46,9 +47,9 @@ bool slice_etc1_data(void *data, int* width, int* height) {
     int newHeight = (blockHeight - 1) << 2;
 
     size_t newDataSz = etc1_get_encoded_data_size(newWidth, newHeight) + ETC_PKM_HEADER_SIZE;
-    SkAutoMalloc am(newDataSz);
+    SkAutoTMalloc<etc1_byte> am(newDataSz);
 
-    etc1_byte *newData = reinterpret_cast<etc1_byte *>(am.get());
+    etc1_byte* newData = am.get();
 
     etc1_pkm_format_header(newData, newWidth, newHeight);
     newData += ETC_PKM_HEADER_SIZE;
index f4a0c90..a8a5e32 100644 (file)
@@ -11,6 +11,7 @@
 #include "SkColorFilter.h"
 #include "SkData.h"
 #include "../private/SkMutex.h"
+#include "../private/SkTemplates.h"
 
 class SK_API SkColorCubeFilter : public SkColorFilter {
 public:
@@ -55,7 +56,7 @@ private:
         SkScalar* fColorToFactors[2];
         SkScalar* fColorToScalar;
 
-        SkAutoMalloc fLutStorage;
+        SkAutoTMalloc<uint8_t> fLutStorage;
 
         const int fCubeDimension;
 
index 533cb26..c1fd4cb 100644 (file)
@@ -272,9 +272,10 @@ public:
     }
 
     /** Resize the memory area pointed to by the current ptr without preserving contents. */
-    void reset(size_t count) {
+    T* reset(size_t count) {
         sk_free(fPtr);
         fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW);
+        return fPtr;
     }
 
     T* get() const { return fPtr; }
@@ -296,6 +297,13 @@ public:
     }
 
     /**
+     *  Releases the block back to the heap
+     */
+    void free() {
+        this->reset(0);
+    }
+
+    /**
      *  Transfer ownership of the ptr to the caller, setting the internal
      *  pointer to NULL. Note that this differs from get(), which also returns
      *  the pointer, but it does not transfer ownership.
index c71fda5..f9865dc 100644 (file)
@@ -27,6 +27,7 @@
 #include "SkPictureRecorder.h"
 #include "SkStream.h"
 #include "SkSurface.h"
+#include "SkTemplates.h"
 #include "SkTSort.h"
 #include "SkTime.h"
 #include "SkTypeface.h"
@@ -792,8 +793,8 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
         SkFILEStream stream(FLAGS_sequence[0]);
         if (stream.isValid()) {
             size_t len = stream.getLength();
-            SkAutoMalloc storage(len + 1);
-            char* buffer = (char*)storage.get();
+            SkAutoTMalloc<char> storage(len + 1);
+            char* buffer = storage.get();
             stream.read(buffer, len);
             buffer[len] = 0;
 
index 9973d37..a0f7aff 100644 (file)
@@ -215,10 +215,10 @@ static SkData* make_3Dlut(int* cubeDimension, bool invR, bool invG, bool invB) {
     int size = 4 << R(5);
     SkData* data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size);
     SkColor* pixels = (SkColor*)(data->writable_data());
-    SkAutoMalloc lutMemory(size);
-    SkAutoMalloc invLutMemory(size);
-    uint8_t* lut = (uint8_t*)lutMemory.get();
-    uint8_t* invLut = (uint8_t*)invLutMemory.get();
+    SkAutoTMalloc<uint8_t> lutMemory(size);
+    SkAutoTMalloc<uint8_t> invLutMemory(size);
+    uint8_t* lut = lutMemory.get();
+    uint8_t* invLut = invLutMemory.get();
     const int maxIndex = size - 1;
     for (int i = 0; i < size; i++) {
         lut[i] = (i * 255) / maxIndex;
index 744bca4..3086a36 100644 (file)
@@ -14,6 +14,7 @@
 #include "SkSize.h"
 #include "SkStream.h"
 #include "SkSwizzler.h"
+#include "SkTemplates.h"
 
 ///////////////////////////////////////////////////////////////////////////////
 // Helper macros
@@ -503,7 +504,7 @@ SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void*
     // error?
     int row = 0;
     // This must be declared above the call to setjmp to avoid memory leaks on incomplete images.
-    SkAutoMalloc storage;
+    SkAutoTMalloc<uint8_t> storage;
     if (setjmp(png_jmpbuf(fPng_ptr))) {
         // Assume that any error that occurs while reading rows is caused by an incomplete input.
         if (fNumberPasses > 1) {
@@ -535,7 +536,7 @@ SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void*
         const size_t srcRowBytes = width * bpp;
 
         storage.reset(width * height * bpp);
-        uint8_t* const base = static_cast<uint8_t*>(storage.get());
+        uint8_t* const base = storage.get();
 
         for (int i = 0; i < fNumberPasses; i++) {
             uint8_t* srcRow = base;
@@ -555,7 +556,7 @@ SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void*
         }
     } else {
         storage.reset(requestedInfo.width() * SkSwizzler::BytesPerPixel(fSrcConfig));
-        uint8_t* srcRow = static_cast<uint8_t*>(storage.get());
+        uint8_t* srcRow = storage.get();
         for (; row < requestedInfo.height(); row++) {
             png_read_rows(fPng_ptr, &srcRow, png_bytepp_NULL, 1);
             // FIXME: Only call IsOpaque once, outside the loop. Same for onGetScanlines.
@@ -642,7 +643,7 @@ public:
 
         fAlphaState = kUnknown_AlphaState;
         fStorage.reset(this->getInfo().width() * SkSwizzler::BytesPerPixel(this->srcConfig()));
-        fSrcRow = static_cast<uint8_t*>(fStorage.get());
+        fSrcRow = fStorage.get();
 
         return kSuccess;
     }
@@ -696,7 +697,7 @@ public:
 
 private:
     AlphaState                  fAlphaState;
-    SkAutoMalloc                fStorage;
+    SkAutoTMalloc<uint8_t>      fStorage;
     uint8_t*                    fSrcRow;
 
     typedef SkPngCodec INHERITED;
@@ -769,8 +770,8 @@ public:
             // fail on the first pass, we can still report than some scanlines are initialized.
             return 0;
         }
-        SkAutoMalloc storage(count * fSrcRowBytes);
-        uint8_t* storagePtr = static_cast<uint8_t*>(storage.get());
+        SkAutoTMalloc<uint8_t> storage(count * fSrcRowBytes);
+        uint8_t* storagePtr = storage.get();
         uint8_t* srcRow;
         const int startRow = this->nextScanline();
         for (int i = 0; i < this->numberPasses(); i++) {
index 6ea13b7..7db772d 100644 (file)
@@ -350,12 +350,12 @@ void SkJpegCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options&
 
     fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, options));
     fStorage.reset(get_row_bytes(fDecoderMgr->dinfo()));
-    fSrcRow = static_cast<uint8_t*>(fStorage.get());
+    fSrcRow = fStorage.get();
 }
 
 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) {
     if (!createIfNecessary || fSwizzler) {
-        SkASSERT(!fSwizzler || (fSrcRow && static_cast<uint8_t*>(fStorage.get()) == fSrcRow));
+        SkASSERT(!fSwizzler || (fSrcRow && fStorage.get() == fSrcRow));
         return fSwizzler;
     }
 
@@ -433,8 +433,8 @@ int SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowBytes) {
 #ifndef TURBO_HAS_SKIP
 // TODO (msarett): Avoid reallocating the memory buffer on each call to skip.
 static uint32_t jpeg_skip_scanlines(jpeg_decompress_struct* dinfo, int count) {
-    SkAutoMalloc storage(get_row_bytes(dinfo));
-    uint8_t* storagePtr = static_cast<uint8_t*>(storage.get());
+    SkAutoTMalloc<uint8_t> storage(get_row_bytes(dinfo));
+    uint8_t* storagePtr = storage.get();
     for (int y = 0; y < count; y++) {
         if (1 != jpeg_read_scanlines(dinfo, &storagePtr, 1)) {
             return y;
index ed94b61..8e2db81 100644 (file)
@@ -13,6 +13,7 @@
 #include "SkJpegDecoderMgr.h"
 #include "SkJpegUtility_codec.h"
 #include "SkStream.h"
+#include "SkTemplates.h"
 
 extern "C" {
     #include "jpeglib.h"
@@ -111,7 +112,7 @@ private:
     const int                     fReadyState;
 
     // scanline decoding
-    SkAutoMalloc               fStorage;    // Only used if sampling is needed
+    SkAutoTMalloc<uint8_t>     fStorage;    // Only used if sampling is needed
     uint8_t*                   fSrcRow;     // Only used if sampling is needed
     SkAutoTDelete<SkSwizzler>  fSwizzler;
     
index 52e5648..38859ad 100644 (file)
@@ -9,6 +9,7 @@
 #include "SkCodecPriv.h"
 #include "SkMath.h"
 #include "SkSampledCodec.h"
+#include "SkTemplates.h"
 
 SkSampledCodec::SkSampledCodec(SkCodec* codec)
     : INHERITED(codec->getInfo())
@@ -267,8 +268,8 @@ SkCodec::Result SkSampledCodec::sampledDecode(const SkImageInfo& info, void* pix
         }
         case SkCodec::kNone_SkScanlineOrder: {
             const int linesNeeded = subsetHeight - samplingOffsetY;
-            SkAutoMalloc storage(linesNeeded * rowBytes);
-            uint8_t* storagePtr = static_cast<uint8_t*>(storage.get());
+            SkAutoTMalloc<uint8_t> storage(linesNeeded * rowBytes);
+            uint8_t* storagePtr = storage.get();
 
             if (!fCodec->skipScanlines(startY)) {
                 fCodec->fillIncompleteImage(info, pixels, rowBytes, options.fZeroInitialized,
index 2137877..6cfb385 100644 (file)
@@ -230,8 +230,8 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
         return kInvalidInput;
     }
 
-    SkAutoMalloc storage(BUFFER_SIZE);
-    uint8_t* buffer = static_cast<uint8_t*>(storage.get());
+    SkAutoTMalloc<uint8_t> storage(BUFFER_SIZE);
+    uint8_t* buffer = storage.get();
     while (true) {
         const size_t bytesRead = stream()->read(buffer, BUFFER_SIZE);
         if (0 == bytesRead) {
index e8a2355..8997f2b 100644 (file)
@@ -17,6 +17,7 @@
 #include "SkReadBuffer.h"
 #include "SkRect.h"
 #include "SkScalar.h"
+#include "SkTemplates.h"
 #include "SkUnPreMultiply.h"
 #include "SkWriteBuffer.h"
 
@@ -1082,8 +1083,8 @@ static void write_raw_pixels(SkWriteBuffer* buffer, const SkPixmap& pmap) {
     info.flatten(*buffer);
 
     const size_t size = snugRB * info.height();
-    SkAutoMalloc storage(size);
-    char* dst = (char*)storage.get();
+    SkAutoTMalloc<char> storage(size);
+    char* dst = storage.get();
     for (int y = 0; y < info.height(); ++y) {
         memcpy(dst, src, snugRB);
         dst += snugRB;
index addd6ec..7ebad61 100644 (file)
@@ -1234,8 +1234,8 @@ void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap,
         }
 
         // allocate (and clear) our temp buffer to hold the transformed bitmap
-        SkAutoMalloc    storage(size);
-        mask.fImage = (uint8_t*)storage.get();
+        SkAutoTMalloc<uint8_t> storage(size);
+        mask.fImage = storage.get();
         memset(mask.fImage, 0, size);
 
         // now draw our bitmap(src) into mask(dst), transformed by the matrix
index 07b229c..7f1f596 100644 (file)
@@ -99,7 +99,7 @@ void SkColorCubeFilter::ColorCubeProcesingCache::initProcessingLuts(
     // We need 256 SkScalar * 2 for fColorToFactors and 256 SkScalar
     // for fColorToScalar, so a total of 768 SkScalar.
     cache->fLutStorage.reset(512 * sizeof(int) + 768 * sizeof(SkScalar));
-    uint8_t* storage = (uint8_t*)cache->fLutStorage.get();
+    uint8_t* storage = cache->fLutStorage.get();
     cache->fColorToIndex[0] = (int*)storage;
     cache->fColorToIndex[1] = cache->fColorToIndex[0] + 256;
     cache->fColorToFactors[0] = (SkScalar*)(storage + (512 * sizeof(int)));
index ef55a8f..2677b13 100644 (file)
@@ -378,8 +378,8 @@ SkImageDecoder::Result SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap
 
             SkAutoLockPixels alp(*bm);
 
-            SkAutoMalloc storage(innerWidth);
-            uint8_t* scanline = (uint8_t*) storage.get();
+            SkAutoTMalloc<uint8_t> storage(innerWidth);
+            uint8_t* scanline = storage.get();
 
             // GIF has an option to store the scanlines of an image, plus a larger background,
             // filled by a fill color. In this case, we will use a subset of the larger bitmap
index 219dad6..0d02a65 100644 (file)
@@ -496,8 +496,8 @@ SkImageDecoder::Result SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap*
         return return_failure(cinfo, *bm, "sampler.begin");
     }
 
-    SkAutoMalloc srcStorage(cinfo.output_width * srcBytesPerPixel);
-    uint8_t* srcRow = (uint8_t*)srcStorage.get();
+    SkAutoTMalloc<uint8_t> srcStorage(cinfo.output_width * srcBytesPerPixel);
+    uint8_t* srcRow = srcStorage.get();
 
     //  Possibly skip initial rows [sampler.srcY0]
     if (!skip_src_rows(&cinfo, srcRow, sampler.srcY0())) {
@@ -931,7 +931,7 @@ protected:
         skjpeg_destination_mgr  sk_wstream(stream);
 
         // allocate these before set call setjmp
-        SkAutoMalloc    oneRow;
+        SkAutoTMalloc<uint8_t>  oneRow;
 
         cinfo.err = jpeg_std_error(&sk_err);
         sk_err.error_exit = skjpeg_error_exit;
@@ -966,7 +966,7 @@ protected:
         jpeg_start_compress(&cinfo, TRUE);
 
         const int       width = bm.width();
-        uint8_t*        oneRowP = (uint8_t*)oneRow.reset(width * 3);
+        uint8_t*        oneRowP = oneRow.reset(width * 3);
 
         const SkPMColor* colors = bm.getColorTable() ? bm.getColorTable()->readColors() : nullptr;
         const void*      srcRow = bm.getPixels();
index 6acbf29..cd8152a 100644 (file)
@@ -401,8 +401,8 @@ SkImageDecoder::Result SkPNGImageDecoder::onDecode(SkStream* sk_stream, SkBitmap
         const int height = decodedBitmap->height();
 
         if (number_passes > 1) {
-            SkAutoMalloc storage(origWidth * origHeight * srcBytesPerPixel);
-            uint8_t* base = (uint8_t*)storage.get();
+            SkAutoTMalloc<uint8_t> storage(origWidth * origHeight * srcBytesPerPixel);
+            uint8_t* base = storage.get();
             size_t rowBytes = origWidth * srcBytesPerPixel;
 
             for (int i = 0; i < number_passes; i++) {
@@ -420,8 +420,8 @@ SkImageDecoder::Result SkPNGImageDecoder::onDecode(SkStream* sk_stream, SkBitmap
                 base += sampler.srcDY() * rowBytes;
             }
         } else {
-            SkAutoMalloc storage(origWidth * srcBytesPerPixel);
-            uint8_t* srcRow = (uint8_t*)storage.get();
+            SkAutoTMalloc<uint8_t> storage(origWidth * srcBytesPerPixel);
+            uint8_t* srcRow = storage.get();
             skip_src_rows(png_ptr, srcRow, sampler.srcY0());
 
             for (int y = 0; y < height; y++) {
@@ -966,8 +966,8 @@ bool SkPNGImageEncoder::doEncode(SkWStream* stream, const SkBitmap& bitmap,
     png_write_info(png_ptr, info_ptr);
 
     const char* srcImage = (const char*)bitmap.getPixels();
-    SkAutoSMalloc<1024> rowStorage(bitmap.width() << 2);
-    char* storage = (char*)rowStorage.get();
+    SkAutoSTMalloc<1024, char> rowStorage(bitmap.width() << 2);
+    char* storage = rowStorage.get();
     transform_scanline_proc proc = choose_proc(ct, hasAlpha);
 
     for (int y = 0; y < bitmap.height(); y++) {
index 07ff83d..5253577 100644 (file)
@@ -201,8 +201,8 @@ static bool webp_idecode(SkStream* stream, WebPDecoderConfig* config) {
     }
     const size_t readBufferSize = stream->hasLength() ?
             SkTMin(stream->getLength(), WEBP_IDECODE_BUFFER_SZ) : WEBP_IDECODE_BUFFER_SZ;
-    SkAutoMalloc srcStorage(readBufferSize);
-    unsigned char* input = (uint8_t*)srcStorage.get();
+    SkAutoTMalloc<unsigned char> srcStorage(readBufferSize);
+    unsigned char* input = srcStorage.get();
     if (nullptr == input) {
         WebPIDelete(idec);
         WebPFreeDecBuffer(&config->output);
index fdfc13a..8ee7d02 100644 (file)
@@ -8,7 +8,8 @@
 
 
 #include "SkSVG.h"
-#include 'SkSVGParser.h"
+#include "SkSVGParser.h"
+#include "SkTemplates.h"
 
 SkSVG::SkSVG() {
 }
@@ -19,8 +20,8 @@ SkSVG::~SkSVG() {
 bool SkSVG::decodeStream(SkStream* stream);
 {
     size_t size = stream->read(nil, 0);
-    SkAutoMalloc    storage(size);
-    char* data = (char*)storage.get();
+    SkAutoTMalloc<char> storage(size);
+    char* data = storage.get();
     size_t actual = stream->read(data, size);
     SkASSERT(size == actual);
     SkSVGParser parser(*fMaker);
index 4d16f4c..62167f0 100644 (file)
@@ -10,6 +10,7 @@
 #include "SkBitmap.h"
 #include "SkCanvas.h"
 #include "SkStream.h"
+#include "SkTemplates.h"
 #include "Test.h"
 
 static SkColorType gColorTypes[] = {
@@ -49,8 +50,8 @@ DEF_TEST(ARGBImageEncoder, reporter) {
 
         // Transform the bitmap.
         int bufferSize = bitmap.width() * bitmap.height() * 4;
-        SkAutoMalloc pixelBufferManager(bufferSize);
-        char *pixelBuffer = static_cast<char *>(pixelBufferManager.get());
+        SkAutoTMalloc<char> pixelBufferManager(bufferSize);
+        char* pixelBuffer = pixelBufferManager.get();
         SkMemoryWStream out(pixelBuffer, bufferSize);
         REPORTER_ASSERT(reporter, enc->encodeStream(&out, bitmap, SkImageEncoder::kDefaultQuality));
 
index 65427ff..6db63fa 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "SkBitmap.h"
 #include "SkRect.h"
+#include "SkTemplates.h"
 #include "Test.h"
 
 static const char* boolStr(bool value) {
@@ -420,8 +421,8 @@ DEF_TEST(BitmapCopy, reporter) {
                 // raw buffer pointer.
                 const size_t bufSize = subH *
                     SkColorTypeMinRowBytes(src.colorType(), subW) * 2;
-                SkAutoMalloc autoBuf (bufSize);
-                uint8_t* buf = static_cast<uint8_t*>(autoBuf.get());
+                SkAutoTMalloc<uint8_t> autoBuf (bufSize);
+                uint8_t* buf = autoBuf.get();
 
                 SkBitmap bufBm; // Attach buf to this bitmap.
                 bool successExpected;
index 2ec25e4..87705dc 100644 (file)
@@ -61,6 +61,7 @@
 #include "SkShader.h"
 #include "SkStream.h"
 #include "SkSurface.h"
+#include "SkTemplates.h"
 #include "SkTDArray.h"
 #include "Test.h"
 
@@ -635,8 +636,8 @@ static void test_newraster(skiatest::Reporter* reporter) {
     SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
     const size_t minRowBytes = info.minRowBytes();
     const size_t size = info.getSafeSize(minRowBytes);
-    SkAutoMalloc storage(size);
-    SkPMColor* baseAddr = static_cast<SkPMColor*>(storage.get());
+    SkAutoTMalloc<SkPMColor> storage(size);
+    SkPMColor* baseAddr = storage.get();
     sk_bzero(baseAddr, size);
 
     SkCanvas* canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes);
index d2e6db2..18afebe 100644 (file)
@@ -9,6 +9,7 @@
 #include "SkData.h"
 #include "SkEndian.h"
 #include "SkImageInfo.h"
+#include "SkTemplates.h"
 #include "SkTextureCompressor.h"
 #include "Test.h"
 
@@ -136,8 +137,8 @@ DEF_TEST(CompressCheckerboard, reporter) {
         }
     }
 
-    SkAutoMalloc decompMemory(kWidth*kHeight);
-    uint8_t* decompBuffer = reinterpret_cast<uint8_t*>(decompMemory.get());
+    SkAutoTMalloc<uint8_t> decompMemory(kWidth*kHeight);
+    uint8_t* decompBuffer = decompMemory.get();
     REPORTER_ASSERT(reporter, decompBuffer);
     if (nullptr == decompBuffer) {
         return;
index 5849d73..39ae79c 100644 (file)
@@ -144,16 +144,13 @@ static void test2(skiatest::Reporter* reporter, SkWriter32* writer) {
 
 static void testWritePad(skiatest::Reporter* reporter, SkWriter32* writer) {
     // Create some random data to write.
-    const size_t dataSize = 10<<2;
-    SkASSERT(SkIsAlign4(dataSize));
+    const size_t dataSize = 10;
 
-    SkAutoMalloc originalData(dataSize);
+    SkAutoTMalloc<uint32_t> originalData(dataSize);
     {
         SkRandom rand(0);
-        uint32_t* ptr = static_cast<uint32_t*>(originalData.get());
-        uint32_t* stop = ptr + (dataSize>>2);
-        while (ptr < stop) {
-            *ptr++ = rand.nextU();
+        for (size_t i = 0; i < dataSize; i++) {
+            originalData[(int) i] = rand.nextU();
         }
 
         // Write  the random data to the writer at different lengths for