fix memory leak, remake Imageshader to use sk_sp
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2239723002 Review-Url: https://codereview.chromium.org/2239723002
This commit is contained in:
parent
8fb6ba5f88
commit
6b2d7acecd
@ -108,7 +108,7 @@ void SkImage::preroll(GrContext* ctx) const {
|
||||
|
||||
sk_sp<SkShader> SkImage::makeShader(SkShader::TileMode tileX, SkShader::TileMode tileY,
|
||||
const SkMatrix* localMatrix) const {
|
||||
return SkImageShader::Make(this, tileX, tileY, localMatrix);
|
||||
return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)), tileX, tileY, localMatrix);
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
class SkImageShader : public SkShader {
|
||||
public:
|
||||
static sk_sp<SkShader> Make(const SkImage*, TileMode tx, TileMode ty,
|
||||
static sk_sp<SkShader> Make(sk_sp<SkImage>, TileMode tx, TileMode ty,
|
||||
const SkMatrix* localMatrix, SkTBlitterAllocator* = nullptr);
|
||||
|
||||
bool isOpaque() const override;
|
||||
@ -26,7 +26,7 @@ public:
|
||||
sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override;
|
||||
#endif
|
||||
|
||||
SkImageShader(const SkImage*, TileMode tx, TileMode ty, const SkMatrix* localMatrix);
|
||||
SkImageShader(sk_sp<SkImage>, TileMode tx, TileMode ty, const SkMatrix* localMatrix);
|
||||
|
||||
protected:
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
@ -35,9 +35,9 @@ protected:
|
||||
bool onIsABitmap(SkBitmap*, SkMatrix*, TileMode*) const override;
|
||||
SkImage* onIsAImage(SkMatrix*, TileMode*) const override;
|
||||
|
||||
SkAutoTUnref<const SkImage> fImage;
|
||||
const TileMode fTileModeX;
|
||||
const TileMode fTileModeY;
|
||||
sk_sp<SkImage> fImage;
|
||||
const TileMode fTileModeX;
|
||||
const TileMode fTileModeY;
|
||||
|
||||
private:
|
||||
friend class SkShader;
|
||||
|
Loading…
Reference in New Issue
Block a user