Changeset 107177 in webkit


Ignore:
Timestamp:
Feb 8, 2012 9:26:00 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[Chromium] Avoid unnecessary full tile updates without breaking atomicity of commits.
https://bugs.webkit.org/show_bug.cgi?id=76740

Patch by David Reveman <reveman@chromium.org> on 2012-02-08
Reviewed by James Robinson.

Source/WebCore:

Allow the final batch of texture uploads to be performed without
allocating new textures and re-painting complete tiles.

This patch is tested by the following unit test:

  • CCLayerTreeHostTestAtomicCommitWithPartialUpdate.runMultiThread
  • TiledLayerChromiumTest.partialUpdates
  • platform/graphics/chromium/TiledLayerChromium.cpp:

(WebCore::UpdatableTile::UpdatableTile):
(UpdatableTile):
(WebCore::TiledLayerChromium::updateCompositorResources):
(WebCore):
(WebCore::TiledLayerChromium::tileOnlyNeedsPartialUpdate):
(WebCore::TiledLayerChromium::tileNeedsBufferedUpdate):
(WebCore::TiledLayerChromium::prepareToUpdateTiles):

  • platform/graphics/chromium/TiledLayerChromium.h:

(TiledLayerChromium):

  • platform/graphics/chromium/cc/CCLayerTreeHost.cpp:

(WebCore::CCLayerTreeHost::CCLayerTreeHost):
(WebCore::CCLayerTreeHost::initializeLayerRenderer):
(WebCore::CCLayerTreeHost::updateLayers):
(WebCore::CCLayerTreeHost::requestPartialTextureUpdate):
(WebCore):

  • platform/graphics/chromium/cc/CCLayerTreeHost.h:

(WebCore::CCSettings::CCSettings):
(CCSettings):
(CCLayerTreeHost):

  • platform/graphics/chromium/cc/CCProxy.h:

(CCProxy):

  • platform/graphics/chromium/cc/CCSingleThreadProxy.cpp:

(WebCore::CCSingleThreadProxy::doCommit):

  • platform/graphics/chromium/cc/CCSingleThreadProxy.h:

(WebCore::CCSingleThreadProxy::maxPartialTextureUpdates):

  • platform/graphics/chromium/cc/CCTextureUpdater.cpp:

(WebCore::CCTextureUpdater::append):
(WebCore):
(WebCore::CCTextureUpdater::appendPartial):
(WebCore::CCTextureUpdater::hasMoreUpdates):
(WebCore::CCTextureUpdater::update):
(WebCore::CCTextureUpdater::clear):

  • platform/graphics/chromium/cc/CCTextureUpdater.h:

(CCTextureUpdater):

  • platform/graphics/chromium/cc/CCThreadProxy.cpp:

(WTF):
(WebCore::CCThreadProxy::scheduledActionUpdateMoreResources):
(WebCore::CCThreadProxy::maxPartialTextureUpdates):

  • platform/graphics/chromium/cc/CCThreadProxy.h:

(CCThreadProxy):

Source/WebKit/chromium:

Add CCLayerTreeHostTestAtomicCommitWithPartialUpdate and
TiledLayerChromiumTest.partialUpdates tests that verifies
atomicity of commits with partial updates.

  • tests/CCLayerTreeHostTest.cpp:

(WTF::CCLayerTreeHostTestAtomicCommit::CCLayerTreeHostTestAtomicCommit):
(WTF::CCLayerTreeHostTestAtomicCommit::beginTest):
(WTF::CCLayerTreeHostTestAtomicCommit::commitCompleteOnCCThread):
(WTF::CCLayerTreeHostTestAtomicCommit::layout):
(CCLayerTreeHostTestAtomicCommit):
(CCLayerTreeHostTestAtomicCommitWithPartialUpdate):
(WTF::CCLayerTreeHostTestAtomicCommitWithPartialUpdate::CCLayerTreeHostTestAtomicCommitWithPartialUpdate):
(WTF::CCLayerTreeHostTestAtomicCommitWithPartialUpdate::beginTest):
(WTF::CCLayerTreeHostTestAtomicCommitWithPartialUpdate::commitCompleteOnCCThread):
(WTF::CCLayerTreeHostTestAtomicCommitWithPartialUpdate::drawLayersOnCCThread):
(WTF::CCLayerTreeHostTestAtomicCommitWithPartialUpdate::layout):
(WTF::CCLayerTreeHostTestAtomicCommitWithPartialUpdate::afterTest):
(WTF):
(WTF::TEST_F):

  • tests/TiledLayerChromiumTest.cpp:

(WTF::FakeLayerTextureUpdater::Texture::Texture):
(WTF::FakeLayerTextureUpdater::Texture::updateRect):
(Texture):
(WTF::FakeLayerTextureUpdater::FakeLayerTextureUpdater):
(FakeLayerTextureUpdater):
(WTF::FakeLayerTextureUpdater::updateCount):
(WTF::FakeLayerTextureUpdater::clearUpdateCount):
(WTF::FakeLayerTextureUpdater::updateRect):
(WTF::FakeLayerTextureUpdater::createTexture):
(FakeTiledLayerChromium):
(WTF::TEST):
(WTF):

Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r107176 r107177  
     12012-02-08  David Reveman  <reveman@chromium.org>
     2
     3        [Chromium] Avoid unnecessary full tile updates without breaking atomicity of commits.
     4        https://bugs.webkit.org/show_bug.cgi?id=76740
     5
     6        Reviewed by James Robinson.
     7
     8        Allow the final batch of texture uploads to be performed without
     9        allocating new textures and re-painting complete tiles.
     10
     11        This patch is tested by the following unit test:
     12        - CCLayerTreeHostTestAtomicCommitWithPartialUpdate.runMultiThread
     13        - TiledLayerChromiumTest.partialUpdates
     14
     15        * platform/graphics/chromium/TiledLayerChromium.cpp:
     16        (WebCore::UpdatableTile::UpdatableTile):
     17        (UpdatableTile):
     18        (WebCore::TiledLayerChromium::updateCompositorResources):
     19        (WebCore):
     20        (WebCore::TiledLayerChromium::tileOnlyNeedsPartialUpdate):
     21        (WebCore::TiledLayerChromium::tileNeedsBufferedUpdate):
     22        (WebCore::TiledLayerChromium::prepareToUpdateTiles):
     23        * platform/graphics/chromium/TiledLayerChromium.h:
     24        (TiledLayerChromium):
     25        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
     26        (WebCore::CCLayerTreeHost::CCLayerTreeHost):
     27        (WebCore::CCLayerTreeHost::initializeLayerRenderer):
     28        (WebCore::CCLayerTreeHost::updateLayers):
     29        (WebCore::CCLayerTreeHost::requestPartialTextureUpdate):
     30        (WebCore):
     31        * platform/graphics/chromium/cc/CCLayerTreeHost.h:
     32        (WebCore::CCSettings::CCSettings):
     33        (CCSettings):
     34        (CCLayerTreeHost):
     35        * platform/graphics/chromium/cc/CCProxy.h:
     36        (CCProxy):
     37        * platform/graphics/chromium/cc/CCSingleThreadProxy.cpp:
     38        (WebCore::CCSingleThreadProxy::doCommit):
     39        * platform/graphics/chromium/cc/CCSingleThreadProxy.h:
     40        (WebCore::CCSingleThreadProxy::maxPartialTextureUpdates):
     41        * platform/graphics/chromium/cc/CCTextureUpdater.cpp:
     42        (WebCore::CCTextureUpdater::append):
     43        (WebCore):
     44        (WebCore::CCTextureUpdater::appendPartial):
     45        (WebCore::CCTextureUpdater::hasMoreUpdates):
     46        (WebCore::CCTextureUpdater::update):
     47        (WebCore::CCTextureUpdater::clear):
     48        * platform/graphics/chromium/cc/CCTextureUpdater.h:
     49        (CCTextureUpdater):
     50        * platform/graphics/chromium/cc/CCThreadProxy.cpp:
     51        (WTF):
     52        (WebCore::CCThreadProxy::scheduledActionUpdateMoreResources):
     53        (WebCore::CCThreadProxy::maxPartialTextureUpdates):
     54        * platform/graphics/chromium/cc/CCThreadProxy.h:
     55        (CCThreadProxy):
     56
    1572012-02-07  MORITA Hajime  <morrita@google.com>
    258
  • trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp

    r106891 r107177  
    5454    WTF_MAKE_NONCOPYABLE(UpdatableTile);
    5555public:
    56     explicit UpdatableTile(PassOwnPtr<LayerTextureUpdater::Texture> texture) : m_texture(texture) { }
     56    explicit UpdatableTile(PassOwnPtr<LayerTextureUpdater::Texture> texture)
     57        : m_partialUpdate(false)
     58        , m_texture(texture)
     59    {
     60    }
    5761
    5862    LayerTextureUpdater::Texture* texture() { return m_texture.get(); }
     
    6973    IntRect m_updateRect;
    7074    IntRect m_opaqueRect;
     75    bool m_partialUpdate;
    7176private:
    7277    OwnPtr<LayerTextureUpdater::Texture> m_texture;
     
    211216                CRASH();
    212217
    213             updater.append(tile->texture(), sourceRect, destRect);
     218            if (tile->m_partialUpdate)
     219                updater.appendPartial(tile->texture(), sourceRect, destRect);
     220            else
     221                updater.append(tile->texture(), sourceRect, destRect);
    214222        }
    215223    }
     
    352360}
    353361
     362// Returns true if tile is dirty and only part of it needs to be updated.
     363bool TiledLayerChromium::tileOnlyNeedsPartialUpdate(UpdatableTile* tile)
     364{
     365    if (!tile->managedTexture()->isValid(m_tiler->tileSize(), m_textureFormat))
     366        return false;
     367
     368    if (!tile->isDirty())
     369        return false;
     370
     371    return !tile->m_dirtyRect.contains(m_tiler->tileRect(tile));
     372}
     373
     374// Dirty tiles with valid textures needs buffered update to guarantee that
     375// we don't modify textures currently used for drawing by the impl thread.
     376bool TiledLayerChromium::tileNeedsBufferedUpdate(UpdatableTile* tile)
     377{
     378    // No impl thread?.
     379    if (!CCProxy::hasImplThread())
     380        return false;
     381
     382    if (!tile->managedTexture()->isValid(m_tiler->tileSize(), m_textureFormat))
     383        return false;
     384
     385    if (!tile->isDirty())
     386        return false;
     387
     388    return true;
     389}
     390
    354391void TiledLayerChromium::prepareToUpdateTiles(bool idle, int left, int top, int right, int bottom)
    355392{
     
    358395        UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second.get());
    359396        tile->m_updateRect = IntRect();
     397        tile->m_partialUpdate = false;
    360398    }
    361399
     
    373411                tile = createTile(i, j);
    374412
    375             // Do post commit deletion of current texture when partial texture
    376             // updates are not used.
    377             if (tile->isDirty() && layerTreeHost() && !layerTreeHost()->settings().partialTextureUpdates)
     413            // FIXME: Decide if partial update should be allowed based on cost
     414            // of update. https://bugs.webkit.org/show_bug.cgi?id=77376
     415            if (tileOnlyNeedsPartialUpdate(tile) && layerTreeHost() && layerTreeHost()->requestPartialTextureUpdate())
     416                tile->m_partialUpdate = true;
     417            else if (tileNeedsBufferedUpdate(tile) && layerTreeHost())
    378418                layerTreeHost()->deleteTextureAfterCommit(tile->managedTexture()->steal());
    379419
  • trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.h

    r106891 r107177  
    108108    void setTilingOption(TilingOption);
    109109
     110    bool tileOnlyNeedsPartialUpdate(UpdatableTile*);
     111    bool tileNeedsBufferedUpdate(UpdatableTile*);
     112
    110113    void prepareToUpdateTiles(bool idle, int left, int top, int right, int bottom);
    111114    IntRect idlePaintRect(const IntRect& visibleLayerRect);
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp

    r106986 r107177  
    4040#include "cc/CCThreadProxy.h"
    4141
     42using namespace std;
     43
    4244namespace {
    4345static int numLayerTreeInstances;
     
    7274    , m_maxPageScale(1)
    7375    , m_triggerIdlePaints(true)
     76    , m_partialTextureUpdateRequests(0)
    7477{
    7578    ASSERT(CCProxy::isMainThread());
     
    121124
    122125    // Update m_settings based on partial update capability.
    123     m_settings.partialTextureUpdates = m_settings.partialTextureUpdates && m_proxy->partialTextureUpdateCapability();
     126    m_settings.maxPartialTextureUpdates = min(m_settings.maxPartialTextureUpdates, m_proxy->maxPartialTextureUpdates());
    124127
    125128    m_contentsTextureManager = TextureManager::create(TextureManager::highLimitBytes(viewportSize()),
     
    415418        CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(rootLayer, rootLayer, identityMatrix, identityMatrix, m_updateList, rootRenderSurface->layerList(), layerRendererCapabilities().maxTextureSize);
    416419    }
     420
     421    // Reset partial texture update requests.
     422    m_partialTextureUpdateRequests = 0;
    417423
    418424    reserveTextures();
     
    624630}
    625631
     632bool CCLayerTreeHost::requestPartialTextureUpdate()
     633{
     634    if (m_partialTextureUpdateRequests >= m_settings.maxPartialTextureUpdates)
     635        return false;
     636
     637    m_partialTextureUpdateRequests++;
     638    return true;
     639}
     640
    626641void CCLayerTreeHost::deleteTextureAfterCommit(PassOwnPtr<ManagedTexture> texture)
    627642{
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h

    r106986 r107177  
    3434#include "cc/CCProxy.h"
    3535
     36#include <limits>
    3637#include <wtf/HashMap.h>
    3738#include <wtf/PassOwnPtr.h>
     
    7576            , perTilePainting(false)
    7677            , partialSwapEnabled(false)
    77             , partialTextureUpdates(true) { }
     78            , maxPartialTextureUpdates(std::numeric_limits<size_t>::max()) { }
    7879
    7980    bool acceleratePainting;
     
    8485    bool perTilePainting;
    8586    bool partialSwapEnabled;
    86     bool partialTextureUpdates;
     87    size_t maxPartialTextureUpdates;
    8788};
    8889
     
    193194    void stopRateLimiter(GraphicsContext3D*);
    194195
     196    bool requestPartialTextureUpdate();
    195197    void deleteTextureAfterCommit(PassOwnPtr<ManagedTexture>);
    196198
     
    244246
    245247    TextureList m_deleteTextureAfterCommitList;
     248    size_t m_partialTextureUpdateRequests;
    246249};
    247250
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCProxy.h

    r106700 r107177  
    8181    virtual void stop() = 0; // Must be called before deleting the proxy.
    8282
    83     // Whether sub-regions of textures can be updated or if complete texture
    84     // updates are required.
    85     virtual bool partialTextureUpdateCapability() const = 0;
     83    // Maximum number of sub-region texture updates supported for each commit.
     84    virtual size_t maxPartialTextureUpdates() const = 0;
    8685
    8786    // Debug hooks
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp

    r107161 r107177  
    3434#include <wtf/CurrentTime.h>
    3535
     36using namespace std;
    3637using namespace WTF;
    3738
     
    173174        CCTextureUpdater updater(m_layerTreeHostImpl->contentsTextureAllocator());
    174175        m_layerTreeHost->updateCompositorResources(m_layerTreeHostImpl->context(), updater);
    175         while (updater.update(m_layerTreeHostImpl->context(), 1)) { }
     176        updater.update(m_layerTreeHostImpl->context(), numeric_limits<size_t>::max());
     177        ASSERT(!updater.hasMoreUpdates());
    176178        m_layerTreeHostImpl->setVisible(m_layerTreeHost->visible());
    177179        m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get());
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.h

    r106986 r107177  
    2929#include "cc/CCLayerTreeHostImpl.h"
    3030#include "cc/CCProxy.h"
     31#include <limits>
    3132#include <wtf/OwnPtr.h>
    3233
     
    5657    virtual void start();
    5758    virtual void stop();
    58     virtual bool partialTextureUpdateCapability() const { return true; }
     59    virtual size_t maxPartialTextureUpdates() const { return std::numeric_limits<size_t>::max(); }
    5960
    6061    // CCLayerTreeHostImplClient implementation
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdater.cpp

    r101600 r107177  
    4949}
    5050
    51 void CCTextureUpdater::append(LayerTextureUpdater::Texture* texture, const IntRect& sourceRect, const IntRect& destRect)
     51void CCTextureUpdater::append(LayerTextureUpdater::Texture* texture, const IntRect& sourceRect, const IntRect& destRect, Vector<UpdateEntry>& entries)
    5252{
    5353    ASSERT(texture);
     
    5757    entry.m_sourceRect = sourceRect;
    5858    entry.m_destRect = destRect;
    59     m_entries.append(entry);
     59    entries.append(entry);
     60}
     61
     62void CCTextureUpdater::append(LayerTextureUpdater::Texture* texture, const IntRect& sourceRect, const IntRect& destRect)
     63{
     64    append(texture, sourceRect, destRect, m_entries);
     65}
     66
     67void CCTextureUpdater::appendPartial(LayerTextureUpdater::Texture* texture, const IntRect& sourceRect, const IntRect& destRect)
     68{
     69    append(texture, sourceRect, destRect, m_partialEntries);
    6070}
    6171
    6272bool CCTextureUpdater::hasMoreUpdates() const
    6373{
    64     return m_entries.size();
     74    return m_entries.size() || m_partialEntries.size();
    6575}
    6676
    6777bool CCTextureUpdater::update(GraphicsContext3D* context, size_t count)
    6878{
     79    size_t index;
    6980    size_t maxIndex = min(m_entryIndex + count, m_entries.size());
    70     for (; m_entryIndex < maxIndex; ++m_entryIndex) {
    71         UpdateEntry& entry = m_entries[m_entryIndex];
     81    for (index = m_entryIndex; index < maxIndex; ++index) {
     82        UpdateEntry& entry = m_entries[index];
    7283        entry.m_texture->updateRect(context, m_allocator, entry.m_sourceRect, entry.m_destRect);
    7384    }
    7485
    75     if (maxIndex < m_entries.size())
     86    bool moreUpdates = maxIndex < m_entries.size();
     87
     88    ASSERT(m_partialEntries.size() <= count);
     89    // Make sure the number of updates including partial updates are not more
     90    // than |count|.
     91    if ((count - (index - m_entryIndex)) < m_partialEntries.size())
     92        moreUpdates = true;
     93
     94    if (moreUpdates) {
     95        m_entryIndex = index;
    7696        return true;
     97    }
     98
     99    for (index = 0; index < m_partialEntries.size(); ++index) {
     100        UpdateEntry& entry = m_partialEntries[index];
     101        entry.m_texture->updateRect(context, m_allocator, entry.m_sourceRect, entry.m_destRect);
     102    }
    77103
    78104    // If no entries left to process, auto-clear.
     
    85111    m_entryIndex = 0;
    86112    m_entries.clear();
     113    m_partialEntries.clear();
    87114}
    88115
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdater.h

    r101600 r107177  
    4242
    4343    void append(LayerTextureUpdater::Texture*, const IntRect& sourceRect, const IntRect& destRect);
     44    void appendPartial(LayerTextureUpdater::Texture*, const IntRect& sourceRect, const IntRect& destRect);
    4445
    4546    bool hasMoreUpdates() const;
     
    5960    };
    6061
     62    static void append(LayerTextureUpdater::Texture*, const IntRect& sourceRect, const IntRect& destRect, Vector<UpdateEntry>&);
     63
    6164    TextureAllocator* m_allocator;
    6265    size_t m_entryIndex;
    6366    Vector<UpdateEntry> m_entries;
     67    Vector<UpdateEntry> m_partialEntries;
    6468};
    6569
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp

    r106986 r107177  
    4444namespace {
    4545
    46 static const size_t textureUpdatesPerFrame = 0;
     46// Number of textures to update with each call to
     47// scheduledActionUpdateMoreResources().
     48static const size_t textureUpdatesPerFrame = 5;
    4749
    4850} // anonymous namespace
     
    463465    TRACE_EVENT("CCThreadProxy::scheduledActionUpdateMoreResources", this, 0);
    464466    ASSERT(m_currentTextureUpdaterOnImplThread);
    465     m_currentTextureUpdaterOnImplThread->update(m_layerTreeHostImpl->context(), textureUpdatesPerFrame > 0 ? textureUpdatesPerFrame : 99999);
     467    m_currentTextureUpdaterOnImplThread->update(m_layerTreeHostImpl->context(), textureUpdatesPerFrame);
    466468}
    467469
     
    596598}
    597599
    598 bool CCThreadProxy::partialTextureUpdateCapability() const
    599 {
    600     return !textureUpdatesPerFrame;
     600size_t CCThreadProxy::maxPartialTextureUpdates() const
     601{
     602    return textureUpdatesPerFrame;
    601603}
    602604
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.h

    r106951 r107177  
    6464    virtual void start();
    6565    virtual void stop();
    66     virtual bool partialTextureUpdateCapability() const;
     66    virtual size_t maxPartialTextureUpdates() const;
    6767
    6868    // CCLayerTreeHostImplClient implementation
  • trunk/Source/WebKit/chromium/ChangeLog

    r107176 r107177  
     12012-02-08  David Reveman  <reveman@chromium.org>
     2
     3        [Chromium] Avoid unnecessary full tile updates without breaking atomicity of commits.
     4        https://bugs.webkit.org/show_bug.cgi?id=76740
     5
     6        Reviewed by James Robinson.
     7
     8        Add CCLayerTreeHostTestAtomicCommitWithPartialUpdate and
     9        TiledLayerChromiumTest.partialUpdates tests that verifies
     10        atomicity of commits with partial updates.
     11
     12        * tests/CCLayerTreeHostTest.cpp:
     13        (WTF::CCLayerTreeHostTestAtomicCommit::CCLayerTreeHostTestAtomicCommit):
     14        (WTF::CCLayerTreeHostTestAtomicCommit::beginTest):
     15        (WTF::CCLayerTreeHostTestAtomicCommit::commitCompleteOnCCThread):
     16        (WTF::CCLayerTreeHostTestAtomicCommit::layout):
     17        (CCLayerTreeHostTestAtomicCommit):
     18        (CCLayerTreeHostTestAtomicCommitWithPartialUpdate):
     19        (WTF::CCLayerTreeHostTestAtomicCommitWithPartialUpdate::CCLayerTreeHostTestAtomicCommitWithPartialUpdate):
     20        (WTF::CCLayerTreeHostTestAtomicCommitWithPartialUpdate::beginTest):
     21        (WTF::CCLayerTreeHostTestAtomicCommitWithPartialUpdate::commitCompleteOnCCThread):
     22        (WTF::CCLayerTreeHostTestAtomicCommitWithPartialUpdate::drawLayersOnCCThread):
     23        (WTF::CCLayerTreeHostTestAtomicCommitWithPartialUpdate::layout):
     24        (WTF::CCLayerTreeHostTestAtomicCommitWithPartialUpdate::afterTest):
     25        (WTF):
     26        (WTF::TEST_F):
     27        * tests/TiledLayerChromiumTest.cpp:
     28        (WTF::FakeLayerTextureUpdater::Texture::Texture):
     29        (WTF::FakeLayerTextureUpdater::Texture::updateRect):
     30        (Texture):
     31        (WTF::FakeLayerTextureUpdater::FakeLayerTextureUpdater):
     32        (FakeLayerTextureUpdater):
     33        (WTF::FakeLayerTextureUpdater::updateCount):
     34        (WTF::FakeLayerTextureUpdater::clearUpdateCount):
     35        (WTF::FakeLayerTextureUpdater::updateRect):
     36        (WTF::FakeLayerTextureUpdater::createTexture):
     37        (FakeTiledLayerChromium):
     38        (WTF::TEST):
     39        (WTF):
     40
    1412012-02-07  MORITA Hajime  <morrita@google.com>
    242
  • trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp

    r106994 r107177  
    11481148public:
    11491149    CCLayerTreeHostTestAtomicCommit()
    1150         : m_updateCheckLayer(ContentLayerChromiumWithUpdateTracking::create(&m_delegate))
    1151         , m_numCommits(0)
     1150        : m_layer(ContentLayerChromiumWithUpdateTracking::create(&m_delegate))
    11521151    {
    11531152        // Make sure partial texture updates are turned off.
    1154         m_settings.partialTextureUpdates = false;
     1153        m_settings.maxPartialTextureUpdates = 0;
    11551154    }
    11561155
    11571156    virtual void beginTest()
    11581157    {
    1159         m_layerTreeHost->setRootLayer(m_updateCheckLayer);
     1158        m_layerTreeHost->setRootLayer(m_layer);
    11601159        m_layerTreeHost->setViewportSize(IntSize(10, 10));
    11611160
     
    11741173            // Number of textures used for commit should be one.
    11751174            EXPECT_EQ(1, context->numUsedTextures());
    1176             // Verify used texture is correct.
     1175            // Verify that used texture is correct.
    11771176            EXPECT_TRUE(context->usedTexture(context->texture(0)));
    11781177
     
    12151214    virtual void layout()
    12161215    {
    1217         m_updateCheckLayer->setNeedsDisplay();
     1216        m_layer->setNeedsDisplay();
    12181217    }
    12191218
     
    12241223private:
    12251224    MockContentLayerDelegate m_delegate;
    1226     RefPtr<ContentLayerChromiumWithUpdateTracking> m_updateCheckLayer;
     1225    RefPtr<ContentLayerChromiumWithUpdateTracking> m_layer;
     1226};
     1227
     1228TEST_F(CCLayerTreeHostTestAtomicCommit, runMultiThread)
     1229{
     1230    runTest(true);
     1231}
     1232
     1233class CCLayerTreeHostTestAtomicCommitWithPartialUpdate : public CCLayerTreeHostTest {
     1234public:
     1235    CCLayerTreeHostTestAtomicCommitWithPartialUpdate()
     1236        : m_parent(ContentLayerChromiumWithUpdateTracking::create(&m_delegate))
     1237        , m_child(ContentLayerChromiumWithUpdateTracking::create(&m_delegate))
     1238        , m_numCommits(0)
     1239    {
     1240        // Allow one partial texture update.
     1241        m_settings.maxPartialTextureUpdates = 1;
     1242    }
     1243
     1244    virtual void beginTest()
     1245    {
     1246        m_layerTreeHost->setRootLayer(m_parent);
     1247        m_layerTreeHost->setViewportSize(IntSize(10, 10));
     1248        m_parent->addChild(m_child);
     1249        m_child->setOpacity(0.5);
     1250        m_child->setBounds(IntSize(20, 20));
     1251
     1252        postSetNeedsCommitToMainThread();
     1253        postSetNeedsRedrawToMainThread();
     1254    }
     1255
     1256    virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl* impl)
     1257    {
     1258        CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(impl->context()));
     1259
     1260        switch (impl->frameNumber()) {
     1261        case 0:
     1262            // Number of textures should be two.
     1263            EXPECT_EQ(2, context->numTextures());
     1264            // Number of textures used for commit should be two.
     1265            EXPECT_EQ(2, context->numUsedTextures());
     1266            // Verify that used textures are correct.
     1267            EXPECT_TRUE(context->usedTexture(context->texture(0)));
     1268            EXPECT_TRUE(context->usedTexture(context->texture(1)));
     1269
     1270            context->resetUsedTextures();
     1271            break;
     1272        case 1:
     1273            // Number of textures should be four as the first two
     1274            // textures are used by the impl thread.
     1275            EXPECT_EQ(4, context->numTextures());
     1276            // Number of textures used for commit should still be two.
     1277            EXPECT_EQ(2, context->numUsedTextures());
     1278            // First two textures should not have been used.
     1279            EXPECT_FALSE(context->usedTexture(context->texture(0)));
     1280            EXPECT_FALSE(context->usedTexture(context->texture(1)));
     1281            // New textures should have been used.
     1282            EXPECT_TRUE(context->usedTexture(context->texture(2)));
     1283            EXPECT_TRUE(context->usedTexture(context->texture(3)));
     1284
     1285            context->resetUsedTextures();
     1286            break;
     1287        case 2:
     1288            // Number of textures should be three as we allow one
     1289            // partial update and the first two textures are used by
     1290            // the impl thread.
     1291            EXPECT_EQ(3, context->numTextures());
     1292            // Number of textures used for commit should still be two.
     1293            EXPECT_EQ(2, context->numUsedTextures());
     1294            // First texture should not have been used.
     1295            EXPECT_FALSE(context->usedTexture(context->texture(0)));
     1296            // Second texture should have been used.
     1297            EXPECT_TRUE(context->usedTexture(context->texture(1)));
     1298            // New textures should have been used.
     1299            EXPECT_TRUE(context->usedTexture(context->texture(2)));
     1300
     1301            context->resetUsedTextures();
     1302            break;
     1303        default:
     1304            ASSERT_NOT_REACHED();
     1305            break;
     1306        }
     1307    }
     1308
     1309    virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
     1310    {
     1311        CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(impl->context()));
     1312
     1313        // Number of textures used for drawing should always be two.
     1314        EXPECT_EQ(2, context->numUsedTextures());
     1315
     1316        if (impl->frameNumber() < 3) {
     1317            context->resetUsedTextures();
     1318            postSetNeedsAnimateAndCommitToMainThread();
     1319            postSetNeedsRedrawToMainThread();
     1320        } else
     1321            endTest();
     1322    }
     1323
     1324    virtual void layout()
     1325    {
     1326        switch (m_numCommits++) {
     1327        case 0:
     1328        case 1:
     1329            m_parent->setNeedsDisplay();
     1330            m_child->setNeedsDisplay();
     1331            break;
     1332        case 2:
     1333            // Damage part of layers.
     1334            m_parent->setNeedsDisplayRect(FloatRect(0, 0, 5, 5));
     1335            m_child->setNeedsDisplayRect(FloatRect(0, 0, 5, 5));
     1336            break;
     1337        default:
     1338            ASSERT_NOT_REACHED();
     1339            break;
     1340        }
     1341    }
     1342
     1343    virtual void afterTest()
     1344    {
     1345    }
     1346
     1347private:
     1348    MockContentLayerDelegate m_delegate;
     1349    RefPtr<ContentLayerChromiumWithUpdateTracking> m_parent;
     1350    RefPtr<ContentLayerChromiumWithUpdateTracking> m_child;
    12271351    int m_numCommits;
    12281352};
    12291353
    1230 TEST_F(CCLayerTreeHostTestAtomicCommit, runMultiThread)
     1354TEST_F(CCLayerTreeHostTestAtomicCommitWithPartialUpdate, runMultiThread)
    12311355{
    12321356    runTest(true);
  • trunk/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp

    r106891 r107177  
    6161    class Texture : public LayerTextureUpdater::Texture {
    6262    public:
    63         Texture(PassOwnPtr<ManagedTexture> texture) : LayerTextureUpdater::Texture(texture) { }
     63        Texture(FakeLayerTextureUpdater* layer, PassOwnPtr<ManagedTexture> texture)
     64            : LayerTextureUpdater::Texture(texture)
     65            , m_layer(layer)
     66        {
     67        }
    6468        virtual ~Texture() { }
    6569
    66         virtual void updateRect(GraphicsContext3D*, TextureAllocator*, const IntRect&, const IntRect&) { }
     70        virtual void updateRect(GraphicsContext3D*, TextureAllocator*, const IntRect&, const IntRect&) { m_layer->updateRect(); }
     71
     72    private:
     73        FakeLayerTextureUpdater* m_layer;
    6774    };
    6875
    69     FakeLayerTextureUpdater() : m_prepareCount(0) { }
     76    FakeLayerTextureUpdater()
     77        : m_prepareCount(0)
     78        , m_updateCount(0)
     79    {
     80    }
    7081    virtual ~FakeLayerTextureUpdater() { }
    7182
     
    7889    void clearPrepareCount() { m_prepareCount = 0; }
    7990
     91    // Number of times updateRect has been invoked.
     92    int updateCount() const { return m_updateCount; }
     93    void clearUpdateCount() { m_updateCount = 0; }
     94    void updateRect() { m_updateCount++; }
     95
    8096    void setOpaquePaintRect(const IntRect& opaquePaintRect) { m_opaquePaintRect = opaquePaintRect; }
    8197
     
    8399    const IntRect& lastUpdateRect()  const { return m_lastUpdateRect; }
    84100
    85     virtual PassOwnPtr<LayerTextureUpdater::Texture> createTexture(TextureManager* manager) { return adoptPtr(new Texture(ManagedTexture::create(manager))); }
     101    virtual PassOwnPtr<LayerTextureUpdater::Texture> createTexture(TextureManager* manager) { return adoptPtr(new Texture(this, ManagedTexture::create(manager))); }
    86102    virtual SampledTexelFormat sampledTexelFormat(GC3Denum) { return SampledTexelFormatRGBA; }
    87103    virtual void prepareToUpdate(const IntRect& contentRect, const IntSize&, int, float, IntRect* resultingOpaqueRect);
     
    89105private:
    90106    int m_prepareCount;
     107    int m_updateCount;
    91108    IntRect m_rectToInvalidate;
    92109    IntRect m_lastUpdateRect;
     
    156173
    157174private:
    158     virtual void createTextureUpdater(const CCLayerTreeHost*) { }
    159 
    160175    virtual LayerTextureUpdater* textureUpdater() const
    161176    {
     
    580595}
    581596
     597TEST(TiledLayerChromiumTest, partialUpdates)
     598{
     599    CCSettings settings;
     600    settings.maxPartialTextureUpdates = 4;
     601    // Initialize without threading support.
     602    WebKit::WebCompositor::initialize(0);
     603    FakeCCLayerTreeHostClient fakeCCLayerTreeHostClient;
     604    RefPtr<CCLayerTreeHost> ccLayerTreeHost = CCLayerTreeHost::create(&fakeCCLayerTreeHostClient, settings);
     605
     606    // Create one 500 x 300 tiled layer.
     607    IntSize contentBounds(300, 200);
     608    IntRect contentRect(IntPoint::zero(), contentBounds);
     609
     610    OwnPtr<TextureManager> textureManager = TextureManager::create(60*1024*1024, 60*1024*1024, 1024);
     611    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(textureManager.get()));
     612    layer->setBounds(contentBounds);
     613    layer->setPosition(FloatPoint(150, 150));
     614    layer->invalidateRect(contentRect);
     615
     616    FakeTextureAllocator textureAllocator;
     617    CCTextureUpdater updater(&textureAllocator);
     618
     619    ccLayerTreeHost->setRootLayer(layer);
     620    ccLayerTreeHost->setViewportSize(IntSize(300, 200));
     621
     622    // Full update of all 6 tiles.
     623    ccLayerTreeHost->updateLayers();
     624    ccLayerTreeHost->updateCompositorResources(ccLayerTreeHost->context(), updater);
     625    updater.update(0, 4);
     626    EXPECT_EQ(4, layer->fakeLayerTextureUpdater()->updateCount());
     627    EXPECT_TRUE(updater.hasMoreUpdates());
     628    layer->fakeLayerTextureUpdater()->clearUpdateCount();
     629    updater.update(0, 4);
     630    EXPECT_EQ(2, layer->fakeLayerTextureUpdater()->updateCount());
     631    EXPECT_FALSE(updater.hasMoreUpdates());
     632    layer->fakeLayerTextureUpdater()->clearUpdateCount();
     633    ccLayerTreeHost->commitComplete();
     634
     635    // Full update of 3 tiles and partial update of 3 tiles.
     636    layer->invalidateRect(IntRect(0, 0, 300, 150));
     637    ccLayerTreeHost->updateLayers();
     638    ccLayerTreeHost->updateCompositorResources(ccLayerTreeHost->context(), updater);
     639    updater.update(0, 4);
     640    EXPECT_EQ(3, layer->fakeLayerTextureUpdater()->updateCount());
     641    EXPECT_TRUE(updater.hasMoreUpdates());
     642    layer->fakeLayerTextureUpdater()->clearUpdateCount();
     643    updater.update(0, 4);
     644    EXPECT_EQ(3, layer->fakeLayerTextureUpdater()->updateCount());
     645    EXPECT_FALSE(updater.hasMoreUpdates());
     646    layer->fakeLayerTextureUpdater()->clearUpdateCount();
     647    ccLayerTreeHost->commitComplete();
     648
     649    // Partial update of 6 tiles.
     650    layer->invalidateRect(IntRect(50, 50, 200, 100));
     651    ccLayerTreeHost->updateLayers();
     652    ccLayerTreeHost->updateCompositorResources(ccLayerTreeHost->context(), updater);
     653    updater.update(0, 4);
     654    EXPECT_EQ(2, layer->fakeLayerTextureUpdater()->updateCount());
     655    EXPECT_TRUE(updater.hasMoreUpdates());
     656    layer->fakeLayerTextureUpdater()->clearUpdateCount();
     657    updater.update(0, 4);
     658    EXPECT_EQ(4, layer->fakeLayerTextureUpdater()->updateCount());
     659    EXPECT_FALSE(updater.hasMoreUpdates());
     660    layer->fakeLayerTextureUpdater()->clearUpdateCount();
     661    ccLayerTreeHost->commitComplete();
     662
     663    ccLayerTreeHost->setRootLayer(0);
     664    ccLayerTreeHost.clear();
     665    WebKit::WebCompositor::shutdown();
     666}
     667
    582668} // namespace
Note: See TracChangeset for help on using the changeset viewer.