| Differences between
and this patch
- a/Source/WebCore/ChangeLog +110 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2012-08-27  Christopher Cameron  <ccameron@chromium.org>
2
3
        [chromium] Allow impl-thread deletion of only some resources
4
        https://bugs.webkit.org/show_bug.cgi?id=95057
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Towards allowing the impl thread to delete just some resources (as
9
        opposed to deleting all resources).
10
11
        Do impl-thread deletion through CCPrioritizedTextureManager instead of
12
        CCResourceProvider. In subsequent changes the impl thread will be able
13
        to set a threshold for what to delete). Put all state that can
14
        be concurrently accessed by the main and impl threads into a separate
15
        SharedState sub-class which has a mutex. Add a set of textures that
16
        have been deleted by the impl thread, but have not had their related
17
        structures clear by the main thread yet. Add helper functions to delete
18
        a backing's resource.
19
20
        Allow multiple in-flight texture purges. In CCThreadProxy, make the
21
        acknowledgement of texture deletion be an integer counter instead of a
22
        bool, because we may have multiple in-flight purges. Remove many
23
        instances where texture purges were avoided when there was an
24
        outstanding text.
25
26
        Add the ability to clear only the references to deleted textures from
27
        the texture upload queue.
28
29
        Add assertions that resources be freed to CCPrioritizedTextureManager.
30
31
        Add lots of asserts to CCPrioritizedTextureManager to ensure and
32
        illuminate supported multithreaded access.
33
        
34
        Fix a dozen places where CCThreadProxy and CCSingleThreadProxy hold
35
        the main thread blocked, but don't notify the debug structures of
36
        this.
37
38
        No new tests (OOPS!).
39
40
        * platform/graphics/chromium/LayerTextureUpdater.h:
41
        (WebCore::LayerTextureUpdater::Texture::backingWasAsynchronouslyDeleted):
42
        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
43
        (WebCore::CCLayerTreeHost::deleteContentsTexturesResourcesOnImplThread):
44
        (WebCore):
45
        (WebCore::CCLayerTreeHost::destroyTexturesDeletedByImplThread):
46
        * platform/graphics/chromium/cc/CCLayerTreeHost.h:
47
        (CCLayerTreeHost):
48
        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
49
        (WebCore::CCLayerTreeHostImpl::releaseContentsTextures):
50
        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
51
        (CCLayerTreeHostImplClient):
52
        (WebCore::CCLayerTreeHostImpl::setContentsTexturesPurged):
53
        (CCLayerTreeHostImpl):
54
        * platform/graphics/chromium/cc/CCPrioritizedTexture.cpp:
55
        (WebCore::CCPrioritizedTexture::upload):
56
        (WebCore::CCPrioritizedTexture::backingWasAsynchronouslyDeleted):
57
        (WebCore):
58
        * platform/graphics/chromium/cc/CCPrioritizedTexture.h:
59
        (CCPrioritizedTexture):
60
        (WebCore::CCPrioritizedTexture::Backing::Backing):
61
        (WebCore::CCPrioritizedTexture::Backing::~Backing):
62
        (Backing):
63
        (WebCore::CCPrioritizedTexture::Backing::owner):
64
        (WebCore::CCPrioritizedTexture::Backing::resourceDeleted):
65
        * platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp:
66
        (WebCore::CCPrioritizedTextureManager::~CCPrioritizedTextureManager):
67
        (WebCore::CCPrioritizedTextureManager::prioritizeTextures):
68
        (WebCore::CCPrioritizedTextureManager::requestLate):
69
        (WebCore::CCPrioritizedTextureManager::acquireBackingTextureIfNeeded):
70
        (WebCore::CCPrioritizedTextureManager::reduceMemory):
71
        (WebCore::CCPrioritizedTextureManager::deleteBackingsResourcesOnImplThread):
72
        (WebCore::CCPrioritizedTextureManager::destroyBackingsFreedByImplThread):
73
        (WebCore):
74
        (WebCore::CCPrioritizedTextureManager::clearAllMemory):
75
        (WebCore::CCPrioritizedTextureManager::registerTexture):
76
        (WebCore::CCPrioritizedTextureManager::returnBackingTexture):
77
        (WebCore::CCPrioritizedTextureManager::createBacking):
78
        (WebCore::CCPrioritizedTextureManager::destroyBacking):
79
        (WebCore::CCPrioritizedTextureManager::assertInvariants):
80
        * platform/graphics/chromium/cc/CCPrioritizedTextureManager.h:
81
        (CCPrioritizedTextureManager):
82
        * platform/graphics/chromium/cc/CCScheduler.cpp:
83
        (WebCore::CCScheduler::beginFrameAborted):
84
        * platform/graphics/chromium/cc/CCSingleThreadProxy.cpp:
85
        (WebCore::CCSingleThreadProxy::recreateContext):
86
        (WebCore::CCSingleThreadProxy::stop):
87
        (WebCore::CCSingleThreadProxy::deleteContentsTexturesOnImplThread):
88
        (WebCore):
89
        (WebCore::CCSingleThreadProxy::commitAndComposite):
90
        * platform/graphics/chromium/cc/CCSingleThreadProxy.h:
91
        * platform/graphics/chromium/cc/CCTextureUpdateQueue.cpp:
92
        (WebCore::CCTextureUpdateQueue::clearUploadsToDeletedResources):
93
        (WebCore):
94
        * platform/graphics/chromium/cc/CCTextureUpdateQueue.h:
95
        (CCTextureUpdateQueue):
96
        * platform/graphics/chromium/cc/CCThreadProxy.cpp:
97
        (WebCore::CCThreadProxy::CCThreadProxy):
98
        (WebCore::CCThreadProxy::deleteContentsTexturesOnImplThread):
99
        (WebCore):
100
        (WebCore::CCThreadProxy::scheduledActionBeginFrame):
101
        (WebCore::CCThreadProxy::beginFrame):
102
        (WebCore::CCThreadProxy::beginFrameCompleteOnImplThread):
103
        (WebCore::CCThreadProxy::scheduledActionCommit):
104
        (WebCore::CCThreadProxy::layerTreeHostClosedOnImplThread):
105
        (WebCore::CCThreadProxy::recreateContextOnImplThread):
106
        * platform/graphics/chromium/cc/CCThreadProxy.h:
107
        (WebCore::CCThreadProxy::BeginFrameAndCommitState::BeginFrameAndCommitState):
108
        (BeginFrameAndCommitState):
109
        (CCThreadProxy):
110
1
2012-08-24  Robert Kroeger  <rjkroege@chromium.org>
111
2012-08-24  Robert Kroeger  <rjkroege@chromium.org>
2
112
3
        [chromium] CCLayerTreeHostImpl::scrollBy always assumes screen space deltas
113
        [chromium] CCLayerTreeHostImpl::scrollBy always assumes screen space deltas
- a/Source/WebKit/chromium/ChangeLog +22 lines
Lines 1-3 a/Source/WebKit/chromium/ChangeLog_sec1
1
2012-08-27  Christopher Cameron  <ccameron@chromium.org>
2
3
        [chromium] Allow impl-thread deletion of only some resources
4
        https://bugs.webkit.org/show_bug.cgi?id=95057
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        In CCLayerTreeHostImplTest, remove the test
9
        releaseContentsTextureShouldTriggerCommit because it is no longer valid
10
        and is redundant.  A releaseContentsTexture will only trigger a commit
11
        if the releaseContentsTexture actually deletes any textures, and
12
        CCLayerTreeHostTestEvictTextures already tests that the commit is
13
        issued upon eviction.
14
15
        Update TiledLayerChromiumTest to adhere to threading requirements and
16
        not leak resources.
17
18
        Update CCPrioritizedTextureTest to adhere to threading requirments.
19
20
        * tests/CCLayerTreeHostImplTest.cpp:
21
        * tests/TiledLayerChromiumTest.cpp:
22
1
2012-08-24  Cris Neckar  <cdn@chromium.org>
23
2012-08-24  Cris Neckar  <cdn@chromium.org>
2
24
3
        Plumb consumeUserGesture() to the chromium platform layer.
25
        Plumb consumeUserGesture() to the chromium platform layer.
- a/Source/WebCore/platform/graphics/chromium/LayerTextureUpdater.h +1 lines
Lines 49-54 public: a/Source/WebCore/platform/graphics/chromium/LayerTextureUpdater.h_sec1
49
49
50
        CCPrioritizedTexture* texture() { return m_texture.get(); }
50
        CCPrioritizedTexture* texture() { return m_texture.get(); }
51
        void swapTextureWith(OwnPtr<CCPrioritizedTexture>& texture) { m_texture.swap(texture); }
51
        void swapTextureWith(OwnPtr<CCPrioritizedTexture>& texture) { m_texture.swap(texture); }
52
        bool backingWasAsynchronouslyDeleted() const { return m_texture->backingWasAsynchronouslyDeleted(); }
52
        virtual void prepareRect(const IntRect& /* sourceRect */, CCRenderingStats&) { }
53
        virtual void prepareRect(const IntRect& /* sourceRect */, CCRenderingStats&) { }
53
        virtual void updateRect(CCResourceProvider*, const IntRect& sourceRect, const IntSize& destOffset) = 0;
54
        virtual void updateRect(CCResourceProvider*, const IntRect& sourceRect, const IntSize& destOffset) = 0;
54
    protected:
55
    protected:
- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp -3 / +11 lines
Lines 192-204 CCLayerTreeHost::RecreateResult CCLayerTreeHost::recreateContext() a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp_sec1
192
    return RecreateFailedAndGaveUp;
192
    return RecreateFailedAndGaveUp;
193
}
193
}
194
194
195
void CCLayerTreeHost::deleteContentsTexturesOnImplThread(CCResourceProvider* resourceProvider)
195
void CCLayerTreeHost::deleteAllContentsTexturesOnImplThread(CCResourceProvider* resourceProvider)
196
{
196
{
197
    ASSERT(CCProxy::isImplThread());
197
    ASSERT(CCProxy::isImplThread());
198
    if (m_rendererInitialized)
198
    if (m_rendererInitialized)
199
        m_contentsTextureManager->clearAllMemory(resourceProvider);
199
        m_contentsTextureManager->clearAllMemory(resourceProvider);
200
}
200
}
201
201
202
bool CCLayerTreeHost::reduceContentsTexturesMemoryOnImplThread(CCResourceProvider* resourceProvider)
203
{
204
    ASSERT(CCProxy::isImplThread());
205
        return m_contentsTextureManager->reduceMemoryOnImplThreadAsync(resourceProvider);
206
    return false;
207
}
208
202
void CCLayerTreeHost::acquireLayerTextures()
209
void CCLayerTreeHost::acquireLayerTextures()
203
{
210
{
204
    ASSERT(CCProxy::isMainThread());
211
    ASSERT(CCProxy::isMainThread());
Lines 411-421 void CCLayerTreeHost::setVisible(bool visible) a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp_sec2
411
    m_proxy->setVisible(visible);
418
    m_proxy->setVisible(visible);
412
}
419
}
413
420
414
void CCLayerTreeHost::evictAllContentTextures()
421
422
void CCLayerTreeHost::destroyContentsTexturesEvictedByImplThread()
415
{
423
{
416
    ASSERT(CCProxy::isMainThread());
424
    ASSERT(CCProxy::isMainThread());
417
    ASSERT(m_contentsTextureManager.get());
425
    ASSERT(m_contentsTextureManager.get());
418
    m_contentsTextureManager->allBackingTexturesWereDeleted();
426
    m_contentsTextureManager->destroyBackingsAsynchronouslyEvicted();
419
}
427
}
420
428
421
void CCLayerTreeHost::startPageScaleAnimation(const IntSize& targetPosition, bool useAnchor, float scale, double durationSec)
429
void CCLayerTreeHost::startPageScaleAnimation(const IntSize& targetPosition, bool useAnchor, float scale, double durationSec)
- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h -6 / +10 lines
Lines 175-181 public: a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h_sec1
175
    RecreateResult recreateContext();
175
    RecreateResult recreateContext();
176
    void didCommitAndDrawFrame() { m_client->didCommitAndDrawFrame(); }
176
    void didCommitAndDrawFrame() { m_client->didCommitAndDrawFrame(); }
177
    void didCompleteSwapBuffers() { m_client->didCompleteSwapBuffers(); }
177
    void didCompleteSwapBuffers() { m_client->didCompleteSwapBuffers(); }
178
    void deleteContentsTexturesOnImplThread(CCResourceProvider*);
179
    virtual void acquireLayerTextures();
178
    virtual void acquireLayerTextures();
180
    // Returns false if we should abort this frame due to initialization failure.
179
    // Returns false if we should abort this frame due to initialization failure.
181
    bool initializeRendererIfNeeded();
180
    bool initializeRendererIfNeeded();
Lines 233-243 public: a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h_sec2
233
232
234
    CCPrioritizedTextureManager* contentsTextureManager() const;
233
    CCPrioritizedTextureManager* contentsTextureManager() const;
235
234
236
    // This will cause contents texture manager to evict all textures, but
235
    void deleteAllContentsTexturesOnImplThread(CCResourceProvider*);
237
    // without deleting them. This happens after all content textures have
236
238
    // already been deleted on impl, after getting a 0 allocation limit.
237
    // This will cause contents texture manager to free some resources used
239
    // Set during a commit, but before updateLayers.
238
    // by textures, but will not delete the texture backings objects. The
240
    void evictAllContentTextures();
239
    // function returns true if some resources were indeed destroyed.
240
    bool reduceContentsTexturesMemoryOnImplThread(CCResourceProvider*);
241
242
    // This will destroy the backings that had their GPU resources freed
243
    // by deleteContentsTexturesResourcesOnImplThread.
244
    void destroyContentsTexturesEvictedByImplThread();
241
245
242
    bool visible() const { return m_visible; }
246
    bool visible() const { return m_visible; }
243
    void setVisible(bool);
247
    void setVisible(bool);
- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp -5 / +1 lines
Lines 525-535 bool CCLayerTreeHostImpl::prepareToDraw(FrameData& frame) a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp_sec1
525
525
526
void CCLayerTreeHostImpl::releaseContentsTextures()
526
void CCLayerTreeHostImpl::releaseContentsTextures()
527
{
527
{
528
    if (m_contentsTexturesPurged)
528
    m_client->reduceContentsTexturesMemoryOnImplThread();
529
        return;
530
    m_resourceProvider->deleteOwnedResources(CCRenderer::ContentPool);
531
    m_contentsTexturesPurged = true;
532
    m_client->setNeedsCommitOnImplThread();
533
}
529
}
534
530
535
void CCLayerTreeHostImpl::setMemoryAllocationLimitBytes(size_t bytes)
531
void CCLayerTreeHostImpl::setMemoryAllocationLimitBytes(size_t bytes)
- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h -1 / +6 lines
Lines 59-64 public: a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h_sec1
59
    virtual void setNeedsRedrawOnImplThread() = 0;
59
    virtual void setNeedsRedrawOnImplThread() = 0;
60
    virtual void setNeedsCommitOnImplThread() = 0;
60
    virtual void setNeedsCommitOnImplThread() = 0;
61
    virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) = 0;
61
    virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) = 0;
62
    virtual void reduceContentsTexturesMemoryOnImplThread() = 0;
62
};
63
};
63
64
64
// CCLayerTreeHostImpl owns the CCLayerImpl tree as well as associated rendering state
65
// CCLayerTreeHostImpl owns the CCLayerImpl tree as well as associated rendering state
Lines 155-161 public: a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h_sec2
155
    int sourceFrameNumber() const { return m_sourceFrameNumber; }
156
    int sourceFrameNumber() const { return m_sourceFrameNumber; }
156
    void setSourceFrameNumber(int frameNumber) { m_sourceFrameNumber = frameNumber; }
157
    void setSourceFrameNumber(int frameNumber) { m_sourceFrameNumber = frameNumber; }
157
158
158
    bool contentsTexturesPurged() const { return m_contentsTexturesPurged; }
159
    void setContentsTexturesPurged() { m_contentsTexturesPurged = true; }
159
    void resetContentsTexturesPurged() { m_contentsTexturesPurged = false; }
160
    void resetContentsTexturesPurged() { m_contentsTexturesPurged = false; }
160
    size_t memoryAllocationLimitBytes() const { return m_memoryAllocationLimitBytes; }
161
    size_t memoryAllocationLimitBytes() const { return m_memoryAllocationLimitBytes; }
161
162
Lines 278-283 private: a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h_sec3
278
    IntSize m_deviceViewportSize;
279
    IntSize m_deviceViewportSize;
279
    float m_deviceScaleFactor;
280
    float m_deviceScaleFactor;
280
    bool m_visible;
281
    bool m_visible;
282
283
    // Set when the impl thread deletes textures, un-set when the impl's layer tree
284
    // is known to not reference any deleted resources. Used to prevent drawing
285
    // with deleted resources.
281
    bool m_contentsTexturesPurged;
286
    bool m_contentsTexturesPurged;
282
    size_t m_memoryAllocationLimitBytes;
287
    size_t m_memoryAllocationLimitBytes;
283
288
- a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTexture.cpp +30 lines
Lines 28-33 a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTexture.cpp_sec1
28
28
29
#include "CCPrioritizedTextureManager.h"
29
#include "CCPrioritizedTextureManager.h"
30
#include "CCPriorityCalculator.h"
30
#include "CCPriorityCalculator.h"
31
#include "CCProxy.h"
31
#include <algorithm>
32
#include <algorithm>
32
33
33
using namespace std;
34
using namespace std;
Lines 106-111 void CCPrioritizedTexture::upload(CCResourceProvider* resourceProvider, a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTexture.cpp_sec2
106
                                  const uint8_t* image, const IntRect& imageRect,
107
                                  const uint8_t* image, const IntRect& imageRect,
107
                                  const IntRect& sourceRect, const IntSize& destOffset)
108
                                  const IntRect& sourceRect, const IntSize& destOffset)
108
{
109
{
110
    ASSERT(!backingWasAsynchronouslyDeleted());
109
    ASSERT(m_isAbovePriorityCutoff);
111
    ASSERT(m_isAbovePriorityCutoff);
110
    if (m_isAbovePriorityCutoff)
112
    if (m_isAbovePriorityCutoff)
111
        acquireBackingTexture(resourceProvider);
113
        acquireBackingTexture(resourceProvider);
Lines 113-118 void CCPrioritizedTexture::upload(CCResourceProvider* resourceProvider, a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTexture.cpp_sec3
113
    resourceProvider->upload(resourceId(), image, imageRect, sourceRect, destOffset);
115
    resourceProvider->upload(resourceId(), image, imageRect, sourceRect, destOffset);
114
}
116
}
115
117
118
bool CCPrioritizedTexture::backingWasAsynchronouslyDeleted() const
119
{
120
    if (m_backing)
121
        return m_backing->resourceDeleted();
122
    return false;
123
}
124
116
void CCPrioritizedTexture::link(Backing* backing)
125
void CCPrioritizedTexture::link(Backing* backing)
117
{
126
{
118
    ASSERT(backing);
127
    ASSERT(backing);
Lines 139-142 void CCPrioritizedTexture::setToSelfManagedMemoryPlaceholder(size_t bytes) a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTexture.cpp_sec4
139
    m_bytes = bytes;
148
    m_bytes = bytes;
140
}
149
}
141
150
151
CCResourceProvider::ResourceId CCPrioritizedTexture::Backing::id()
152
{
153
    ASSERT(CCProxy::isImplThread());
154
    return m_texture.id();
155
}
156
157
bool CCPrioritizedTexture::Backing::resourceDeleted() const
158
{
159
    ASSERT(CCProxy::isImplThread());
160
    return m_resourceDeleted;
161
}
162
163
void CCPrioritizedTexture::Backing::deleteResource(CCResourceProvider* resourceProvider)
164
{
165
    ASSERT(CCProxy::isImplThread());
166
    ASSERT(resourceProvider);
167
    ASSERT(!m_resourceDeleted);
168
    resourceProvider->deleteResource(m_texture.id());
169
    m_resourceDeleted = true;
170
}
171
142
} // namespace WebCore
172
} // namespace WebCore
- a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTexture.h -4 / +17 lines
Lines 88-93 public: a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTexture.h_sec1
88
    // Uploads pixels into the backing resource. This functions will aquire the backing if needed.
88
    // Uploads pixels into the backing resource. This functions will aquire the backing if needed.
89
    void upload(CCResourceProvider*, const uint8_t* image, const IntRect& imageRect, const IntRect& sourceRect, const IntSize& destOffset);
89
    void upload(CCResourceProvider*, const uint8_t* image, const IntRect& imageRect, const IntRect& sourceRect, const IntSize& destOffset);
90
90
91
    bool backingWasAsynchronouslyDeleted() const;
92
91
    CCResourceProvider::ResourceId resourceId() const;
93
    CCResourceProvider::ResourceId resourceId() const;
92
94
93
    // Self-managed textures are accounted for when prioritizing other textures,
95
    // Self-managed textures are accounted for when prioritizing other textures,
Lines 101-116 public: a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTexture.h_sec2
101
private:
103
private:
102
    friend class CCPrioritizedTextureManager;
104
    friend class CCPrioritizedTextureManager;
103
105
104
    class Backing : public CCTexture {
106
    class Backing {
105
        WTF_MAKE_NONCOPYABLE(Backing);
107
        WTF_MAKE_NONCOPYABLE(Backing);
106
    public:
108
    public:
107
        Backing(unsigned id, IntSize size, GC3Denum format)
109
        Backing(unsigned id, IntSize size, GC3Denum format)
108
            : CCTexture(id, size, format), m_owner(0) { }
110
            : m_texture(id, size, format), m_resourceDeleted(false), m_owner(0) { }
109
        ~Backing() { ASSERT(!m_owner); }
111
        ~Backing() { ASSERT(!m_owner && m_resourceDeleted); }
112
113
        CCPrioritizedTexture* owner() const { return m_owner; }
114
115
        CCResourceProvider::ResourceId id();
116
        void deleteResource(CCResourceProvider*);
117
        bool resourceDeleted() const;
118
        const IntSize& size() const { return m_texture.size(); }
119
        GC3Denum format() const { return m_texture.format(); }
120
        size_t bytes() const { return m_texture.bytes(); }
110
121
111
        CCPrioritizedTexture* owner() { return m_owner; }
112
    private:
122
    private:
113
        friend class CCPrioritizedTexture;
123
        friend class CCPrioritizedTexture;
124
        friend class CCPrioritizedTextureManager;
125
        CCTexture m_texture;
126
        bool m_resourceDeleted;
114
        CCPrioritizedTexture* m_owner;
127
        CCPrioritizedTexture* m_owner;
115
    };
128
    };
116
129
- a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp -28 / +96 lines
Lines 28-33 a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp_sec1
28
28
29
#include "CCPrioritizedTexture.h"
29
#include "CCPrioritizedTexture.h"
30
#include "CCPriorityCalculator.h"
30
#include "CCPriorityCalculator.h"
31
#include "CCProxy.h"
31
#include "TraceEvent.h"
32
#include "TraceEvent.h"
32
#include <algorithm>
33
#include <algorithm>
33
34
Lines 49-63 CCPrioritizedTextureManager::~CCPrioritizedTextureManager() a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp_sec2
49
    while (m_textures.size() > 0)
50
    while (m_textures.size() > 0)
50
        unregisterTexture(*m_textures.begin());
51
        unregisterTexture(*m_textures.begin());
51
52
52
    // Each remaining backing is a leaked opengl texture. We don't have the resourceProvider
53
    // Remove any backings that were evicted.
53
    // to delete the textures at this time so clearMemory() needs to be called before this.
54
    clearEvictedBackings();
54
    while (m_backings.size() > 0)
55
55
        destroyBacking(*m_backings.begin(), 0);
56
    // Each remaining backing is real memory leak. This shouldn't happen.
57
    ASSERT(m_backings.isEmpty());
56
}
58
}
57
59
58
void CCPrioritizedTextureManager::prioritizeTextures()
60
void CCPrioritizedTextureManager::prioritizeTextures()
59
{
61
{
60
    TRACE_EVENT0("cc", "CCPrioritizedTextureManager::prioritizeTextures");
62
    TRACE_EVENT0("cc", "CCPrioritizedTextureManager::prioritizeTextures");
63
    ASSERT(CCProxy::isMainThread());
61
64
62
#if !ASSERT_DISABLED
65
#if !ASSERT_DISABLED
63
    assertInvariants();
66
    assertInvariants();
Lines 137-142 void CCPrioritizedTextureManager::prioritizeTextures() a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp_sec3
137
140
138
void CCPrioritizedTextureManager::clearPriorities()
141
void CCPrioritizedTextureManager::clearPriorities()
139
{
142
{
143
    ASSERT(CCProxy::isMainThread());
140
    for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); ++it) {
144
    for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); ++it) {
141
        // FIXME: We should remove this and just set all priorities to
145
        // FIXME: We should remove this and just set all priorities to
142
        //        CCPriorityCalculator::lowestPriority() once we have priorities
146
        //        CCPriorityCalculator::lowestPriority() once we have priorities
Lines 148-153 void CCPrioritizedTextureManager::clearPriorities() a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp_sec4
148
152
149
bool CCPrioritizedTextureManager::requestLate(CCPrioritizedTexture* texture)
153
bool CCPrioritizedTextureManager::requestLate(CCPrioritizedTexture* texture)
150
{
154
{
155
    ASSERT(CCProxy::isMainThread());
156
151
    // This is already above cutoff, so don't double count it's memory below.
157
    // This is already above cutoff, so don't double count it's memory below.
152
    if (texture->isAbovePriorityCutoff())
158
    if (texture->isAbovePriorityCutoff())
153
        return true;
159
        return true;
Lines 170-175 bool CCPrioritizedTextureManager::requestLate(CCPrioritizedTexture* texture) a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp_sec5
170
176
171
void CCPrioritizedTextureManager::acquireBackingTextureIfNeeded(CCPrioritizedTexture* texture, CCResourceProvider* resourceProvider)
177
void CCPrioritizedTextureManager::acquireBackingTextureIfNeeded(CCPrioritizedTexture* texture, CCResourceProvider* resourceProvider)
172
{
178
{
179
    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
180
    ASSERT(resourceProvider);
173
    ASSERT(!texture->isSelfManaged());
181
    ASSERT(!texture->isSelfManaged());
174
    ASSERT(texture->isAbovePriorityCutoff());
182
    ASSERT(texture->isAbovePriorityCutoff());
175
    if (texture->backing() || !texture->isAbovePriorityCutoff())
183
    if (texture->backing() || !texture->isAbovePriorityCutoff())
Lines 204-223 void CCPrioritizedTextureManager::acquireBackingTextureIfNeeded(CCPrioritizedTex a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp_sec6
204
212
205
void CCPrioritizedTextureManager::reduceMemory(size_t limitBytes, CCResourceProvider* resourceProvider)
213
void CCPrioritizedTextureManager::reduceMemory(size_t limitBytes, CCResourceProvider* resourceProvider)
206
{
214
{
215
    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
216
    ASSERT(resourceProvider);
207
    if (memoryUseBytes() <= limitBytes)
217
    if (memoryUseBytes() <= limitBytes)
208
        return;
218
        return;
209
    // Destroy backings until we are below the limit,
219
    // Destroy backings until we are below the limit,
210
    // or until all backings remaining are above the cutoff.
220
    // or until all backings remaining are above the cutoff.
211
    while (memoryUseBytes() > limitBytes && m_backings.size() > 0) {
221
    while (memoryUseBytes() > limitBytes && m_backings.size() > 0) {
212
        BackingSet::iterator it = m_backings.begin();
222
        CCPrioritizedTexture::Backing* backing = *m_backings.begin();
213
        if ((*it)->owner() && (*it)->owner()->isAbovePriorityCutoff())
223
        if (backing->owner() && backing->owner()->isAbovePriorityCutoff())
214
            break;
224
            break;
215
        destroyBacking((*it), resourceProvider);
225
        m_sharedState.removeBackingOnImplThread(backing);
226
        if (!backing->resourceDeleted())
227
            backing->deleteResource(resourceProvider);
228
        destroyBacking(backing);
216
    }
229
    }
217
}
230
}
218
231
219
void CCPrioritizedTextureManager::reduceMemory(CCResourceProvider* resourceProvider)
232
void CCPrioritizedTextureManager::reduceMemory(CCResourceProvider* resourceProvider)
220
{
233
{
234
    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
221
    reduceMemory(m_memoryAvailableBytes, resourceProvider);
235
    reduceMemory(m_memoryAvailableBytes, resourceProvider);
222
    ASSERT(memoryUseBytes() <= maxMemoryLimitBytes());
236
    ASSERT(memoryUseBytes() <= maxMemoryLimitBytes());
223
237
Lines 238-264 void CCPrioritizedTextureManager::reduceMemory(CCResourceProvider* resourceProvi a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp_sec7
238
    reduceMemory(memoryUseBytes() - (wastedMemory - tenPercentOfMemory), resourceProvider);
252
    reduceMemory(memoryUseBytes() - (wastedMemory - tenPercentOfMemory), resourceProvider);
239
}
253
}
240
254
241
void CCPrioritizedTextureManager::clearAllMemory(CCResourceProvider* resourceProvider)
255
bool CCPrioritizedTextureManager::reduceMemoryOnImplThreadAsync(CCResourceProvider* resourceProvider)
242
{
256
{
243
    // Unlink and destroy all backing textures.
257
    ASSERT(CCProxy::isImplThread());
244
    while (m_backings.size() > 0) {
258
    ASSERT(resourceProvider);
245
        BackingSet::iterator it = m_backings.begin();
259
    return m_sharedState.evictBackingsResourcesOnImplThreadAsync(resourceProvider);
246
        if ((*it)->owner())
247
            (*it)->owner()->unlink();
248
        destroyBacking((*it), resourceProvider);
249
    }
250
}
260
}
251
261
252
void CCPrioritizedTextureManager::allBackingTexturesWereDeleted()
262
void CCPrioritizedTextureManager::destroyBackingsAsynchronouslyEvicted()
253
{
263
{
254
    // Same as clearAllMemory, except all our textures were already
264
    ASSERT(CCProxy::isMainThread());
255
    // deleted externally, so we don't delete them. Passing no
265
    clearEvictedBackings();
256
    // resourceProvider results in leaking the (now invalid) texture ids.
266
}
257
    clearAllMemory(0);
267
268
void CCPrioritizedTextureManager::clearEvictedBackings()
269
{
270
    BackingSet evictedBackings;
271
    m_sharedState.getAndClearEvictedBackings(evictedBackings);
272
    for (BackingSet::iterator it = evictedBackings.begin(); it != evictedBackings.end(); ++it)
273
        destroyBacking((*it));
274
}
275
276
void CCPrioritizedTextureManager::clearAllMemory(CCResourceProvider* resourceProvider)
277
{
278
    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
279
    ASSERT(resourceProvider);
280
    reduceMemoryOnImplThreadAsync(resourceProvider);
281
    clearEvictedBackings();
258
}
282
}
259
283
260
void CCPrioritizedTextureManager::registerTexture(CCPrioritizedTexture* texture)
284
void CCPrioritizedTextureManager::registerTexture(CCPrioritizedTexture* texture)
261
{
285
{
286
    ASSERT(CCProxy::isMainThread());
262
    ASSERT(texture);
287
    ASSERT(texture);
263
    ASSERT(!texture->textureManager());
288
    ASSERT(!texture->textureManager());
264
    ASSERT(!texture->backing());
289
    ASSERT(!texture->backing());
Lines 266-276 void CCPrioritizedTextureManager::registerTexture(CCPrioritizedTexture* texture) a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp_sec8
266
291
267
    texture->setManagerInternal(this);
292
    texture->setManagerInternal(this);
268
    m_textures.add(texture);
293
    m_textures.add(texture);
269
270
}
294
}
271
295
272
void CCPrioritizedTextureManager::unregisterTexture(CCPrioritizedTexture* texture)
296
void CCPrioritizedTextureManager::unregisterTexture(CCPrioritizedTexture* texture)
273
{
297
{
298
    ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()));
274
    ASSERT(texture);
299
    ASSERT(texture);
275
    ASSERT(m_textures.find(texture) != m_textures.end());
300
    ASSERT(m_textures.find(texture) != m_textures.end());
276
301
Lines 280-288 void CCPrioritizedTextureManager::unregisterTexture(CCPrioritizedTexture* textur a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp_sec9
280
    texture->setAbovePriorityCutoff(false);
305
    texture->setAbovePriorityCutoff(false);
281
}
306
}
282
307
283
284
void CCPrioritizedTextureManager::returnBackingTexture(CCPrioritizedTexture* texture)
308
void CCPrioritizedTextureManager::returnBackingTexture(CCPrioritizedTexture* texture)
285
{
309
{
310
    ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()));
286
    if (texture->backing()) {
311
    if (texture->backing()) {
287
        // Move the backing texture to the front for eviction/recycling and unlink it.
312
        // Move the backing texture to the front for eviction/recycling and unlink it.
288
        m_backings.remove(texture->backing());
313
        m_backings.remove(texture->backing());
Lines 293-317 void CCPrioritizedTextureManager::returnBackingTexture(CCPrioritizedTexture* tex a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp_sec10
293
318
294
CCPrioritizedTexture::Backing* CCPrioritizedTextureManager::createBacking(IntSize size, GC3Denum format, CCResourceProvider* resourceProvider)
319
CCPrioritizedTexture::Backing* CCPrioritizedTextureManager::createBacking(IntSize size, GC3Denum format, CCResourceProvider* resourceProvider)
295
{
320
{
321
    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
296
    ASSERT(resourceProvider);
322
    ASSERT(resourceProvider);
297
298
    CCResourceProvider::ResourceId resourceId = resourceProvider->createResource(m_pool, size, format, CCResourceProvider::TextureUsageAny);
323
    CCResourceProvider::ResourceId resourceId = resourceProvider->createResource(m_pool, size, format, CCResourceProvider::TextureUsageAny);
299
    CCPrioritizedTexture::Backing* backing = new CCPrioritizedTexture::Backing(resourceId, size, format);
324
    CCPrioritizedTexture::Backing* backing = new CCPrioritizedTexture::Backing(resourceId, size, format);
300
    m_memoryUseBytes += backing->bytes();
325
    m_memoryUseBytes += backing->bytes();
301
    // Put backing texture at the front for eviction, since it isn't in use yet.
326
    // Put backing texture at the front for eviction, since it isn't in use yet.
302
    m_backings.insertBefore(m_backings.begin(), backing);
327
    m_backings.insertBefore(m_backings.begin(), backing);
328
    m_sharedState.addBackingOnImplThread(backing);
303
    return backing;
329
    return backing;
304
}
330
}
305
331
306
void CCPrioritizedTextureManager::destroyBacking(CCPrioritizedTexture::Backing* backing, CCResourceProvider* resourceProvider)
332
void CCPrioritizedTextureManager::destroyBacking(CCPrioritizedTexture::Backing* backing)
307
{
333
{
308
    ASSERT(backing);
334
    ASSERT(backing);
309
    ASSERT(!backing->owner() || !backing->owner()->isAbovePriorityCutoff());
310
    ASSERT(!backing->owner() || !backing->owner()->isSelfManaged());
335
    ASSERT(!backing->owner() || !backing->owner()->isSelfManaged());
311
    ASSERT(m_backings.find(backing) != m_backings.end());
336
    ASSERT(m_backings.find(backing) != m_backings.end());
312
337
313
    if (resourceProvider)
314
        resourceProvider->deleteResource(backing->id());
315
    if (backing->owner())
338
    if (backing->owner())
316
        backing->owner()->unlink();
339
        backing->owner()->unlink();
317
    m_memoryUseBytes -= backing->bytes();
340
    m_memoryUseBytes -= backing->bytes();
Lines 320-329 void CCPrioritizedTextureManager::destroyBacking(CCPrioritizedTexture::Backing* a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp_sec11
320
    delete backing;
343
    delete backing;
321
}
344
}
322
345
323
324
#if !ASSERT_DISABLED
346
#if !ASSERT_DISABLED
325
void CCPrioritizedTextureManager::assertInvariants()
347
void CCPrioritizedTextureManager::assertInvariants()
326
{
348
{
349
    ASSERT(CCProxy::isMainThread());
350
327
    // If we hit any of these asserts, there is a bug in this class. To see
351
    // If we hit any of these asserts, there is a bug in this class. To see
328
    // where the bug is, call this function at the beginning and end of
352
    // where the bug is, call this function at the beginning and end of
329
    // every public function.
353
    // every public function.
Lines 355-359 void CCPrioritizedTextureManager::assertInvariants() a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp_sec12
355
}
379
}
356
#endif
380
#endif
357
381
382
CCPrioritizedTextureManager::SharedState::~SharedState()
383
{
384
    ASSERT(m_evictedBackings.isEmpty());
385
    ASSERT(m_unevictedBackings.isEmpty());
386
}
387
388
void CCPrioritizedTextureManager::SharedState::addBackingOnImplThread(CCPrioritizedTexture::Backing* backing)
389
{
390
    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
391
    m_unevictedBackings.add(backing);
392
}
393
394
void CCPrioritizedTextureManager::SharedState::removeBackingOnImplThread(CCPrioritizedTexture::Backing* backing)
395
{
396
    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
397
    if (backing->resourceDeleted()) {
398
        ASSERT(m_evictedBackings.find(backing) != m_evictedBackings.end());
399
        m_evictedBackings.remove(backing);
400
    } else {
401
        ASSERT(m_unevictedBackings.find(backing) != m_unevictedBackings.end());
402
        m_unevictedBackings.remove(backing);
403
    }
404
}
405
406
bool CCPrioritizedTextureManager::SharedState::evictBackingsResourcesOnImplThreadAsync(CCResourceProvider* resourceProvider)
407
{
408
    bool result = false;
409
    ASSERT(CCProxy::isImplThread());
410
    MutexLocker lock(m_mutex);
411
    for (BackingSet::iterator it = m_unevictedBackings.begin(); it != m_unevictedBackings.end(); ++it) {
412
        result = true;
413
        (*it)->deleteResource(resourceProvider);
414
        m_evictedBackings.add((*it));
415
    }
416
    m_unevictedBackings.clear();
417
    return result;
418
}
419
420
void CCPrioritizedTextureManager::SharedState::getAndClearEvictedBackings(BackingSet& evictedBackings)
421
{
422
    evictedBackings.clear();
423
    MutexLocker lock(m_mutex);
424
    evictedBackings.swap(m_evictedBackings);
425
}
358
426
359
} // namespace WebCore
427
} // namespace WebCore
- a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.h -4 / +44 lines
Lines 33-38 a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.h_sec1
33
#include "IntSize.h"
33
#include "IntSize.h"
34
#include <wtf/HashSet.h>
34
#include <wtf/HashSet.h>
35
#include <wtf/ListHashSet.h>
35
#include <wtf/ListHashSet.h>
36
#include <wtf/ThreadingPrimitives.h>
36
#include <wtf/Vector.h>
37
#include <wtf/Vector.h>
37
38
38
namespace WebCore {
39
namespace WebCore {
Lines 77-84 public: a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.h_sec2
77
    bool requestLate(CCPrioritizedTexture*);
78
    bool requestLate(CCPrioritizedTexture*);
78
79
79
    void reduceMemory(CCResourceProvider*);
80
    void reduceMemory(CCResourceProvider*);
81
82
    // Returns true if resources are deleted as a result of this call.
83
    // This can be called concurrently with the main thread accessing this
84
    // structure, and only touches data in the quarantined m_sharedState.
85
    bool reduceMemoryOnImplThreadAsync(CCResourceProvider*);
86
87
    // Remove the backings whose resources were destroyed by 
88
    // reduceMemoryOnImplThreadAsync
89
    void destroyBackingsAsynchronouslyEvicted();
90
91
    // Delete all textures and frm the impl thread (at thread exit and
92
    // context lost).
80
    void clearAllMemory(CCResourceProvider*);
93
    void clearAllMemory(CCResourceProvider*);
81
    void allBackingTexturesWereDeleted();
82
94
83
    void acquireBackingTextureIfNeeded(CCPrioritizedTexture*, CCResourceProvider*);
95
    void acquireBackingTextureIfNeeded(CCPrioritizedTexture*, CCResourceProvider*);
84
96
Lines 91-96 public: a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.h_sec3
91
#endif
103
#endif
92
104
93
private:
105
private:
106
94
    // Compare textures. Highest priority first.
107
    // Compare textures. Highest priority first.
95
    static inline bool compareTextures(CCPrioritizedTexture* a, CCPrioritizedTexture* b)
108
    static inline bool compareTextures(CCPrioritizedTexture* a, CCPrioritizedTexture* b)
96
    {
109
    {
Lines 109-119 private: a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.h_sec4
109
    }
122
    }
110
123
111
    CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, int pool);
124
    CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, int pool);
112
113
    void reduceMemory(size_t limit, CCResourceProvider*);
125
    void reduceMemory(size_t limit, CCResourceProvider*);
114
115
    CCPrioritizedTexture::Backing* createBacking(IntSize, GC3Denum format, CCResourceProvider*);
126
    CCPrioritizedTexture::Backing* createBacking(IntSize, GC3Denum format, CCResourceProvider*);
116
    void destroyBacking(CCPrioritizedTexture::Backing*, CCResourceProvider*);
127
    void clearEvictedBackings();
128
    void destroyBacking(CCPrioritizedTexture::Backing*);
117
129
118
    size_t m_maxMemoryLimitBytes;
130
    size_t m_maxMemoryLimitBytes;
119
    unsigned m_priorityCutoff;
131
    unsigned m_priorityCutoff;
Lines 132-137 private: a/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.h_sec5
132
144
133
    TextureVector m_tempTextureVector;
145
    TextureVector m_tempTextureVector;
134
    BackingVector m_tempBackingVector;
146
    BackingVector m_tempBackingVector;
147
148
    // This state that can be concurrently accessed by the main and impl thread,
149
    // and needs protection by a mutex.
150
    class SharedState {
151
    public:
152
        SharedState() { }
153
        ~SharedState();
154
155
        // Called on the impl thread while the main thread is blocked
156
        void addBackingOnImplThread(CCPrioritizedTexture::Backing*);
157
        void removeBackingOnImplThread(CCPrioritizedTexture::Backing*);
158
159
        // Called on the impl thread while the main thread may not be
160
        // blocked
161
        bool evictBackingsResourcesOnImplThreadAsync(CCResourceProvider*);
162
163
        // Called on the main thread, possibly concurrently with 
164
        // evictBackingsResourcesOnImplThreadAsync.
165
        // Also called on the impl thread during thread-shutdown and 
166
        // context-lost
167
        void getAndClearEvictedBackings(BackingSet&);
168
169
    private:
170
        Mutex m_mutex;
171
        BackingSet m_unevictedBackings;
172
        BackingSet m_evictedBackings;
173
    };
174
    SharedState m_sharedState;
135
};
175
};
136
176
137
} // WebCore
177
} // WebCore
- a/Source/WebCore/platform/graphics/chromium/cc/CCScheduler.cpp +1 lines
Lines 99-104 void CCScheduler::beginFrameAborted() a/Source/WebCore/platform/graphics/chromium/cc/CCScheduler.cpp_sec1
99
    TRACE_EVENT0("cc", "CCScheduler::beginFrameAborted");
99
    TRACE_EVENT0("cc", "CCScheduler::beginFrameAborted");
100
    m_stateMachine.beginFrameAborted();
100
    m_stateMachine.beginFrameAborted();
101
    processScheduledActions();
101
    processScheduledActions();
102
    setNeedsCommit();
102
}
103
}
103
104
104
void CCScheduler::setMaxFramesPending(int maxFramesPending)
105
void CCScheduler::setMaxFramesPending(int maxFramesPending)
- a/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp -7 / +13 lines
Lines 155-163 bool CCSingleThreadProxy::recreateContext() a/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp_sec1
155
155
156
    bool initialized;
156
    bool initialized;
157
    {
157
    {
158
        DebugScopedSetMainThreadBlocked mainThreadBlocked;
158
        DebugScopedSetImplThread impl;
159
        DebugScopedSetImplThread impl;
159
        if (!m_layerTreeHostImpl->contentsTexturesPurged())
160
        m_layerTreeHost->deleteAllContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider());
160
            m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider());
161
        initialized = m_layerTreeHostImpl->initializeRenderer(context.release(), UnthrottledUploader);
161
        initialized = m_layerTreeHostImpl->initializeRenderer(context.release(), UnthrottledUploader);
162
        if (initialized) {
162
        if (initialized) {
163
            m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererCapabilities();
163
            m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererCapabilities();
Lines 260-268 void CCSingleThreadProxy::stop() a/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp_sec2
260
    {
260
    {
261
        DebugScopedSetMainThreadBlocked mainThreadBlocked;
261
        DebugScopedSetMainThreadBlocked mainThreadBlocked;
262
        DebugScopedSetImplThread impl;
262
        DebugScopedSetImplThread impl;
263
263
        m_layerTreeHost->deleteAllContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider());
264
        if (!m_layerTreeHostImpl->contentsTexturesPurged())
265
            m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider());
266
        m_layerTreeHostImpl.clear();
264
        m_layerTreeHostImpl.clear();
267
    }
265
    }
268
    m_layerTreeHost = 0;
266
    m_layerTreeHost = 0;
Lines 275-280 void CCSingleThreadProxy::postAnimationEventsToMainThreadOnImplThread(PassOwnPtr a/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp_sec3
275
    m_layerTreeHost->setAnimationEvents(events, wallClockTime);
273
    m_layerTreeHost->setAnimationEvents(events, wallClockTime);
276
}
274
}
277
275
276
void CCSingleThreadProxy::reduceContentsTexturesMemoryOnImplThread()
277
{
278
    ASSERT(CCProxy::isImplThread());
279
    if (m_layerTreeHost->reduceContentsTexturesMemoryOnImplThread(m_layerTreeHostImpl->resourceProvider())) {
280
        m_layerTreeHostImpl->setContentsTexturesPurged();
281
        setNeedsCommitOnImplThread();
282
    }
283
}
284
278
// Called by the legacy scheduling path (e.g. where render_widget does the scheduling)
285
// Called by the legacy scheduling path (e.g. where render_widget does the scheduling)
279
void CCSingleThreadProxy::compositeImmediately()
286
void CCSingleThreadProxy::compositeImmediately()
280
{
287
{
Lines 301-308 bool CCSingleThreadProxy::commitAndComposite() a/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp_sec4
301
    if (!m_layerTreeHost->initializeRendererIfNeeded())
308
    if (!m_layerTreeHost->initializeRendererIfNeeded())
302
        return false;
309
        return false;
303
310
304
    if (m_layerTreeHostImpl->contentsTexturesPurged())
311
    m_layerTreeHost->destroyContentsTexturesEvictedByImplThread();
305
        m_layerTreeHost->evictAllContentTextures();
306
312
307
    CCTextureUpdateQueue queue;
313
    CCTextureUpdateQueue queue;
308
    m_layerTreeHost->updateLayers(queue, m_layerTreeHostImpl->memoryAllocationLimitBytes());
314
    m_layerTreeHost->updateLayers(queue, m_layerTreeHostImpl->memoryAllocationLimitBytes());
- a/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.h -1 / +11 lines
Lines 72-77 public: a/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.h_sec1
72
    virtual void setNeedsRedrawOnImplThread() OVERRIDE { m_layerTreeHost->scheduleComposite(); }
72
    virtual void setNeedsRedrawOnImplThread() OVERRIDE { m_layerTreeHost->scheduleComposite(); }
73
    virtual void setNeedsCommitOnImplThread() OVERRIDE { m_layerTreeHost->scheduleComposite(); }
73
    virtual void setNeedsCommitOnImplThread() OVERRIDE { m_layerTreeHost->scheduleComposite(); }
74
    virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) OVERRIDE;
74
    virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) OVERRIDE;
75
    virtual void reduceContentsTexturesMemoryOnImplThread() OVERRIDE;
75
76
76
    // Called by the legacy path where RenderWidget does the scheduling.
77
    // Called by the legacy path where RenderWidget does the scheduling.
77
    void compositeImmediately();
78
    void compositeImmediately();
Lines 102-108 private: a/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.h_sec2
102
};
103
};
103
104
104
// For use in the single-threaded case. In debug builds, it pretends that the
105
// For use in the single-threaded case. In debug builds, it pretends that the
105
// code is running on the thread to satisfy assertion checks.
106
// code is running on the impl thread to satisfy assertion checks.
106
class DebugScopedSetImplThread {
107
class DebugScopedSetImplThread {
107
public:
108
public:
108
    DebugScopedSetImplThread()
109
    DebugScopedSetImplThread()
Lines 137-142 public: a/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.h_sec3
137
    }
138
    }
138
};
139
};
139
140
141
// For use in the single-threaded case. In debug builds, it pretends that the
142
// code is running on the impl thread and that the main thread is blocked to
143
// satisfy assertion checks
144
class DebugScopedSetImplThreadAndMainThreadBlocked {
145
private:
146
    DebugScopedSetImplThread m_implThread;
147
    DebugScopedSetMainThreadBlocked m_mainThreadBlocked;
148
};
149
140
} // namespace WebCore
150
} // namespace WebCore
141
151
142
#endif
152
#endif
- a/Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdateQueue.cpp -3 / +14 lines
Lines 54-63 void CCTextureUpdateQueue::appendCopy(TextureCopier::Parameters copy) a/Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdateQueue.cpp_sec1
54
    m_copyEntries.append(copy);
54
    m_copyEntries.append(copy);
55
}
55
}
56
56
57
void CCTextureUpdateQueue::clearUploads()
57
void CCTextureUpdateQueue::clearUploadsToDeletedResources()
58
{
58
{
59
    m_fullEntries.clear();
59
    clearUploadsToDeletedResources(m_fullEntries);
60
    m_partialEntries.clear();
60
    clearUploadsToDeletedResources(m_partialEntries);
61
}
62
63
void CCTextureUpdateQueue::clearUploadsToDeletedResources(Deque<TextureUploader::Parameters>& entryQueue)
64
{
65
    Deque<TextureUploader::Parameters> temp;
66
    entryQueue.swap(temp);
67
    while (temp.size()) {
68
        TextureUploader::Parameters upload = temp.takeFirst();
69
        if (!upload.texture->backingWasAsynchronouslyDeleted())
70
            entryQueue.append(upload);
71
    }
61
}
72
}
62
73
63
TextureUploader::Parameters CCTextureUpdateQueue::takeFirstFullUpload()
74
TextureUploader::Parameters CCTextureUpdateQueue::takeFirstFullUpload()
- a/Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdateQueue.h -1 / +2 lines
Lines 43-49 public: a/Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdateQueue.h_sec1
43
    void appendPartialUpload(TextureUploader::Parameters);
43
    void appendPartialUpload(TextureUploader::Parameters);
44
    void appendCopy(TextureCopier::Parameters);
44
    void appendCopy(TextureCopier::Parameters);
45
45
46
    void clearUploads();
46
    void clearUploadsToDeletedResources();
47
47
48
    TextureUploader::Parameters takeFirstFullUpload();
48
    TextureUploader::Parameters takeFirstFullUpload();
49
    TextureUploader::Parameters takeFirstPartialUpload();
49
    TextureUploader::Parameters takeFirstPartialUpload();
Lines 56-61 public: a/Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdateQueue.h_sec2
56
    bool hasMoreUpdates() const;
56
    bool hasMoreUpdates() const;
57
57
58
private:
58
private:
59
    void clearUploadsToDeletedResources(Deque<TextureUploader::Parameters>& entryQueue);
59
    Deque<TextureUploader::Parameters> m_fullEntries;
60
    Deque<TextureUploader::Parameters> m_fullEntries;
60
    Deque<TextureUploader::Parameters> m_partialEntries;
61
    Deque<TextureUploader::Parameters> m_partialEntries;
61
    Deque<TextureCopier::Parameters> m_copyEntries;
62
    Deque<TextureCopier::Parameters> m_copyEntries;
- a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp -44 / +73 lines
Lines 80-86 CCThreadProxy::CCThreadProxy(CCLayerTreeHost* layerTreeHost) a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec1
80
    , m_readbackRequestOnImplThread(0)
80
    , m_readbackRequestOnImplThread(0)
81
    , m_commitCompletionEventOnImplThread(0)
81
    , m_commitCompletionEventOnImplThread(0)
82
    , m_textureAcquisitionCompletionEventOnImplThread(0)
82
    , m_textureAcquisitionCompletionEventOnImplThread(0)
83
    , m_resetContentsTexturesPurgedAfterCommitOnImplThread(false)
83
    , m_contentsTexturesPurgeCount(0)
84
    , m_contentsTexturesPurgeAck(0)
84
    , m_nextFrameIsNewlyCommittedFrameOnImplThread(false)
85
    , m_nextFrameIsNewlyCommittedFrameOnImplThread(false)
85
    , m_renderVSyncEnabled(layerTreeHost->settings().renderVSyncEnabled)
86
    , m_renderVSyncEnabled(layerTreeHost->settings().renderVSyncEnabled)
86
{
87
{
Lines 108-116 bool CCThreadProxy::compositeAndReadback(void *pixels, const IntRect& rect) a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec2
108
109
109
110
110
    // Perform a synchronous commit.
111
    // Perform a synchronous commit.
111
    CCCompletionEvent beginFrameCompletion;
112
    {
112
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::forceBeginFrameOnImplThread, &beginFrameCompletion));
113
        DebugScopedSetMainThreadBlocked mainThreadBlocked;
113
    beginFrameCompletion.wait();
114
        CCCompletionEvent beginFrameCompletion;
115
        CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::forceBeginFrameOnImplThread, &beginFrameCompletion));
116
        beginFrameCompletion.wait();
117
    }
114
    m_inCompositeAndReadback = true;
118
    m_inCompositeAndReadback = true;
115
    beginFrame();
119
    beginFrame();
116
    m_inCompositeAndReadback = false;
120
    m_inCompositeAndReadback = false;
Lines 119-126 bool CCThreadProxy::compositeAndReadback(void *pixels, const IntRect& rect) a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec3
119
    ReadbackRequest request;
123
    ReadbackRequest request;
120
    request.rect = rect;
124
    request.rect = rect;
121
    request.pixels = pixels;
125
    request.pixels = pixels;
122
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::requestReadbackOnImplThread, &request));
126
    {
123
    request.completion.wait();
127
        DebugScopedSetMainThreadBlocked mainThreadBlocked;
128
        CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::requestReadbackOnImplThread, &request));
129
        request.completion.wait();
130
    }
124
    return request.success;
131
    return request.success;
125
}
132
}
126
133
Lines 157-162 void CCThreadProxy::finishAllRendering() a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec4
157
    ASSERT(CCProxy::isMainThread());
164
    ASSERT(CCProxy::isMainThread());
158
165
159
    // Make sure all GL drawing is finished on the impl thread.
166
    // Make sure all GL drawing is finished on the impl thread.
167
    DebugScopedSetMainThreadBlocked mainThreadBlocked;
160
    CCCompletionEvent completion;
168
    CCCompletionEvent completion;
161
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::finishAllRenderingOnImplThread, &completion));
169
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::finishAllRenderingOnImplThread, &completion));
162
    completion.wait();
170
    completion.wait();
Lines 195-200 void CCThreadProxy::setSurfaceReadyOnImplThread() a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec5
195
void CCThreadProxy::setVisible(bool visible)
203
void CCThreadProxy::setVisible(bool visible)
196
{
204
{
197
    TRACE_EVENT0("cc", "CCThreadProxy::setVisible");
205
    TRACE_EVENT0("cc", "CCThreadProxy::setVisible");
206
    DebugScopedSetMainThreadBlocked mainThreadBlocked;
198
    CCCompletionEvent completion;
207
    CCCompletionEvent completion;
199
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::setVisibleOnImplThread, &completion, visible));
208
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::setVisibleOnImplThread, &completion, visible));
200
    completion.wait();
209
    completion.wait();
Lines 213-226 bool CCThreadProxy::initializeRenderer() a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec6
213
    TRACE_EVENT0("cc", "CCThreadProxy::initializeRenderer");
222
    TRACE_EVENT0("cc", "CCThreadProxy::initializeRenderer");
214
    // Make a blocking call to initializeRendererOnImplThread. The results of that call
223
    // Make a blocking call to initializeRendererOnImplThread. The results of that call
215
    // are pushed into the initializeSucceeded and capabilities local variables.
224
    // are pushed into the initializeSucceeded and capabilities local variables.
216
    CCCompletionEvent completion;
217
    bool initializeSucceeded = false;
225
    bool initializeSucceeded = false;
218
    RendererCapabilities capabilities;
226
    RendererCapabilities capabilities;
219
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::initializeRendererOnImplThread,
227
    {
220
                                                       &completion,
228
        DebugScopedSetMainThreadBlocked mainThreadBlocked;
221
                                                       &initializeSucceeded,
229
        CCCompletionEvent completion;
222
                                                       &capabilities));
230
        CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::initializeRendererOnImplThread,
223
    completion.wait();
231
                                                           &completion,
232
                                                           &initializeSucceeded,
233
                                                           &capabilities));
234
        completion.wait();
235
    }
224
236
225
    if (initializeSucceeded) {
237
    if (initializeSucceeded) {
226
        m_rendererInitialized = true;
238
        m_rendererInitialized = true;
Lines 245-259 bool CCThreadProxy::recreateContext() a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec7
245
    // Make a blocking call to recreateContextOnImplThread. The results of that
257
    // Make a blocking call to recreateContextOnImplThread. The results of that
246
    // call are pushed into the recreateSucceeded and capabilities local
258
    // call are pushed into the recreateSucceeded and capabilities local
247
    // variables.
259
    // variables.
248
    CCCompletionEvent completion;
249
    bool recreateSucceeded = false;
260
    bool recreateSucceeded = false;
250
    RendererCapabilities capabilities;
261
    RendererCapabilities capabilities;
251
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::recreateContextOnImplThread,
262
    {
252
                                                       &completion,
263
        DebugScopedSetMainThreadBlocked mainThreadBlocked;
253
                                                       context.leakPtr(),
264
        CCCompletionEvent completion;
254
                                                       &recreateSucceeded,
265
        CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::recreateContextOnImplThread,
255
                                                       &capabilities));
266
                                                           &completion,
256
    completion.wait();
267
                                                           context.leakPtr(),
268
                                                           &recreateSucceeded,
269
                                                           &capabilities));
270
        completion.wait();
271
    }
257
272
258
    if (recreateSucceeded)
273
    if (recreateSucceeded)
259
        m_RendererCapabilitiesMainThreadCopy = capabilities;
274
        m_RendererCapabilitiesMainThreadCopy = capabilities;
Lines 270-275 void CCThreadProxy::implSideRenderingStats(CCRenderingStats& stats) a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec8
270
{
285
{
271
    ASSERT(isMainThread());
286
    ASSERT(isMainThread());
272
287
288
    DebugScopedSetMainThreadBlocked mainThreadBlocked;
273
    CCCompletionEvent completion;
289
    CCCompletionEvent completion;
274
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::implSideRenderingStatsOnImplThread,
290
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::implSideRenderingStatsOnImplThread,
275
                                                       &completion,
291
                                                       &completion,
Lines 332-337 void CCThreadProxy::onVSyncParametersChanged(double monotonicTimebase, double in a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec9
332
    m_schedulerOnImplThread->setTimebaseAndInterval(monotonicTimebase, intervalInSeconds);
348
    m_schedulerOnImplThread->setTimebaseAndInterval(monotonicTimebase, intervalInSeconds);
333
}
349
}
334
350
351
void CCThreadProxy::reduceContentsTexturesMemoryOnImplThread()
352
{
353
    ASSERT(isImplThread());
354
    TRACE_EVENT0("cc", "CCThreadProxy::reduceContentsTexturesMemoryOnImplThread");
355
356
    if (m_layerTreeHost->reduceContentsTexturesMemoryOnImplThread(m_layerTreeHostImpl->resourceProvider())) {
357
        m_contentsTexturesPurgeCount += 1;
358
        m_layerTreeHostImpl->setContentsTexturesPurged();
359
        setNeedsCommitOnImplThread();
360
    }
361
}
362
335
void CCThreadProxy::setNeedsCommitOnImplThread()
363
void CCThreadProxy::setNeedsCommitOnImplThread()
336
{
364
{
337
    ASSERT(isImplThread());
365
    ASSERT(isImplThread());
Lines 380-385 void CCThreadProxy::start() a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec10
380
    ASSERT(isMainThread());
408
    ASSERT(isMainThread());
381
    ASSERT(CCProxy::implThread());
409
    ASSERT(CCProxy::implThread());
382
    // Create LayerTreeHostImpl.
410
    // Create LayerTreeHostImpl.
411
    DebugScopedSetMainThreadBlocked mainThreadBlocked;
383
    CCCompletionEvent completion;
412
    CCCompletionEvent completion;
384
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::initializeImplOnImplThread, &completion));
413
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::initializeImplOnImplThread, &completion));
385
    completion.wait();
414
    completion.wait();
Lines 396-402 void CCThreadProxy::stop() a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec11
396
    // Synchronously deletes the impl.
425
    // Synchronously deletes the impl.
397
    {
426
    {
398
        DebugScopedSetMainThreadBlocked mainThreadBlocked;
427
        DebugScopedSetMainThreadBlocked mainThreadBlocked;
399
400
        CCCompletionEvent completion;
428
        CCCompletionEvent completion;
401
        CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::layerTreeHostClosedOnImplThread, &completion));
429
        CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::layerTreeHostClosedOnImplThread, &completion));
402
        completion.wait();
430
        completion.wait();
Lines 411-416 void CCThreadProxy::stop() a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec12
411
439
412
void CCThreadProxy::forceSerializeOnSwapBuffers()
440
void CCThreadProxy::forceSerializeOnSwapBuffers()
413
{
441
{
442
    DebugScopedSetMainThreadBlocked mainThreadBlocked;
414
    CCCompletionEvent completion;
443
    CCCompletionEvent completion;
415
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::forceSerializeOnSwapBuffersOnImplThread, &completion));
444
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::forceSerializeOnSwapBuffersOnImplThread, &completion));
416
    completion.wait();
445
    completion.wait();
Lines 453-459 void CCThreadProxy::scheduledActionBeginFrame() a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec13
453
    m_pendingBeginFrameRequest = adoptPtr(new BeginFrameAndCommitState());
482
    m_pendingBeginFrameRequest = adoptPtr(new BeginFrameAndCommitState());
454
    m_pendingBeginFrameRequest->monotonicFrameBeginTime = monotonicallyIncreasingTime();
483
    m_pendingBeginFrameRequest->monotonicFrameBeginTime = monotonicallyIncreasingTime();
455
    m_pendingBeginFrameRequest->scrollInfo = m_layerTreeHostImpl->processScrollDeltas();
484
    m_pendingBeginFrameRequest->scrollInfo = m_layerTreeHostImpl->processScrollDeltas();
456
    m_pendingBeginFrameRequest->contentsTexturesWereDeleted = m_layerTreeHostImpl->contentsTexturesPurged();
485
    m_pendingBeginFrameRequest->contentsTexturesPurgeAck = m_contentsTexturesPurgeCount;
457
    m_pendingBeginFrameRequest->memoryAllocationLimitBytes = m_layerTreeHostImpl->memoryAllocationLimitBytes();
486
    m_pendingBeginFrameRequest->memoryAllocationLimitBytes = m_layerTreeHostImpl->memoryAllocationLimitBytes();
458
487
459
    m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadProxy::beginFrame));
488
    m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadProxy::beginFrame));
Lines 520-527 void CCThreadProxy::beginFrame() a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec14
520
    if (!m_layerTreeHost->initializeRendererIfNeeded())
549
    if (!m_layerTreeHost->initializeRendererIfNeeded())
521
        return;
550
        return;
522
551
523
    if (request->contentsTexturesWereDeleted)
552
    m_layerTreeHost->destroyContentsTexturesEvictedByImplThread();
524
        m_layerTreeHost->evictAllContentTextures();
525
553
526
    OwnPtr<CCTextureUpdateQueue> queue = adoptPtr(new CCTextureUpdateQueue);
554
    OwnPtr<CCTextureUpdateQueue> queue = adoptPtr(new CCTextureUpdateQueue);
527
    m_layerTreeHost->updateLayers(*(queue.get()), request->memoryAllocationLimitBytes);
555
    m_layerTreeHost->updateLayers(*(queue.get()), request->memoryAllocationLimitBytes);
Lines 544-552 void CCThreadProxy::beginFrame() a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec15
544
    {
572
    {
545
        TRACE_EVENT0("cc", "commit");
573
        TRACE_EVENT0("cc", "commit");
546
        DebugScopedSetMainThreadBlocked mainThreadBlocked;
574
        DebugScopedSetMainThreadBlocked mainThreadBlocked;
547
548
        CCCompletionEvent completion;
575
        CCCompletionEvent completion;
549
        CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::beginFrameCompleteOnImplThread, &completion, queue.release(), request->contentsTexturesWereDeleted));
576
        CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::beginFrameCompleteOnImplThread, &completion, queue.release(), request->contentsTexturesPurgeAck));
550
        completion.wait();
577
        completion.wait();
551
    }
578
    }
552
579
Lines 554-560 void CCThreadProxy::beginFrame() a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec16
554
    m_layerTreeHost->didBeginFrame();
581
    m_layerTreeHost->didBeginFrame();
555
}
582
}
556
583
557
void CCThreadProxy::beginFrameCompleteOnImplThread(CCCompletionEvent* completion, PassOwnPtr<CCTextureUpdateQueue> queue, bool contentsTexturesWereDeleted)
584
void CCThreadProxy::beginFrameCompleteOnImplThread(CCCompletionEvent* completion, PassOwnPtr<CCTextureUpdateQueue> queue, int contentsTexturesPurgeAck)
558
{
585
{
559
    TRACE_EVENT0("cc", "CCThreadProxy::beginFrameCompleteOnImplThread");
586
    TRACE_EVENT0("cc", "CCThreadProxy::beginFrameCompleteOnImplThread");
560
    ASSERT(!m_commitCompletionEventOnImplThread);
587
    ASSERT(!m_commitCompletionEventOnImplThread);
Lines 567-585 void CCThreadProxy::beginFrameCompleteOnImplThread(CCCompletionEvent* completion a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec17
567
        return;
594
        return;
568
    }
595
    }
569
596
570
    if (!contentsTexturesWereDeleted && m_layerTreeHostImpl->contentsTexturesPurged()) {
597
    m_contentsTexturesPurgeAck = contentsTexturesPurgeAck;
571
        // We purged the content textures on the impl thread between the time we
598
    if (m_contentsTexturesPurgeAck != m_contentsTexturesPurgeCount) {
572
        // posted the beginFrame task and now, meaning we have a bunch of
599
        TRACE_EVENT0("cc", "CCThreadProxy::beginFrameCompleteOnImplThread_purge_since_commit");
573
        // uploads that are now invalid. Clear the uploads (they all go to
600
        // The upload queue may contain references to textures that were asynchronously
574
        // content textures), and kick another commit to fill them again.
601
        // deleted. Remove them.
575
        queue->clearUploads();
602
        queue->clearUploadsToDeletedResources();
603
        // There exist textures purged by the impl thread that the main thread
604
        // doesn't know of. Rquest a recommit, which will inform the main thread
605
        // of the purged resources.
576
        setNeedsCommitOnImplThread();
606
        setNeedsCommitOnImplThread();
577
    } else
607
    }
578
        m_resetContentsTexturesPurgedAfterCommitOnImplThread = true;
579
608
580
    m_currentTextureUpdateControllerOnImplThread = CCTextureUpdateController::create(CCProxy::implThread(), queue, m_layerTreeHostImpl->resourceProvider(), m_layerTreeHostImpl->renderer()->textureCopier(), m_layerTreeHostImpl->renderer()->textureUploader());
609
    m_currentTextureUpdateControllerOnImplThread = CCTextureUpdateController::create(CCProxy::implThread(), queue, m_layerTreeHostImpl->resourceProvider(), m_layerTreeHostImpl->renderer()->textureCopier(), m_layerTreeHostImpl->renderer()->textureUploader());
581
    m_commitCompletionEventOnImplThread = completion;
610
    m_commitCompletionEventOnImplThread = completion;
582
583
    m_schedulerOnImplThread->beginFrameComplete();
611
    m_schedulerOnImplThread->beginFrameComplete();
584
}
612
}
585
613
Lines 630-637 void CCThreadProxy::scheduledActionCommit() a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec18
630
    m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get());
658
    m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get());
631
    m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get());
659
    m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get());
632
660
633
    if (m_resetContentsTexturesPurgedAfterCommitOnImplThread) {
661
    if (m_contentsTexturesPurgeAck == m_contentsTexturesPurgeCount) {
634
        m_resetContentsTexturesPurgedAfterCommitOnImplThread = false;
662
        // The tree now references no purged textures. Allow it to draw again.
635
        m_layerTreeHostImpl->resetContentsTexturesPurged();
663
        m_layerTreeHostImpl->resetContentsTexturesPurged();
636
    }
664
    }
637
665
Lines 725-733 void CCThreadProxy::acquireLayerTextures() a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec19
725
        return;
753
        return;
726
754
727
    TRACE_EVENT0("cc", "CCThreadProxy::acquireLayerTextures");
755
    TRACE_EVENT0("cc", "CCThreadProxy::acquireLayerTextures");
728
    CCCompletionEvent completion;
756
    {
729
    CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::acquireLayerTexturesForMainThreadOnImplThread, &completion));
757
        DebugScopedSetMainThreadBlocked mainThreadBlocked;
730
    completion.wait(); // Block until it is safe to write to layer textures from the main thread.
758
        CCCompletionEvent completion;
759
        CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::acquireLayerTexturesForMainThreadOnImplThread, &completion));
760
        completion.wait(); // Block until it is safe to write to layer textures from the main thread.
761
    }
731
762
732
    m_texturesAcquired = true;
763
    m_texturesAcquired = true;
733
}
764
}
Lines 869-876 void CCThreadProxy::layerTreeHostClosedOnImplThread(CCCompletionEvent* completio a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec20
869
{
900
{
870
    TRACE_EVENT0("cc", "CCThreadProxy::layerTreeHostClosedOnImplThread");
901
    TRACE_EVENT0("cc", "CCThreadProxy::layerTreeHostClosedOnImplThread");
871
    ASSERT(isImplThread());
902
    ASSERT(isImplThread());
872
    if (!m_layerTreeHostImpl->contentsTexturesPurged())
903
    m_layerTreeHost->deleteAllContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider());
873
        m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider());
874
    m_inputHandlerOnImplThread.clear();
904
    m_inputHandlerOnImplThread.clear();
875
    m_layerTreeHostImpl.clear();
905
    m_layerTreeHostImpl.clear();
876
    m_schedulerOnImplThread.clear();
906
    m_schedulerOnImplThread.clear();
Lines 892-899 void CCThreadProxy::recreateContextOnImplThread(CCCompletionEvent* completion, C a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp_sec21
892
{
922
{
893
    TRACE_EVENT0("cc", "CCThreadProxy::recreateContextOnImplThread");
923
    TRACE_EVENT0("cc", "CCThreadProxy::recreateContextOnImplThread");
894
    ASSERT(isImplThread());
924
    ASSERT(isImplThread());
895
    if (!m_layerTreeHostImpl->contentsTexturesPurged())
925
    m_layerTreeHost->deleteAllContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider());
896
        m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider());
897
    *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(adoptPtr(contextPtr), textureUploader);
926
    *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(adoptPtr(contextPtr), textureUploader);
898
    if (*recreateSucceeded) {
927
    if (*recreateSucceeded) {
899
        *capabilities = m_layerTreeHostImpl->rendererCapabilities();
928
        *capabilities = m_layerTreeHostImpl->rendererCapabilities();
- a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.h -6 / +12 lines
Lines 81-86 public: a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.h_sec1
81
    virtual void setNeedsRedrawOnImplThread() OVERRIDE;
81
    virtual void setNeedsRedrawOnImplThread() OVERRIDE;
82
    virtual void setNeedsCommitOnImplThread() OVERRIDE;
82
    virtual void setNeedsCommitOnImplThread() OVERRIDE;
83
    virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) OVERRIDE;
83
    virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) OVERRIDE;
84
    virtual void reduceContentsTexturesMemoryOnImplThread() OVERRIDE;
84
85
85
    // CCSchedulerClient implementation
86
    // CCSchedulerClient implementation
86
    virtual bool canDraw() OVERRIDE;
87
    virtual bool canDraw() OVERRIDE;
Lines 100-112 private: a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.h_sec2
100
    // Set on impl thread, read on main thread.
101
    // Set on impl thread, read on main thread.
101
    struct BeginFrameAndCommitState {
102
    struct BeginFrameAndCommitState {
102
        BeginFrameAndCommitState()
103
        BeginFrameAndCommitState()
103
            : monotonicFrameBeginTime(0)
104
            : monotonicFrameBeginTime(0), contentsTexturesPurgeAck(0)
104
        {
105
        {
105
        }
106
        }
106
107
107
        double monotonicFrameBeginTime;
108
        double monotonicFrameBeginTime;
108
        OwnPtr<CCScrollAndScaleSet> scrollInfo;
109
        OwnPtr<CCScrollAndScaleSet> scrollInfo;
109
        bool contentsTexturesWereDeleted;
110
        int contentsTexturesPurgeAck;
110
        size_t memoryAllocationLimitBytes;
111
        size_t memoryAllocationLimitBytes;
111
    };
112
    };
112
    OwnPtr<BeginFrameAndCommitState> m_pendingBeginFrameRequest;
113
    OwnPtr<BeginFrameAndCommitState> m_pendingBeginFrameRequest;
Lines 127-133 private: a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.h_sec3
127
        IntRect rect;
128
        IntRect rect;
128
    };
129
    };
129
    void forceBeginFrameOnImplThread(CCCompletionEvent*);
130
    void forceBeginFrameOnImplThread(CCCompletionEvent*);
130
    void beginFrameCompleteOnImplThread(CCCompletionEvent*, PassOwnPtr<CCTextureUpdateQueue>, bool contentsTexturesWereDeleted);
131
    void beginFrameCompleteOnImplThread(CCCompletionEvent*, PassOwnPtr<CCTextureUpdateQueue>, int contentsTexturesPurgeAck);
131
    void beginFrameAbortedOnImplThread();
132
    void beginFrameAbortedOnImplThread();
132
    void requestReadbackOnImplThread(ReadbackRequest*);
133
    void requestReadbackOnImplThread(ReadbackRequest*);
133
    void requestStartPageScaleAnimationOnImplThread(IntSize targetPosition, bool useAnchor, float scale, double durationSec);
134
    void requestStartPageScaleAnimationOnImplThread(IntSize targetPosition, bool useAnchor, float scale, double durationSec);
Lines 185-193 private: a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.h_sec4
185
186
186
    OwnPtr<CCTextureUpdateController> m_currentTextureUpdateControllerOnImplThread;
187
    OwnPtr<CCTextureUpdateController> m_currentTextureUpdateControllerOnImplThread;
187
188
188
    // Set when we need to reset the contentsTexturesPurged flag after the
189
    // Counter incremented every time the impl thread deletes textures, sent to the
189
    // commit.
190
    // main thread with each commit.
190
    bool m_resetContentsTexturesPurgedAfterCommitOnImplThread;
191
    int m_contentsTexturesPurgeCount;
192
193
    // Value that the main thread sends as an acknowledgement to the impl thread.
194
    // If this does not equal m_contentsTexturesPurgeCount then the impl layer tree
195
    // may reference textures that have been purged.
196
    int m_contentsTexturesPurgeAck;
191
197
192
    // Set when the next draw should post didCommitAndDrawFrame to the main thread.
198
    // Set when the next draw should post didCommitAndDrawFrame to the main thread.
193
    bool m_nextFrameIsNewlyCommittedFrameOnImplThread;
199
    bool m_nextFrameIsNewlyCommittedFrameOnImplThread;
- a/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp -6 / +1 lines
Lines 86-91 public: a/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp_sec1
86
    virtual void setNeedsRedrawOnImplThread() OVERRIDE { m_didRequestRedraw = true; }
86
    virtual void setNeedsRedrawOnImplThread() OVERRIDE { m_didRequestRedraw = true; }
87
    virtual void setNeedsCommitOnImplThread() OVERRIDE { m_didRequestCommit = true; }
87
    virtual void setNeedsCommitOnImplThread() OVERRIDE { m_didRequestCommit = true; }
88
    virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) OVERRIDE { }
88
    virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) OVERRIDE { }
89
    virtual void reduceContentsTexturesMemoryOnImplThread() OVERRIDE { }
89
90
90
    PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHost(bool partialSwap, PassOwnPtr<CCGraphicsContext> graphicsContext, PassOwnPtr<CCLayerImpl> rootPtr)
91
    PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHost(bool partialSwap, PassOwnPtr<CCGraphicsContext> graphicsContext, PassOwnPtr<CCLayerImpl> rootPtr)
91
    {
92
    {
Lines 3772-3783 TEST_F(CCLayerTreeHostImplTest, surfaceTextureCachingNoPartialSwap) a/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp_sec2
3772
    }
3773
    }
3773
}
3774
}
3774
3775
3775
TEST_F(CCLayerTreeHostImplTest, releaseContentsTextureShouldTriggerCommit)
3776
{
3777
    m_hostImpl->releaseContentsTextures();
3778
    EXPECT_TRUE(m_didRequestCommit);
3779
}
3780
3781
struct RenderPassCacheEntry {
3776
struct RenderPassCacheEntry {
3782
    mutable OwnPtr<CCRenderPass> renderPassPtr;
3777
    mutable OwnPtr<CCRenderPass> renderPassPtr;
3783
    CCRenderPass* renderPass;
3778
    CCRenderPass* renderPass;
- a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp -16 / +21 lines
Lines 32-37 a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec1
32
#include "CCTiledLayerTestCommon.h"
32
#include "CCTiledLayerTestCommon.h"
33
#include "FakeCCGraphicsContext.h"
33
#include "FakeCCGraphicsContext.h"
34
#include <gtest/gtest.h>
34
#include <gtest/gtest.h>
35
#include <public/WebCompositor.h>
35
36
36
using namespace WebCore;
37
using namespace WebCore;
37
using namespace WebKitTests;
38
using namespace WebKitTests;
Lines 46-59 public: a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec2
46
        , m_textureFormat(GraphicsContext3D::RGBA)
47
        , m_textureFormat(GraphicsContext3D::RGBA)
47
        , m_context(WebKit::createFakeCCGraphicsContext())
48
        , m_context(WebKit::createFakeCCGraphicsContext())
48
    {
49
    {
50
        WebKit::WebCompositor::initialize(0);
49
        DebugScopedSetImplThread implThread;
51
        DebugScopedSetImplThread implThread;
50
        m_resourceProvider = CCResourceProvider::create(m_context.get());
52
        m_resourceProvider = CCResourceProvider::create(m_context.get());
51
    }
53
    }
52
54
53
    virtual ~CCPrioritizedTextureTest()
55
    virtual ~CCPrioritizedTextureTest()
54
    {
56
    {
55
        DebugScopedSetImplThread implThread;
57
        {
56
        m_resourceProvider.clear();
58
            DebugScopedSetImplThread implThread;
59
            m_resourceProvider.clear();
60
        }
61
        WebKit::WebCompositor::shutdown();
57
    }
62
    }
58
63
59
    size_t texturesMemorySize(size_t textureCount)
64
    size_t texturesMemorySize(size_t textureCount)
Lines 68-79 public: a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec3
68
73
69
    bool validateTexture(OwnPtr<CCPrioritizedTexture>& texture, bool requestLate)
74
    bool validateTexture(OwnPtr<CCPrioritizedTexture>& texture, bool requestLate)
70
    {
75
    {
71
        DebugScopedSetImplThread implThread;
72
#if !ASSERT_DISABLED
76
#if !ASSERT_DISABLED
73
        texture->textureManager()->assertInvariants();
77
        texture->textureManager()->assertInvariants();
74
#endif
78
#endif
75
        if (requestLate)
79
        if (requestLate)
76
            texture->requestLate();
80
            texture->requestLate();
81
        DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
77
        bool success = texture->canAcquireBackingTexture();
82
        bool success = texture->canAcquireBackingTexture();
78
        if (success)
83
        if (success)
79
            texture->acquireBackingTexture(resourceProvider());
84
            texture->acquireBackingTexture(resourceProvider());
Lines 128-134 TEST_F(CCPrioritizedTextureTest, requestTextureExceedingMaxLimit) a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec4
128
    EXPECT_EQ(texturesMemorySize(maxTextures), textureManager->memoryAboveCutoffBytes());
133
    EXPECT_EQ(texturesMemorySize(maxTextures), textureManager->memoryAboveCutoffBytes());
129
    EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes());
134
    EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes());
130
135
131
    DebugScopedSetImplThread implThread;
136
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
132
    textureManager->clearAllMemory(resourceProvider());
137
    textureManager->clearAllMemory(resourceProvider());
133
}
138
}
134
139
Lines 149-155 TEST_F(CCPrioritizedTextureTest, changeMemoryLimits) a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec5
149
    for (size_t i = 0; i < maxTextures; ++i)
154
    for (size_t i = 0; i < maxTextures; ++i)
150
        validateTexture(textures[i], false);
155
        validateTexture(textures[i], false);
151
    {
156
    {
152
        DebugScopedSetImplThread implThread;
157
        DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
153
        textureManager->reduceMemory(resourceProvider());
158
        textureManager->reduceMemory(resourceProvider());
154
    }
159
    }
155
160
Lines 162-168 TEST_F(CCPrioritizedTextureTest, changeMemoryLimits) a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec6
162
    for (size_t i = 0; i < maxTextures; ++i)
167
    for (size_t i = 0; i < maxTextures; ++i)
163
        EXPECT_EQ(validateTexture(textures[i], false), i < 5);
168
        EXPECT_EQ(validateTexture(textures[i], false), i < 5);
164
    {
169
    {
165
        DebugScopedSetImplThread implThread;
170
        DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
166
        textureManager->reduceMemory(resourceProvider());
171
        textureManager->reduceMemory(resourceProvider());
167
    }
172
    }
168
173
Lines 175-188 TEST_F(CCPrioritizedTextureTest, changeMemoryLimits) a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec7
175
    for (size_t i = 0; i < maxTextures; ++i)
180
    for (size_t i = 0; i < maxTextures; ++i)
176
        EXPECT_EQ(validateTexture(textures[i], false), i < 4);
181
        EXPECT_EQ(validateTexture(textures[i], false), i < 4);
177
    {
182
    {
178
        DebugScopedSetImplThread implThread;
183
        DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
179
        textureManager->reduceMemory(resourceProvider());
184
        textureManager->reduceMemory(resourceProvider());
180
    }
185
    }
181
186
182
    EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes());
187
    EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes());
183
    EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes());
188
    EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes());
184
189
185
    DebugScopedSetImplThread implThread;
190
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
186
    textureManager->clearAllMemory(resourceProvider());
191
    textureManager->clearAllMemory(resourceProvider());
187
}
192
}
188
193
Lines 242-248 TEST_F(CCPrioritizedTextureTest, textureManagerPartialUpdateTextures) a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec8
242
    EXPECT_FALSE(textures[2]->haveBackingTexture());
247
    EXPECT_FALSE(textures[2]->haveBackingTexture());
243
    EXPECT_FALSE(textures[3]->haveBackingTexture());
248
    EXPECT_FALSE(textures[3]->haveBackingTexture());
244
249
245
    DebugScopedSetImplThread implThread;
250
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
246
    textureManager->clearAllMemory(resourceProvider());
251
    textureManager->clearAllMemory(resourceProvider());
247
}
252
}
248
253
Lines 282-288 TEST_F(CCPrioritizedTextureTest, textureManagerPrioritiesAreEqual) a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec9
282
    EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes());
287
    EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes());
283
    EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes());
288
    EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes());
284
289
285
    DebugScopedSetImplThread implThread;
290
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
286
    textureManager->clearAllMemory(resourceProvider());
291
    textureManager->clearAllMemory(resourceProvider());
287
}
292
}
288
293
Lines 302-308 TEST_F(CCPrioritizedTextureTest, textureManagerDestroyedFirst) a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec10
302
    EXPECT_TRUE(texture->haveBackingTexture());
307
    EXPECT_TRUE(texture->haveBackingTexture());
303
308
304
    {
309
    {
305
        DebugScopedSetImplThread implThread;
310
        DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
306
        textureManager->clearAllMemory(resourceProvider());
311
        textureManager->clearAllMemory(resourceProvider());
307
    }
312
    }
308
    textureManager.clear();
313
    textureManager.clear();
Lines 330-336 TEST_F(CCPrioritizedTextureTest, textureMovedToNewManager) a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec11
330
    texture->setTextureManager(0);
335
    texture->setTextureManager(0);
331
336
332
    {
337
    {
333
        DebugScopedSetImplThread implThread;
338
        DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
334
        textureManagerOne->clearAllMemory(resourceProvider());
339
        textureManagerOne->clearAllMemory(resourceProvider());
335
    }
340
    }
336
    textureManagerOne.clear();
341
    textureManagerOne.clear();
Lines 346-352 TEST_F(CCPrioritizedTextureTest, textureMovedToNewManager) a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec12
346
    EXPECT_TRUE(texture->canAcquireBackingTexture());
351
    EXPECT_TRUE(texture->canAcquireBackingTexture());
347
    EXPECT_TRUE(texture->haveBackingTexture());
352
    EXPECT_TRUE(texture->haveBackingTexture());
348
353
349
    DebugScopedSetImplThread implThread;
354
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
350
    textureManagerTwo->clearAllMemory(resourceProvider());
355
    textureManagerTwo->clearAllMemory(resourceProvider());
351
}
356
}
352
357
Lines 392-398 TEST_F(CCPrioritizedTextureTest, renderSurfacesReduceMemoryAvailableOutsideRootS a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec13
392
    EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTextures());
397
    EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTextures());
393
    EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes());
398
    EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes());
394
399
395
    DebugScopedSetImplThread implThread;
400
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
396
    textureManager->clearAllMemory(resourceProvider());
401
    textureManager->clearAllMemory(resourceProvider());
397
}
402
}
398
403
Lines 429-435 TEST_F(CCPrioritizedTextureTest, renderSurfacesReduceMemoryAvailableForRequestLa a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec14
429
    EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTextures());
434
    EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTextures());
430
    EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes());
435
    EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes());
431
436
432
    DebugScopedSetImplThread implThread;
437
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
433
    textureManager->clearAllMemory(resourceProvider());
438
    textureManager->clearAllMemory(resourceProvider());
434
}
439
}
435
440
Lines 469-475 TEST_F(CCPrioritizedTextureTest, whenRenderSurfaceNotAvailableTexturesAlsoNotAva a/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp_sec15
469
    EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTextures());
474
    EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTextures());
470
    EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes());
475
    EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes());
471
476
472
    DebugScopedSetImplThread implThread;
477
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
473
    textureManager->clearAllMemory(resourceProvider());
478
    textureManager->clearAllMemory(resourceProvider());
474
}
479
}
475
480
- a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp -451 / +465 lines
Lines 80-93 public: a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec1
80
        , m_textureManager(CCPrioritizedTextureManager::create(60*1024*1024, 1024, CCRenderer::ContentPool))
80
        , m_textureManager(CCPrioritizedTextureManager::create(60*1024*1024, 1024, CCRenderer::ContentPool))
81
        , m_occlusion(0)
81
        , m_occlusion(0)
82
    {
82
    {
83
        DebugScopedSetImplThread implThread;
83
        WebKit::WebCompositor::initialize(0);
84
        DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
84
        m_resourceProvider = CCResourceProvider::create(m_context.get());
85
        m_resourceProvider = CCResourceProvider::create(m_context.get());
85
    }
86
    }
86
87
87
    virtual ~TiledLayerChromiumTest()
88
    virtual ~TiledLayerChromiumTest()
88
    {
89
    {
89
        DebugScopedSetImplThread implThread;
90
        {
90
        m_resourceProvider.clear();
91
            DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
92
            m_textureManager->clearAllMemory(m_resourceProvider.get());
93
            m_resourceProvider.clear();
94
        }
95
        WebKit::WebCompositor::shutdown();
91
    }
96
    }
92
97
93
    void updateTextures(int count = 500)
98
    void updateTextures(int count = 500)
Lines 100-118 public: a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec2
100
                       FakeTiledLayerChromium* layer2 = 0,
105
                       FakeTiledLayerChromium* layer2 = 0,
101
                       CCLayerImpl* layerImpl2 = 0)
106
                       CCLayerImpl* layerImpl2 = 0)
102
    {
107
    {
103
        // Get textures
108
        {
104
        m_textureManager->clearPriorities();
109
            DebugScopedSetMainThread mainThread;
105
        if (layer1)
110
            
106
            layer1->setTexturePriorities(m_priorityCalculator);
111
            // Get textures
107
        if (layer2)
112
            m_textureManager->clearPriorities();
108
            layer2->setTexturePriorities(m_priorityCalculator);     
113
            if (layer1)
109
        m_textureManager->prioritizeTextures();
114
                layer1->setTexturePriorities(m_priorityCalculator);
110
115
            if (layer2)
111
        // Update content
116
                layer2->setTexturePriorities(m_priorityCalculator);     
112
        if (layer1)
117
            m_textureManager->prioritizeTextures();
113
            layer1->update(m_queue, m_occlusion, m_stats);
118
114
        if (layer2)
119
            // Update content
115
            layer2->update(m_queue, m_occlusion, m_stats);
120
            if (layer1)
121
                layer1->update(m_queue, m_occlusion, m_stats);
122
            if (layer2)
123
                layer2->update(m_queue, m_occlusion, m_stats);
124
        }
116
125
117
        bool needsUpdate = false;
126
        bool needsUpdate = false;
118
        if (layer1)
127
        if (layer1)
Lines 130-135 public: a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec3
130
        return needsUpdate;
139
        return needsUpdate;
131
    }
140
    }
132
141
142
    void setTexturePrioritiesAndPrioritizeTexturesOnMainThread(FakeTiledLayerChromium* layer)
143
    {
144
        DebugScopedSetMainThread mainThread;
145
        layer->setTexturePriorities(m_priorityCalculator);
146
        m_textureManager->prioritizeTextures();
147
    }
148
149
    void updateLayerOnMainThread(FakeTiledLayerChromium* layer, TestCCOcclusionTracker* occluded)
150
    {
151
        DebugScopedSetMainThread mainThread;
152
        layer->update(m_queue, occluded, m_stats);
153
    }
154
133
public:
155
public:
134
    OwnPtr<CCGraphicsContext> m_context;
156
    OwnPtr<CCGraphicsContext> m_context;
135
    OwnPtr<CCResourceProvider> m_resourceProvider;
157
    OwnPtr<CCResourceProvider> m_resourceProvider;
Lines 142-151 public: a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec4
142
    TestCCOcclusionTracker* m_occlusion;
164
    TestCCOcclusionTracker* m_occlusion;
143
};
165
};
144
166
145
TEST_F(TiledLayerChromiumTest, pushDirtyTiles)
167
class TiledLayerChromiumTestOnImplThread : public TiledLayerChromiumTest {
168
public:
169
    TiledLayerChromiumTestOnImplThread() { }
170
    virtual ~TiledLayerChromiumTestOnImplThread() { }
171
172
private:
173
     DebugScopedSetImplThreadAndMainThreadBlocked m_implThreadAndMainThreadBlocked;
174
};
175
176
TEST_F(TiledLayerChromiumTestOnImplThread, pushDirtyTiles)
146
{
177
{
147
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
178
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
148
    DebugScopedSetImplThread implThread;
149
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
179
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
150
180
151
    // The tile size is 100x100, so this invalidates and then paints two tiles.
181
    // The tile size is 100x100, so this invalidates and then paints two tiles.
Lines 169-178 TEST_F(TiledLayerChromiumTest, pushDirtyTiles) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec5
169
    EXPECT_FALSE(layerImpl->hasTileAt(0, 1));
199
    EXPECT_FALSE(layerImpl->hasTileAt(0, 1));
170
}
200
}
171
201
172
TEST_F(TiledLayerChromiumTest, pushOccludedDirtyTiles)
202
TEST_F(TiledLayerChromiumTestOnImplThread, pushOccludedDirtyTiles)
173
{
203
{
174
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
204
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
175
    DebugScopedSetImplThread implThread;
176
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
205
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
177
    TestCCOcclusionTracker occluded;
206
    TestCCOcclusionTracker occluded;
178
    m_occlusion = &occluded;
207
    m_occlusion = &occluded;
Lines 206-215 TEST_F(TiledLayerChromiumTest, pushOccludedDirtyTiles) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec6
206
    EXPECT_TRUE(layerImpl->hasTileAt(0, 1));
235
    EXPECT_TRUE(layerImpl->hasTileAt(0, 1));
207
}
236
}
208
237
209
TEST_F(TiledLayerChromiumTest, pushDeletedTiles)
238
TEST_F(TiledLayerChromiumTestOnImplThread, pushDeletedTiles)
210
{
239
{
211
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
240
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
212
    DebugScopedSetImplThread implThread;
213
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
241
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
214
242
215
    // The tile size is 100x100, so this invalidates and then paints two tiles.
243
    // The tile size is 100x100, so this invalidates and then paints two tiles.
Lines 222-228 TEST_F(TiledLayerChromiumTest, pushDeletedTiles) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec7
222
    EXPECT_TRUE(layerImpl->hasTileAt(0, 0));
250
    EXPECT_TRUE(layerImpl->hasTileAt(0, 0));
223
    EXPECT_TRUE(layerImpl->hasTileAt(0, 1));
251
    EXPECT_TRUE(layerImpl->hasTileAt(0, 1));
224
252
225
    m_textureManager->clearPriorities();
253
    {
254
        DebugScopedSetMainThread mainThread;
255
        m_textureManager->clearPriorities();
256
    }
226
    m_textureManager->clearAllMemory(m_resourceProvider.get());
257
    m_textureManager->clearAllMemory(m_resourceProvider.get());
227
    m_textureManager->setMaxMemoryLimitBytes(4*1024*1024);
258
    m_textureManager->setMaxMemoryLimitBytes(4*1024*1024);
228
259
Lines 242-251 TEST_F(TiledLayerChromiumTest, pushDeletedTiles) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec8
242
    EXPECT_FALSE(layerImpl->hasTileAt(0, 1));
273
    EXPECT_FALSE(layerImpl->hasTileAt(0, 1));
243
}
274
}
244
275
245
TEST_F(TiledLayerChromiumTest, pushIdlePaintTiles)
276
TEST_F(TiledLayerChromiumTestOnImplThread, pushIdlePaintTiles)
246
{
277
{
247
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
278
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
248
    DebugScopedSetImplThread implThread;
249
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
279
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
250
280
251
    // The tile size is 100x100. Setup 5x5 tiles with one visible tile in the center.
281
    // The tile size is 100x100. Setup 5x5 tiles with one visible tile in the center.
Lines 279-289 TEST_F(TiledLayerChromiumTest, pushIdlePaintTiles) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec9
279
    EXPECT_FALSE(needsUpdate);
309
    EXPECT_FALSE(needsUpdate);
280
}
310
}
281
311
282
TEST_F(TiledLayerChromiumTest, pushTilesAfterIdlePaintFailed)
312
TEST_F(TiledLayerChromiumTestOnImplThread, pushTilesAfterIdlePaintFailed)
283
{
313
{
284
    // Start with 2mb of memory, but the test is going to try to use just more than 1mb, so we reduce to 1mb later.
314
    // Start with 2mb of memory, but the test is going to try to use just more than 1mb, so we reduce to 1mb later.
285
    m_textureManager->setMaxMemoryLimitBytes(2 * 1024 * 1024);    
315
    m_textureManager->setMaxMemoryLimitBytes(2 * 1024 * 1024);    
286
    DebugScopedSetImplThread implThread;
287
    RefPtr<FakeTiledLayerChromium> layer1 = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
316
    RefPtr<FakeTiledLayerChromium> layer1 = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
288
    OwnPtr<FakeCCTiledLayerImpl> layerImpl1(adoptPtr(new FakeCCTiledLayerImpl(1)));
317
    OwnPtr<FakeCCTiledLayerImpl> layerImpl1(adoptPtr(new FakeCCTiledLayerImpl(1)));
289
    RefPtr<FakeTiledLayerChromium> layer2 = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
318
    RefPtr<FakeTiledLayerChromium> layer2 = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
Lines 334-343 TEST_F(TiledLayerChromiumTest, pushTilesAfterIdlePaintFailed) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec10
334
    EXPECT_FALSE(layerImpl2->hasTileAt(0, 2));
363
    EXPECT_FALSE(layerImpl2->hasTileAt(0, 2));
335
}
364
}
336
365
337
TEST_F(TiledLayerChromiumTest, pushIdlePaintedOccludedTiles)
366
TEST_F(TiledLayerChromiumTestOnImplThread, pushIdlePaintedOccludedTiles)
338
{
367
{
339
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
368
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
340
    DebugScopedSetImplThread implThread;
341
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
369
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
342
    TestCCOcclusionTracker occluded;
370
    TestCCOcclusionTracker occluded;
343
    m_occlusion = &occluded;
371
    m_occlusion = &occluded;
Lines 354-363 TEST_F(TiledLayerChromiumTest, pushIdlePaintedOccludedTiles) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec11
354
    EXPECT_EQ(1, occluded.overdrawMetrics().tilesCulledForUpload());
382
    EXPECT_EQ(1, occluded.overdrawMetrics().tilesCulledForUpload());
355
}
383
}
356
384
357
TEST_F(TiledLayerChromiumTest, pushTilesMarkedDirtyDuringPaint)
385
TEST_F(TiledLayerChromiumTestOnImplThread, pushTilesMarkedDirtyDuringPaint)
358
{
386
{
359
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
387
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
360
    DebugScopedSetImplThread implThread;
361
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
388
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
362
389
363
    // The tile size is 100x100, so this invalidates and then paints two tiles.
390
    // The tile size is 100x100, so this invalidates and then paints two tiles.
Lines 373-383 TEST_F(TiledLayerChromiumTest, pushTilesMarkedDirtyDuringPaint) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec12
373
    EXPECT_TRUE(layerImpl->hasTileAt(0, 1));
400
    EXPECT_TRUE(layerImpl->hasTileAt(0, 1));
374
}
401
}
375
402
376
TEST_F(TiledLayerChromiumTest, pushTilesLayerMarkedDirtyDuringPaintOnNextLayer)
403
TEST_F(TiledLayerChromiumTestOnImplThread, pushTilesLayerMarkedDirtyDuringPaintOnNextLayer)
377
{
404
{
378
    RefPtr<FakeTiledLayerChromium> layer1 = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
405
    RefPtr<FakeTiledLayerChromium> layer1 = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
379
    RefPtr<FakeTiledLayerChromium> layer2 = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
406
    RefPtr<FakeTiledLayerChromium> layer2 = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
380
    DebugScopedSetImplThread implThread;
381
    OwnPtr<FakeCCTiledLayerImpl> layer1Impl(adoptPtr(new FakeCCTiledLayerImpl(1)));
407
    OwnPtr<FakeCCTiledLayerImpl> layer1Impl(adoptPtr(new FakeCCTiledLayerImpl(1)));
382
    OwnPtr<FakeCCTiledLayerImpl> layer2Impl(adoptPtr(new FakeCCTiledLayerImpl(2)));
408
    OwnPtr<FakeCCTiledLayerImpl> layer2Impl(adoptPtr(new FakeCCTiledLayerImpl(2)));
383
409
Lines 397-407 TEST_F(TiledLayerChromiumTest, pushTilesLayerMarkedDirtyDuringPaintOnNextLayer) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec13
397
    EXPECT_TRUE(layer2Impl->hasTileAt(0, 1));
423
    EXPECT_TRUE(layer2Impl->hasTileAt(0, 1));
398
}
424
}
399
425
400
TEST_F(TiledLayerChromiumTest, pushTilesLayerMarkedDirtyDuringPaintOnPreviousLayer)
426
TEST_F(TiledLayerChromiumTestOnImplThread, pushTilesLayerMarkedDirtyDuringPaintOnPreviousLayer)
401
{
427
{
402
    RefPtr<FakeTiledLayerChromium> layer1 = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
428
    RefPtr<FakeTiledLayerChromium> layer1 = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
403
    RefPtr<FakeTiledLayerChromium> layer2 = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
429
    RefPtr<FakeTiledLayerChromium> layer2 = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
404
    DebugScopedSetImplThread implThread;
405
    OwnPtr<FakeCCTiledLayerImpl> layer1Impl(adoptPtr(new FakeCCTiledLayerImpl(1)));
430
    OwnPtr<FakeCCTiledLayerImpl> layer1Impl(adoptPtr(new FakeCCTiledLayerImpl(1)));
406
    OwnPtr<FakeCCTiledLayerImpl> layer2Impl(adoptPtr(new FakeCCTiledLayerImpl(2)));
431
    OwnPtr<FakeCCTiledLayerImpl> layer2Impl(adoptPtr(new FakeCCTiledLayerImpl(2)));
407
432
Lines 424-495 TEST_F(TiledLayerChromiumTest, paintSmallAnimatedLayersImmediately) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec14
424
{
449
{
425
    // Create a CCLayerTreeHost that has the right viewportsize,
450
    // Create a CCLayerTreeHost that has the right viewportsize,
426
    // so the layer is considered small enough.
451
    // so the layer is considered small enough.
427
    WebKit::WebCompositor::initialize(0);
428
    FakeCCLayerTreeHostClient fakeCCLayerTreeHostClient;
452
    FakeCCLayerTreeHostClient fakeCCLayerTreeHostClient;
429
    OwnPtr<CCLayerTreeHost> ccLayerTreeHost = CCLayerTreeHost::create(&fakeCCLayerTreeHostClient, CCLayerTreeSettings());
453
    OwnPtr<CCLayerTreeHost> ccLayerTreeHost = CCLayerTreeHost::create(&fakeCCLayerTreeHostClient, CCLayerTreeSettings());
430
454
431
    bool runOutOfMemory[2] = {false, true};
455
    {
432
    for (int i = 0; i < 2; i++) {
456
        DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
433
        // Create a layer with 4x4 tiles.
457
        bool runOutOfMemory[2] = {false, true};
434
        int layerWidth  = 4 * FakeTiledLayerChromium::tileSize().width();
458
        for (int i = 0; i < 2; i++) {
435
        int layerHeight = 4 * FakeTiledLayerChromium::tileSize().height();
459
            // Create a layer with 4x4 tiles.
436
        int memoryForLayer = layerWidth * layerHeight * 4;
460
            int layerWidth  = 4 * FakeTiledLayerChromium::tileSize().width();
437
        IntSize viewportSize = IntSize(layerWidth, layerHeight);
461
            int layerHeight = 4 * FakeTiledLayerChromium::tileSize().height();
438
        ccLayerTreeHost->setViewportSize(viewportSize, viewportSize);
462
            int memoryForLayer = layerWidth * layerHeight * 4;
463
            IntSize viewportSize = IntSize(layerWidth, layerHeight);
464
            {
465
                DebugScopedSetMainThread mainThread;
466
                ccLayerTreeHost->setViewportSize(viewportSize, viewportSize);
467
            }
439
468
440
        // Use 8x4 tiles to run out of memory.
469
            // Use 8x4 tiles to run out of memory.
441
        if (runOutOfMemory[i])
470
            if (runOutOfMemory[i])
442
            layerWidth *= 2;
471
                layerWidth *= 2;
443
472
444
        m_textureManager->setMaxMemoryLimitBytes(memoryForLayer);
473
            m_textureManager->setMaxMemoryLimitBytes(memoryForLayer);
445
        DebugScopedSetImplThread implThread;
446
474
447
        RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
475
            RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
448
        OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
476
            OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
449
477
450
        // Full size layer with half being visible.
478
            {
451
        IntSize contentBounds(layerWidth, layerHeight);
479
                DebugScopedSetMainThread mainThread;
452
        IntRect contentRect(IntPoint::zero(), contentBounds);
453
        IntRect visibleRect(IntPoint::zero(), IntSize(layerWidth / 2, layerHeight));
454
480
455
        // Pretend the layer is animating.
481
                // Full size layer with half being visible.
456
        layer->setDrawTransformIsAnimating(true);
482
                IntSize contentBounds(layerWidth, layerHeight);
457
        layer->setBounds(contentBounds);
483
                IntRect contentRect(IntPoint::zero(), contentBounds);
458
        layer->setVisibleContentRect(visibleRect);
484
                IntRect visibleRect(IntPoint::zero(), IntSize(layerWidth / 2, layerHeight));
459
        layer->invalidateContentRect(contentRect);
485
460
        layer->setLayerTreeHost(ccLayerTreeHost.get());
486
                // Pretend the layer is animating.
461
487
                layer->setDrawTransformIsAnimating(true);
462
        // The layer should paint it's entire contents on the first paint
488
                layer->setBounds(contentBounds);
463
        // if it is close to the viewport size and has the available memory.
489
                layer->setVisibleContentRect(visibleRect);
464
        layer->setTexturePriorities(m_priorityCalculator);
490
                layer->invalidateContentRect(contentRect);
465
        m_textureManager->prioritizeTextures();
491
                layer->setLayerTreeHost(ccLayerTreeHost.get());
466
        layer->update(m_queue, 0, m_stats);
467
        updateTextures();
468
        layer->pushPropertiesTo(layerImpl.get());
469
470
        // We should have all the tiles for the small animated layer.
471
        // We should still have the visible tiles when we didn't
472
        // have enough memory for all the tiles.
473
        if (!runOutOfMemory[i]) {
474
            for (int i = 0; i < 4; ++i) {
475
                for (int j = 0; j < 4; ++j)
476
                    EXPECT_TRUE(layerImpl->hasTileAt(i, j));
477
            }
492
            }
478
        } else {
493
479
            for (int i = 0; i < 8; ++i) {
494
            // The layer should paint it's entire contents on the first paint
480
                for (int j = 0; j < 4; ++j)
495
            // if it is close to the viewport size and has the available memory.
481
                    EXPECT_EQ(layerImpl->hasTileAt(i, j), i < 4);
496
            setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
497
            updateLayerOnMainThread(layer.get(), 0);
498
            updateTextures();
499
            layer->pushPropertiesTo(layerImpl.get());
500
501
            // We should have all the tiles for the small animated layer.
502
            // We should still have the visible tiles when we didn't
503
            // have enough memory for all the tiles.
504
            if (!runOutOfMemory[i]) {
505
                for (int i = 0; i < 4; ++i) {
506
                    for (int j = 0; j < 4; ++j)
507
                        EXPECT_TRUE(layerImpl->hasTileAt(i, j));
508
                }
509
            } else {
510
                for (int i = 0; i < 8; ++i) {
511
                    for (int j = 0; j < 4; ++j)
512
                        EXPECT_EQ(layerImpl->hasTileAt(i, j), i < 4);
513
                }
482
            }
514
            }
483
        }
515
        }
484
    }
516
    }
485
    ccLayerTreeHost.clear();
517
    ccLayerTreeHost.clear();
486
    WebKit::WebCompositor::shutdown();
487
}
518
}
488
519
489
TEST_F(TiledLayerChromiumTest, idlePaintOutOfMemory)
520
TEST_F(TiledLayerChromiumTestOnImplThread, idlePaintOutOfMemory)
490
{
521
{
491
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
522
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
492
    DebugScopedSetImplThread implThread;
493
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
523
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
494
524
495
    // We have enough memory for only the visible rect, so we will run out of memory in first idle paint.
525
    // We have enough memory for only the visible rect, so we will run out of memory in first idle paint.
Lines 510-519 TEST_F(TiledLayerChromiumTest, idlePaintOutOfMemory) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec15
510
    EXPECT_TRUE(layerImpl->hasTileAt(1, 1));
540
    EXPECT_TRUE(layerImpl->hasTileAt(1, 1));
511
}
541
}
512
542
513
TEST_F(TiledLayerChromiumTest, idlePaintZeroSizedLayer)
543
TEST_F(TiledLayerChromiumTestOnImplThread, idlePaintZeroSizedLayer)
514
{
544
{
515
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
545
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
516
    DebugScopedSetImplThread implThread;
517
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
546
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
518
547
519
    bool animating[2] = {false, true};
548
    bool animating[2] = {false, true};
Lines 538-547 TEST_F(TiledLayerChromiumTest, idlePaintZeroSizedLayer) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec16
538
    }
567
    }
539
}
568
}
540
569
541
TEST_F(TiledLayerChromiumTest, idlePaintNonVisibleLayers)
570
TEST_F(TiledLayerChromiumTestOnImplThread, idlePaintNonVisibleLayers)
542
{
571
{
543
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
572
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
544
    DebugScopedSetImplThread implThread;
545
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
573
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
546
574
547
    // Alternate between not visible and visible.
575
    // Alternate between not visible and visible.
Lines 569-578 TEST_F(TiledLayerChromiumTest, idlePaintNonVisibleLayers) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec17
569
    }
597
    }
570
}
598
}
571
599
572
TEST_F(TiledLayerChromiumTest, invalidateFromPrepare)
600
TEST_F(TiledLayerChromiumTestOnImplThread, invalidateFromPrepare)
573
{
601
{
574
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
602
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
575
    DebugScopedSetImplThread implThread;
576
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
603
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
577
604
578
    // The tile size is 100x100, so this invalidates and then paints two tiles.
605
    // The tile size is 100x100, so this invalidates and then paints two tiles.
Lines 603-614 TEST_F(TiledLayerChromiumTest, invalidateFromPrepare) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec18
603
    EXPECT_EQ(1, layer->fakeLayerTextureUpdater()->prepareCount());
630
    EXPECT_EQ(1, layer->fakeLayerTextureUpdater()->prepareCount());
604
}
631
}
605
632
606
TEST_F(TiledLayerChromiumTest, verifyUpdateRectWhenContentBoundsAreScaled)
633
TEST_F(TiledLayerChromiumTestOnImplThread, verifyUpdateRectWhenContentBoundsAreScaled)
607
{
634
{
608
    // The updateRect (that indicates what was actually painted) should be in
635
    // The updateRect (that indicates what was actually painted) should be in
609
    // layer space, not the content space.
636
    // layer space, not the content space.
610
    RefPtr<FakeTiledLayerWithScaledBounds> layer = adoptRef(new FakeTiledLayerWithScaledBounds(m_textureManager.get()));
637
    RefPtr<FakeTiledLayerWithScaledBounds> layer = adoptRef(new FakeTiledLayerWithScaledBounds(m_textureManager.get()));
611
    DebugScopedSetImplThread implThread;
612
638
613
    IntRect layerBounds(0, 0, 300, 200);
639
    IntRect layerBounds(0, 0, 300, 200);
614
    IntRect contentBounds(0, 0, 200, 250);
640
    IntRect contentBounds(0, 0, 200, 250);
Lines 621-653 TEST_F(TiledLayerChromiumTest, verifyUpdateRectWhenContentBoundsAreScaled) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec19
621
    // However, it should still be in layer space, not content space.
647
    // However, it should still be in layer space, not content space.
622
    layer->invalidateContentRect(contentBounds);
648
    layer->invalidateContentRect(contentBounds);
623
649
624
    layer->setTexturePriorities(m_priorityCalculator);
650
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
625
    m_textureManager->prioritizeTextures();
651
    updateLayerOnMainThread(layer.get(), 0);
626
    layer->update(m_queue, 0, m_stats);
627
    EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 300, 300 * 0.8), layer->updateRect());
652
    EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 300, 300 * 0.8), layer->updateRect());
628
    updateTextures();
653
    updateTextures();
629
654
630
    // After the tiles are updated once, another invalidate only needs to update the bounds of the layer.
655
    // After the tiles are updated once, another invalidate only needs to update the bounds of the layer.
631
    layer->setTexturePriorities(m_priorityCalculator);
656
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
632
    m_textureManager->prioritizeTextures();
633
    layer->invalidateContentRect(contentBounds);
657
    layer->invalidateContentRect(contentBounds);
634
    layer->update(m_queue, 0, m_stats);
658
    updateLayerOnMainThread(layer.get(), 0);
635
    EXPECT_FLOAT_RECT_EQ(FloatRect(layerBounds), layer->updateRect());
659
    EXPECT_FLOAT_RECT_EQ(FloatRect(layerBounds), layer->updateRect());
636
    updateTextures();
660
    updateTextures();
637
661
638
    // Partial re-paint should also be represented by the updateRect in layer space, not content space.
662
    // Partial re-paint should also be represented by the updateRect in layer space, not content space.
639
    IntRect partialDamage(30, 100, 10, 10);
663
    IntRect partialDamage(30, 100, 10, 10);
640
    layer->invalidateContentRect(partialDamage);
664
    layer->invalidateContentRect(partialDamage);
641
    layer->setTexturePriorities(m_priorityCalculator);
665
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
642
    m_textureManager->prioritizeTextures();
666
    updateLayerOnMainThread(layer.get(), 0);
643
    layer->update(m_queue, 0, m_stats);
644
    EXPECT_FLOAT_RECT_EQ(FloatRect(45, 80, 15, 8), layer->updateRect());
667
    EXPECT_FLOAT_RECT_EQ(FloatRect(45, 80, 15, 8), layer->updateRect());
645
}
668
}
646
669
647
TEST_F(TiledLayerChromiumTest, verifyInvalidationWhenContentsScaleChanges)
670
TEST_F(TiledLayerChromiumTestOnImplThread, verifyInvalidationWhenContentsScaleChanges)
648
{
671
{
649
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
672
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
650
    DebugScopedSetImplThread implThread;
651
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
673
    OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
652
674
653
    // Create a layer with one tile.
675
    // Create a layer with one tile.
Lines 659-667 TEST_F(TiledLayerChromiumTest, verifyInvalidationWhenContentsScaleChanges) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec20
659
    EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 100, 100), layer->lastNeedsDisplayRect());
681
    EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 100, 100), layer->lastNeedsDisplayRect());
660
682
661
    // Push the tiles to the impl side and check that there is exactly one.
683
    // Push the tiles to the impl side and check that there is exactly one.
662
    layer->setTexturePriorities(m_priorityCalculator);
684
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
663
    m_textureManager->prioritizeTextures();
685
    updateLayerOnMainThread(layer.get(), 0);
664
    layer->update(m_queue, 0, m_stats);
665
    updateTextures();
686
    updateTextures();
666
    layer->pushPropertiesTo(layerImpl.get());
687
    layer->pushPropertiesTo(layerImpl.get());
667
    EXPECT_TRUE(layerImpl->hasTileAt(0, 0));
688
    EXPECT_TRUE(layerImpl->hasTileAt(0, 0));
Lines 676-684 TEST_F(TiledLayerChromiumTest, verifyInvalidationWhenContentsScaleChanges) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec21
676
    EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 100, 100), layer->lastNeedsDisplayRect());
697
    EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 100, 100), layer->lastNeedsDisplayRect());
677
698
678
    // The impl side should get 2x2 tiles now.
699
    // The impl side should get 2x2 tiles now.
679
    layer->setTexturePriorities(m_priorityCalculator);
700
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
680
    m_textureManager->prioritizeTextures();
701
    updateLayerOnMainThread(layer.get(), 0);
681
    layer->update(m_queue, 0, m_stats);
682
    updateTextures();
702
    updateTextures();
683
    layer->pushPropertiesTo(layerImpl.get());
703
    layer->pushPropertiesTo(layerImpl.get());
684
    EXPECT_TRUE(layerImpl->hasTileAt(0, 0));
704
    EXPECT_TRUE(layerImpl->hasTileAt(0, 0));
Lines 689-697 TEST_F(TiledLayerChromiumTest, verifyInvalidationWhenContentsScaleChanges) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec22
689
    // Invalidate the entire layer again, but do not paint. All tiles should be gone now from the
709
    // Invalidate the entire layer again, but do not paint. All tiles should be gone now from the
690
    // impl side.
710
    // impl side.
691
    layer->setNeedsDisplay();
711
    layer->setNeedsDisplay();
692
    layer->setTexturePriorities(m_priorityCalculator);
712
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
693
    m_textureManager->prioritizeTextures();
694
695
    layer->pushPropertiesTo(layerImpl.get());
713
    layer->pushPropertiesTo(layerImpl.get());
696
    EXPECT_FALSE(layerImpl->hasTileAt(0, 0));
714
    EXPECT_FALSE(layerImpl->hasTileAt(0, 0));
697
    EXPECT_FALSE(layerImpl->hasTileAt(0, 1));
715
    EXPECT_FALSE(layerImpl->hasTileAt(0, 1));
Lines 701-756 TEST_F(TiledLayerChromiumTest, verifyInvalidationWhenContentsScaleChanges) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec23
701
719
702
TEST_F(TiledLayerChromiumTest, skipsDrawGetsReset)
720
TEST_F(TiledLayerChromiumTest, skipsDrawGetsReset)
703
{
721
{
704
    // Initialize without threading support.
705
    WebKit::WebCompositor::initialize(0);
706
    FakeCCLayerTreeHostClient fakeCCLayerTreeHostClient;
722
    FakeCCLayerTreeHostClient fakeCCLayerTreeHostClient;
707
    OwnPtr<CCLayerTreeHost> ccLayerTreeHost = CCLayerTreeHost::create(&fakeCCLayerTreeHostClient, CCLayerTreeSettings());
723
    OwnPtr<CCLayerTreeHost> ccLayerTreeHost = CCLayerTreeHost::create(&fakeCCLayerTreeHostClient, CCLayerTreeSettings());
708
    ASSERT_TRUE(ccLayerTreeHost->initializeRendererIfNeeded());
724
    ASSERT_TRUE(ccLayerTreeHost->initializeRendererIfNeeded());
709
725
710
    // Create two 300 x 300 tiled layers.
726
    {
711
    IntSize contentBounds(300, 300);
727
        DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
712
    IntRect contentRect(IntPoint::zero(), contentBounds);
713
714
    // We have enough memory for only one of the two layers.
715
    int memoryLimit = 4 * 300 * 300; // 4 bytes per pixel.
716
717
    RefPtr<FakeTiledLayerChromium> rootLayer = adoptRef(new FakeTiledLayerChromium(ccLayerTreeHost->contentsTextureManager()));
718
    RefPtr<FakeTiledLayerChromium> childLayer = adoptRef(new FakeTiledLayerChromium(ccLayerTreeHost->contentsTextureManager()));
719
    rootLayer->addChild(childLayer);
720
721
    rootLayer->setBounds(contentBounds);
722
    rootLayer->setVisibleContentRect(contentRect);
723
    rootLayer->setPosition(FloatPoint(0, 0));
724
    childLayer->setBounds(contentBounds);
725
    childLayer->setVisibleContentRect(contentRect);
726
    childLayer->setPosition(FloatPoint(0, 0));
727
    rootLayer->invalidateContentRect(contentRect);
728
    childLayer->invalidateContentRect(contentRect);
729
730
    ccLayerTreeHost->setRootLayer(rootLayer);
731
    ccLayerTreeHost->setViewportSize(IntSize(300, 300), IntSize(300, 300));
732
733
    ccLayerTreeHost->updateLayers(m_queue, memoryLimit);
734
728
735
    // We'll skip the root layer.
729
        // Create two 300 x 300 tiled layers.
736
    EXPECT_TRUE(rootLayer->skipsDraw());
730
        IntSize contentBounds(300, 300);
737
    EXPECT_FALSE(childLayer->skipsDraw());
731
        IntRect contentRect(IntPoint::zero(), contentBounds);
738
732
739
    ccLayerTreeHost->commitComplete();
733
        // We have enough memory for only one of the two layers.
734
        int memoryLimit = 4 * 300 * 300; // 4 bytes per pixel.
735
736
        RefPtr<FakeTiledLayerChromium> rootLayer = adoptRef(new FakeTiledLayerChromium(ccLayerTreeHost->contentsTextureManager()));
737
        RefPtr<FakeTiledLayerChromium> childLayer = adoptRef(new FakeTiledLayerChromium(ccLayerTreeHost->contentsTextureManager()));
738
        rootLayer->addChild(childLayer);
739
740
        {
741
            DebugScopedSetMainThread mainThread;
742
            rootLayer->setBounds(contentBounds);
743
            rootLayer->setVisibleContentRect(contentRect);
744
            rootLayer->setPosition(FloatPoint(0, 0));
745
            childLayer->setBounds(contentBounds);
746
            childLayer->setVisibleContentRect(contentRect);
747
            childLayer->setPosition(FloatPoint(0, 0));
748
            rootLayer->invalidateContentRect(contentRect);
749
            childLayer->invalidateContentRect(contentRect);
750
751
            ccLayerTreeHost->setRootLayer(rootLayer);
752
            ccLayerTreeHost->setViewportSize(IntSize(300, 300), IntSize(300, 300));
753
            ccLayerTreeHost->updateLayers(m_queue, memoryLimit);
754
        }
740
755
741
    // Remove the child layer.
756
        // We'll skip the root layer.
742
    rootLayer->removeAllChildren();
757
        EXPECT_TRUE(rootLayer->skipsDraw());
758
        EXPECT_FALSE(childLayer->skipsDraw());
743
759
744
    ccLayerTreeHost->updateLayers(m_queue, memoryLimit);
760
        ccLayerTreeHost->commitComplete();
745
    EXPECT_FALSE(rootLayer->skipsDraw());
746
761
747
    ccLayerTreeHost->contentsTextureManager()->clearAllMemory(m_resourceProvider.get());
762
        {
763
            DebugScopedSetMainThread mainThread;
764
            // Remove the child layer.
765
            rootLayer->removeAllChildren();
766
            ccLayerTreeHost->updateLayers(m_queue, memoryLimit);
767
            EXPECT_FALSE(rootLayer->skipsDraw());
768
        }
769
        ccLayerTreeHost->contentsTextureManager()->clearAllMemory(m_resourceProvider.get());
770
    }
748
    ccLayerTreeHost->setRootLayer(0);
771
    ccLayerTreeHost->setRootLayer(0);
749
    ccLayerTreeHost.clear();
772
    ccLayerTreeHost.clear();
750
    WebKit::WebCompositor::shutdown();
751
}
773
}
752
774
753
TEST_F(TiledLayerChromiumTest, resizeToSmaller)
775
TEST_F(TiledLayerChromiumTestOnImplThread, resizeToSmaller)
754
{
776
{
755
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
777
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
756
778
Lines 758-772 TEST_F(TiledLayerChromiumTest, resizeToSmaller) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec24
758
    layer->setVisibleContentRect(IntRect(0, 0, 700, 700));
780
    layer->setVisibleContentRect(IntRect(0, 0, 700, 700));
759
    layer->invalidateContentRect(IntRect(0, 0, 700, 700));
781
    layer->invalidateContentRect(IntRect(0, 0, 700, 700));
760
782
761
    layer->setTexturePriorities(m_priorityCalculator);
783
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
762
    m_textureManager->prioritizeTextures();
784
    updateLayerOnMainThread(layer.get(), 0);
763
    layer->update(m_queue, 0, m_stats);
764
785
765
    layer->setBounds(IntSize(200, 200));
786
    layer->setBounds(IntSize(200, 200));
766
    layer->invalidateContentRect(IntRect(0, 0, 200, 200));
787
    layer->invalidateContentRect(IntRect(0, 0, 200, 200));
767
}
788
}
768
789
769
TEST_F(TiledLayerChromiumTest, hugeLayerUpdateCrash)
790
TEST_F(TiledLayerChromiumTestOnImplThread, hugeLayerUpdateCrash)
770
{
791
{
771
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
792
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
772
793
Lines 776-791 TEST_F(TiledLayerChromiumTest, hugeLayerUpdateCrash) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec25
776
    layer->invalidateContentRect(IntRect(0, 0, size, size));
797
    layer->invalidateContentRect(IntRect(0, 0, size, size));
777
798
778
    // Ensure no crash for bounds where size * size would overflow an int.
799
    // Ensure no crash for bounds where size * size would overflow an int.
779
    layer->setTexturePriorities(m_priorityCalculator);
800
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
780
    m_textureManager->prioritizeTextures();
801
    updateLayerOnMainThread(layer.get(), 0);
781
    layer->update(m_queue, 0, m_stats);
782
}
802
}
783
803
784
TEST_F(TiledLayerChromiumTest, partialUpdates)
804
TEST_F(TiledLayerChromiumTest, partialUpdates)
785
{
805
{
786
    // Initialize without threading support.
787
    WebKit::WebCompositor::initialize(0);
788
789
    CCLayerTreeSettings settings;
806
    CCLayerTreeSettings settings;
790
    settings.maxPartialTextureUpdates = 4;
807
    settings.maxPartialTextureUpdates = 4;
791
808
Lines 793-916 TEST_F(TiledLayerChromiumTest, partialUpdates) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec26
793
    OwnPtr<CCLayerTreeHost> ccLayerTreeHost = CCLayerTreeHost::create(&fakeCCLayerTreeHostClient, settings);
810
    OwnPtr<CCLayerTreeHost> ccLayerTreeHost = CCLayerTreeHost::create(&fakeCCLayerTreeHostClient, settings);
794
    ASSERT_TRUE(ccLayerTreeHost->initializeRendererIfNeeded());
811
    ASSERT_TRUE(ccLayerTreeHost->initializeRendererIfNeeded());
795
812
796
    // Create one 300 x 200 tiled layer with 3 x 2 tiles.
813
    {
797
    IntSize contentBounds(300, 200);
814
        DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
798
    IntRect contentRect(IntPoint::zero(), contentBounds);
799
815
800
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(ccLayerTreeHost->contentsTextureManager()));
816
        // Create one 300 x 200 tiled layer with 3 x 2 tiles.
801
    layer->setBounds(contentBounds);
817
        IntSize contentBounds(300, 200);
802
    layer->setPosition(FloatPoint(0, 0));
818
        IntRect contentRect(IntPoint::zero(), contentBounds);
803
    layer->setVisibleContentRect(contentRect);
804
    layer->invalidateContentRect(contentRect);
805
819
806
    ccLayerTreeHost->setRootLayer(layer);
820
        RefPtr<FakeTiledLayerChromium> layer(adoptRef(new FakeTiledLayerChromium(ccLayerTreeHost->contentsTextureManager())));
807
    ccLayerTreeHost->setViewportSize(IntSize(300, 200), IntSize(300, 200));
808
821
809
    // Full update of all 6 tiles.
822
        {
810
    ccLayerTreeHost->updateLayers(m_queue, std::numeric_limits<size_t>::max());
823
            DebugScopedSetMainThread mainThread;
811
    {
824
            layer->setBounds(contentBounds);
812
        DebugScopedSetImplThread implThread;
825
            layer->setPosition(FloatPoint(0, 0));
813
        OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
826
            layer->setVisibleContentRect(contentRect);
814
        updateTextures(4);
827
            layer->invalidateContentRect(contentRect);
815
        EXPECT_EQ(4, layer->fakeLayerTextureUpdater()->updateCount());
816
        EXPECT_TRUE(m_queue.hasMoreUpdates());
817
        layer->fakeLayerTextureUpdater()->clearUpdateCount();
818
        updateTextures(4);
819
        EXPECT_EQ(2, layer->fakeLayerTextureUpdater()->updateCount());
820
        EXPECT_FALSE(m_queue.hasMoreUpdates());
821
        layer->fakeLayerTextureUpdater()->clearUpdateCount();
822
        layer->pushPropertiesTo(layerImpl.get());
823
    }
824
    ccLayerTreeHost->commitComplete();
825
828
826
    // Full update of 3 tiles and partial update of 3 tiles.
829
            ccLayerTreeHost->setRootLayer(layer);
827
    layer->invalidateContentRect(IntRect(0, 0, 300, 150));
830
            ccLayerTreeHost->setViewportSize(IntSize(300, 200), IntSize(300, 200));
828
    ccLayerTreeHost->updateLayers(m_queue, std::numeric_limits<size_t>::max());
829
    {
830
        DebugScopedSetImplThread implThread;
831
        OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
832
        updateTextures(4);
833
        EXPECT_EQ(3, layer->fakeLayerTextureUpdater()->updateCount());
834
        EXPECT_TRUE(m_queue.hasMoreUpdates());
835
        layer->fakeLayerTextureUpdater()->clearUpdateCount();
836
        updateTextures(4);
837
        EXPECT_EQ(3, layer->fakeLayerTextureUpdater()->updateCount());
838
        EXPECT_FALSE(m_queue.hasMoreUpdates());
839
        layer->fakeLayerTextureUpdater()->clearUpdateCount();
840
        layer->pushPropertiesTo(layerImpl.get());
841
    }
842
    ccLayerTreeHost->commitComplete();
843
844
    // Partial update of 6 tiles.
845
    layer->invalidateContentRect(IntRect(50, 50, 200, 100));
846
    {
847
        DebugScopedSetImplThread implThread;
848
        OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
849
        ccLayerTreeHost->updateLayers(m_queue, std::numeric_limits<size_t>::max());
850
        updateTextures(4);
851
        EXPECT_EQ(2, layer->fakeLayerTextureUpdater()->updateCount());
852
        EXPECT_TRUE(m_queue.hasMoreUpdates());
853
        layer->fakeLayerTextureUpdater()->clearUpdateCount();
854
        updateTextures(4);
855
        EXPECT_EQ(4, layer->fakeLayerTextureUpdater()->updateCount());
856
        EXPECT_FALSE(m_queue.hasMoreUpdates());
857
        layer->fakeLayerTextureUpdater()->clearUpdateCount();
858
        layer->pushPropertiesTo(layerImpl.get());
859
    }
860
    ccLayerTreeHost->commitComplete();
861
831
862
    // Checkerboard all tiles.
832
            // Full update of all 6 tiles.
863
    layer->invalidateContentRect(IntRect(0, 0, 300, 200));
833
            ccLayerTreeHost->updateLayers(m_queue, std::numeric_limits<size_t>::max());
864
    {
834
        }
865
        DebugScopedSetImplThread implThread;
866
        OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
867
        layer->pushPropertiesTo(layerImpl.get());
868
    }
869
    ccLayerTreeHost->commitComplete();
870
835
871
    // Partial update of 6 checkerboard tiles.
836
        {
872
    layer->invalidateContentRect(IntRect(50, 50, 200, 100));
837
            OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
873
    {
838
            updateTextures(4);
874
        DebugScopedSetImplThread implThread;
839
            EXPECT_EQ(4, layer->fakeLayerTextureUpdater()->updateCount());
875
        OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
840
            EXPECT_TRUE(m_queue.hasMoreUpdates());
876
        ccLayerTreeHost->updateLayers(m_queue, std::numeric_limits<size_t>::max());
841
            layer->fakeLayerTextureUpdater()->clearUpdateCount();
877
        updateTextures(4);
842
            updateTextures(4);
878
        EXPECT_EQ(4, layer->fakeLayerTextureUpdater()->updateCount());
843
            EXPECT_EQ(2, layer->fakeLayerTextureUpdater()->updateCount());
879
        EXPECT_TRUE(m_queue.hasMoreUpdates());
844
            EXPECT_FALSE(m_queue.hasMoreUpdates());
880
        layer->fakeLayerTextureUpdater()->clearUpdateCount();
845
            layer->fakeLayerTextureUpdater()->clearUpdateCount();
881
        updateTextures(4);
846
            layer->pushPropertiesTo(layerImpl.get());
882
        EXPECT_EQ(2, layer->fakeLayerTextureUpdater()->updateCount());
847
        }
883
        EXPECT_FALSE(m_queue.hasMoreUpdates());
848
        ccLayerTreeHost->commitComplete();
884
        layer->fakeLayerTextureUpdater()->clearUpdateCount();
885
        layer->pushPropertiesTo(layerImpl.get());
886
    }
887
    ccLayerTreeHost->commitComplete();
888
849
889
    // Partial update of 4 tiles.
850
        // Full update of 3 tiles and partial update of 3 tiles.
890
    layer->invalidateContentRect(IntRect(50, 50, 100, 100));
851
        layer->invalidateContentRect(IntRect(0, 0, 300, 150));
891
    {
852
        {
892
        DebugScopedSetImplThread implThread;
853
            DebugScopedSetMainThread mainThread;
893
        OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
854
            ccLayerTreeHost->updateLayers(m_queue, std::numeric_limits<size_t>::max());
894
        ccLayerTreeHost->updateLayers(m_queue, std::numeric_limits<size_t>::max());
855
        }
895
        updateTextures(4);
856
        {
896
        EXPECT_EQ(4, layer->fakeLayerTextureUpdater()->updateCount());
857
            OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
897
        EXPECT_FALSE(m_queue.hasMoreUpdates());
858
            updateTextures(4);
898
        layer->fakeLayerTextureUpdater()->clearUpdateCount();
859
            EXPECT_EQ(3, layer->fakeLayerTextureUpdater()->updateCount());
899
        layer->pushPropertiesTo(layerImpl.get());
860
            EXPECT_TRUE(m_queue.hasMoreUpdates());
900
    }
861
            layer->fakeLayerTextureUpdater()->clearUpdateCount();
901
    ccLayerTreeHost->commitComplete();
862
            updateTextures(4);
863
            EXPECT_EQ(3, layer->fakeLayerTextureUpdater()->updateCount());
864
            EXPECT_FALSE(m_queue.hasMoreUpdates());
865
            layer->fakeLayerTextureUpdater()->clearUpdateCount();
866
            layer->pushPropertiesTo(layerImpl.get());
867
        }
868
        ccLayerTreeHost->commitComplete();
869
870
        // Partial update of 6 tiles.
871
        layer->invalidateContentRect(IntRect(50, 50, 200, 100));
872
        {
873
            OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
874
            {
875
                DebugScopedSetMainThread mainThread;
876
                ccLayerTreeHost->updateLayers(m_queue, std::numeric_limits<size_t>::max());
877
            }
878
            updateTextures(4);
879
            EXPECT_EQ(2, layer->fakeLayerTextureUpdater()->updateCount());
880
            EXPECT_TRUE(m_queue.hasMoreUpdates());
881
            layer->fakeLayerTextureUpdater()->clearUpdateCount();
882
            updateTextures(4);
883
            EXPECT_EQ(4, layer->fakeLayerTextureUpdater()->updateCount());
884
            EXPECT_FALSE(m_queue.hasMoreUpdates());
885
            layer->fakeLayerTextureUpdater()->clearUpdateCount();
886
            layer->pushPropertiesTo(layerImpl.get());
887
        }
888
        ccLayerTreeHost->commitComplete();
902
889
903
    {
890
        // Checkerboard all tiles.
904
        DebugScopedSetImplThread implThread;
891
        layer->invalidateContentRect(IntRect(0, 0, 300, 200));
892
        {
893
            OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
894
            layer->pushPropertiesTo(layerImpl.get());
895
        }
896
        ccLayerTreeHost->commitComplete();
897
898
        // Partial update of 6 checkerboard tiles.
899
        layer->invalidateContentRect(IntRect(50, 50, 200, 100));
900
        {
901
            OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
902
            {
903
                DebugScopedSetMainThread mainThread;
904
                ccLayerTreeHost->updateLayers(m_queue, std::numeric_limits<size_t>::max());
905
            }
906
            updateTextures(4);
907
            EXPECT_EQ(4, layer->fakeLayerTextureUpdater()->updateCount());
908
            EXPECT_TRUE(m_queue.hasMoreUpdates());
909
            layer->fakeLayerTextureUpdater()->clearUpdateCount();
910
            updateTextures(4);
911
            EXPECT_EQ(2, layer->fakeLayerTextureUpdater()->updateCount());
912
            EXPECT_FALSE(m_queue.hasMoreUpdates());
913
            layer->fakeLayerTextureUpdater()->clearUpdateCount();
914
            layer->pushPropertiesTo(layerImpl.get());
915
        }
916
        ccLayerTreeHost->commitComplete();
917
918
        // Partial update of 4 tiles.
919
        layer->invalidateContentRect(IntRect(50, 50, 100, 100));
920
        {
921
            OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1)));
922
            {
923
                DebugScopedSetMainThread mainThread;
924
                ccLayerTreeHost->updateLayers(m_queue, std::numeric_limits<size_t>::max());
925
            }
926
            updateTextures(4);
927
            EXPECT_EQ(4, layer->fakeLayerTextureUpdater()->updateCount());
928
            EXPECT_FALSE(m_queue.hasMoreUpdates());
929
            layer->fakeLayerTextureUpdater()->clearUpdateCount();
930
            layer->pushPropertiesTo(layerImpl.get());
931
        }
932
        ccLayerTreeHost->commitComplete();
905
        ccLayerTreeHost->contentsTextureManager()->clearAllMemory(m_resourceProvider.get());
933
        ccLayerTreeHost->contentsTextureManager()->clearAllMemory(m_resourceProvider.get());
906
    }
934
    }
907
    ccLayerTreeHost->setRootLayer(0);
935
    ccLayerTreeHost->setRootLayer(0);
908
    ccLayerTreeHost.clear();
936
    ccLayerTreeHost.clear();
909
    WebKit::WebCompositor::shutdown();
910
}
937
}
911
938
912
TEST_F(TiledLayerChromiumTest, tilesPaintedWithoutOcclusion)
939
TEST_F(TiledLayerChromiumTest, tilesPaintedWithoutOcclusion)
913
{
940
{
941
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
914
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
942
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
915
943
916
    // The tile size is 100x100, so this invalidates and then paints two tiles.
944
    // The tile size is 100x100, so this invalidates and then paints two tiles.
Lines 919-932 TEST_F(TiledLayerChromiumTest, tilesPaintedWithoutOcclusion) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec27
919
    layer->setVisibleContentRect(IntRect(0, 0, 100, 200));
947
    layer->setVisibleContentRect(IntRect(0, 0, 100, 200));
920
    layer->invalidateContentRect(IntRect(0, 0, 100, 200));
948
    layer->invalidateContentRect(IntRect(0, 0, 100, 200));
921
949
922
    layer->setTexturePriorities(m_priorityCalculator);
950
923
    m_textureManager->prioritizeTextures();
951
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
924
    layer->update(m_queue, 0, m_stats);
952
    updateLayerOnMainThread(layer.get(), 0);
925
    EXPECT_EQ(2, layer->fakeLayerTextureUpdater()->prepareRectCount());
953
    EXPECT_EQ(2, layer->fakeLayerTextureUpdater()->prepareRectCount());
926
}
954
}
927
955
928
TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusion)
956
TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusion)
929
{
957
{
958
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
930
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
959
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
931
    TestCCOcclusionTracker occluded;
960
    TestCCOcclusionTracker occluded;
932
961
Lines 939-947 TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusion) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec28
939
    layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds()));
968
    layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds()));
940
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
969
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
941
970
942
    layer->setTexturePriorities(m_priorityCalculator);
971
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
943
    m_textureManager->prioritizeTextures();
972
    updateLayerOnMainThread(layer.get(), &occluded);
944
    layer->update(m_queue, &occluded, m_stats);
945
    EXPECT_EQ(36-3, layer->fakeLayerTextureUpdater()->prepareRectCount());
973
    EXPECT_EQ(36-3, layer->fakeLayerTextureUpdater()->prepareRectCount());
946
974
947
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
975
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
Lines 949-960 TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusion) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec29
949
    EXPECT_EQ(3, occluded.overdrawMetrics().tilesCulledForUpload());
977
    EXPECT_EQ(3, occluded.overdrawMetrics().tilesCulledForUpload());
950
978
951
    layer->fakeLayerTextureUpdater()->clearPrepareRectCount();
979
    layer->fakeLayerTextureUpdater()->clearPrepareRectCount();
952
    layer->setTexturePriorities(m_priorityCalculator);
980
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
953
    m_textureManager->prioritizeTextures();
954
981
955
    occluded.setOcclusion(IntRect(250, 200, 300, 100));
982
    occluded.setOcclusion(IntRect(250, 200, 300, 100));
956
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
983
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
957
    layer->update(m_queue, &occluded, m_stats);
984
    updateLayerOnMainThread(layer.get(), &occluded);
958
    EXPECT_EQ(36-2, layer->fakeLayerTextureUpdater()->prepareRectCount());
985
    EXPECT_EQ(36-2, layer->fakeLayerTextureUpdater()->prepareRectCount());
959
986
960
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
987
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
Lines 962-973 TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusion) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec30
962
    EXPECT_EQ(3 + 2, occluded.overdrawMetrics().tilesCulledForUpload());
989
    EXPECT_EQ(3 + 2, occluded.overdrawMetrics().tilesCulledForUpload());
963
990
964
    layer->fakeLayerTextureUpdater()->clearPrepareRectCount();
991
    layer->fakeLayerTextureUpdater()->clearPrepareRectCount();
965
    layer->setTexturePriorities(m_priorityCalculator);
992
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
966
    m_textureManager->prioritizeTextures();
967
993
968
    occluded.setOcclusion(IntRect(250, 250, 300, 100));
994
    occluded.setOcclusion(IntRect(250, 250, 300, 100));
969
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
995
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
970
    layer->update(m_queue, &occluded, m_stats);
996
    updateLayerOnMainThread(layer.get(), &occluded);
971
    EXPECT_EQ(36, layer->fakeLayerTextureUpdater()->prepareRectCount());
997
    EXPECT_EQ(36, layer->fakeLayerTextureUpdater()->prepareRectCount());
972
998
973
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
999
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
Lines 977-982 TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusion) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec31
977
1003
978
TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndVisiblityConstraints)
1004
TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndVisiblityConstraints)
979
{
1005
{
1006
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
980
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
1007
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
981
    TestCCOcclusionTracker occluded;
1008
    TestCCOcclusionTracker occluded;
982
1009
Lines 990-998 TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndVisiblityConstraints) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec32
990
    layer->setVisibleContentRect(IntRect(0, 0, 600, 360));
1017
    layer->setVisibleContentRect(IntRect(0, 0, 600, 360));
991
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1018
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
992
1019
993
    layer->setTexturePriorities(m_priorityCalculator);
1020
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
994
    m_textureManager->prioritizeTextures();
1021
    updateLayerOnMainThread(layer.get(), &occluded);
995
    layer->update(m_queue, &occluded, m_stats);
996
    EXPECT_EQ(24-3, layer->fakeLayerTextureUpdater()->prepareRectCount());
1022
    EXPECT_EQ(24-3, layer->fakeLayerTextureUpdater()->prepareRectCount());
997
1023
998
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1024
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
Lines 1006-1014 TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndVisiblityConstraints) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec33
1006
    layer->setDrawableContentRect(IntRect(0, 0, 600, 350));
1032
    layer->setDrawableContentRect(IntRect(0, 0, 600, 350));
1007
    layer->setVisibleContentRect(IntRect(0, 0, 600, 350));
1033
    layer->setVisibleContentRect(IntRect(0, 0, 600, 350));
1008
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1034
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1009
    layer->setTexturePriorities(m_priorityCalculator);
1035
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
1010
    m_textureManager->prioritizeTextures();
1036
    updateLayerOnMainThread(layer.get(), &occluded);
1011
    layer->update(m_queue, &occluded, m_stats);
1012
    EXPECT_EQ(24-6, layer->fakeLayerTextureUpdater()->prepareRectCount());
1037
    EXPECT_EQ(24-6, layer->fakeLayerTextureUpdater()->prepareRectCount());
1013
1038
1014
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1039
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
Lines 1022-1030 TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndVisiblityConstraints) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec34
1022
    layer->setDrawableContentRect(IntRect(0, 0, 600, 340));
1047
    layer->setDrawableContentRect(IntRect(0, 0, 600, 340));
1023
    layer->setVisibleContentRect(IntRect(0, 0, 600, 340));
1048
    layer->setVisibleContentRect(IntRect(0, 0, 600, 340));
1024
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1049
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1025
    layer->setTexturePriorities(m_priorityCalculator);
1050
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
1026
    m_textureManager->prioritizeTextures();
1051
    updateLayerOnMainThread(layer.get(), &occluded);
1027
    layer->update(m_queue, &occluded, m_stats);
1028
    EXPECT_EQ(24-6, layer->fakeLayerTextureUpdater()->prepareRectCount());
1052
    EXPECT_EQ(24-6, layer->fakeLayerTextureUpdater()->prepareRectCount());
1029
1053
1030
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1054
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
Lines 1035-1040 TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndVisiblityConstraints) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec35
1035
1059
1036
TEST_F(TiledLayerChromiumTest, tilesNotPaintedWithoutInvalidation)
1060
TEST_F(TiledLayerChromiumTest, tilesNotPaintedWithoutInvalidation)
1037
{
1061
{
1062
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
1038
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
1063
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
1039
    TestCCOcclusionTracker occluded;
1064
    TestCCOcclusionTracker occluded;
1040
1065
Lines 1046-1070 TEST_F(TiledLayerChromiumTest, tilesNotPaintedWithoutInvalidation) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec36
1046
    layer->setDrawableContentRect(IntRect(0, 0, 600, 600));
1071
    layer->setDrawableContentRect(IntRect(0, 0, 600, 600));
1047
    layer->setVisibleContentRect(IntRect(0, 0, 600, 600));
1072
    layer->setVisibleContentRect(IntRect(0, 0, 600, 600));
1048
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1073
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1049
    layer->setTexturePriorities(m_priorityCalculator);
1074
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
1050
    m_textureManager->prioritizeTextures();
1075
    updateLayerOnMainThread(layer.get(), &occluded);
1051
    layer->update(m_queue, &occluded, m_stats);
1052
    EXPECT_EQ(36-3, layer->fakeLayerTextureUpdater()->prepareRectCount());
1076
    EXPECT_EQ(36-3, layer->fakeLayerTextureUpdater()->prepareRectCount());
1053
    {
1077
    updateTextures();
1054
        DebugScopedSetImplThread implThread;
1055
        updateTextures();
1056
    }
1057
1078
1058
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1079
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1059
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 330000, 1);
1080
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 330000, 1);
1060
    EXPECT_EQ(3, occluded.overdrawMetrics().tilesCulledForUpload());
1081
    EXPECT_EQ(3, occluded.overdrawMetrics().tilesCulledForUpload());
1061
1082
1062
    layer->fakeLayerTextureUpdater()->clearPrepareRectCount();
1083
    layer->fakeLayerTextureUpdater()->clearPrepareRectCount();
1063
    layer->setTexturePriorities(m_priorityCalculator);
1084
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
1064
    m_textureManager->prioritizeTextures();
1065
1085
1066
    // Repaint without marking it dirty. The 3 culled tiles will be pre-painted now.
1086
    // Repaint without marking it dirty. The 3 culled tiles will be pre-painted now.
1067
    layer->update(m_queue, &occluded, m_stats);
1087
    updateLayerOnMainThread(layer.get(), &occluded);
1068
    EXPECT_EQ(3, layer->fakeLayerTextureUpdater()->prepareRectCount());
1088
    EXPECT_EQ(3, layer->fakeLayerTextureUpdater()->prepareRectCount());
1069
1089
1070
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1090
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
Lines 1074-1079 TEST_F(TiledLayerChromiumTest, tilesNotPaintedWithoutInvalidation) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec37
1074
1094
1075
TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndTransforms)
1095
TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndTransforms)
1076
{
1096
{
1097
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
1077
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
1098
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
1078
    TestCCOcclusionTracker occluded;
1099
    TestCCOcclusionTracker occluded;
1079
1100
Lines 1091-1099 TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndTransforms) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec38
1091
    layer->setDrawableContentRect(IntRect(IntPoint(), layer->contentBounds()));
1112
    layer->setDrawableContentRect(IntRect(IntPoint(), layer->contentBounds()));
1092
    layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds()));
1113
    layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds()));
1093
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1114
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1094
    layer->setTexturePriorities(m_priorityCalculator);
1115
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
1095
    m_textureManager->prioritizeTextures();
1116
    updateLayerOnMainThread(layer.get(), &occluded);
1096
    layer->update(m_queue, &occluded, m_stats);
1097
    EXPECT_EQ(36-3, layer->fakeLayerTextureUpdater()->prepareRectCount());
1117
    EXPECT_EQ(36-3, layer->fakeLayerTextureUpdater()->prepareRectCount());
1098
1118
1099
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1119
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
Lines 1103-1108 TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndTransforms) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec39
1103
1123
1104
TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndScaling)
1124
TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndScaling)
1105
{
1125
{
1126
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
1106
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
1127
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
1107
    TestCCOcclusionTracker occluded;
1128
    TestCCOcclusionTracker occluded;
1108
1129
Lines 1122-1130 TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndScaling) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec40
1122
    layer->setDrawableContentRect(IntRect(IntPoint(), layer->contentBounds()));
1143
    layer->setDrawableContentRect(IntRect(IntPoint(), layer->contentBounds()));
1123
    layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds()));
1144
    layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds()));
1124
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1145
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1125
    layer->setTexturePriorities(m_priorityCalculator);
1146
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
1126
    m_textureManager->prioritizeTextures();
1147
    updateLayerOnMainThread(layer.get(), &occluded);
1127
    layer->update(m_queue, &occluded, m_stats);
1128
    // The content is half the size of the layer (so the number of tiles is fewer).
1148
    // The content is half the size of the layer (so the number of tiles is fewer).
1129
    // In this case, the content is 300x300, and since the tile size is 100, the
1149
    // In this case, the content is 300x300, and since the tile size is 100, the
1130
    // number of tiles 3x3.
1150
    // number of tiles 3x3.
Lines 1143-1151 TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndScaling) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec41
1143
    layer->setDrawableContentRect(IntRect(IntPoint(), layer->contentBounds()));
1163
    layer->setDrawableContentRect(IntRect(IntPoint(), layer->contentBounds()));
1144
    layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds()));
1164
    layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds()));
1145
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1165
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1146
    layer->setTexturePriorities(m_priorityCalculator);
1166
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
1147
    m_textureManager->prioritizeTextures();
1167
    updateLayerOnMainThread(layer.get(), &occluded);
1148
    layer->update(m_queue, &occluded, m_stats);
1149
    EXPECT_EQ(9-1, layer->fakeLayerTextureUpdater()->prepareRectCount());
1168
    EXPECT_EQ(9-1, layer->fakeLayerTextureUpdater()->prepareRectCount());
1150
1169
1151
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1170
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
Lines 1164-1172 TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndScaling) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec42
1164
    layer->setDrawableContentRect(IntRect(IntPoint(), layer->contentBounds()));
1183
    layer->setDrawableContentRect(IntRect(IntPoint(), layer->contentBounds()));
1165
    layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds()));
1184
    layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds()));
1166
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1185
    layer->invalidateContentRect(IntRect(0, 0, 600, 600));
1167
    layer->setTexturePriorities(m_priorityCalculator);
1186
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
1168
    m_textureManager->prioritizeTextures();
1187
    updateLayerOnMainThread(layer.get(), &occluded);
1169
    layer->update(m_queue, &occluded, m_stats);
1170
    EXPECT_EQ(9-1, layer->fakeLayerTextureUpdater()->prepareRectCount());
1188
    EXPECT_EQ(9-1, layer->fakeLayerTextureUpdater()->prepareRectCount());
1171
1189
1172
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1190
    EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
Lines 1176-1184 TEST_F(TiledLayerChromiumTest, tilesPaintedWithOcclusionAndScaling) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec43
1176
1194
1177
TEST_F(TiledLayerChromiumTest, visibleContentOpaqueRegion)
1195
TEST_F(TiledLayerChromiumTest, visibleContentOpaqueRegion)
1178
{
1196
{
1197
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
1179
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
1198
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
1180
    TestCCOcclusionTracker occluded;
1199
    TestCCOcclusionTracker occluded;
1181
    DebugScopedSetImplThread implThread;
1182
1200
1183
    // The tile size is 100x100, so this invalidates and then paints two tiles in various ways.
1201
    // The tile size is 100x100, so this invalidates and then paints two tiles in various ways.
1184
1202
Lines 1193-1205 TEST_F(TiledLayerChromiumTest, visibleContentOpaqueRegion) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec44
1193
    layer->setVisibleContentRect(visibleBounds);
1211
    layer->setVisibleContentRect(visibleBounds);
1194
    layer->setDrawOpacity(1);
1212
    layer->setDrawOpacity(1);
1195
1213
1196
    layer->setTexturePriorities(m_priorityCalculator);
1214
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
1197
    m_textureManager->prioritizeTextures();
1198
1215
1199
    // If the layer doesn't paint opaque content, then the visibleContentOpaqueRegion should be empty.
1216
    // If the layer doesn't paint opaque content, then the visibleContentOpaqueRegion should be empty.
1200
    layer->fakeLayerTextureUpdater()->setOpaquePaintRect(IntRect());
1217
    layer->fakeLayerTextureUpdater()->setOpaquePaintRect(IntRect());
1201
    layer->invalidateContentRect(contentBounds);
1218
    layer->invalidateContentRect(contentBounds);
1202
    layer->update(m_queue, &occluded, m_stats);
1219
    updateLayerOnMainThread(layer.get(), &occluded);
1203
    opaqueContents = layer->visibleContentOpaqueRegion();
1220
    opaqueContents = layer->visibleContentOpaqueRegion();
1204
    EXPECT_TRUE(opaqueContents.isEmpty());
1221
    EXPECT_TRUE(opaqueContents.isEmpty());
1205
1222
Lines 1212-1218 TEST_F(TiledLayerChromiumTest, visibleContentOpaqueRegion) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec45
1212
    opaquePaintRect = IntRect(10, 10, 90, 190);
1229
    opaquePaintRect = IntRect(10, 10, 90, 190);
1213
    layer->fakeLayerTextureUpdater()->setOpaquePaintRect(opaquePaintRect);
1230
    layer->fakeLayerTextureUpdater()->setOpaquePaintRect(opaquePaintRect);
1214
    layer->invalidateContentRect(contentBounds);
1231
    layer->invalidateContentRect(contentBounds);
1215
    layer->update(m_queue, &occluded, m_stats);
1232
    updateLayerOnMainThread(layer.get(), &occluded);
1216
    updateTextures();
1233
    updateTextures();
1217
    opaqueContents = layer->visibleContentOpaqueRegion();
1234
    opaqueContents = layer->visibleContentOpaqueRegion();
1218
    EXPECT_EQ_RECT(intersection(opaquePaintRect, visibleBounds), opaqueContents.bounds());
1235
    EXPECT_EQ_RECT(intersection(opaquePaintRect, visibleBounds), opaqueContents.bounds());
Lines 1225-1231 TEST_F(TiledLayerChromiumTest, visibleContentOpaqueRegion) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec46
1225
1242
1226
    // If we paint again without invalidating, the same stuff should be opaque.
1243
    // If we paint again without invalidating, the same stuff should be opaque.
1227
    layer->fakeLayerTextureUpdater()->setOpaquePaintRect(IntRect());
1244
    layer->fakeLayerTextureUpdater()->setOpaquePaintRect(IntRect());
1228
    layer->update(m_queue, &occluded, m_stats);
1245
    updateLayerOnMainThread(layer.get(), &occluded);
1229
    updateTextures();
1246
    updateTextures();
1230
    opaqueContents = layer->visibleContentOpaqueRegion();
1247
    opaqueContents = layer->visibleContentOpaqueRegion();
1231
    EXPECT_EQ_RECT(intersection(opaquePaintRect, visibleBounds), opaqueContents.bounds());
1248
    EXPECT_EQ_RECT(intersection(opaquePaintRect, visibleBounds), opaqueContents.bounds());
Lines 1240-1246 TEST_F(TiledLayerChromiumTest, visibleContentOpaqueRegion) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec47
1240
    // not be affected.
1257
    // not be affected.
1241
    layer->fakeLayerTextureUpdater()->setOpaquePaintRect(IntRect());
1258
    layer->fakeLayerTextureUpdater()->setOpaquePaintRect(IntRect());
1242
    layer->invalidateContentRect(IntRect(0, 0, 1, 1));
1259
    layer->invalidateContentRect(IntRect(0, 0, 1, 1));
1243
    layer->update(m_queue, &occluded, m_stats);
1260
    updateLayerOnMainThread(layer.get(), &occluded);
1244
    updateTextures();
1261
    updateTextures();
1245
    opaqueContents = layer->visibleContentOpaqueRegion();
1262
    opaqueContents = layer->visibleContentOpaqueRegion();
1246
    EXPECT_EQ_RECT(intersection(opaquePaintRect, visibleBounds), opaqueContents.bounds());
1263
    EXPECT_EQ_RECT(intersection(opaquePaintRect, visibleBounds), opaqueContents.bounds());
Lines 1255-1261 TEST_F(TiledLayerChromiumTest, visibleContentOpaqueRegion) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec48
1255
    // not be affected.
1272
    // not be affected.
1256
    layer->fakeLayerTextureUpdater()->setOpaquePaintRect(IntRect());
1273
    layer->fakeLayerTextureUpdater()->setOpaquePaintRect(IntRect());
1257
    layer->invalidateContentRect(IntRect(10, 10, 1, 1));
1274
    layer->invalidateContentRect(IntRect(10, 10, 1, 1));
1258
    layer->update(m_queue, &occluded, m_stats);
1275
    updateLayerOnMainThread(layer.get(), &occluded);
1259
    updateTextures();
1276
    updateTextures();
1260
    opaqueContents = layer->visibleContentOpaqueRegion();
1277
    opaqueContents = layer->visibleContentOpaqueRegion();
1261
    EXPECT_EQ_RECT(intersection(IntRect(10, 100, 90, 100), visibleBounds), opaqueContents.bounds());
1278
    EXPECT_EQ_RECT(intersection(IntRect(10, 100, 90, 100), visibleBounds), opaqueContents.bounds());
Lines 1269-1277 TEST_F(TiledLayerChromiumTest, visibleContentOpaqueRegion) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec49
1269
1286
1270
TEST_F(TiledLayerChromiumTest, pixelsPaintedMetrics)
1287
TEST_F(TiledLayerChromiumTest, pixelsPaintedMetrics)
1271
{
1288
{
1289
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
1272
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
1290
    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(m_textureManager.get()));
1273
    TestCCOcclusionTracker occluded;
1291
    TestCCOcclusionTracker occluded;
1274
    DebugScopedSetImplThread implThread;
1275
1292
1276
    // The tile size is 100x100, so this invalidates and then paints two tiles in various ways.
1293
    // The tile size is 100x100, so this invalidates and then paints two tiles in various ways.
1277
1294
Lines 1286-1298 TEST_F(TiledLayerChromiumTest, pixelsPaintedMetrics) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec50
1286
    layer->setVisibleContentRect(visibleBounds);
1303
    layer->setVisibleContentRect(visibleBounds);
1287
    layer->setDrawOpacity(1);
1304
    layer->setDrawOpacity(1);
1288
1305
1289
    layer->setTexturePriorities(m_priorityCalculator);
1306
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
1290
    m_textureManager->prioritizeTextures();
1291
1307
1292
    // Invalidates and paints the whole layer.
1308
    // Invalidates and paints the whole layer.
1293
    layer->fakeLayerTextureUpdater()->setOpaquePaintRect(IntRect());
1309
    layer->fakeLayerTextureUpdater()->setOpaquePaintRect(IntRect());
1294
    layer->invalidateContentRect(contentBounds);
1310
    layer->invalidateContentRect(contentBounds);
1295
    layer->update(m_queue, &occluded, m_stats);
1311
    updateLayerOnMainThread(layer.get(), &occluded);
1296
    updateTextures();
1312
    updateTextures();
1297
    opaqueContents = layer->visibleContentOpaqueRegion();
1313
    opaqueContents = layer->visibleContentOpaqueRegion();
1298
    EXPECT_TRUE(opaqueContents.isEmpty());
1314
    EXPECT_TRUE(opaqueContents.isEmpty());
Lines 1307-1313 TEST_F(TiledLayerChromiumTest, pixelsPaintedMetrics) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec51
1307
    layer->fakeLayerTextureUpdater()->setOpaquePaintRect(IntRect());
1323
    layer->fakeLayerTextureUpdater()->setOpaquePaintRect(IntRect());
1308
    layer->invalidateContentRect(IntRect(0, 0, 1, 1));
1324
    layer->invalidateContentRect(IntRect(0, 0, 1, 1));
1309
    layer->invalidateContentRect(IntRect(50, 200, 10, 10));
1325
    layer->invalidateContentRect(IntRect(50, 200, 10, 10));
1310
    layer->update(m_queue, &occluded, m_stats);
1326
    updateLayerOnMainThread(layer.get(), &occluded);
1311
    updateTextures();
1327
    updateTextures();
1312
    opaqueContents = layer->visibleContentOpaqueRegion();
1328
    opaqueContents = layer->visibleContentOpaqueRegion();
1313
    EXPECT_TRUE(opaqueContents.isEmpty());
1329
    EXPECT_TRUE(opaqueContents.isEmpty());
Lines 1322-1330 TEST_F(TiledLayerChromiumTest, pixelsPaintedMetrics) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec52
1322
1338
1323
TEST_F(TiledLayerChromiumTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated)
1339
TEST_F(TiledLayerChromiumTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated)
1324
{
1340
{
1325
    // Initialize without threading support.
1326
    WebKit::WebCompositor::initialize(0);
1327
1328
    // Tile size is 100x100.
1341
    // Tile size is 100x100.
1329
    IntRect rootRect(0, 0, 300, 200);
1342
    IntRect rootRect(0, 0, 300, 200);
1330
    IntRect childRect(0, 0, 300, 100);
1343
    IntRect childRect(0, 0, 300, 100);
Lines 1335-1379 TEST_F(TiledLayerChromiumTest, dontAllocateContentsWhenTargetSurfaceCantBeAlloca a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec53
1335
    OwnPtr<CCLayerTreeHost> ccLayerTreeHost = CCLayerTreeHost::create(&fakeCCLayerTreeHostClient, settings);
1348
    OwnPtr<CCLayerTreeHost> ccLayerTreeHost = CCLayerTreeHost::create(&fakeCCLayerTreeHostClient, settings);
1336
    ASSERT_TRUE(ccLayerTreeHost->initializeRendererIfNeeded());
1349
    ASSERT_TRUE(ccLayerTreeHost->initializeRendererIfNeeded());
1337
1350
1338
    RefPtr<FakeTiledLayerChromium> root = adoptRef(new FakeTiledLayerChromium(ccLayerTreeHost->contentsTextureManager()));
1339
    RefPtr<LayerChromium> surface = LayerChromium::create();
1340
    RefPtr<FakeTiledLayerChromium> child = adoptRef(new FakeTiledLayerChromium(ccLayerTreeHost->contentsTextureManager()));
1341
    RefPtr<FakeTiledLayerChromium> child2 = adoptRef(new FakeTiledLayerChromium(ccLayerTreeHost->contentsTextureManager()));
1342
1343
    root->setBounds(rootRect.size());
1344
    root->setAnchorPoint(FloatPoint());
1345
    root->setDrawableContentRect(rootRect);
1346
    root->setVisibleContentRect(rootRect);
1347
    root->addChild(surface);
1348
1349
    surface->setForceRenderSurface(true);
1350
    surface->setAnchorPoint(FloatPoint());
1351
    surface->setOpacity(0.5);
1352
    surface->addChild(child);
1353
    surface->addChild(child2);
1354
1355
    child->setBounds(childRect.size());
1356
    child->setAnchorPoint(FloatPoint());
1357
    child->setPosition(childRect.location());
1358
    child->setVisibleContentRect(childRect);
1359
    child->setDrawableContentRect(rootRect);
1360
1361
    child2->setBounds(child2Rect.size());
1362
    child2->setAnchorPoint(FloatPoint());
1363
    child2->setPosition(child2Rect.location());
1364
    child2->setVisibleContentRect(child2Rect);
1365
    child2->setDrawableContentRect(rootRect);
1366
1367
    ccLayerTreeHost->setRootLayer(root);
1368
    ccLayerTreeHost->setViewportSize(rootRect.size(), rootRect.size());
1369
1370
    // With a huge memory limit, all layers should update and push their textures.
1371
    root->invalidateContentRect(rootRect);
1372
    child->invalidateContentRect(childRect);
1373
    child2->invalidateContentRect(child2Rect);
1374
    ccLayerTreeHost->updateLayers(m_queue, std::numeric_limits<size_t>::max());
1375
    {
1351
    {
1376
        DebugScopedSetImplThread implThread;
1352
        DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
1353
        RefPtr<FakeTiledLayerChromium> root = adoptRef(new FakeTiledLayerChromium(ccLayerTreeHost->contentsTextureManager()));
1354
        RefPtr<LayerChromium> surface = LayerChromium::create();
1355
        RefPtr<FakeTiledLayerChromium> child = adoptRef(new FakeTiledLayerChromium(ccLayerTreeHost->contentsTextureManager()));
1356
        RefPtr<FakeTiledLayerChromium> child2 = adoptRef(new FakeTiledLayerChromium(ccLayerTreeHost->contentsTextureManager()));
1357
1358
        {
1359
            DebugScopedSetMainThread mainThread;
1360
1361
            root->setBounds(rootRect.size());
1362
            root->setAnchorPoint(FloatPoint());
1363
            root->setDrawableContentRect(rootRect);
1364
            root->setVisibleContentRect(rootRect);
1365
            root->addChild(surface);
1366
1367
            surface->setForceRenderSurface(true);
1368
            surface->setAnchorPoint(FloatPoint());
1369
            surface->setOpacity(0.5);
1370
            surface->addChild(child);
1371
            surface->addChild(child2);
1372
1373
            child->setBounds(childRect.size());
1374
            child->setAnchorPoint(FloatPoint());
1375
            child->setPosition(childRect.location());
1376
            child->setVisibleContentRect(childRect);
1377
            child->setDrawableContentRect(rootRect);
1378
1379
            child2->setBounds(child2Rect.size());
1380
            child2->setAnchorPoint(FloatPoint());
1381
            child2->setPosition(child2Rect.location());
1382
            child2->setVisibleContentRect(child2Rect);
1383
            child2->setDrawableContentRect(rootRect);
1384
1385
            ccLayerTreeHost->setRootLayer(root);
1386
            ccLayerTreeHost->setViewportSize(rootRect.size(), rootRect.size());
1387
1388
            // With a huge memory limit, all layers should update and push their textures.
1389
            root->invalidateContentRect(rootRect);
1390
            child->invalidateContentRect(childRect);
1391
            child2->invalidateContentRect(child2Rect);
1392
            ccLayerTreeHost->updateLayers(m_queue, std::numeric_limits<size_t>::max());
1393
        }
1394
1377
        updateTextures(1000);
1395
        updateTextures(1000);
1378
        EXPECT_EQ(6, root->fakeLayerTextureUpdater()->updateCount());
1396
        EXPECT_EQ(6, root->fakeLayerTextureUpdater()->updateCount());
1379
        EXPECT_EQ(3, child->fakeLayerTextureUpdater()->updateCount());
1397
        EXPECT_EQ(3, child->fakeLayerTextureUpdater()->updateCount());
Lines 1384-1414 TEST_F(TiledLayerChromiumTest, dontAllocateContentsWhenTargetSurfaceCantBeAlloca a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec54
1384
        child->fakeLayerTextureUpdater()->clearUpdateCount();
1402
        child->fakeLayerTextureUpdater()->clearUpdateCount();
1385
        child2->fakeLayerTextureUpdater()->clearUpdateCount();
1403
        child2->fakeLayerTextureUpdater()->clearUpdateCount();
1386
1404
1387
        OwnPtr<FakeCCTiledLayerImpl> rootImpl(adoptPtr(new FakeCCTiledLayerImpl(root->id())));
1405
        {
1388
        OwnPtr<FakeCCTiledLayerImpl> childImpl(adoptPtr(new FakeCCTiledLayerImpl(child->id())));
1406
            OwnPtr<FakeCCTiledLayerImpl> rootImpl(adoptPtr(new FakeCCTiledLayerImpl(root->id())));
1389
        OwnPtr<FakeCCTiledLayerImpl> child2Impl(adoptPtr(new FakeCCTiledLayerImpl(child2->id())));
1407
            OwnPtr<FakeCCTiledLayerImpl> childImpl(adoptPtr(new FakeCCTiledLayerImpl(child->id())));
1390
        root->pushPropertiesTo(rootImpl.get());
1408
            OwnPtr<FakeCCTiledLayerImpl> child2Impl(adoptPtr(new FakeCCTiledLayerImpl(child2->id())));
1391
        child->pushPropertiesTo(childImpl.get());
1409
            root->pushPropertiesTo(rootImpl.get());
1392
        child2->pushPropertiesTo(child2Impl.get());
1410
            child->pushPropertiesTo(childImpl.get());
1393
1411
            child2->pushPropertiesTo(child2Impl.get());
1394
        for (unsigned i = 0; i < 3; ++i) {
1412
1395
            for (unsigned j = 0; j < 2; ++j)
1413
            for (unsigned i = 0; i < 3; ++i) {
1396
                EXPECT_TRUE(rootImpl->hasTextureIdForTileAt(i, j));
1414
                for (unsigned j = 0; j < 2; ++j)
1397
            EXPECT_TRUE(childImpl->hasTextureIdForTileAt(i, 0));
1415
                    EXPECT_TRUE(rootImpl->hasTextureIdForTileAt(i, j));
1398
            EXPECT_TRUE(child2Impl->hasTextureIdForTileAt(i, 0));
1416
                EXPECT_TRUE(childImpl->hasTextureIdForTileAt(i, 0));
1417
                EXPECT_TRUE(child2Impl->hasTextureIdForTileAt(i, 0));
1418
            }
1399
        }
1419
        }
1400
    }
1420
        ccLayerTreeHost->commitComplete();
1401
    ccLayerTreeHost->commitComplete();
1421
1402
1422
        // With a memory limit that includes only the root layer (3x2 tiles) and half the surface that
1403
    // With a memory limit that includes only the root layer (3x2 tiles) and half the surface that
1423
        // the child layers draw into, the child layers will not be allocated. If the surface isn't
1404
    // the child layers draw into, the child layers will not be allocated. If the surface isn't
1424
        // accounted for, then one of the children would fit within the memory limit.
1405
    // accounted for, then one of the children would fit within the memory limit.
1425
        {
1406
    root->invalidateContentRect(rootRect);
1426
            DebugScopedSetMainThread mainThread;
1407
    child->invalidateContentRect(childRect);
1427
            root->invalidateContentRect(rootRect);
1408
    child2->invalidateContentRect(child2Rect);
1428
            child->invalidateContentRect(childRect);
1409
    ccLayerTreeHost->updateLayers(m_queue, (3 * 2 + 3 * 1) * (100 * 100) * 4);
1429
            child2->invalidateContentRect(child2Rect);
1410
    {
1430
            ccLayerTreeHost->updateLayers(m_queue, (3 * 2 + 3 * 1) * (100 * 100) * 4);
1411
        DebugScopedSetImplThread implThread;
1431
        }
1432
1412
        updateTextures(1000);
1433
        updateTextures(1000);
1413
        EXPECT_EQ(6, root->fakeLayerTextureUpdater()->updateCount());
1434
        EXPECT_EQ(6, root->fakeLayerTextureUpdater()->updateCount());
1414
        EXPECT_EQ(0, child->fakeLayerTextureUpdater()->updateCount());
1435
        EXPECT_EQ(0, child->fakeLayerTextureUpdater()->updateCount());
Lines 1419-1483 TEST_F(TiledLayerChromiumTest, dontAllocateContentsWhenTargetSurfaceCantBeAlloca a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec55
1419
        child->fakeLayerTextureUpdater()->clearUpdateCount();
1440
        child->fakeLayerTextureUpdater()->clearUpdateCount();
1420
        child2->fakeLayerTextureUpdater()->clearUpdateCount();
1441
        child2->fakeLayerTextureUpdater()->clearUpdateCount();
1421
1442
1422
        OwnPtr<FakeCCTiledLayerImpl> rootImpl(adoptPtr(new FakeCCTiledLayerImpl(root->id())));
1443
        {
1423
        OwnPtr<FakeCCTiledLayerImpl> childImpl(adoptPtr(new FakeCCTiledLayerImpl(child->id())));
1444
            OwnPtr<FakeCCTiledLayerImpl> rootImpl(adoptPtr(new FakeCCTiledLayerImpl(root->id())));
1424
        OwnPtr<FakeCCTiledLayerImpl> child2Impl(adoptPtr(new FakeCCTiledLayerImpl(child2->id())));
1445
            OwnPtr<FakeCCTiledLayerImpl> childImpl(adoptPtr(new FakeCCTiledLayerImpl(child->id())));
1425
        root->pushPropertiesTo(rootImpl.get());
1446
            OwnPtr<FakeCCTiledLayerImpl> child2Impl(adoptPtr(new FakeCCTiledLayerImpl(child2->id())));
1426
        child->pushPropertiesTo(childImpl.get());
1447
            root->pushPropertiesTo(rootImpl.get());
1427
        child2->pushPropertiesTo(child2Impl.get());
1448
            child->pushPropertiesTo(childImpl.get());
1428
1449
            child2->pushPropertiesTo(child2Impl.get());
1429
        for (unsigned i = 0; i < 3; ++i) {
1450
1430
            for (unsigned j = 0; j < 2; ++j)
1451
            for (unsigned i = 0; i < 3; ++i) {
1431
                EXPECT_TRUE(rootImpl->hasTextureIdForTileAt(i, j));
1452
                for (unsigned j = 0; j < 2; ++j)
1432
            EXPECT_FALSE(childImpl->hasTextureIdForTileAt(i, 0));
1453
                    EXPECT_TRUE(rootImpl->hasTextureIdForTileAt(i, j));
1433
            EXPECT_FALSE(child2Impl->hasTextureIdForTileAt(i, 0));
1454
                EXPECT_FALSE(childImpl->hasTextureIdForTileAt(i, 0));
1455
                EXPECT_FALSE(child2Impl->hasTextureIdForTileAt(i, 0));
1456
            }
1434
        }
1457
        }
1435
    }
1458
        ccLayerTreeHost->commitComplete();
1436
    ccLayerTreeHost->commitComplete();
1459
1437
1460
        // With a memory limit that includes only half the root layer, no contents will be
1438
    // With a memory limit that includes only half the root layer, no contents will be
1461
        // allocated. If render surface memory wasn't accounted for, there is enough space
1439
    // allocated. If render surface memory wasn't accounted for, there is enough space
1462
        // for one of the children layers, but they draw into a surface that can't be
1440
    // for one of the children layers, but they draw into a surface that can't be
1463
        // allocated.
1441
    // allocated.
1464
        {
1442
    root->invalidateContentRect(rootRect);
1465
            DebugScopedSetMainThread mainThread;
1443
    child->invalidateContentRect(childRect);
1466
            root->invalidateContentRect(rootRect);
1444
    child2->invalidateContentRect(child2Rect);
1467
            child->invalidateContentRect(childRect);
1445
    ccLayerTreeHost->updateLayers(m_queue, (3 * 1) * (100 * 100) * 4);
1468
            child2->invalidateContentRect(child2Rect);
1446
    {
1469
            ccLayerTreeHost->updateLayers(m_queue, (3 * 1) * (100 * 100) * 4);
1447
        DebugScopedSetImplThread implThread;
1448
        updateTextures(1000);
1449
        EXPECT_EQ(0, root->fakeLayerTextureUpdater()->updateCount());
1450
        EXPECT_EQ(0, child->fakeLayerTextureUpdater()->updateCount());
1451
        EXPECT_EQ(0, child2->fakeLayerTextureUpdater()->updateCount());
1452
        EXPECT_FALSE(m_queue.hasMoreUpdates());
1453
1454
        root->fakeLayerTextureUpdater()->clearUpdateCount();
1455
        child->fakeLayerTextureUpdater()->clearUpdateCount();
1456
        child2->fakeLayerTextureUpdater()->clearUpdateCount();
1457
1458
        OwnPtr<FakeCCTiledLayerImpl> rootImpl(adoptPtr(new FakeCCTiledLayerImpl(root->id())));
1459
        OwnPtr<FakeCCTiledLayerImpl> childImpl(adoptPtr(new FakeCCTiledLayerImpl(child->id())));
1460
        OwnPtr<FakeCCTiledLayerImpl> child2Impl(adoptPtr(new FakeCCTiledLayerImpl(child2->id())));
1461
        root->pushPropertiesTo(rootImpl.get());
1462
        child->pushPropertiesTo(childImpl.get());
1463
        child2->pushPropertiesTo(child2Impl.get());
1464
1465
        for (unsigned i = 0; i < 3; ++i) {
1466
            for (unsigned j = 0; j < 2; ++j)
1467
                EXPECT_FALSE(rootImpl->hasTextureIdForTileAt(i, j));
1468
            EXPECT_FALSE(childImpl->hasTextureIdForTileAt(i, 0));
1469
            EXPECT_FALSE(child2Impl->hasTextureIdForTileAt(i, 0));
1470
        }
1470
        }
1471
    }
1471
        {
1472
    ccLayerTreeHost->commitComplete();
1472
            updateTextures(1000);
1473
1473
            EXPECT_EQ(0, root->fakeLayerTextureUpdater()->updateCount());
1474
    {
1474
            EXPECT_EQ(0, child->fakeLayerTextureUpdater()->updateCount());
1475
        DebugScopedSetImplThread implThread;
1475
            EXPECT_EQ(0, child2->fakeLayerTextureUpdater()->updateCount());
1476
            EXPECT_FALSE(m_queue.hasMoreUpdates());
1477
1478
            root->fakeLayerTextureUpdater()->clearUpdateCount();
1479
            child->fakeLayerTextureUpdater()->clearUpdateCount();
1480
            child2->fakeLayerTextureUpdater()->clearUpdateCount();
1481
1482
            OwnPtr<FakeCCTiledLayerImpl> rootImpl(adoptPtr(new FakeCCTiledLayerImpl(root->id())));
1483
            OwnPtr<FakeCCTiledLayerImpl> childImpl(adoptPtr(new FakeCCTiledLayerImpl(child->id())));
1484
            OwnPtr<FakeCCTiledLayerImpl> child2Impl(adoptPtr(new FakeCCTiledLayerImpl(child2->id())));
1485
            root->pushPropertiesTo(rootImpl.get());
1486
            child->pushPropertiesTo(childImpl.get());
1487
            child2->pushPropertiesTo(child2Impl.get());
1488
1489
            for (unsigned i = 0; i < 3; ++i) {
1490
                for (unsigned j = 0; j < 2; ++j)
1491
                    EXPECT_FALSE(rootImpl->hasTextureIdForTileAt(i, j));
1492
                EXPECT_FALSE(childImpl->hasTextureIdForTileAt(i, 0));
1493
                EXPECT_FALSE(child2Impl->hasTextureIdForTileAt(i, 0));
1494
            }
1495
        }
1496
        ccLayerTreeHost->commitComplete();
1476
        ccLayerTreeHost->contentsTextureManager()->clearAllMemory(m_resourceProvider.get());
1497
        ccLayerTreeHost->contentsTextureManager()->clearAllMemory(m_resourceProvider.get());
1477
    }
1498
    }
1478
    ccLayerTreeHost->setRootLayer(0);
1499
    ccLayerTreeHost->setRootLayer(0);
1479
    ccLayerTreeHost.clear();
1500
    ccLayerTreeHost.clear();
1480
    WebKit::WebCompositor::shutdown();
1481
}
1501
}
1482
1502
1483
class TrackingLayerPainter : public LayerPainterChromium {
1503
class TrackingLayerPainter : public LayerPainterChromium {
Lines 1521-1526 private: a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec56
1521
1541
1522
TEST_F(TiledLayerChromiumTest, nonIntegerContentsScaleIsNotDistortedDuringPaint)
1542
TEST_F(TiledLayerChromiumTest, nonIntegerContentsScaleIsNotDistortedDuringPaint)
1523
{
1543
{
1544
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
1524
    RefPtr<UpdateTrackingTiledLayerChromium> layer = adoptRef(new UpdateTrackingTiledLayerChromium(m_textureManager.get()));
1545
    RefPtr<UpdateTrackingTiledLayerChromium> layer = adoptRef(new UpdateTrackingTiledLayerChromium(m_textureManager.get()));
1525
1546
1526
    IntRect layerRect(0, 0, 30, 31);
1547
    IntRect layerRect(0, 0, 30, 31);
Lines 1533-1561 TEST_F(TiledLayerChromiumTest, nonIntegerContentsScaleIsNotDistortedDuringPaint) a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec57
1533
    layer->setVisibleContentRect(contentRect);
1554
    layer->setVisibleContentRect(contentRect);
1534
    layer->setDrawableContentRect(contentRect);
1555
    layer->setDrawableContentRect(contentRect);
1535
1556
1536
    layer->setTexturePriorities(m_priorityCalculator);
1557
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
1537
    m_textureManager->prioritizeTextures();
1538
1558
1539
    // Update the whole tile.
1559
    // Update the whole tile.
1540
    layer->update(m_queue, 0, m_stats);
1560
    updateLayerOnMainThread(layer.get(), 0);
1541
    layer->trackingLayerPainter()->resetPaintedRect();
1561
    layer->trackingLayerPainter()->resetPaintedRect();
1542
1562
1543
    EXPECT_INT_RECT_EQ(IntRect(), layer->trackingLayerPainter()->paintedRect());
1563
    EXPECT_INT_RECT_EQ(IntRect(), layer->trackingLayerPainter()->paintedRect());
1544
1564
1545
    {
1565
    updateTextures();
1546
        DebugScopedSetImplThread implThread;
1547
        updateTextures();
1548
    }
1549
1566
1550
    // Invalidate the entire layer in content space. When painting, the rect given to webkit should match the layer's bounds.
1567
    // Invalidate the entire layer in content space. When painting, the rect given to webkit should match the layer's bounds.
1551
    layer->invalidateContentRect(contentRect);
1568
    layer->invalidateContentRect(contentRect);
1552
    layer->update(m_queue, 0, m_stats);
1569
    updateLayerOnMainThread(layer.get(), 0);
1553
1570
1554
    EXPECT_INT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect());
1571
    EXPECT_INT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect());
1555
}
1572
}
1556
1573
1557
TEST_F(TiledLayerChromiumTest, nonIntegerContentsScaleIsNotDistortedDuringInvalidation)
1574
TEST_F(TiledLayerChromiumTest, nonIntegerContentsScaleIsNotDistortedDuringInvalidation)
1558
{
1575
{
1576
    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
1559
    RefPtr<UpdateTrackingTiledLayerChromium> layer = adoptRef(new UpdateTrackingTiledLayerChromium(m_textureManager.get()));
1577
    RefPtr<UpdateTrackingTiledLayerChromium> layer = adoptRef(new UpdateTrackingTiledLayerChromium(m_textureManager.get()));
1560
1578
1561
    IntRect layerRect(0, 0, 30, 31);
1579
    IntRect layerRect(0, 0, 30, 31);
Lines 1567-1589 TEST_F(TiledLayerChromiumTest, nonIntegerContentsScaleIsNotDistortedDuringInvali a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp_sec58
1567
    layer->setVisibleContentRect(contentRect);
1585
    layer->setVisibleContentRect(contentRect);
1568
    layer->setDrawableContentRect(contentRect);
1586
    layer->setDrawableContentRect(contentRect);
1569
1587
1570
    layer->setTexturePriorities(m_priorityCalculator);
1588
    setTexturePrioritiesAndPrioritizeTexturesOnMainThread(layer.get());
1571
    m_textureManager->prioritizeTextures();
1572
1589
1573
    // Update the whole tile.
1590
    // Update the whole tile.
1574
    layer->update(m_queue, 0, m_stats);
1591
    updateLayerOnMainThread(layer.get(), 0);
1575
    layer->trackingLayerPainter()->resetPaintedRect();
1592
    layer->trackingLayerPainter()->resetPaintedRect();
1576
1593
1577
    EXPECT_INT_RECT_EQ(IntRect(), layer->trackingLayerPainter()->paintedRect());
1594
    EXPECT_INT_RECT_EQ(IntRect(), layer->trackingLayerPainter()->paintedRect());
1578
1595
1579
    {
1596
    updateTextures();
1580
        DebugScopedSetImplThread implThread;
1581
        updateTextures();
1582
    }
1583
1597
1584
    // Invalidate the entire layer in layer space. When painting, the rect given to webkit should match the layer's bounds.
1598
    // Invalidate the entire layer in layer space. When painting, the rect given to webkit should match the layer's bounds.
1585
    layer->setNeedsDisplayRect(layerRect);
1599
    layer->setNeedsDisplayRect(layerRect);
1586
    layer->update(m_queue, 0, m_stats);
1600
    updateLayerOnMainThread(layer.get(), 0);
1587
1601
1588
    EXPECT_INT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect());
1602
    EXPECT_INT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect());
1589
}
1603
}

Return to Bug 95057