https://bugs.webkit.org/show_bug.cgi?id=151516
Reviewed by Tim Horton.
Source/WebCore:
Previously IOSurface::create was only looking in the pool for RGBA-format surfaces. Change that to
always look in the pool, and to cache all format types. We include format in the criteria used
to pick a surface from the pool.
* platform/graphics/cg/IOSurfacePool.cpp:
(WebCore::surfaceMatchesParameters):
(WebCore::IOSurfacePool::takeSurface):
(WebCore::IOSurfacePool::shouldCacheFormat):
(WebCore::IOSurfacePool::shouldCacheSurface):
(WebCore::IOSurfacePool::addSurface):
* platform/graphics/cg/IOSurfacePool.h:
* platform/graphics/cocoa/IOSurface.h:
* platform/graphics/cocoa/IOSurface.mm:
(IOSurface::surfaceFromPool):
(IOSurface::create):
(IOSurface::IOSurface):
Source/WebKit2:
Have RemoteLayerBackingStore go through a static function on IOSurface to return
a surface to the pool, rather than knowing about IOSurfacePool directly.
* Shared/mac/RemoteLayerBackingStore.mm:
(WebKit::RemoteLayerBackingStore::Buffer::discard):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192701
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2015-11-20 Simon Fraser <simon.fraser@apple.com>
+
+ Allow more buffer formats in the IOSurface pool
+ https://bugs.webkit.org/show_bug.cgi?id=151516
+
+ Reviewed by Tim Horton.
+
+ Previously IOSurface::create was only looking in the pool for RGBA-format surfaces. Change that to
+ always look in the pool, and to cache all format types. We include format in the criteria used
+ to pick a surface from the pool.
+
+ * platform/graphics/cg/IOSurfacePool.cpp:
+ (WebCore::surfaceMatchesParameters):
+ (WebCore::IOSurfacePool::takeSurface):
+ (WebCore::IOSurfacePool::shouldCacheFormat):
+ (WebCore::IOSurfacePool::shouldCacheSurface):
+ (WebCore::IOSurfacePool::addSurface):
+ * platform/graphics/cg/IOSurfacePool.h:
+ * platform/graphics/cocoa/IOSurface.h:
+ * platform/graphics/cocoa/IOSurface.mm:
+ (IOSurface::surfaceFromPool):
+ (IOSurface::create):
+ (IOSurface::IOSurface):
+
2015-11-20 Brent Fulgham <bfulgham@apple.com>
[Win] Support High DPI drawing with CACFLayers
#if USE(IOSURFACE)
#include "GraphicsContextCG.h"
-#include "IOSurface.h"
#include <CoreGraphics/CoreGraphics.h>
#include <chrono>
#include <wtf/NeverDestroyed.h>
return pool;
}
-static bool surfaceMatchesParameters(IOSurface& surface, const IntSize& requestedSize, ColorSpace colorSpace)
+static bool surfaceMatchesParameters(IOSurface& surface, IntSize requestedSize, ColorSpace colorSpace, IOSurface::Format format)
{
- IntSize surfaceSize = surface.size();
+ if (format != surface.format())
+ return false;
if (colorSpace != surface.colorSpace())
return false;
- if (surfaceSize != requestedSize)
+ if (requestedSize != surface.size())
return false;
return true;
}
m_sizesInPruneOrder.append(size);
}
-std::unique_ptr<IOSurface> IOSurfacePool::takeSurface(IntSize size, ColorSpace colorSpace)
+std::unique_ptr<IOSurface> IOSurfacePool::takeSurface(IntSize size, ColorSpace colorSpace, IOSurface::Format format)
{
CachedSurfaceMap::iterator mapIter = m_cachedSurfaces.find(size);
}
for (auto surfaceIter = mapIter->value.begin(); surfaceIter != mapIter->value.end(); ++surfaceIter) {
- if (!surfaceMatchesParameters(*surfaceIter->get(), size, colorSpace))
+ if (!surfaceMatchesParameters(*surfaceIter->get(), size, colorSpace, format))
continue;
auto surface = WTF::move(*surfaceIter);
// Some of the in-use surfaces may no longer actually be in-use, but we haven't moved them over yet.
for (auto surfaceIter = m_inUseSurfaces.begin(); surfaceIter != m_inUseSurfaces.end(); ++surfaceIter) {
- if (!surfaceMatchesParameters(*surfaceIter->get(), size, colorSpace))
+ if (!surfaceMatchesParameters(*surfaceIter->get(), size, colorSpace, format))
continue;
if (surfaceIter->get()->isInUse())
continue;
return nullptr;
}
-void IOSurfacePool::addSurface(std::unique_ptr<IOSurface> surface)
+bool IOSurfacePool::shouldCacheSurface(const IOSurface& surface) const
{
- if (surface->totalBytes() > m_maximumBytesCached)
- return;
+ if (surface.totalBytes() > m_maximumBytesCached)
+ return false;
// There's no reason to pool empty surfaces; we should never allocate them in the first place.
// This also covers isZero(), which would cause trouble when used as the key in m_cachedSurfaces.
- if (surface->size().isEmpty())
+ if (surface.size().isEmpty())
+ return false;
+
+ return true;
+}
+
+void IOSurfacePool::addSurface(std::unique_ptr<IOSurface> surface)
+{
+ if (!shouldCacheSurface(*surface))
return;
bool surfaceIsInUse = surface->isInUse();
#define IOSurfacePool_h
#include "ColorSpace.h"
+#include "IOSurface.h"
#include "IntSize.h"
#include "IntSizeHash.h"
#include "Timer.h"
namespace WebCore {
-class IOSurface;
-
class IOSurfacePool {
WTF_MAKE_NONCOPYABLE(IOSurfacePool);
WTF_MAKE_FAST_ALLOCATED;
public:
WEBCORE_EXPORT static IOSurfacePool& sharedPool();
- std::unique_ptr<IOSurface> takeSurface(IntSize, ColorSpace);
+ std::unique_ptr<IOSurface> takeSurface(IntSize, ColorSpace, IOSurface::Format);
WEBCORE_EXPORT void addSurface(std::unique_ptr<IOSurface>);
void discardAllSurfaces();
typedef Deque<std::unique_ptr<IOSurface>> CachedSurfaceQueue;
typedef HashMap<IntSize, CachedSurfaceQueue> CachedSurfaceMap;
typedef HashMap<IOSurface*, CachedSurfaceDetails> CachedSurfaceDetailsMap;
+
+ bool shouldCacheSurface(const IOSurface&) const;
void willAddSurface(IOSurface&, bool inUse);
void didRemoveSurface(IOSurface&, bool inUse);
};
WEBCORE_EXPORT static std::unique_ptr<IOSurface> create(IntSize, ColorSpace, Format = Format::RGBA);
- WEBCORE_EXPORT static std::unique_ptr<IOSurface> create(IntSize, IntSize contextSize, ColorSpace);
+ WEBCORE_EXPORT static std::unique_ptr<IOSurface> create(IntSize, IntSize contextSize, ColorSpace, Format = Format::RGBA);
WEBCORE_EXPORT static std::unique_ptr<IOSurface> createFromSendRight(const MachSendRight&, ColorSpace);
static std::unique_ptr<IOSurface> createFromSurface(IOSurfaceRef, ColorSpace);
WEBCORE_EXPORT static std::unique_ptr<IOSurface> createFromImage(CGImageRef);
+ WEBCORE_EXPORT static void moveToPool(std::unique_ptr<IOSurface>&&);
+
static IntSize maximumSize();
WEBCORE_EXPORT MachSendRight createSendRight() const;
private:
IOSurface(IntSize, ColorSpace, Format);
- IOSurface(IntSize, IntSize contextSize, ColorSpace);
+ IOSurface(IntSize, IntSize contextSize, ColorSpace, Format);
IOSurface(IOSurfaceRef, ColorSpace);
- static std::unique_ptr<IOSurface> surfaceFromPool(IntSize, IntSize contextSize, ColorSpace);
+ static std::unique_ptr<IOSurface> surfaceFromPool(IntSize, IntSize contextSize, ColorSpace, Format);
IntSize contextSize() const { return m_contextSize; }
void setContextSize(IntSize);
using namespace WebCore;
-inline std::unique_ptr<IOSurface> IOSurface::surfaceFromPool(IntSize size, IntSize contextSize, ColorSpace colorSpace)
+inline std::unique_ptr<IOSurface> IOSurface::surfaceFromPool(IntSize size, IntSize contextSize, ColorSpace colorSpace, Format pixelFormat)
{
- auto cachedSurface = IOSurfacePool::sharedPool().takeSurface(size, colorSpace);
+ auto cachedSurface = IOSurfacePool::sharedPool().takeSurface(size, colorSpace, pixelFormat);
if (!cachedSurface)
return nullptr;
std::unique_ptr<IOSurface> IOSurface::create(IntSize size, ColorSpace colorSpace, Format pixelFormat)
{
- // YUV422 IOSurfaces do not go in the pool.
- // FIXME: Want pooling of RGB10, RGB10A8.
- if (pixelFormat == Format::RGBA) {
- if (auto cachedSurface = surfaceFromPool(size, size, colorSpace))
- return cachedSurface;
- }
+ if (auto cachedSurface = surfaceFromPool(size, size, colorSpace, pixelFormat))
+ return cachedSurface;
return std::unique_ptr<IOSurface>(new IOSurface(size, colorSpace, pixelFormat));
}
-std::unique_ptr<IOSurface> IOSurface::create(IntSize size, IntSize contextSize, ColorSpace colorSpace)
+std::unique_ptr<IOSurface> IOSurface::create(IntSize size, IntSize contextSize, ColorSpace colorSpace, Format pixelFormat)
{
- if (auto cachedSurface = surfaceFromPool(size, contextSize, colorSpace))
+ if (auto cachedSurface = surfaceFromPool(size, contextSize, colorSpace, pixelFormat))
return cachedSurface;
- return std::unique_ptr<IOSurface>(new IOSurface(size, contextSize, colorSpace));
+ return std::unique_ptr<IOSurface>(new IOSurface(size, contextSize, colorSpace, pixelFormat));
}
std::unique_ptr<IOSurface> IOSurface::createFromSendRight(const MachSendRight& sendRight, ColorSpace colorSpace)
return surface;
}
+void IOSurface::moveToPool(std::unique_ptr<IOSurface>&& surface)
+{
+ IOSurfacePool::sharedPool().addSurface(WTF::move(surface));
+}
+
IOSurface::IOSurface(IntSize size, ColorSpace colorSpace, Format format)
: m_colorSpace(colorSpace)
, m_size(size)
NSLog(@"Surface creation failed for options %@", options);
}
-IOSurface::IOSurface(IntSize size, IntSize contextSize, ColorSpace colorSpace)
- : IOSurface(size, colorSpace, Format::RGBA)
+IOSurface::IOSurface(IntSize size, IntSize contextSize, ColorSpace colorSpace, Format pixelFormat)
+ : IOSurface(size, colorSpace, pixelFormat)
{
ASSERT(contextSize.width() <= size.width());
ASSERT(contextSize.height() <= size.height());
+2015-11-20 Simon Fraser <simon.fraser@apple.com>
+
+ Allow more buffer formats in the IOSurface pool
+ https://bugs.webkit.org/show_bug.cgi?id=151516
+
+ Reviewed by Tim Horton.
+
+ Have RemoteLayerBackingStore go through a static function on IOSurface to return
+ a surface to the pool, rather than knowing about IOSurfacePool directly.
+
+ * Shared/mac/RemoteLayerBackingStore.mm:
+ (WebKit::RemoteLayerBackingStore::Buffer::discard):
+
2015-11-20 Alex Christensen <achristensen@webkit.org>
Remove NETWORK_PROCESS compile flag
#import <QuartzCore/QuartzCore.h>
#import <WebCore/GraphicsContextCG.h>
#import <WebCore/IOSurface.h>
-#import <WebCore/IOSurfacePool.h>
#import <WebCore/MachSendRight.h>
#import <WebCore/QuartzCoreSPI.h>
#import <WebCore/WebLayer.h>
{
#if USE(IOSURFACE)
if (surface)
- IOSurfacePool::sharedPool().addSurface(WTF::move(surface));
+ IOSurface::moveToPool(WTF::move(surface));
isVolatile = false;
#endif
bitmap = nullptr;