Revert of Fix memory leak in SkGradientShader. (https://codereview.chromium.org/240303003/)
Reason for revert: This and https://codereview.chromium.org/207683004 are causing memory leaks. Original issue's description: > Fix memory leak in SkGradientShader. > > Make sure pointer to gradient shader cache is unreffed in SkGradientShaderBase::getGradientTableBitmap. > Rename methods returning a "pre-reffed" object to indicate obligations. > > BUG=skia:1976 > > Committed: http://code.google.com/p/skia/source/detail?r=14223 R=reed@google.com, scroggo@google.com, dominikg@chromium.org TBR=dominikg@chromium.org, reed@google.com, scroggo@google.com NOTREECHECKS=true NOTRY=true BUG=skia:1976 Author: bungeman@google.com Review URL: https://codereview.chromium.org/241603002 git-svn-id: http://skia.googlecode.com/svn/trunk@14245 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
d202528f48
commit
68ea91a493
@ -55,7 +55,7 @@ void SkPictureShader::flatten(SkWriteBuffer& buffer) const {
|
||||
}
|
||||
}
|
||||
|
||||
SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix) const {
|
||||
SkShader* SkPictureShader::buildBitmapShader(const SkMatrix& matrix) const {
|
||||
if (!fPicture || (0 == fPicture->width() && 0 == fPicture->height())) {
|
||||
return NULL;
|
||||
}
|
||||
@ -121,12 +121,17 @@ SkShader* SkPictureShader::validInternal(const SkBitmap& device, const SkPaint&
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(matrix));
|
||||
if (!bitmapShader || !bitmapShader->validContext(device, paint, matrix)) {
|
||||
SkShader* bitmapShader = this->buildBitmapShader(matrix);
|
||||
if (!bitmapShader) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return bitmapShader.detach();
|
||||
if (!bitmapShader->validContext(device, paint, matrix)) {
|
||||
bitmapShader->unref();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return bitmapShader;
|
||||
}
|
||||
|
||||
bool SkPictureShader::validContext(const SkBitmap& device, const SkPaint& paint,
|
||||
@ -137,13 +142,13 @@ bool SkPictureShader::validContext(const SkBitmap& device, const SkPaint& paint,
|
||||
|
||||
SkShader::Context* SkPictureShader::createContext(const SkBitmap& device, const SkPaint& paint,
|
||||
const SkMatrix& matrix, void* storage) const {
|
||||
SkAutoTUnref<SkShader> bitmapShader(this->validInternal(device, paint, matrix, NULL));
|
||||
SkShader* bitmapShader = this->validInternal(device, paint, matrix, NULL);
|
||||
if (!bitmapShader) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return SkNEW_PLACEMENT_ARGS(storage, PictureShaderContext,
|
||||
(*this, device, paint, matrix, bitmapShader.detach()));
|
||||
(*this, device, paint, matrix, bitmapShader));
|
||||
}
|
||||
|
||||
size_t SkPictureShader::contextSize() const {
|
||||
@ -204,7 +209,7 @@ void SkPictureShader::toString(SkString* str) const {
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint) const {
|
||||
SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix()));
|
||||
SkAutoTUnref<SkShader> bitmapShader(this->buildBitmapShader(context->getMatrix()));
|
||||
if (!bitmapShader) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ private:
|
||||
SkShader* validInternal(const SkBitmap& device, const SkPaint& paint,
|
||||
const SkMatrix& matrix, SkMatrix* totalInverse) const;
|
||||
|
||||
SkShader* refBitmapShader(const SkMatrix&) const;
|
||||
SkShader* buildBitmapShader(const SkMatrix&) const;
|
||||
|
||||
SkPicture* fPicture;
|
||||
TileMode fTmx, fTmy;
|
||||
|
@ -211,7 +211,7 @@ SkGradientShaderBase::GradientShaderBaseContext::GradientShaderBaseContext(
|
||||
const SkGradientShaderBase& shader, const SkBitmap& device,
|
||||
const SkPaint& paint, const SkMatrix& matrix)
|
||||
: INHERITED(shader, device, paint, matrix)
|
||||
, fCache(shader.refCache(getPaintAlpha()))
|
||||
, fCache(shader.getCache(getPaintAlpha()))
|
||||
{
|
||||
const SkMatrix& inverse = this->getTotalInverse();
|
||||
|
||||
@ -558,7 +558,7 @@ void SkGradientShaderBase::GradientShaderCache::initCache32(GradientShaderCache*
|
||||
* The gradient holds a cache for the most recent value of alpha. Successive
|
||||
* callers with the same alpha value will share the same cache.
|
||||
*/
|
||||
SkGradientShaderBase::GradientShaderCache* SkGradientShaderBase::refCache(U8CPU alpha) const {
|
||||
SkGradientShaderBase::GradientShaderCache* SkGradientShaderBase::getCache(U8CPU alpha) const {
|
||||
SkAutoMutexAcquire ama(fCacheMutex);
|
||||
if (!fCache || fCache->getAlpha() != alpha) {
|
||||
fCache.reset(SkNEW_ARGS(GradientShaderCache, (alpha, *this)));
|
||||
@ -581,7 +581,7 @@ SkGradientShaderBase::GradientShaderCache* SkGradientShaderBase::refCache(U8CPU
|
||||
void SkGradientShaderBase::getGradientTableBitmap(SkBitmap* bitmap) const {
|
||||
// our caller assumes no external alpha, so we ensure that our cache is
|
||||
// built with 0xFF
|
||||
SkAutoTUnref<GradientShaderCache> cache(this->refCache(0xFF));
|
||||
GradientShaderCache* cache = this->getCache(0xFF);
|
||||
|
||||
// don't have a way to put the mapper into our cache-key yet
|
||||
if (fMapper) {
|
||||
|
@ -215,7 +215,7 @@ private:
|
||||
SkColor* fOrigColors; // original colors, before modulation by paint in context.
|
||||
bool fColorsAreOpaque;
|
||||
|
||||
GradientShaderCache* refCache(U8CPU alpha) const;
|
||||
GradientShaderCache* getCache(U8CPU alpha) const;
|
||||
mutable SkMutex fCacheMutex;
|
||||
mutable SkAutoTUnref<GradientShaderCache> fCache;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user