Changeset 82959 in webkit


Ignore:
Timestamp:
Apr 5, 2011 11:01:12 AM (13 years ago)
Author:
Adam Roben
Message:

Add a way for LayerTreeHost to participate in DrawingAreaImpl's normal display mechanism

When LayerTreeHost participates in display, it renders each frame into a bitmap.
DrawingAreaImpl sends the bitmap to the UI process in an Update message, just like in
non-accelerated compositing mode. The UI process never knows that accelerated compositing is
going on. (When LayerTreeHost does not participate in display, as on Mac, it is responsible
for getting bits from the web process to the UI process.)

No LayerTreeHost uses this mechanism (yet). This patch should cause no change in behavior.

Fixes <http://webkit.org/b/57792> LayerTreeHost needs a way to render frames to a bitmap

Reviewed by Anders Carlsson.

  • WebProcess/WebPage/DrawingAreaImpl.cpp:

(WebKit::DrawingAreaImpl::forceRepaint): If the layer tree host participates in display,
perform a display (like in the non-accelerated case).
(WebKit::DrawingAreaImpl::layerHostDidFlushLayers): Don't send an
EnterAcceleratedCompositing message to the UI process if the layer tree host participates in
display. In that case, the UI process doesn't even need to know we're using accelerated
compositing in the web process.
(WebKit::DrawingAreaImpl::sendDidUpdateBackingStoreState): Go through the normal display
mechanism if we have a layer tree host that participates in display.
(WebKit::DrawingAreaImpl::didUpdate): Don't ignore DidUpdate messages when we have a layer
tree host that participates in display.
(WebKit::DrawingAreaImpl::enterAcceleratedCompositingMode): If the new layer tree host
participates in display, let the display timer continue to run and continue to expect
DidUpdate messages so that we don't interrupt the normal display mechanism. We still clear
out m_dirtyRegion, m_scrollRect, and m_scrollOffset, though, because the layer tree host is
still responsible for keeping track of those things even when it participates in display.
(WebKit::DrawingAreaImpl::exitAcceleratedCompositingMode): If the outgoing layer tree host
was participating in display, just send another Update message instead of an
ExitAcceleratedCompositing message, since the UI process never even knew we were using
accelerated compositing.
(WebKit::DrawingAreaImpl::displayTimerFired): If we have a layer tree host that's
participating in display, ask it when it next needs to display when scheduling our timer.

(WebKit::DrawingAreaImpl::scheduleDisplay):
(WebKit::DrawingAreaImpl::display):
If we have a layer tree host that's participating in display, it will keep track of its own
dirty region, so ask it if it needs display rather than checking our own dirty region.

(WebKit::DrawingAreaImpl::display): If we have a layer tree host that's participating in
display, don't bail out. Instead, tell it to display rather than asking the page to paint.
Moved the setting of updateInfo.viewSize earlier so that it will be set even when the layer
tree host is displaying. Other changes are just due to indentation.

  • WebProcess/WebPage/LayerTreeHost.h:

(WebKit::LayerTreeHost::participatesInDisplay):
(WebKit::LayerTreeHost::needsDisplay):
(WebKit::LayerTreeHost::timeUntilNextDisplay):
(WebKit::LayerTreeHost::display):
Stubbed out these functions. Derived classes can override them to participate in display.

Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r82952 r82959  
     12011-04-04  Adam Roben  <aroben@apple.com>
     2
     3        Add a way for LayerTreeHost to participate in DrawingAreaImpl's normal display mechanism
     4
     5        When LayerTreeHost participates in display, it renders each frame into a bitmap.
     6        DrawingAreaImpl sends the bitmap to the UI process in an Update message, just like in
     7        non-accelerated compositing mode. The UI process never knows that accelerated compositing is
     8        going on. (When LayerTreeHost does not participate in display, as on Mac, it is responsible
     9        for getting bits from the web process to the UI process.)
     10
     11        No LayerTreeHost uses this mechanism (yet). This patch should cause no change in behavior.
     12
     13        Fixes <http://webkit.org/b/57792> LayerTreeHost needs a way to render frames to a bitmap
     14
     15        Reviewed by Anders Carlsson.
     16
     17        * WebProcess/WebPage/DrawingAreaImpl.cpp:
     18        (WebKit::DrawingAreaImpl::forceRepaint): If the layer tree host participates in display,
     19        perform a display (like in the non-accelerated case).
     20        (WebKit::DrawingAreaImpl::layerHostDidFlushLayers): Don't send an
     21        EnterAcceleratedCompositing message to the UI process if the layer tree host participates in
     22        display. In that case, the UI process doesn't even need to know we're using accelerated
     23        compositing in the web process.
     24        (WebKit::DrawingAreaImpl::sendDidUpdateBackingStoreState): Go through the normal display
     25        mechanism if we have a layer tree host that participates in display.
     26        (WebKit::DrawingAreaImpl::didUpdate): Don't ignore DidUpdate messages when we have a layer
     27        tree host that participates in display.
     28        (WebKit::DrawingAreaImpl::enterAcceleratedCompositingMode): If the new layer tree host
     29        participates in display, let the display timer continue to run and continue to expect
     30        DidUpdate messages so that we don't interrupt the normal display mechanism. We still clear
     31        out m_dirtyRegion, m_scrollRect, and m_scrollOffset, though, because the layer tree host is
     32        still responsible for keeping track of those things even when it participates in display.
     33        (WebKit::DrawingAreaImpl::exitAcceleratedCompositingMode): If the outgoing layer tree host
     34        was participating in display, just send another Update message instead of an
     35        ExitAcceleratedCompositing message, since the UI process never even knew we were using
     36        accelerated compositing.
     37        (WebKit::DrawingAreaImpl::displayTimerFired): If we have a layer tree host that's
     38        participating in display, ask it when it next needs to display when scheduling our timer.
     39
     40        (WebKit::DrawingAreaImpl::scheduleDisplay):
     41        (WebKit::DrawingAreaImpl::display):
     42        If we have a layer tree host that's participating in display, it will keep track of its own
     43        dirty region, so ask it if it needs display rather than checking our own dirty region.
     44
     45        (WebKit::DrawingAreaImpl::display): If we have a layer tree host that's participating in
     46        display, don't bail out. Instead, tell it to display rather than asking the page to paint.
     47        Moved the setting of updateInfo.viewSize earlier so that it will be set even when the layer
     48        tree host is displaying. Other changes are just due to indentation.
     49
     50        * WebProcess/WebPage/LayerTreeHost.h:
     51        (WebKit::LayerTreeHost::participatesInDisplay):
     52        (WebKit::LayerTreeHost::needsDisplay):
     53        (WebKit::LayerTreeHost::timeUntilNextDisplay):
     54        (WebKit::LayerTreeHost::display):
     55        Stubbed out these functions. Derived classes can override them to participate in display.
     56
    1572011-04-04  MORITA Hajime  <morrita@google.com>
    258
  • trunk/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp

    r82543 r82959  
    4343
    4444using namespace WebCore;
     45using namespace std;
    4546
    4647namespace WebKit {
     
    160161    if (m_layerTreeHost) {
    161162        m_layerTreeHost->forceRepaint();
    162         return;
     163        if (!m_layerTreeHost->participatesInDisplay())
     164            return;
    163165    }
    164166
     
    202204    }
    203205
    204     if (!m_layerTreeHost)
    205         return;
     206    if (!m_layerTreeHost || m_layerTreeHost->participatesInDisplay()) {
     207        // When the layer tree host participates in display, we never tell the UI process about
     208        // accelerated compositing. From the UI process's point of view, we're still just sending
     209        // it a series of bitmaps in Update messages.
     210        return;
     211    }
    206212
    207213#if USE(ACCELERATED_COMPOSITING)
     
    302308    UpdateInfo updateInfo;
    303309
    304     if (!m_isPaintingSuspended && !m_layerTreeHost)
     310    if (!m_isPaintingSuspended && (!m_layerTreeHost || m_layerTreeHost->participatesInDisplay()))
    305311        display(updateInfo);
    306312
     
    308314    LayerTreeContext layerTreeContext;
    309315
    310     if (m_isPaintingSuspended || m_layerTreeHost) {
     316    if (m_isPaintingSuspended || m_layerTreeHost && !m_layerTreeHost->participatesInDisplay()) {
    311317        updateInfo.viewSize = m_webPage->size();
    312318
     
    331337    // We might get didUpdate messages from the UI process even after we've
    332338    // entered accelerated compositing mode. Ignore them.
    333     if (m_layerTreeHost)
     339    if (m_layerTreeHost && !m_layerTreeHost->participatesInDisplay())
    334340        return;
    335341
     
    374380    m_scrollRect = IntRect();
    375381    m_scrollOffset = IntSize();
    376     m_displayTimer.stop();
    377     m_isWaitingForDidUpdate = false;
     382
     383    if (!m_layerTreeHost->participatesInDisplay()) {
     384        m_displayTimer.stop();
     385        m_isWaitingForDidUpdate = false;
     386    }
    378387}
    379388
     
    386395
    387396    ASSERT(m_layerTreeHost);
     397
     398    bool wasParticipatingInDisplay = m_layerTreeHost->participatesInDisplay();
    388399
    389400    m_layerTreeHost->invalidate();
     
    406417
    407418#if USE(ACCELERATED_COMPOSITING)
    408     // Send along a complete update of the page so we can paint the contents right after we exit the
    409     // accelerated compositing mode, eliminiating flicker.
    410     m_webPage->send(Messages::DrawingAreaProxy::ExitAcceleratedCompositingMode(m_backingStoreStateID, updateInfo));
     419    if (wasParticipatingInDisplay) {
     420        // When the layer tree host participates in display, we never tell the UI process about
     421        // accelerated compositing. From the UI process's point of view, we're still just sending
     422        // it a series of bitmaps in Update messages.
     423        m_webPage->send(Messages::DrawingAreaProxy::Update(m_backingStoreStateID, updateInfo));
     424    } else {
     425        // Send along a complete update of the page so we can paint the contents right after we exit the
     426        // accelerated compositing mode, eliminiating flicker.
     427        m_webPage->send(Messages::DrawingAreaProxy::ExitAcceleratedCompositingMode(m_backingStoreStateID, updateInfo));
     428    }
    411429#endif
    412430}
     
    422440void DrawingAreaImpl::scheduleDisplay()
    423441{
     442    ASSERT(!m_layerTreeHost || m_layerTreeHost->participatesInDisplay());
     443
    424444    if (m_isWaitingForDidUpdate)
    425445        return;
     
    428448        return;
    429449
    430     if (m_dirtyRegion.isEmpty())
    431         return;
     450    if (m_layerTreeHost) {
     451        if (!m_layerTreeHost->needsDisplay())
     452            return;
     453    } else if (m_dirtyRegion.isEmpty())
     454            return;
    432455
    433456    if (m_displayTimer.isActive())
     
    442465   
    443466    double timeSinceLastDisplay = currentTime() - m_lastDisplayTime;
    444     double timeUntilNextDisplay = minimumFrameInterval - timeSinceLastDisplay;
     467    double timeUntilLayerTreeHostNeedsDisplay = m_layerTreeHost && m_layerTreeHost->participatesInDisplay() ? m_layerTreeHost->timeUntilNextDisplay() : 0;
     468    double timeUntilNextDisplay = max(minimumFrameInterval - timeSinceLastDisplay, timeUntilLayerTreeHostNeedsDisplay);
    445469
    446470    if (timeUntilNextDisplay > 0) {
     
    454478void DrawingAreaImpl::display()
    455479{
    456     ASSERT(!m_layerTreeHost);
     480    ASSERT(!m_layerTreeHost || m_layerTreeHost->participatesInDisplay());
    457481    ASSERT(!m_isWaitingForDidUpdate);
    458482    ASSERT(!m_inUpdateBackingStoreState);
     
    461485        return;
    462486
    463     if (m_dirtyRegion.isEmpty())
     487    if (m_layerTreeHost) {
     488        if (!m_layerTreeHost->needsDisplay())
     489            return;
     490    } else if (m_dirtyRegion.isEmpty())
    464491        return;
    465492
     
    472499    display(updateInfo);
    473500
    474     if (m_layerTreeHost) {
     501    if (m_layerTreeHost && !m_layerTreeHost->participatesInDisplay()) {
    475502        // The call to update caused layout which turned on accelerated compositing.
    476503        // Don't send an Update message in this case.
     
    506533{
    507534    ASSERT(!m_isPaintingSuspended);
    508     ASSERT(!m_layerTreeHost);
     535    ASSERT(!m_layerTreeHost || m_layerTreeHost->participatesInDisplay());
    509536    ASSERT(!m_webPage->size().isEmpty());
    510537
     
    518545    m_webPage->layoutIfNeeded();
    519546
    520     // The layout may have put the page into accelerated compositing mode, in which case the
    521     // LayerTreeHost is now in charge of displaying.
     547    // The layout may have put the page into accelerated compositing mode. If the LayerTreeHost is
     548    // in charge of displaying, we have nothing more to do.
     549    if (m_layerTreeHost && !m_layerTreeHost->participatesInDisplay())
     550        return;
     551
     552    updateInfo.viewSize = m_webPage->size();
     553
    522554    if (m_layerTreeHost)
    523         return;
    524 
    525     IntRect bounds = m_dirtyRegion.bounds();
    526     ASSERT(m_webPage->bounds().contains(bounds));
    527 
    528     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(bounds.size(), ShareableBitmap::SupportsAlpha);
    529     if (!bitmap->createHandle(updateInfo.bitmapHandle))
    530         return;
    531 
    532     Vector<IntRect> rects = m_dirtyRegion.rects();
    533 
    534     if (shouldPaintBoundsRect(bounds, rects)) {
    535         rects.clear();
    536         rects.append(bounds);
    537     }
    538 
    539     updateInfo.scrollRect = m_scrollRect;
    540     updateInfo.scrollOffset = m_scrollOffset;
    541 
    542     m_dirtyRegion = Region();
    543     m_scrollRect = IntRect();
    544     m_scrollOffset = IntSize();
    545 
    546     OwnPtr<GraphicsContext> graphicsContext = bitmap->createGraphicsContext();
    547    
    548     updateInfo.viewSize = m_webPage->size();
    549     updateInfo.updateRectBounds = bounds;
    550 
    551     graphicsContext->translate(-bounds.x(), -bounds.y());
    552 
    553     for (size_t i = 0; i < rects.size(); ++i) {
    554         m_webPage->drawRect(*graphicsContext, rects[i]);
    555         if (m_webPage->hasPageOverlay())
    556             m_webPage->drawPageOverlay(*graphicsContext, rects[i]);
    557         updateInfo.updateRects.append(rects[i]);
     555        m_layerTreeHost->display(updateInfo);
     556    else {
     557        IntRect bounds = m_dirtyRegion.bounds();
     558        ASSERT(m_webPage->bounds().contains(bounds));
     559
     560        RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(bounds.size(), ShareableBitmap::SupportsAlpha);
     561        if (!bitmap->createHandle(updateInfo.bitmapHandle))
     562            return;
     563
     564        Vector<IntRect> rects = m_dirtyRegion.rects();
     565
     566        if (shouldPaintBoundsRect(bounds, rects)) {
     567            rects.clear();
     568            rects.append(bounds);
     569        }
     570
     571        updateInfo.scrollRect = m_scrollRect;
     572        updateInfo.scrollOffset = m_scrollOffset;
     573
     574        m_dirtyRegion = Region();
     575        m_scrollRect = IntRect();
     576        m_scrollOffset = IntSize();
     577
     578        OwnPtr<GraphicsContext> graphicsContext = bitmap->createGraphicsContext();
     579       
     580        updateInfo.updateRectBounds = bounds;
     581
     582        graphicsContext->translate(-bounds.x(), -bounds.y());
     583
     584        for (size_t i = 0; i < rects.size(); ++i) {
     585            m_webPage->drawRect(*graphicsContext, rects[i]);
     586            if (m_webPage->hasPageOverlay())
     587                m_webPage->drawPageOverlay(*graphicsContext, rects[i]);
     588            updateInfo.updateRects.append(rects[i]);
     589        }
    558590    }
    559591
  • trunk/Source/WebKit2/WebProcess/WebPage/LayerTreeHost.h

    r79593 r82959  
    3939
    4040class LayerTreeContext;
     41class UpdateInfo;
    4142class WebPage;
    4243
     
    6162    virtual void setPageOverlayNeedsDisplay(const WebCore::IntRect&) = 0;
    6263
     64    // If a derived class overrides this function to return true, the derived class must also
     65    // override the functions beneath it.
     66    virtual bool participatesInDisplay() { return false; }
     67    virtual bool needsDisplay() { ASSERT_NOT_REACHED(); return false; }
     68    virtual double timeUntilNextDisplay() { ASSERT_NOT_REACHED(); return 0; }
     69    virtual void display(UpdateInfo&) { ASSERT_NOT_REACHED(); }
     70
    6371protected:
    6472    explicit LayerTreeHost(WebPage*);
Note: See TracChangeset for help on using the changeset viewer.