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

Unified Diff: src/image/SkImageShader.cpp

Issue 2239723002: fix memory leak, remake Imageshader to use sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/image/SkImageShader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkImageShader.cpp
diff --git a/src/image/SkImageShader.cpp b/src/image/SkImageShader.cpp
index eb577e175894ea6ab52efc7b8662f5d3013b80c9..db2bacb4ef4d96e9c2db5e02184c5463d1086d7a 100644
--- a/src/image/SkImageShader.cpp
+++ b/src/image/SkImageShader.cpp
@@ -15,9 +15,9 @@
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
-SkImageShader::SkImageShader(const SkImage* img, TileMode tmx, TileMode tmy, const SkMatrix* matrix)
+SkImageShader::SkImageShader(sk_sp<SkImage> img, TileMode tmx, TileMode tmy, const SkMatrix* matrix)
: INHERITED(matrix)
- , fImage(SkRef(img))
+ , fImage(std::move(img))
, fTileModeX(tmx)
, fTileModeY(tmy)
{}
@@ -31,14 +31,14 @@ sk_sp<SkFlattenable> SkImageShader::CreateProc(SkReadBuffer& buffer) {
if (!img) {
return nullptr;
}
- return SkImageShader::Make(img.release(), tx, ty, &matrix);
+ return SkImageShader::Make(std::move(img), tx, ty, &matrix);
}
void SkImageShader::flatten(SkWriteBuffer& buffer) const {
buffer.writeUInt(fTileModeX);
buffer.writeUInt(fTileModeY);
buffer.writeMatrix(this->getLocalMatrix());
- buffer.writeImage(fImage);
+ buffer.writeImage(fImage.get());
}
bool SkImageShader::isOpaque() const {
@@ -46,12 +46,12 @@ bool SkImageShader::isOpaque() const {
}
size_t SkImageShader::onContextSize(const ContextRec& rec) const {
- return SkBitmapProcLegacyShader::ContextSize(rec, SkBitmapProvider(fImage).info());
+ return SkBitmapProcLegacyShader::ContextSize(rec, SkBitmapProvider(fImage.get()).info());
}
SkShader::Context* SkImageShader::onCreateContext(const ContextRec& rec, void* storage) const {
return SkBitmapProcLegacyShader::MakeContext(*this, fTileModeX, fTileModeY,
- SkBitmapProvider(fImage), rec, storage);
+ SkBitmapProvider(fImage.get()), rec, storage);
}
SkImage* SkImageShader::onIsAImage(SkMatrix* texM, TileMode xy[]) const {
@@ -129,7 +129,7 @@ static bool can_use_color_shader(const SkImage* image, SkColor* color) {
return false;
}
-sk_sp<SkShader> SkImageShader::Make(const SkImage* image, TileMode tx, TileMode ty,
+sk_sp<SkShader> SkImageShader::Make(sk_sp<SkImage> image, TileMode tx, TileMode ty,
const SkMatrix* localMatrix,
SkTBlitterAllocator* allocator) {
SkShader* shader;
@@ -140,7 +140,7 @@ sk_sp<SkShader> SkImageShader::Make(const SkImage* image, TileMode tx, TileMode
} else {
shader = allocator->createT<SkEmptyShader>();
}
- } else if (can_use_color_shader(image, &color)) {
+ } else if (can_use_color_shader(image.get(), &color)) {
if (nullptr == allocator) {
shader = new SkColorShader(color);
} else {
@@ -241,7 +241,7 @@ sk_sp<SkShader> SkMakeBitmapShader(const SkBitmap& src, SkShader::TileMode tmx,
// or modify this assert.
SkASSERT(!allocator || (kNever_SkCopyPixelsMode == cpm));
- return SkImageShader::Make(SkMakeImageFromRasterBitmap(src, cpm, allocator).get(),
+ return SkImageShader::Make(SkMakeImageFromRasterBitmap(src, cpm, allocator),
tmx, tmy, localMatrix, allocator);
}
« no previous file with comments | « src/image/SkImageShader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698