Diff
Modified: branches/safari-601.1.46-branch/Source/WebCore/ChangeLog (192418 => 192419)
--- branches/safari-601.1.46-branch/Source/WebCore/ChangeLog 2015-11-13 17:02:44 UTC (rev 192418)
+++ branches/safari-601.1.46-branch/Source/WebCore/ChangeLog 2015-11-13 17:02:48 UTC (rev 192419)
@@ -1,3 +1,33 @@
+2015-11-12 Matthew Hanson <matthew_han...@apple.com>
+
+ Merge r190574. rdar://problem/22846841
+
+ 2015-10-05 Beth Dakin <bda...@apple.com>
+
+ Compress snapshots on iOS
+ https://bugs.webkit.org/show_bug.cgi?id=149814
+ -and corresponding-
+ rdar://problem/22976230
+
+ Reviewed by Simon Fraser.
+
+ Though the default is still RGBA, it is now possible to create an IOSurface
+ that uses the YUV422 pixel format.
+ * platform/graphics/cocoa/IOSurface.h:
+ * platform/graphics/cocoa/IOSurface.mm:
+ (IOSurface::surfaceFromPool):
+ (IOSurface::create):
+ (IOSurface::createFromImage):
+ (IOSurface::IOSurface):
+ (IOSurface::releaseGraphicsContext):
+
+ In order to have a YUV IOSurface, we actually have to create an RGBA surface
+ first and then convert it to YUV, so this class method will handle that.
+ (IOSurface::convertToFormat):
+
+ Necessary SPI.
+ * platform/spi/cocoa/IOSurfaceSPI.h:
+
2015-10-29 Lucas Forschler <lforsch...@apple.com>
Merge r191706. rdar://problem/23319282
Modified: branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.h (192418 => 192419)
--- branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.h 2015-11-13 17:02:44 UTC (rev 192418)
+++ branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.h 2015-11-13 17:02:48 UTC (rev 192419)
@@ -38,7 +38,14 @@
class IOSurface final {
public:
- WEBCORE_EXPORT static std::unique_ptr<IOSurface> create(IntSize, ColorSpace);
+ enum class Format {
+ RGBA,
+#if PLATFORM(IOS)
+ YUV422
+#endif
+ };
+
+ 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> createFromSendRight(const MachSendRight&, ColorSpace);
static std::unique_ptr<IOSurface> createFromSurface(IOSurfaceRef, ColorSpace);
@@ -73,6 +80,7 @@
IntSize size() const { return m_size; }
size_t totalBytes() const { return m_totalBytes; }
ColorSpace colorSpace() const { return m_colorSpace; }
+ Format format() const { return m_format; }
WEBCORE_EXPORT bool isInUse() const;
@@ -80,8 +88,12 @@
// an accurate result from isInUse(), it needs to be released.
WEBCORE_EXPORT void releaseGraphicsContext();
+#if PLATFORM(IOS)
+ WEBCORE_EXPORT static void convertToFormat(std::unique_ptr<WebCore::IOSurface>&& inSurface, Format, std::function<void(std::unique_ptr<WebCore::IOSurface>)>);
+#endif
+
private:
- IOSurface(IntSize, ColorSpace);
+ IOSurface(IntSize, ColorSpace, Format);
IOSurface(IntSize, IntSize contextSize, ColorSpace);
IOSurface(IOSurfaceRef, ColorSpace);
@@ -90,6 +102,7 @@
void setContextSize(IntSize);
ColorSpace m_colorSpace;
+ Format m_format;
IntSize m_size;
IntSize m_contextSize;
size_t m_totalBytes;
Modified: branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.mm (192418 => 192419)
--- branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.mm 2015-11-13 17:02:44 UTC (rev 192418)
+++ branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.mm 2015-11-13 17:02:48 UTC (rev 192419)
@@ -51,11 +51,15 @@
return cachedSurface;
}
-std::unique_ptr<IOSurface> IOSurface::create(IntSize size, ColorSpace colorSpace)
+std::unique_ptr<IOSurface> IOSurface::create(IntSize size, ColorSpace colorSpace, Format pixelFormat)
{
- if (auto cachedSurface = surfaceFromPool(size, size, colorSpace))
- return cachedSurface;
- return std::unique_ptr<IOSurface>(new IOSurface(size, colorSpace));
+ // YUV422 IOSurfaces do not go in the pool.
+ if (pixelFormat == Format::RGBA) {
+ if (auto cachedSurface = surfaceFromPool(size, size, colorSpace))
+ return cachedSurface;
+ }
+
+ return std::unique_ptr<IOSurface>(new IOSurface(size, colorSpace, pixelFormat));
}
std::unique_ptr<IOSurface> IOSurface::create(IntSize size, IntSize contextSize, ColorSpace colorSpace)
@@ -92,17 +96,30 @@
return surface;
}
-IOSurface::IOSurface(IntSize size, ColorSpace colorSpace)
+IOSurface::IOSurface(IntSize size, ColorSpace colorSpace, Format format)
: m_colorSpace(colorSpace)
+ , m_format(format)
, m_size(size)
, m_contextSize(size)
{
unsigned pixelFormat = 'BGRA';
+ unsigned bytesPerPixel = 4;
unsigned bytesPerElement = 4;
+ unsigned elementWidth = 1;
+
+#if PLATFORM(IOS)
+ if (format == Format::YUV422) {
+ pixelFormat = 'yuvf';
+ bytesPerPixel = 2;
+ elementWidth = 2;
+ bytesPerElement = 4;
+ }
+#endif
+
int width = size.width();
int height = size.height();
- size_t bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * bytesPerElement);
+ size_t bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * bytesPerPixel);
ASSERT(bytesPerRow);
m_totalBytes = IOSurfaceAlignProperty(kIOSurfaceAllocSize, height * bytesPerRow);
@@ -116,15 +133,17 @@
(id)kIOSurfaceBytesPerRow: @(bytesPerRow),
(id)kIOSurfaceAllocSize: @(m_totalBytes),
#if PLATFORM(IOS)
- (id)kIOSurfaceCacheMode: @(kIOMapWriteCombineCache)
+ (id)kIOSurfaceCacheMode: @(kIOMapWriteCombineCache),
#endif
+ (id)kIOSurfaceElementWidth: @(elementWidth),
+ (id)kIOSurfaceElementHeight: @(1)
};
m_surface = adoptCF(IOSurfaceCreate((CFDictionaryRef)options));
}
IOSurface::IOSurface(IntSize size, IntSize contextSize, ColorSpace colorSpace)
- : IOSurface(size, colorSpace)
+ : IOSurface(size, colorSpace, Format::RGBA)
{
ASSERT(contextSize.width() <= size.width());
ASSERT(contextSize.height() <= size.height());
@@ -133,6 +152,7 @@
IOSurface::IOSurface(IOSurfaceRef surface, ColorSpace colorSpace)
: m_colorSpace(colorSpace)
+ , m_format(Format::RGBA)
, m_surface(surface)
{
m_size = IntSize(IOSurfaceGetWidth(surface), IOSurfaceGetHeight(surface));
@@ -228,4 +248,39 @@
m_cgContext = nullptr;
}
+#if PLATFORM(IOS)
+ void IOSurface::convertToFormat(std::unique_ptr<WebCore::IOSurface>&& inSurface, Format format, std::function<void(std::unique_ptr<WebCore::IOSurface>)> callback)
+{
+ static IOSurfaceAcceleratorRef accelerator;
+ if (!accelerator) {
+ IOSurfaceAcceleratorCreate(nullptr, nullptr, &accelerator);
+
+ auto runLoopSource = IOSurfaceAcceleratorGetRunLoopSource(accelerator);
+ CFRunLoopAddSource(CFRunLoopGetMain(), runLoopSource, kCFRunLoopDefaultMode);
+ }
+
+ if (inSurface->format() == format) {
+ callback(WTF::move(inSurface));
+ return;
+ }
+
+ auto destinationSurface = IOSurface::create(inSurface->size(), inSurface->colorSpace(), format);
+ IOSurfaceRef destinationIOSurfaceRef = destinationSurface->surface();
+
+ IOSurfaceAcceleratorCompletion completion;
+ completion.completionRefCon = new std::function<void(std::unique_ptr<IOSurface>)> (WTF::move(callback));
+ completion.completionRefCon2 = destinationSurface.release();
+ completion.completionCallback = [](void *completionRefCon, IOReturn, void * completionRefCon2) {
+ auto* callback = static_cast<std::function<void(std::unique_ptr<WebCore::IOSurface>)>*>(completionRefCon);
+ auto destinationSurface = std::unique_ptr<IOSurface>(static_cast<IOSurface*>(completionRefCon2));
+
+ (*callback)(WTF::move(destinationSurface));
+ delete callback;
+ };
+
+ IOReturn ret = IOSurfaceAcceleratorTransformSurface(accelerator, inSurface->surface(), destinationIOSurfaceRef, nullptr, nullptr, &completion, nullptr, nullptr);
+ ASSERT_UNUSED(ret, ret == kIOReturnSuccess);
+}
+#endif // PLATFORM(IOS)
+
#endif // USE(IOSURFACE)
Modified: branches/safari-601.1.46-branch/Source/WebCore/platform/spi/cocoa/IOSurfaceSPI.h (192418 => 192419)
--- branches/safari-601.1.46-branch/Source/WebCore/platform/spi/cocoa/IOSurfaceSPI.h 2015-11-13 17:02:44 UTC (rev 192418)
+++ branches/safari-601.1.46-branch/Source/WebCore/platform/spi/cocoa/IOSurfaceSPI.h 2015-11-13 17:02:48 UTC (rev 192419)
@@ -94,6 +94,35 @@
WTF_EXTERN_C_END
-#endif
+#if PLATFORM(IOS)
+#if USE(APPLE_INTERNAL_SDK)
+#import <IOSurfaceAccelerator/IOSurfaceAccelerator.h>
+
+#else
+
+typedef struct __IOSurfaceAccelerator *IOSurfaceAcceleratorRef;
+
+WTF_EXTERN_C_BEGIN
+
+IOReturn IOSurfaceAcceleratorCreate(CFAllocatorRef allocator, CFDictionaryRef properties, IOSurfaceAcceleratorRef* acceleratorOut);
+CFRunLoopSourceRef IOSurfaceAcceleratorGetRunLoopSource(IOSurfaceAcceleratorRef accelerator);
+
+typedef void (*IOSurfaceAcceleratorCompletionCallback)(void* completionRefCon, IOReturn status, void* completionRefCon2);
+
+typedef struct IOSurfaceAcceleratorCompletion {
+ IOSurfaceAcceleratorCompletionCallback completionCallback;
+ void* completionRefCon;
+ void* completionRefCon2;
+} IOSurfaceAcceleratorCompletion;
+
+IOReturn IOSurfaceAcceleratorTransformSurface(IOSurfaceAcceleratorRef accelerator, IOSurfaceRef sourceBuffer, IOSurfaceRef destinationBuffer, CFDictionaryRef options, void* pCropRectangles, IOSurfaceAcceleratorCompletion* pCompletion, void* pSwap, uint32_t* pCommandID);
+
+WTF_EXTERN_C_END
+
+#endif // USE(APPLE_INTERNAL_SDK)
+#endif // PLATFORM(IOS)
+
+#endif // !PLATFORM(IOS_SIMULATOR)
+
#endif // IOSurfaceSPI_h
Modified: branches/safari-601.1.46-branch/Source/WebKit2/ChangeLog (192418 => 192419)
--- branches/safari-601.1.46-branch/Source/WebKit2/ChangeLog 2015-11-13 17:02:44 UTC (rev 192418)
+++ branches/safari-601.1.46-branch/Source/WebKit2/ChangeLog 2015-11-13 17:02:48 UTC (rev 192419)
@@ -1,5 +1,28 @@
2015-11-12 Matthew Hanson <matthew_han...@apple.com>
+ Merge r190574. rdar://problem/22846841
+
+ 2015-10-05 Beth Dakin <bda...@apple.com>
+
+ Compress snapshots on iOS
+ https://bugs.webkit.org/show_bug.cgi?id=149814
+ -and corresponding-
+ rdar://problem/22976230
+
+ Reviewed by Simon Fraser.
+
+ Compress the snapshot.
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView _takeViewSnapshot]):
+
+ Since the snapshots are converted to YUV asynchronously, it is possible to
+ get here and have a snapshot that does not yet have an image, so we have to
+ relax this constraint.
+ * UIProcess/mac/ViewSnapshotStore.mm:
+ (WebKit::ViewSnapshotStore::recordSnapshot):
+
+2015-11-12 Matthew Hanson <matthew_han...@apple.com>
+
Merge r189635. rdar://problem/22846841
2015-09-11 Beth Dakin <bda...@apple.com>
Modified: branches/safari-601.1.46-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (192418 => 192419)
--- branches/safari-601.1.46-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2015-11-13 17:02:44 UTC (rev 192418)
+++ branches/safari-601.1.46-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2015-11-13 17:02:48 UTC (rev 192419)
@@ -1114,7 +1114,12 @@
auto surface = WebCore::IOSurface::create(WebCore::expandedIntSize(snapshotSize), WebCore::ColorSpaceDeviceRGB);
CARenderServerRenderLayerWithTransform(MACH_PORT_NULL, self.layer.context.contextId, reinterpret_cast<uint64_t>(self.layer), surface->surface(), 0, 0, &transform);
- return WebKit::ViewSnapshot::create(nullptr);
+ RefPtr<WebKit::ViewSnapshot> viewSnapshot = WebKit::ViewSnapshot::create(nullptr);
+ WebCore::IOSurface::convertToFormat(WTF::move(surface), WebCore::IOSurface::Format::YUV422, [viewSnapshot](std::unique_ptr<WebCore::IOSurface> convertedSurface) {
+ viewSnapshot->setSurface(WTF::move(convertedSurface));
+ });
+
+ return viewSnapshot;
#else
uint32_t slotID = [WebKit::ViewSnapshotStore::snapshottingContext() createImageSlot:snapshotSize hasAlpha:YES];
Modified: branches/safari-601.1.46-branch/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm (192418 => 192419)
--- branches/safari-601.1.46-branch/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm 2015-11-13 17:02:44 UTC (rev 192418)
+++ branches/safari-601.1.46-branch/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm 2015-11-13 17:02:48 UTC (rev 192419)
@@ -115,7 +115,7 @@
webPageProxy.willRecordNavigationSnapshot(item);
RefPtr<ViewSnapshot> snapshot = webPageProxy.takeViewSnapshot();
- if (!snapshot || !snapshot->hasImage())
+ if (!snapshot)
return;
snapshot->setRenderTreeSize(webPageProxy.renderTreeSize());