Changeset 128253 in webkit


Ignore:
Timestamp:
Sep 11, 2012 6:35:47 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[chromium] Make prioritized texture manager not touch backings array on the main thread
https://bugs.webkit.org/show_bug.cgi?id=96114

Patch by Christopher Cameron <ccameron@chromium.org> on 2012-09-11
Reviewed by James Robinson.

Take a snapshot of the textures' priorities from the main thread,
and save it in their backings for access by the impl thread.
Update functions that access the sorted backings array to use the
snapshotted values instead of the values that the main thread may
have computed for the next frame.

Make the main thread not touch the m_backings array. Split
prioritizeTextures into a updateBackingsPriorities function.
In places where the main thread would have touched m_backings,
set a flag specifying that m_backings needs to be re-sorted
before any function that requires it be sorted by priority be
executed.

Update the two functions that require sorted order (acquireBacking
and reduceMemory) to sort the backings array (if needed) before
traversing it.

Updated tests to set correct thread during asserts. Add a test to
verify that requestLate is correctly incorporated into the backing
sorting.

Source/WebCore:

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

(WebCore::CCPrioritizedTextureManager::CCPrioritizedTextureManager):
(WebCore::CCPrioritizedTextureManager::prioritizeTextures):
(WebCore):
(WebCore::CCPrioritizedTextureManager::prioritizeBackings):
(WebCore::CCPrioritizedTextureManager::requestLate):
(WebCore::CCPrioritizedTextureManager::acquireBackingTextureIfNeeded):
(WebCore::CCPrioritizedTextureManager::reduceMemory):
(WebCore::CCPrioritizedTextureManager::returnBackingTexture):
(WebCore::CCPrioritizedTextureManager::destroyBacking):
(WebCore::CCPrioritizedTextureManager::assertInvariants):

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

(CCPrioritizedTextureManager):

Source/WebKit/chromium:

  • tests/CCPrioritizedTextureTest.cpp:

(WTF::CCPrioritizedTextureTest::validateTexture):

Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r128251 r128253  
     12012-09-11  Christopher Cameron  <ccameron@chromium.org>
     2
     3        [chromium] Make prioritized texture manager not touch backings array on the main thread
     4        https://bugs.webkit.org/show_bug.cgi?id=96114
     5
     6        Reviewed by James Robinson.
     7
     8        Take a snapshot of the textures' priorities from the main thread,
     9        and save it in their backings for access by the impl thread.
     10        Update functions that access the sorted backings array to use the
     11        snapshotted values instead of the values that the main thread may
     12        have computed for the next frame.
     13
     14        Make the main thread not touch the m_backings array.  Split
     15        prioritizeTextures into a updateBackingsPriorities function.
     16        In places where the main thread would have touched m_backings,
     17        set a flag specifying that m_backings needs to be re-sorted
     18        before any function that requires it be sorted by priority be
     19        executed.
     20
     21        Update the two functions that require sorted order (acquireBacking
     22        and reduceMemory) to sort the backings array (if needed) before
     23        traversing it.
     24
     25        Updated tests to set correct thread during asserts. Add a test to
     26        verify that requestLate is correctly incorporated into the backing
     27        sorting.
     28
     29        * platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp:
     30        (WebCore::CCPrioritizedTextureManager::CCPrioritizedTextureManager):
     31        (WebCore::CCPrioritizedTextureManager::prioritizeTextures):
     32        (WebCore):
     33        (WebCore::CCPrioritizedTextureManager::prioritizeBackings):
     34        (WebCore::CCPrioritizedTextureManager::requestLate):
     35        (WebCore::CCPrioritizedTextureManager::acquireBackingTextureIfNeeded):
     36        (WebCore::CCPrioritizedTextureManager::reduceMemory):
     37        (WebCore::CCPrioritizedTextureManager::returnBackingTexture):
     38        (WebCore::CCPrioritizedTextureManager::destroyBacking):
     39        (WebCore::CCPrioritizedTextureManager::assertInvariants):
     40        * platform/graphics/chromium/cc/CCPrioritizedTextureManager.h:
     41        (CCPrioritizedTextureManager):
     42
    1432012-09-11  Adam Barth  <abarth@webkit.org>
    244
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTexture.cpp

    r126473 r128253  
    2929#include "CCPrioritizedTextureManager.h"
    3030#include "CCPriorityCalculator.h"
     31#include "CCProxy.h"
    3132#include <algorithm>
    3233
     
    140141}
    141142
     143CCPrioritizedTexture::Backing::Backing(unsigned id, IntSize size, GC3Denum format)
     144    : CCTexture(id, size, format)
     145    , m_owner(0)
     146    , m_priorityAtLastPriorityUpdate(CCPriorityCalculator::lowestPriority())
     147    , m_ownerExistedAtLastPriorityUpdate(false)
     148    , m_wasAbovePriorityCutoffAtLastPriorityUpdate(false)
     149{
     150}
     151
     152CCPrioritizedTexture::Backing::~Backing()
     153{
     154    ASSERT(!m_owner);
     155}
     156
     157void CCPrioritizedTexture::Backing::updatePriority()
     158{
     159    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
     160    if (m_owner) {
     161        m_ownerExistedAtLastPriorityUpdate = true;
     162        m_priorityAtLastPriorityUpdate = m_owner->requestPriority();
     163        m_wasAbovePriorityCutoffAtLastPriorityUpdate = m_owner->isAbovePriorityCutoff();
     164    } else {
     165        m_ownerExistedAtLastPriorityUpdate = false;
     166        m_priorityAtLastPriorityUpdate = CCPriorityCalculator::lowestPriority();
     167        m_wasAbovePriorityCutoffAtLastPriorityUpdate = false;
     168    }
     169}
     170
    142171} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTexture.h

    r125932 r128253  
    101101private:
    102102    friend class CCPrioritizedTextureManager;
     103    friend class CCPrioritizedTextureTest;
    103104
    104105    class Backing : public CCTexture {
    105106        WTF_MAKE_NONCOPYABLE(Backing);
    106107    public:
    107         Backing(unsigned id, IntSize size, GC3Denum format)
    108             : CCTexture(id, size, format), m_owner(0) { }
    109         ~Backing() { ASSERT(!m_owner); }
     108        Backing(unsigned id, IntSize, GC3Denum format);
     109        ~Backing();
     110        void updatePriority();
    110111
    111112        CCPrioritizedTexture* owner() { return m_owner; }
     113        bool hadOwnerAtLastPriorityUpdate() const { return m_ownerExistedAtLastPriorityUpdate; }
     114        bool requestPriorityAtLastPriorityUpdate() const { return m_priorityAtLastPriorityUpdate; }
     115        bool wasAbovePriorityCutoffAtLastPriorityUpdate() const { return m_wasAbovePriorityCutoffAtLastPriorityUpdate; }
     116
    112117    private:
    113118        friend class CCPrioritizedTexture;
    114119        CCPrioritizedTexture* m_owner;
     120        int m_priorityAtLastPriorityUpdate;
     121        bool m_ownerExistedAtLastPriorityUpdate;
     122        bool m_wasAbovePriorityCutoffAtLastPriorityUpdate;
    115123    };
    116124
     
    129137    size_t m_bytes;
    130138
    131     size_t m_priority;
     139    int m_priority;
    132140    bool m_isAbovePriorityCutoff;
    133141    bool m_isSelfManaged;
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp

    r128005 r128253  
    4343    , m_memoryAvailableBytes(0)
    4444    , m_pool(pool)
     45    , m_needsUpdateBackingsPrioritites(false)
    4546{
    4647}
     
    6263    ASSERT(CCProxy::isMainThread());
    6364
    64 #if !ASSERT_DISABLED
    65     assertInvariants();
    66 #endif
    67 
    6865    // Sorting textures in this function could be replaced by a slightly
    6966    // modified O(n) quick-select to partition textures rather than
     
    7168
    7269    TextureVector& sortedTextures = m_tempTextureVector;
    73     BackingVector& sortedBackings = m_tempBackingVector;
    7470    sortedTextures.clear();
    75     sortedBackings.clear();
    7671
    7772    // Copy all textures into a vector and sort them.
     
    117112            m_memoryAboveCutoffBytes += (*it)->bytes();
    118113    }
     114    sortedTextures.clear();
     115
     116    m_needsUpdateBackingsPrioritites = true;
     117
    119118    ASSERT(m_memoryAboveCutoffBytes <= m_memoryAvailableBytes);
    120 
    121     // Put backings in eviction/recycling order.
    122     for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); ++it)
     119    ASSERT(memoryAboveCutoffBytes() <= maxMemoryLimitBytes());
     120}
     121
     122void CCPrioritizedTextureManager::updateBackingsPriorities()
     123{
     124    TRACE_EVENT0("cc", "CCPrioritizedTextureManager::updateBackingsPriorities");
     125    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
     126
     127    if (!m_needsUpdateBackingsPrioritites)
     128        return;
     129
     130#if !ASSERT_DISABLED
     131    assertInvariants();
     132#endif
     133
     134    // Update backings' priorities and put backings in eviction/recycling order.
     135    BackingVector& sortedBackings = m_tempBackingVector;
     136    sortedBackings.clear();
     137    for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); ++it) {
     138        (*it)->updatePriority();
    123139        sortedBackings.append(*it);
     140    }
    124141    std::sort(sortedBackings.begin(), sortedBackings.end(), compareBackings);
    125142
     
    128145        m_backings.add(*it);
    129146    }
    130 
    131     sortedTextures.clear();
    132147    sortedBackings.clear();
     148    m_needsUpdateBackingsPrioritites = false;
    133149
    134150#if !ASSERT_DISABLED
    135151    assertInvariants();
    136     ASSERT(memoryAboveCutoffBytes() <= maxMemoryLimitBytes());
    137152#endif
    138153}
     
    167182    m_memoryAboveCutoffBytes = newMemoryBytes;
    168183    texture->setAbovePriorityCutoff(true);
    169     if (texture->backing()) {
    170         m_backings.remove(texture->backing());
    171         m_backings.add(texture->backing());
    172     }
     184    m_needsUpdateBackingsPrioritites = true;
    173185    return true;
    174186}
     
    182194        return;
    183195
     196    // Make sure that the backings list is up to date and sorted before traversing it.
     197    updateBackingsPriorities();
     198
    184199    // Find a backing below, by either recycling or allocating.
    185200    CCPrioritizedTexture::Backing* backing = 0;
     
    187202    // First try to recycle
    188203    for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); ++it) {
    189         if ((*it)->owner() && (*it)->owner()->isAbovePriorityCutoff())
     204        if ((*it)->hadOwnerAtLastPriorityUpdate() && (*it)->wasAbovePriorityCutoffAtLastPriorityUpdate())
    190205            break;
    191206        if ((*it)->size() == texture->size() && (*it)->format() == texture->format()) {
     
    207222    m_backings.remove(backing);
    208223    m_backings.add(backing);
     224
     225    // Update the backing's priority from its new owner.
     226    backing->updatePriority();
    209227}
    210228
     
    218236    while (memoryUseBytes() > limitBytes && m_backings.size() > 0) {
    219237        BackingSet::iterator it = m_backings.begin();
    220         if ((*it)->owner() && (*it)->owner()->isAbovePriorityCutoff())
     238        if ((*it)->hadOwnerAtLastPriorityUpdate() && (*it)->wasAbovePriorityCutoffAtLastPriorityUpdate())
    221239            break;
    222240        destroyBacking((*it), resourceProvider);
     
    227245{
    228246    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
     247
     248    // Make sure that the backings list is up to date and sorted before traversing it.
     249    updateBackingsPriorities();
     250
    229251    reduceMemory(m_memoryAvailableBytes, resourceProvider);
    230252    ASSERT(memoryUseBytes() <= maxMemoryLimitBytes());
     
    309331    ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()));
    310332    if (texture->backing()) {
    311         // Move the backing texture to the front for eviction/recycling and unlink it.
    312         m_backings.remove(texture->backing());
    313         m_backings.insertBefore(m_backings.begin(), texture->backing());
    314333        texture->unlink();
     334        m_needsUpdateBackingsPrioritites = true;
    315335    }
    316336}
     
    330350void CCPrioritizedTextureManager::destroyBacking(CCPrioritizedTexture::Backing* backing, CCResourceProvider* resourceProvider)
    331351{
     352    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
    332353    ASSERT(backing);
    333354    ASSERT(!backing->owner() || !backing->owner()->isAbovePriorityCutoff());
     
    345366}
    346367
    347 
    348368#if !ASSERT_DISABLED
    349369void CCPrioritizedTextureManager::assertInvariants()
    350370{
    351     ASSERT(CCProxy::isMainThread());
     371    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
    352372
    353373    // If we hit any of these asserts, there is a bug in this class. To see
     
    372392    // backings that can't be evicted in the backing texture list (otherwise
    373393    // reduceMemory will not find all textures available for eviction/recycling).
    374     bool reachedProtected = false;
     394    bool reachedOwned = false;
     395    bool reachedAboveCutoff = false;
    375396    for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); ++it) {
    376         if ((*it)->owner() && (*it)->owner()->isAbovePriorityCutoff())
    377             reachedProtected = true;
    378         if (reachedProtected)
    379             ASSERT((*it)->owner() && (*it)->owner()->isAbovePriorityCutoff());
     397        if ((*it)->hadOwnerAtLastPriorityUpdate())
     398            reachedOwned = true;
     399        if ((*it)->wasAbovePriorityCutoffAtLastPriorityUpdate())
     400            reachedAboveCutoff = true;
     401        if (reachedOwned)
     402            ASSERT((*it)->hadOwnerAtLastPriorityUpdate());
     403        if (reachedAboveCutoff) {
     404            ASSERT((*it)->hadOwnerAtLastPriorityUpdate() && (*it)->wasAbovePriorityCutoffAtLastPriorityUpdate());
     405            ASSERT(reachedOwned);
     406        }
    380407    }
    381408}
    382409#endif
    383410
    384 
    385411} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.h

    r128005 r128253  
    8888    void returnBackingTexture(CCPrioritizedTexture*);
    8989
    90 #if !ASSERT_DISABLED
    91     void assertInvariants();
    92 #endif
     90private:
     91    friend class CCPrioritizedTextureTest;
    9392
    94 private:
    9593    // Compare textures. Highest priority first.
    9694    static inline bool compareTextures(CCPrioritizedTexture* a, CCPrioritizedTexture* b)
     
    103101    static inline bool compareBackings(CCPrioritizedTexture::Backing* a, CCPrioritizedTexture::Backing* b)
    104102    {
    105         int priorityA = a->owner() ? a->owner()->requestPriority() : CCPriorityCalculator::lowestPriority();
    106         int priorityB = b->owner() ? b->owner()->requestPriority() : CCPriorityCalculator::lowestPriority();
    107         if (priorityA == priorityB)
    108             return a < b;
    109         return CCPriorityCalculator::priorityIsLower(priorityA, priorityB);
     103        int priorityA = a->requestPriorityAtLastPriorityUpdate();
     104        int priorityB = b->requestPriorityAtLastPriorityUpdate();
     105        if (priorityA != priorityB)
     106            return CCPriorityCalculator::priorityIsLower(priorityA, priorityB);
     107        bool aboveCutoffA = a->wasAbovePriorityCutoffAtLastPriorityUpdate();
     108        bool aboveCutoffB = b->wasAbovePriorityCutoffAtLastPriorityUpdate();
     109        if (!aboveCutoffA && aboveCutoffB)
     110            return true;
     111        if (aboveCutoffA && !aboveCutoffB)
     112            return false;
     113        return a < b;
    110114    }
    111115
    112116    CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, int pool);
    113117
     118    void updateBackingsPriorities();
    114119    void reduceMemory(size_t limit, CCResourceProvider*);
    115 
    116120    CCPrioritizedTexture::Backing* createBacking(IntSize, GC3Denum format, CCResourceProvider*);
    117121    void destroyBacking(CCPrioritizedTexture::Backing*, CCResourceProvider*);
     122
     123#if !ASSERT_DISABLED
     124    void assertInvariants();
     125#endif
    118126
    119127    size_t m_maxMemoryLimitBytes;
     
    134142    TextureVector m_tempTextureVector;
    135143    BackingVector m_tempBackingVector;
     144
     145    // Set by the main thread when it adjust priorities in such a way that
     146    // the m_backings array's view of priorities is now out of date.
     147    bool m_needsUpdateBackingsPrioritites;
    136148};
    137149
  • trunk/Source/WebKit/chromium/ChangeLog

    r128218 r128253  
     12012-09-11  Christopher Cameron  <ccameron@chromium.org>
     2
     3        [chromium] Make prioritized texture manager not touch backings array on the main thread
     4        https://bugs.webkit.org/show_bug.cgi?id=96114
     5
     6        Reviewed by James Robinson.
     7
     8        Take a snapshot of the textures' priorities from the main thread,
     9        and save it in their backings for access by the impl thread.
     10        Update functions that access the sorted backings array to use the
     11        snapshotted values instead of the values that the main thread may
     12        have computed for the next frame.
     13
     14        Make the main thread not touch the m_backings array.  Split
     15        prioritizeTextures into a updateBackingsPriorities function.
     16        In places where the main thread would have touched m_backings,
     17        set a flag specifying that m_backings needs to be re-sorted
     18        before any function that requires it be sorted by priority be
     19        executed.
     20
     21        Update the two functions that require sorted order (acquireBacking
     22        and reduceMemory) to sort the backings array (if needed) before
     23        traversing it.
     24
     25        Updated tests to set correct thread during asserts. Add a test to
     26        verify that requestLate is correctly incorporated into the backing
     27        sorting.
     28
     29        * tests/CCPrioritizedTextureTest.cpp:
     30        (WTF::CCPrioritizedTextureTest::validateTexture):
     31
    1322012-09-11  Sheriff Bot  <webkit.review.bot@gmail.com>
    233
  • trunk/Source/WebKit/chromium/tests/CCPrioritizedTextureTest.cpp

    r127794 r128253  
    3939using namespace WTF;
    4040
    41 namespace {
     41namespace WebCore {
    4242
    4343class CCPrioritizedTextureTest : public testing::Test {
     
    7171    bool validateTexture(OwnPtr<CCPrioritizedTexture>& texture, bool requestLate)
    7272    {
    73 #if !ASSERT_DISABLED
    74         texture->textureManager()->assertInvariants();
    75 #endif
     73        textureManagerAssertInvariants(texture->textureManager());
    7674        if (requestLate)
    7775            texture->requestLate();
     76        textureManagerAssertInvariants(texture->textureManager());
    7877        DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
    7978        bool success = texture->canAcquireBackingTexture();
     
    8382    }
    8483
     84    void prioritizeTexturesAndBackings(CCPrioritizedTextureManager* textureManager)
     85    {
     86        textureManager->prioritizeTextures();
     87        textureManagerUpdateBackingsPriorities(textureManager);
     88    }
     89
     90    void textureManagerUpdateBackingsPriorities(CCPrioritizedTextureManager* textureManager)
     91    {
     92        DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
     93        textureManager->updateBackingsPriorities();
     94    }
     95
    8596    CCResourceProvider* resourceProvider()
    8697    {
    8798       return m_resourceProvider.get();
     99    }
     100
     101    void textureManagerAssertInvariants(CCPrioritizedTextureManager* textureManager)
     102    {
     103#if !ASSERT_DISABLED
     104        DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
     105        textureManager->assertInvariants();
     106#endif
     107    }
     108
     109    bool textureBackingIsAbovePriorityCutoff(CCPrioritizedTexture* texture)
     110    {
     111        return texture->m_backing->wasAbovePriorityCutoffAtLastPriorityUpdate();
    88112    }
    89113
     
    96120};
    97121
     122}
     123
     124namespace {
     125
    98126TEST_F(CCPrioritizedTextureTest, requestTextureExceedingMaxLimit)
    99127{
     
    112140
    113141    // Only lower half should be available.
    114     textureManager->prioritizeTextures();
     142    prioritizeTexturesAndBackings(textureManager.get());
    115143    EXPECT_TRUE(validateTexture(textures[0], false));
    116144    EXPECT_TRUE(validateTexture(textures[7], false));
     
    123151
    124152    // Only upper half should be available.
    125     textureManager->prioritizeTextures();
     153    prioritizeTexturesAndBackings(textureManager.get());
    126154    EXPECT_FALSE(validateTexture(textures[0], false));
    127155    EXPECT_FALSE(validateTexture(textures[7], false));
     
    149177    // Set max limit to 8 textures
    150178    textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8));
    151     textureManager->prioritizeTextures();
     179    prioritizeTexturesAndBackings(textureManager.get());
    152180    for (size_t i = 0; i < maxTextures; ++i)
    153181        validateTexture(textures[i], false);
     
    162190    // Set max limit to 5 textures
    163191    textureManager->setMaxMemoryLimitBytes(texturesMemorySize(5));
    164     textureManager->prioritizeTextures();
     192    prioritizeTexturesAndBackings(textureManager.get());
    165193    for (size_t i = 0; i < maxTextures; ++i)
    166194        EXPECT_EQ(validateTexture(textures[i], false), i < 5);
     
    175203    // Set max limit to 4 textures
    176204    textureManager->setMaxMemoryLimitBytes(texturesMemorySize(4));
    177     textureManager->prioritizeTextures();
     205    prioritizeTexturesAndBackings(textureManager.get());
    178206    for (size_t i = 0; i < maxTextures; ++i)
    179207        EXPECT_EQ(validateTexture(textures[i], false), i < 4);
     
    205233    for (size_t i = 0; i < numTextures; ++i)
    206234        textures[i]->setRequestPriority(200 + i);
    207     textureManager->prioritizeTextures();
     235    prioritizeTexturesAndBackings(textureManager.get());
    208236
    209237    // Allocate textures which are currently high priority.
     
    220248    for (size_t i = 0; i < numTextures; ++i)
    221249        moreTextures[i]->setRequestPriority(100 + i);
    222     textureManager->prioritizeTextures();
     250    prioritizeTexturesAndBackings(textureManager.get());
    223251
    224252    // Textures are now below cutoff.
     
    267295    // Set max limit to 8 textures
    268296    textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8));
    269     textureManager->prioritizeTextures();
     297    prioritizeTexturesAndBackings(textureManager.get());
    270298
    271299    // The two high priority textures should be available, others should not.
     
    299327
    300328    texture->setRequestPriority(100);
    301     textureManager->prioritizeTextures();
     329    prioritizeTexturesAndBackings(textureManager.get());
    302330
    303331    EXPECT_TRUE(validateTexture(texture, false));
     
    325353
    326354    texture->setRequestPriority(100);
    327     textureManagerOne->prioritizeTextures();
     355    prioritizeTexturesAndBackings(textureManagerOne.get());
    328356
    329357    EXPECT_TRUE(validateTexture(texture, false));
     
    344372    texture->setTextureManager(textureManagerTwo.get());
    345373
    346     textureManagerTwo->prioritizeTextures();
     374    prioritizeTexturesAndBackings(textureManagerTwo.get());
    347375
    348376    EXPECT_TRUE(validateTexture(texture, false));
     
    375403
    376404    // Only lower half should be available.
    377     textureManager->prioritizeTextures();
     405    prioritizeTexturesAndBackings(textureManager.get());
    378406    EXPECT_TRUE(validateTexture(textures[0], false));
    379407    EXPECT_TRUE(validateTexture(textures[3], false));
     
    386414
    387415    // Only upper half should be available.
    388     textureManager->prioritizeTextures();
     416    prioritizeTexturesAndBackings(textureManager.get());
    389417    EXPECT_FALSE(validateTexture(textures[0], false));
    390418    EXPECT_FALSE(validateTexture(textures[3], false));
     
    421449
    422450    // The first four to be requested late will be available.
    423     textureManager->prioritizeTextures();
     451    prioritizeTexturesAndBackings(textureManager.get());
    424452    for (unsigned i = 0; i < maxTextures; ++i)
    425453        EXPECT_FALSE(validateTexture(textures[i], false));
     
    459487        textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(false));
    460488
    461     textureManager->prioritizeTextures();
     489    prioritizeTexturesAndBackings(textureManager.get());
    462490
    463491    // Unable to requestLate textures in the child surface.
     
    477505}
    478506
     507TEST_F(CCPrioritizedTextureTest, requestLateBackingsSorting)
     508{
     509    const size_t maxTextures = 8;
     510    OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextures);
     511    textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures));
     512
     513    // Create textures to fill our memory limit.
     514    OwnPtr<CCPrioritizedTexture> textures[maxTextures];
     515    for (size_t i = 0; i < maxTextures; ++i)
     516        textures[i] = textureManager->createTexture(m_textureSize, m_textureFormat);
     517
     518    // Set equal priorities, and allocate backings for all textures.
     519    for (size_t i = 0; i < maxTextures; ++i)
     520        textures[i]->setRequestPriority(100);
     521    prioritizeTexturesAndBackings(textureManager.get());
     522    for (unsigned i = 0; i < maxTextures; ++i)
     523        EXPECT_TRUE(validateTexture(textures[i], false));
     524
     525    // Drop the memory limit and prioritize (none will be above the threshold,
     526    // but they still have backings because reduceMemory hasn't been called).
     527    textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures / 2));
     528    prioritizeTexturesAndBackings(textureManager.get());
     529
     530    // Push half of them back over the limit.
     531    for (size_t i = 0; i < maxTextures; i += 2)
     532        EXPECT_TRUE(textures[i]->requestLate());
     533
     534    // Push the priorities to the backings array and sort the backings array
     535    textureManagerUpdateBackingsPriorities(textureManager.get());
     536
     537    // Assert that the backings list be sorted with the below-limit backings
     538    // before the above-limit backings.
     539    textureManagerAssertInvariants(textureManager.get());
     540
     541    // Make sure that we have backings for all of the textures.
     542    for (size_t i = 0; i < maxTextures; ++i)
     543        EXPECT_TRUE(textures[i]->haveBackingTexture());
     544
     545    // Make sure that only the requestLate textures are above the priority cutoff
     546    for (size_t i = 0; i < maxTextures; i += 2)
     547        EXPECT_TRUE(textureBackingIsAbovePriorityCutoff(textures[i].get()));
     548    for (size_t i = 1; i < maxTextures; i += 2)
     549        EXPECT_FALSE(textureBackingIsAbovePriorityCutoff(textures[i].get()));
     550
     551    DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
     552    textureManager->clearAllMemory(resourceProvider());
     553}
     554
     555
    479556} // namespace
Note: See TracChangeset for help on using the changeset viewer.