Changeset 173702 in webkit


Ignore:
Timestamp:
Sep 17, 2014 2:18:04 PM (10 years ago)
Author:
Simon Fraser
Message:

Fix an issue that caused video playback to not always use high resolution streams
https://bugs.webkit.org/show_bug.cgi?id=136879
rdar://problem/18316542

Reviewed by Eric Carlson.

The underlying video framework expects to be able to use -[CALayer convertRect:toLayer:nil] on
the video layer to obtain information about the display resolution of the video,
including the device scale factor. This doesn't work for layers in the web process,
which are remotely hosted into the UI process.

For now, use a workaround which involves putting a scale transform equivalent to
the device scale factor on the web process layer, and the inverse scale on the
hosting layer in the UI process.

We have to do this in two places, for in-page video, and for fullscreen video.

  • Shared/mac/RemoteLayerTreeTransaction.h: Add hostingDeviceScaleFactor to the LayerCreation

properties.

  • Shared/mac/RemoteLayerTreeTransaction.mm:

(WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::LayerCreationProperties):
(WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::encode):
(WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::decode):

  • UIProcess/ios/RemoteLayerTreeHostIOS.mm:

(-[WKRemoteView initWithFrame:contextID:hostingDeviceScaleFactor:]): Set the inverse scale
transform on the layer.
(WebKit::RemoteLayerTreeHost::createLayer):
(-[WKRemoteView initWithFrame:contextID:]): Deleted.

  • UIProcess/ios/WebVideoFullscreenManagerProxy.h:
  • UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in:
  • UIProcess/ios/WebVideoFullscreenManagerProxy.mm:

(WebKit::WebVideoFullscreenManagerProxy::setupFullscreenWithID):

  • WebProcess/WebPage/mac/PlatformCALayerRemoteCustom.mm:

(WebKit::PlatformCALayerRemoteCustom::PlatformCALayerRemoteCustom):

  • WebProcess/WebPage/mac/RemoteLayerTreeContext.h:

(WebKit::RemoteLayerTreeContext::deviceScaleFactor):

  • WebProcess/WebPage/mac/RemoteLayerTreeContext.mm:

(WebKit::RemoteLayerTreeContext::layerWasCreated):

  • WebProcess/ios/WebVideoFullscreenManager.mm:

(WebKit::WebVideoFullscreenManager::enterFullscreenForNode):
(WebKit::WebVideoFullscreenManager::didSetupFullscreen):

Location:
trunk/Source/WebKit2
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r173696 r173702  
     12014-09-17  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Fix an issue that caused video playback to not always use high resolution streams
     4        https://bugs.webkit.org/show_bug.cgi?id=136879
     5        rdar://problem/18316542
     6
     7        Reviewed by Eric Carlson.
     8       
     9        The underlying video framework expects to be able to use -[CALayer convertRect:toLayer:nil] on
     10        the video layer to obtain information about the display resolution of the video,
     11        including the device scale factor. This doesn't work for layers in the web process,
     12        which are remotely hosted into the UI process.
     13       
     14        For now, use a workaround which involves putting a scale transform equivalent to
     15        the device scale factor on the web process layer, and the inverse scale on the
     16        hosting layer in the UI process.
     17       
     18        We have to do this in two places, for in-page video, and for fullscreen video.
     19
     20        * Shared/mac/RemoteLayerTreeTransaction.h: Add hostingDeviceScaleFactor to the LayerCreation
     21        properties.
     22        * Shared/mac/RemoteLayerTreeTransaction.mm:
     23        (WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::LayerCreationProperties):
     24        (WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::encode):
     25        (WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::decode):
     26        * UIProcess/ios/RemoteLayerTreeHostIOS.mm:
     27        (-[WKRemoteView initWithFrame:contextID:hostingDeviceScaleFactor:]): Set the inverse scale
     28        transform on the layer.
     29        (WebKit::RemoteLayerTreeHost::createLayer):
     30        (-[WKRemoteView initWithFrame:contextID:]): Deleted.
     31        * UIProcess/ios/WebVideoFullscreenManagerProxy.h:
     32        * UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in:
     33        * UIProcess/ios/WebVideoFullscreenManagerProxy.mm:
     34        (WebKit::WebVideoFullscreenManagerProxy::setupFullscreenWithID):
     35        * WebProcess/WebPage/mac/PlatformCALayerRemoteCustom.mm:
     36        (WebKit::PlatformCALayerRemoteCustom::PlatformCALayerRemoteCustom):
     37        * WebProcess/WebPage/mac/RemoteLayerTreeContext.h:
     38        (WebKit::RemoteLayerTreeContext::deviceScaleFactor):
     39        * WebProcess/WebPage/mac/RemoteLayerTreeContext.mm:
     40        (WebKit::RemoteLayerTreeContext::layerWasCreated):
     41        * WebProcess/ios/WebVideoFullscreenManager.mm:
     42        (WebKit::WebVideoFullscreenManager::enterFullscreenForNode):
     43        (WebKit::WebVideoFullscreenManager::didSetupFullscreen):
     44
    1452014-09-17  Gavin Barraclough  <baraclough@apple.com>
    246
  • trunk/Source/WebKit2/Shared/mac/RemoteLayerTreeTransaction.h

    r170774 r173702  
    9696
    9797        uint32_t hostingContextID;
     98        float hostingDeviceScaleFactor;
    9899    };
    99100
  • trunk/Source/WebKit2/Shared/mac/RemoteLayerTreeTransaction.mm

    r170864 r173702  
    4848    , type(PlatformCALayer::LayerTypeLayer)
    4949    , hostingContextID(0)
     50    , hostingDeviceScaleFactor(1)
    5051{
    5152}
     
    5657    encoder.encodeEnum(type);
    5758    encoder << hostingContextID;
     59    encoder << hostingDeviceScaleFactor;
    5860}
    5961
     
    6769
    6870    if (!decoder.decode(result.hostingContextID))
     71        return false;
     72
     73    if (!decoder.decode(result.hostingDeviceScaleFactor))
    6974        return false;
    7075
  • trunk/Source/WebKit2/UIProcess/ios/RemoteLayerTreeHostIOS.mm

    r170864 r173702  
    109109
    110110@implementation WKRemoteView
    111 - (instancetype)initWithFrame:(CGRect)frame contextID:(uint32_t)contextID
     111- (instancetype)initWithFrame:(CGRect)frame contextID:(uint32_t)contextID hostingDeviceScaleFactor:(float)scaleFactor
    112112{
    113113    if ((self = [super initWithFrame:frame])) {
    114114        [[self layer] setContextId:contextID];
     115        // Invert the scale transform added in the WebProcess to fix <rdar://problem/18316542>.
     116        float inverseScale = 1 / scaleFactor;
     117        [[self layer] setTransform:CATransform3DMakeScale(inverseScale, inverseScale, 1)];
    115118    }
    116119   
     
    156159    case PlatformCALayer::LayerTypeWebGLLayer:
    157160        if (!m_isDebugLayerTreeHost)
    158             view = adoptNS([[WKRemoteView alloc] initWithFrame:CGRectZero contextID:properties.hostingContextID]);
     161            view = adoptNS([[WKRemoteView alloc] initWithFrame:CGRectZero contextID:properties.hostingContextID hostingDeviceScaleFactor:properties.hostingDeviceScaleFactor]);
    159162        else
    160163            view = adoptNS([[WKCompositingView alloc] init]);
  • trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.h

    r170083 r173702  
    5656
    5757    // Translate to FullscreenInterface
    58     void setupFullscreenWithID(uint32_t, WebCore::IntRect initialRect);
     58    void setupFullscreenWithID(uint32_t, WebCore::IntRect initialRect, float hostingDeviceScaleFactor);
    5959    void setSeekableRangesVector(Vector<std::pair<double, double>>&);
    6060    void setExternalPlaybackProperties(bool enabled, uint32_t targetType, String localizedDeviceName);
  • trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in

    r171288 r173702  
    3232    SetDuration(double duration)
    3333    SetRate(bool isPlaying, double rate)
    34     SetupFullscreenWithID(uint32_t videoLayerID, WebCore::IntRect initialRect)
     34    SetupFullscreenWithID(uint32_t videoLayerID, WebCore::IntRect initialRect, float hostingScaleFactor)
    3535    EnterFullscreen()
    3636    ExitFullscreen(WebCore::IntRect finalRect)
  • trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.mm

    r171973 r173702  
    7373}
    7474
    75 void WebVideoFullscreenManagerProxy::setupFullscreenWithID(uint32_t videoLayerID, WebCore::IntRect initialRect)
     75void WebVideoFullscreenManagerProxy::setupFullscreenWithID(uint32_t videoLayerID, WebCore::IntRect initialRect, float hostingDeviceScaleFactor)
    7676{
    7777    ASSERT(videoLayerID);
    7878    m_layerHost = WKMakeRenderLayer(videoLayerID);
     79    if (hostingDeviceScaleFactor != 1) {
     80        // Invert the scale transform added in the WebProcess to fix <rdar://problem/18316542>.
     81        float inverseScale = 1 / hostingDeviceScaleFactor;
     82        [m_layerHost setTransform:CATransform3DMakeScale(inverseScale, inverseScale, 1)];
     83    }
     84
    7985    UIView *parentView = toRemoteLayerTreeDrawingAreaProxy(m_page->drawingArea())->remoteLayerTreeHost().rootLayer();
    8086    setupFullscreen(*m_layerHost.get(), initialRect, parentView);
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/PlatformCALayerRemoteCustom.mm

    r172681 r173702  
    6565    case LayerHostingMode::OutOfProcess:
    6666        m_layerHostingContext = LayerHostingContext::createForExternalHostingProcess();
     67#if PLATFORM(IOS)
     68        float scaleFactor = context.deviceScaleFactor();
     69        // Set a scale factor here to make convertRect:toLayer:nil take scale factor into account. <rdar://problem/18316542>.
     70        // This scale factor is inverted in the hosting process.
     71        [customLayer setTransform:CATransform3DMakeScale(scaleFactor, scaleFactor, 1)];
     72#endif
    6773        break;
    6874#endif
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeContext.h

    r172836 r173702  
    5656    WebCore::LayerPool& layerPool() { return m_layerPool; }
    5757
     58    float deviceScaleFactor() const { return m_webPage.deviceScaleFactor(); }
     59
    5860    LayerHostingMode layerHostingMode() const { return m_webPage.layerHostingMode(); }
    5961
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeContext.mm

    r172836 r173702  
    6262    creationProperties.type = type;
    6363
    64     if (layer.isPlatformCALayerRemoteCustom())
     64    if (layer.isPlatformCALayerRemoteCustom()) {
    6565        creationProperties.hostingContextID = layer.hostingContextID();
     66        creationProperties.hostingDeviceScaleFactor = deviceScaleFactor();
     67    }
    6668
    6769    m_createdLayers.append(creationProperties);
  • trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.mm

    r173230 r173702  
    9898    m_layerHostingContext = LayerHostingContext::createForExternalHostingProcess();
    9999   
    100     m_page->send(Messages::WebVideoFullscreenManagerProxy::SetupFullscreenWithID(m_layerHostingContext->contextID(), clientRectForElement(videoElement)), m_page->pageID());
     100    m_page->send(Messages::WebVideoFullscreenManagerProxy::SetupFullscreenWithID(m_layerHostingContext->contextID(), clientRectForElement(videoElement), m_page->deviceScaleFactor()), m_page->pageID());
    101101}
    102102
     
    176176    [CATransaction begin];
    177177    [CATransaction setDisableActions:YES];
     178
    178179    [videoLayer setBackgroundColor:cachedCGColor(WebCore::Color::transparent, WebCore::ColorSpaceDeviceRGB)];
     180
     181    // Set a scale factor here to make convertRect:toLayer:nil take scale factor into account. <rdar://problem/18316542>.
     182    // This scale factor is inverted in the hosting process.
     183    float hostingScaleFactor = m_page->deviceScaleFactor();
     184    [videoLayer setTransform:CATransform3DMakeScale(hostingScaleFactor, hostingScaleFactor, 1)];
    179185    m_layerHostingContext->setRootLayer(videoLayer);
     186
    180187    setVideoFullscreenLayer(videoLayer);
    181188    [CATransaction commit];
     189
    182190    m_page->send(Messages::WebVideoFullscreenManagerProxy::EnterFullscreen(), m_page->pageID());
    183191}
Note: See TracChangeset for help on using the changeset viewer.