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

Side by Side Diff: src/effects/gradients/SkGradientShader.cpp

Issue 241603002: Revert of Fix memory leak in SkGradientShader. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 8 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
« no previous file with comments | « src/core/SkPictureShader.cpp ('k') | src/effects/gradients/SkGradientShaderPriv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkGradientShaderPriv.h" 8 #include "SkGradientShaderPriv.h"
9 #include "SkLinearGradient.h" 9 #include "SkLinearGradient.h"
10 #include "SkRadialGradient.h" 10 #include "SkRadialGradient.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 204 }
205 205
206 bool SkGradientShaderBase::isOpaque() const { 206 bool SkGradientShaderBase::isOpaque() const {
207 return fColorsAreOpaque; 207 return fColorsAreOpaque;
208 } 208 }
209 209
210 SkGradientShaderBase::GradientShaderBaseContext::GradientShaderBaseContext( 210 SkGradientShaderBase::GradientShaderBaseContext::GradientShaderBaseContext(
211 const SkGradientShaderBase& shader, const SkBitmap& device, 211 const SkGradientShaderBase& shader, const SkBitmap& device,
212 const SkPaint& paint, const SkMatrix& matrix) 212 const SkPaint& paint, const SkMatrix& matrix)
213 : INHERITED(shader, device, paint, matrix) 213 : INHERITED(shader, device, paint, matrix)
214 , fCache(shader.refCache(getPaintAlpha())) 214 , fCache(shader.getCache(getPaintAlpha()))
215 { 215 {
216 const SkMatrix& inverse = this->getTotalInverse(); 216 const SkMatrix& inverse = this->getTotalInverse();
217 217
218 fDstToIndex.setConcat(shader.fPtsToUnit, inverse); 218 fDstToIndex.setConcat(shader.fPtsToUnit, inverse);
219 219
220 fDstToIndexProc = fDstToIndex.getMapXYProc(); 220 fDstToIndexProc = fDstToIndex.getMapXYProc();
221 fDstToIndexClass = (uint8_t)SkShader::Context::ComputeMatrixClass(fDstToInde x); 221 fDstToIndexClass = (uint8_t)SkShader::Context::ComputeMatrixClass(fDstToInde x);
222 222
223 // now convert our colors in to PMColors 223 // now convert our colors in to PMColors
224 unsigned paintAlpha = this->getPaintAlpha(); 224 unsigned paintAlpha = this->getPaintAlpha();
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 cache->fCache32PixelRef->unref(); 551 cache->fCache32PixelRef->unref();
552 cache->fCache32PixelRef = newPR; 552 cache->fCache32PixelRef = newPR;
553 cache->fCache32 = (SkPMColor*)newPR->getAddr(); 553 cache->fCache32 = (SkPMColor*)newPR->getAddr();
554 } 554 }
555 } 555 }
556 556
557 /* 557 /*
558 * The gradient holds a cache for the most recent value of alpha. Successive 558 * The gradient holds a cache for the most recent value of alpha. Successive
559 * callers with the same alpha value will share the same cache. 559 * callers with the same alpha value will share the same cache.
560 */ 560 */
561 SkGradientShaderBase::GradientShaderCache* SkGradientShaderBase::refCache(U8CPU alpha) const { 561 SkGradientShaderBase::GradientShaderCache* SkGradientShaderBase::getCache(U8CPU alpha) const {
562 SkAutoMutexAcquire ama(fCacheMutex); 562 SkAutoMutexAcquire ama(fCacheMutex);
563 if (!fCache || fCache->getAlpha() != alpha) { 563 if (!fCache || fCache->getAlpha() != alpha) {
564 fCache.reset(SkNEW_ARGS(GradientShaderCache, (alpha, *this))); 564 fCache.reset(SkNEW_ARGS(GradientShaderCache, (alpha, *this)));
565 } 565 }
566 // Increment the ref counter inside the mutex to ensure the returned pointer is still valid. 566 // Increment the ref counter inside the mutex to ensure the returned pointer is still valid.
567 // Otherwise, the pointer may have been overwritten on a different thread be fore the object's 567 // Otherwise, the pointer may have been overwritten on a different thread be fore the object's
568 // ref count was incremented. 568 // ref count was incremented.
569 fCache.get()->ref(); 569 fCache.get()->ref();
570 return fCache; 570 return fCache;
571 } 571 }
572 572
573 /* 573 /*
574 * Because our caller might rebuild the same (logically the same) gradient 574 * Because our caller might rebuild the same (logically the same) gradient
575 * over and over, we'd like to return exactly the same "bitmap" if possible, 575 * over and over, we'd like to return exactly the same "bitmap" if possible,
576 * allowing the client to utilize a cache of our bitmap (e.g. with a GPU). 576 * allowing the client to utilize a cache of our bitmap (e.g. with a GPU).
577 * To do that, we maintain a private cache of built-bitmaps, based on our 577 * To do that, we maintain a private cache of built-bitmaps, based on our
578 * colors and positions. Note: we don't try to flatten the fMapper, so if one 578 * colors and positions. Note: we don't try to flatten the fMapper, so if one
579 * is present, we skip the cache for now. 579 * is present, we skip the cache for now.
580 */ 580 */
581 void SkGradientShaderBase::getGradientTableBitmap(SkBitmap* bitmap) const { 581 void SkGradientShaderBase::getGradientTableBitmap(SkBitmap* bitmap) const {
582 // our caller assumes no external alpha, so we ensure that our cache is 582 // our caller assumes no external alpha, so we ensure that our cache is
583 // built with 0xFF 583 // built with 0xFF
584 SkAutoTUnref<GradientShaderCache> cache(this->refCache(0xFF)); 584 GradientShaderCache* cache = this->getCache(0xFF);
585 585
586 // don't have a way to put the mapper into our cache-key yet 586 // don't have a way to put the mapper into our cache-key yet
587 if (fMapper) { 587 if (fMapper) {
588 // force our cache32pixelref to be built 588 // force our cache32pixelref to be built
589 (void)cache->getCache32(); 589 (void)cache->getCache32();
590 bitmap->setConfig(SkImageInfo::MakeN32Premul(kCache32Count, 1)); 590 bitmap->setConfig(SkImageInfo::MakeN32Premul(kCache32Count, 1));
591 bitmap->setPixelRef(cache->getCache32PixelRef()); 591 bitmap->setPixelRef(cache->getCache32PixelRef());
592 return; 592 return;
593 } 593 }
594 594
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 (*stops)[i] = stop; 1142 (*stops)[i] = stop;
1143 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; 1143 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f;
1144 } 1144 }
1145 } 1145 }
1146 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); 1146 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount));
1147 1147
1148 return outColors; 1148 return outColors;
1149 } 1149 }
1150 1150
1151 #endif 1151 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureShader.cpp ('k') | src/effects/gradients/SkGradientShaderPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698