Title: [232139] trunk/Source/WebCore
- Revision
- 232139
- Author
- [email protected]
- Date
- 2018-05-23 17:50:16 -0700 (Wed, 23 May 2018)
Log Message
Don't create the SubimageCache just to clear an image from it
<https://webkit.org/b/185757>
Reviewed by Said Abou-Hallawa.
To fix this we make SubimageCacheWithTimer::clearImage() a
static class method that checks whether the cache exists before
removing it. We also make SubimageCacheWithTimer::getImage() a
static class method, and move more methods into the
SubimageCacheWithTimer class and make them private to reduce API
footprint.
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::drawNativeImage): Switch to use new
SubimageCacheWithTimer::getSubimage() static class method.
* platform/graphics/cg/NativeImageCG.cpp:
(WebCore::clearNativeImageSubimages): Switch to use new
SubimageCacheWithTimer::clearImage() static class method which
returns early if the subimage cache has not been created yet.
This fixes the bug.
* platform/graphics/cg/SubimageCacheWithTimer.cpp:
(WebCore::SubimageCacheWithTimer::s_cache): Allocate space for
static class variable.
(WebCore::SubimageCacheWithTimer::getSubimage): Replace instance
method with new static class method that gets the subimage cache
singleton and calls the subimage() instance method.
(WebCore::SubimageCacheWithTimer::clearImage): Replace instance
methdod with new static class method that returns early if the
static cache singleton doesn't exist (fixes the bug), otherwise
calls the clearImageAndSubimages() instance method.
(WebCore::SubimageCacheWithTimer::subimage): Rename from
getSubimage(). Use `auto` after renaming SubimageCache typedef
to SubimageCacheHashSet.
(WebCore::SubimageCacheWithTimer::clearImageAndSubimages):
Rename from clearImage(). Modernize loops.
(WebCore::SubimageCacheWithTimer::subimageCache): Change
WebCore::subimageCache() to a static class method that creates
the subimage cache singleton if it doesn't exist yet, and
returns it.
(WebCore::SubimageCacheWithTimer::subimageCacheExists): Add.
Returns false if the subimage cache singleton has not been
created yet.
* platform/graphics/cg/SubimageCacheWithTimer.h:
- Rename typedef SubimageCache to SubimageCacheHashSet to avoid
general confusion.
(WebCore::SubimageCacheWithTimer::getSubimage):
(WebCore::SubimageCacheWithTimer::clearImage):
- Change to static class methods.
(WebCore::SubimageCacheWithTimer::SubimageCacheWithTimer):
- Make private.
(WebCore::SubimageCacheWithTimer::subimage):
- Rename from getSubimage() and make private.
(WebCore::SubimageCacheWithTimer::clearImageAndSubimages):
- Rename from clearImage() and make private.
(WebCore::SubimageCacheWithTimer::subimageCache):
- Rename from WebCore::subimageCache() and make a private static
class method.
(WebCore::SubimageCacheWithTimer::subimageCacheExists):
- Add private static class method.
(WebCore::SubimageCacheWithTimer::s_cache):
- Declare private static variable to hold singleton.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (232138 => 232139)
--- trunk/Source/WebCore/ChangeLog 2018-05-24 00:47:35 UTC (rev 232138)
+++ trunk/Source/WebCore/ChangeLog 2018-05-24 00:50:16 UTC (rev 232139)
@@ -1,3 +1,69 @@
+2018-05-23 David Kilzer <[email protected]>
+
+ Don't create the SubimageCache just to clear an image from it
+ <https://webkit.org/b/185757>
+
+ Reviewed by Said Abou-Hallawa.
+
+ To fix this we make SubimageCacheWithTimer::clearImage() a
+ static class method that checks whether the cache exists before
+ removing it. We also make SubimageCacheWithTimer::getImage() a
+ static class method, and move more methods into the
+ SubimageCacheWithTimer class and make them private to reduce API
+ footprint.
+
+ * platform/graphics/cg/GraphicsContextCG.cpp:
+ (WebCore::GraphicsContext::drawNativeImage): Switch to use new
+ SubimageCacheWithTimer::getSubimage() static class method.
+ * platform/graphics/cg/NativeImageCG.cpp:
+ (WebCore::clearNativeImageSubimages): Switch to use new
+ SubimageCacheWithTimer::clearImage() static class method which
+ returns early if the subimage cache has not been created yet.
+ This fixes the bug.
+
+ * platform/graphics/cg/SubimageCacheWithTimer.cpp:
+ (WebCore::SubimageCacheWithTimer::s_cache): Allocate space for
+ static class variable.
+ (WebCore::SubimageCacheWithTimer::getSubimage): Replace instance
+ method with new static class method that gets the subimage cache
+ singleton and calls the subimage() instance method.
+ (WebCore::SubimageCacheWithTimer::clearImage): Replace instance
+ methdod with new static class method that returns early if the
+ static cache singleton doesn't exist (fixes the bug), otherwise
+ calls the clearImageAndSubimages() instance method.
+ (WebCore::SubimageCacheWithTimer::subimage): Rename from
+ getSubimage(). Use `auto` after renaming SubimageCache typedef
+ to SubimageCacheHashSet.
+ (WebCore::SubimageCacheWithTimer::clearImageAndSubimages):
+ Rename from clearImage(). Modernize loops.
+ (WebCore::SubimageCacheWithTimer::subimageCache): Change
+ WebCore::subimageCache() to a static class method that creates
+ the subimage cache singleton if it doesn't exist yet, and
+ returns it.
+ (WebCore::SubimageCacheWithTimer::subimageCacheExists): Add.
+ Returns false if the subimage cache singleton has not been
+ created yet.
+
+ * platform/graphics/cg/SubimageCacheWithTimer.h:
+ - Rename typedef SubimageCache to SubimageCacheHashSet to avoid
+ general confusion.
+ (WebCore::SubimageCacheWithTimer::getSubimage):
+ (WebCore::SubimageCacheWithTimer::clearImage):
+ - Change to static class methods.
+ (WebCore::SubimageCacheWithTimer::SubimageCacheWithTimer):
+ - Make private.
+ (WebCore::SubimageCacheWithTimer::subimage):
+ - Rename from getSubimage() and make private.
+ (WebCore::SubimageCacheWithTimer::clearImageAndSubimages):
+ - Rename from clearImage() and make private.
+ (WebCore::SubimageCacheWithTimer::subimageCache):
+ - Rename from WebCore::subimageCache() and make a private static
+ class method.
+ (WebCore::SubimageCacheWithTimer::subimageCacheExists):
+ - Add private static class method.
+ (WebCore::SubimageCacheWithTimer::s_cache):
+ - Declare private static variable to hold singleton.
+
2018-05-23 Eric Carlson <[email protected]>
Avoid loading AVFoundation to check supported MIME types if possible
Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (232138 => 232139)
--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp 2018-05-24 00:47:35 UTC (rev 232138)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp 2018-05-24 00:50:16 UTC (rev 232139)
@@ -330,7 +330,7 @@
adjustedDestRect.setHeight(subimageRect.height() / yScale);
#if CACHE_SUBIMAGES
- subImage = subimageCache().getSubimage(subImage.get(), subimageRect);
+ subImage = SubimageCacheWithTimer::getSubimage(subImage.get(), subimageRect);
#else
subImage = adoptCF(CGImageCreateWithImageInRect(subImage.get(), subimageRect));
#endif
Modified: trunk/Source/WebCore/platform/graphics/cg/NativeImageCG.cpp (232138 => 232139)
--- trunk/Source/WebCore/platform/graphics/cg/NativeImageCG.cpp 2018-05-24 00:47:35 UTC (rev 232138)
+++ trunk/Source/WebCore/platform/graphics/cg/NativeImageCG.cpp 2018-05-24 00:50:16 UTC (rev 232139)
@@ -86,7 +86,7 @@
{
#if CACHE_SUBIMAGES
if (image)
- subimageCache().clearImage(image.get());
+ SubimageCacheWithTimer::clearImage(image.get());
#endif
}
Modified: trunk/Source/WebCore/platform/graphics/cg/SubimageCacheWithTimer.cpp (232138 => 232139)
--- trunk/Source/WebCore/platform/graphics/cg/SubimageCacheWithTimer.cpp 2018-05-24 00:47:35 UTC (rev 232138)
+++ trunk/Source/WebCore/platform/graphics/cg/SubimageCacheWithTimer.cpp 2018-05-24 00:50:16 UTC (rev 232139)
@@ -34,9 +34,22 @@
namespace WebCore {
+SubimageCacheWithTimer* SubimageCacheWithTimer::s_cache;
+
static const Seconds subimageCacheClearDelay { 1_s };
static const int maxSubimageCacheSize = 300;
+RetainPtr<CGImageRef> SubimageCacheWithTimer::getSubimage(CGImageRef image, const FloatRect& rect)
+{
+ return subimageCache().subimage(image, rect);
+}
+
+void SubimageCacheWithTimer::clearImage(CGImageRef image)
+{
+ if (subimageCacheExists())
+ subimageCache().clearImageAndSubimages(image);
+}
+
struct SubimageRequest {
CGImageRef image;
const FloatRect& rect;
@@ -73,7 +86,7 @@
m_cache.clear();
}
-RetainPtr<CGImageRef> SubimageCacheWithTimer::getSubimage(CGImageRef image, const FloatRect& rect)
+RetainPtr<CGImageRef> SubimageCacheWithTimer::subimage(CGImageRef image, const FloatRect& rect)
{
m_timer.restart();
if (m_cache.size() == maxSubimageCacheSize) {
@@ -83,7 +96,7 @@
}
ASSERT(m_cache.size() < maxSubimageCacheSize);
- SubimageCache::AddResult result = m_cache.add<SubimageCacheAdder>(SubimageRequest(image, rect));
+ auto result = m_cache.add<SubimageCacheAdder>(SubimageRequest(image, rect));
if (result.isNewEntry)
m_images.add(image);
@@ -90,31 +103,36 @@
return result.iterator->subimage;
}
-void SubimageCacheWithTimer::clearImage(CGImageRef image)
+void SubimageCacheWithTimer::clearImageAndSubimages(CGImageRef image)
{
if (m_images.contains(image)) {
Vector<SubimageCacheEntry> toBeRemoved;
- SubimageCache::const_iterator end = m_cache.end();
- for (SubimageCache::const_iterator it = m_cache.begin(); it != end; ++it) {
- if (it->image.get() == image)
- toBeRemoved.append(*it);
+ for (const auto& entry : m_cache) {
+ if (entry.image.get() == image)
+ toBeRemoved.append(entry);
}
- for (Vector<SubimageCacheEntry>::iterator removeIt = toBeRemoved.begin(); removeIt != toBeRemoved.end(); ++removeIt)
- m_cache.remove(*removeIt);
+ for (auto& entry : toBeRemoved)
+ m_cache.remove(entry);
m_images.removeAll(image);
}
}
-SubimageCacheWithTimer& subimageCache()
+SubimageCacheWithTimer& SubimageCacheWithTimer::subimageCache()
{
- static SubimageCacheWithTimer& cache = *new SubimageCacheWithTimer;
- return cache;
+ if (!s_cache)
+ s_cache = new SubimageCacheWithTimer;
+ return *s_cache;
}
+bool SubimageCacheWithTimer::subimageCacheExists()
+{
+ return !!s_cache;
}
+}
+
#endif
#endif
Modified: trunk/Source/WebCore/platform/graphics/cg/SubimageCacheWithTimer.h (232138 => 232139)
--- trunk/Source/WebCore/platform/graphics/cg/SubimageCacheWithTimer.h 2018-05-24 00:47:35 UTC (rev 232138)
+++ trunk/Source/WebCore/platform/graphics/cg/SubimageCacheWithTimer.h 2018-05-24 00:50:16 UTC (rev 232139)
@@ -80,23 +80,27 @@
static const bool safeToCompareToEmptyOrDeleted = true;
};
- typedef HashSet<SubimageCacheEntry, SubimageCacheHash, SubimageCacheEntryTraits> SubimageCache;
+ static RetainPtr<CGImageRef> getSubimage(CGImageRef, const FloatRect&);
+ static void clearImage(CGImageRef);
-public:
+private:
+ typedef HashSet<SubimageCacheEntry, SubimageCacheHash, SubimageCacheEntryTraits> SubimageCacheHashSet;
+
SubimageCacheWithTimer();
- RetainPtr<CGImageRef> getSubimage(CGImageRef, const FloatRect&);
- void clearImage(CGImageRef);
-
-private:
void invalidateCacheTimerFired();
+ RetainPtr<CGImageRef> subimage(CGImageRef, const FloatRect&);
+ void clearImageAndSubimages(CGImageRef);
+
HashCountedSet<CGImageRef> m_images;
- SubimageCache m_cache;
+ SubimageCacheHashSet m_cache;
DeferrableOneShotTimer m_timer;
+
+ static SubimageCacheWithTimer& subimageCache();
+ static bool subimageCacheExists();
+ static SubimageCacheWithTimer* s_cache;
};
-SubimageCacheWithTimer& subimageCache();
-
#endif // CACHE_SUBIMAGES
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes