Changeset 121076 in webkit


Ignore:
Timestamp:
Jun 22, 2012 4:57:43 PM (12 years ago)
Author:
jamesr@google.com
Message:

[chromium] LayerRendererChromium is not getting visibility messages in single threaded compositing mode.
https://bugs.webkit.org/show_bug.cgi?id=89045

Reviewed by Adrienne Walker.

Based on patch by Michal Mocny <mmocny@google.com>.

Source/WebCore:

Invariants:

1.) We never commit (paint, animate, any of it) when not visible on the main thread -except- for
compositeAndReadback, regardless of threaded vs non-threaded mode
2.) CCLayerTreeHost::m_contentsTextureManager's memory budget is only set by updateLayers() when we are going to
make a frame and is always set to a non-zero value
3.) Zero-sized allocations from the GPU process are always serviced immediately on the impl thread. Non-zero
allocations are met in the next frame, whenever we would produce that frame according to our usual frame
scheduling logic.
4.) The impl thread always knows the set of currently-allocated managed texture IDs and can delete them all
whenever it likes without needing the main thread to be responsive.

Details:

There are two main changes - tweaking how the contents texture manager's budget is handled and tweaking frame
scheduling for the !visible case.

The scheduling change is a bit more subtle but it unifies the single and multi threaded paths and is really
important. Except for compositeAndReadback (which I'll talk about below), we simply won't produce frames when
not visible. This already happens in the single threaded path thanks to render_widget so the only change is to
the threaded path. The difficulty here is we might post a beginFrame task from the impl thread and then get a
setVisible(false) call on the main thread before the beginFrame task runs. Since I'm making the setVisible()
call a blocking call from main thread -> impl thread, when the beginFrame task eventually does run on the main
thread we can know that the impl thread's notion of visibility is in sync with the main threads. Thus I'm
planning to simply abort the frame before doing any processing on the main thread. The scheduler will know if
it gets a beginFrameAborted and COMMIT_STATE_IDLE.

compositeAndReadback is special - this call currently does come in when we aren't visible (in single and
threaded mode) and we need to service it. In particular, we need to send a beginFrame over and have it
not be ignored on the main thread. For this I'm thinking of having the proxy keep track of whether it's
servicing a compositeAndReadback() and use that bit on the main thread to know to process the beginFrame
normally. On the impl side, we need a few changes. First, we have to allocate a default framebuffer
(ensureFramebufferCHROMIUM) even if we've dropped it previously and remember to discard it after the
readPixels(). Second, we have to provide a non-zero contents texture allocation on the beginFrame message, and
again remember to delete the textures after the readPixels(). Third, we have to know that the beginFrame is a
forced frame so when we get the beginFrameComplete we go ahead with the rest of the frame. For this, I think
I'll have to add ACTION_BEGIN_FORCED_FRAME and a corresponding COMMIT_STATE_FORCED_FRAME_IN_PROGRESS so the
scheduler can keep track of the magicness of this frame, and then add some logic after the readpixels call to
drop resources after the readback. It's probably a good time to stop swapping on readbacks too....

The contents texture manager's budget is only relevant when we want to make a frame, so it's now passed in on
the updateLayers(). Since we only make frames when we are visible and we never have a zero allocation when
visible (thanks to the frame scheduling changes above), this value is always non-zero. The other thing the
texture manager needs to know about is if we've killed all of the underlying textures from the impl thread -
this bit is passed in by the proxy before the updateLayers() call. This means if we're running while visible
and the manager wants to decrease our budget to something other than zero, we'll get a new (non-zero) allocation
on the impl thread, schedule a frame, then when it's time to make the frame pass the new lower limit in to
updateLayers(), then have the contents texture manager evict down to our new limit and make a frame with the new
budget. When the commit completes we'll get notified on the impl thread of which textures the contents texture
manager decided to evict and issue the deleteTexture() calls on them.

The texture budget we pass in will be based on the most recent non-zero memory allocation we received from the
GPU memory manager, or some default value I'll pull out my ass if we haven't heard anything yet. On compositor
initialization, we can't afford to wait for a round-trip through the GPU process to get a budget for the first
frame. I don't think handling a decrease to a non-zero budget on a visible tab needs to be terribly urgent - we
can get to it when we get to making the next frame. If we wanted to satisfy reduced texture budgets directly
from the impl thread, we could keep a priority-list ordered set of textures once we have priorities and delete
based on that. Let's worry about that later.

  • platform/graphics/chromium/LayerRendererChromium.cpp:

(WebCore::LayerRendererGpuMemoryAllocationChangedCallbackAdapter::onGpuMemoryAllocationChangedOnImpl):
(WebCore::LayerRendererChromium::LayerRendererChromium):
(WebCore::LayerRendererChromium::initialize):
(WebCore::LayerRendererChromium::setVisible):
(WebCore::LayerRendererChromium::setGpuMemoryAllocation):
(WebCore):
(WebCore::LayerRendererChromium::swapBuffers):
(WebCore::LayerRendererChromium::getFramebufferPixels):

  • platform/graphics/chromium/LayerRendererChromium.h:

(WebCore):
(LayerRendererChromium):

  • platform/graphics/chromium/TextureManager.cpp:

(WebCore::TextureManager::evictAndRemoveAllDeletedTextures):
(WebCore):

  • platform/graphics/chromium/TextureManager.h:

(TextureAllocator):
(TextureManager):

  • platform/graphics/chromium/TrackingTextureAllocator.cpp:

(WebCore::TrackingTextureAllocator::createTexture):
(WebCore::TrackingTextureAllocator::deleteTexture):
(WebCore):
(WebCore::TrackingTextureAllocator::deleteAllTextures):

  • platform/graphics/chromium/TrackingTextureAllocator.h:

(TrackingTextureAllocator):

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

(WebCore::CCLayerTreeHost::CCLayerTreeHost):
(WebCore::CCLayerTreeHost::initializeLayerRenderer):
(WebCore::CCLayerTreeHost::finishCommitOnImplThread):
(WebCore::CCLayerTreeHost::setVisible):
(WebCore::CCLayerTreeHost::evictAllContentTextures):
(WebCore::CCLayerTreeHost::updateLayers):

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

(CCLayerTreeHost):

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

(WebCore::CCLayerTreeHostImpl::CCLayerTreeHostImpl):
(WebCore::CCLayerTreeHostImpl::commitComplete):
(WebCore::CCLayerTreeHostImpl::canDraw):
(WebCore::CCLayerTreeHostImpl::context):
(WebCore::CCLayerTreeHostImpl::releaseContentsTextures):
(WebCore):
(WebCore::CCLayerTreeHostImpl::setMemoryAllocationLimitBytes):

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

(CCLayerTreeHostImplClient):
(WebCore::CCLayerTreeHostImpl::contentsTexturesWerePurgedSinceLastCommit):
(WebCore::CCLayerTreeHostImpl::memoryAllocationLimitBytes):
(CCLayerTreeHostImpl):

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

(CCProxy):

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

(CCRendererClient):

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

(WebCore::CCScheduler::beginFrameComplete):
(WebCore::CCScheduler::beginFrameAborted):
(WebCore):
(WebCore::CCScheduler::didSwapBuffersComplete):
(WebCore::CCScheduler::didLoseContext):
(WebCore::CCScheduler::didRecreateContext):
(WebCore::CCScheduler::vsyncTick):

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

(CCScheduler):

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

(WebCore::CCSchedulerStateMachine::beginFrameAborted):
(WebCore):

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

(WebCore::CCSingleThreadProxy::setVisible):
(WebCore):
(WebCore::CCSingleThreadProxy::stop):
(WebCore::CCSingleThreadProxy::commitAndComposite):

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

(CCSingleThreadProxy):

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

(WebCore::CCThreadProxy::CCThreadProxy):
(WebCore::CCThreadProxy::compositeAndReadback):
(WebCore::CCThreadProxy::setVisible):
(WebCore):
(WebCore::CCThreadProxy::setVisibleOnImplThread):
(WebCore::CCThreadProxy::scheduledActionBeginFrame):
(WebCore::CCThreadProxy::beginFrame):
(WebCore::CCThreadProxy::beginFrameAbortedOnImplThread):
(WebCore::CCThreadProxy::scheduledActionDrawAndSwapInternal):
(WebCore::CCThreadProxy::layerTreeHostClosedOnImplThread):

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

(CCThreadProxy):
(BeginFrameAndCommitState):

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

(WebCore::CCVideoLayerImpl::~CCVideoLayerImpl):
(WebCore::CCVideoLayerImpl::willDraw):
(WebCore::CCVideoLayerImpl::willDrawInternal):
(WebCore::CCVideoLayerImpl::FramePlane::allocateData):
(WebCore::CCVideoLayerImpl::FramePlane::freeData):
(WebCore::CCVideoLayerImpl::allocatePlaneData):
(WebCore::CCVideoLayerImpl::freePlaneData):
(WebCore::CCVideoLayerImpl::freeUnusedPlaneData):
(WebCore::CCVideoLayerImpl::didLoseContext):

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

(FramePlane):

Source/WebKit/chromium:

Update various test fixtures and tests to cover scheduling, visibility, and resource allocation changes.

  • tests/CCLayerTreeHostImplTest.cpp:
  • tests/CCLayerTreeHostTest.cpp:

(CCLayerTreeHostTestAbortFrameWhenInvisible):
(WTF::CCLayerTreeHostTestAbortFrameWhenInvisible::CCLayerTreeHostTestAbortFrameWhenInvisible):
(WTF::CCLayerTreeHostTestAbortFrameWhenInvisible::beginTest):
(WTF::CCLayerTreeHostTestAbortFrameWhenInvisible::afterTest):
(WTF):
(WTF::TEST_F):
(WTF::CCLayerTreeHostTestLayerOcclusion::beginTest):
(WTF::CCLayerTreeHostTestLayerOcclusionWithFilters::beginTest):
(WTF::CCLayerTreeHostTestManySurfaces::beginTest):

  • tests/CCSchedulerStateMachineTest.cpp:

(WebCore::TEST):

  • tests/CCTiledLayerTestCommon.h:
  • tests/FakeWebGraphicsContext3D.h:

(WebKit::FakeWebGraphicsContext3D::FakeWebGraphicsContext3D):
(FakeWebGraphicsContext3D):
(WebKit::FakeWebGraphicsContext3D::createTexture):

  • tests/LayerRendererChromiumTest.cpp:

(TEST_F):

  • tests/TiledLayerChromiumTest.cpp:
Location:
trunk/Source
Files:
31 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r121072 r121076  
     12012-06-22  James Robinson  <jamesr@chromium.org>
     2
     3        [chromium] LayerRendererChromium is not getting visibility messages in single threaded compositing mode.
     4        https://bugs.webkit.org/show_bug.cgi?id=89045
     5
     6        Reviewed by Adrienne Walker.
     7
     8        Based on patch by Michal Mocny <mmocny@google.com>.
     9
     10        Invariants:
     11
     12        1.) We never commit (paint, animate, any of it) when not visible on the main thread -except- for
     13        compositeAndReadback, regardless of threaded vs non-threaded mode
     14        2.) CCLayerTreeHost::m_contentsTextureManager's memory budget is only set by updateLayers() when we are going to
     15        make a frame and is always set to a non-zero value
     16        3.) Zero-sized allocations from the GPU process are always serviced immediately on the impl thread.  Non-zero
     17        allocations are met in the next frame, whenever we would produce that frame according to our usual frame
     18        scheduling logic.
     19        4.) The impl thread always knows the set of currently-allocated managed texture IDs and can delete them all
     20        whenever it likes without needing the main thread to be responsive.
     21
     22        Details:
     23
     24        There are two main changes - tweaking how the contents texture manager's budget is handled and tweaking frame
     25        scheduling for the !visible case.
     26
     27        The scheduling change is a bit more subtle but it unifies the single and multi threaded paths and is really
     28        important.  Except for compositeAndReadback (which I'll talk about below), we simply won't produce frames when
     29        not visible.  This already happens in the single threaded path thanks to render_widget so the only change is to
     30        the threaded path.  The difficulty here is we might post a beginFrame task from the impl thread and then get a
     31        setVisible(false) call on the main thread before the beginFrame task runs.  Since I'm making the setVisible()
     32        call a blocking call from main thread -> impl thread, when the beginFrame task eventually does run on the main
     33        thread we can know that the impl thread's notion of visibility is in sync with the main threads.  Thus I'm
     34        planning to simply abort the frame before doing any processing on the main thread.  The scheduler will know if
     35        it gets a beginFrameAborted and COMMIT_STATE_IDLE.
     36
     37        compositeAndReadback is special - this call currently does come in when we aren't visible (in single and
     38        threaded mode) and we need to service it.  In particular, we need to send a beginFrame over and have it
     39        not be ignored on the main thread.  For this I'm thinking of having the proxy keep track of whether it's
     40        servicing a compositeAndReadback() and use that bit on the main thread to know to process the beginFrame
     41        normally.  On the impl side, we need a few changes.  First, we have to allocate a default framebuffer
     42        (ensureFramebufferCHROMIUM) even if we've dropped it previously and remember to discard it after the
     43        readPixels().  Second, we have to provide a non-zero contents texture allocation on the beginFrame message, and
     44        again remember to delete the textures after the readPixels().  Third, we have to know that the beginFrame is a
     45        forced frame so when we get the beginFrameComplete we go ahead with the rest of the frame.  For this, I think
     46        I'll have to add ACTION_BEGIN_FORCED_FRAME and a corresponding COMMIT_STATE_FORCED_FRAME_IN_PROGRESS so the
     47        scheduler can keep track of the magicness of this frame, and then add some logic after the readpixels call to
     48        drop resources after the readback.  It's probably a good time to stop swapping on readbacks too....
     49
     50        The contents texture manager's budget is only relevant when we want to make a frame, so it's now passed in on
     51        the updateLayers().  Since we only make frames when we are visible and we never have a zero allocation when
     52        visible (thanks to the frame scheduling changes above), this value is always non-zero.  The other thing the
     53        texture manager needs to know about is if we've killed all of the underlying textures from the impl thread -
     54        this bit is passed in by the proxy before the updateLayers() call.  This means if we're running while visible
     55        and the manager wants to decrease our budget to something other than zero, we'll get a new (non-zero) allocation
     56        on the impl thread, schedule a frame, then when it's time to make the frame pass the new lower limit in to
     57        updateLayers(), then have the contents texture manager evict down to our new limit and make a frame with the new
     58        budget.  When the commit completes we'll get notified on the impl thread of which textures the contents texture
     59        manager decided to evict and issue the deleteTexture() calls on them.
     60
     61        The texture budget we pass in will be based on the most recent non-zero memory allocation we received from the
     62        GPU memory manager, or some default value I'll pull out my ass if we haven't heard anything yet.  On compositor
     63        initialization, we can't afford to wait for a round-trip through the GPU process to get a budget for the first
     64        frame.  I don't think handling a decrease to a non-zero budget on a visible tab needs to be terribly urgent - we
     65        can get to it when we get to making the next frame.  If we wanted to satisfy reduced texture budgets directly
     66        from the impl thread, we could keep a priority-list ordered set of textures once we have priorities and delete
     67        based on that.  Let's worry about that later.
     68
     69        * platform/graphics/chromium/LayerRendererChromium.cpp:
     70        (WebCore::LayerRendererGpuMemoryAllocationChangedCallbackAdapter::onGpuMemoryAllocationChangedOnImpl):
     71        (WebCore::LayerRendererChromium::LayerRendererChromium):
     72        (WebCore::LayerRendererChromium::initialize):
     73        (WebCore::LayerRendererChromium::setVisible):
     74        (WebCore::LayerRendererChromium::setGpuMemoryAllocation):
     75        (WebCore):
     76        (WebCore::LayerRendererChromium::swapBuffers):
     77        (WebCore::LayerRendererChromium::getFramebufferPixels):
     78        * platform/graphics/chromium/LayerRendererChromium.h:
     79        (WebCore):
     80        (LayerRendererChromium):
     81        * platform/graphics/chromium/TextureManager.cpp:
     82        (WebCore::TextureManager::evictAndRemoveAllDeletedTextures):
     83        (WebCore):
     84        * platform/graphics/chromium/TextureManager.h:
     85        (TextureAllocator):
     86        (TextureManager):
     87        * platform/graphics/chromium/TrackingTextureAllocator.cpp:
     88        (WebCore::TrackingTextureAllocator::createTexture):
     89        (WebCore::TrackingTextureAllocator::deleteTexture):
     90        (WebCore):
     91        (WebCore::TrackingTextureAllocator::deleteAllTextures):
     92        * platform/graphics/chromium/TrackingTextureAllocator.h:
     93        (TrackingTextureAllocator):
     94        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
     95        (WebCore::CCLayerTreeHost::CCLayerTreeHost):
     96        (WebCore::CCLayerTreeHost::initializeLayerRenderer):
     97        (WebCore::CCLayerTreeHost::finishCommitOnImplThread):
     98        (WebCore::CCLayerTreeHost::setVisible):
     99        (WebCore::CCLayerTreeHost::evictAllContentTextures):
     100        (WebCore::CCLayerTreeHost::updateLayers):
     101        * platform/graphics/chromium/cc/CCLayerTreeHost.h:
     102        (CCLayerTreeHost):
     103        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
     104        (WebCore::CCLayerTreeHostImpl::CCLayerTreeHostImpl):
     105        (WebCore::CCLayerTreeHostImpl::commitComplete):
     106        (WebCore::CCLayerTreeHostImpl::canDraw):
     107        (WebCore::CCLayerTreeHostImpl::context):
     108        (WebCore::CCLayerTreeHostImpl::releaseContentsTextures):
     109        (WebCore):
     110        (WebCore::CCLayerTreeHostImpl::setMemoryAllocationLimitBytes):
     111        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
     112        (CCLayerTreeHostImplClient):
     113        (WebCore::CCLayerTreeHostImpl::contentsTexturesWerePurgedSinceLastCommit):
     114        (WebCore::CCLayerTreeHostImpl::memoryAllocationLimitBytes):
     115        (CCLayerTreeHostImpl):
     116        * platform/graphics/chromium/cc/CCProxy.h:
     117        (CCProxy):
     118        * platform/graphics/chromium/cc/CCRenderer.h:
     119        (CCRendererClient):
     120        * platform/graphics/chromium/cc/CCScheduler.cpp:
     121        (WebCore::CCScheduler::beginFrameComplete):
     122        (WebCore::CCScheduler::beginFrameAborted):
     123        (WebCore):
     124        (WebCore::CCScheduler::didSwapBuffersComplete):
     125        (WebCore::CCScheduler::didLoseContext):
     126        (WebCore::CCScheduler::didRecreateContext):
     127        (WebCore::CCScheduler::vsyncTick):
     128        * platform/graphics/chromium/cc/CCScheduler.h:
     129        (CCScheduler):
     130        * platform/graphics/chromium/cc/CCSchedulerStateMachine.cpp:
     131        (WebCore::CCSchedulerStateMachine::beginFrameAborted):
     132        (WebCore):
     133        * platform/graphics/chromium/cc/CCSchedulerStateMachine.h:
     134        * platform/graphics/chromium/cc/CCSingleThreadProxy.cpp:
     135        (WebCore::CCSingleThreadProxy::setVisible):
     136        (WebCore):
     137        (WebCore::CCSingleThreadProxy::stop):
     138        (WebCore::CCSingleThreadProxy::commitAndComposite):
     139        * platform/graphics/chromium/cc/CCSingleThreadProxy.h:
     140        (CCSingleThreadProxy):
     141        * platform/graphics/chromium/cc/CCThreadProxy.cpp:
     142        (WebCore::CCThreadProxy::CCThreadProxy):
     143        (WebCore::CCThreadProxy::compositeAndReadback):
     144        (WebCore::CCThreadProxy::setVisible):
     145        (WebCore):
     146        (WebCore::CCThreadProxy::setVisibleOnImplThread):
     147        (WebCore::CCThreadProxy::scheduledActionBeginFrame):
     148        (WebCore::CCThreadProxy::beginFrame):
     149        (WebCore::CCThreadProxy::beginFrameAbortedOnImplThread):
     150        (WebCore::CCThreadProxy::scheduledActionDrawAndSwapInternal):
     151        (WebCore::CCThreadProxy::layerTreeHostClosedOnImplThread):
     152        * platform/graphics/chromium/cc/CCThreadProxy.h:
     153        (CCThreadProxy):
     154        (BeginFrameAndCommitState):
     155        * platform/graphics/chromium/cc/CCVideoLayerImpl.cpp:
     156        (WebCore::CCVideoLayerImpl::~CCVideoLayerImpl):
     157        (WebCore::CCVideoLayerImpl::willDraw):
     158        (WebCore::CCVideoLayerImpl::willDrawInternal):
     159        (WebCore::CCVideoLayerImpl::FramePlane::allocateData):
     160        (WebCore::CCVideoLayerImpl::FramePlane::freeData):
     161        (WebCore::CCVideoLayerImpl::allocatePlaneData):
     162        (WebCore::CCVideoLayerImpl::freePlaneData):
     163        (WebCore::CCVideoLayerImpl::freeUnusedPlaneData):
     164        (WebCore::CCVideoLayerImpl::didLoseContext):
     165        * platform/graphics/chromium/cc/CCVideoLayerImpl.h:
     166        (FramePlane):
     167
    11682012-06-22  Julien Chaffraix  <jchaffraix@webkit.org>
    2169
  • trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp

    r121005 r121076  
    3636
    3737#include "Extensions3D.h"
    38 #include "Extensions3DChromium.h"
    3938#include "FloatQuad.h"
    4039#include "GeometryBinding.h"
     
    220219    {
    221220        ASSERT(CCProxy::isImplThread());
    222         if (!allocation.suggestHaveBackbuffer)
    223             m_layerRenderer->discardFramebuffer();
    224         else
    225             m_layerRenderer->ensureFramebuffer();
    226         m_layerRenderer->m_client->setContentsMemoryAllocationLimitBytes(allocation.gpuResourceSizeInBytes);
     221        m_layerRenderer->setGpuMemoryAllocation(allocation);
    227222    }
    228223
     
    252247    , m_isViewportChanged(false)
    253248    , m_isFramebufferDiscarded(false)
     249    , m_visible(true)
    254250    , m_textureUploaderSetting(textureUploaderSetting)
    255251{
     
    335331        extensions3DChromium->setGpuMemoryAllocationChangedCallbackCHROMIUM(LayerRendererGpuMemoryAllocationChangedCallbackAdapter::create(this));
    336332    } else {
    337         m_client->setContentsMemoryAllocationLimitBytes(TextureManager::highLimitBytes(viewportSize()));
     333        m_client->setMemoryAllocationLimitBytes(TextureManager::highLimitBytes(viewportSize()));
    338334    }
    339335
     
    376372void LayerRendererChromium::setVisible(bool visible)
    377373{
    378     if (!visible)
    379         releaseRenderPassTextures();
     374    if (m_visible == visible)
     375        return;
     376    m_visible = visible;
    380377
    381378    // TODO: Replace setVisibilityCHROMIUM with an extension to explicitly manage front/backbuffers
     
    12711268}
    12721269
     1270void LayerRendererChromium::setGpuMemoryAllocation(Extensions3DChromium::GpuMemoryAllocationCHROMIUM allocation)
     1271{
     1272    if (m_visible && !allocation.gpuResourceSizeInBytes)
     1273        return;
     1274
     1275    if (!allocation.suggestHaveBackbuffer && !m_visible)
     1276        discardFramebuffer();
     1277
     1278    if (!allocation.gpuResourceSizeInBytes) {
     1279        releaseRenderPassTextures();
     1280        m_client->releaseContentsTextures();
     1281        GLC(m_context, m_context->flush());
     1282    } else
     1283        m_client->setMemoryAllocationLimitBytes(allocation.gpuResourceSizeInBytes);
     1284}
     1285
    12731286void LayerRendererChromium::finish()
    12741287{
     
    12791292bool LayerRendererChromium::swapBuffers(const IntRect& subBuffer)
    12801293{
    1281     // FIXME: Remove this once gpu process supports ignoring swap buffers command while framebuffer is discarded.
    1282     //        Alternatively (preferably?), protect all cc code so as not to attempt a swap after a framebuffer discard.
    1283     if (m_isFramebufferDiscarded) {
    1284         m_client->setFullRootLayerDamage();
    1285         return false;
    1286     }
     1294    ASSERT(m_visible);
     1295    ASSERT(!m_isFramebufferDiscarded);
    12871296
    12881297    TRACE_EVENT("LayerRendererChromium::swapBuffers", this, 0);
     
    13871396        GLC(context, context->deleteFramebuffer(temporaryFBO));
    13881397        GLC(context, context->deleteTexture(temporaryTexture));
     1398    }
     1399
     1400    if (!m_visible) {
     1401        TRACE_EVENT0("cc", "LayerRendererChromium::getFramebufferPixels dropping resources after readback");
     1402        discardFramebuffer();
     1403        releaseRenderPassTextures();
     1404        m_client->releaseContentsTextures();
     1405        GLC(m_context, m_context->flush());
    13891406    }
    13901407}
  • trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h

    r121005 r121076  
    3535#if USE(ACCELERATED_COMPOSITING)
    3636
     37#include "Extensions3DChromium.h"
    3738#include "TextureCopier.h"
    3839#include "TrackingTextureAllocator.h"
     
    5455class GeometryBinding;
    5556class GraphicsContext3D;
    56 class LayerRendererGpuMemoryAllocationChangedCallbackAdapter;
    5757class LayerRendererSwapBuffersCompleteCallbackAdapter;
    5858class ManagedTexture;
     
    112112                          int matrixLocation, int alphaLocation, int quadLocation);
    113113    void copyTextureToFramebuffer(int textureId, const IntSize& bounds, const WebKit::WebTransformationMatrix& drawMatrix);
     114    void setGpuMemoryAllocation(Extensions3DChromium::GpuMemoryAllocationCHROMIUM);
    114115
    115116protected:
    116     friend class LayerRendererGpuMemoryAllocationChangedCallbackAdapter;
    117117    void discardFramebuffer();
    118118    void ensureFramebuffer();
     
    259259    bool m_isViewportChanged;
    260260    bool m_isFramebufferDiscarded;
     261    bool m_visible;
    261262    TextureUploaderOption m_textureUploaderSetting;
    262263};
  • trunk/Source/WebCore/platform/graphics/chromium/TextureManager.cpp

    r121005 r121076  
    243243}
    244244
     245void TextureManager::evictAndRemoveAllDeletedTextures()
     246{
     247    unprotectAllTextures();
     248    reduceMemoryToLimit(0);
     249    m_evictedTextures.clear();
     250}
     251
    245252void TextureManager::evictAndDeleteAllTextures(TextureAllocator* allocator)
    246253{
  • trunk/Source/WebCore/platform/graphics/chromium/TextureManager.h

    r121005 r121076  
    4545    virtual unsigned createTexture(const IntSize&, GC3Denum format) = 0;
    4646    virtual void deleteTexture(unsigned texture, const IntSize&, GC3Denum) = 0;
     47    virtual void deleteAllTextures() = 0;
    4748
    4849protected:
     
    8990    void deleteEvictedTextures(TextureAllocator*);
    9091
     92    void evictAndRemoveAllDeletedTextures();
    9193    void evictAndDeleteAllTextures(TextureAllocator*);
    9294
  • trunk/Source/WebCore/platform/graphics/chromium/TrackingTextureAllocator.cpp

    r121005 r121076  
    9090    } else
    9191        GLC(m_context.get(), m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, format, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE));
     92    m_allocatedTextureIds.add(textureId);
    9293    return textureId;
    9394}
     
    9798    m_currentMemoryUseBytes -= TextureManager::memoryUseBytes(size, format);
    9899    GLC(m_context.get(), m_context->deleteTexture(textureId));
     100    ASSERT(m_allocatedTextureIds.contains(textureId));
     101    m_allocatedTextureIds.remove(textureId);
     102}
     103
     104void TrackingTextureAllocator::deleteAllTextures()
     105{
     106    for (HashSet<unsigned>::const_iterator it = m_allocatedTextureIds.begin(); it != m_allocatedTextureIds.end(); ++it)
     107        GLC(m_context.get(), m_context->deleteTexture(*it));
     108    m_currentMemoryUseBytes = 0;
     109    m_allocatedTextureIds.clear();
    99110}
    100111
  • trunk/Source/WebCore/platform/graphics/chromium/TrackingTextureAllocator.h

    r121005 r121076  
    2828#include "GraphicsContext3D.h"
    2929#include "TextureManager.h"
     30#include <wtf/HashSet.h>
    3031#include <wtf/PassRefPtr.h>
    3132
     
    4142    virtual ~TrackingTextureAllocator();
    4243
    43     virtual unsigned createTexture(const IntSize&, GC3Denum format);
    44     virtual void deleteTexture(unsigned texture, const IntSize&, GC3Denum format);
     44    virtual unsigned createTexture(const IntSize&, GC3Denum format) OVERRIDE;
     45    virtual void deleteTexture(unsigned texture, const IntSize&, GC3Denum format) OVERRIDE;
     46    virtual void deleteAllTextures() OVERRIDE;
    4547
    4648    size_t currentMemoryUseBytes() const { return m_currentMemoryUseBytes; }
     
    5860    TextureUsageHint m_textureUsageHint;
    5961    bool m_useTextureStorageExt;
     62    HashSet<unsigned> m_allocatedTextureIds;
    6063};
    6164
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp

    r121069 r121076  
    7474    , m_client(client)
    7575    , m_frameNumber(0)
    76     , m_frameIsForDisplay(false)
    7776    , m_layerRendererInitialized(false)
    7877    , m_contextLost(false)
     
    8281    , m_deviceScaleFactor(1)
    8382    , m_visible(true)
    84     , m_memoryAllocationBytes(0)
    85     , m_memoryAllocationIsForDisplay(false)
    8683    , m_pageScaleFactor(1)
    8784    , m_minPageScaleFactor(1)
     
    152149
    153150    m_contentsTextureManager = TextureManager::create(0, 0, m_proxy->layerRendererCapabilities().maxTextureSize);
    154 
    155     // FIXME: This is the same as setContentsMemoryAllocationLimitBytes, but
    156     // we're in the middle of a commit here and don't want to force another.
    157     m_memoryAllocationBytes = TextureManager::highLimitBytes(deviceViewportSize());
    158     m_memoryAllocationIsForDisplay = true;
    159151
    160152    m_layerRendererInitialized = true;
     
    258250    hostImpl->setBackgroundColor(m_backgroundColor);
    259251    hostImpl->setHasTransparentBackground(m_hasTransparentBackground);
    260     hostImpl->setVisible(m_visible);
    261     hostImpl->setSourceFrameCanBeDrawn(m_frameIsForDisplay);
    262252
    263253    m_frameNumber++;
     
    328318{
    329319    m_proxy->setNeedsCommit();
    330 }
    331 
    332 void CCLayerTreeHost::setNeedsForcedCommit()
    333 {
    334     m_proxy->setNeedsForcedCommit();
    335320}
    336321
     
    400385    if (m_visible == visible)
    401386        return;
    402 
    403387    m_visible = visible;
    404 
    405     // FIXME: Remove this stuff, it is here just for the m20 merge.
    406     if (!m_visible && m_layerRendererInitialized) {
    407         if (m_proxy->layerRendererCapabilities().contextHasCachedFrontBuffer)
    408             setContentsMemoryAllocationLimitBytes(0);
    409         else
    410             setContentsMemoryAllocationLimitBytes(m_contentsTextureManager->preferredMemoryLimitBytes());
    411     }
    412 
    413     setNeedsForcedCommit();
    414 }
    415 
    416 void CCLayerTreeHost::setContentsMemoryAllocationLimitBytes(size_t bytes)
     388    m_proxy->setVisible(visible);
     389}
     390
     391void CCLayerTreeHost::evictAllContentTextures()
    417392{
    418393    ASSERT(CCProxy::isMainThread());
    419     if (m_memoryAllocationBytes == bytes)
    420         return;
    421 
    422     m_memoryAllocationBytes = bytes;
    423     m_memoryAllocationIsForDisplay = bytes;
    424 
    425     // When not visible, force a commit so that we change our memory allocation
    426     // and evict/delete any textures if we are being requested to.
    427     if (!m_visible)
    428         setNeedsForcedCommit();
    429     else
    430         setNeedsCommit();
     394    ASSERT(m_contentsTextureManager.get());
     395    m_contentsTextureManager->evictAndRemoveAllDeletedTextures();
    431396}
    432397
     
    475440
    476441
    477 void CCLayerTreeHost::updateLayers(CCTextureUpdater& updater)
     442void CCLayerTreeHost::updateLayers(CCTextureUpdater& updater, size_t contentsMemoryLimitBytes)
    478443{
    479444    ASSERT(m_layerRendererInitialized);
    480     // The visible state and memory allocation are set independently and in
    481     // arbitrary order, so do not change the memory allocation used for the
    482     // current commit until both values match intentions.
    483     // FIXME: These two states should be combined into a single action so we
    484     // need a single commit to change visible state, and this can be removed.
    485     bool memoryAllocationStateMatchesVisibility = m_visible == m_memoryAllocationIsForDisplay;
    486     if (memoryAllocationStateMatchesVisibility) {
    487         m_contentsTextureManager->setMemoryAllocationLimitBytes(m_memoryAllocationBytes);
    488         m_frameIsForDisplay = m_memoryAllocationIsForDisplay;
    489     }
     445    ASSERT(contentsMemoryLimitBytes);
    490446
    491447    if (!rootLayer())
     
    494450    if (viewportSize().isEmpty())
    495451        return;
     452
     453    m_contentsTextureManager->setMemoryAllocationLimitBytes(contentsMemoryLimitBytes);
    496454
    497455    updateLayers(rootLayer(), updater);
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h

    r121069 r121076  
    172172    // Returns false if we should abort this frame due to initialization failure.
    173173    bool initializeLayerRendererIfNeeded();
    174     void updateLayers(CCTextureUpdater&);
     174    void updateLayers(CCTextureUpdater&, size_t contentsMemoryLimitBytes);
    175175
    176176    CCLayerTreeHostClient* client() { return m_client; }
     
    203203    // virtual for testing
    204204    virtual void setNeedsCommit();
    205     void setNeedsForcedCommit();
    206205    void setNeedsRedraw();
    207206    bool commitRequested() const;
     
    229228
    230229    TextureManager* contentsTextureManager() const;
    231     void setContentsMemoryAllocationLimitBytes(size_t);
     230
     231    // This will cause contents texture manager to evict all textures, but
     232    // without deleting them. This happens after all content textures have
     233    // already been deleted on impl, after getting a 0 allocation limit.
     234    // Set during a commit, but before updateLayers.
     235    void evictAllContentTextures();
    232236
    233237    bool visible() const { return m_visible; }
     
    282286
    283287    int m_frameNumber;
    284     bool m_frameIsForDisplay;
    285288
    286289    OwnPtr<CCProxy> m_proxy;
     
    301304    bool m_visible;
    302305
    303     size_t m_memoryAllocationBytes;
    304     bool m_memoryAllocationIsForDisplay;
    305 
    306306    typedef HashMap<WebKit::WebGraphicsContext3D*, RefPtr<RateLimiter> > RateLimiterMap;
    307307    RateLimiterMap m_rateLimiters;
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp

    r121069 r121076  
    3030#include "TextStream.h"
    3131#include "TraceEvent.h"
     32#include "TrackingTextureAllocator.h"
    3233#include "cc/CCActiveGestureAnimation.h"
    3334#include "cc/CCDamageTracker.h"
     
    121122    , m_deviceScaleFactor(1)
    122123    , m_visible(true)
    123     , m_sourceFrameCanBeDrawn(true)
     124    , m_contentsTexturesWerePurgedSinceLastCommit(false)
     125    , m_memoryAllocationLimitBytes(TextureManager::highLimitBytes(viewportSize()))
    124126    , m_headsUpDisplay(CCHeadsUpDisplay::create())
    125127    , m_pageScale(1)
     
    156158    // updated.
    157159    updateMaxScrollPosition();
     160    m_contentsTexturesWerePurgedSinceLastCommit = false;
    158161}
    159162
     
    166169    if (!m_layerRenderer)
    167170        return false;
    168     if (!m_sourceFrameCanBeDrawn)
     171    if (m_contentsTexturesWerePurgedSinceLastCommit)
    169172        return false;
    170173    return true;
    171174}
    172175
    173 CCGraphicsContext* CCLayerTreeHostImpl::context()
     176CCGraphicsContext* CCLayerTreeHostImpl::context() const
    174177{
    175178    return m_context.get();
     
    468471}
    469472
    470 void CCLayerTreeHostImpl::setContentsMemoryAllocationLimitBytes(size_t bytes)
    471 {
    472     m_client->postSetContentsMemoryAllocationLimitBytesToMainThreadOnImplThread(bytes);
     473void CCLayerTreeHostImpl::releaseContentsTextures()
     474{
     475    contentsTextureAllocator()->deleteAllTextures();
     476    m_contentsTexturesWerePurgedSinceLastCommit = true;
     477}
     478
     479void CCLayerTreeHostImpl::setMemoryAllocationLimitBytes(size_t bytes)
     480{
     481    if (m_memoryAllocationLimitBytes == bytes)
     482        return;
     483    m_memoryAllocationLimitBytes = bytes;
     484
     485    ASSERT(bytes);
     486    m_client->setNeedsCommitOnImplThread();
    473487}
    474488
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h

    r121069 r121076  
    5858    virtual void setNeedsCommitOnImplThread() = 0;
    5959    virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) = 0;
    60     virtual void postSetContentsMemoryAllocationLimitBytesToMainThreadOnImplThread(size_t) = 0;
    6160};
    6261
     
    110109    virtual void onSwapBuffersComplete() OVERRIDE;
    111110    virtual void setFullRootLayerDamage() OVERRIDE;
    112     virtual void setContentsMemoryAllocationLimitBytes(size_t) OVERRIDE;
     111    virtual void releaseContentsTextures() OVERRIDE;
     112    virtual void setMemoryAllocationLimitBytes(size_t) OVERRIDE;
    113113
    114114    // Implementation
    115115    bool canDraw();
    116     CCGraphicsContext* context();
     116    CCGraphicsContext* context() const;
    117117
    118118    String layerTreeAsText() const;
     
    147147    void setSourceFrameNumber(int frameNumber) { m_sourceFrameNumber = frameNumber; }
    148148
    149     bool sourceFrameCanBeDrawn() const { return m_sourceFrameCanBeDrawn; }
    150     void setSourceFrameCanBeDrawn(bool sourceFrameCanBeDrawn) { m_sourceFrameCanBeDrawn = sourceFrameCanBeDrawn; }
     149    bool contentsTexturesWerePurgedSinceLastCommit() const { return m_contentsTexturesWerePurgedSinceLastCommit; }
     150    size_t memoryAllocationLimitBytes() const { return m_memoryAllocationLimitBytes; }
    151151
    152152    const IntSize& viewportSize() const { return m_viewportSize; }
     
    236236    float m_deviceScaleFactor;
    237237    bool m_visible;
    238     bool m_sourceFrameCanBeDrawn;
     238    bool m_contentsTexturesWerePurgedSinceLastCommit;
     239    size_t m_memoryAllocationLimitBytes;
    239240
    240241    OwnPtr<CCHeadsUpDisplay> m_headsUpDisplay;
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCProxy.h

    r121069 r121076  
    7171    virtual void setSurfaceReady() = 0;
    7272
     73    virtual void setVisible(bool) = 0;
     74
    7375    // Attempts to initialize the layer renderer. Returns false if the context isn't usable for compositing.
    7476    virtual bool initializeLayerRenderer() = 0;
     
    8486    virtual void setNeedsAnimate() = 0;
    8587    virtual void setNeedsCommit() = 0;
    86     virtual void setNeedsForcedCommit() = 0;
    8788    virtual void setNeedsRedraw() = 0;
    8889
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderer.h

    r121005 r121076  
    5050    virtual void onSwapBuffersComplete() = 0;
    5151    virtual void setFullRootLayerDamage() = 0;
    52     virtual void setContentsMemoryAllocationLimitBytes(size_t) = 0;
     52    virtual void releaseContentsTextures() = 0;
     53    virtual void setMemoryAllocationLimitBytes(size_t) = 0;
    5354};
    5455
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCScheduler.cpp

    r121005 r121076  
    8989void CCScheduler::beginFrameComplete()
    9090{
    91     TRACE_EVENT("CCScheduler::beginFrameComplete", this, 0);
     91    TRACE_EVENT0("cc", "CCScheduler::beginFrameComplete");
    9292    m_stateMachine.beginFrameComplete();
    9393    processScheduledActions();
    9494}
    9595
     96void CCScheduler::beginFrameAborted()
     97{
     98    TRACE_EVENT0("cc", "CCScheduler::beginFrameAborted");
     99    m_stateMachine.beginFrameAborted();
     100    processScheduledActions();
     101}
     102
    96103void CCScheduler::setMaxFramesPending(int maxFramesPending)
    97104{
     
    101108void CCScheduler::didSwapBuffersComplete()
    102109{
    103     TRACE_EVENT("CCScheduler::didSwapBuffersComplete", this, 0);
     110    TRACE_EVENT0("cc", "CCScheduler::didSwapBuffersComplete");
    104111    m_frameRateController->didFinishFrame();
    105112}
     
    107114void CCScheduler::didLoseContext()
    108115{
    109     TRACE_EVENT("CCScheduler::didLoseContext", this, 0);
     116    TRACE_EVENT0("cc", "CCScheduler::didLoseContext");
    110117    m_frameRateController->didAbortAllPendingFrames();
    111118    m_stateMachine.didLoseContext();
     
    115122void CCScheduler::didRecreateContext()
    116123{
    117     TRACE_EVENT("CCScheduler::didRecreateContext", this, 0);
     124    TRACE_EVENT0("cc", "CCScheduler::didRecreateContext");
    118125    m_stateMachine.didRecreateContext();
    119126    processScheduledActions();
     
    126133        m_stateMachine.beginUpdateMoreResourcesComplete(m_client->hasMoreResourceUpdates());
    127134    }
    128     TRACE_EVENT("CCScheduler::vsyncTick", this, 0);
     135    TRACE_EVENT0("cc", "CCScheduler::vsyncTick");
    129136
    130137    m_stateMachine.didEnterVSync();
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCScheduler.h

    r121005 r121076  
    9595
    9696    void beginFrameComplete();
     97    void beginFrameAborted();
    9798
    9899    void setMaxFramesPending(int);
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCSchedulerStateMachine.cpp

    r121005 r121076  
    2727#include "cc/CCSchedulerStateMachine.h"
    2828
     29#include <stdio.h>
     30
    2931namespace WebCore {
    3032
     
    300302}
    301303
     304void CCSchedulerStateMachine::beginFrameAborted()
     305{
     306    ASSERT(m_commitState == COMMIT_STATE_FRAME_IN_PROGRESS);
     307    m_commitState = COMMIT_STATE_IDLE;
     308}
     309
    302310void CCSchedulerStateMachine::beginUpdateMoreResourcesComplete(bool morePending)
    303311{
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCSchedulerStateMachine.h

    r121005 r121076  
    121121    void beginFrameComplete();
    122122
     123    // Call this only in response to receiving an ACTION_BEGIN_FRAME
     124    // from nextState if the client rejects the beginFrame message.
     125    void beginFrameAborted();
     126
    123127    // Call this only in response to receiving an ACTION_UPDATE_MORE_RESOURCES
    124128    // from nextState. Indicates that the specific update request completed.
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp

    r121069 r121076  
    154154}
    155155
     156void CCSingleThreadProxy::setVisible(bool visible)
     157{
     158    DebugScopedSetImplThread impl;
     159    m_layerTreeHostImpl->setVisible(visible);
     160}
     161
    156162bool CCSingleThreadProxy::initializeLayerRenderer()
    157163{
     
    259265}
    260266
    261 void CCSingleThreadProxy::setNeedsForcedCommit()
    262 {
    263     // This proxy doesn't block commits when not visible so use a normal commit.
    264     setNeedsCommit();
    265 }
    266 
    267267void CCSingleThreadProxy::setNeedsRedraw()
    268268{
     
    291291        DebugScopedSetImplThread impl;
    292292
    293         m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->contentsTextureAllocator());
     293        if (!m_layerTreeHostImpl->contentsTexturesWerePurgedSinceLastCommit())
     294            m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->contentsTextureAllocator());
    294295        m_layerTreeHostImpl.clear();
    295296    }
     
    311312}
    312313
    313 void CCSingleThreadProxy::postSetContentsMemoryAllocationLimitBytesToMainThreadOnImplThread(size_t bytes)
    314 {
    315     ASSERT(CCProxy::isImplThread());
    316     DebugScopedSetMainThread main;
    317     ASSERT(m_layerTreeHost);
    318     m_layerTreeHost->setContentsMemoryAllocationLimitBytes(bytes);
    319 }
    320 
    321314// Called by the legacy scheduling path (e.g. where render_widget does the scheduling)
    322315void CCSingleThreadProxy::compositeImmediately()
     
    346339    ASSERT(CCProxy::isMainThread());
    347340
     341
    348342    if (!m_layerTreeHost->initializeLayerRendererIfNeeded())
    349343        return false;
    350344
     345    if (m_layerTreeHostImpl->contentsTexturesWerePurgedSinceLastCommit())
     346        m_layerTreeHost->evictAllContentTextures();
     347
    351348    CCTextureUpdater updater;
    352     m_layerTreeHost->updateLayers(updater);
     349    m_layerTreeHost->updateLayers(updater, m_layerTreeHostImpl->memoryAllocationLimitBytes());
    353350
    354351    m_layerTreeHost->willCommit();
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.h

    r121069 r121076  
    5050    virtual bool initializeContext() OVERRIDE;
    5151    virtual void setSurfaceReady() OVERRIDE;
     52    virtual void setVisible(bool) OVERRIDE;
    5253    virtual bool initializeLayerRenderer() OVERRIDE;
    5354    virtual bool recreateContext() OVERRIDE;
     
    5758    virtual void setNeedsAnimate() OVERRIDE;
    5859    virtual void setNeedsCommit() OVERRIDE;
    59     virtual void setNeedsForcedCommit() OVERRIDE;
    6060    virtual void setNeedsRedraw() OVERRIDE;
    6161    virtual bool commitRequested() const OVERRIDE;
     
    7474    virtual void setNeedsCommitOnImplThread() OVERRIDE { m_layerTreeHost->scheduleComposite(); }
    7575    virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) OVERRIDE;
    76     virtual void postSetContentsMemoryAllocationLimitBytesToMainThreadOnImplThread(size_t) OVERRIDE;
    7776
    7877    // Called by the legacy path where RenderWidget does the scheduling.
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp

    r121069 r121076  
    8181    , m_started(false)
    8282    , m_texturesAcquired(true)
     83    , m_inCompositeAndReadback(false)
    8384    , m_mainThreadProxy(CCScopedThreadProxy::create(CCProxy::mainThread()))
    8485    , m_beginFrameCompletionEventOnImplThread(0)
     
    115116    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::forceBeginFrameOnImplThread, AllowCrossThreadAccess(&beginFrameCompletion)));
    116117    beginFrameCompletion.wait();
     118    m_inCompositeAndReadback = true;
    117119    beginFrame();
     120    m_inCompositeAndReadback = false;
    118121
    119122    // Perform a synchronous readback.
     
    202205    TRACE_EVENT0("cc", "CCThreadProxy::setSurfaceReadyOnImplThread");
    203206    m_schedulerOnImplThread->setCanBeginFrame(true);
     207}
     208
     209void CCThreadProxy::setVisible(bool visible)
     210{
     211    TRACE_EVENT0("cc", "CCThreadProxy::setVisible");
     212    CCCompletionEvent completion;
     213    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::setVisibleOnImplThread, AllowCrossThreadAccess(&completion), visible));
     214    completion.wait();
     215}
     216
     217void CCThreadProxy::setVisibleOnImplThread(CCCompletionEvent* completion, bool visible)
     218{
     219    TRACE_EVENT0("cc", "CCThreadProxy::setVisibleOnImplThread");
     220    m_layerTreeHostImpl->setVisible(visible);
     221    m_schedulerOnImplThread->setVisible(visible);
     222    completion->signal();
    204223}
    205224
     
    301320}
    302321
    303 void CCThreadProxy::setNeedsForcedCommit()
    304 {
    305     ASSERT(isMainThread());
    306     if (m_forcedCommitRequested)
    307         return;
    308 
    309     TRACE_EVENT("CCThreadProxy::setNeedsForcedCommit", this, 0);
    310     m_commitRequested = true;
    311     m_forcedCommitRequested = true;
    312     CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::setNeedsForcedCommitOnImplThread));
    313 }
    314 
    315322void CCThreadProxy::didLoseContextOnImplThread()
    316323{
     
    348355    TRACE_EVENT("CCThreadProxy::postAnimationEventsToMainThreadOnImplThread", this, 0);
    349356    m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadProxy::setAnimationEvents, events, wallClockTime));
    350 }
    351 
    352 void CCThreadProxy::postSetContentsMemoryAllocationLimitBytesToMainThreadOnImplThread(size_t bytes)
    353 {
    354     ASSERT(isImplThread());
    355     m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadProxy::setContentsMemoryAllocationLimitBytes, bytes));
    356357}
    357358
     
    457458    m_currentTextureUpdaterOnImplThread = adoptPtr(new CCTextureUpdater);
    458459    m_pendingBeginFrameRequest->updater = m_currentTextureUpdaterOnImplThread.get();
     460    m_pendingBeginFrameRequest->contentsTexturesWereDeleted = m_layerTreeHostImpl->contentsTexturesWerePurgedSinceLastCommit();
     461    m_pendingBeginFrameRequest->memoryAllocationLimitBytes = m_layerTreeHostImpl->memoryAllocationLimitBytes();
    459462
    460463    m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadProxy::beginFrame));
     
    499502    m_layerTreeHost->applyScrollAndScale(*request->scrollInfo);
    500503
     504    if (!m_inCompositeAndReadback && !m_layerTreeHost->visible()) {
     505        m_commitRequested = false;
     506        m_forcedCommitRequested = false;
     507
     508        TRACE_EVENT0("cc", "EarlyOut_NotVisible");
     509        CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::beginFrameAbortedOnImplThread));
     510        return;
     511    }
     512
    501513    m_layerTreeHost->willBeginFrame();
    502514
    503     // FIXME: recreate the context if it was requested by the impl thread.
    504515    m_layerTreeHost->updateAnimations(request->monotonicFrameBeginTime);
    505516    m_layerTreeHost->layout();
     
    514525        return;
    515526
    516     m_layerTreeHost->updateLayers(*request->updater);
     527    if (request->contentsTexturesWereDeleted)
     528        m_layerTreeHost->evictAllContentTextures();
     529
     530    m_layerTreeHost->updateLayers(*request->updater, request->memoryAllocationLimitBytes);
    517531
    518532    // Once single buffered layers are committed, they cannot be modified until
     
    560574
    561575    m_schedulerOnImplThread->beginFrameComplete();
     576}
     577
     578void CCThreadProxy::beginFrameAbortedOnImplThread()
     579{
     580    TRACE_EVENT0("cc", "CCThreadProxy::beginFrameAbortedOnImplThread");
     581    ASSERT(isImplThread());
     582    ASSERT(m_schedulerOnImplThread);
     583    ASSERT(m_schedulerOnImplThread->commitPending());
     584
     585    m_schedulerOnImplThread->beginFrameAborted();
    562586}
    563587
     
    662686        m_readbackRequestOnImplThread->completion.signal();
    663687        m_readbackRequestOnImplThread = 0;
    664     }
    665 
    666     if (drawFrame)
     688    } else if (drawFrame)
    667689        result.didSwap = m_layerTreeHostImpl->swapBuffers();
    668690
     
    745767        return;
    746768    m_layerTreeHost->setAnimationEvents(events, wallClockTime);
    747 }
    748 
    749 void CCThreadProxy::setContentsMemoryAllocationLimitBytes(size_t bytes)
    750 {
    751     ASSERT(isMainThread());
    752     if (!m_layerTreeHost)
    753         return;
    754     m_layerTreeHost->setContentsMemoryAllocationLimitBytes(bytes);
    755769}
    756770
     
    837851    TRACE_EVENT("CCThreadProxy::layerTreeHostClosedOnImplThread", this, 0);
    838852    ASSERT(isImplThread());
    839     m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->contentsTextureAllocator());
     853    if (!m_layerTreeHostImpl->contentsTexturesWerePurgedSinceLastCommit())
     854        m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->contentsTextureAllocator());
    840855    m_inputHandlerOnImplThread.clear();
    841856    m_layerTreeHostImpl.clear();
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.h

    r121069 r121076  
    5757    virtual bool initializeContext() OVERRIDE;
    5858    virtual void setSurfaceReady() OVERRIDE;
     59    virtual void setVisible(bool) OVERRIDE;
    5960    virtual bool initializeLayerRenderer() OVERRIDE;
    6061    virtual bool recreateContext() OVERRIDE;
     
    6465    virtual void setNeedsAnimate() OVERRIDE;
    6566    virtual void setNeedsCommit() OVERRIDE;
    66     virtual void setNeedsForcedCommit() OVERRIDE;
    6767    virtual void setNeedsRedraw() OVERRIDE;
    6868    virtual bool commitRequested() const OVERRIDE;
     
    8181    virtual void setNeedsCommitOnImplThread() OVERRIDE;
    8282    virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) OVERRIDE;
    83     virtual void postSetContentsMemoryAllocationLimitBytesToMainThreadOnImplThread(size_t) OVERRIDE;
    8483
    8584    // CCSchedulerClient implementation
     
    109108        OwnPtr<CCScrollAndScaleSet> scrollInfo;
    110109        CCTextureUpdater* updater;
     110        bool contentsTexturesWereDeleted;
     111        size_t memoryAllocationLimitBytes;
    111112    };
    112113    OwnPtr<BeginFrameAndCommitState> m_pendingBeginFrameRequest;
     
    117118    void didCompleteSwapBuffers();
    118119    void setAnimationEvents(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime);
    119     void setContentsMemoryAllocationLimitBytes(size_t);
    120120    void beginContextRecreation();
    121121    void tryToRecreateContext();
     
    130130    void forceBeginFrameOnImplThread(CCCompletionEvent*);
    131131    void beginFrameCompleteOnImplThread(CCCompletionEvent*);
     132    void beginFrameAbortedOnImplThread();
    132133    void requestReadbackOnImplThread(ReadbackRequest*);
    133134    void requestStartPageScaleAnimationOnImplThread(IntSize targetPosition, bool useAnchor, float scale, double durationSec);
     
    135136    void initializeImplOnImplThread(CCCompletionEvent*);
    136137    void setSurfaceReadyOnImplThread();
     138    void setVisibleOnImplThread(CCCompletionEvent*, bool);
    137139    void initializeContextOnImplThread(CCGraphicsContext*);
    138140    void initializeLayerRendererOnImplThread(CCCompletionEvent*, bool* initializeSucceeded, LayerRendererCapabilities*);
     
    158160    bool m_started;
    159161    bool m_texturesAcquired;
     162    bool m_inCompositeAndReadback;
    160163
    161164    OwnPtr<CCLayerTreeHostImpl> m_layerTreeHostImpl;
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.cpp

    r121005 r121076  
    3232#include "Extensions3DChromium.h"
    3333#include "GraphicsContext3D.h"
     34#include "LayerRendererChromium.h" // For GLC macro
    3435#include "LayerTextureSubImage.h"
    3536#include "NotImplemented.h"
     
    7677        m_provider = 0;
    7778    }
    78     freePlaneData(layerTreeHostImpl()->layerRenderer());
     79    freePlaneData(layerTreeHostImpl()->context());
    7980
    8081#if !ASSERT_DISABLED
     
    126127
    127128    willDrawInternal(layerRenderer, context);
    128     freeUnusedPlaneData(layerRenderer);
     129    freeUnusedPlaneData(context);
    129130
    130131    if (!m_frame)
     
    160161    }
    161162
    162     if (!allocatePlaneData(layerRenderer)) {
     163    if (!allocatePlaneData(layerRenderer, context)) {
    163164        m_provider->putCurrentFrame(m_frame);
    164165        m_frame = 0;
     
    283284}
    284285
    285 bool CCVideoLayerImpl::FramePlane::allocateData(CCRenderer* layerRenderer)
     286bool CCVideoLayerImpl::FramePlane::allocateData(CCGraphicsContext* context)
    286287{
    287288    if (textureId)
    288289        return true;
    289290
    290     textureId = layerRenderer->contentsTextureAllocator()->createTexture(size, format);
     291    GraphicsContext3D* context3D = context->context3D();
     292    if (!context3D)
     293        return false;
     294
     295    GLC(context3D, textureId = context3D->createTexture());
     296    GLC(context3D, context3D->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId));
     297    // Do basic linear filtering on resize.
     298    GLC(context3D, context3D->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));
     299    GLC(context3D, context3D->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));
     300    // NPOT textures in GL ES only work when the wrap mode is set to GraphicsContext3D::CLAMP_TO_EDGE.
     301    GLC(context3D, context3D->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE));
     302    GLC(context3D, context3D->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));
     303
     304    GLC(context3D, context3D->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, format, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE));
     305
    291306    return textureId;
    292307}
    293308
    294 void CCVideoLayerImpl::FramePlane::freeData(CCRenderer* layerRenderer)
     309void CCVideoLayerImpl::FramePlane::freeData(CCGraphicsContext* context)
    295310{
    296311    if (!textureId)
    297312        return;
    298313
    299     layerRenderer->contentsTextureAllocator()->deleteTexture(textureId, size, format);
     314    GraphicsContext3D* context3D = context->context3D();
     315    if (!context3D)
     316        return;
     317
     318    GLC(context3D, context3D->deleteTexture(textureId));
    300319    textureId = 0;
    301320}
    302321
    303 bool CCVideoLayerImpl::allocatePlaneData(CCRenderer* layerRenderer)
     322bool CCVideoLayerImpl::allocatePlaneData(CCRenderer* layerRenderer, CCGraphicsContext* context)
    304323{
    305324    int maxTextureSize = layerRenderer->capabilities().maxTextureSize;
     
    313332
    314333        if (plane.size != requiredTextureSize || plane.format != m_format) {
    315             plane.freeData(layerRenderer);
     334            plane.freeData(context);
    316335            plane.size = requiredTextureSize;
    317336            plane.format = m_format;
     
    319338
    320339        if (!plane.textureId) {
    321             if (!plane.allocateData(layerRenderer))
     340            if (!plane.allocateData(context))
    322341                return false;
    323342            plane.visibleSize = computeVisibleSize(*m_frame, planeIndex);
     
    352371}
    353372
    354 void CCVideoLayerImpl::freePlaneData(CCRenderer* layerRenderer)
     373void CCVideoLayerImpl::freePlaneData(CCGraphicsContext* context)
    355374{
    356375    for (unsigned i = 0; i < WebKit::WebVideoFrame::maxPlanes; ++i)
    357         m_framePlanes[i].freeData(layerRenderer);
    358 }
    359 
    360 void CCVideoLayerImpl::freeUnusedPlaneData(CCRenderer* layerRenderer)
     376        m_framePlanes[i].freeData(context);
     377}
     378
     379void CCVideoLayerImpl::freeUnusedPlaneData(CCGraphicsContext* context)
    361380{
    362381    unsigned firstUnusedPlane = m_frame ? m_frame->planes() : 0;
    363382    for (unsigned i = firstUnusedPlane; i < WebKit::WebVideoFrame::maxPlanes; ++i)
    364         m_framePlanes[i].freeData(layerRenderer);
     383        m_framePlanes[i].freeData(context);
    365384}
    366385
     
    382401void CCVideoLayerImpl::didLoseContext()
    383402{
    384     freePlaneData(layerTreeHostImpl()->layerRenderer());
     403    freePlaneData(layerTreeHostImpl()->context());
    385404}
    386405
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.h

    r121005 r121076  
    7676        FramePlane() : textureId(0) { }
    7777
    78         bool allocateData(CCRenderer*);
    79         void freeData(CCRenderer*);
     78        bool allocateData(CCGraphicsContext*);
     79        void freeData(CCGraphicsContext*);
    8080    };
    8181
     
    8787
    8888    void willDrawInternal(CCRenderer*, CCGraphicsContext*);
    89     bool allocatePlaneData(CCRenderer*);
     89    bool allocatePlaneData(CCRenderer*, CCGraphicsContext*);
    9090    bool copyPlaneData(CCRenderer*, CCGraphicsContext*);
    91     void freePlaneData(CCRenderer*);
    92     void freeUnusedPlaneData(CCRenderer*);
     91    void freePlaneData(CCGraphicsContext*);
     92    void freeUnusedPlaneData(CCGraphicsContext*);
    9393
    9494    // Guards the destruction of m_provider and the frame that it provides
  • trunk/Source/WebKit/chromium/ChangeLog

    r121070 r121076  
     12012-06-22  James Robinson  <jamesr@chromium.org>
     2
     3        [chromium] LayerRendererChromium is not getting visibility messages in single threaded compositing mode.
     4        https://bugs.webkit.org/show_bug.cgi?id=89045
     5
     6        Reviewed by Adrienne Walker.
     7
     8        Based on patch by Michal Mocny <mmocny@google.com>.
     9
     10        Update various test fixtures and tests to cover scheduling, visibility, and resource allocation changes.
     11
     12        * tests/CCLayerTreeHostImplTest.cpp:
     13        * tests/CCLayerTreeHostTest.cpp:
     14        (CCLayerTreeHostTestAbortFrameWhenInvisible):
     15        (WTF::CCLayerTreeHostTestAbortFrameWhenInvisible::CCLayerTreeHostTestAbortFrameWhenInvisible):
     16        (WTF::CCLayerTreeHostTestAbortFrameWhenInvisible::beginTest):
     17        (WTF::CCLayerTreeHostTestAbortFrameWhenInvisible::afterTest):
     18        (WTF):
     19        (WTF::TEST_F):
     20        (WTF::CCLayerTreeHostTestLayerOcclusion::beginTest):
     21        (WTF::CCLayerTreeHostTestLayerOcclusionWithFilters::beginTest):
     22        (WTF::CCLayerTreeHostTestManySurfaces::beginTest):
     23        * tests/CCSchedulerStateMachineTest.cpp:
     24        (WebCore::TEST):
     25        * tests/CCTiledLayerTestCommon.h:
     26        * tests/FakeWebGraphicsContext3D.h:
     27        (WebKit::FakeWebGraphicsContext3D::FakeWebGraphicsContext3D):
     28        (FakeWebGraphicsContext3D):
     29        (WebKit::FakeWebGraphicsContext3D::createTexture):
     30        * tests/LayerRendererChromiumTest.cpp:
     31        (TEST_F):
     32        * tests/TiledLayerChromiumTest.cpp:
     33
     34
    1352012-06-22  Sadrul Habib Chowdhury  <sadrul@chromium.org>
    236
  • trunk/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp

    r121005 r121076  
    8282    virtual void setNeedsCommitOnImplThread() OVERRIDE { m_didRequestCommit = true; }
    8383    virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) OVERRIDE { }
    84     virtual void postSetContentsMemoryAllocationLimitBytesToMainThreadOnImplThread(size_t) OVERRIDE { }
    8584
    8685    PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHost(bool partialSwap, PassRefPtr<CCGraphicsContext> graphicsContext, PassOwnPtr<CCLayerImpl> rootPtr)
     
    17931792}
    17941793
    1795 class PartialSwapContext: public FakeWebGraphicsContext3D {
     1794class PartialSwapContext : public FakeWebGraphicsContext3D {
    17961795public:
    17971796    WebString getString(WGC3Denum name)
     
    20422041class StrictWebGraphicsContext3D : public FakeWebGraphicsContext3D {
    20432042public:
     2043    StrictWebGraphicsContext3D()
     2044        : FakeWebGraphicsContext3D()
     2045    {
     2046        m_nextTextureId = 7; // Start allocating texture ids larger than any other resource IDs so we can tell if someone's mixing up their resource types.
     2047    }
     2048
    20442049    virtual WebGLId createBuffer() { return 2; }
    20452050    virtual WebGLId createFramebuffer() { return 3; }
     
    20472052    virtual WebGLId createRenderbuffer() { return 5; }
    20482053    virtual WebGLId createShader(WGC3Denum) { return 6; }
    2049     virtual WebGLId createTexture() { return 7; }
    20502054
    20512055    virtual void deleteBuffer(WebGLId id)
     
    20792083    }
    20802084
     2085    virtual WebGLId createTexture()
     2086    {
     2087        unsigned textureId = FakeWebGraphicsContext3D::createTexture();
     2088        m_allocatedTextureIds.add(textureId);
     2089        return textureId;
     2090    }
    20812091    virtual void deleteTexture(WebGLId id)
    20822092    {
    2083         if (id != 7)
     2093        if (!m_allocatedTextureIds.contains(id))
    20842094            ADD_FAILURE() << "Trying to delete texture id " << id;
     2095        m_allocatedTextureIds.remove(id);
    20852096    }
    20862097
     
    21172128    virtual void bindTexture(WGC3Denum, WebGLId id)
    21182129    {
    2119         if (id != 7 && id)
     2130        if (id && !m_allocatedTextureIds.contains(id))
    21202131            ADD_FAILURE() << "Trying to bind texture id " << id;
    21212132    }
     
    21252136        return GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new StrictWebGraphicsContext3D()), GraphicsContext3D::RenderDirectlyToHostWindow);
    21262137    }
     2138
     2139private:
     2140    HashSet<unsigned> m_allocatedTextureIds;
    21272141};
    21282142
     
    22642278public:
    22652279    TrackingWebGraphicsContext3D()
    2266         : m_nextTextureId(1)
     2280        : FakeWebGraphicsContext3D()
    22672281        , m_numTextures(0)
    22682282    { }
     
    22702284    virtual WebGLId createTexture() OVERRIDE
    22712285    {
    2272         WebGLId id = m_nextTextureId;
    2273         ++m_nextTextureId;
     2286        WebGLId id = FakeWebGraphicsContext3D::createTexture();
    22742287
    22752288        m_textures.set(id, true);
     
    23032316
    23042317private:
    2305     WebGLId m_nextTextureId;
    23062318    HashMap<WebGLId, bool> m_textures;
    23072319    unsigned m_numTextures;
  • trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp

    r121069 r121076  
    487487}
    488488
     489class CCLayerTreeHostTestAbortFrameWhenInvisible : public CCLayerTreeHostTestThreadOnly {
     490public:
     491    CCLayerTreeHostTestAbortFrameWhenInvisible()
     492    {
     493    }
     494
     495    virtual void beginTest()
     496    {
     497        // Request a commit (from the main thread), which will trigger the commit flow from the impl side.
     498        m_layerTreeHost->setNeedsCommit();
     499        // Then mark ourselves as not visible before processing any more messages on the main thread.
     500        m_layerTreeHost->setVisible(false);
     501        // If we make it without kicking a frame, we pass!
     502        endTestAfterDelay(1);
     503    }
     504
     505    virtual void layout() OVERRIDE
     506    {
     507        ASSERT_FALSE(true);
     508        endTest();
     509    }
     510
     511    virtual void afterTest()
     512    {
     513    }
     514
     515private:
     516};
     517
     518TEST_F(CCLayerTreeHostTestAbortFrameWhenInvisible, runMultiThread)
     519{
     520    runTestThreaded();
     521}
     522
    489523
    490524// Trigger a frame with setNeedsCommit. Then, inside the resulting animate
     
    9971031    runTest(true);
    9981032}
    999 
    1000 class CCLayerTreeHostTestVisibilityAndAllocationControlDrawing : public CCLayerTreeHostTest {
    1001 public:
    1002 
    1003     CCLayerTreeHostTestVisibilityAndAllocationControlDrawing() { }
    1004 
    1005     virtual void beginTest()
    1006     {
    1007         postSetNeedsCommitToMainThread();
    1008     }
    1009 
    1010     virtual void didCommitAndDrawFrame()
    1011     {
    1012         int lastFrame = m_layerTreeHost->frameNumber() - 1;
    1013 
    1014         // These frames should draw.
    1015         switch (lastFrame) {
    1016         case 0:
    1017             // Set the tree invisible, this should not draw.
    1018             m_layerTreeHost->setVisible(false);
    1019             break;
    1020         case 2:
    1021             // Set the tree invisible and give a non-visible allocation, this
    1022             // should not draw.
    1023             m_layerTreeHost->setVisible(false);
    1024             m_layerTreeHost->setContentsMemoryAllocationLimitBytes(0);
    1025             break;
    1026         case 5:
    1027             // Give a memory allocation not for display, but while we are
    1028             // visible. This should not be used and we should remain
    1029             // ready for display and it should draw.
    1030             m_layerTreeHost->setContentsMemoryAllocationLimitBytes(0);
    1031             break;
    1032         case 6:
    1033             endTest();
    1034             break;
    1035 
    1036         default:
    1037             ASSERT_NOT_REACHED();
    1038         }
    1039     }
    1040 
    1041     virtual void didCommit()
    1042     {
    1043         int lastFrame = m_layerTreeHost->frameNumber() - 1;
    1044 
    1045         // These frames should not draw.
    1046         switch (lastFrame) {
    1047         case 1:
    1048             // Set the tree visible, this should draw.
    1049             m_layerTreeHost->setVisible(true);
    1050             break;
    1051         case 3:
    1052             // Set visible without giving a visible memory allocation, this
    1053             // shouldn't make the impl side ready for display, so it should
    1054             // not draw.
    1055             m_layerTreeHost->setVisible(true);
    1056             break;
    1057         case 4:
    1058             // Now give a memory allocation for display, this should draw.
    1059             m_layerTreeHost->setContentsMemoryAllocationLimitBytes(1);
    1060             break;
    1061         }
    1062     }
    1063 
    1064     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl* impl)
    1065     {
    1066         switch (impl->sourceFrameNumber()) {
    1067         case 0:
    1068             // The host starts out visible and able to display before we do any commit.
    1069             EXPECT_TRUE(impl->visible());
    1070             EXPECT_TRUE(impl->sourceFrameCanBeDrawn());
    1071             break;
    1072         case 1:
    1073             // We still have a memory allocation for display.
    1074             EXPECT_FALSE(impl->visible());
    1075             EXPECT_TRUE(impl->sourceFrameCanBeDrawn());
    1076             break;
    1077         case 2:
    1078             EXPECT_TRUE(impl->visible());
    1079             EXPECT_TRUE(impl->sourceFrameCanBeDrawn());
    1080             break;
    1081         case 3:
    1082             EXPECT_FALSE(impl->visible());
    1083             EXPECT_FALSE(impl->sourceFrameCanBeDrawn());
    1084             break;
    1085         case 4:
    1086             EXPECT_TRUE(impl->visible());
    1087             EXPECT_FALSE(impl->sourceFrameCanBeDrawn());
    1088             break;
    1089         case 5:
    1090             EXPECT_TRUE(impl->visible());
    1091             EXPECT_TRUE(impl->sourceFrameCanBeDrawn());
    1092             break;
    1093         case 6:
    1094             EXPECT_TRUE(impl->visible());
    1095             EXPECT_TRUE(impl->sourceFrameCanBeDrawn());
    1096             break;
    1097         }
    1098     }
    1099 
    1100     virtual void afterTest()
    1101     {
    1102     }
    1103 };
    1104 
    1105 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestVisibilityAndAllocationControlDrawing)
    11061033
    11071034// Verifies that startPageScaleAnimation events propagate correctly from CCLayerTreeHost to
     
    17351662        ASSERT_TRUE(m_layerTreeHost->initializeLayerRendererIfNeeded());
    17361663        CCTextureUpdater updater;
    1737         m_layerTreeHost->updateLayers(updater);
     1664        m_layerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    17381665        m_layerTreeHost->commitComplete();
    17391666
     
    17521679        m_layerTreeHost->setRootLayer(rootLayer);
    17531680        m_layerTreeHost->setViewportSize(rootLayer->bounds());
    1754         m_layerTreeHost->updateLayers(updater);
     1681        m_layerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    17551682        m_layerTreeHost->commitComplete();
    17561683
     
    17701697        m_layerTreeHost->setRootLayer(rootLayer);
    17711698        m_layerTreeHost->setViewportSize(rootLayer->bounds());
    1772         m_layerTreeHost->updateLayers(updater);
     1699        m_layerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    17731700        m_layerTreeHost->commitComplete();
    17741701
     
    17901717        m_layerTreeHost->setRootLayer(rootLayer);
    17911718        m_layerTreeHost->setViewportSize(rootLayer->bounds());
    1792         m_layerTreeHost->updateLayers(updater);
     1719        m_layerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    17931720        m_layerTreeHost->commitComplete();
    17941721
     
    18121739        m_layerTreeHost->setRootLayer(rootLayer);
    18131740        m_layerTreeHost->setViewportSize(rootLayer->bounds());
    1814         m_layerTreeHost->updateLayers(updater);
     1741        m_layerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    18151742        m_layerTreeHost->commitComplete();
    18161743
     
    18341761        m_layerTreeHost->setRootLayer(rootLayer);
    18351762        m_layerTreeHost->setViewportSize(rootLayer->bounds());
    1836         m_layerTreeHost->updateLayers(updater);
     1763        m_layerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    18371764        m_layerTreeHost->commitComplete();
    18381765
     
    18571784        m_layerTreeHost->setRootLayer(rootLayer);
    18581785        m_layerTreeHost->setViewportSize(rootLayer->bounds());
    1859         m_layerTreeHost->updateLayers(updater);
     1786        m_layerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    18601787        m_layerTreeHost->commitComplete();
    18611788
     
    18801807        m_layerTreeHost->setRootLayer(rootLayer);
    18811808        m_layerTreeHost->setViewportSize(rootLayer->bounds());
    1882         m_layerTreeHost->updateLayers(updater);
     1809        m_layerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    18831810        m_layerTreeHost->commitComplete();
    18841811
     
    19431870        ASSERT_TRUE(m_layerTreeHost->initializeLayerRendererIfNeeded());
    19441871        CCTextureUpdater updater;
    1945         m_layerTreeHost->updateLayers(updater);
     1872        m_layerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    19461873        m_layerTreeHost->commitComplete();
    19471874
     
    19701897        m_layerTreeHost->setRootLayer(rootLayer);
    19711898        m_layerTreeHost->setViewportSize(rootLayer->bounds());
    1972         m_layerTreeHost->updateLayers(updater);
     1899        m_layerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    19731900        m_layerTreeHost->commitComplete();
    19741901
     
    20321959        ASSERT_TRUE(m_layerTreeHost->initializeLayerRendererIfNeeded());
    20331960        CCTextureUpdater updater;
    2034         m_layerTreeHost->updateLayers(updater);
     1961        m_layerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    20351962        m_layerTreeHost->commitComplete();
    20361963
  • trunk/Source/WebKit/chromium/tests/CCSchedulerStateMachineTest.cpp

    r121005 r121076  
    808808}
    809809
    810 TEST(CCSchedulerStateMachineTest, TestGoesInvisibleMidCommit)
     810TEST(CCSchedulerStateMachineTest, TestGoesInvisibleBeforeBeginFrameCompletes)
    811811{
    812812    StateMachine state;
     
    824824    EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction());
    825825
    826     // Become invisible
     826    // Become invisible and abort the beginFrame.
    827827    state.setVisible(false);
    828 
    829     // Tell the scheduler the frame finished
    830     state.beginFrameComplete();
    831     EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCES, state.commitState());
    832     EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state.nextAction());
    833 
    834     // Tell the scheduler the update began and finished
    835     state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES);
    836     state.beginUpdateMoreResourcesComplete(false);
    837     EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitState());
    838     EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction());
    839 
    840     // Commit in invisible state should leave us:
    841     // - COMMIT_STATE_WAITING_FOR_FIRST_DRAW
    842     // - Waiting for redraw.
    843     // - No commit needed
    844     state.updateState(CCSchedulerStateMachine::ACTION_COMMIT);
    845     EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.commitState());
    846     EXPECT_TRUE(state.needsRedraw());
    847     EXPECT_FALSE(state.needsCommit());
    848 
    849     // Expect to do nothing, both in and out of vsync.
    850     state.didLeaveVSync();
    851     EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction());
    852     state.didEnterVSync();
     828    state.beginFrameAborted();
     829
     830    // We should now be back in the idle state as if we didn't start a frame at all.
     831    EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState());
    853832    EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction());
    854833}
  • trunk/Source/WebKit/chromium/tests/CCTiledLayerTestCommon.h

    r121005 r121076  
    151151class FakeTextureAllocator : public WebCore::TextureAllocator {
    152152public:
    153     virtual unsigned createTexture(const WebCore::IntSize&, GC3Denum) { return 1; }
    154     virtual void deleteTexture(unsigned, const WebCore::IntSize&, GC3Denum) { }
     153    virtual unsigned createTexture(const WebCore::IntSize&, GC3Denum) OVERRIDE { return 1; }
     154    virtual void deleteTexture(unsigned, const WebCore::IntSize&, GC3Denum) OVERRIDE { }
     155    virtual void deleteAllTextures() OVERRIDE { }
    155156};
    156157
  • trunk/Source/WebKit/chromium/tests/FakeWebGraphicsContext3D.h

    r121005 r121076  
    3636class FakeWebGraphicsContext3D : public WebGraphicsContext3D {
    3737public:
     38    FakeWebGraphicsContext3D()
     39        : m_nextTextureId(1)
     40    {
     41    }
     42
    3843    virtual bool makeContextCurrent() { return true; }
    3944
     
    247252    virtual WebGLId createRenderbuffer() { return 1; }
    248253    virtual WebGLId createShader(WGC3Denum) { return 1; }
    249     virtual WebGLId createTexture() { return 1; }
     254    virtual WebGLId createTexture() { return m_nextTextureId++; }
    250255
    251256    virtual void deleteBuffer(WebGLId) { }
     
    268273
    269274protected:
     275    unsigned m_nextTextureId;
    270276    Attributes m_attrs;
    271277};
  • trunk/Source/WebKit/chromium/tests/LayerRendererChromiumTest.cpp

    r121005 r121076  
    8585
    8686    // CCRendererClient methods.
    87     virtual const IntSize& deviceViewportSize() const OVERRIDE { static IntSize fakeSize; return fakeSize; }
     87    virtual const IntSize& deviceViewportSize() const OVERRIDE { static IntSize fakeSize(1, 1); return fakeSize; }
    8888    virtual const CCLayerTreeSettings& settings() const OVERRIDE { static CCLayerTreeSettings fakeSettings; return fakeSettings; }
    8989    virtual void didLoseContext() OVERRIDE { }
    9090    virtual void onSwapBuffersComplete() OVERRIDE { }
    9191    virtual void setFullRootLayerDamage() OVERRIDE { m_setFullRootLayerDamageCount++; }
    92     virtual void setContentsMemoryAllocationLimitBytes(size_t bytes) OVERRIDE { m_memoryAllocationLimitBytes = bytes; }
     92    virtual void releaseContentsTextures() OVERRIDE { }
     93    virtual void setMemoryAllocationLimitBytes(size_t bytes) OVERRIDE { m_memoryAllocationLimitBytes = bytes; }
    9394
    9495    // Methods added for test.
     
    169170
    170171// Test LayerRendererChromium discardFramebuffer functionality:
    171 // Suggest discarding framebuffer when one exists.
     172// Suggest discarding framebuffer when one exists and the renderer is not visible.
    172173// Expected: it is discarded and damage tracker is reset.
    173 TEST_F(LayerRendererChromiumTest, SuggestBackbufferNoShouldDiscardBackbufferAndDamageRootLayer)
    174 {
     174TEST_F(LayerRendererChromiumTest, SuggestBackbufferNoShouldDiscardBackbufferAndDamageRootLayerWhileNotVisible)
     175{
     176    m_layerRendererChromium.setVisible(false);
    175177    m_mockContext.setMemoryAllocation(m_suggestHaveBackbufferNo);
    176178    EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount());
    177179    EXPECT_TRUE(m_layerRendererChromium.isFramebufferDiscarded());
    178180}
     181
     182// Test LayerRendererChromium discardFramebuffer functionality:
     183// Suggest discarding framebuffer when one exists and the renderer is visible.
     184// Expected: the allocation is ignored.
     185TEST_F(LayerRendererChromiumTest, SuggestBackbufferNoDoNothingWhenVisible)
     186{
     187    m_layerRendererChromium.setVisible(true);
     188    m_mockContext.setMemoryAllocation(m_suggestHaveBackbufferNo);
     189    EXPECT_EQ(0, m_mockClient.setFullRootLayerDamageCount());
     190    EXPECT_FALSE(m_layerRendererChromium.isFramebufferDiscarded());
     191}
     192
    179193
    180194// Test LayerRendererChromium discardFramebuffer functionality:
     
    183197TEST_F(LayerRendererChromiumTest, SuggestBackbufferNoWhenItDoesntExistShouldDoNothing)
    184198{
     199    m_layerRendererChromium.setVisible(false);
    185200    m_mockContext.setMemoryAllocation(m_suggestHaveBackbufferNo);
    186201    EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount());
     
    190205    EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount());
    191206    EXPECT_TRUE(m_layerRendererChromium.isFramebufferDiscarded());
    192 }
    193 
    194 // Test LayerRendererChromium discardFramebuffer functionality:
    195 // Suggest discarding framebuffer, then try to swapBuffers.
    196 // Expected: framebuffer is discarded, swaps are ignored, and damage is reset after discard and after each swap.
    197 TEST_F(LayerRendererChromiumTest, SwapBuffersWhileBackbufferDiscardedShouldIgnoreSwapAndDamageRootLayer)
    198 {
    199     m_mockContext.setMemoryAllocation(m_suggestHaveBackbufferNo);
    200     EXPECT_TRUE(m_layerRendererChromium.isFramebufferDiscarded());
    201     EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount());
    202 
    203     swapBuffers();
    204     EXPECT_EQ(0, m_mockContext.frameCount());
    205     EXPECT_EQ(2, m_mockClient.setFullRootLayerDamageCount());
    206 
    207     swapBuffers();
    208     EXPECT_EQ(0, m_mockContext.frameCount());
    209     EXPECT_EQ(3, m_mockClient.setFullRootLayerDamageCount());
    210207}
    211208
     
    213210// Begin drawing a frame while a framebuffer is discarded.
    214211// Expected: will recreate framebuffer.
    215 TEST_F(LayerRendererChromiumTest, DiscardedBackbufferIsRecreatredForScopeDuration)
    216 {
     212TEST_F(LayerRendererChromiumTest, DiscardedBackbufferIsRecreatedForScopeDuration)
     213{
     214    m_layerRendererChromium.setVisible(false);
    217215    m_mockContext.setMemoryAllocation(m_suggestHaveBackbufferNo);
    218216    EXPECT_TRUE(m_layerRendererChromium.isFramebufferDiscarded());
    219217    EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount());
    220218
     219    m_layerRendererChromium.setVisible(true);
    221220    m_layerRendererChromium.beginDrawingFrame(m_mockClient.rootRenderPass());
    222221    EXPECT_FALSE(m_layerRendererChromium.isFramebufferDiscarded());
     
    224223    swapBuffers();
    225224    EXPECT_EQ(1, m_mockContext.frameCount());
     225}
     226
     227TEST_F(LayerRendererChromiumTest, FramebufferDiscardedAfterReadbackWhenNotVisible)
     228{
     229    m_layerRendererChromium.setVisible(false);
     230    m_mockContext.setMemoryAllocation(m_suggestHaveBackbufferNo);
     231    EXPECT_TRUE(m_layerRendererChromium.isFramebufferDiscarded());
     232    EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount());
     233
     234    char pixels[4];
     235    m_layerRendererChromium.beginDrawingFrame(m_mockClient.rootRenderPass());
     236    EXPECT_FALSE(m_layerRendererChromium.isFramebufferDiscarded());
     237
     238    m_layerRendererChromium.getFramebufferPixels(pixels, IntRect(0, 0, 1, 1));
     239    EXPECT_TRUE(m_layerRendererChromium.isFramebufferDiscarded());
     240    EXPECT_EQ(2, m_mockClient.setFullRootLayerDamageCount());
    226241}
    227242
  • trunk/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp

    r121005 r121076  
    825825    ccLayerTreeHost->setRootLayer(rootLayer);
    826826    ccLayerTreeHost->setViewportSize(IntSize(300, 300));
    827     textureManager->setMaxMemoryLimitBytes(memoryLimit);
    828     ccLayerTreeHost->updateLayers(updater);
     827    ccLayerTreeHost->updateLayers(updater, memoryLimit);
    829828
    830829    // We'll skip the root layer.
     
    838837    rootLayer->removeAllChildren();
    839838
    840     ccLayerTreeHost->updateLayers(updater);
     839    ccLayerTreeHost->updateLayers(updater, memoryLimit);
    841840    EXPECT_FALSE(rootLayer->skipsDraw());
    842841
     
    905904
    906905    // Full update of all 6 tiles.
    907     ccLayerTreeHost->updateLayers(updater);
     906    ccLayerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    908907    {
    909908        DebugScopedSetImplThread implThread;
     
    923922    // Full update of 3 tiles and partial update of 3 tiles.
    924923    layer->invalidateRect(IntRect(0, 0, 300, 150));
    925     ccLayerTreeHost->updateLayers(updater);
     924    ccLayerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    926925    {
    927926        DebugScopedSetImplThread implThread;
     
    944943        DebugScopedSetImplThread implThread;
    945944        OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(0)));
    946         ccLayerTreeHost->updateLayers(updater);
     945        ccLayerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    947946        updater.update(0, &allocator, &copier, &uploader, 4);
    948947        EXPECT_EQ(2, layer->fakeLayerTextureUpdater()->updateCount());
     
    971970        DebugScopedSetImplThread implThread;
    972971        OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(0)));
    973         ccLayerTreeHost->updateLayers(updater);
     972        ccLayerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    974973        updater.update(0, &allocator, &copier, &uploader, 4);
    975974        EXPECT_EQ(4, layer->fakeLayerTextureUpdater()->updateCount());
     
    989988        DebugScopedSetImplThread implThread;
    990989        OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(0)));
    991         ccLayerTreeHost->updateLayers(updater);
     990        ccLayerTreeHost->updateLayers(updater, std::numeric_limits<size_t>::max());
    992991        updater.update(0, &allocator, &copier, &uploader, 4);
    993992        EXPECT_EQ(4, layer->fakeLayerTextureUpdater()->updateCount());
Note: See TracChangeset for help on using the changeset viewer.