Allow ImageBuffer to re-use IOSurfaces
https://bugs.webkit.org/show_bug.cgi?id=125477
Source/WebCore:
Reviewed by Geoff Garen. Modifications reviewed by Tim Horton.
This patch is taken from r160945, but the modifications to ImageBufferCG.cpp
have been reverted.
This test adds a static class, ImageBufferBackingStoreCache, that vends
IOSurfaces. It remembers IOSurfaces that have been returned to it until
a configurable timeout.
The storage used by this class is in the form of a HashMap from a
bucketed size to the IOSurface. There are many other data structures
that could be used, but this implementation gives a 80% hit rate on
normal browsing of some example sites with Canvas and
text-decoration-skip: ink. Because the buckets are fairly
small (rounding the width and height up to multiples of 8), traversing the
bucket contents takes on average 2 steps.
Test: fast/canvas/canvas-backing-store-reuse.html
* WebCore.xcodeproj/project.pbxproj: Added new caching class
* platform/graphics/cg/ImageBufferBackingStoreCache.cpp: Added.
(WebCore::createIOSurface): Copied from ImageBufferCG.cpp
(WebCore::ImageBufferBackingStoreCache::timerFired): Forget the cache
contents
(WebCore::ImageBufferBackingStoreCache::schedulePurgeTimer):
(WebCore::ImageBufferBackingStoreCache::get): Static getter
(WebCore::ImageBufferBackingStoreCache::ImageBufferBackingStoreCache):
(WebCore::ImageBufferBackingStoreCache::insertIntoCache): Memory-management
creation function
(WebCore::ImageBufferBackingStoreCache::takeFromCache): Memory-management
deletion function
(WebCore::ImageBufferBackingStoreCache::isAcceptableSurface): Does this cached
IOSurface fit the bill?
(WebCore::ImageBufferBackingStoreCache::tryTakeFromCache): Lookup
a bucket and walk through its contents
(WebCore::ImageBufferBackingStoreCache::getOrAllocate): Public function
for clients who want a IOSurface from the cache
(WebCore::ImageBufferBackingStoreCache::deallocate): Public
function for clients to return an IOSurface to the pool
* platform/graphics/cg/ImageBufferBackingStoreCache.h: Added.
(WebCore::ImageBuffer::ImageBuffer):
(WebCore::ImageBuffer::~ImageBuffer):
PerformanceTests:
Reviewed by Geoff Garen.
This test times creating a variety of different sizes of canvases
once some have already been created. The second creation of the
canvases should re-use the existing IOSurfaces.
* Canvas/reuse.html: Added.
LayoutTests:
Reviewed by Geoff Garen.
Now that we're re-using the backing store of canvases, this
test makes sure that if we draw to a canvas, then destroy it,
then create a new canvas (which should share the same backing
store) that it doesn't have the stale data in it
* fast/canvas/canvas-backing-store-reuse-expected.txt: Added.
* fast/canvas/canvas-backing-store-reuse.html: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@161235 268f45cc-cd09-0410-ab3c-d52691b4dbfc
9 files changed