Changeset 107707 in webkit


Ignore:
Timestamp:
Feb 14, 2012 4:53:30 AM (12 years ago)
Author:
noam.rosenthal@nokia.com
Message:

[Qt][Texmap] Refactor backing-store code in TextureMapper
https://bugs.webkit.org/show_bug.cgi?id=78305

Source/WebCore:

Instead of dealing with tiling inside of TextureMapperNode, we now deal with that in a new
TextureMapperBackingStore class. Since the class is abstract, WebKit2 can overload it to
support remotely-managed tiles.
The backing-store for directly composited images is handled separately, in a new class
TextureMapperCompositedImage. The TextureMapper implementation decides the dimension of
the tiles, for example 2000 in the case of OpenGL.
Also, directly composited content is now handled correctly, by painting it after the regular
content and not as part of the same texture.

To make this work, the functions in TextureMapperPlatformLayers had to become non-const,
thus the changes to that file and GraphicsContext3DQt.

Reviewed by Kenneth Rohde Christiansen.

No new functionality, no new tests.

  • GNUmakefile.list.am:
  • Target.pri:
  • WebCore.gypi:
  • platform/graphics/opengl/TextureMapperGL.h:

(WebCore::TextureMapperGL::maxTextureDimension):

  • platform/graphics/qt/GraphicsContext3DQt.cpp:

(GraphicsContext3DPrivate):
(WebCore::GraphicsContext3DPrivate::paintToTextureMapper):

  • platform/graphics/texmap/GraphicsLayerTextureMapper.cpp:

(WebCore::GraphicsLayerTextureMapper::GraphicsLayerTextureMapper):
(WebCore::GraphicsLayerTextureMapper::didSynchronize):
(WebCore::GraphicsLayerTextureMapper::setNeedsDisplay):
(WebCore::GraphicsLayerTextureMapper::setContentsNeedsDisplay):
(WebCore::GraphicsLayerTextureMapper::setNeedsDisplayInRect):
(WebCore::GraphicsLayerTextureMapper::addChildBelow):
(WebCore):
(WebCore::GraphicsLayerTextureMapper::getContentsLayer):
(WebCore::GraphicsLayerTextureMapper::setContentsToImage):
(WebCore::GraphicsLayerTextureMapper::setContentsToMedia):

  • platform/graphics/texmap/GraphicsLayerTextureMapper.h:

(GraphicsLayerTextureMapper):
(WebCore::GraphicsLayerTextureMapper::platformLayer):
(WebCore::GraphicsLayerTextureMapper::needsDisplay):
(WebCore::GraphicsLayerTextureMapper::needsDisplayRect):

  • platform/graphics/texmap/TextureMapper.cpp:
  • platform/graphics/texmap/TextureMapper.h:

(WebCore::TextureMapper::maxTextureDimension):
(TextureMapper):

  • platform/graphics/texmap/TextureMapperBackingStore.cpp: Added.
  • platform/graphics/texmap/TextureMapperBackingStore.h: Added.
  • platform/graphics/texmap/TextureMapperNode.cpp:

(WebCore::TextureMapperNode::backingStore):
(WebCore::TextureMapperNode::updateBackingStore):
(WebCore::TextureMapperNode::paint):
(WebCore::TextureMapperNode::paintSelf):
(WebCore::TextureMapperNode::intermediateSurfaceRect):
(WebCore::TextureMapperNode::paintRecursive):
(WebCore::TextureMapperNode::syncCompositingStateSelf):
(WebCore::TextureMapperNode::syncCompositingState):

  • platform/graphics/texmap/TextureMapperNode.h:

(TextureMapperPaintOptions):
(WebCore::TextureMapperPaintOptions::TextureMapperPaintOptions):
(WebCore::TextureMapperNode::TextureMapperNode):
(TextureMapperNode):
(WebCore::TextureMapperNode::setBackingStore):
(WebCore::TextureMapperNode::texture):
(WebCore::TextureMapperNode::layerRect):
(WebCore::TextureMapperNode::createBackingStore):
(State):
(WebCore::TextureMapperNode::State::State):

  • platform/graphics/texmap/TextureMapperPlatformLayer.h:

(TextureMapperPlatformLayer):
(WebCore::TextureMapperPlatformLayer::swapBuffers):

Source/WebKit2:

Move the backing-store code to LayerTreeBackingStore, implementing the virtual functions
in TextureMapperBackingStore.
We save the double-buffered tile in the backing-store, and then convert them to regular
tiles in updateContents, based on the order of painting.
Use TextureMapperCompositedImage for images instead of saving our own composited image
registry.

Reviewed by Kenneth Rohde Christiansen.

  • Target.pri:
  • UIProcess/LayerTreeHostProxy.h:

(WebKit):
(LayerTreeHostProxy):

  • UIProcess/qt/LayerBackingStore.cpp: Added.
  • UIProcess/qt/LayerBackingStore.h: Added.
  • UIProcess/qt/LayerTreeHostProxyQt.cpp:

(WebKit::LayerTreeHostProxy::createLayer):
(WebKit::LayerTreeHostProxy::syncLayerParameters):
(WebKit::LayerTreeHostProxy::getBackingStore):
(WebKit::LayerTreeHostProxy::createTile):
(WebKit::LayerTreeHostProxy::removeTile):
(WebKit::LayerTreeHostProxy::updateTile):
(WebKit::LayerTreeHostProxy::createImage):
(WebKit::LayerTreeHostProxy::assignImageToLayer):
(WebKit::LayerTreeHostProxy::purgeGLResources):

  • WebProcess.pro:
Location:
trunk/Source
Files:
4 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r107706 r107707  
     12012-02-14  No'am Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        [Qt][Texmap] Refactor backing-store code in TextureMapper
     4        https://bugs.webkit.org/show_bug.cgi?id=78305
     5
     6        Instead of dealing with tiling inside of TextureMapperNode, we now deal with that in a new
     7        TextureMapperBackingStore class. Since the class is abstract, WebKit2 can overload it to
     8        support remotely-managed tiles.
     9        The backing-store for directly composited images is handled separately, in a new class
     10        TextureMapperCompositedImage. The TextureMapper implementation decides the dimension of
     11        the tiles, for example 2000 in the case of OpenGL.
     12        Also, directly composited content is now handled correctly, by painting it after the regular
     13        content and not as part of the same texture.
     14
     15        To make this work, the functions in TextureMapperPlatformLayers had to become non-const,
     16        thus the changes to that file and GraphicsContext3DQt.
     17
     18        Reviewed by Kenneth Rohde Christiansen.
     19
     20        No new functionality, no new tests.
     21
     22        * GNUmakefile.list.am:
     23        * Target.pri:
     24        * WebCore.gypi:
     25        * platform/graphics/opengl/TextureMapperGL.h:
     26        (WebCore::TextureMapperGL::maxTextureDimension):
     27        * platform/graphics/qt/GraphicsContext3DQt.cpp:
     28        (GraphicsContext3DPrivate):
     29        (WebCore::GraphicsContext3DPrivate::paintToTextureMapper):
     30        * platform/graphics/texmap/GraphicsLayerTextureMapper.cpp:
     31        (WebCore::GraphicsLayerTextureMapper::GraphicsLayerTextureMapper):
     32        (WebCore::GraphicsLayerTextureMapper::didSynchronize):
     33        (WebCore::GraphicsLayerTextureMapper::setNeedsDisplay):
     34        (WebCore::GraphicsLayerTextureMapper::setContentsNeedsDisplay):
     35        (WebCore::GraphicsLayerTextureMapper::setNeedsDisplayInRect):
     36        (WebCore::GraphicsLayerTextureMapper::addChildBelow):
     37        (WebCore):
     38        (WebCore::GraphicsLayerTextureMapper::getContentsLayer):
     39        (WebCore::GraphicsLayerTextureMapper::setContentsToImage):
     40        (WebCore::GraphicsLayerTextureMapper::setContentsToMedia):
     41        * platform/graphics/texmap/GraphicsLayerTextureMapper.h:
     42        (GraphicsLayerTextureMapper):
     43        (WebCore::GraphicsLayerTextureMapper::platformLayer):
     44        (WebCore::GraphicsLayerTextureMapper::needsDisplay):
     45        (WebCore::GraphicsLayerTextureMapper::needsDisplayRect):
     46        * platform/graphics/texmap/TextureMapper.cpp:
     47        * platform/graphics/texmap/TextureMapper.h:
     48        (WebCore::TextureMapper::maxTextureDimension):
     49        (TextureMapper):
     50        * platform/graphics/texmap/TextureMapperBackingStore.cpp: Added.
     51        * platform/graphics/texmap/TextureMapperBackingStore.h: Added.
     52        * platform/graphics/texmap/TextureMapperNode.cpp:
     53        (WebCore::TextureMapperNode::backingStore):
     54        (WebCore::TextureMapperNode::updateBackingStore):
     55        (WebCore::TextureMapperNode::paint):
     56        (WebCore::TextureMapperNode::paintSelf):
     57        (WebCore::TextureMapperNode::intermediateSurfaceRect):
     58        (WebCore::TextureMapperNode::paintRecursive):
     59        (WebCore::TextureMapperNode::syncCompositingStateSelf):
     60        (WebCore::TextureMapperNode::syncCompositingState):
     61        * platform/graphics/texmap/TextureMapperNode.h:
     62        (TextureMapperPaintOptions):
     63        (WebCore::TextureMapperPaintOptions::TextureMapperPaintOptions):
     64        (WebCore::TextureMapperNode::TextureMapperNode):
     65        (TextureMapperNode):
     66        (WebCore::TextureMapperNode::setBackingStore):
     67        (WebCore::TextureMapperNode::texture):
     68        (WebCore::TextureMapperNode::layerRect):
     69        (WebCore::TextureMapperNode::createBackingStore):
     70        (State):
     71        (WebCore::TextureMapperNode::State::State):
     72        * platform/graphics/texmap/TextureMapperPlatformLayer.h:
     73        (TextureMapperPlatformLayer):
     74        (WebCore::TextureMapperPlatformLayer::swapBuffers):
     75
    1762012-02-14  Shinya Kawanaka  <shinyak@google.com>
    277
  • trunk/Source/WebCore/GNUmakefile.list.am

    r107662 r107707  
    57505750        Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp \
    57515751        Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h \
     5752        Source/WebCore/platform/graphics/texmap/TextureMapperBackingStore.cpp \
     5753        Source/WebCore/platform/graphics/texmap/TextureMapperBackingStore.h \
    57525754        Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.cpp \
    57535755        Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.h \
     
    57725774        Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp \
    57735775        Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h \
     5776        Source/WebCore/platform/graphics/texmap/TextureMapperBackingStore.cpp \
     5777        Source/WebCore/platform/graphics/texmap/TextureMapperBackingStore.h \
    57745778        Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.cpp \
    57755779        Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.h \
  • trunk/Source/WebCore/Target.pri

    r107558 r107707  
    39563956        platform/graphics/texmap/TextureMapper.h \
    39573957        platform/graphics/texmap/TextureMapperAnimation.h \
     3958        platform/graphics/texmap/TextureMapperBackingStore.h \
    39583959        platform/graphics/texmap/TextureMapperImageBuffer.h \
    39593960        platform/graphics/texmap/TextureMapperNode.h \
     
    39643965        platform/graphics/texmap/TextureMapper.cpp \
    39653966        platform/graphics/texmap/TextureMapperAnimation.cpp \
     3967        platform/graphics/texmap/TextureMapperBackingStore.cpp \
    39663968        platform/graphics/texmap/TextureMapperImageBuffer.cpp \
    39673969        platform/graphics/texmap/TextureMapperNode.cpp \
  • trunk/Source/WebCore/WebCore.gypi

    r107558 r107707  
    35873587            'platform/graphics/texmap/TextureMapperAnimation.cpp',
    35883588            'platform/graphics/texmap/TextureMapperAnimation.h',
     3589            'platform/graphics/texmap/TextureMapperBackingStore.cpp',
     3590            'platform/graphics/texmap/TextureMapperBackingStore.h',
    35893591            'platform/graphics/texmap/TextureMapperImageBuffer.cpp',
    35903592            'platform/graphics/texmap/TextureMapperImageBuffer.h',
  • trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.h

    r106659 r107707  
    4747    virtual void endPainting();
    4848    virtual void endClip();
     49    virtual IntSize maxTextureSize() { return IntSize(2000, 2000); }
    4950    virtual PassRefPtr<BitmapTexture> createTexture();
    5051    virtual const char* type() const;
  • trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp

    r106659 r107707  
    7575    QGLWidget* getViewportGLWidget();
    7676#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
    77     virtual void paintToTextureMapper(TextureMapper*, const FloatRect& target, const TransformationMatrix&, float opacity, BitmapTexture* mask) const;
     77    virtual void paintToTextureMapper(TextureMapper*, const FloatRect& target, const TransformationMatrix&, float opacity, BitmapTexture* mask);
    7878#endif
    7979
     
    143143
    144144#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
    145 void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity, BitmapTexture* mask) const
     145void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity, BitmapTexture* mask)
    146146{
    147147    blitMultisampleFramebufferAndRestoreContext();
  • trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp

    r106190 r107707  
    2929    , m_node(adoptPtr(new TextureMapperNode()))
    3030    , m_changeMask(0)
     31    , m_needsDisplay(false)
     32    , m_contentsLayer(0)
    3133    , m_animationStartedTimer(this, &GraphicsLayerTextureMapper::animationStartedTimerFired)
    3234{
     
    4547    m_syncQueued = false;
    4648    m_changeMask = 0;
    47     m_pendingContent.needsDisplay = false;
    48     m_pendingContent.needsDisplayRect = IntRect();
     49    m_needsDisplay = false;
     50    m_needsDisplayRect = IntRect();
    4951}
    5052
     
    6264void GraphicsLayerTextureMapper::setNeedsDisplay()
    6365{
    64     m_pendingContent.needsDisplay = true;
     66    m_needsDisplay = true;
    6567    notifyChange(TextureMapperNode::DisplayChange);
    6668}
     
    7072void GraphicsLayerTextureMapper::setContentsNeedsDisplay()
    7173{
    72     if (!node()->media())
    73         m_pendingContent.needsDisplay = true;
     74    if (m_image)
     75        setContentsToImage(m_image.get());
    7476    notifyChange(TextureMapperNode::DisplayChange);
    7577}
     
    7981void GraphicsLayerTextureMapper::setNeedsDisplayInRect(const FloatRect& rect)
    8082{
    81     if (m_pendingContent.needsDisplay)
    82         return;
    83     m_pendingContent.needsDisplayRect.unite(rect);
     83    if (m_needsDisplay)
     84        return;
     85    m_needsDisplayRect.unite(rect);
    8486    notifyChange(TextureMapperNode::DisplayChange);
    8587}
     
    129131void GraphicsLayerTextureMapper::addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling)
    130132{
    131 
    132133    GraphicsLayer::addChildBelow(layer, sibling);
    133134    notifyChange(TextureMapperNode::ChildrenChange);
     
    260261/* \reimp (GraphicsLayer.h)
    261262*/
    262 void GraphicsLayerTextureMapper::setBackgroundColor(const Color& value)
    263 {
    264     if (value == m_pendingContent.backgroundColor)
    265         return;
    266     m_pendingContent.backgroundColor = value;
    267     GraphicsLayer::setBackgroundColor(value);
    268     notifyChange(TextureMapperNode::BackgroundColorChange);
    269 }
    270 
    271 /* \reimp (GraphicsLayer.h)
    272 */
    273 void GraphicsLayerTextureMapper::clearBackgroundColor()
    274 {
    275     if (!m_pendingContent.backgroundColor.isValid())
    276         return;
    277     m_pendingContent.backgroundColor = Color();
    278     GraphicsLayer::clearBackgroundColor();
    279     notifyChange(TextureMapperNode::BackgroundColorChange);
    280 }
    281 
    282 /* \reimp (GraphicsLayer.h)
    283 */
    284263void GraphicsLayerTextureMapper::setContentsOpaque(bool value)
    285264{
     
    324303void GraphicsLayerTextureMapper::setContentsToImage(Image* image)
    325304{
     305    if (image == m_image)
     306        return;
     307
     308    m_image = image;
     309    if (m_image) {
     310        RefPtr<TextureMapperTiledBackingStore> backingStore = TextureMapperTiledBackingStore::create();
     311        backingStore->setContentsToImage(image);
     312        m_compositedImage = backingStore;
     313    } else
     314        m_compositedImage = 0;
     315
     316    setContentsToMedia(m_compositedImage.get());
    326317    notifyChange(TextureMapperNode::ContentChange);
    327     m_pendingContent.contentType = image ? TextureMapperNode::DirectImageContentType : TextureMapperNode::HTMLContentType;
    328     m_pendingContent.image = image;
    329318    GraphicsLayer::setContentsToImage(image);
    330319}
     
    332321void GraphicsLayerTextureMapper::setContentsToMedia(TextureMapperPlatformLayer* media)
    333322{
     323    if (media == m_contentsLayer)
     324        return;
     325
    334326    GraphicsLayer::setContentsToMedia(media);
    335327    notifyChange(TextureMapperNode::ContentChange);
    336     m_pendingContent.contentType = media ? TextureMapperNode::MediaContentType : TextureMapperNode::HTMLContentType;
    337     m_pendingContent.media = media;
     328    m_contentsLayer = media;
    338329}
    339330
     
    350341{
    351342    m_node->syncCompositingState(this, TextureMapperNode::TraverseDescendants);
    352 }
    353 
    354 /* \reimp (GraphicsLayer.h)
    355 */
    356 PlatformLayer* GraphicsLayerTextureMapper::platformLayer() const
    357 {
    358     return const_cast<TextureMapperPlatformLayer*>(node()->media());
    359343}
    360344
  • trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h

    r105925 r107707  
    6565    virtual void setMasksToBounds(bool b);
    6666    virtual void setDrawsContent(bool b);
    67     virtual void setBackgroundColor(const Color&);
    68     virtual void clearBackgroundColor();
    6967    virtual void setContentsOpaque(bool b);
    7068    virtual void setBackfaceVisibility(bool b);
     
    7876    virtual void syncCompositingStateForThisLayerOnly();
    7977    virtual void setName(const String& name);
    80     virtual PlatformLayer* platformLayer() const;
     78    virtual PlatformLayer* platformLayer() const { return 0; }
    8179
    8280    void notifyChange(TextureMapperNode::ChangeMask changeMask);
    83     inline TextureMapperNode::ContentData& pendingContent() { return m_pendingContent; }
    8481    inline int changeMask() const { return m_changeMask; }
    8582    void didSynchronize();
     
    9087
    9188    TextureMapperNode* node() const { return m_node.get(); }
     89    TextureMapperPlatformLayer* contentsLayer() const { return m_contentsLayer; }
     90    bool needsDisplay() const { return m_needsDisplay; }
     91    IntRect needsDisplayRect() const { return enclosingIntRect(m_needsDisplayRect); }
    9292
    9393private:
    9494    OwnPtr<TextureMapperNode> m_node;
     95    RefPtr<TextureMapperBackingStore> m_compositedImage;
     96    RefPtr<Image> m_image;
    9597    bool m_syncQueued;
    9698    int m_changeMask;
    97     TextureMapperNode::ContentData m_pendingContent;
     99    bool m_needsDisplay;
     100    TextureMapperPlatformLayer* m_contentsLayer;
     101    FloatRect m_needsDisplayRect;
    98102    TextureMapperAnimations m_animations;
    99103    void animationStartedTimerFired(Timer<GraphicsLayerTextureMapper>*);
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp

    r106659 r107707  
    7474}
    7575
    76 
    7776PassOwnPtr<TextureMapper> TextureMapper::create(AccelerationMode mode)
    7877{
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.h

    r106668 r107707  
    107107    virtual void endPainting() { }
    108108
     109    virtual IntSize maxTextureSize() const { return IntSize(INT_MAX, INT_MAX); }
     110
    109111    // A surface is released implicitly when dereferenced.
    110112    virtual PassRefPtr<BitmapTexture> acquireTextureFromPool(const IntSize&);
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp

    r106804 r107707  
    2121#include "TextureMapperNode.h"
    2222
     23#include "stdio.h"
     24
    2325#if USE(ACCELERATED_COMPOSITING)
    2426
     
    2628#include "ImageBuffer.h"
    2729#include "MathExtras.h"
    28 
    29 namespace {
    30     static const float gTileDimension = 1024.0;
    31 }
    3230
    3331namespace WebCore {
     
    5048{
    5149    m_transform.setLocalTransform(matrix);
     50}
     51
     52void TextureMapperNode::clearBackingStoresRecursive()
     53{
     54    m_backingStore.clear();
     55    m_contentsLayer = 0;
     56    for (size_t i = 0; i < m_children.size(); ++i)
     57        m_children[i]->clearBackingStoresRecursive();
     58    if (m_state.maskLayer)
     59        m_state.maskLayer->clearBackingStoresRecursive();
    5260}
    5361
     
    8290}
    8391
    84 void TextureMapperNode::computeTiles()
    85 {
    86 #if USE(TILED_BACKING_STORE)
    87     if (m_state.tileOwnership == ExternallyManagedTiles)
    88         return;
    89 #endif
    90     if (m_currentContent.contentType == HTMLContentType && !m_state.drawsContent) {
    91         m_ownedTiles.clear();
    92         return;
    93     }
    94     Vector<FloatRect> tilesToAdd;
    95     Vector<int> tilesToRemove;
    96     const int TileEraseThreshold = 6;
    97     FloatSize size = contentSize();
    98     FloatRect contentRect(0, 0, size.width(), size.height());
    99 
    100     for (float y = 0; y < contentRect.height(); y += gTileDimension) {
    101         for (float x = 0; x < contentRect.width(); x += gTileDimension) {
    102             FloatRect tileRect(x, y, gTileDimension, gTileDimension);
    103             tileRect.intersect(contentRect);
    104             tilesToAdd.append(tileRect);
    105         }
    106     }
    107 
    108     for (int i = m_ownedTiles.size() - 1; i >= 0; --i) {
    109         const FloatRect oldTile = m_ownedTiles[i].rect;
    110         bool found = false;
    111 
    112         for (int j = tilesToAdd.size() - 1; j >= 0; --j) {
    113             const FloatRect newTile = tilesToAdd[j];
    114             if (oldTile != newTile)
    115                 continue;
    116 
    117             found = true;
    118             tilesToAdd.remove(j);
    119             break;
    120         }
    121 
    122         if (!found)
    123             tilesToRemove.append(i);
    124     }
    125 
    126     for (size_t i = 0; i < tilesToAdd.size(); ++i) {
    127         if (!tilesToRemove.isEmpty()) {
    128             OwnedTile& tile = m_ownedTiles[tilesToRemove[0]];
    129             tilesToRemove.remove(0);
    130             tile.rect = tilesToAdd[i];
    131             tile.needsReset = true;
    132             continue;
    133         }
    134 
    135         OwnedTile tile;
    136         tile.rect = tilesToAdd[i];
    137         tile.needsReset = true;
    138         m_ownedTiles.append(tile);
    139     }
    140 
    141     for (size_t i = 0; i < tilesToRemove.size() && m_ownedTiles.size() > TileEraseThreshold; ++i)
    142         m_ownedTiles.remove(tilesToRemove[i]);
    143 }
    144 
    145 void TextureMapperNode::renderContent(TextureMapper* textureMapper, GraphicsLayer* layer)
    146 {
    147 #if USE(TILED_BACKING_STORE)
    148     if (m_state.tileOwnership == ExternallyManagedTiles)
    149         return;
    150 #endif
    151 
    152     if (m_size.isEmpty() || !layer || (!m_state.drawsContent && m_currentContent.contentType == HTMLContentType)) {
    153         m_ownedTiles.clear();
    154         return;
    155     }
    156 
    157     if (!textureMapper)
    158         return;
    159 
    160     IntRect dirtyRect = enclosingIntRect(m_currentContent.needsDisplay ? entireRect() : m_currentContent.needsDisplayRect);
    161 
    162     for (size_t tileIndex = 0; tileIndex < m_ownedTiles.size(); ++tileIndex) {
    163         OwnedTile& tile = m_ownedTiles[tileIndex];
    164         if (!tile.texture)
    165             tile.texture = textureMapper->createTexture();
    166         RefPtr<BitmapTexture>& texture = tile.texture;
    167         IntSize tileSize = enclosingIntRect(tile.rect).size();
    168 
    169         if (tile.needsReset || texture->contentSize() != tileSize || !texture->isValid()) {
    170             tile.needsReset = false;
    171             texture->reset(tileSize, m_state.contentsOpaque);
    172             dirtyRect.unite(enclosingIntRect(tile.rect));
    173         }
    174     }
    175 
     92void TextureMapperNode::updateBackingStore(TextureMapper* textureMapper, GraphicsLayer* layer)
     93{
     94    if (!layer || !textureMapper)
     95        return;
     96
     97    if (!m_shouldUpdateBackingStoreFromLayer)
     98        return;
     99
     100    if (!m_state.drawsContent || m_size.isEmpty()) {
     101        m_backingStore.clear();
     102        return;
     103    }
     104
     105    IntRect dirtyRect = enclosingIntRect(m_state.needsDisplay ? layerRect() : m_state.needsDisplayRect);
    176106    if (dirtyRect.isEmpty())
    177107        return;
     108
     109    if (!m_backingStore)
     110        m_backingStore = TextureMapperTiledBackingStore::create();
     111
     112    ASSERT(dynamic_cast<TextuerMapperTiledBackingStore*>(m_backingStore.get()));
    178113
    179114    // Paint the entire dirty rect into an image buffer. This ensures we only paint once.
     
    184119    context->translate(-dirtyRect.x(), -dirtyRect.y());
    185120    layer->paintGraphicsLayerContents(*context, dirtyRect);
    186     if (m_currentContent.contentType == DirectImageContentType)
    187         context->drawImage(m_currentContent.image.get(), ColorSpaceDeviceRGB, m_state.contentsRect);
    188121
    189122    RefPtr<Image> image;
     
    196129#endif
    197130
    198     // Divide the image to tiles.
    199     for (size_t tileIndex = 0; tileIndex < m_ownedTiles.size(); ++tileIndex) {
    200         OwnedTile& tile = m_ownedTiles[tileIndex];
    201         IntRect targetRect = enclosingIntRect(tile.rect);
    202         targetRect.intersect(dirtyRect);
    203         if (targetRect.isEmpty())
    204             continue;
    205         IntRect sourceRect = targetRect;
    206 
    207         // Normalize sourceRect to the buffer's coordinates.
    208         sourceRect.move(-dirtyRect.x(), -dirtyRect.y());
    209 
    210         // Normalize targetRect to the texture's coordinqates.
    211         targetRect.move(-tile.rect.x(), -tile.rect.y());
    212         tile.texture->updateContents(image.get(), targetRect, sourceRect, BitmapTexture::RGBAFormat);
    213     }
    214 
    215     m_currentContent.needsDisplay = false;
    216     m_currentContent.needsDisplayRect = IntRect();
     131    static_cast<TextureMapperTiledBackingStore*>(m_backingStore.get())->updateContents(textureMapper, image.get(), m_size, dirtyRect);
    217132}
    218133
    219134void TextureMapperNode::paint()
    220135{
    221     if (m_size.isEmpty())
    222         return;
    223 
    224136    computeTransformsRecursive();
    225137
    226     TextureMapperPaintOptions opt;
    227     opt.textureMapper = m_textureMapper;
    228     opt.textureMapper->bindSurface(0);
    229     paintRecursive(opt);
    230 }
    231 
    232 FloatRect TextureMapperNode::targetRectForTileRect(const FloatRect& targetRect, const FloatRect& tileRect) const
    233 {
    234     return FloatRect(
    235                 targetRect.x() + (tileRect.x() - targetRect.x()),
    236                 targetRect.y() + (tileRect.y() - targetRect.y()),
    237                 tileRect.width(),
    238                 tileRect.height());
     138    TextureMapperPaintOptions options;
     139    options.textureMapper = m_textureMapper;
     140    options.textureMapper->bindSurface(0);
     141    paintRecursive(options);
    239142}
    240143
    241144void TextureMapperNode::paintSelf(const TextureMapperPaintOptions& options)
    242145{
    243     if (m_size.isEmpty() || (!m_state.drawsContent && m_currentContent.contentType == HTMLContentType))
    244         return;
    245 
    246     float opacity = options.opacity;
    247     BitmapTexture* mask = options.mask;
    248     FloatRect targetRect = this->targetRect();
    249 
    250146    // We apply the following transform to compensate for painting into a surface, and then apply the offset so that the painting fits in the target rect.
    251147    TransformationMatrix transform =
     
    254150            .translate(options.offset.width(), options.offset.height());
    255151
    256 #if USE(TILED_BACKING_STORE)
    257     Vector<ExternallyManagedTile> tilesToPaint;
    258 
    259     if (m_state.tileOwnership == ExternallyManagedTiles) {
    260         // Sort tiles, with current scale factor last.
    261         Vector<ExternallyManagedTile*> tiles;
    262         HashMap<int, ExternallyManagedTile>::iterator end = m_externallyManagedTiles.end();
    263         for (HashMap<int, ExternallyManagedTile>::iterator it = m_externallyManagedTiles.begin(); it != end; ++it) {
    264             if (!it->second.frontBuffer.texture)
    265                 continue;
    266 
    267             if (it->second.scale == m_state.contentScale) {
    268                 tiles.append(&it->second);
    269                 continue;
    270             }
    271 
    272             // This creates a transitional effect looks good only when there's no transparency, so we only use it when the opacity for the layer is above a certain threshold.
    273             if (opacity > 0.95)
    274                 tiles.prepend(&it->second);
    275         }
    276 
    277         for (int i = 0; i < tiles.size(); ++i) {
    278             ExternallyManagedTile& tile = *tiles[i];
    279             FloatRect rect = tile.frontBuffer.targetRect;
    280             BitmapTexture& texture = *tile.frontBuffer.texture;
    281             options.textureMapper->drawTexture(texture, rect, transform, opacity, mask);
    282         }
    283         return;
    284     }
    285 #endif
    286 
    287     // Now we paint owned tiles, if we're in OwnedTileMode.
    288     for (size_t i = 0; i < m_ownedTiles.size(); ++i) {
    289         BitmapTexture* texture = m_ownedTiles[i].texture.get();
    290         const FloatRect rect = targetRectForTileRect(targetRect, m_ownedTiles[i].rect);
    291         options.textureMapper->drawTexture(*texture, rect, transform, opacity, mask);
    292     }
    293 
    294     if (m_currentContent.contentType == MediaContentType && m_currentContent.media)
    295         m_currentContent.media->paintToTextureMapper(options.textureMapper, targetRect, transform, opacity, mask);
     152    float opacity = options.opacity;
     153    RefPtr<BitmapTexture> mask = options.mask;
     154
     155    if (m_backingStore)
     156        m_backingStore->paintToTextureMapper(options.textureMapper, layerRect(), transform, opacity, mask.get());
     157
     158    if (m_contentsLayer)
     159        m_contentsLayer->paintToTextureMapper(options.textureMapper, m_state.contentsRect, transform, opacity, mask.get());
    296160}
    297161
     
    333197    IntRect rect;
    334198    TransformationMatrix localTransform = TransformationMatrix(matrix).multiply(m_transform.combined());
    335     rect = enclosingIntRect(localTransform.mapRect(entireRect()));
     199    rect = enclosingIntRect(localTransform.mapRect(layerRect()));
    336200    if (!m_state.masksToBounds && !m_state.maskLayer) {
    337201        for (int i = 0; i < m_children.size(); ++i)
     
    434298        maskTexture = 0;
    435299
    436     options.textureMapper->bindSurface(options.surface);
     300    options.textureMapper->bindSurface(options.surface.get());
    437301    TransformationMatrix targetTransform =
    438302            TransformationMatrix(options.transform)
     
    451315}
    452316
    453 #if USE(TILED_BACKING_STORE)
    454 int TextureMapperNode::createContentsTile(float scale)
    455 {
    456     static int nextID = 0;
    457     int id = ++nextID;
    458     m_externallyManagedTiles.add(id, ExternallyManagedTile(scale));
    459     m_state.contentScale = scale;
    460     return id;
    461 }
    462 
    463 void TextureMapperNode::removeContentsTile(int id)
    464 {
    465     m_externallyManagedTiles.remove(id);
    466 }
    467 
    468 void TextureMapperNode::purgeNodeTexturesRecursive()
    469 {
    470     m_externallyManagedTiles.clear();
    471 
    472     for (int i = m_children.size() - 1; i >= 0; --i)
    473         m_children[i]->purgeNodeTexturesRecursive();
    474 }
    475 
    476 void TextureMapperNode::setTileBackBufferTextureForDirectlyCompositedImage(int id, const IntRect& sourceRect, const FloatRect& targetRect, BitmapTexture* texture)
    477 {
    478     HashMap<int, ExternallyManagedTile>::iterator it = m_externallyManagedTiles.find(id);
    479 
    480     if (it == m_externallyManagedTiles.end())
    481         return;
    482 
    483     ExternallyManagedTile& tile = it->second;
    484 
    485     tile.backBuffer.sourceRect = sourceRect;
    486     tile.backBuffer.targetRect = targetRect;
    487     tile.backBuffer.texture = texture;
    488     tile.isBackBufferUpdated = true;
    489     tile.isDirectlyCompositedImage = true;
    490 }
    491 
    492 void TextureMapperNode::clearAllDirectlyCompositedImageTiles()
    493 {
    494     for (HashMap<int, ExternallyManagedTile>::iterator it = m_externallyManagedTiles.begin(); it != m_externallyManagedTiles.end(); ++it) {
    495         if (it->second.isDirectlyCompositedImage)
    496             m_externallyManagedTiles.remove(it);
    497     }
    498 }
    499 
    500 void TextureMapperNode::setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, const void* data)
    501 {
    502     ASSERT(m_textureMapper);
    503 
    504     HashMap<int, ExternallyManagedTile>::iterator it = m_externallyManagedTiles.find(id);
    505     if (it == m_externallyManagedTiles.end())
    506         return;
    507 
    508     ExternallyManagedTile& tile = it->second;
    509 
    510     tile.backBuffer.sourceRect = sourceRect;
    511     tile.backBuffer.targetRect = FloatRect(targetRect);
    512     tile.backBuffer.targetRect.scale(1.0 / tile.scale);
    513 
    514     if (!tile.backBuffer.texture)
    515         tile.backBuffer.texture = m_textureMapper->createTexture();
    516     tile.backBuffer.texture->reset(sourceRect.size(), false);
    517     tile.backBuffer.texture->updateContents(data, sourceRect);
    518     tile.isBackBufferUpdated = true;
    519 }
    520 
    521 void TextureMapperNode::swapContentsBuffers()
    522 {
    523     HashMap<int, ExternallyManagedTile>::iterator end = m_externallyManagedTiles.end();
    524     for (HashMap<int, ExternallyManagedTile>::iterator it = m_externallyManagedTiles.begin(); it != end; ++it) {
    525         ExternallyManagedTile& tile = it->second;
    526         if (!tile.isBackBufferUpdated)
    527             continue;
    528         tile.isBackBufferUpdated = false;
    529         ExternallyManagedTileBuffer swapBuffer = tile.frontBuffer;
    530         tile.frontBuffer = tile.backBuffer;
    531         tile.backBuffer = swapBuffer;
    532     }
    533 }
    534 #endif
    535 
    536317void TextureMapperNode::syncCompositingState(GraphicsLayerTextureMapper* graphicsLayer, int options)
    537318{
     
    542323{
    543324    int changeMask = graphicsLayer->changeMask();
    544     const TextureMapperNode::ContentData& pendingContent = graphicsLayer->pendingContent();
    545 #if USE(TILED_BACKING_STORE)
    546     swapContentsBuffers();
    547 #endif
    548     if (changeMask == NoChanges && graphicsLayer->m_animations.isEmpty() && pendingContent.needsDisplayRect.isEmpty() && !pendingContent.needsDisplay)
    549         return;
    550 
    551     if (m_currentContent.contentType == HTMLContentType && (changeMask & ParentChange)) {
     325
     326    if (changeMask == NoChanges && graphicsLayer->m_animations.isEmpty())
     327        return;
     328
     329    if (changeMask & ParentChange) {
    552330        TextureMapperNode* newParent = toTextureMapperNode(graphicsLayer->parent());
    553331        if (newParent != m_parent) {
     
    581359    }
    582360
    583     if (changeMask & (SizeChange | ContentsRectChange)) {
    584         FloatSize wantedSize(graphicsLayer->size().width(), graphicsLayer->size().height());
    585         if (wantedSize.isEmpty() && pendingContent.contentType == HTMLContentType)
    586             wantedSize = FloatSize(graphicsLayer->contentsRect().width(), graphicsLayer->contentsRect().height());
    587 
    588         if (wantedSize != m_size)
    589             m_ownedTiles.clear();
    590 
    591         m_size = wantedSize;
    592     }
     361    m_size = graphicsLayer->size();
    593362
    594363    if (changeMask & MaskLayerChange) {
     
    620389    m_state.childrenTransform = graphicsLayer->childrenTransform();
    621390    m_state.opacity = graphicsLayer->opacity();
    622 
    623     m_currentContent.contentType = pendingContent.contentType;
    624     m_currentContent.image = pendingContent.image;
    625     m_currentContent.media = pendingContent.media;
    626     m_currentContent.needsDisplay = m_currentContent.needsDisplay || pendingContent.needsDisplay;
    627     if (!m_currentContent.needsDisplay)
    628         m_currentContent.needsDisplayRect.unite(pendingContent.needsDisplayRect);
     391    m_state.needsDisplay = m_state.needsDisplay || graphicsLayer->needsDisplay();
     392    if (!m_state.needsDisplay)
     393        m_state.needsDisplayRect.unite(graphicsLayer->needsDisplayRect());
     394    m_contentsLayer = graphicsLayer->contentsLayer();
    629395
    630396    m_transform.setPosition(m_state.pos);
     
    667433void TextureMapperNode::syncCompositingState(GraphicsLayerTextureMapper* graphicsLayer, TextureMapper* textureMapper, int options)
    668434{
     435    if (!textureMapper)
     436        return;
     437
    669438    if (graphicsLayer && !(options & ComputationsOnly)) {
    670439        syncCompositingStateSelf(graphicsLayer, textureMapper);
     
    684453
    685454    syncAnimations();
    686     computeTiles();
    687 
    688     if (graphicsLayer)
    689         renderContent(textureMapper, graphicsLayer);
     455    updateBackingStore(textureMapper, graphicsLayer);
    690456
    691457    if (!(options & TraverseDescendants))
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperNode.h

    r106659 r107707  
    2929#include "TextureMapper.h"
    3030#include "TextureMapperAnimation.h"
     31#include "TextureMapperBackingStore.h"
    3132#include "Timer.h"
    3233#include "TransformOperations.h"
     
    4344class TextureMapperPaintOptions {
    4445public:
    45     BitmapTexture* surface;
    46     BitmapTexture* mask;
     46    RefPtr<BitmapTexture> surface;
     47    RefPtr<BitmapTexture> mask;
    4748    float opacity;
    4849    TransformationMatrix transform;
     
    5051    TextureMapper* textureMapper;
    5152    TextureMapperPaintOptions()
    52         : surface(0)
    53         , mask(0)
    54         , opacity(1)
     53        : opacity(1)
    5554        , textureMapper(0)
    5655    { }
     
    9897    };
    9998
    100     enum TileOwnership {
    101         OwnedTiles,
    102         ExternallyManagedTiles
    103     };
    104 
    105     typedef HashMap<TextureMapperNode*, FloatRect> NodeRectMap;
    106 
    107     // The compositor lets us special-case images and colors, so we try to do so.
    108     enum ContentType { HTMLContentType, DirectImageContentType, ColorContentType, MediaContentType, Canvas3DContentType};
    109     struct ContentData {
    110         FloatRect needsDisplayRect;
    111         bool needsDisplay;
    112         Color backgroundColor;
    113 
    114         ContentType contentType;
    115         RefPtr<Image> image;
    116         const TextureMapperPlatformLayer* media;
    117         ContentData()
    118             : needsDisplay(false)
    119             , contentType(HTMLContentType)
    120             , image(0)
    121             , media(0)
    122         {
    123         }
    124     };
    125 
    12699    TextureMapperNode()
    127100        : m_parent(0)
    128101        , m_effectTarget(0)
     102        , m_contentsLayer(0)
    129103        , m_opacity(1)
    130104        , m_centerZ(0)
     105        , m_shouldUpdateBackingStoreFromLayer(true)
    131106        , m_textureMapper(0)
    132107    { }
     
    145120    void paint();
    146121
    147 #if USE(TILED_BACKING_STORE)
    148     void setTileOwnership(TileOwnership ownership) { m_state.tileOwnership = ownership; }
    149     int createContentsTile(float scale);
    150     void removeContentsTile(int id);
    151     void setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, const void*);
    152     void setTileBackBufferTextureForDirectlyCompositedImage(int id, const IntRect& sourceRect, const FloatRect& targetRect, BitmapTexture*);
    153     void clearAllDirectlyCompositedImageTiles();
    154     void purgeNodeTexturesRecursive();
    155 #endif
    156     void setID(int id) { m_id = id; }
    157     int id() const { return m_id; }
    158 
    159     const TextureMapperPlatformLayer* media() const { return m_currentContent.media; }
     122    void setShouldUpdateBackingStoreFromLayer(bool b) { m_shouldUpdateBackingStoreFromLayer = b; }
     123    void setBackingStore(TextureMapperBackingStore* backingStore) { m_backingStore = backingStore; }
     124    PassRefPtr<TextureMapperBackingStore> backingStore() { return m_backingStore; }
     125    void clearBackingStoresRecursive();
    160126
    161127private:
     
    175141    static void sortByZOrder(Vector<TextureMapperNode* >& array, int first, int last);
    176142
    177     BitmapTexture* texture() { return m_ownedTiles.isEmpty() ? 0 : m_ownedTiles[0].texture.get(); }
     143    PassRefPtr<BitmapTexture> texture() { return m_backingStore ? m_backingStore->texture() : 0; }
    178144
    179145    void paintRecursive(const TextureMapperPaintOptions&);
     
    181147    void paintSelfAndChildren(const TextureMapperPaintOptions&);
    182148    void paintSelfAndChildrenWithReplica(const TextureMapperPaintOptions&);
    183     void renderContent(TextureMapper*, GraphicsLayer*);
     149    void updateBackingStore(TextureMapper*, GraphicsLayer*);
    184150
    185151    void syncAnimations();
     
    189155    LayerTransform m_transform;
    190156
    191     inline FloatRect targetRect() const
     157    inline FloatRect layerRect() const
    192158    {
    193         return m_currentContent.contentType == HTMLContentType ? entireRect() : m_state.contentsRect;
     159        return FloatRect(FloatPoint::zero(), m_size);
    194160    }
    195 
    196     inline FloatRect entireRect() const
    197     {
    198         return FloatRect(0, 0, m_size.width(), m_size.height());
    199     }
    200 
    201     FloatSize contentSize() const
    202     {
    203         return m_currentContent.contentType == DirectImageContentType && m_currentContent.image ? m_currentContent.image->size() : m_size;
    204     }
    205     struct OwnedTile {
    206         FloatRect rect;
    207         RefPtr<BitmapTexture> texture;
    208         bool needsReset;
    209     };
    210 
    211     Vector<OwnedTile> m_ownedTiles;
    212 
    213 #if USE(TILED_BACKING_STORE)
    214     struct ExternallyManagedTileBuffer {
    215         FloatRect sourceRect;
    216         FloatRect targetRect;
    217         RefPtr<BitmapTexture> texture;
    218     };
    219 
    220     struct ExternallyManagedTile {
    221         bool isBackBufferUpdated;
    222         bool isDirectlyCompositedImage;
    223         float scale;
    224         ExternallyManagedTileBuffer frontBuffer;
    225         ExternallyManagedTileBuffer backBuffer;
    226 
    227         ExternallyManagedTile(float scale = 1.0)
    228             : isBackBufferUpdated(false)
    229             , isDirectlyCompositedImage(false)
    230             , scale(scale)
    231         {
    232         }
    233     };
    234 
    235     HashMap<int, ExternallyManagedTile> m_externallyManagedTiles;
    236 #endif
    237 
    238     ContentData m_currentContent;
    239161
    240162    Vector<TextureMapperNode*> m_children;
    241163    TextureMapperNode* m_parent;
    242164    TextureMapperNode* m_effectTarget;
     165    RefPtr<TextureMapperBackingStore> m_backingStore;
     166    TextureMapperPlatformLayer* m_contentsLayer;
    243167    FloatSize m_size;
    244168    float m_opacity;
    245169    float m_centerZ;
    246170    String m_name;
    247     int m_id;
     171    bool m_shouldUpdateBackingStoreFromLayer;
    248172
    249173    struct State {
     
    255179        float opacity;
    256180        FloatRect contentsRect;
     181        FloatRect needsDisplayRect;
    257182        int descendantsWithContent;
    258183        TextureMapperNode* maskLayer;
     
    264189        bool backfaceVisibility : 1;
    265190        bool visible : 1;
    266         bool needsReset: 1;
     191        bool needsDisplay: 1;
    267192        bool mightHaveOverlaps : 1;
    268193        bool needsRepaint;
    269         float contentScale;
    270 #if USE(TILED_BACKING_STORE)
    271         TileOwnership tileOwnership;
    272 #endif
    273194        State()
    274195            : opacity(1.f)
     
    281202            , backfaceVisibility(false)
    282203            , visible(true)
    283             , needsReset(false)
     204            , needsDisplay(true)
    284205            , mightHaveOverlaps(false)
    285206            , needsRepaint(false)
    286             , contentScale(1.0f)
    287 #if USE(TILED_BACKING_STORE)
    288             , tileOwnership(OwnedTiles)
    289 #endif
    290207        {
    291208        }
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h

    r95901 r107707  
    2121#define TextureMapperPlatformLayer_h
    2222
    23 #include "FloatRect.h"
    2423#include "TransformationMatrix.h"
    2524
     
    3130class TextureMapperPlatformLayer {
    3231public:
    33     virtual void paintToTextureMapper(TextureMapper*, const FloatRect&, const TransformationMatrix& modelViewMatrix = TransformationMatrix(), float opacity = 1.0, BitmapTexture* mask = 0) const = 0;
     32    virtual void paintToTextureMapper(TextureMapper*, const FloatRect&, const TransformationMatrix& modelViewMatrix = TransformationMatrix(), float opacity = 1.0, BitmapTexture* mask = 0) = 0;
     33    virtual void swapBuffers() { }
    3434};
    3535
  • trunk/Source/WebKit2/ChangeLog

    r107706 r107707  
     12012-02-14  No'am Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        [Qt][Texmap] Refactor backing-store code in TextureMapper
     4        https://bugs.webkit.org/show_bug.cgi?id=78305
     5
     6        Move the backing-store code to LayerTreeBackingStore, implementing the virtual functions
     7        in TextureMapperBackingStore.
     8        We save the double-buffered tile in the backing-store, and then convert them to regular
     9        tiles in updateContents, based on the order of painting.
     10        Use TextureMapperCompositedImage for images instead of saving our own composited image
     11        registry.
     12
     13        Reviewed by Kenneth Rohde Christiansen.
     14
     15        * Target.pri:
     16        * UIProcess/LayerTreeHostProxy.h:
     17        (WebKit):
     18        (LayerTreeHostProxy):
     19        * UIProcess/qt/LayerBackingStore.cpp: Added.
     20        * UIProcess/qt/LayerBackingStore.h: Added.
     21        * UIProcess/qt/LayerTreeHostProxyQt.cpp:
     22        (WebKit::LayerTreeHostProxy::createLayer):
     23        (WebKit::LayerTreeHostProxy::syncLayerParameters):
     24        (WebKit::LayerTreeHostProxy::getBackingStore):
     25        (WebKit::LayerTreeHostProxy::createTile):
     26        (WebKit::LayerTreeHostProxy::removeTile):
     27        (WebKit::LayerTreeHostProxy::updateTile):
     28        (WebKit::LayerTreeHostProxy::createImage):
     29        (WebKit::LayerTreeHostProxy::assignImageToLayer):
     30        (WebKit::LayerTreeHostProxy::purgeGLResources):
     31        * WebProcess.pro:
     32
     33
    1342012-02-14  Shinya Kawanaka  <shinyak@google.com>
    235
  • trunk/Source/WebKit2/Target.pri

    r107232 r107707  
    254254    UIProcess/WebResourceLoadClient.h \
    255255    UIProcess/WebUIClient.h \
     256    UIProcess/qt/LayerBackingStore.h \
    256257    UIProcess/qt/QtWebContext.h \
    257258    UIProcess/qt/QtWebPageEventHandler.h \
     
    582583    UIProcess/WebUIClient.cpp \
    583584    UIProcess/qt/QtWebContext.cpp \
     585    UIProcess/qt/LayerBackingStore.cpp \
    584586    UIProcess/qt/LayerTreeHostProxyQt.cpp \
    585587    UIProcess/qt/QtWebPageEventHandler.cpp \
  • trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.h

    r106524 r107707  
    3131#include <WebCore/IntSize.h>
    3232#include <WebCore/RunLoop.h>
     33#include <WebCore/Timer.h>
    3334#include <wtf/HashSet.h>
    3435
    3536#if USE(TEXTURE_MAPPER)
    3637#include "TextureMapper.h"
    37 #include "TextureMapperNode.h"
     38#include "TextureMapperBackingStore.h"
    3839#endif
    3940
    4041namespace WebKit {
    4142
     43class LayerBackingStore;
    4244class WebLayerInfo;
    4345class WebLayerUpdateInfo;
     
    99101
    100102#if PLATFORM(QT)
    101     typedef HashMap<WebCore::IntPoint, RefPtr<WebCore::BitmapTexture> > TiledImage;
    102     WebCore::TextureMapperNode::NodeRectMap m_nodeVisualContentsRectMap;
    103     HashMap<int, int> m_tileToNodeTile;
    104     int remoteTileIDToNodeTileID(int tileID) const;
    105     HashMap<int64_t, TiledImage> m_directlyCompositedImages;
    106 
    107103    void scheduleWebViewUpdate();
    108104    void synchronizeViewport();
     
    119115    void ensureRootLayer();
    120116    void ensureLayer(WebLayerID);
    121 
     117    PassRefPtr<LayerBackingStore> getBackingStore(WebLayerID);
     118    void swapBuffers();
    122119#endif
    123120
    124121    OwnPtr<WebCore::GraphicsLayer> m_rootLayer;
    125122    Vector<WebLayerID> m_layersToDelete;
     123    HashMap<int64_t, RefPtr<WebCore::TextureMapperBackingStore> > m_directlyCompositedImages;
     124    HashSet<RefPtr<LayerBackingStore> > m_backingStoresWithPendingBuffers;
    126125
    127126#if PLATFORM(QT)
  • trunk/Source/WebKit2/UIProcess/qt/LayerTreeHostProxyQt.cpp

    r106659 r107707  
    2323#include "LayerTreeHostProxy.h"
    2424
     25#include "GraphicsLayerTextureMapper.h"
     26#include "LayerBackingStore.h"
    2527#include "LayerTreeHostMessages.h"
    2628#include "MainThread.h"
     
    2830#include "ShareableBitmap.h"
    2931#include "TextureMapper.h"
     32#include "TextureMapperBackingStore.h"
     33#include "TextureMapperNode.h"
    3034#include "UpdateInfo.h"
    3135#include "WebCoreArgumentCoders.h"
     
    3337#include "WebPageProxy.h"
    3438#include "WebProcessProxy.h"
    35 #include "texmap/GraphicsLayerTextureMapper.h"
    36 #include "texmap/TextureMapper.h"
    37 #include "texmap/TextureMapperNode.h"
    3839#include <QDateTime>
    3940#include <cairo/OpenGLShims.h>
     
    150151    GraphicsLayer* newLayer = new GraphicsLayerTextureMapper(this);
    151152    TextureMapperNode* node = toTextureMapperNode(newLayer);
    152     node->setID(layerID);
    153     node->setTileOwnership(TextureMapperNode::ExternallyManagedTiles);
     153    node->setShouldUpdateBackingStoreFromLayer(false);
    154154    return adoptPtr(newLayer);
    155155}
     
    236236}
    237237
    238 int LayerTreeHostProxy::remoteTileIDToNodeTileID(int tileID) const
    239 {
    240     HashMap<int, int>::const_iterator it = m_tileToNodeTile.find(tileID);
    241     if (it == m_tileToNodeTile.end())
    242         return 0;
    243     return it->second;
    244 }
    245 
    246238void LayerTreeHostProxy::syncLayerParameters(const WebLayerInfo& layerInfo)
    247239{
     
    250242    LayerMap::iterator it = m_layers.find(id);
    251243    GraphicsLayer* layer = it->second;
    252     bool needsToUpdateImageTiles = layerInfo.imageIsUpdated || layerInfo.contentsRect != layer->contentsRect();
     244    bool needsToUpdateImageTiles = layerInfo.imageIsUpdated || (layerInfo.contentsRect != layer->contentsRect() && layerInfo.imageBackingStoreID);
    253245
    254246    layer->setName(layerInfo.name);
     
    349341}
    350342
     343PassRefPtr<LayerBackingStore> LayerTreeHostProxy::getBackingStore(WebLayerID id)
     344{
     345    ensureLayer(id);
     346    TextureMapperNode* node = toTextureMapperNode(layerByID(id));
     347    RefPtr<LayerBackingStore> backingStore = static_cast<LayerBackingStore*>(node->backingStore().get());
     348    if (!backingStore) {
     349        backingStore = LayerBackingStore::create();
     350        node->setBackingStore(backingStore.get());
     351    }
     352    ASSERT(backingStore);
     353    return backingStore;
     354}
     355
    351356void LayerTreeHostProxy::createTile(WebLayerID layerID, int tileID, float scale)
    352357{
    353     ensureLayer(layerID);
    354     TextureMapperNode* node = toTextureMapperNode(layerByID(layerID));
    355 
    356     int nodeTileID = node->createContentsTile(scale);
    357     m_tileToNodeTile.add(tileID, nodeTileID);
     358    getBackingStore(layerID)->createTile(tileID, scale);
    358359}
    359360
    360361void LayerTreeHostProxy::removeTile(WebLayerID layerID, int tileID)
    361362{
    362     TextureMapperNode* node = toTextureMapperNode(layerByID(layerID));
    363     if (!node)
    364         return;
    365 
    366     int nodeTileID = remoteTileIDToNodeTileID(tileID);
    367     if (!nodeTileID)
    368         return;
    369 
    370     node->removeContentsTile(nodeTileID);
    371     m_tileToNodeTile.remove(tileID);
     363    getBackingStore(layerID)->removeTile(tileID);
    372364}
    373365
    374366void LayerTreeHostProxy::updateTile(WebLayerID layerID, int tileID, const IntRect& sourceRect, const IntRect& targetRect, ShareableBitmap* bitmap)
    375367{
    376     ensureLayer(layerID);
    377     TextureMapperNode* node = toTextureMapperNode(layerByID(layerID));
    378     if (!node)
    379         return;
    380 
    381     int nodeTileID = remoteTileIDToNodeTileID(tileID);
    382     if (!nodeTileID)
    383         return;
    384 
    385     node->setTextureMapper(m_textureMapper.get());
    386     QImage image = bitmap->createQImage();
    387     node->setContentsTileBackBuffer(nodeTileID, sourceRect, targetRect, image.constBits());
     368    RefPtr<LayerBackingStore> backingStore = getBackingStore(layerID);
     369    backingStore->updateTile(tileID, sourceRect, targetRect, bitmap);
     370    m_backingStoresWithPendingBuffers.add(backingStore);
    388371}
    389372
    390373void LayerTreeHostProxy::createImage(int64_t imageID, ShareableBitmap* bitmap)
    391374{
    392     TiledImage tiledImage;
    393     static const int TileDimension = 1024;
    394     QImage image = bitmap->createQImage();
    395     bool imageHasAlpha = image.hasAlphaChannel();
    396     IntRect imageRect(0, 0, image.width(), image.height());
    397     for (int y = 0; y < image.height(); y += TileDimension) {
    398         for (int x = 0; x < image.width(); x += TileDimension) {
    399             QImage subImage;
    400             IntRect rect(x, y, TileDimension, TileDimension);
    401             rect.intersect(imageRect);
    402             if (QSize(rect.size()) == image.size())
    403                 subImage = image;
    404             else
    405                 subImage = image.copy(rect);
    406             RefPtr<BitmapTexture> texture = m_textureMapper->createTexture();
    407             texture->reset(rect.size(), !imageHasAlpha);
    408             texture->updateContents(subImage.constBits(), IntRect(IntPoint::zero(), rect.size()));
    409             tiledImage.add(rect.location(), texture);
    410         }
    411     }
    412 
    413     m_directlyCompositedImages.set(imageID, tiledImage);
     375    RefPtr<TextureMapperTiledBackingStore> backingStore = TextureMapperTiledBackingStore::create();
     376    backingStore->updateContents(m_textureMapper.get(), bitmap->createImage().get());
     377    m_directlyCompositedImages.set(imageID, backingStore);
    414378}
    415379
     
    421385void LayerTreeHostProxy::assignImageToLayer(GraphicsLayer* layer, int64_t imageID)
    422386{
    423     TextureMapperNode* node = toTextureMapperNode(layer);
    424     if (!node)
    425         return;
    426 
    427     if (!imageID) {
    428         node->clearAllDirectlyCompositedImageTiles();
    429         return;
    430     }
    431 
    432     FloatSize size(layer->size());
    433     FloatRect contentsRect(layer->contentsRect());
    434     float horizontalFactor = contentsRect.width() / size.width();
    435     float verticalFactor = contentsRect.height() / size.height();
    436     HashMap<int64_t, TiledImage>::iterator it = m_directlyCompositedImages.find(imageID);
    437     if (it == m_directlyCompositedImages.end())
    438         return;
    439 
    440     TiledImage::iterator endTileIterator = it->second.end();
    441     for (TiledImage::iterator tileIt = it->second.begin(); tileIt != endTileIterator; ++tileIt) {
    442         FloatRect sourceRect(FloatPoint(tileIt->first), FloatSize(tileIt->second->size()));
    443         FloatRect targetRect(sourceRect.x() * horizontalFactor + contentsRect.x(),
    444                              sourceRect.y() * verticalFactor + contentsRect.y(),
    445                              sourceRect.width() * horizontalFactor,
    446                              sourceRect.height() * verticalFactor);
    447         int newTileID = node->createContentsTile(1.0);
    448         node->setTileBackBufferTextureForDirectlyCompositedImage(newTileID, IntRect(sourceRect), targetRect, tileIt->second.get());
    449     }
     387    HashMap<int64_t, RefPtr<TextureMapperBackingStore> >::iterator it = m_directlyCompositedImages.find(imageID);
     388    ASSERT(it != m_directlyCompositedImages.end());
     389    layer->setContentsToMedia(it->second.get());
     390}
     391
     392void LayerTreeHostProxy::swapBuffers()
     393{
     394    HashSet<RefPtr<LayerBackingStore> >::iterator end = m_backingStoresWithPendingBuffers.end();
     395    for (HashSet<RefPtr<LayerBackingStore> >::iterator it = m_backingStoresWithPendingBuffers.begin(); it != end; ++it)
     396        (*it)->swapBuffers(m_textureMapper.get());
     397
     398    m_backingStoresWithPendingBuffers.clear();
    450399}
    451400
     
    453402{
    454403    m_rootLayer->syncCompositingState(FloatRect());
     404    swapBuffers();
     405
    455406    // The pending tiles state is on its way for the screen, tell the web process to render the next one.
    456407    m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeHost::RenderNextFrame(), m_drawingAreaProxy->page()->pageID());
     
    630581
    631582    if (node)
    632         node->purgeNodeTexturesRecursive();
     583        node->clearBackingStoresRecursive();
    633584
    634585    m_directlyCompositedImages.clear();
    635 
    636586    m_textureMapper.clear();
    637 
     587    m_backingStoresWithPendingBuffers.clear();
    638588    m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeHost::PurgeBackingStores(), m_drawingAreaProxy->page()->pageID());
    639589}
Note: See TracChangeset for help on using the changeset viewer.