Adopt WebCore::IOSurface in ImageBuffer
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Feb 2015 23:05:12 +0000 (23:05 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Feb 2015 23:05:12 +0000 (23:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141751

Reviewed by Simon Fraser.

* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::createIOSurface): Deleted.
(WebCore::ImageBuffer::ImageBuffer):
Make use of cachedCGColorSpace.
Make use of WebCore::IOSurface.
Remove the unused size argument from ImageBufferDataCG.
Clear the IOSurface once we've allocated it; WebCore::IOSurface doesn't
do this for us, unlike wkIOSurfaceContextCreate.
Apply the flipping and scale factor to whichever context we made.
We don't need to setIsAcceleratedContext anymore because it's always
false for software contexts, and WebCore::IOSurface will set it for
any accelerated contexts.

(WebCore::ImageBuffer::context):
If we are IOSurface-backed, return WebCore::IOSurface's GraphicsContext.

(WebCore::ImageBuffer::flushContext):
Make use of context(); m_context is now null for accelerated ImageBuffers.

(WebCore::ImageBuffer::copyNativeImage):
Adopt in-line with the Create functions for clarity. Make use of
IOSurface::createImage instead of wkIOSurfaceContextCreateImage.

(WebCore::ImageBuffer::draw):
(WebCore::ImageBuffer::drawPattern):
(WebCore::ImageBuffer::getUnmultipliedImageData):
(WebCore::ImageBuffer::getPremultipliedImageData):
(WebCore::ImageBuffer::putByteArray):
(WebCore::ImageBuffer::toDataURL):
Make use of context(); m_context is now null for accelerated ImageBuffers.

* platform/graphics/cg/ImageBufferDataCG.cpp:
(WebCore::ImageBufferData::ImageBufferData):
Indentation fix, and use nullptr.

(WebCore::convertScanline):
Grammar fix (is -> are).

(WebCore::ImageBufferData::getData):
(WebCore::ImageBufferData::putData):
Grab the IOSurfaceRef from the IOSurface wrapper. Eventually these things
should be made more convenient by the wrapper.

* platform/graphics/cg/ImageBufferDataCG.h:
Drop the unused size argument from the constructor.
Reorganize and label the various members which are only used
for a particular type of ImageBufferDataCG.

* platform/graphics/cocoa/IOSurface.mm:
(IOSurface::ensureGraphicsContext):
IOSurface-backed GraphicsContexts are always considered accelerated.

(IOSurface::create):
(IOSurface::IOSurface):
Add a constructor that take an extra size to use when making the CGContext;
it can only be less than the actual backing IOSurface size.
This is needed for r160121.

* platform/ios/WebCoreSystemInterfaceIOS.mm:
* platform/mac/WebCoreSystemInterface.h:
* platform/mac/WebCoreSystemInterface.mm:
Remove old WKSI IOSurface-related functions.

* WebCoreSupport/WebSystemInterface.mm:
(InitWebCoreSystemInterface):
Remove old WKSI IOSurface-related functions.

* WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
(InitWebCoreSystemInterface):
Remove old WKSI IOSurface-related functions.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180308 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp
Source/WebCore/platform/graphics/cg/ImageBufferDataCG.cpp
Source/WebCore/platform/graphics/cg/ImageBufferDataCG.h
Source/WebCore/platform/graphics/cocoa/IOSurface.h
Source/WebCore/platform/graphics/cocoa/IOSurface.mm
Source/WebCore/platform/ios/WebCoreSystemInterfaceIOS.mm
Source/WebCore/platform/mac/WebCoreSystemInterface.h
Source/WebCore/platform/mac/WebCoreSystemInterface.mm
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm

index a983172..a9a1d15 100644 (file)
@@ -1,3 +1,73 @@
+2015-02-18  Timothy Horton  <timothy_horton@apple.com>
+
+        Adopt WebCore::IOSurface in ImageBuffer
+        https://bugs.webkit.org/show_bug.cgi?id=141751
+
+        Reviewed by Simon Fraser.
+
+        * platform/graphics/cg/ImageBufferCG.cpp:
+        (WebCore::createIOSurface): Deleted.
+        (WebCore::ImageBuffer::ImageBuffer):
+        Make use of cachedCGColorSpace.
+        Make use of WebCore::IOSurface.
+        Remove the unused size argument from ImageBufferDataCG.
+        Clear the IOSurface once we've allocated it; WebCore::IOSurface doesn't
+        do this for us, unlike wkIOSurfaceContextCreate.
+        Apply the flipping and scale factor to whichever context we made.
+        We don't need to setIsAcceleratedContext anymore because it's always
+        false for software contexts, and WebCore::IOSurface will set it for
+        any accelerated contexts.
+
+        (WebCore::ImageBuffer::context):
+        If we are IOSurface-backed, return WebCore::IOSurface's GraphicsContext.
+
+        (WebCore::ImageBuffer::flushContext):
+        Make use of context(); m_context is now null for accelerated ImageBuffers.
+
+        (WebCore::ImageBuffer::copyNativeImage):
+        Adopt in-line with the Create functions for clarity. Make use of
+        IOSurface::createImage instead of wkIOSurfaceContextCreateImage.
+
+        (WebCore::ImageBuffer::draw):
+        (WebCore::ImageBuffer::drawPattern):
+        (WebCore::ImageBuffer::getUnmultipliedImageData):
+        (WebCore::ImageBuffer::getPremultipliedImageData):
+        (WebCore::ImageBuffer::putByteArray):
+        (WebCore::ImageBuffer::toDataURL):
+        Make use of context(); m_context is now null for accelerated ImageBuffers.
+
+        * platform/graphics/cg/ImageBufferDataCG.cpp:
+        (WebCore::ImageBufferData::ImageBufferData):
+        Indentation fix, and use nullptr.
+
+        (WebCore::convertScanline):
+        Grammar fix (is -> are).
+
+        (WebCore::ImageBufferData::getData):
+        (WebCore::ImageBufferData::putData):
+        Grab the IOSurfaceRef from the IOSurface wrapper. Eventually these things
+        should be made more convenient by the wrapper.
+
+        * platform/graphics/cg/ImageBufferDataCG.h:
+        Drop the unused size argument from the constructor.
+        Reorganize and label the various members which are only used
+        for a particular type of ImageBufferDataCG.
+
+        * platform/graphics/cocoa/IOSurface.mm:
+        (IOSurface::ensureGraphicsContext):
+        IOSurface-backed GraphicsContexts are always considered accelerated.
+
+        (IOSurface::create):
+        (IOSurface::IOSurface):
+        Add a constructor that take an extra size to use when making the CGContext;
+        it can only be less than the actual backing IOSurface size.
+        This is needed for r160121.
+
+        * platform/ios/WebCoreSystemInterfaceIOS.mm:
+        * platform/mac/WebCoreSystemInterface.h:
+        * platform/mac/WebCoreSystemInterface.mm:
+        Remove old WKSI IOSurface-related functions.
+
 2015-02-18  Alex Christensen  <achristensen@webkit.org>
 
         Prepare to use WEBCORE_EXPORT on Windows.
index f5825f5..e7f73f5 100644 (file)
 
 namespace WebCore {
 
-#if USE(IOSURFACE_CANVAS_BACKING_STORE)
-
-// FIXME: Adopt WebCore::IOSurface.
-static RetainPtr<IOSurfaceRef> createIOSurface(const IntSize& size)
-{
-    unsigned pixelFormat = 'BGRA';
-    unsigned bytesPerElement = 4;
-    int width = size.width();
-    int height = size.height();
-
-    unsigned long bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, size.width() * bytesPerElement);
-    if (!bytesPerRow)
-        return 0;
-
-    unsigned long allocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, size.height() * bytesPerRow);
-    if (!allocSize)
-        return 0;
-
-#if !PLATFORM(IOS)
-    const void* keys[6];
-    const void* values[6];
-#else
-    const void* keys[7];
-    const void* values[7];
-#endif
-    keys[0] = kIOSurfaceWidth;
-    values[0] = CFNumberCreate(0, kCFNumberIntType, &width);
-    keys[1] = kIOSurfaceHeight;
-    values[1] = CFNumberCreate(0, kCFNumberIntType, &height);
-    keys[2] = kIOSurfacePixelFormat;
-    values[2] = CFNumberCreate(0, kCFNumberIntType, &pixelFormat);
-    keys[3] = kIOSurfaceBytesPerElement;
-    values[3] = CFNumberCreate(0, kCFNumberIntType, &bytesPerElement);
-    keys[4] = kIOSurfaceBytesPerRow;
-    values[4] = CFNumberCreate(0, kCFNumberLongType, &bytesPerRow);
-    keys[5] = kIOSurfaceAllocSize;
-    values[5] = CFNumberCreate(0, kCFNumberLongType, &allocSize);
-#if PLATFORM(IOS)
-    keys[6] = kIOSurfaceCacheMode;
-    int cacheMode = kIOMapWriteCombineCache;
-    values[6] = CFNumberCreate(0, kCFNumberIntType, &cacheMode);
-#endif
-
-    RetainPtr<CFDictionaryRef> dict = adoptCF(CFDictionaryCreate(0, keys, values, WTF_ARRAY_LENGTH(values), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
-    for (unsigned i = 0; i < WTF_ARRAY_LENGTH(values); ++i)
-        CFRelease(values[i]);
-
-    return adoptCF(IOSurfaceCreate(dict.get()));
-}
-#endif
-
 static void releaseImageData(void*, const void* data, size_t)
 {
     fastFree(const_cast<void*>(data));
@@ -121,8 +70,7 @@ static FloatSize scaleSizeToUserSpace(const FloatSize& logicalSize, const IntSiz
 }
 
 ImageBuffer::ImageBuffer(const FloatSize& size, float resolutionScale, ColorSpace imageColorSpace, RenderingMode renderingMode, bool& success)
-    : m_data(IntSize(size)) // NOTE: The input here isn't important as ImageBufferDataCG's constructor just ignores it.
-    , m_logicalSize(size)
+    : m_logicalSize(size)
     , m_resolutionScale(resolutionScale)
 {
     float scaledWidth = ceilf(resolutionScale * size.width());
@@ -159,25 +107,18 @@ ImageBuffer::ImageBuffer(const FloatSize& size, float resolutionScale, ColorSpac
     ASSERT(renderingMode == Unaccelerated);
 #endif
 
-    switch (imageColorSpace) {
-    case ColorSpaceDeviceRGB:
-        m_data.m_colorSpace = deviceRGBColorSpaceRef();
-        break;
-    case ColorSpaceSRGB:
-        m_data.m_colorSpace = sRGBColorSpaceRef();
-        break;
-    case ColorSpaceLinearRGB:
-        m_data.m_colorSpace = linearRGBColorSpaceRef();
-        break;
-    }
+    m_data.m_colorSpace = cachedCGColorSpace(imageColorSpace);
 
     RetainPtr<CGContextRef> cgContext;
     if (accelerateRendering) {
 #if USE(IOSURFACE_CANVAS_BACKING_STORE)
-        m_data.m_surface = createIOSurface(m_data.m_backingStoreSize);
         FloatSize userBounds = scaleSizeToUserSpace(FloatSize(width.unsafeGet(), height.unsafeGet()), m_data.m_backingStoreSize, m_size);
-        cgContext = adoptCF(wkIOSurfaceContextCreate(m_data.m_surface.get(), userBounds.width(), userBounds.height(), m_data.m_colorSpace));
+        m_data.m_surface = IOSurface::create(m_data.m_backingStoreSize, IntSize(userBounds), imageColorSpace);
+        cgContext = m_data.m_surface->ensurePlatformContext();
+        if (cgContext)
+            CGContextClearRect(cgContext.get(), FloatRect(FloatPoint(), userBounds));
 #endif
+
         if (!cgContext)
             accelerateRendering = false; // If allocation fails, fall back to non-accelerated path.
     }
@@ -195,16 +136,17 @@ ImageBuffer::ImageBuffer(const FloatSize& size, float resolutionScale, ColorSpac
         cgContext = adoptCF(CGBitmapContextCreate(m_data.m_data, m_data.m_backingStoreSize.width(), m_data.m_backingStoreSize.height(), 8, m_data.m_bytesPerRow.unsafeGet(), m_data.m_colorSpace, m_data.m_bitmapInfo));
         // Create a live image that wraps the data.
         m_data.m_dataProvider = adoptCF(CGDataProviderCreateWithData(0, m_data.m_data, numBytes.unsafeGet(), releaseImageData));
+
+        if (!cgContext)
+            return;
+
+        m_context = adoptPtr(new GraphicsContext(cgContext.get()));
     }
 
-    if (!cgContext)
-        return;
+    context()->scale(FloatSize(1, -1));
+    context()->translate(0, -m_data.m_backingStoreSize.height());
+    context()->applyDeviceScaleFactor(m_resolutionScale);
 
-    m_context = adoptPtr(new GraphicsContext(cgContext.get()));
-    m_context->scale(FloatSize(1, -1));
-    m_context->translate(0, -m_data.m_backingStoreSize.height());
-    m_context->applyDeviceScaleFactor(m_resolutionScale);
-    m_context->setIsAcceleratedContext(accelerateRendering);
     success = true;
 }
 
@@ -214,12 +156,16 @@ ImageBuffer::~ImageBuffer()
 
 GraphicsContext* ImageBuffer::context() const
 {
+#if USE(IOSURFACE_CANVAS_BACKING_STORE)
+    if (m_data.m_surface)
+        return &m_data.m_surface->ensureGraphicsContext();
+#endif
     return m_context.get();
 }
 
 void ImageBuffer::flushContext() const
 {
-    CGContextFlush(m_context->platformContext());
+    CGContextFlush(context()->platformContext());
 }
 
 static RetainPtr<CGImageRef> createCroppedImageIfNecessary(CGImageRef image, const IntSize& bounds)
@@ -263,14 +209,14 @@ BackingStoreCopy ImageBuffer::fastCopyImageMode()
 
 RetainPtr<CGImageRef> ImageBuffer::copyNativeImage(BackingStoreCopy copyBehavior) const
 {
-    CGImageRef image = 0;
-    if (!m_context->isAcceleratedContext()) {
+    RetainPtr<CGImageRef> image;
+    if (!context()->isAcceleratedContext()) {
         switch (copyBehavior) {
         case DontCopyBackingStore:
-            image = CGImageCreate(m_data.m_backingStoreSize.width(), m_data.m_backingStoreSize.height(), 8, 32, m_data.m_bytesPerRow.unsafeGet(), m_data.m_colorSpace, m_data.m_bitmapInfo, m_data.m_dataProvider.get(), 0, true, kCGRenderingIntentDefault);
+            image = adoptCF(CGImageCreate(m_data.m_backingStoreSize.width(), m_data.m_backingStoreSize.height(), 8, 32, m_data.m_bytesPerRow.unsafeGet(), m_data.m_colorSpace, m_data.m_bitmapInfo, m_data.m_dataProvider.get(), 0, true, kCGRenderingIntentDefault));
             break;
         case CopyBackingStore:
-            image = CGBitmapContextCreateImage(context()->platformContext());
+            image = adoptCF(CGBitmapContextCreateImage(context()->platformContext()));
             break;
         default:
             ASSERT_NOT_REACHED();
@@ -279,19 +225,19 @@ RetainPtr<CGImageRef> ImageBuffer::copyNativeImage(BackingStoreCopy copyBehavior
     }
 #if USE(IOSURFACE_CANVAS_BACKING_STORE)
     else
-        image = wkIOSurfaceContextCreateImage(context()->platformContext());
+        image = m_data.m_surface->createImage();
 #endif
 
-    return adoptCF(image);
+    return image;
 }
 
 void ImageBuffer::draw(GraphicsContext* destContext, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode, bool useLowQualityScale)
 {
     UNUSED_PARAM(useLowQualityScale);
-    ColorSpace colorSpace = (destContext == m_context) ? ColorSpaceDeviceRGB : styleColorSpace;
+    ColorSpace colorSpace = (destContext == context()) ? ColorSpaceDeviceRGB : styleColorSpace;
 
     RetainPtr<CGImageRef> image;
-    if (destContext == m_context || destContext->isAcceleratedContext())
+    if (destContext == context() || destContext->isAcceleratedContext())
         image = copyNativeImage(CopyBackingStore); // Drawing into our own buffer, need to deep copy.
     else
         image = copyNativeImage(DontCopyBackingStore);
@@ -306,8 +252,8 @@ void ImageBuffer::drawPattern(GraphicsContext* destContext, const FloatRect& src
     FloatRect adjustedSrcRect = srcRect;
     adjustedSrcRect.scale(m_resolutionScale, m_resolutionScale);
 
-    if (!m_context->isAcceleratedContext()) {
-        if (destContext == m_context || destContext->isAcceleratedContext()) {
+    if (!context()->isAcceleratedContext()) {
+        if (destContext == context() || destContext->isAcceleratedContext()) {
             RefPtr<Image> copy = copyImage(CopyBackingStore); // Drawing into our own buffer, need to deep copy.
             copy->drawPattern(destContext, adjustedSrcRect, patternTransform, phase, styleColorSpace, op, destRect, blendMode);
         } else {
@@ -337,31 +283,31 @@ void ImageBuffer::clip(GraphicsContext* contextToClip, const FloatRect& rect) co
 
 PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem coordinateSystem) const
 {
-    if (m_context->isAcceleratedContext())
+    if (context()->isAcceleratedContext())
         flushContext();
 
     IntRect srcRect = rect;
     if (coordinateSystem == LogicalCoordinateSystem)
         srcRect.scale(m_resolutionScale);
 
-    return m_data.getData(srcRect, internalSize(), m_context->isAcceleratedContext(), true, 1);
+    return m_data.getData(srcRect, internalSize(), context()->isAcceleratedContext(), true, 1);
 }
 
 PassRefPtr<Uint8ClampedArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem coordinateSystem) const
 {
-    if (m_context->isAcceleratedContext())
+    if (context()->isAcceleratedContext())
         flushContext();
 
     IntRect srcRect = rect;
     if (coordinateSystem == LogicalCoordinateSystem)
         srcRect.scale(m_resolutionScale);
 
-    return m_data.getData(srcRect, internalSize(), m_context->isAcceleratedContext(), false, 1);
+    return m_data.getData(srcRect, internalSize(), context()->isAcceleratedContext(), false, 1);
 }
 
 void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem coordinateSystem)
 {
-    if (!m_context->isAcceleratedContext()) {
+    if (!context()->isAcceleratedContext()) {
         IntRect scaledSourceRect = sourceRect;
         IntSize scaledSourceSize = sourceSize;
         if (coordinateSystem == LogicalCoordinateSystem) {
@@ -484,7 +430,7 @@ String ImageBuffer::toDataURL(const String& mimeType, const double* quality, Coo
 {
     ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
 
-    if (m_context->isAcceleratedContext())
+    if (context()->isAcceleratedContext())
         flushContext();
 
     RetainPtr<CFStringRef> uti = utiFromMIMEType(mimeType);
index 822be7f..ad3fed6 100644 (file)
@@ -35,6 +35,7 @@
 #endif
 
 #if USE(IOSURFACE_CANVAS_BACKING_STORE)
+#include "IOSurface.h"
 #include "IOSurfaceSPI.h"
 #include <dispatch/dispatch.h>
 #endif
@@ -54,10 +55,10 @@ struct ScanlineData {
 
 namespace WebCore {
 
-ImageBufferData::ImageBufferData(const IntSize&)
-: m_data(0)
+ImageBufferData::ImageBufferData()
+    : m_data(nullptr)
 #if USE(IOSURFACE_CANVAS_BACKING_STORE)
-, m_surface(0)
+    , m_surface(nullptr)
 #endif
 {
 }
@@ -89,7 +90,7 @@ static void convertScanline(void* data, size_t tileNumber, bool premultiply)
             return;
     }
 
-    // Swap channels 1 and 3, to convert BGRA<->RGBA. IOSurfaces is BGRA, ImageData expects RGBA.
+    // Swap channels 1 and 3, to convert BGRA<->RGBA. IOSurfaces are BGRA, ImageData expects RGBA.
     const uint8_t map[4] = { 2, 1, 0, 3 };
     vImagePermuteChannels_ARGB8888(&dest, &dest, map, kvImageDoNotTile);
 }
@@ -269,7 +270,8 @@ PassRefPtr<Uint8ClampedArray> ImageBufferData::getData(const IntRect& rect, cons
         }
     } else {
 #if USE(IOSURFACE_CANVAS_BACKING_STORE)
-        IOSurfaceRef surface = m_surface.get();
+        // FIXME: WebCore::IOSurface should have a locking RAII object and base-address getter.
+        IOSurfaceRef surface = m_surface->surface();
         IOSurfaceLock(surface, kIOSurfaceLockReadOnly, 0);
         srcBytesPerRow = IOSurfaceGetBytesPerRow(surface);
         srcRows = (unsigned char*)(IOSurfaceGetBaseAddress(surface)) + originy * srcBytesPerRow + originx * 4;
@@ -513,7 +515,7 @@ void ImageBufferData::putData(Uint8ClampedArray*& source, const IntSize& sourceS
         }
     } else {
 #if USE(IOSURFACE_CANVAS_BACKING_STORE)
-        IOSurfaceRef surface = m_surface.get();
+        IOSurfaceRef surface = m_surface->surface();
         IOSurfaceLock(surface, 0, 0);
         destBytesPerRow = IOSurfaceGetBytesPerRow(surface);
         destRows = (unsigned char*)(IOSurfaceGetBaseAddress(surface)) + (desty * destBytesPerRow + destx * 4).unsafeGet();
index f36135a..cd82914 100644 (file)
@@ -43,20 +43,26 @@ typedef uint32_t CGBitmapInfo;
 
 namespace WebCore {
 
+class IOSurface;
 class IntSize;
 
 class ImageBufferData {
 public:
-    ImageBufferData(const IntSize&);
+    ImageBufferData();
 
+    IntSize m_backingStoreSize;
+    Checked<unsigned, RecordOverflow> m_bytesPerRow;
+    CGColorSpaceRef m_colorSpace;
+
+    // Only for Software ImageBuffers.
     void* m_data;
-    
     RetainPtr<CGDataProviderRef> m_dataProvider;
     CGBitmapInfo m_bitmapInfo;
-    Checked<unsigned, RecordOverflow> m_bytesPerRow;
-    CGColorSpaceRef m_colorSpace;
-    RetainPtr<IOSurfaceRef> m_surface;
-    IntSize m_backingStoreSize;
+
+#if WTF_USE_IOSURFACE_CANVAS_BACKING_STORE
+    // Only for Accelerated ImageBuffers.
+    std::unique_ptr<IOSurface> m_surface;
+#endif
 
     PassRefPtr<Uint8ClampedArray> getData(const IntRect&, const IntSize&, bool accelerateRendering, bool unmultiplied, float resolutionScale) const;
     void putData(Uint8ClampedArray*& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize&, bool accelerateRendering, bool unmultiplied, float resolutionScale);
index 0d132fe..e752a26 100644 (file)
@@ -39,6 +39,7 @@ class MachSendRight;
 class IOSurface final {
 public:
     WEBCORE_EXPORT static std::unique_ptr<IOSurface> create(IntSize, ColorSpace);
+    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);
     WEBCORE_EXPORT static std::unique_ptr<IOSurface> createFromImage(CGImageRef);
@@ -81,10 +82,12 @@ public:
 
 private:
     IOSurface(IntSize, ColorSpace);
+    IOSurface(IntSize, IntSize contextSize, ColorSpace);
     IOSurface(IOSurfaceRef, ColorSpace);
 
     ColorSpace m_colorSpace;
     IntSize m_size;
+    IntSize m_contextSize;
     size_t m_totalBytes;
 
     OwnPtr<GraphicsContext> m_graphicsContext;
index 5c4ce2e..287c74d 100644 (file)
@@ -48,6 +48,12 @@ std::unique_ptr<IOSurface> IOSurface::create(IntSize size, ColorSpace colorSpace
     return std::unique_ptr<IOSurface>(new IOSurface(size, colorSpace));
 }
 
+std::unique_ptr<IOSurface> IOSurface::create(IntSize size, IntSize contextSize, ColorSpace colorSpace)
+{
+    // FIXME: We should be able to pull surfaces out of the IOSurfacePool and adjust their contextSize.
+    return std::unique_ptr<IOSurface>(new IOSurface(size, contextSize, colorSpace));
+}
+
 std::unique_ptr<IOSurface> IOSurface::createFromSendRight(const MachSendRight& sendRight, ColorSpace colorSpace)
 {
     RetainPtr<IOSurfaceRef> surface = adoptCF(IOSurfaceLookupFromMachPort(sendRight.sendRight()));
@@ -78,6 +84,7 @@ std::unique_ptr<IOSurface> IOSurface::createFromImage(CGImageRef image)
 IOSurface::IOSurface(IntSize size, ColorSpace colorSpace)
     : m_colorSpace(colorSpace)
     , m_size(size)
+    , m_contextSize(size)
 {
     unsigned pixelFormat = 'BGRA';
     unsigned bytesPerElement = 4;
@@ -105,6 +112,14 @@ IOSurface::IOSurface(IntSize size, ColorSpace colorSpace)
     m_surface = adoptCF(IOSurfaceCreate((CFDictionaryRef)options));
 }
 
+IOSurface::IOSurface(IntSize size, IntSize contextSize, ColorSpace colorSpace)
+    : IOSurface(size, colorSpace)
+{
+    ASSERT(contextSize.width() <= size.width());
+    ASSERT(contextSize.height() <= size.height());
+    m_contextSize = contextSize;
+}
+
 IOSurface::IOSurface(IOSurfaceRef surface, ColorSpace colorSpace)
     : m_colorSpace(colorSpace)
     , m_surface(surface)
@@ -136,7 +151,7 @@ CGContextRef IOSurface::ensurePlatformContext()
     CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
     size_t bitsPerComponent = 8;
     size_t bitsPerPixel = 32;
-    m_cgContext = adoptCF(CGIOSurfaceContextCreate(m_surface.get(), m_size.width(), m_size.height(), bitsPerComponent, bitsPerPixel, cachedCGColorSpace(m_colorSpace), bitmapInfo));
+    m_cgContext = adoptCF(CGIOSurfaceContextCreate(m_surface.get(), m_contextSize.width(), m_contextSize.height(), bitsPerComponent, bitsPerPixel, cachedCGColorSpace(m_colorSpace), bitmapInfo));
 
     return m_cgContext.get();
 }
@@ -147,6 +162,7 @@ GraphicsContext& IOSurface::ensureGraphicsContext()
         return *m_graphicsContext;
 
     m_graphicsContext = adoptPtr(new GraphicsContext(ensurePlatformContext()));
+    m_graphicsContext->setIsAcceleratedContext(true);
 
     return *m_graphicsContext;
 }
index 5db466b..c7e5970 100644 (file)
@@ -70,11 +70,6 @@ WEBCORE_EXPORT void (*wkSetCFURLRequestShouldContentSniff)(CFMutableURLRequestRe
 WEBCORE_EXPORT void (*wkSetRequestStorageSession)(CFURLStorageSessionRef, CFMutableURLRequestRef);
 #endif
 
-#if !PLATFORM(IOS_SIMULATOR)
-WEBCORE_EXPORT CGContextRef (*wkIOSurfaceContextCreate)(IOSurfaceRef surface, unsigned width, unsigned height, CGColorSpaceRef colorSpace);
-WEBCORE_EXPORT CGImageRef (*wkIOSurfaceContextCreateImage)(CGContextRef context);
-#endif // !PLATFORM(IOS_SIMULATOR)
-
 WEBCORE_EXPORT CFURLStorageSessionRef (*wkCreatePrivateStorageSession)(CFStringRef);
 WEBCORE_EXPORT NSURLRequest* (*wkCopyRequestWithStorageSession)(CFURLStorageSessionRef, NSURLRequest*);
 WEBCORE_EXPORT CFHTTPCookieStorageRef (*wkCopyHTTPCookieStorage)(CFURLStorageSessionRef);
index b7685d8..49d788f 100644 (file)
@@ -221,11 +221,6 @@ extern CFHTTPMessageRef (*wkCopyCONNECTProxyResponse)(CFReadStreamRef, CFURLRef
 extern void* wkGetHyphenationLocationBeforeIndex;
 #endif
 
-#if PLATFORM(COCOA) && USE(CA) && !PLATFORM(IOS_SIMULATOR)
-extern CGContextRef (*wkIOSurfaceContextCreate)(IOSurfaceRef surface, unsigned width, unsigned height, CGColorSpaceRef colorSpace);
-extern CGImageRef (*wkIOSurfaceContextCreateImage)(CGContextRef context);
-#endif
-
 #if !PLATFORM(IOS)
 extern int (*wkRecommendedScrollerStyle)(void);
 
index bdb990d..2942621 100644 (file)
@@ -102,9 +102,6 @@ void (*wkSetRequestStorageSession)(CFURLStorageSessionRef, CFMutableURLRequestRe
 
 void* wkGetHyphenationLocationBeforeIndex;
 
-CGContextRef (*wkIOSurfaceContextCreate)(IOSurfaceRef surface, unsigned width, unsigned height, CGColorSpaceRef colorSpace);
-CGImageRef (*wkIOSurfaceContextCreateImage)(CGContextRef context);
-
 int (*wkRecommendedScrollerStyle)(void);
 
 bool (*wkExecutableWasLinkedOnOrBeforeSnowLeopard)(void);
index 46409a2..8b66e39 100644 (file)
@@ -1,3 +1,14 @@
+2015-02-18  Timothy Horton  <timothy_horton@apple.com>
+
+        Adopt WebCore::IOSurface in ImageBuffer
+        https://bugs.webkit.org/show_bug.cgi?id=141751
+
+        Reviewed by Simon Fraser.
+
+        * WebCoreSupport/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface):
+        Remove old WKSI IOSurface-related functions.
+
 2015-02-18  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r180286.
index 0e67c8b..81dc6e8 100644 (file)
@@ -128,10 +128,6 @@ void InitWebCoreSystemInterface(void)
     INIT(GetMediaUIImageData);
 #endif
 
-#if !PLATFORM(IOS_SIMULATOR)
-    INIT(IOSurfaceContextCreate);
-    INIT(IOSurfaceContextCreateImage);
-#endif
 #if !PLATFORM(IOS)
     INIT(RecommendedScrollerStyle);
     INIT(ExecutableWasLinkedOnOrBeforeSnowLeopard);
index 818b5d8..fc98fe5 100644 (file)
@@ -1,3 +1,14 @@
+2015-02-18  Timothy Horton  <timothy_horton@apple.com>
+
+        Adopt WebCore::IOSurface in ImageBuffer
+        https://bugs.webkit.org/show_bug.cgi?id=141751
+
+        Reviewed by Simon Fraser.
+
+        * WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface):
+        Remove old WKSI IOSurface-related functions.
+
 2015-02-18  Beth Dakin  <bdakin@apple.com>
 
         iBooks immediate action blacklist should not even create the gesture recognizer
index a6a49b6..8c357a3 100644 (file)
@@ -119,10 +119,6 @@ void InitWebCoreSystemInterface(void)
         INIT(SetMetadataURL);
 #endif // !PLATFORM(IOS)
 
-#if !PLATFORM(IOS_SIMULATOR)
-        INIT(IOSurfaceContextCreate);
-        INIT(IOSurfaceContextCreateImage);
-#endif // !PLATFORM(IOS_SIMULATOR)
 #if !PLATFORM(IOS)
         INIT(RecommendedScrollerStyle);
         INIT(ExecutableWasLinkedOnOrBeforeSnowLeopard);