Changeset 232139 in webkit
- Timestamp:
- May 23, 2018 5:50:16 PM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r232136 r232139 1 2018-05-23 David Kilzer <ddkilzer@apple.com> 2 3 Don't create the SubimageCache just to clear an image from it 4 <https://webkit.org/b/185757> 5 6 Reviewed by Said Abou-Hallawa. 7 8 To fix this we make SubimageCacheWithTimer::clearImage() a 9 static class method that checks whether the cache exists before 10 removing it. We also make SubimageCacheWithTimer::getImage() a 11 static class method, and move more methods into the 12 SubimageCacheWithTimer class and make them private to reduce API 13 footprint. 14 15 * platform/graphics/cg/GraphicsContextCG.cpp: 16 (WebCore::GraphicsContext::drawNativeImage): Switch to use new 17 SubimageCacheWithTimer::getSubimage() static class method. 18 * platform/graphics/cg/NativeImageCG.cpp: 19 (WebCore::clearNativeImageSubimages): Switch to use new 20 SubimageCacheWithTimer::clearImage() static class method which 21 returns early if the subimage cache has not been created yet. 22 This fixes the bug. 23 24 * platform/graphics/cg/SubimageCacheWithTimer.cpp: 25 (WebCore::SubimageCacheWithTimer::s_cache): Allocate space for 26 static class variable. 27 (WebCore::SubimageCacheWithTimer::getSubimage): Replace instance 28 method with new static class method that gets the subimage cache 29 singleton and calls the subimage() instance method. 30 (WebCore::SubimageCacheWithTimer::clearImage): Replace instance 31 methdod with new static class method that returns early if the 32 static cache singleton doesn't exist (fixes the bug), otherwise 33 calls the clearImageAndSubimages() instance method. 34 (WebCore::SubimageCacheWithTimer::subimage): Rename from 35 getSubimage(). Use `auto` after renaming SubimageCache typedef 36 to SubimageCacheHashSet. 37 (WebCore::SubimageCacheWithTimer::clearImageAndSubimages): 38 Rename from clearImage(). Modernize loops. 39 (WebCore::SubimageCacheWithTimer::subimageCache): Change 40 WebCore::subimageCache() to a static class method that creates 41 the subimage cache singleton if it doesn't exist yet, and 42 returns it. 43 (WebCore::SubimageCacheWithTimer::subimageCacheExists): Add. 44 Returns false if the subimage cache singleton has not been 45 created yet. 46 47 * platform/graphics/cg/SubimageCacheWithTimer.h: 48 - Rename typedef SubimageCache to SubimageCacheHashSet to avoid 49 general confusion. 50 (WebCore::SubimageCacheWithTimer::getSubimage): 51 (WebCore::SubimageCacheWithTimer::clearImage): 52 - Change to static class methods. 53 (WebCore::SubimageCacheWithTimer::SubimageCacheWithTimer): 54 - Make private. 55 (WebCore::SubimageCacheWithTimer::subimage): 56 - Rename from getSubimage() and make private. 57 (WebCore::SubimageCacheWithTimer::clearImageAndSubimages): 58 - Rename from clearImage() and make private. 59 (WebCore::SubimageCacheWithTimer::subimageCache): 60 - Rename from WebCore::subimageCache() and make a private static 61 class method. 62 (WebCore::SubimageCacheWithTimer::subimageCacheExists): 63 - Add private static class method. 64 (WebCore::SubimageCacheWithTimer::s_cache): 65 - Declare private static variable to hold singleton. 66 1 67 2018-05-23 Eric Carlson <eric.carlson@apple.com> 2 68 -
trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
r229209 r232139 331 331 332 332 #if CACHE_SUBIMAGES 333 subImage = subimageCache().getSubimage(subImage.get(), subimageRect);333 subImage = SubimageCacheWithTimer::getSubimage(subImage.get(), subimageRect); 334 334 #else 335 335 subImage = adoptCF(CGImageCreateWithImageInRect(subImage.get(), subimageRect)); -
trunk/Source/WebCore/platform/graphics/cg/NativeImageCG.cpp
r220506 r232139 87 87 #if CACHE_SUBIMAGES 88 88 if (image) 89 subimageCache().clearImage(image.get());89 SubimageCacheWithTimer::clearImage(image.get()); 90 90 #endif 91 91 } -
trunk/Source/WebCore/platform/graphics/cg/SubimageCacheWithTimer.cpp
r215152 r232139 35 35 namespace WebCore { 36 36 37 SubimageCacheWithTimer* SubimageCacheWithTimer::s_cache; 38 37 39 static const Seconds subimageCacheClearDelay { 1_s }; 38 40 static const int maxSubimageCacheSize = 300; 41 42 RetainPtr<CGImageRef> SubimageCacheWithTimer::getSubimage(CGImageRef image, const FloatRect& rect) 43 { 44 return subimageCache().subimage(image, rect); 45 } 46 47 void SubimageCacheWithTimer::clearImage(CGImageRef image) 48 { 49 if (subimageCacheExists()) 50 subimageCache().clearImageAndSubimages(image); 51 } 39 52 40 53 struct SubimageRequest { … … 74 87 } 75 88 76 RetainPtr<CGImageRef> SubimageCacheWithTimer:: getSubimage(CGImageRef image, const FloatRect& rect)89 RetainPtr<CGImageRef> SubimageCacheWithTimer::subimage(CGImageRef image, const FloatRect& rect) 77 90 { 78 91 m_timer.restart(); … … 84 97 85 98 ASSERT(m_cache.size() < maxSubimageCacheSize); 86 SubimageCache::AddResultresult = m_cache.add<SubimageCacheAdder>(SubimageRequest(image, rect));99 auto result = m_cache.add<SubimageCacheAdder>(SubimageRequest(image, rect)); 87 100 if (result.isNewEntry) 88 101 m_images.add(image); … … 91 104 } 92 105 93 void SubimageCacheWithTimer::clearImage (CGImageRef image)106 void SubimageCacheWithTimer::clearImageAndSubimages(CGImageRef image) 94 107 { 95 108 if (m_images.contains(image)) { 96 109 Vector<SubimageCacheEntry> toBeRemoved; 97 SubimageCache::const_iterator end = m_cache.end(); 98 for (SubimageCache::const_iterator it = m_cache.begin(); it != end; ++it) { 99 if (it->image.get() == image) 100 toBeRemoved.append(*it); 110 for (const auto& entry : m_cache) { 111 if (entry.image.get() == image) 112 toBeRemoved.append(entry); 101 113 } 102 114 103 for ( Vector<SubimageCacheEntry>::iterator removeIt = toBeRemoved.begin(); removeIt != toBeRemoved.end(); ++removeIt)104 m_cache.remove( *removeIt);115 for (auto& entry : toBeRemoved) 116 m_cache.remove(entry); 105 117 106 118 m_images.removeAll(image); … … 108 120 } 109 121 110 SubimageCacheWithTimer& subimageCache()122 SubimageCacheWithTimer& SubimageCacheWithTimer::subimageCache() 111 123 { 112 static SubimageCacheWithTimer& cache = *new SubimageCacheWithTimer; 113 return cache; 124 if (!s_cache) 125 s_cache = new SubimageCacheWithTimer; 126 return *s_cache; 127 } 128 129 bool SubimageCacheWithTimer::subimageCacheExists() 130 { 131 return !!s_cache; 114 132 } 115 133 -
trunk/Source/WebCore/platform/graphics/cg/SubimageCacheWithTimer.h
r169550 r232139 81 81 }; 82 82 83 typedef HashSet<SubimageCacheEntry, SubimageCacheHash, SubimageCacheEntryTraits> SubimageCache; 84 85 public: 86 SubimageCacheWithTimer(); 87 RetainPtr<CGImageRef> getSubimage(CGImageRef, const FloatRect&); 88 void clearImage(CGImageRef); 83 static RetainPtr<CGImageRef> getSubimage(CGImageRef, const FloatRect&); 84 static void clearImage(CGImageRef); 89 85 90 86 private: 87 typedef HashSet<SubimageCacheEntry, SubimageCacheHash, SubimageCacheEntryTraits> SubimageCacheHashSet; 88 89 SubimageCacheWithTimer(); 91 90 void invalidateCacheTimerFired(); 92 91 92 RetainPtr<CGImageRef> subimage(CGImageRef, const FloatRect&); 93 void clearImageAndSubimages(CGImageRef); 94 93 95 HashCountedSet<CGImageRef> m_images; 94 SubimageCache m_cache;96 SubimageCacheHashSet m_cache; 95 97 DeferrableOneShotTimer m_timer; 98 99 static SubimageCacheWithTimer& subimageCache(); 100 static bool subimageCacheExists(); 101 static SubimageCacheWithTimer* s_cache; 96 102 }; 97 98 SubimageCacheWithTimer& subimageCache();99 103 100 104 #endif // CACHE_SUBIMAGES
Note: See TracChangeset
for help on using the changeset viewer.