Changeset 192689 in webkit


Ignore:
Timestamp:
Nov 20, 2015 12:05:05 PM (8 years ago)
Author:
Simon Fraser
Message:

Back-buffer to front-buffer copy fails for some buffer formats
https://bugs.webkit.org/show_bug.cgi?id=151475
rdar://problem/23617899

Reviewed by Tim Horton.

Source/WebCore:

Fix some fo the bitsPerComponent/bitsPerPixel options in IOSurface::ensurePlatformContext()
for RGB10 buffers. Fix IOSurface::format() to return the new formats.

Implement IOSurface::copyToSurface(), which does a synchronous copy between
surfaces.

  • platform/graphics/cocoa/IOSurface.h:
  • platform/graphics/cocoa/IOSurface.mm:

(IOSurface::create):
(IOSurface::ensurePlatformContext):
(IOSurface::format):
(IOSurface::copyToSurface):

Source/WebKit2:

When displaying RemoteLayerBackingStore, we copy the back buffer to the front
buffer before painting the updated regions. For buffers using Format::RGB10A8,
the CGImage-based copy fails, so in this case, use IOSurface::copyToSurface().

Reorganized RemoteLayerBackingStore::drawInContext() to make this a bit easier
to understand. First, we either copy the entire surface over, or paint the backImage.
Then we clip to the dirty rects, and clear them, then paint the layer contents.

  • Shared/mac/RemoteLayerBackingStore.mm:

(WebKit::RemoteLayerBackingStore::display):
(WebKit::RemoteLayerBackingStore::drawInContext):

Location:
trunk/Source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r192688 r192689  
     12015-11-19  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Back-buffer to front-buffer copy fails for some buffer formats
     4        https://bugs.webkit.org/show_bug.cgi?id=151475
     5        rdar://problem/23617899
     6
     7        Reviewed by Tim Horton.
     8       
     9        Fix some fo the bitsPerComponent/bitsPerPixel options in IOSurface::ensurePlatformContext()
     10        for RGB10 buffers. Fix IOSurface::format() to return the new formats.
     11       
     12        Implement IOSurface::copyToSurface(), which does a synchronous copy between
     13        surfaces.
     14
     15        * platform/graphics/cocoa/IOSurface.h:
     16        * platform/graphics/cocoa/IOSurface.mm:
     17        (IOSurface::create):
     18        (IOSurface::ensurePlatformContext):
     19        (IOSurface::format):
     20        (IOSurface::copyToSurface):
     21
    1222015-11-20  Zalan Bujtas  <zalan@apple.com>
    223
  • trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h

    r192284 r192689  
    8181    size_t totalBytes() const { return m_totalBytes; }
    8282    ColorSpace colorSpace() const { return m_colorSpace; }
    83     Format format() const;
     83    WEBCORE_EXPORT Format format() const;
    8484
    8585    WEBCORE_EXPORT bool isInUse() const;
     
    9090
    9191#if PLATFORM(IOS)
     92    WEBCORE_EXPORT void copyToSurface(IOSurface&);
    9293    WEBCORE_EXPORT static void convertToFormat(std::unique_ptr<WebCore::IOSurface>&& inSurface, Format, std::function<void(std::unique_ptr<WebCore::IOSurface>)>);
    9394#endif
  • trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm

    r192284 r192689  
    5555{
    5656    // YUV422 IOSurfaces do not go in the pool.
     57    // FIXME: Want pooling of RGB10, RGB10A8.
    5758    if (pixelFormat == Format::RGBA) {
    5859        if (auto cachedSurface = surfaceFromPool(size, size, colorSpace))
     
    260261
    261262    CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
     263
    262264    size_t bitsPerComponent = 8;
    263265    size_t bitsPerPixel = 32;
     266   
     267    switch (format()) {
     268    case Format::RGBA:
     269        break;
     270    case Format::RGB10:
     271        bitsPerComponent = 10;
     272        bitsPerPixel = 32;
     273        break;
     274    case Format::RGB10A8:
     275        // FIXME: This doesn't take the two-plane format into account.
     276        bitsPerComponent = 10;
     277        bitsPerPixel = 32;
     278        break;
     279    case Format::YUV422:
     280        ASSERT_NOT_REACHED();
     281        break;
     282    }
     283   
    264284    m_cgContext = adoptCF(CGIOSurfaceContextCreate(m_surface.get(), m_contextSize.width(), m_contextSize.height(), bitsPerComponent, bitsPerPixel, cachedCGColorSpace(m_colorSpace), bitmapInfo));
    265285
     
    311331    if (pixelFormat == 'BGRA')
    312332        return Format::RGBA;
     333
     334    if (pixelFormat == 'w30r')
     335        return Format::RGB10;
     336
     337    if (pixelFormat == 'b3a8')
     338        return Format::RGB10A8;
     339
    313340    if (pixelFormat == 'yuvf')
    314341        return Format::YUV422;
     
    330357
    331358#if PLATFORM(IOS)
     359WEBCORE_EXPORT void IOSurface::copyToSurface(IOSurface& destSurface)
     360{
     361    if (destSurface.format() != format()) {
     362        WTFLogAlways("Trying to copy IOSurface to another surface with a different format");
     363        return;
     364    }
     365
     366    if (destSurface.size() != size()) {
     367        WTFLogAlways("Trying to copy IOSurface to another surface with a different size");
     368        return;
     369    }
     370
     371    static IOSurfaceAcceleratorRef accelerator;
     372    if (!accelerator)
     373        IOSurfaceAcceleratorCreate(nullptr, nullptr, &accelerator);
     374
     375    IOReturn ret = IOSurfaceAcceleratorTransformSurface(accelerator, m_surface.get(), destSurface.surface(), nullptr, nullptr, nullptr, nullptr, nullptr);
     376    if (ret)
     377        WTFLogAlways("IOSurfaceAcceleratorTransformSurface %p to %p failed with error %d", m_surface.get(), destSurface.surface(), ret);
     378}
     379
    332380void IOSurface::convertToFormat(std::unique_ptr<WebCore::IOSurface>&& inSurface, Format format, std::function<void(std::unique_ptr<WebCore::IOSurface>)> callback)
    333381{
  • trunk/Source/WebKit2/ChangeLog

    r192673 r192689  
     12015-11-19  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Back-buffer to front-buffer copy fails for some buffer formats
     4        https://bugs.webkit.org/show_bug.cgi?id=151475
     5        rdar://problem/23617899
     6
     7        Reviewed by Tim Horton.
     8       
     9        When displaying RemoteLayerBackingStore, we copy the back buffer to the front
     10        buffer before painting the updated regions. For buffers using Format::RGB10A8,
     11        the CGImage-based copy fails, so in this case, use IOSurface::copyToSurface().
     12       
     13        Reorganized RemoteLayerBackingStore::drawInContext() to make this a bit easier
     14        to understand. First, we either copy the entire surface over, or paint the backImage.
     15        Then we clip to the dirty rects, and clear them, then paint the layer contents.
     16
     17        * Shared/mac/RemoteLayerBackingStore.mm:
     18        (WebKit::RemoteLayerBackingStore::display):
     19        (WebKit::RemoteLayerBackingStore::drawInContext):
     20
    1212015-11-19  Commit Queue  <commit-queue@webkit.org>
    222
  • trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm

    r192284 r192689  
    253253    if (m_acceleratesDrawing) {
    254254        RetainPtr<CGImageRef> backImage;
    255         if (m_backBuffer.surface && !willPaintEntireBackingStore)
    256             backImage = m_backBuffer.surface->createImage();
     255        if (m_backBuffer.surface && !willPaintEntireBackingStore) {
     256#if PLATFORM(IOS)
     257            if (m_backBuffer.surface->format() == WebCore::IOSurface::Format::RGB10A8) {
     258                // FIXME: remove this when rdar://problem/23623670 is fixed.
     259                m_backBuffer.surface->copyToSurface(*m_frontBuffer.surface);
     260            } else
     261#endif
     262                backImage = m_backBuffer.surface->createImage();
     263        }
    257264
    258265        GraphicsContext& context = m_frontBuffer.surface->ensureGraphicsContext();
     
    286293    scaledSize.scale(m_scale);
    287294    IntRect scaledLayerBounds(IntPoint(), roundedIntSize(scaledSize));
    288 
    289     if (!m_isOpaque)
    290         context.clearRect(scaledLayerBounds);
    291 
    292 #ifndef NDEBUG
    293     if (m_isOpaque)
    294         context.fillRect(scaledLayerBounds, Color(255, 0, 0));
    295 #endif
    296 
    297     CGContextRef cgContext = context.platformContext();
    298295
    299296    // If we have less than webLayerMaxRectsToPaint rects to paint and they cover less
     
    324321    }
    325322
     323    CGContextRef cgContext = context.platformContext();
     324
    326325    if (backImage) {
    327         CGContextSaveGState(cgContext);
     326        CGContextStateSaver stateSaver(cgContext);
    328327        CGContextSetBlendMode(cgContext, kCGBlendModeCopy);
    329 
    330         CGContextAddRect(cgContext, CGRectInfinite);
    331         CGContextAddRects(cgContext, cgPaintingRects, m_paintingRects.size());
    332         CGContextEOClip(cgContext);
    333 
    334328        CGContextTranslateCTM(cgContext, 0, scaledLayerBounds.height());
    335329        CGContextScaleCTM(cgContext, 1, -1);
    336330        CGContextDrawImage(cgContext, scaledLayerBounds, backImage);
    337         CGContextRestoreGState(cgContext);
    338331    }
    339332
    340333    CGContextClipToRects(cgContext, cgPaintingRects, m_paintingRects.size());
     334
     335    if (!m_isOpaque)
     336        context.clearRect(scaledLayerBounds);
     337
     338#ifndef NDEBUG
     339    if (m_isOpaque)
     340        context.fillRect(scaledLayerBounds, Color(255, 0, 0));
     341#endif
    341342
    342343    context.scale(FloatSize(m_scale, m_scale));
Note: See TracChangeset for help on using the changeset viewer.