Changeset 40543 in webkit


Ignore:
Timestamp:
Feb 3, 2009 12:14:37 PM (15 years ago)
Author:
Simon Fraser
Message:

2009-02-03 Simon Fraser <Simon Fraser>

Reviewed by Dave Hyatt

https://bugs.webkit.org/show_bug.cgi?id=23365

Hook up accelerated compositing layers the native
view system on Mac.

Location:
trunk
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r40542 r40543  
     12009-02-03  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Reviewed by Dave Hyatt
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=23365
     6       
     7        Hook up accelerated compositing layers the native
     8        view system on Mac.
     9
     10        * WebCore.base.exp:
     11        Export new Page methods.
     12
     13        * page/ChromeClient.h:
     14        (WebCore::ChromeClient::attachRootGraphicsLayer):
     15        (WebCore::ChromeClient::setNeedsOneShotDrawingSynchronization):
     16        New methods for attaching/detaching the root GraphicsLayer, and
     17        synchronizing layer changes with window drawing.
     18
     19        * page/FrameView.h:
     20        * page/FrameView.cpp:
     21        (WebCore::FrameView::updateCompositingLayers):
     22        (WebCore::FrameView::setNeedsOneShotDrawingSynchronization):
     23        (WebCore::FrameView::didMoveOnscreen):
     24        (WebCore::FrameView::willMoveOffscreen):
     25        New methods to update the compositing layer hierarchy,
     26        and pass-throughs to the RenderLayerCompositor.
     27
     28        (WebCore::FrameView::layout):
     29        Update compositing layers after layout() and updateLayerPositions().
     30
     31        * page/Page.cpp:
     32        (WebCore::Page::didMoveOnscreen):
     33        (WebCore::Page::willMoveOffscreen):
     34        * page/Page.h:
     35        New methods to allow the native view system to tell the Page when it
     36        starts to be presented on-screen, and when it will be hidden.
     37
     38        * rendering/RenderLayerCompositor.h:
     39        * rendering/RenderLayerCompositor.cpp:
     40        (WebCore::RenderLayerCompositor::updateLayerCompositingState):
     41        (WebCore::RenderLayerCompositor::didMoveOnscreen):
     42        (WebCore::RenderLayerCompositor::willMoveOffscreen):
     43        (WebCore::RenderLayerCompositor::ensureRootPlatformLayer):
     44        Rename 'attached' methods to 'moveOnscreen/moveOffscreen' to match
     45        the calls through from Page, FrameView.
     46
     47        (WebCore::RenderLayerCompositor::layerWillBeRemoved):
     48        Dont' try to repaint or update layers if the document is being torn
     49        down.
     50
     51        * rendering/RenderView.cpp:
     52        (WebCore::RenderView::didMoveOnscreen):
     53        (WebCore::RenderView::willMoveOffscreen):
     54        * rendering/RenderView.h:
     55        New methods.
     56
    1572009-02-03  Dirk Schulze  <krit@webkit.org>
    258
  • trunk/WebCore/WebCore.base.exp

    r40514 r40543  
    814814__ZNK7WebCore4Page10pluginDataEv
    815815__ZNK7WebCore4Page34inLowQualityImageInterpolationModeEv
     816__ZN7WebCore4Page17willMoveOffscreenEv
     817__ZN7WebCore4Page15didMoveOnscreenEv
    816818__ZNK7WebCore4Page9groupNameEv
    817819__ZNK7WebCore5Frame11currentFormEv
  • trunk/WebCore/page/ChromeClient.h

    r39717 r40543  
    5252    struct FrameLoadRequest;
    5353    struct WindowFeatures;
     54
     55#if USE(ACCELERATED_COMPOSITING)
     56    class GraphicsLayer;
     57#endif
    5458
    5559    class ChromeClient {
     
    155159        virtual void formStateDidChange(const Node*) = 0;
    156160
     161#if USE(ACCELERATED_COMPOSITING)
     162        // Pass 0 as the GraphicsLayer to detatch the root layer.
     163        virtual void attachRootGraphicsLayer(Frame*, GraphicsLayer*) { }
     164        // Sets a flag to specify that the next time content is drawn to the window,
     165        // the changes appear on the screen in synchrony with updates to GraphicsLayers.
     166        virtual void setNeedsOneShotDrawingSynchronization() { }
     167#endif
     168
    157169#if PLATFORM(MAC)
    158170        virtual KeyboardUIMode keyboardUIMode() { return KeyboardAccessDefault; }
  • trunk/WebCore/page/FrameView.cpp

    r40473 r40543  
    5151#include "Settings.h"
    5252#include <wtf/CurrentTime.h>
     53
     54#if USE(ACCELERATED_COMPOSITING)
     55#include "RenderLayerCompositor.h"
     56#endif
    5357
    5458namespace WebCore {
     
    364368}
    365369
     370#if USE(ACCELERATED_COMPOSITING)
     371void FrameView::updateCompositingLayers(CompositingUpdate updateType)
     372{
     373    RenderView* view = m_frame->contentRenderer();
     374    if (!view || !view->usesCompositing())
     375        return;
     376
     377    if (updateType == ForcedUpdate)
     378        view->compositor()->setCompositingLayersNeedUpdate();
     379   
     380    view->compositor()->updateCompositingLayers();
     381}
     382
     383void FrameView::setNeedsOneShotDrawingSynchronization()
     384{
     385    Page* page = frame() ? frame()->page() : 0;
     386    if (page)
     387        page->chrome()->client()->setNeedsOneShotDrawingSynchronization();
     388}
     389#endif // USE(ACCELERATED_COMPOSITING)
     390
     391void FrameView::didMoveOnscreen()
     392{
     393    RenderView* view = m_frame->contentRenderer();
     394    if (view)
     395        view->didMoveOnscreen();
     396}
     397
     398void FrameView::willMoveOffscreen()
     399{
     400    RenderView* view = m_frame->contentRenderer();
     401    if (view)
     402        view->willMoveOffscreen();
     403}
     404
    366405RenderObject* FrameView::layoutRoot(bool onlyDuringLayout) const
    367406{
     
    538577    layer->updateLayerPositions(m_doFullRepaint);
    539578    endDeferredRepaints();
     579
     580#if USE(ACCELERATED_COMPOSITING)
     581    updateCompositingLayers();
     582#endif
    540583   
    541584    m_layoutCount++;
  • trunk/WebCore/page/FrameView.h

    r40473 r40543  
    9898    bool needsFullRepaint() const { return m_doFullRepaint; }
    9999
     100#if USE(ACCELERATED_COMPOSITING)
     101    enum CompositingUpdate { NormalCompositingUpdate, ForcedCompositingUpdate };
     102    void updateCompositingLayers(CompositingUpdate updateType = NormalCompositingUpdate);
     103
     104    // Called when changes to the GraphicsLayer hierarchy have to be synchronized with
     105    // content rendered via the normal painting path.
     106    void setNeedsOneShotDrawingSynchronization();
     107#endif
     108
     109    void didMoveOnscreen();
     110    void willMoveOffscreen();
     111
    100112    void resetScrollbars();
    101113
  • trunk/WebCore/page/Page.cpp

    r39969 r40543  
    410410}
    411411
     412void Page::didMoveOnscreen()
     413{
     414    for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) {
     415        if (frame->view())
     416            frame->view()->didMoveOnscreen();
     417    }
     418}
     419
     420void Page::willMoveOffscreen()
     421{
     422    for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) {
     423        if (frame->view())
     424            frame->view()->willMoveOffscreen();
     425    }
     426}
     427
    412428void Page::userStyleSheetLocationChanged()
    413429{
  • trunk/WebCore/page/Page.h

    r39818 r40543  
    154154        void setMediaVolume(float volume);
    155155
     156        // Notifications when the Page starts and stops being presented via a native window.
     157        void didMoveOnscreen();
     158        void willMoveOffscreen();
     159
    156160        void userStyleSheetLocationChanged();
    157161        const String& userStyleSheet() const;
  • trunk/WebCore/rendering/RenderLayerCompositor.cpp

    r40434 r40543  
    180180            // and a GraphicsLayer, so we need to make sure the window system
    181181            // synchronizes those changes on the screen.
    182             m_renderView->frameView()->setNeedsSynchronizedGraphicsFlush();
     182            m_renderView->frameView()->setNeedsOneShotDrawingSynchronization();
    183183        }
    184184
     
    268268        setCompositingParent(child, 0);
    269269   
     270    // If the document is being torn down (document's renderer() is null), then there's
     271    // no need to do any layer updating.
     272    if (parent->renderer()->documentBeingDestroyed())
     273        return;
     274
    270275    RenderLayer* compLayer = enclosingCompositingLayer(parent, false);
    271276    if (compLayer) {
     
    274279        // The contents of this layer may be moving from a GraphicsLayer to the window,
    275280        // so we need to make sure the window system synchronizes those changes on the screen.
    276         m_renderView->frameView()->setNeedsSynchronizedGraphicsFlush();
     281        m_renderView->frameView()->setNeedsOneShotDrawingSynchronization();
    277282    }
    278283
     
    586591}
    587592
    588 void RenderLayerCompositor::willBeDetached()
    589 {
    590     if (!m_rootPlatformLayer ||! m_rootLayerAttached)
     593void RenderLayerCompositor::didMoveOnscreen()
     594{
     595    if (!m_rootPlatformLayer)
    591596        return;
    592597
     
    596601        return;
    597602
    598     page->chrome()->client()->attachRootGraphicsLayer(frame, 0);
    599     m_rootLayerAttached = false;
    600 }
    601 
    602 void RenderLayerCompositor::wasAttached()
    603 {
    604     if (!m_rootPlatformLayer)
     603    page->chrome()->client()->attachRootGraphicsLayer(frame, m_rootPlatformLayer);
     604    m_rootLayerAttached = true;
     605}
     606
     607void RenderLayerCompositor::willMoveOffscreen()
     608{
     609    if (!m_rootPlatformLayer || !m_rootLayerAttached)
    605610        return;
    606611
     
    610615        return;
    611616
    612     page->chrome()->client()->attachRootGraphicsLayer(frame, m_rootPlatformLayer);
    613     m_rootLayerAttached = true;
     617    page->chrome()->client()->attachRootGraphicsLayer(frame, 0);
     618    m_rootLayerAttached = false;
    614619}
    615620
     
    743748    m_rootPlatformLayer->setMasksToBounds(true);
    744749   
    745     wasAttached();
     750    didMoveOnscreen();
    746751}
    747752
  • trunk/WebCore/rendering/RenderLayerCompositor.h

    r40434 r40543  
    8484    GraphicsLayer* rootPlatformLayer() const;
    8585
    86     void willBeDetached();
    87     void wasAttached();
     86    void didMoveOnscreen();
     87    void willMoveOffscreen();
     88
    8889    void updateRootLayerPosition();
    8990
  • trunk/WebCore/rendering/RenderView.cpp

    r40312 r40543  
    627627}
    628628
     629void RenderView::didMoveOnscreen()
     630{
     631    // FIXME: will call into RenderLayerCompositor
     632}
     633
     634void RenderView::willMoveOffscreen()
     635{
     636    // FIXME: will call into RenderLayerCompositor
     637}
     638
    629639} // namespace WebCore
  • trunk/WebCore/rendering/RenderView.h

    r40417 r40543  
    146146
    147147    virtual void updateHitTestResult(HitTestResult&, const IntPoint&);
     148
     149    void didMoveOnscreen();
     150    void willMoveOffscreen();
    148151
    149152protected:
  • trunk/WebKit/mac/ChangeLog

    r40514 r40543  
     12009-02-03  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Reviewed by Dave Hyatt
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=23365
     6       
     7        Hook up accelerated compositing layers the native
     8        view system on Mac.
     9
     10        * WebCoreSupport/WebChromeClient.h:
     11        * WebCoreSupport/WebChromeClient.mm:
     12        (WebChromeClient::attachRootGraphicsLayer):
     13        (WebChromeClient::setNeedsOneShotDrawingSynchronization):
     14        New methods to hook up the root GraphicsLayer to the native
     15        view system, and to synchronize layer changes with view-based
     16        drawing when layers come and go.
     17
     18        * WebView/WebHTMLView.mm:
     19        (-[WebHTMLViewPrivate clear]):
     20        Clear the pointer to layerHostingView.
     21
     22        (-[WebHTMLView _setAsideSubviews]):
     23        (-[WebHTMLView willRemoveSubview:]):
     24        Keep the special layer-hosting view in the subviews even
     25        when the rest of the subviews are ripped out for
     26        painting.
     27
     28        (-[WebHTMLView _isUsingAcceleratedCompositing]):
     29        New utility method for DumpRenderTree to know if we're
     30        hosting layers.
     31
     32        (-[WebHTMLView drawRect:]):
     33        Call -disableScreenUpdatesUntilFlush if we have to
     34        synchronize layer changes with painting.
     35
     36        (-[WebHTMLView attachRootLayer:]):
     37        (-[WebHTMLView detachRootLayer]):
     38        Attach and detach the root GraphicsLayer.
     39
     40        * WebView/WebViewInternal.h:
     41        * WebView/WebHTMLViewInternal.h:
     42        * WebView/WebHTMLViewPrivate.h:
     43        New method declarations.
     44       
     45        * WebView/WebView.mm:
     46        (-[WebView _needsOneShotDrawingSynchronization]):
     47        (-[WebView _setNeedsOneShotDrawingSynchronization:]):
     48        Set the flag to say if we need to synchronize layer
     49        changes and painting on the next -drawRect: call.
     50
     51        (-[WebView viewWillMoveToWindow:]):
     52        (-[WebView viewDidMoveToWindow]):
     53        Call new notifications that the view was added to or removed from
     54        the window, which are required by the layer hosting mechanism.
     55
    1562009-02-02  Geoffrey Garen  <ggaren@apple.com>
    257
  • trunk/WebKit/mac/WebCoreSupport/WebChromeClient.h

    r39717 r40543  
    136136    virtual void formStateDidChange(const WebCore::Node*) { }
    137137
     138#if USE(ACCELERATED_COMPOSITING)
     139    virtual void attachRootGraphicsLayer(WebCore::Frame*, WebCore::GraphicsLayer*);
     140    virtual void setNeedsOneShotDrawingSynchronization();
     141#endif
     142
    138143private:
    139144    WebView *m_webView;
  • trunk/WebKit/mac/WebCoreSupport/WebChromeClient.mm

    r39717 r40543  
    6161#import <wtf/PassRefPtr.h>
    6262#import <wtf/Vector.h>
     63
     64#if USE(ACCELERATED_COMPOSITING)
     65#import <WebCore/GraphicsLayer.h>
     66#endif
    6367
    6468@interface NSView (WebNSViewDetails)
     
    644648}
    645649
     650#if USE(ACCELERATED_COMPOSITING)
     651void WebChromeClient::attachRootGraphicsLayer(Frame* frame, GraphicsLayer* graphicsLayer)
     652{
     653    WebFrameView *frameView = [kit(frame) frameView];
     654    WebHTMLView *docView = (WebHTMLView *)[frameView documentView];
     655    if (graphicsLayer)
     656        [docView attachRootLayer:graphicsLayer->nativeLayer()];
     657    else
     658        [docView detachRootLayer];
     659}
     660
     661void WebChromeClient::setNeedsOneShotDrawingSynchronization()
     662{
     663    [m_webView _setNeedsOneShotDrawingSynchronization:YES];
     664}
     665#endif
     666
    646667@implementation WebOpenPanelResultListener
    647668
  • trunk/WebKit/mac/WebView/WebHTMLView.mm

    r40498 r40543  
    114114#import <runtime/InitializeThreading.h>
    115115
     116#if USE(ACCELERATED_COMPOSITING)
     117#import <QuartzCore/QuartzCore.h>
     118#endif
     119
    116120using namespace WebCore;
    117121using namespace HTMLNames;
     
    381385    id savedSubviews;
    382386    BOOL subviewsSetAside;
     387   
     388#if USE(ACCELERATED_COMPOSITING)
     389    NSView *layerHostingView;
     390#endif
    383391
    384392    NSEvent *mouseDownEvent; // Kept after handling the event.
     
    529537    highlighters = nil;
    530538    promisedDragTIFFDataSource = 0;
     539
     540#if USE(ACCELERATED_COMPOSITING)
     541    layerHostingView = nil;
     542#endif   
    531543}
    532544
     
    11371149    ASSERT(_private->savedSubviews == nil);
    11381150    _private->savedSubviews = _subviews;
     1151#if USE(ACCELERATED_COMPOSITING)
     1152    // We need to keep the layer-hosting view in the subviews, otherwise the layers flash.
     1153    if (_private->layerHostingView) {
     1154        NSArray* newSubviews = [[NSArray alloc] initWithObjects:_private->layerHostingView, nil];
     1155        _subviews = newSubviews;
     1156    } else
     1157        _subviews = nil;
     1158#else
    11391159    _subviews = nil;
     1160#endif   
    11401161    _private->subviewsSetAside = YES;
    11411162 }
     
    11441165 {
    11451166    ASSERT(_private->subviewsSetAside);
     1167#if USE(ACCELERATED_COMPOSITING)
     1168    if (_private->layerHostingView) {
     1169        [_subviews release];
     1170        _subviews = _private->savedSubviews;
     1171    } else {
     1172        ASSERT(_subviews == nil);
     1173        _subviews = _private->savedSubviews;
     1174    }
     1175#else
    11461176    ASSERT(_subviews == nil);
    11471177    _subviews = _private->savedSubviews;
     1178#endif   
    11481179    _private->savedSubviews = nil;
    11491180    _private->subviewsSetAside = NO;
     
    11601191- (void)willRemoveSubview:(NSView *)subview
    11611192{
    1162     if (_private->enumeratingSubviews)
     1193    // Have to null-check _private, since this can be called via -dealloc when
     1194    // cleaning up the the layerHostingView.
     1195    if (_private && _private->enumeratingSubviews)
    11631196        LOG(View, "A view of class %s was removed during subview enumeration for layout or printing mode change. We will still do layout or the printing mode change even though this view is no longer in the view hierarchy.", object_getClassName([subview class]));
    11641197}
     
    20712104}
    20722105#endif
     2106
     2107- (BOOL)_isUsingAcceleratedCompositing
     2108{
     2109#if USE(ACCELERATED_COMPOSITING)
     2110    return _private->layerHostingView != nil;
     2111#else
     2112    return NO;
     2113#endif
     2114}
    20732115
    20742116@end
     
    30223064    if (subviewsWereSetAside)
    30233065        [self _setAsideSubviews];
     3066       
     3067#if USE(ACCELERATED_COMPOSITING)
     3068    if ([[self _webView] _needsOneShotDrawingSynchronization]) {
     3069        // Disable screen updates so that drawing into the NSView and
     3070        // CALayer updates appear on the screen at the same time.
     3071        [[self window] disableScreenUpdatesUntilFlush];
     3072        [CATransaction flush];
     3073        [[self _webView] _setNeedsOneShotDrawingSynchronization:NO];
     3074    }
     3075#endif
    30243076}
    30253077
     
    49745026}
    49755027
     5028#if USE(ACCELERATED_COMPOSITING)
     5029- (void)attachRootLayer:(CALayer*)layer
     5030{
     5031    if (!_private->layerHostingView) {
     5032        NSView* hostingView = [[NSView alloc] initWithFrame:[self bounds]];
     5033        [hostingView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
     5034        [self addSubview:hostingView];
     5035        [hostingView release];
     5036        // hostingView is owned by being a subview of self
     5037        _private->layerHostingView = hostingView;
     5038    }
     5039
     5040    // Make a container layer, which will get sized/positioned by AppKit and CA
     5041    CALayer* viewLayer = [CALayer layer];
     5042    [_private->layerHostingView setLayer:viewLayer];
     5043    [_private->layerHostingView setWantsLayer:YES];
     5044   
     5045    // Parent our root layer in the container layer
     5046    [viewLayer addSublayer:layer];
     5047}
     5048
     5049- (void)detachRootLayer
     5050{
     5051    if (_private->layerHostingView) {
     5052        [_private->layerHostingView setLayer:nil];
     5053        [_private->layerHostingView setWantsLayer:NO];
     5054        [_private->layerHostingView removeFromSuperview];
     5055        _private->layerHostingView = nil;
     5056    }
     5057}
     5058#endif
     5059
    49765060@end
    49775061
  • trunk/WebKit/mac/WebView/WebHTMLViewInternal.h

    r34608 r40543  
    5959- (void)_web_layoutIfNeededRecursive;
    6060- (void)_destroyAllWebPlugins;
     61
     62#if USE(ACCELERATED_COMPOSITING)
     63- (void)attachRootLayer:(CALayer*)layer;
     64- (void)detachRootLayer;
     65#endif
     66
    6167@end
  • trunk/WebKit/mac/WebView/WebHTMLViewPrivate.h

    r34608 r40543  
    120120// SPI for DumpRenderTree
    121121- (void)_updateFocusedAndActiveState;
     122- (BOOL)_isUsingAcceleratedCompositing;
    122123
    123124// SPI for printing (should be converted to API someday). When the WebHTMLView isn't being printed
  • trunk/WebKit/mac/WebView/WebView.mm

    r40449 r40543  
    407407    // When this flag is set, we will not make any subviews underneath this WebView.  This means no WebFrameViews and no WebHTMLViews.
    408408    BOOL useDocumentViews;
     409
     410#if USE(ACCELERATED_COMPOSITING)
     411    // When this flag is set, next time a WebHTMLView draws, it needs to temporarily disable screen updates
     412    // so that the NSView drawing is visually synchronized with CALayer updates.
     413    BOOL needsOneShotDrawingSynchronization;
     414#endif   
    409415}
    410416@end
     
    20702076}
    20712077
     2078#if USE(ACCELERATED_COMPOSITING)
     2079- (BOOL)_needsOneShotDrawingSynchronization
     2080{
     2081    return _private->needsOneShotDrawingSynchronization;
     2082}
     2083
     2084- (void)_setNeedsOneShotDrawingSynchronization:(BOOL)needsSynchronization
     2085{
     2086    _private->needsOneShotDrawingSynchronization = needsSynchronization;
     2087}
     2088#endif   
     2089
    20722090@end
    20732091
     
    24992517        [self removeWindowObservers];
    25002518        [self removeSizeObservers];
    2501     }
     2519    } else
     2520        _private->page->willMoveOffscreen();
    25022521}
    25032522
     
    25142533        [self addWindowObservers];
    25152534        [self addSizeObservers];
     2535        _private->page->didMoveOnscreen();
    25162536    }
    25172537}
  • trunk/WebKit/mac/WebView/WebViewInternal.h

    r39393 r40543  
    146146+ (BOOL)_canHandleRequest:(NSURLRequest *)request forMainFrame:(BOOL)forMainFrame;
    147147
     148#if USE(ACCELERATED_COMPOSITING)
     149- (BOOL)_needsOneShotDrawingSynchronization;
     150- (void)_setNeedsOneShotDrawingSynchronization:(BOOL)needsSynchronization;
     151#endif   
     152
    148153@end
    149154
Note: See TracChangeset for help on using the changeset viewer.