Title: [219146] trunk/Source/WebCore
Revision
219146
Author
[email protected]
Date
2017-07-05 12:56:23 -0700 (Wed, 05 Jul 2017)

Log Message

Add a logging channel for IOSurface allocations
https://bugs.webkit.org/show_bug.cgi?id=174167

Reviewed by Tim Horton.

Add an "IOSurface" log channel, make IOSurface TextStream-loggable, and log cached
and new IOSurface allocations. Do some namespace-related cleanup.

* platform/Logging.h:
* platform/graphics/cocoa/IOSurface.h:
* platform/graphics/cocoa/IOSurface.mm:
(WebCore::WebCore::IOSurface::create):
(WebCore::WebCore::IOSurface::surfaceID):
(WebCore::operator<<):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (219145 => 219146)


--- trunk/Source/WebCore/ChangeLog	2017-07-05 19:53:55 UTC (rev 219145)
+++ trunk/Source/WebCore/ChangeLog	2017-07-05 19:56:23 UTC (rev 219146)
@@ -1,3 +1,20 @@
+2017-07-05  Simon Fraser  <[email protected]>
+
+        Add a logging channel for IOSurface allocations
+        https://bugs.webkit.org/show_bug.cgi?id=174167
+
+        Reviewed by Tim Horton.
+
+        Add an "IOSurface" log channel, make IOSurface TextStream-loggable, and log cached
+        and new IOSurface allocations. Do some namespace-related cleanup.
+
+        * platform/Logging.h:
+        * platform/graphics/cocoa/IOSurface.h:
+        * platform/graphics/cocoa/IOSurface.mm:
+        (WebCore::WebCore::IOSurface::create):
+        (WebCore::WebCore::IOSurface::surfaceID):
+        (WebCore::operator<<):
+
 2017-07-05  Antti Koivisto  <[email protected]>
 
         Low memory notification shouldn't cause style recalc

Modified: trunk/Source/WebCore/platform/Logging.h (219145 => 219146)


--- trunk/Source/WebCore/platform/Logging.h	2017-07-05 19:53:55 UTC (rev 219145)
+++ trunk/Source/WebCore/platform/Logging.h	2017-07-05 19:56:23 UTC (rev 219146)
@@ -52,6 +52,7 @@
     M(Fullscreen) \
     M(Gamepad) \
     M(History) \
+    M(IOSurface) \
     M(IconDatabase) \
     M(Images) \
     M(IndexedDB) \

Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h (219145 => 219146)


--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2017-07-05 19:53:55 UTC (rev 219145)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2017-07-05 19:56:23 UTC (rev 219146)
@@ -23,8 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef IOSurface_h
-#define IOSurface_h
+#pragma once
 
 #if USE(IOSURFACE)
 
@@ -34,6 +33,7 @@
 namespace WebCore {
 
 class MachSendRight;
+class TextStream;
 
 class IOSurface final {
     WTF_MAKE_FAST_ALLOCATED;
@@ -87,6 +87,7 @@
     size_t totalBytes() const { return m_totalBytes; }
     CGColorSpaceRef colorSpace() const { return m_colorSpace.get(); }
     WEBCORE_EXPORT Format format() const;
+    IOSurfaceID surfaceID() const;
 
     WEBCORE_EXPORT bool isInUse() const;
 
@@ -118,8 +119,9 @@
     RetainPtr<IOSurfaceRef> m_surface;
 };
 
+WEBCORE_EXPORT TextStream& operator<<(TextStream&, const WebCore::IOSurface&);
+
 } // namespace WebCore
 
 #endif // USE(IOSURFACE)
 
-#endif // IOSurface_h

Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm (219145 => 219146)


--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm	2017-07-05 19:53:55 UTC (rev 219145)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm	2017-07-05 19:56:23 UTC (rev 219146)
@@ -36,6 +36,7 @@
 #import "ImageBufferDataCG.h"
 #import "Logging.h"
 #import "MachSendRight.h"
+#import "TextStream.h"
 #import <wtf/Assertions.h>
 #import <wtf/MathExtras.h>
 
@@ -44,9 +45,9 @@
 NSString * const WebIOSurfaceAcceleratorUnwireSurfaceKey = @"UnwireSurface";
 #endif
 
-using namespace WebCore;
+namespace WebCore {
 
-inline std::unique_ptr<WebCore::IOSurface> WebCore::IOSurface::surfaceFromPool(IntSize size, IntSize contextSize, CGColorSpaceRef colorSpace, Format pixelFormat)
+inline std::unique_ptr<IOSurface> IOSurface::surfaceFromPool(IntSize size, IntSize contextSize, CGColorSpaceRef colorSpace, Format pixelFormat)
 {
     auto cachedSurface = IOSurfacePool::sharedPool().takeSurface(size, colorSpace, pixelFormat);
     if (!cachedSurface)
@@ -56,34 +57,40 @@
     return cachedSurface;
 }
 
-std::unique_ptr<WebCore::IOSurface> WebCore::IOSurface::create(IntSize size, CGColorSpaceRef colorSpace, Format pixelFormat)
+std::unique_ptr<IOSurface> IOSurface::create(IntSize size, CGColorSpaceRef colorSpace, Format pixelFormat)
 {
     return IOSurface::create(size, size, colorSpace, pixelFormat);
 }
 
-std::unique_ptr<WebCore::IOSurface> WebCore::IOSurface::create(IntSize size, IntSize contextSize, CGColorSpaceRef colorSpace, Format pixelFormat)
+std::unique_ptr<IOSurface> IOSurface::create(IntSize size, IntSize contextSize, CGColorSpaceRef colorSpace, Format pixelFormat)
 {
-    if (auto cachedSurface = surfaceFromPool(size, contextSize, colorSpace, pixelFormat))
+    if (auto cachedSurface = surfaceFromPool(size, contextSize, colorSpace, pixelFormat)) {
+        LOG_WITH_STREAM(IOSurface, stream << "IOSurface::create took from pool: " << *cachedSurface);
         return cachedSurface;
+    }
     bool success = false;
     auto surface = std::unique_ptr<IOSurface>(new IOSurface(size, contextSize, colorSpace, pixelFormat, success));
-    if (!success)
+    if (!success) {
+        LOG(IOSurface, "IOSurface::create failed to create %dx%d surface", size.width(), size.height());
         return nullptr;
+    }
+
+    LOG_WITH_STREAM(IOSurface, stream << "IOSurface::create created " << *surface);
     return surface;
 }
 
-std::unique_ptr<WebCore::IOSurface> WebCore::IOSurface::createFromSendRight(const MachSendRight&& sendRight, CGColorSpaceRef colorSpace)
+std::unique_ptr<IOSurface> IOSurface::createFromSendRight(const MachSendRight&& sendRight, CGColorSpaceRef colorSpace)
 {
     auto surface = adoptCF(IOSurfaceLookupFromMachPort(sendRight.sendRight()));
     return IOSurface::createFromSurface(surface.get(), colorSpace);
 }
 
-std::unique_ptr<WebCore::IOSurface> WebCore::IOSurface::createFromSurface(IOSurfaceRef surface, CGColorSpaceRef colorSpace)
+std::unique_ptr<IOSurface> IOSurface::createFromSurface(IOSurfaceRef surface, CGColorSpaceRef colorSpace)
 {
     return std::unique_ptr<IOSurface>(new IOSurface(surface, colorSpace));
 }
 
-std::unique_ptr<WebCore::IOSurface> WebCore::IOSurface::createFromImage(CGImageRef image)
+std::unique_ptr<IOSurface> IOSurface::createFromImage(CGImageRef image)
 {
     if (!image)
         return nullptr;
@@ -100,12 +107,12 @@
     return surface;
 }
 
-void WebCore::IOSurface::moveToPool(std::unique_ptr<IOSurface>&& surface)
+void IOSurface::moveToPool(std::unique_ptr<IOSurface>&& surface)
 {
     IOSurfacePool::sharedPool().addSurface(WTFMove(surface));
 }
 
-std::unique_ptr<WebCore::IOSurface> WebCore::IOSurface::createFromImageBuffer(std::unique_ptr<ImageBuffer> imageBuffer)
+std::unique_ptr<IOSurface> IOSurface::createFromImageBuffer(std::unique_ptr<ImageBuffer> imageBuffer)
 {
     return WTFMove(imageBuffer->m_data.surface);
 }
@@ -182,7 +189,7 @@
 
 }
 
-WebCore::IOSurface::IOSurface(IntSize size, IntSize contextSize, CGColorSpaceRef colorSpace, Format format, bool& success)
+IOSurface::IOSurface(IntSize size, IntSize contextSize, CGColorSpaceRef colorSpace, Format format, bool& success)
     : m_colorSpace(colorSpace)
     , m_size(size)
     , m_contextSize(contextSize)
@@ -215,7 +222,7 @@
         RELEASE_LOG_ERROR(Layers, "Surface creation failed for size: (%d %d) and format: (%d)", size.width(), size.height(), format);
 }
 
-WebCore::IOSurface::IOSurface(IOSurfaceRef surface, CGColorSpaceRef colorSpace)
+IOSurface::IOSurface(IOSurfaceRef surface, CGColorSpaceRef colorSpace)
     : m_colorSpace(colorSpace)
     , m_surface(surface)
 {
@@ -223,7 +230,7 @@
     m_totalBytes = IOSurfaceGetAllocSize(surface);
 }
 
-IntSize WebCore::IOSurface::maximumSize()
+IntSize IOSurface::maximumSize()
 {
     IntSize maxSize(clampToInteger(IOSurfaceGetPropertyMaximum(kIOSurfaceWidth)), clampToInteger(IOSurfaceGetPropertyMaximum(kIOSurfaceHeight)));
 
@@ -241,22 +248,22 @@
     return maxSize.constrainedBetween({ iOSMaxSurfaceDimensionLowerBound, iOSMaxSurfaceDimensionLowerBound }, { iOSMaxSurfaceDimension, iOSMaxSurfaceDimension });
 }
 
-MachSendRight WebCore::IOSurface::createSendRight() const
+MachSendRight IOSurface::createSendRight() const
 {
     return MachSendRight::adopt(IOSurfaceCreateMachPort(m_surface.get()));
 }
 
-RetainPtr<CGImageRef> WebCore::IOSurface::createImage()
+RetainPtr<CGImageRef> IOSurface::createImage()
 {
     return adoptCF(CGIOSurfaceContextCreateImage(ensurePlatformContext()));
 }
 
-RetainPtr<CGImageRef> WebCore::IOSurface::sinkIntoImage(std::unique_ptr<IOSurface> surface)
+RetainPtr<CGImageRef> IOSurface::sinkIntoImage(std::unique_ptr<IOSurface> surface)
 {
     return adoptCF(CGIOSurfaceContextCreateImageReference(surface->ensurePlatformContext()));
 }
 
-void WebCore::IOSurface::setContextSize(IntSize contextSize)
+void IOSurface::setContextSize(IntSize contextSize)
 {
     if (contextSize == m_contextSize)
         return;
@@ -267,7 +274,7 @@
     m_contextSize = contextSize;
 }
 
-CGContextRef WebCore::IOSurface::ensurePlatformContext()
+CGContextRef IOSurface::ensurePlatformContext()
 {
     if (m_cgContext)
         return m_cgContext.get();
@@ -298,7 +305,7 @@
     return m_cgContext.get();
 }
 
-GraphicsContext& WebCore::IOSurface::ensureGraphicsContext()
+GraphicsContext& IOSurface::ensureGraphicsContext()
 {
     if (m_graphicsContext)
         return *m_graphicsContext;
@@ -309,7 +316,7 @@
     return *m_graphicsContext;
 }
 
-WebCore::IOSurface::SurfaceState WebCore::IOSurface::state() const
+IOSurface::SurfaceState IOSurface::state() const
 {
     uint32_t previousState = 0;
     IOReturn ret = IOSurfaceSetPurgeable(m_surface.get(), kIOSurfacePurgeableKeepCurrent, &previousState);
@@ -317,7 +324,7 @@
     return previousState == kIOSurfacePurgeableEmpty ? IOSurface::SurfaceState::Empty : IOSurface::SurfaceState::Valid;
 }
 
-bool WebCore::IOSurface::isVolatile() const
+bool IOSurface::isVolatile() const
 {
     uint32_t previousState = 0;
     IOReturn ret = IOSurfaceSetPurgeable(m_surface.get(), kIOSurfacePurgeableKeepCurrent, &previousState);
@@ -325,7 +332,7 @@
     return previousState != kIOSurfacePurgeableNonVolatile;
 }
 
-WebCore::IOSurface::SurfaceState WebCore::IOSurface::setIsVolatile(bool isVolatile)
+IOSurface::SurfaceState IOSurface::setIsVolatile(bool isVolatile)
 {
     uint32_t previousState = 0;
     IOReturn ret = IOSurfaceSetPurgeable(m_surface.get(), isVolatile ? kIOSurfacePurgeableVolatile : kIOSurfacePurgeableNonVolatile, &previousState);
@@ -337,7 +344,7 @@
     return IOSurface::SurfaceState::Valid;
 }
 
-WebCore::IOSurface::Format WebCore::IOSurface::format() const
+IOSurface::Format IOSurface::format() const
 {
     unsigned pixelFormat = IOSurfaceGetPixelFormat(m_surface.get());
     if (pixelFormat == 'BGRA')
@@ -356,12 +363,17 @@
     return Format::RGBA;
 }
 
-bool WebCore::IOSurface::isInUse() const
+IOSurfaceID IOSurface::surfaceID() const
 {
+    return IOSurfaceGetID(m_surface.get());
+}
+
+bool IOSurface::isInUse() const
+{
     return IOSurfaceIsInUse(m_surface.get());
 }
 
-void WebCore::IOSurface::releaseGraphicsContext()
+void IOSurface::releaseGraphicsContext()
 {
     m_graphicsContext = nullptr;
     m_cgContext = nullptr;
@@ -368,7 +380,7 @@
 }
 
 #if PLATFORM(IOS)
-bool WebCore::IOSurface::allowConversionFromFormatToFormat(Format sourceFormat, Format destFormat)
+bool IOSurface::allowConversionFromFormatToFormat(Format sourceFormat, Format destFormat)
 {
     if ((sourceFormat == Format::RGB10 || sourceFormat == Format::RGB10A8) && destFormat == Format::YUV422)
         return false;
@@ -376,7 +388,7 @@
     return true;
 }
 
-void WebCore::IOSurface::convertToFormat(std::unique_ptr<WebCore::IOSurface>&& inSurface, Format format, WTF::Function<void(std::unique_ptr<WebCore::IOSurface>)>&& callback)
+void IOSurface::convertToFormat(std::unique_ptr<IOSurface>&& inSurface, Format format, WTF::Function<void(std::unique_ptr<IOSurface>)>&& callback)
 {
     static IOSurfaceAcceleratorRef accelerator;
     if (!accelerator) {
@@ -399,11 +411,11 @@
 
     IOSurfaceRef destinationIOSurfaceRef = destinationSurface->surface();
     IOSurfaceAcceleratorCompletion completion;
-    completion.completionRefCon = new WTF::Function<void(std::unique_ptr<WebCore::IOSurface>)> (WTFMove(callback));
+    completion.completionRefCon = new WTF::Function<void(std::unique_ptr<IOSurface>)> (WTFMove(callback));
     completion.completionRefCon2 = destinationSurface.release();
     completion.completionCallback = [](void *completionRefCon, IOReturn, void * completionRefCon2) {
-        auto* callback = static_cast<WTF::Function<void(std::unique_ptr<WebCore::IOSurface>)>*>(completionRefCon);
-        auto destinationSurface = std::unique_ptr<WebCore::IOSurface>(static_cast<WebCore::IOSurface*>(completionRefCon2));
+        auto* callback = static_cast<WTF::Function<void(std::unique_ptr<IOSurface>)>*>(completionRefCon);
+        auto destinationSurface = std::unique_ptr<IOSurface>(static_cast<IOSurface*>(completionRefCon2));
         
         (*callback)(WTFMove(destinationSurface));
         delete callback;
@@ -416,4 +428,43 @@
 }
 #endif // PLATFORM(IOS)
 
+static TextStream& operator<<(TextStream& ts, IOSurface::Format format)
+{
+    switch (format) {
+    case IOSurface::Format::RGBA:
+        ts << "RGBA";
+        break;
+    case IOSurface::Format::YUV422:
+        ts << "YUV422";
+        break;
+    case IOSurface::Format::RGB10:
+        ts << "RGB10";
+        break;
+    case IOSurface::Format::RGB10A8:
+        ts << "RGB10A8";
+        break;
+    }
+    return ts;
+}
+
+static TextStream& operator<<(TextStream& ts, IOSurface::SurfaceState state)
+{
+    switch (state) {
+    case IOSurface::SurfaceState::Valid:
+        ts << "valid";
+        break;
+    case IOSurface::SurfaceState::Empty:
+        ts << "empty";
+        break;
+    }
+    return ts;
+}
+
+TextStream& operator<<(TextStream& ts, const IOSurface& surface)
+{
+    return ts << "IOSurface " << surface.surfaceID() << " size " << surface.size() << " format " << surface.format() << " state " << surface.state();
+}
+
+} // namespace WebCore
+
 #endif // USE(IOSURFACE)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to