Changeset 53618 in webkit


Ignore:
Timestamp:
Jan 21, 2010 1:49:02 AM (14 years ago)
Author:
Simon Hausmann
Message:

[Qt] Implement GraphicsLayer for accelerated layer compositing
https://bugs.webkit.org/show_bug.cgi?id=33514

Patch by No'am Rosenthal <noam.rosenthal@nokia.com> on 2010-01-21
Reviewed by Antti Koivisto.

.:

  • WebKit.pri: Addded compile flags to enable accelerated compositing

on versions higher than 4.5

WebCore:

No new tests: tests in LayoutTests/compositing are now relevant for
QtWebkit!

  • WebCore.pro: added accelerated-compositing related files
  • platform/graphics/GraphicsLayer.h: define Qt-specific implementation of GraphicsLayer
  • platform/graphics/qt/GraphicsLayerQt.cpp: Added.

(WebCore::GraphicsLayerQtImpl::): Implementation of GraphicsLayer with
a QGraphicsItem
(WebCore::GraphicsLayerQtImpl::ContentData::ContentData): save
pixmap/color info for directly composited content
(WebCore::GraphicsLayerQtImpl::State::State): save info for syncing
(WebCore::GraphicsLayerQtImpl::GraphicsLayerQtImpl): ctor
(WebCore::GraphicsLayerQtImpl::~GraphicsLayerQtImpl): dtor
(WebCore::GraphicsLayerQtImpl::setBaseTransform): set Qt
transformation in the way WebCore wants it
(WebCore::GraphicsLayerQtImpl::opaqueArea): calculate opaque area
based on info we have
(WebCore::GraphicsLayerQtImpl::boundingRect): reimp QGraphicsItem
(WebCore::GraphicsLayerQtImpl::paint): reimp QGraphicsItem
(WebCore::GraphicsLayerQtImpl::drawContents): draw HTML/Pixmap/Color
(WebCore::GraphicsLayerQtImpl::notifyChange): let WebCore know
something has changed
(WebCore::GraphicsLayerQtImpl::flushChanges): Make the changes appear
on screen by setting them to QGraphicsItems
(WebCore::GraphicsLayerQtImpl::notifyAnimationStarted): let WebCore
know the QAnimation started
(WebCore::GraphicsLayerQt::GraphicsLayerQt): ctor
(WebCore::GraphicsLayerQt::~GraphicsLayerQt): dtor
(WebCore::GraphicsLayer::create): hook for WebCore to know we're
implementing compositing
(WebCore::GraphicsLayer::compositingCoordinatesOrientation): hook for
WebCore to know we use a top-down system
(WebCore::GraphicsLayerQt::setNeedsDisplay): update the display
(WebCore::GraphicsLayerQt::setNeedsDisplayInRect): udpate part of the
display
(WebCore::GraphicsLayerQt::setName): reimp
(WebCore::GraphicsLayerQt::setParent): reimp
(WebCore::GraphicsLayerQt::setChildren): reimp
(WebCore::GraphicsLayerQt::addChild): reimp
(WebCore::GraphicsLayerQt::addChildAtIndex): reimp
(WebCore::GraphicsLayerQt::addChildAbove): reimp
(WebCore::GraphicsLayerQt::addChildBelow): reimp
(WebCore::GraphicsLayerQt::replaceChild): reimp
(WebCore::GraphicsLayerQt::removeFromParent): reimp
(WebCore::GraphicsLayerQt::setMaskLayer): reimp
(WebCore::GraphicsLayerQt::setPosition): reimp
(WebCore::GraphicsLayerQt::setAnchorPoint): reimp
(WebCore::GraphicsLayerQt::setSize): reimp
(WebCore::GraphicsLayerQt::setTransform): reimp
(WebCore::GraphicsLayerQt::setChildrenTransform): reimp
(WebCore::GraphicsLayerQt::setPreserves3D): reimp
(WebCore::GraphicsLayerQt::setMasksToBounds): reimp
(WebCore::GraphicsLayerQt::setDrawsContent): reimp
(WebCore::GraphicsLayerQt::setBackgroundColor): reimp
(WebCore::GraphicsLayerQt::clearBackgroundColor): reimp
(WebCore::GraphicsLayerQt::setContentsOpaque): reimp
(WebCore::GraphicsLayerQt::setBackfaceVisibility): reimp
(WebCore::GraphicsLayerQt::setOpacity): reimp
(WebCore::GraphicsLayerQt::setContentsRect): reimp
(WebCore::GraphicsLayerQt::setContentsToImage): reimp
(WebCore::GraphicsLayerQt::setContentsBackgroundColor): reimp
(WebCore::GraphicsLayerQt::setGeometryOrientation): reimp
(WebCore::GraphicsLayerQt::setContentsOrientation): reimp
(WebCore::GraphicsLayerQt::distributeOpacity): reimp
(WebCore::GraphicsLayerQt::accumulatedOpacity): reimp
(WebCore::GraphicsLayerQt::syncCompositingState): reimp
(WebCore::GraphicsLayerQt::nativeLayer): reimp (QGraphicsItem*)
(WebCore::GraphicsLayerQt::platformLayer): reimp (QGraphicsItem*)
(WebCore::solveEpsilon): copy from AnimationBase.cpp
(WebCore::solveCubicBezierFunction): copy from AniamtionBase.cpp
(WebCore::applyTimingFunction): use WebCore's timing and not Qt's
(WebCore::webkitAnimationToQtAnimationValue): safely figure out
animation values
(WebCore::AnimationQtBase::AnimationQtBase): base class for Qt-based
Webcore-initiated animations
(WebCore::AnimationQtBase::updateState): notify when an animation
starts
(WebCore::AnimationQtBase::duration): reimp QAbstractAnimation
(WebCore::AnimationQt:::AnimationQtBase):
(WebCore::AnimationQt::updateCurrentTime): realize keyframes from
progress
(WebCore::TransformAnimationQt::TransformAnimationQt): ctor
(WebCore::TransformAnimationQt::~TransformAnimationQt): dtor
(WebCore::TransformAnimationQt::applyFrame): set the actual QTransform
based on WebCore TransformOperations
(WebCore::TransformAnimationQt::updateState): change cache mode
(WebCore::OpacityAnimationQt::OpacityAnimationQt):
(WebCore::OpacityAnimationQt::applyFrame): change item's opacity
(WebCore::OpacityAnimationQt::updateState):
(WebCore::GraphicsLayerQt::addAnimation): convert WebCore Animation to
Qt Animation
(WebCore::GraphicsLayerQt::removeAnimationsForProperty):
(WebCore::GraphicsLayerQt::removeAnimationsForKeyframes):
(WebCore::GraphicsLayerQt::pauseAnimation):
(WebCore::GraphicsLayerQt::suspendAnimations):
(WebCore::GraphicsLayerQt::resumeAnimations):

  • platform/graphics/qt/GraphicsLayerQt.h: Added.
  • platform/qt/QWebPageClient.h: virtual functions for QGraphicsWebView

compositing
(QWebPageClient::setRootGraphicsLayer): let QGraphicsWebView know that
compositing has started/ended
(QWebPageClient::markForSync): let QGraphicsWebView know the
compositing layers need to sync, either soon or with the next update

WebKit/qt:

Here we have the QGraphicsWebView support for accelerated compositing

  • Api/qgraphicswebview.cpp:

(QGraphicsWebViewOverlay::q): access to container object
(QGraphicsWebViewOverlay::boundingRect): overlay has same rect as the
webview
(QGraphicsWebViewOverlay::paint): paint everything but the contents
(QGraphicsWebViewPrivate::QGraphicsWebViewPrivate): some vars needed
for accelerated compositing
(QGraphicsWebViewPrivate::):
(QGraphicsWebViewPrivate::~QGraphicsWebViewPrivate):
(QGraphicsWebViewPrivate::setRootGraphicsLayer): make sure we have a
scrollbar overlay, and that the new graphics layer is parented by the
web-view
(QGraphicsWebViewPrivate::markForSync): flush changes at earliest
convenience or during the next draw

(QGraphicsWebViewPrivate::updateCompositingScrollPosition): sync the
position of the compositing layer with the scroll position
(QGraphicsWebViewPrivate::syncLayers): flush changes now
(QGraphicsWebViewPrivate::scroll): make sure we also move the
compositing layer
(QGraphicsWebViewPrivate::update): also update the overlay if needed
(QGraphicsWebView::QGraphicsWebView): initialize overlay with 0
(QGraphicsWebView::paint): paint only contents if we have an overlay,
sync the compositing layers now if needed
(QGraphicsWebView::setPage): also clean up the compositing
(QGraphicsWebView::updateGeometry): also update overlay geo
(QGraphicsWebView::setGeometry): also update overlay geo

  • Api/qgraphicswebview.h: reimp compositing stuff from QWebPageClient
  • Api/qwebsettings.cpp: init new settings flag for compositing as

false
(QWebSettingsPrivate::apply): apply new settings flag for compositing
(QWebSettings::QWebSettings):

  • Api/qwebsettings.h: new settings flag for compositing
  • Api/qwebview.cpp:

(QWebView::setPage): qwebview doesn't support compositing: always false

  • QGVLauncher/main.cpp:

(WebView::WebView): some more cmdline arguments + compositing
(MainWindow::init): some more cmdline arguments
(main): ditto

  • WebCoreSupport/ChromeClientQt.cpp:

(WebCore::ChromeClientQt::attachRootGraphicsLayer): reimp for
accel-compositing
(WebCore::ChromeClientQt::setNeedsOneShotDrawingSynchronization):
reimp for accel compositing
(WebCore::ChromeClientQt::scheduleCompositingLayerSync): reimp for
accel compositing

  • WebCoreSupport/ChromeClientQt.h: reimps for accel compositing
Location:
trunk
Files:
2 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r53543 r53618  
     12010-01-21  No'am Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        Reviewed by Antti Koivisto.
     4
     5        [Qt] Implement GraphicsLayer for accelerated layer compositing
     6        https://bugs.webkit.org/show_bug.cgi?id=33514
     7
     8        * WebKit.pri: Addded compile flags to enable accelerated compositing
     9        on versions higher than 4.5
     10
    1112010-01-20  Tor Arne Vestbø  <tor.arne.vestbo@nokia.com>
    212
  • trunk/WebCore/ChangeLog

    r53617 r53618  
    1616        * platform/graphics/gtk/MediaPlayerPrivateGStreamer.h:
    1717        (WebCore::MediaPlayerPrivate::pipelineReset):
     18
     192010-01-21  No'am Rosenthal  <noam.rosenthal@nokia.com>
     20
     21        Reviewed by Antti Koivisto.
     22
     23        [Qt] Implement GraphicsLayer for accelerated layer compositing
     24        https://bugs.webkit.org/show_bug.cgi?id=33514
     25
     26        No new tests: tests in LayoutTests/compositing are now relevant for
     27        QtWebkit!
     28
     29        * WebCore.pro: added accelerated-compositing related files
     30        * platform/graphics/GraphicsLayer.h: define Qt-specific implementation           of GraphicsLayer
     31        * platform/graphics/qt/GraphicsLayerQt.cpp: Added.
     32        (WebCore::GraphicsLayerQtImpl::): Implementation of GraphicsLayer with
     33        a QGraphicsItem
     34        (WebCore::GraphicsLayerQtImpl::ContentData::ContentData): save
     35        pixmap/color info for directly composited content
     36        (WebCore::GraphicsLayerQtImpl::State::State): save info for syncing
     37        (WebCore::GraphicsLayerQtImpl::GraphicsLayerQtImpl): ctor
     38        (WebCore::GraphicsLayerQtImpl::~GraphicsLayerQtImpl): dtor
     39        (WebCore::GraphicsLayerQtImpl::setBaseTransform): set Qt
     40        transformation in the way WebCore wants it
     41        (WebCore::GraphicsLayerQtImpl::opaqueArea): calculate opaque area
     42        based on info we have
     43        (WebCore::GraphicsLayerQtImpl::boundingRect): reimp QGraphicsItem
     44        (WebCore::GraphicsLayerQtImpl::paint): reimp QGraphicsItem
     45        (WebCore::GraphicsLayerQtImpl::drawContents): draw HTML/Pixmap/Color
     46        (WebCore::GraphicsLayerQtImpl::notifyChange): let WebCore know
     47        something has changed
     48        (WebCore::GraphicsLayerQtImpl::flushChanges): Make the changes appear
     49        on screen by setting them to QGraphicsItems
     50        (WebCore::GraphicsLayerQtImpl::notifyAnimationStarted): let WebCore
     51        know the QAnimation started
     52        (WebCore::GraphicsLayerQt::GraphicsLayerQt): ctor
     53        (WebCore::GraphicsLayerQt::~GraphicsLayerQt): dtor
     54        (WebCore::GraphicsLayer::create): hook for WebCore to know we're
     55        implementing compositing
     56        (WebCore::GraphicsLayer::compositingCoordinatesOrientation): hook for
     57        WebCore to know we use a top-down system
     58        (WebCore::GraphicsLayerQt::setNeedsDisplay): update the display
     59        (WebCore::GraphicsLayerQt::setNeedsDisplayInRect): udpate part of the
     60        display
     61        (WebCore::GraphicsLayerQt::setName): reimp
     62        (WebCore::GraphicsLayerQt::setParent): reimp
     63        (WebCore::GraphicsLayerQt::setChildren): reimp
     64        (WebCore::GraphicsLayerQt::addChild): reimp
     65        (WebCore::GraphicsLayerQt::addChildAtIndex): reimp
     66        (WebCore::GraphicsLayerQt::addChildAbove): reimp
     67        (WebCore::GraphicsLayerQt::addChildBelow): reimp
     68        (WebCore::GraphicsLayerQt::replaceChild): reimp
     69        (WebCore::GraphicsLayerQt::removeFromParent): reimp
     70        (WebCore::GraphicsLayerQt::setMaskLayer): reimp
     71        (WebCore::GraphicsLayerQt::setPosition): reimp
     72        (WebCore::GraphicsLayerQt::setAnchorPoint): reimp
     73        (WebCore::GraphicsLayerQt::setSize): reimp
     74        (WebCore::GraphicsLayerQt::setTransform): reimp
     75        (WebCore::GraphicsLayerQt::setChildrenTransform): reimp
     76        (WebCore::GraphicsLayerQt::setPreserves3D): reimp
     77        (WebCore::GraphicsLayerQt::setMasksToBounds): reimp
     78        (WebCore::GraphicsLayerQt::setDrawsContent): reimp
     79        (WebCore::GraphicsLayerQt::setBackgroundColor): reimp
     80        (WebCore::GraphicsLayerQt::clearBackgroundColor): reimp
     81        (WebCore::GraphicsLayerQt::setContentsOpaque): reimp
     82        (WebCore::GraphicsLayerQt::setBackfaceVisibility): reimp
     83        (WebCore::GraphicsLayerQt::setOpacity): reimp
     84        (WebCore::GraphicsLayerQt::setContentsRect): reimp
     85        (WebCore::GraphicsLayerQt::setContentsToImage): reimp
     86        (WebCore::GraphicsLayerQt::setContentsBackgroundColor): reimp
     87        (WebCore::GraphicsLayerQt::setGeometryOrientation): reimp
     88        (WebCore::GraphicsLayerQt::setContentsOrientation): reimp
     89        (WebCore::GraphicsLayerQt::distributeOpacity): reimp
     90        (WebCore::GraphicsLayerQt::accumulatedOpacity): reimp
     91        (WebCore::GraphicsLayerQt::syncCompositingState): reimp
     92        (WebCore::GraphicsLayerQt::nativeLayer): reimp (QGraphicsItem*)
     93        (WebCore::GraphicsLayerQt::platformLayer): reimp (QGraphicsItem*)
     94        (WebCore::solveEpsilon): copy from AnimationBase.cpp
     95        (WebCore::solveCubicBezierFunction): copy from AniamtionBase.cpp
     96        (WebCore::applyTimingFunction): use WebCore's timing and not Qt's
     97        (WebCore::webkitAnimationToQtAnimationValue): safely figure out
     98        animation values
     99        (WebCore::AnimationQtBase::AnimationQtBase): base class for Qt-based
     100        Webcore-initiated animations
     101        (WebCore::AnimationQtBase::updateState): notify when an animation
     102        starts
     103        (WebCore::AnimationQtBase::duration): reimp QAbstractAnimation
     104        (WebCore::AnimationQt:::AnimationQtBase):
     105        (WebCore::AnimationQt::updateCurrentTime): realize keyframes from
     106        progress
     107        (WebCore::TransformAnimationQt::TransformAnimationQt): ctor
     108        (WebCore::TransformAnimationQt::~TransformAnimationQt): dtor
     109        (WebCore::TransformAnimationQt::applyFrame): set the actual QTransform
     110        based on WebCore TransformOperations
     111        (WebCore::TransformAnimationQt::updateState): change cache mode
     112        (WebCore::OpacityAnimationQt::OpacityAnimationQt):
     113        (WebCore::OpacityAnimationQt::applyFrame): change item's opacity
     114        (WebCore::OpacityAnimationQt::updateState):
     115        (WebCore::GraphicsLayerQt::addAnimation): convert WebCore Animation to
     116        Qt Animation
     117        (WebCore::GraphicsLayerQt::removeAnimationsForProperty):
     118        (WebCore::GraphicsLayerQt::removeAnimationsForKeyframes):
     119        (WebCore::GraphicsLayerQt::pauseAnimation):
     120        (WebCore::GraphicsLayerQt::suspendAnimations):
     121        (WebCore::GraphicsLayerQt::resumeAnimations):
     122        * platform/graphics/qt/GraphicsLayerQt.h: Added.
     123        * platform/qt/QWebPageClient.h: virtual functions for QGraphicsWebView
     124        compositing
     125        (QWebPageClient::setRootGraphicsLayer): let QGraphicsWebView know that
     126        compositing has started/ended
     127        (QWebPageClient::markForSync): let QGraphicsWebView know the
     128        compositing layers need to sync, either soon or with the next update
    18129
    191302010-01-21  No'am Rosenthal  <noam.rosenthal@nokia.com>
  • trunk/WebCore/WebCore.pro

    r53611 r53618  
    27232723    }
    27242724}
     2725contains(DEFINES, WTF_USE_ACCELERATED_COMPOSITING) {
     2726HEADERS += \
     2727    rendering/RenderLayerBacking.h \
     2728    rendering/RenderLayerCompositor.h \
     2729    platform/graphics/GraphicsLayer.h \
     2730    platform/graphics/GraphicsLayerClient.h \
     2731    platform/graphics/qt/GraphicsLayerQt.h
     2732SOURCES += \
     2733    platform/graphics/GraphicsLayer.cpp \
     2734    platform/graphics/qt/GraphicsLayerQt.cpp \
     2735    rendering/RenderLayerBacking.cpp \
     2736    rendering/RenderLayerCompositor.cpp
     2737}
    27252738
    27262739symbian {
  • trunk/WebCore/platform/graphics/GraphicsLayer.h

    r53510 r53618  
    6060typedef void* NativeLayer;
    6161}
     62#elif PLATFORM(QT)
     63class QGraphicsItem;
     64typedef QGraphicsItem PlatformLayer;
     65typedef QGraphicsItem* NativeLayer;
    6266#else
    6367typedef void* PlatformLayer;
  • trunk/WebCore/platform/qt/QWebPageClient.h

    r51171 r53618  
    3030#include <QCursor>
    3131#endif
     32
    3233#include <QRect>
     34class QGraphicsItem;
    3335
    3436class QWebPageClient {
     
    4042    virtual void setInputMethodEnabled(bool enable) = 0;
    4143    virtual bool inputMethodEnabled() const = 0;
     44#if USE(ACCELERATED_COMPOSITING)
     45    // this gets called when we start/stop compositing.
     46    virtual void setRootGraphicsLayer(QGraphicsItem* layer) {}
     47
     48    // this gets called when the compositor wants us to sync the layers
     49    // if scheduleSync is true, we schedule a sync ourselves. otherwise,
     50    // we wait for the next update and sync the layers then.
     51    virtual void markForSync(bool scheduleSync = false) {}
     52#endif
     53
    4254#if QT_VERSION >= 0x040600
    4355    virtual void setInputMethodHint(Qt::InputMethodHint hint, bool enable) = 0;
  • trunk/WebKit.pri

    r53319 r53618  
    4646    DEPENDPATH += $$PWD/WebKit/qt/Api
    4747}
     48greaterThan(QT_MINOR_VERSION, 5):DEFINES += WTF_USE_ACCELERATED_COMPOSITING
    4849
    4950!mac:!unix|symbian {
  • trunk/WebKit/qt/Api/qgraphicswebview.cpp

    r52552 r53618  
    2323
    2424#include "qwebframe.h"
     25#include "qwebframe_p.h"
    2526#include "qwebpage.h"
    2627#include "qwebpage_p.h"
    2728#include "QWebPageClient.h"
    28 #include <QtGui/QGraphicsScene>
    29 #include <QtGui/QGraphicsView>
     29#include <FrameView.h>
     30#include <QtCore/qsharedpointer.h>
     31#include <QtCore/qtimer.h>
    3032#include <QtGui/qapplication.h>
     33#include <QtGui/qgraphicsscene.h>
    3134#include <QtGui/qgraphicssceneevent.h>
     35#include <QtGui/qgraphicsview.h>
     36#include <QtGui/qpixmapcache.h>
    3237#include <QtGui/qstyleoption.h>
    3338#if defined(Q_WS_X11)
    3439#include <QX11Info>
     40#endif
     41#include <Settings.h>
     42
     43#if USE(ACCELERATED_COMPOSITING)
     44
     45// the overlay is here for one reason only: to have the scroll-bars and other
     46// extra UI elements appear on top of any QGraphicsItems created by CSS compositing layers
     47class QGraphicsWebViewOverlay : public QGraphicsItem {
     48    public:
     49    QGraphicsWebViewOverlay(QGraphicsWebView* view)
     50            :QGraphicsItem(view)
     51            , q(view)
     52    {
     53        setPos(0, 0);
     54        setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
     55        setCacheMode(QGraphicsItem::DeviceCoordinateCache);
     56    }
     57
     58    QRectF boundingRect() const
     59    {
     60        return q->boundingRect();
     61    }
     62
     63    void paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget*)
     64    {
     65        q->page()->mainFrame()->render(painter, static_cast<QWebFrame::RenderLayer>(QWebFrame::AllLayers&(~QWebFrame::ContentsLayer)), options->exposedRect.toRect());
     66    }
     67
     68    friend class QGraphicsWebView;
     69    QGraphicsWebView* q;
     70};
     71
    3572#endif
    3673
     
    4077        : q(parent)
    4178        , page(0)
    42     {}
     79#if USE(ACCELERATED_COMPOSITING)
     80        , rootGraphicsLayer(0)
     81        , shouldSync(true)
     82#endif
     83    {
     84#if USE(ACCELERATED_COMPOSITING)
     85        // the overlay and stays alive for the lifetime of
     86        // this QGraphicsWebView as the scrollbars are needed when there's no compositing
     87        q->setFlag(QGraphicsItem::ItemUsesExtendedStyleOption);
     88#endif
     89    }
    4390
    4491    virtual ~QGraphicsWebViewPrivate();
     
    62109    virtual QObject* pluginParent() const;
    63110
     111#if USE(ACCELERATED_COMPOSITING)
     112    virtual void setRootGraphicsLayer(QGraphicsItem* layer);
     113    virtual void markForSync(bool scheduleSync);
     114    void updateCompositingScrollPosition();
     115#endif
     116
     117    void syncLayers();
    64118    void _q_doLoadFinished(bool success);
    65119
    66120    QGraphicsWebView* q;
    67121    QWebPage* page;
     122#if USE(ACCELERATED_COMPOSITING)
     123    QGraphicsItem* rootGraphicsLayer;
     124
     125    // the overlay gets instantiated when the root layer is attached, and get deleted when it's detached
     126    QSharedPointer<QGraphicsWebViewOverlay> overlay;
     127
     128    // we need to sync the layers if we get a special call from the WebCore
     129    // compositor telling us to do so. We'll get that call from ChromeClientQt
     130    bool shouldSync;
     131
     132    // we need to put the root graphics layer behind the overlay (which contains the scrollbar)
     133    enum { RootGraphicsLayerZValue, OverlayZValue };
     134#endif
    68135};
    69136
    70137QGraphicsWebViewPrivate::~QGraphicsWebViewPrivate()
    71138{
     139#if USE(ACCELERATED_COMPOSITING)
     140    if (rootGraphicsLayer) {
     141        // we don't need to delete the root graphics layer
     142        // The lifecycle is managed in GraphicsLayerQt.cpp
     143        rootGraphicsLayer->setParentItem(0);
     144        q->scene()->removeItem(rootGraphicsLayer);
     145    }
     146#endif
     147}
     148
     149#if USE(ACCELERATED_COMPOSITING)
     150void QGraphicsWebViewPrivate::setRootGraphicsLayer(QGraphicsItem* layer)
     151{
     152    if (rootGraphicsLayer) {
     153        rootGraphicsLayer->setParentItem(0);
     154        q->scene()->removeItem(rootGraphicsLayer);
     155        QWebFramePrivate::core(q->page()->mainFrame())->view()->syncCompositingStateRecursive();
     156    }
     157
     158    rootGraphicsLayer = layer;
     159
     160    if (layer) {
     161        layer->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
     162        layer->setParentItem(q);
     163        layer->setZValue(RootGraphicsLayerZValue);
     164        if (!overlay) {
     165            overlay = QSharedPointer<QGraphicsWebViewOverlay>(new QGraphicsWebViewOverlay(q));
     166            overlay->setZValue(OverlayZValue);
     167        }
     168        updateCompositingScrollPosition();
     169    } else {
     170        // we don't have compositing layers, we can render the scrollbars and content in one go
     171        overlay.clear();
     172    }
     173}
     174
     175void QGraphicsWebViewPrivate::markForSync(bool scheduleSync)
     176{
     177    shouldSync = true;
     178    if (scheduleSync)
     179        QTimer::singleShot(0, q, SLOT(syncLayers()));
     180}
     181
     182void QGraphicsWebViewPrivate::updateCompositingScrollPosition()
     183{
     184    if (rootGraphicsLayer && q->page() && q->page()->mainFrame()) {
     185        const QPoint scrollPosition = q->page()->mainFrame()->scrollPosition();
     186        rootGraphicsLayer->setPos(-scrollPosition);
     187    }
     188}
     189
     190#endif
     191
     192void QGraphicsWebViewPrivate::syncLayers()
     193{
     194#if USE(ACCELERATED_COMPOSITING)
     195    if (shouldSync) {
     196        QWebFramePrivate::core(q->page()->mainFrame())->view()->syncCompositingStateRecursive();
     197        shouldSync = false;
     198    }
     199#endif
    72200}
    73201
     
    84212{
    85213    q->scroll(qreal(dx), qreal(dy), QRectF(rectToScroll));
     214#if USE(ACCELERATED_COMPOSITING)
     215    updateCompositingScrollPosition();
     216#endif
    86217}
    87218
     
    89220{
    90221    q->update(QRectF(dirtyRect));
     222#if USE(ACCELERATED_COMPOSITING)
     223    if (overlay)
     224        overlay->update(QRectF(dirtyRect));
     225#endif
    91226}
    92227
     
    249384#endif
    250385    setFocusPolicy(Qt::StrongFocus);
     386    setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
    251387}
    252388
     
    298434void QGraphicsWebView::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget*)
    299435{
    300     page()->mainFrame()->render(painter, option->exposedRect.toRect());
     436#if USE(ACCELERATED_COMPOSITING)
     437    page()->mainFrame()->render(painter, d->overlay ? QWebFrame::ContentsLayer : QWebFrame::AllLayers, option->exposedRect.toAlignedRect());
     438    d->syncLayers();
     439#else
     440    page()->mainFrame()->render(painter, QWebFrame::AllLayers, option->exposedRect.toRect());
     441#endif
    301442}
    302443
     
    426567    if (!d->page)
    427568        return;
     569#if USE(ACCELERATED_COMPOSITING)
     570    if (d->overlay)
     571        d->overlay->prepareGeometryChange();
     572#endif
    428573    d->page->d->client = d; // set the page client
    429574
     
    529674void QGraphicsWebView::updateGeometry()
    530675{
     676
     677#if USE(ACCELERATED_COMPOSITING)
     678    if (d->overlay)
     679        d->overlay->prepareGeometryChange();
     680#endif
     681
    531682    QGraphicsWidget::updateGeometry();
    532683
     
    543694{
    544695    QGraphicsWidget::setGeometry(rect);
     696
     697#if USE(ACCELERATED_COMPOSITING)
     698    if (d->overlay)
     699        d->overlay->prepareGeometryChange();
     700#endif
    545701
    546702    if (!d->page)
  • trunk/WebKit/qt/Api/qgraphicswebview.h

    r50652 r53618  
    135135private:
    136136    Q_PRIVATE_SLOT(d, void _q_doLoadFinished(bool success))
     137    // we don't want to change the moc based on USE() macro, so this function is here
     138    // but will be empty if ACCLERATED_COMPOSITING is disabled
     139    Q_PRIVATE_SLOT(d, void syncLayers())
    137140
    138141    QGraphicsWebViewPrivate* const d;
  • trunk/WebKit/qt/Api/qwebsettings.cpp

    r53060 r53618  
    153153                                      global->attributes.value(QWebSettings::JavascriptEnabled));
    154154        settings->setJavaScriptEnabled(value);
    155 
     155#if USE(ACCELERATED_COMPOSITING)
     156        value = attributes.value(QWebSettings::AcceleratedCompositingEnabled,
     157                                      global->attributes.value(QWebSettings::AcceleratedCompositingEnabled));
     158
     159        settings->setAcceleratedCompositingEnabled(value);
     160#endif
    156161        value = attributes.value(QWebSettings::JavascriptCanOpenWindows,
    157162                                      global->attributes.value(QWebSettings::JavascriptCanOpenWindows));
     
    390395    d->attributes.insert(QWebSettings::LocalStorageEnabled, false);
    391396    d->attributes.insert(QWebSettings::LocalContentCanAccessRemoteUrls, false);
     397    d->attributes.insert(QWebSettings::AcceleratedCompositingEnabled, false);
    392398    d->offlineStorageDefaultQuota = 5 * 1024 * 1024;
    393399    d->defaultTextEncoding = QLatin1String("iso-8859-1");
  • trunk/WebKit/qt/Api/qwebsettings.h

    r53060 r53618  
    6969        LocalContentCanAccessRemoteUrls,
    7070        DnsPrefetchEnabled,
    71         XSSAuditorEnabled
     71        XSSAuditorEnabled,
     72        AcceleratedCompositingEnabled
    7273    };
    7374    enum WebGraphic {
  • trunk/WebKit/qt/Api/qwebview.cpp

    r52256 r53618  
    2323#include "qwebview.h"
    2424
     25#include "Page.h"
    2526#include "QWebPageClient.h"
     27#include "Settings.h"
    2628#include "qwebframe.h"
    2729#include "qwebpage_p.h"
    28 
    2930#include "qbitmap.h"
    3031#include "qevent.h"
     
    248249    }
    249250    setAttribute(Qt::WA_OpaquePaintEvent, d->page);
     251#if USE(ACCELERATED_COMPOSITING)
     252    d->page->d->page->settings()->setAcceleratedCompositingEnabled(false);
     253#endif
    250254    update();
    251255}
  • trunk/WebKit/qt/ChangeLog

    r53614 r53618  
     12010-01-21  No'am Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        Reviewed by Antti Koivisto.
     4
     5        [Qt] Implement GraphicsLayer for accelerated layer compositing
     6        https://bugs.webkit.org/show_bug.cgi?id=33514
     7
     8        Here we have the QGraphicsWebView support for accelerated compositing
     9
     10        * Api/qgraphicswebview.cpp:
     11        (QGraphicsWebViewOverlay::q): access to container object
     12        (QGraphicsWebViewOverlay::boundingRect): overlay has same rect as the
     13        webview
     14        (QGraphicsWebViewOverlay::paint): paint everything but the contents
     15        (QGraphicsWebViewPrivate::QGraphicsWebViewPrivate): some vars needed
     16        for accelerated compositing
     17        (QGraphicsWebViewPrivate::):
     18        (QGraphicsWebViewPrivate::~QGraphicsWebViewPrivate):
     19        (QGraphicsWebViewPrivate::setRootGraphicsLayer): make sure we have a
     20        scrollbar overlay, and that the new graphics layer is parented by the
     21        web-view
     22        (QGraphicsWebViewPrivate::markForSync): flush changes at earliest
     23        convenience or during the next draw
     24
     25        (QGraphicsWebViewPrivate::updateCompositingScrollPosition): sync the
     26        position of the compositing layer with the scroll position
     27        (QGraphicsWebViewPrivate::syncLayers): flush changes now
     28        (QGraphicsWebViewPrivate::scroll): make sure we also move the
     29        compositing layer
     30        (QGraphicsWebViewPrivate::update): also update the overlay if needed
     31        (QGraphicsWebView::QGraphicsWebView): initialize overlay with 0
     32        (QGraphicsWebView::paint): paint only contents if we have an overlay,
     33        sync the compositing layers now if needed
     34        (QGraphicsWebView::setPage): also clean up the compositing
     35        (QGraphicsWebView::updateGeometry): also update overlay geo
     36        (QGraphicsWebView::setGeometry): also update overlay geo
     37        * Api/qgraphicswebview.h: reimp compositing stuff from QWebPageClient
     38        * Api/qwebsettings.cpp: init new settings flag for compositing as
     39        false
     40        (QWebSettingsPrivate::apply): apply new settings flag for compositing
     41        (QWebSettings::QWebSettings):
     42        * Api/qwebsettings.h: new settings flag for compositing
     43        * Api/qwebview.cpp:
     44        (QWebView::setPage): qwebview doesn't support compositing: always false
     45        * QGVLauncher/main.cpp:
     46        (WebView::WebView): some more cmdline arguments + compositing
     47        (MainWindow::init): some more cmdline arguments
     48        (main): ditto
     49        * WebCoreSupport/ChromeClientQt.cpp:
     50        (WebCore::ChromeClientQt::attachRootGraphicsLayer): reimp for
     51        accel-compositing
     52        (WebCore::ChromeClientQt::setNeedsOneShotDrawingSynchronization):
     53        reimp for accel compositing
     54        (WebCore::ChromeClientQt::scheduleCompositingLayerSync): reimp for
     55        accel compositing
     56        * WebCoreSupport/ChromeClientQt.h: reimps for accel compositing
     57
    1582010-01-21  Benjamin Poulain  <benjamin.poulain@nokia.com>
    259
  • trunk/WebKit/qt/QGVLauncher/main.cpp

    r52713 r53618  
    7373        : QGraphicsWebView(parent)
    7474    {
     75        if (QApplication::instance()->arguments().contains("--cacheWebView"))
     76            setCacheMode(QGraphicsItem::DeviceCoordinateCache);
    7577    }
    7678    void setYRotation(qreal angle)
     
    254256
    255257        view->setScene(scene->scene());
     258        const QStringList arguments = QApplication::instance()->arguments();
     259        const int indexOfViewportUpdateMode = arguments.indexOf("--updateMode");
     260        if (indexOfViewportUpdateMode > 1 && indexOfViewportUpdateMode < arguments.count() - 1) {
     261            const QString updateMode = arguments[indexOfViewportUpdateMode+1] + "ViewportUpdate";
     262            view->setViewportUpdateMode(static_cast<QGraphicsView::ViewportUpdateMode>(QGraphicsView::staticMetaObject.enumerator(QGraphicsView::staticMetaObject.indexOfEnumerator("ViewportUpdateMode")).keysToValue(updateMode.toAscii())));
     263        }
    256264
    257265        setCentralWidget(view);
     
    448456{
    449457    QApplication app(argc, argv);
     458    if (app.arguments().contains("--help")) {
     459        qDebug() << "Usage: QGVLauncher [--url url] [--compositing] [--updateMode Full|Minimal|Smart|No|BoundingRect] [--cacheWebView]\n";
     460        return 0;
     461    }
    450462    QString url = QString("file://%1/%2").arg(QDir::homePath()).arg(QLatin1String("index.html"));
    451463
     
    459471
    460472    const QStringList args = app.arguments();
    461     if (args.count() > 1)
     473    const int indexOfUrl = args.indexOf("--url");
     474    if (indexOfUrl > 0 && indexOfUrl < args.count() - 1)
     475        url = args.at(indexOfUrl+1);
     476    else if (args.count() > 1)
    462477        url = args.at(1);
     478    if (args.contains("--compositing"))
     479        QWebSettings::globalSettings()->setAttribute(QWebSettings::AcceleratedCompositingEnabled, true);
    463480
    464481    MainWindow* window = new MainWindow;
    465482    window->load(url);
    466483
    467     for (int i = 2; i < args.count(); i++)
    468         window->newWindow(args.at(i));
     484    for (int i = 2; i < args.count(); ++i)
     485        if (!args.at(i).startsWith("-") && !args.at(i - 1).startsWith("-"))
     486            window->newWindow(args.at(i));
    469487
    470488    window->show();
  • trunk/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp

    r53610 r53618  
    2626 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829#include "config.h"
    2930#include "ChromeClientQt.h"
     
    4344#include "SecurityOrigin.h"
    4445
     46#include <qdebug.h>
     47#include <qtextdocument.h>
     48#include <qtooltip.h>
     49
    4550#include "qwebpage.h"
    4651#include "qwebpage_p.h"
     
    5055#include "qwebview.h"
    5156
    52 #include <qtooltip.h>
    53 #include <qtextdocument.h>
    54 
    55 namespace WebCore
    56 {
    57 
     57#if USE(ACCELERATED_COMPOSITING)
     58#include "GraphicsLayerQt.h"
     59#endif
     60
     61namespace WebCore {
    5862
    5963ChromeClientQt::ChromeClientQt(QWebPage* webPage)
     
    467471}
    468472
     473#if USE(ACCELERATED_COMPOSITING)
     474void ChromeClientQt::attachRootGraphicsLayer(Frame* frame, GraphicsLayer* graphicsLayer)
     475{   
     476    if (platformPageClient())
     477        platformPageClient()->setRootGraphicsLayer(graphicsLayer ? graphicsLayer->nativeLayer() : 0);
     478}
     479
     480void ChromeClientQt::setNeedsOneShotDrawingSynchronization()
     481{
     482    // we want the layers to synchronize next time we update the screen anyway
     483    if (platformPageClient())
     484        platformPageClient()->markForSync(false);
     485}
     486
     487void ChromeClientQt::scheduleCompositingLayerSync()
     488{
     489    // we want the layers to synchronize ASAP
     490    if (platformPageClient())
     491        platformPageClient()->markForSync(true);
     492}
     493#endif
     494
    469495QtAbstractWebPopup* ChromeClientQt::createSelectPopup()
    470496{
  • trunk/WebKit/qt/WebCoreSupport/ChromeClientQt.h

    r53610 r53618  
    124124        virtual void reachedMaxAppCacheSize(int64_t spaceNeeded);
    125125#endif
     126
     127#if USE(ACCELERATED_COMPOSITING)
     128        // see ChromeClient.h
     129        // this is a hook for WebCore to tell us what we need to do with the GraphicsLayers
     130        virtual void attachRootGraphicsLayer(Frame*, GraphicsLayer*);
     131        virtual void setNeedsOneShotDrawingSynchronization();
     132        virtual void scheduleCompositingLayerSync();
     133#endif
     134
    126135        virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>);
    127136
Note: See TracChangeset for help on using the changeset viewer.