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

Side by Side Diff: third_party/WebKit/Source/core/frame/ImageBitmap.cpp

Issue 2696703008: Adds RefPtr::leakRef method to allow raw pointers that prevent destruct. (Closed)
Patch Set: Added deref in RefPtrTest.LeakRef to avoid memory leak. Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/frame/ImageBitmap.h" 5 #include "core/frame/ImageBitmap.h"
6 6
7 #include "core/html/Float32ImageData.h" 7 #include "core/html/Float32ImageData.h"
8 #include "core/html/HTMLCanvasElement.h" 8 #include "core/html/HTMLCanvasElement.h"
9 #include "core/html/HTMLVideoElement.h" 9 #include "core/html/HTMLVideoElement.h"
10 #include "core/html/ImageData.h" 10 #include "core/html/ImageData.h"
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 RefPtr<Uint8Array> resizedPixels = 758 RefPtr<Uint8Array> resizedPixels =
759 Uint8Array::create(dstBuffer, 0, dstBuffer->byteLength()); 759 Uint8Array::create(dstBuffer, 0, dstBuffer->byteLength());
760 SkPixmap pixmap( 760 SkPixmap pixmap(
761 resizedInfo, resizedPixels->data(), 761 resizedInfo, resizedPixels->data(),
762 static_cast<unsigned>(resizeWidth) * resizedInfo.bytesPerPixel()); 762 static_cast<unsigned>(resizeWidth) * resizedInfo.bytesPerPixel());
763 skImage->scalePixels(pixmap, resizeQuality); 763 skImage->scalePixels(pixmap, resizeQuality);
764 return SkImage::MakeFromRaster(pixmap, 764 return SkImage::MakeFromRaster(pixmap,
765 [](const void*, void* pixels) { 765 [](const void*, void* pixels) {
766 static_cast<Uint8Array*>(pixels)->deref(); 766 static_cast<Uint8Array*>(pixels)->deref();
767 }, 767 },
768 resizedPixels.release().leakRef()); 768 resizedPixels.leakRef());
769 } 769 }
770 770
771 RefPtr<Float32Array> resizedPixels = 771 RefPtr<Float32Array> resizedPixels =
772 Float32Array::create(dstBuffer, 0, dstBuffer->byteLength()); 772 Float32Array::create(dstBuffer, 0, dstBuffer->byteLength());
773 SkPixmap pixmap( 773 SkPixmap pixmap(
774 resizedInfo, resizedPixels->data(), 774 resizedInfo, resizedPixels->data(),
775 static_cast<unsigned>(resizeWidth) * resizedInfo.bytesPerPixel()); 775 static_cast<unsigned>(resizeWidth) * resizedInfo.bytesPerPixel());
776 skImage->scalePixels(pixmap, resizeQuality); 776 skImage->scalePixels(pixmap, resizeQuality);
777 return SkImage::MakeFromRaster(pixmap, 777 return SkImage::MakeFromRaster(pixmap,
778 [](const void*, void* pixels) { 778 [](const void*, void* pixels) {
779 static_cast<Float32Array*>(pixels)->deref(); 779 static_cast<Float32Array*>(pixels)->deref();
780 }, 780 },
781 resizedPixels.release().leakRef()); 781 resizedPixels.leakRef());
782 } 782 }
783 783
784 ImageBitmap::ImageBitmap(ImageData* data, 784 ImageBitmap::ImageBitmap(ImageData* data,
785 Optional<IntRect> cropRect, 785 Optional<IntRect> cropRect,
786 const ImageBitmapOptions& options) { 786 const ImageBitmapOptions& options) {
787 // TODO(xidachen): implement the resize option 787 // TODO(xidachen): implement the resize option
788 IntRect dataSrcRect = IntRect(IntPoint(), data->size()); 788 IntRect dataSrcRect = IntRect(IntPoint(), data->size());
789 ParsedOptions parsedOptions = 789 ParsedOptions parsedOptions =
790 parseOptions(options, cropRect, data->bitmapSourceSize()); 790 parseOptions(options, cropRect, data->bitmapSourceSize());
791 if (dstBufferSizeHasOverflow(parsedOptions)) 791 if (dstBufferSizeHasOverflow(parsedOptions))
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, 1152 void ImageBitmap::adjustDrawRects(FloatRect* srcRect,
1153 FloatRect* dstRect) const {} 1153 FloatRect* dstRect) const {}
1154 1154
1155 FloatSize ImageBitmap::elementSize(const FloatSize&) const { 1155 FloatSize ImageBitmap::elementSize(const FloatSize&) const {
1156 return FloatSize(width(), height()); 1156 return FloatSize(width(), height());
1157 } 1157 }
1158 1158
1159 DEFINE_TRACE(ImageBitmap) {} 1159 DEFINE_TRACE(ImageBitmap) {}
1160 1160
1161 } // namespace blink 1161 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/PassRefPtr.h » ('j') | third_party/WebKit/Source/wtf/RefPtrTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698