diff options
author | scroggo <scroggo@google.com> | 2015-12-10 10:44:13 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-10 10:44:13 -0800 |
commit | 565901db954c231840750ea955ed31b820b9ade8 (patch) | |
tree | 376c6355e252cd946babb6a267adba2e016efab4 | |
parent | 9907371f0a79776d90b68d534aeb44eb46acafe5 (diff) |
Switch SkAutoMalloc to SkAutoTMalloc to avoid cast
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
-rw-r--r-- | bench/ColorCubeBench.cpp | 5 | ||||
-rw-r--r-- | gm/colorcube.cpp | 9 | ||||
-rw-r--r-- | gm/etc1bitmap.cpp | 5 | ||||
-rw-r--r-- | include/effects/SkColorCubeFilter.h | 3 | ||||
-rw-r--r-- | include/private/SkTemplates.h | 10 | ||||
-rw-r--r-- | samplecode/SampleApp.cpp | 5 | ||||
-rw-r--r-- | samplecode/SampleFilterFuzz.cpp | 8 | ||||
-rw-r--r-- | src/codec/SkCodec_libpng.cpp | 15 | ||||
-rw-r--r-- | src/codec/SkJpegCodec.cpp | 8 | ||||
-rw-r--r-- | src/codec/SkJpegCodec.h | 3 | ||||
-rw-r--r-- | src/codec/SkSampledCodec.cpp | 5 | ||||
-rw-r--r-- | src/codec/SkWebpCodec.cpp | 4 | ||||
-rw-r--r-- | src/core/SkBitmap.cpp | 5 | ||||
-rw-r--r-- | src/core/SkDraw.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkColorCubeFilter.cpp | 2 | ||||
-rw-r--r-- | src/images/SkImageDecoder_libgif.cpp | 4 | ||||
-rw-r--r-- | src/images/SkImageDecoder_libjpeg.cpp | 8 | ||||
-rw-r--r-- | src/images/SkImageDecoder_libpng.cpp | 12 | ||||
-rw-r--r-- | src/images/SkImageDecoder_libwebp.cpp | 4 | ||||
-rw-r--r-- | src/svg/parser/SkSVG.cpp | 7 | ||||
-rw-r--r-- | tests/ARGBImageEncoderTest.cpp | 5 | ||||
-rw-r--r-- | tests/BitmapCopyTest.cpp | 5 | ||||
-rw-r--r-- | tests/CanvasTest.cpp | 5 | ||||
-rw-r--r-- | tests/TextureCompressionTest.cpp | 5 | ||||
-rw-r--r-- | tests/Writer32Test.cpp | 11 |
25 files changed, 88 insertions, 69 deletions
diff --git a/bench/ColorCubeBench.cpp b/bench/ColorCubeBench.cpp index 55d1726166..6c5a16d6a2 100644 --- a/bench/ColorCubeBench.cpp +++ b/bench/ColorCubeBench.cpp @@ -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 diff --git a/gm/colorcube.cpp b/gm/colorcube.cpp index 519f88a6a5..fa9eea9f99 100644 --- a/gm/colorcube.cpp +++ b/gm/colorcube.cpp @@ -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; diff --git a/gm/etc1bitmap.cpp b/gm/etc1bitmap.cpp index bbe75610ef..d9b08d1e86 100644 --- a/gm/etc1bitmap.cpp +++ b/gm/etc1bitmap.cpp @@ -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; diff --git a/include/effects/SkColorCubeFilter.h b/include/effects/SkColorCubeFilter.h index f4a0c9009d..a8a5e329de 100644 --- a/include/effects/SkColorCubeFilter.h +++ b/include/effects/SkColorCubeFilter.h @@ -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; diff --git a/include/private/SkTemplates.h b/include/private/SkTemplates.h index 533cb264d1..c1fd4cbca6 100644 --- a/include/private/SkTemplates.h +++ b/include/private/SkTemplates.h @@ -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. diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index c71fda5f9d..f9865dcfc0 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -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; diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp index 9973d3762a..a0f7aff5ef 100644 --- a/samplecode/SampleFilterFuzz.cpp +++ b/samplecode/SampleFilterFuzz.cpp @@ -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; diff --git a/src/codec/SkCodec_libpng.cpp b/src/codec/SkCodec_libpng.cpp index 744bca41fa..3086a36599 100644 --- a/src/codec/SkCodec_libpng.cpp +++ b/src/codec/SkCodec_libpng.cpp @@ -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++) { diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp index 6ea13b7639..7db772da63 100644 --- a/src/codec/SkJpegCodec.cpp +++ b/src/codec/SkJpegCodec.cpp @@ -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; diff --git a/src/codec/SkJpegCodec.h b/src/codec/SkJpegCodec.h index ed94b613f9..8e2db81b73 100644 --- a/src/codec/SkJpegCodec.h +++ b/src/codec/SkJpegCodec.h @@ -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; diff --git a/src/codec/SkSampledCodec.cpp b/src/codec/SkSampledCodec.cpp index 52e5648742..38859ad6be 100644 --- a/src/codec/SkSampledCodec.cpp +++ b/src/codec/SkSampledCodec.cpp @@ -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, diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp index 2137877f1e..6cfb385294 100644 --- a/src/codec/SkWebpCodec.cpp +++ b/src/codec/SkWebpCodec.cpp @@ -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) { diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index e8a235597d..8997f2b014 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -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; diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index addd6ec555..7ebad61dde 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -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 diff --git a/src/effects/SkColorCubeFilter.cpp b/src/effects/SkColorCubeFilter.cpp index 07b229ceae..7f1f59622e 100644 --- a/src/effects/SkColorCubeFilter.cpp +++ b/src/effects/SkColorCubeFilter.cpp @@ -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))); diff --git a/src/images/SkImageDecoder_libgif.cpp b/src/images/SkImageDecoder_libgif.cpp index ef55a8f2e0..2677b13073 100644 --- a/src/images/SkImageDecoder_libgif.cpp +++ b/src/images/SkImageDecoder_libgif.cpp @@ -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 diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp index 219dad6db2..0d02a658f2 100644 --- a/src/images/SkImageDecoder_libjpeg.cpp +++ b/src/images/SkImageDecoder_libjpeg.cpp @@ -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(); diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp index 6acbf29d8c..cd8152a36b 100644 --- a/src/images/SkImageDecoder_libpng.cpp +++ b/src/images/SkImageDecoder_libpng.cpp @@ -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++) { diff --git a/src/images/SkImageDecoder_libwebp.cpp b/src/images/SkImageDecoder_libwebp.cpp index 07ff83de9b..52535779fa 100644 --- a/src/images/SkImageDecoder_libwebp.cpp +++ b/src/images/SkImageDecoder_libwebp.cpp @@ -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); diff --git a/src/svg/parser/SkSVG.cpp b/src/svg/parser/SkSVG.cpp index fdfc13a6d5..8ee7d0286a 100644 --- a/src/svg/parser/SkSVG.cpp +++ b/src/svg/parser/SkSVG.cpp @@ -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); diff --git a/tests/ARGBImageEncoderTest.cpp b/tests/ARGBImageEncoderTest.cpp index 4d16f4cc6d..62167f0f2a 100644 --- a/tests/ARGBImageEncoderTest.cpp +++ b/tests/ARGBImageEncoderTest.cpp @@ -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)); diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp index 65427ffd7b..6db63fae45 100644 --- a/tests/BitmapCopyTest.cpp +++ b/tests/BitmapCopyTest.cpp @@ -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; diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp index 2ec25e4bab..87705dc7f5 100644 --- a/tests/CanvasTest.cpp +++ b/tests/CanvasTest.cpp @@ -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); diff --git a/tests/TextureCompressionTest.cpp b/tests/TextureCompressionTest.cpp index d2e6db209b..18afebeff2 100644 --- a/tests/TextureCompressionTest.cpp +++ b/tests/TextureCompressionTest.cpp @@ -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; diff --git a/tests/Writer32Test.cpp b/tests/Writer32Test.cpp index 5849d731ef..39ae79cff6 100644 --- a/tests/Writer32Test.cpp +++ b/tests/Writer32Test.cpp @@ -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 |