summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorhartmanng@chromium.org <hartmanng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-20 21:17:34 +0000
committerhartmanng@chromium.org <hartmanng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-20 21:17:34 +0000
commitb56c13022ebca2d41761fa17d66a3743c2ee5a62 (patch)
treedfa278088936a4efbd4da23bd49c69e569781045 /cc
parentfc779cfea4cc72c51c96385d57b028c64d647c7c (diff)
downloadchromium_src-b56c13022ebca2d41761fa17d66a3743c2ee5a62.zip
chromium_src-b56c13022ebca2d41761fa17d66a3743c2ee5a62.tar.gz
chromium_src-b56c13022ebca2d41761fa17d66a3743c2ee5a62.tar.bz2
Chromify prioritized_resource_manager.* and prioritized_resource_unittest.cc.
BUG=none Review URL: https://chromiumcodereview.appspot.com/12731010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189404 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/layers/nine_patch_layer_unittest.cc8
-rw-r--r--cc/layers/scrollbar_layer_unittest.cc4
-rw-r--r--cc/layers/tiled_layer_unittest.cc108
-rw-r--r--cc/output/gl_renderer_unittest.cc6
-rw-r--r--cc/resources/prioritized_resource.cc18
-rw-r--r--cc/resources/prioritized_resource_manager.cc872
-rw-r--r--cc/resources/prioritized_resource_manager.h374
-rw-r--r--cc/resources/prioritized_resource_unittest.cc909
-rw-r--r--cc/resources/resource_update_controller_unittest.cc32
-rw-r--r--cc/trees/layer_tree_host.cc20
-rw-r--r--cc/trees/layer_tree_host_impl.cc2
-rw-r--r--cc/trees/layer_tree_host_unittest.cc6
-rw-r--r--cc/trees/single_thread_proxy.cc12
-rw-r--r--cc/trees/thread_proxy.cc16
14 files changed, 1267 insertions, 1120 deletions
diff --git a/cc/layers/nine_patch_layer_unittest.cc b/cc/layers/nine_patch_layer_unittest.cc
index 45de303..927d0cc 100644
--- a/cc/layers/nine_patch_layer_unittest.cc
+++ b/cc/layers/nine_patch_layer_unittest.cc
@@ -100,8 +100,8 @@ TEST_F(NinePatchLayerTest, triggerFullUploadOnceWhenChangingBitmap)
EXPECT_TRUE(params.texture != NULL);
// Upload the texture.
- layer_tree_host_->contents_texture_manager()->setMaxMemoryLimitBytes(1024 * 1024);
- layer_tree_host_->contents_texture_manager()->prioritizeTextures();
+ layer_tree_host_->contents_texture_manager()->SetMaxMemoryLimitBytes(1024 * 1024);
+ layer_tree_host_->contents_texture_manager()->PrioritizeTextures();
scoped_ptr<OutputSurface> outputSurface;
scoped_ptr<ResourceProvider> resourceProvider;
@@ -123,7 +123,7 @@ TEST_F(NinePatchLayerTest, triggerFullUploadOnceWhenChangingBitmap)
{
DebugScopedSetImplThread implThread(proxy());
DebugScopedSetMainThreadBlocked mainThreadBlocked(proxy());
- layer_tree_host_->contents_texture_manager()->clearAllMemory(resourceProvider.get());
+ layer_tree_host_->contents_texture_manager()->ClearAllMemory(resourceProvider.get());
}
// Reupload after eviction
@@ -133,7 +133,7 @@ TEST_F(NinePatchLayerTest, triggerFullUploadOnceWhenChangingBitmap)
EXPECT_EQ(queue.partialUploadSize(), 0);
// PrioritizedResourceManager clearing
- layer_tree_host_->contents_texture_manager()->unregisterTexture(params.texture);
+ layer_tree_host_->contents_texture_manager()->UnregisterTexture(params.texture);
EXPECT_EQ(NULL, params.texture->resource_manager());
testLayer->SetTexturePriorities(calculator);
ResourceUpdateQueue queue2;
diff --git a/cc/layers/scrollbar_layer_unittest.cc b/cc/layers/scrollbar_layer_unittest.cc
index ad140b4..bc46342 100644
--- a/cc/layers/scrollbar_layer_unittest.cc
+++ b/cc/layers/scrollbar_layer_unittest.cc
@@ -294,7 +294,7 @@ public:
layerTreeRoot->AddChild(scrollbarLayer);
m_layerTreeHost->InitializeRendererIfNeeded();
- m_layerTreeHost->contents_texture_manager()->setMaxMemoryLimitBytes(1024 * 1024);
+ m_layerTreeHost->contents_texture_manager()->SetMaxMemoryLimitBytes(1024 * 1024);
m_layerTreeHost->SetRootLayer(layerTreeRoot);
scrollbarLayer->SetIsDrawable(true);
@@ -316,7 +316,7 @@ public:
OcclusionTracker occlusionTracker(gfx::Rect(), false);
scrollbarLayer->SetTexturePriorities(calculator);
- m_layerTreeHost->contents_texture_manager()->prioritizeTextures();
+ m_layerTreeHost->contents_texture_manager()->PrioritizeTextures();
scrollbarLayer->Update(&queue, &occlusionTracker, NULL);
EXPECT_EQ(0, queue.fullUploadSize());
EXPECT_EQ(expectedResources, queue.partialUploadSize());
diff --git a/cc/layers/tiled_layer_unittest.cc b/cc/layers/tiled_layer_unittest.cc
index cfc8b51..140704b 100644
--- a/cc/layers/tiled_layer_unittest.cc
+++ b/cc/layers/tiled_layer_unittest.cc
@@ -46,7 +46,7 @@ public:
class TiledLayerTest : public testing::Test {
public:
TiledLayerTest()
- : m_proxy(NULL)
+ : proxy_(NULL)
, m_outputSurface(createFakeOutputSurface())
, m_queue(make_scoped_ptr(new ResourceUpdateQueue))
, m_fakeLayerImplTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)
@@ -58,21 +58,21 @@ public:
virtual void SetUp()
{
layer_tree_host_ = LayerTreeHost::Create(&m_fakeLayerImplTreeHostClient, m_settings, scoped_ptr<Thread>(NULL));
- m_proxy = layer_tree_host_->proxy();
- m_resourceManager = PrioritizedResourceManager::create(m_proxy);
+ proxy_ = layer_tree_host_->proxy();
+ m_resourceManager = PrioritizedResourceManager::Create(proxy_);
layer_tree_host_->InitializeRendererIfNeeded();
layer_tree_host_->SetRootLayer(Layer::Create());
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy);
+ DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(proxy_);
m_resourceProvider = ResourceProvider::Create(m_outputSurface.get());
- m_hostImpl = make_scoped_ptr(new FakeLayerTreeHostImpl(m_proxy));
+ m_hostImpl = make_scoped_ptr(new FakeLayerTreeHostImpl(proxy_));
}
virtual ~TiledLayerTest()
{
resourceManagerClearAllMemory(m_resourceManager.get(), m_resourceProvider.get());
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy);
+ DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(proxy_);
m_resourceProvider.reset();
m_hostImpl.reset();
}
@@ -80,20 +80,20 @@ public:
void resourceManagerClearAllMemory(PrioritizedResourceManager* resourceManager, ResourceProvider* resourceProvider)
{
{
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy);
- resourceManager->clearAllMemory(resourceProvider);
- resourceManager->reduceMemory(resourceProvider);
+ DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(proxy_);
+ resourceManager->ClearAllMemory(resourceProvider);
+ resourceManager->ReduceMemory(resourceProvider);
}
- resourceManager->unlinkAndClearEvictedBackings();
+ resourceManager->UnlinkAndClearEvictedBackings();
}
void updateTextures()
{
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy);
+ DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(proxy_);
DCHECK(m_queue);
scoped_ptr<ResourceUpdateController> updateController =
ResourceUpdateController::Create(
NULL,
- m_proxy->ImplThread(),
+ proxy_->ImplThread(),
m_queue.Pass(),
m_resourceProvider.get());
updateController->Finalize();
@@ -101,12 +101,12 @@ public:
}
void layerPushPropertiesTo(FakeTiledLayer* layer, FakeTiledLayerImpl* layerImpl)
{
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy);
+ DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(proxy_);
layer->PushPropertiesTo(layerImpl);
}
void layerUpdate(FakeTiledLayer* layer, TestOcclusionTracker* occluded)
{
- DebugScopedSetMainThread mainThread(m_proxy);
+ DebugScopedSetMainThread mainThread(proxy_);
layer->Update(m_queue.get(), occluded, NULL);
}
@@ -151,12 +151,12 @@ public:
const scoped_ptr<FakeTiledLayerImpl>& layerImpl2)
{
// Get textures
- m_resourceManager->clearPriorities();
+ m_resourceManager->ClearPriorities();
if (layer1)
layer1->SetTexturePriorities(m_priorityCalculator);
if (layer2)
layer2->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
// Update content
if (layer1)
@@ -181,7 +181,7 @@ public:
}
public:
- Proxy* m_proxy;
+ Proxy* proxy_;
LayerTreeSettings m_settings;
scoped_ptr<OutputSurface> m_outputSurface;
scoped_ptr<ResourceProvider> m_resourceProvider;
@@ -269,9 +269,9 @@ TEST_F(TiledLayerTest, pushDeletedTiles)
EXPECT_TRUE(layerImpl->HasResourceIdForTileAt(0, 0));
EXPECT_TRUE(layerImpl->HasResourceIdForTileAt(0, 1));
- m_resourceManager->clearPriorities();
+ m_resourceManager->ClearPriorities();
resourceManagerClearAllMemory(m_resourceManager.get(), m_resourceProvider.get());
- m_resourceManager->setMaxMemoryLimitBytes(4*1024*1024);
+ m_resourceManager->SetMaxMemoryLimitBytes(4*1024*1024);
// This should drop the tiles on the impl thread.
layerPushPropertiesTo(layer.get(), layerImpl.get());
@@ -399,7 +399,7 @@ TEST_F(TiledLayerTest, predictivePainting)
TEST_F(TiledLayerTest, pushTilesAfterIdlePaintFailed)
{
// Start with 2mb of memory, but the test is going to try to use just more than 1mb, so we reduce to 1mb later.
- m_resourceManager->setMaxMemoryLimitBytes(2 * 1024 * 1024);
+ m_resourceManager->SetMaxMemoryLimitBytes(2 * 1024 * 1024);
scoped_refptr<FakeTiledLayer> layer1 = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get()));
scoped_ptr<FakeTiledLayerImpl> layerImpl1 = make_scoped_ptr(new FakeTiledLayerImpl(m_hostImpl->active_tree(), 1));
scoped_refptr<FakeTiledLayer> layer2 = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get()));
@@ -427,7 +427,7 @@ TEST_F(TiledLayerTest, pushTilesAfterIdlePaintFailed)
EXPECT_TRUE(needsUpdate);
// Reduce our memory limits to 1mb.
- m_resourceManager->setMaxMemoryLimitBytes(1024 * 1024);
+ m_resourceManager->SetMaxMemoryLimitBytes(1024 * 1024);
// Now idle paint layer2. We are going to run out of memory though!
// Oh well, commit the frame and push.
@@ -555,7 +555,7 @@ TEST_F(TiledLayerTest, paintSmallAnimatedLayersImmediately)
if (runOutOfMemory[i])
layerWidth *= 2;
- m_resourceManager->setMaxMemoryLimitBytes(memoryForLayer);
+ m_resourceManager->SetMaxMemoryLimitBytes(memoryForLayer);
scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get()));
scoped_ptr<FakeTiledLayerImpl> layerImpl = make_scoped_ptr(new FakeTiledLayerImpl(m_hostImpl->active_tree(), 1));
@@ -573,7 +573,7 @@ TEST_F(TiledLayerTest, paintSmallAnimatedLayersImmediately)
// The layer should paint its entire contents on the first paint
// if it is close to the viewport size and has the available memory.
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), 0, NULL);
updateTextures();
layerPushPropertiesTo(layer.get(), layerImpl.get());
@@ -602,7 +602,7 @@ TEST_F(TiledLayerTest, idlePaintOutOfMemory)
// We have enough memory for only the visible rect, so we will run out of memory in first idle paint.
int memoryLimit = 4 * 100 * 100; // 1 tiles, 4 bytes per pixel.
- m_resourceManager->setMaxMemoryLimitBytes(memoryLimit);
+ m_resourceManager->SetMaxMemoryLimitBytes(memoryLimit);
// The tile size is 100x100, so this invalidates and then paints two tiles.
bool needsUpdate = false;
@@ -730,14 +730,14 @@ TEST_F(TiledLayerTest, verifyUpdateRectWhenContentBoundsAreScaled)
layer->InvalidateContentRect(contentBounds);
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), 0, NULL);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 300, 300 * 0.8), layer->updateRect());
updateTextures();
// After the tiles are updated once, another invalidate only needs to update the bounds of the layer.
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->InvalidateContentRect(contentBounds);
layer->Update(m_queue.get(), 0, NULL);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(layerBounds), layer->updateRect());
@@ -747,7 +747,7 @@ TEST_F(TiledLayerTest, verifyUpdateRectWhenContentBoundsAreScaled)
gfx::Rect partialDamage(30, 100, 10, 10);
layer->InvalidateContentRect(partialDamage);
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), 0, NULL);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(45, 80, 15, 8), layer->updateRect());
}
@@ -765,7 +765,7 @@ TEST_F(TiledLayerTest, verifyInvalidationWhenContentsScaleChanges)
// Push the tiles to the impl side and check that there is exactly one.
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), 0, NULL);
updateTextures();
layerPushPropertiesTo(layer.get(), layerImpl.get());
@@ -783,7 +783,7 @@ TEST_F(TiledLayerTest, verifyInvalidationWhenContentsScaleChanges)
// The impl side should get 2x2 tiles now.
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), 0, NULL);
updateTextures();
layerPushPropertiesTo(layer.get(), layerImpl.get());
@@ -800,7 +800,7 @@ TEST_F(TiledLayerTest, verifyInvalidationWhenContentsScaleChanges)
// impl side.
layer->SetNeedsDisplay();
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layerPushPropertiesTo(layer.get(), layerImpl.get());
EXPECT_FALSE(layerImpl->HasResourceIdForTileAt(0, 0));
@@ -861,7 +861,7 @@ TEST_F(TiledLayerTest, resizeToSmaller)
layer->InvalidateContentRect(gfx::Rect(0, 0, 700, 700));
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), 0, NULL);
layer->SetBounds(gfx::Size(200, 200));
@@ -879,7 +879,7 @@ TEST_F(TiledLayerTest, hugeLayerUpdateCrash)
// Ensure no crash for bounds where size * size would overflow an int.
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), 0, NULL);
}
@@ -1002,7 +1002,7 @@ TEST_F(TiledLayerTest, tilesPaintedWithoutOcclusion)
calcDrawProps(layer);
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), 0, NULL);
EXPECT_EQ(2, layer->fakeLayerUpdater()->updateCount());
}
@@ -1025,7 +1025,7 @@ TEST_F(TiledLayerTest, tilesPaintedWithOcclusion)
layer->InvalidateContentRect(gfx::Rect(0, 0, 600, 600));
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
EXPECT_EQ(36-3, layer->fakeLayerUpdater()->updateCount());
@@ -1035,7 +1035,7 @@ TEST_F(TiledLayerTest, tilesPaintedWithOcclusion)
layer->fakeLayerUpdater()->clearUpdateCount();
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
occluded.setOcclusion(gfx::Rect(250, 200, 300, 100));
layer->InvalidateContentRect(gfx::Rect(0, 0, 600, 600));
@@ -1048,7 +1048,7 @@ TEST_F(TiledLayerTest, tilesPaintedWithOcclusion)
layer->fakeLayerUpdater()->clearUpdateCount();
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
occluded.setOcclusion(gfx::Rect(250, 250, 300, 100));
layer->InvalidateContentRect(gfx::Rect(0, 0, 600, 600));
@@ -1079,7 +1079,7 @@ TEST_F(TiledLayerTest, tilesPaintedWithOcclusionAndVisiblityConstraints)
layer->InvalidateContentRect(gfx::Rect(0, 0, 600, 600));
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
EXPECT_EQ(24-3, layer->fakeLayerUpdater()->updateCount());
@@ -1095,7 +1095,7 @@ TEST_F(TiledLayerTest, tilesPaintedWithOcclusionAndVisiblityConstraints)
layer->draw_properties().visible_content_rect = gfx::Rect(0, 0, 600, 350);
layer->InvalidateContentRect(gfx::Rect(0, 0, 600, 600));
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
EXPECT_EQ(24-6, layer->fakeLayerUpdater()->updateCount());
@@ -1111,7 +1111,7 @@ TEST_F(TiledLayerTest, tilesPaintedWithOcclusionAndVisiblityConstraints)
layer->draw_properties().visible_content_rect = gfx::Rect(0, 0, 600, 340);
layer->InvalidateContentRect(gfx::Rect(0, 0, 600, 600));
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
EXPECT_EQ(24-6, layer->fakeLayerUpdater()->updateCount());
@@ -1138,7 +1138,7 @@ TEST_F(TiledLayerTest, tilesNotPaintedWithoutInvalidation)
layer->draw_properties().visible_content_rect = gfx::Rect(0, 0, 600, 600);
layer->InvalidateContentRect(gfx::Rect(0, 0, 600, 600));
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
EXPECT_EQ(36-3, layer->fakeLayerUpdater()->updateCount());
{
@@ -1151,7 +1151,7 @@ TEST_F(TiledLayerTest, tilesNotPaintedWithoutInvalidation)
layer->fakeLayerUpdater()->clearUpdateCount();
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
// Repaint without marking it dirty. The 3 culled tiles will be pre-painted now.
layer->Update(m_queue.get(), &occluded, NULL);
@@ -1185,7 +1185,7 @@ TEST_F(TiledLayerTest, tilesPaintedWithOcclusionAndTransforms)
layer->draw_properties().visible_content_rect = gfx::Rect(gfx::Point(), layer->content_bounds());
layer->InvalidateContentRect(gfx::Rect(0, 0, 600, 600));
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
EXPECT_EQ(36-3, layer->fakeLayerUpdater()->updateCount());
@@ -1221,7 +1221,7 @@ TEST_F(TiledLayerTest, tilesPaintedWithOcclusionAndScaling)
layer->draw_properties().visible_content_rect = gfx::Rect(gfx::Point(), layer->content_bounds());
layer->InvalidateContentRect(gfx::Rect(0, 0, 600, 600));
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
// The content is half the size of the layer (so the number of tiles is fewer).
// In this case, the content is 300x300, and since the tile size is 100, the
@@ -1242,7 +1242,7 @@ TEST_F(TiledLayerTest, tilesPaintedWithOcclusionAndScaling)
layer->draw_properties().visible_content_rect = gfx::Rect(gfx::Point(), layer->content_bounds());
layer->InvalidateContentRect(gfx::Rect(0, 0, 600, 600));
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
EXPECT_EQ(9-1, layer->fakeLayerUpdater()->updateCount());
@@ -1265,7 +1265,7 @@ TEST_F(TiledLayerTest, tilesPaintedWithOcclusionAndScaling)
layer->draw_properties().visible_content_rect = gfx::Rect(gfx::Point(), layer->content_bounds());
layer->InvalidateContentRect(gfx::Rect(0, 0, 600, 600));
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
EXPECT_EQ(9-1, layer->fakeLayerUpdater()->updateCount());
@@ -1298,7 +1298,7 @@ TEST_F(TiledLayerTest, visibleContentOpaqueRegion)
layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect());
layer->InvalidateContentRect(contentBounds);
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
opaqueContents = layer->VisibleContentOpaqueRegion();
EXPECT_TRUE(opaqueContents.IsEmpty());
@@ -1313,7 +1313,7 @@ TEST_F(TiledLayerTest, visibleContentOpaqueRegion)
layer->fakeLayerUpdater()->setOpaquePaintRect(opaquePaintRect);
layer->InvalidateContentRect(contentBounds);
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
updateTextures();
opaqueContents = layer->VisibleContentOpaqueRegion();
@@ -1327,7 +1327,7 @@ TEST_F(TiledLayerTest, visibleContentOpaqueRegion)
// If we paint again without invalidating, the same stuff should be opaque.
layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect());
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
updateTextures();
opaqueContents = layer->VisibleContentOpaqueRegion();
@@ -1343,7 +1343,7 @@ TEST_F(TiledLayerTest, visibleContentOpaqueRegion)
layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect());
layer->InvalidateContentRect(gfx::Rect(0, 0, 1, 1));
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
updateTextures();
opaqueContents = layer->VisibleContentOpaqueRegion();
@@ -1359,7 +1359,7 @@ TEST_F(TiledLayerTest, visibleContentOpaqueRegion)
layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect());
layer->InvalidateContentRect(gfx::Rect(10, 10, 1, 1));
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
updateTextures();
opaqueContents = layer->VisibleContentOpaqueRegion();
@@ -1391,7 +1391,7 @@ TEST_F(TiledLayerTest, pixels_paintedMetrics)
layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect());
layer->InvalidateContentRect(contentBounds);
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
updateTextures();
opaqueContents = layer->VisibleContentOpaqueRegion();
@@ -1408,7 +1408,7 @@ TEST_F(TiledLayerTest, pixels_paintedMetrics)
layer->InvalidateContentRect(gfx::Rect(0, 0, 1, 1));
layer->InvalidateContentRect(gfx::Rect(50, 200, 10, 10));
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
layer->Update(m_queue.get(), &occluded, NULL);
updateTextures();
opaqueContents = layer->VisibleContentOpaqueRegion();
@@ -1621,7 +1621,7 @@ TEST_F(TiledLayerTest, nonIntegerContentsScaleIsNotDistortedDuringPaint)
layer->draw_properties().drawable_content_rect = contentRect;
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
// Update the whole tile.
layer->Update(m_queue.get(), 0, NULL);
@@ -1651,7 +1651,7 @@ TEST_F(TiledLayerTest, nonIntegerContentsScaleIsNotDistortedDuringInvalidation)
layer->draw_properties().drawable_content_rect = contentRect;
layer->SetTexturePriorities(m_priorityCalculator);
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
// Update the whole tile.
layer->Update(m_queue.get(), 0, NULL);
diff --git a/cc/output/gl_renderer_unittest.cc b/cc/output/gl_renderer_unittest.cc
index c105ac5..62cf2ec 100644
--- a/cc/output/gl_renderer_unittest.cc
+++ b/cc/output/gl_renderer_unittest.cc
@@ -110,11 +110,11 @@ private:
class FakeRendererClient : public RendererClient {
public:
FakeRendererClient()
- : m_hostImpl(&m_proxy)
+ : m_hostImpl(&proxy_)
, m_setFullRootLayerDamageCount(0)
, m_lastCallWasSetVisibility(0)
, m_rootLayer(LayerImpl::Create(m_hostImpl.active_tree(), 1))
- , m_memoryAllocationLimitBytes(PrioritizedResourceManager::defaultMemoryAllocationLimit())
+ , m_memoryAllocationLimitBytes(PrioritizedResourceManager::DefaultMemoryAllocationLimit())
{
m_rootLayer->CreateRenderSurface();
RenderPass::Id renderPassId = m_rootLayer->render_surface()->RenderPassId();
@@ -146,7 +146,7 @@ public:
size_t memoryAllocationLimitBytes() const { return m_memoryAllocationLimitBytes; }
private:
- FakeImplProxy m_proxy;
+ FakeImplProxy proxy_;
FakeLayerTreeHostImpl m_hostImpl;
int m_setFullRootLayerDamageCount;
bool* m_lastCallWasSetVisibility;
diff --git a/cc/resources/prioritized_resource.cc b/cc/resources/prioritized_resource.cc
index 4cdb0bf..f166971 100644
--- a/cc/resources/prioritized_resource.cc
+++ b/cc/resources/prioritized_resource.cc
@@ -30,12 +30,12 @@ PrioritizedResource::PrioritizedResource(PrioritizedResourceManager* manager,
if (format)
bytes_ = Resource::MemorySizeBytes(size, format);
if (manager)
- manager->registerTexture(this);
+ manager->RegisterTexture(this);
}
PrioritizedResource::~PrioritizedResource() {
if (manager_)
- manager_->unregisterTexture(this);
+ manager_->UnregisterTexture(this);
}
void PrioritizedResource::SetTextureManager(
@@ -43,9 +43,9 @@ void PrioritizedResource::SetTextureManager(
if (manager_ == manager)
return;
if (manager_)
- manager_->unregisterTexture(this);
+ manager_->UnregisterTexture(this);
if (manager)
- manager->registerTexture(this);
+ manager->RegisterTexture(this);
}
void PrioritizedResource::SetDimensions(gfx::Size size, GLenum format) {
@@ -56,14 +56,14 @@ void PrioritizedResource::SetDimensions(gfx::Size size, GLenum format) {
bytes_ = Resource::MemorySizeBytes(size, format);
DCHECK(manager_ || !backing_);
if (manager_)
- manager_->returnBackingTexture(this);
+ manager_->ReturnBackingTexture(this);
}
}
bool PrioritizedResource::RequestLate() {
if (!manager_)
return false;
- return manager_->requestLate(this);
+ return manager_->RequestLate(this);
}
bool PrioritizedResource::BackingResourceWasEvicted() const {
@@ -74,7 +74,7 @@ void PrioritizedResource::AcquireBackingTexture(
ResourceProvider* resource_provider) {
DCHECK(is_above_priority_cutoff_);
if (is_above_priority_cutoff_)
- manager_->acquireBackingTextureIfNeeded(this, resource_provider);
+ manager_->AcquireBackingTextureIfNeeded(this, resource_provider);
}
ResourceProvider::ResourceId PrioritizedResource::ResourceId() const {
@@ -194,13 +194,13 @@ void PrioritizedResource::Backing::UpdateInDrawingImplTree() {
void PrioritizedResource::ReturnBackingTexture() {
DCHECK(manager_ || !backing_);
if (manager_)
- manager_->returnBackingTexture(this);
+ manager_->ReturnBackingTexture(this);
}
const Proxy* PrioritizedResource::Backing::proxy() const {
if (!owner_ || !owner_->resource_manager())
return NULL;
- return owner_->resource_manager()->proxyForDebug();
+ return owner_->resource_manager()->ProxyForDebug();
}
} // namespace cc
diff --git a/cc/resources/prioritized_resource_manager.cc b/cc/resources/prioritized_resource_manager.cc
index 403a2a0..e3eea72 100644
--- a/cc/resources/prioritized_resource_manager.cc
+++ b/cc/resources/prioritized_resource_manager.cc
@@ -15,483 +15,529 @@
namespace cc {
PrioritizedResourceManager::PrioritizedResourceManager(const Proxy* proxy)
- : m_proxy(proxy)
- , m_maxMemoryLimitBytes(defaultMemoryAllocationLimit())
- , m_externalPriorityCutoff(PriorityCalculator::AllowEverythingCutoff())
- , m_memoryUseBytes(0)
- , m_memoryAboveCutoffBytes(0)
- , m_memoryAvailableBytes(0)
- , m_backingsTailNotSorted(false)
- , m_memoryVisibleBytes(0)
- , m_memoryVisibleAndNearbyBytes(0)
- , m_memoryVisibleLastPushedBytes(0)
- , m_memoryVisibleAndNearbyLastPushedBytes(0)
-{
+ : proxy_(proxy),
+ max_memory_limit_bytes_(DefaultMemoryAllocationLimit()),
+ external_priority_cutoff_(PriorityCalculator::AllowEverythingCutoff()),
+ memory_use_bytes_(0),
+ memory_above_cutoff_bytes_(0),
+ memory_available_bytes_(0),
+ backings_tail_not_sorted_(false),
+ memory_visible_bytes_(0),
+ memory_visible_and_nearby_bytes_(0),
+ memory_visible_last_pushed_bytes_(0),
+ memory_visible_and_nearby_last_pushed_bytes_(0) {}
+
+PrioritizedResourceManager::~PrioritizedResourceManager() {
+ while (textures_.size() > 0)
+ UnregisterTexture(*textures_.begin());
+
+ UnlinkAndClearEvictedBackings();
+ DCHECK(evicted_backings_.empty());
+
+ // Each remaining backing is a leaked opengl texture. There should be none.
+ DCHECK(backings_.empty());
}
-PrioritizedResourceManager::~PrioritizedResourceManager()
-{
- while (m_textures.size() > 0)
- unregisterTexture(*m_textures.begin());
-
- unlinkAndClearEvictedBackings();
- DCHECK(m_evictedBackings.empty());
-
- // Each remaining backing is a leaked opengl texture. There should be none.
- DCHECK(m_backings.empty());
+size_t PrioritizedResourceManager::MemoryVisibleBytes() const {
+ DCHECK(proxy_->IsImplThread());
+ return memory_visible_last_pushed_bytes_;
}
-size_t PrioritizedResourceManager::memoryVisibleBytes() const
-{
- DCHECK(m_proxy->IsImplThread());
- return m_memoryVisibleLastPushedBytes;
+size_t PrioritizedResourceManager::MemoryVisibleAndNearbyBytes() const {
+ DCHECK(proxy_->IsImplThread());
+ return memory_visible_and_nearby_last_pushed_bytes_;
}
-size_t PrioritizedResourceManager::memoryVisibleAndNearbyBytes() const
-{
- DCHECK(m_proxy->IsImplThread());
- return m_memoryVisibleAndNearbyLastPushedBytes;
-}
-
-void PrioritizedResourceManager::prioritizeTextures()
-{
- TRACE_EVENT0("cc", "PrioritizedResourceManager::prioritizeTextures");
- DCHECK(m_proxy->IsMainThread());
-
- // Sorting textures in this function could be replaced by a slightly
- // modified O(n) quick-select to partition textures rather than
- // sort them (if performance of the sort becomes an issue).
-
- TextureVector& sortedTextures = m_tempTextureVector;
- sortedTextures.clear();
-
- // Copy all textures into a vector, sort them, and collect memory requirements statistics.
- m_memoryVisibleBytes = 0;
- m_memoryVisibleAndNearbyBytes = 0;
- for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); ++it) {
- PrioritizedResource* texture = (*it);
- sortedTextures.push_back(texture);
- if (PriorityCalculator::priority_is_higher(texture->request_priority(), PriorityCalculator::AllowVisibleOnlyCutoff()))
- m_memoryVisibleBytes += texture->bytes();
- if (PriorityCalculator::priority_is_higher(texture->request_priority(), PriorityCalculator::AllowVisibleAndNearbyCutoff()))
- m_memoryVisibleAndNearbyBytes += texture->bytes();
- }
- std::sort(sortedTextures.begin(), sortedTextures.end(), compareTextures);
-
- // Compute a priority cutoff based on memory pressure
- m_memoryAvailableBytes = m_maxMemoryLimitBytes;
- m_priorityCutoff = m_externalPriorityCutoff;
- size_t memoryBytes = 0;
- for (TextureVector::iterator it = sortedTextures.begin(); it != sortedTextures.end(); ++it) {
- if ((*it)->is_self_managed()) {
- // Account for self-managed memory immediately by reducing the memory
- // available (since it never gets acquired).
- size_t newMemoryBytes = memoryBytes + (*it)->bytes();
- if (newMemoryBytes > m_memoryAvailableBytes) {
- m_priorityCutoff = (*it)->request_priority();
- m_memoryAvailableBytes = memoryBytes;
- break;
- }
- m_memoryAvailableBytes -= (*it)->bytes();
- } else {
- size_t newMemoryBytes = memoryBytes + (*it)->bytes();
- if (newMemoryBytes > m_memoryAvailableBytes) {
- m_priorityCutoff = (*it)->request_priority();
- break;
- }
- memoryBytes = newMemoryBytes;
- }
- }
-
- // Disallow any textures with priority below the external cutoff to have backings.
- for (TextureVector::iterator it = sortedTextures.begin(); it != sortedTextures.end(); ++it) {
- PrioritizedResource* texture = (*it);
- if (!PriorityCalculator::priority_is_higher(texture->request_priority(), m_externalPriorityCutoff) &&
- texture->have_backing_texture())
- texture->Unlink();
+void PrioritizedResourceManager::PrioritizeTextures() {
+ TRACE_EVENT0("cc", "PrioritizedResourceManager::PrioritizeTextures");
+ DCHECK(proxy_->IsMainThread());
+
+ // Sorting textures in this function could be replaced by a slightly
+ // modified O(n) quick-select to partition textures rather than
+ // sort them (if performance of the sort becomes an issue).
+
+ TextureVector& sorted_textures = temp_texture_vector_;
+ sorted_textures.clear();
+
+ // Copy all textures into a vector, sort them, and collect memory requirements
+ // statistics.
+ memory_visible_bytes_ = 0;
+ memory_visible_and_nearby_bytes_ = 0;
+ for (TextureSet::iterator it = textures_.begin(); it != textures_.end();
+ ++it) {
+ PrioritizedResource* texture = (*it);
+ sorted_textures.push_back(texture);
+ if (PriorityCalculator::priority_is_higher(
+ texture->request_priority(),
+ PriorityCalculator::AllowVisibleOnlyCutoff()))
+ memory_visible_bytes_ += texture->bytes();
+ if (PriorityCalculator::priority_is_higher(
+ texture->request_priority(),
+ PriorityCalculator::AllowVisibleAndNearbyCutoff()))
+ memory_visible_and_nearby_bytes_ += texture->bytes();
+ }
+ std::sort(sorted_textures.begin(), sorted_textures.end(), CompareTextures);
+
+ // Compute a priority cutoff based on memory pressure
+ memory_available_bytes_ = max_memory_limit_bytes_;
+ priority_cutoff_ = external_priority_cutoff_;
+ size_t memory_bytes = 0;
+ for (TextureVector::iterator it = sorted_textures.begin();
+ it != sorted_textures.end();
+ ++it) {
+ if ((*it)->is_self_managed()) {
+ // Account for self-managed memory immediately by reducing the memory
+ // available (since it never gets acquired).
+ size_t new_memory_bytes = memory_bytes + (*it)->bytes();
+ if (new_memory_bytes > memory_available_bytes_) {
+ priority_cutoff_ = (*it)->request_priority();
+ memory_available_bytes_ = memory_bytes;
+ break;
+ }
+ memory_available_bytes_ -= (*it)->bytes();
+ } else {
+ size_t new_memory_bytes = memory_bytes + (*it)->bytes();
+ if (new_memory_bytes > memory_available_bytes_) {
+ priority_cutoff_ = (*it)->request_priority();
+ break;
+ }
+ memory_bytes = new_memory_bytes;
}
-
- // Only allow textures if they are higher than the cutoff. All textures
- // of the same priority are accepted or rejected together, rather than
- // being partially allowed randomly.
- m_memoryAboveCutoffBytes = 0;
- for (TextureVector::iterator it = sortedTextures.begin(); it != sortedTextures.end(); ++it) {
- bool is_above_priority_cutoff = PriorityCalculator::priority_is_higher((*it)->request_priority(), m_priorityCutoff);
- (*it)->set_above_priority_cutoff(is_above_priority_cutoff);
- if (is_above_priority_cutoff && !(*it)->is_self_managed())
- m_memoryAboveCutoffBytes += (*it)->bytes();
- }
- sortedTextures.clear();
-
- DCHECK(m_memoryAboveCutoffBytes <= m_memoryAvailableBytes);
- DCHECK(memoryAboveCutoffBytes() <= maxMemoryLimitBytes());
+ }
+
+ // Disallow any textures with priority below the external cutoff to have
+ // backings.
+ for (TextureVector::iterator it = sorted_textures.begin();
+ it != sorted_textures.end();
+ ++it) {
+ PrioritizedResource* texture = (*it);
+ if (!PriorityCalculator::priority_is_higher(texture->request_priority(),
+ external_priority_cutoff_) &&
+ texture->have_backing_texture())
+ texture->Unlink();
+ }
+
+ // Only allow textures if they are higher than the cutoff. All textures
+ // of the same priority are accepted or rejected together, rather than
+ // being partially allowed randomly.
+ memory_above_cutoff_bytes_ = 0;
+ for (TextureVector::iterator it = sorted_textures.begin();
+ it != sorted_textures.end();
+ ++it) {
+ bool is_above_priority_cutoff = PriorityCalculator::priority_is_higher(
+ (*it)->request_priority(), priority_cutoff_);
+ (*it)->set_above_priority_cutoff(is_above_priority_cutoff);
+ if (is_above_priority_cutoff && !(*it)->is_self_managed())
+ memory_above_cutoff_bytes_ += (*it)->bytes();
+ }
+ sorted_textures.clear();
+
+ DCHECK_LE(memory_above_cutoff_bytes_, memory_available_bytes_);
+ DCHECK_LE(MemoryAboveCutoffBytes(), MaxMemoryLimitBytes());
}
-void PrioritizedResourceManager::pushTexturePrioritiesToBackings()
-{
- TRACE_EVENT0("cc", "PrioritizedResourceManager::pushTexturePrioritiesToBackings");
- DCHECK(m_proxy->IsImplThread() && m_proxy->IsMainThreadBlocked());
-
- assertInvariants();
- for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it)
- (*it)->UpdatePriority();
- sortBackings();
- assertInvariants();
-
- // Push memory requirements to the impl thread structure.
- m_memoryVisibleLastPushedBytes = m_memoryVisibleBytes;
- m_memoryVisibleAndNearbyLastPushedBytes = m_memoryVisibleAndNearbyBytes;
+void PrioritizedResourceManager::PushTexturePrioritiesToBackings() {
+ TRACE_EVENT0("cc",
+ "PrioritizedResourceManager::PushTexturePrioritiesToBackings");
+ DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked());
+
+ AssertInvariants();
+ for (BackingList::iterator it = backings_.begin(); it != backings_.end();
+ ++it)
+ (*it)->UpdatePriority();
+ SortBackings();
+ AssertInvariants();
+
+ // Push memory requirements to the impl thread structure.
+ memory_visible_last_pushed_bytes_ = memory_visible_bytes_;
+ memory_visible_and_nearby_last_pushed_bytes_ =
+ memory_visible_and_nearby_bytes_;
}
-void PrioritizedResourceManager::updateBackingsInDrawingImplTree()
-{
- TRACE_EVENT0("cc", "PrioritizedResourceManager::updateBackingsInDrawingImplTree");
- DCHECK(m_proxy->IsImplThread() && m_proxy->IsMainThreadBlocked());
-
- assertInvariants();
- for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it) {
- PrioritizedResource::Backing* backing = (*it);
- backing->UpdateInDrawingImplTree();
- }
- sortBackings();
- assertInvariants();
+void PrioritizedResourceManager::UpdateBackingsInDrawingImplTree() {
+ TRACE_EVENT0("cc",
+ "PrioritizedResourceManager::UpdateBackingsInDrawingImplTree");
+ DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked());
+
+ AssertInvariants();
+ for (BackingList::iterator it = backings_.begin(); it != backings_.end();
+ ++it) {
+ PrioritizedResource::Backing* backing = (*it);
+ backing->UpdateInDrawingImplTree();
+ }
+ SortBackings();
+ AssertInvariants();
}
-void PrioritizedResourceManager::sortBackings()
-{
- TRACE_EVENT0("cc", "PrioritizedResourceManager::sortBackings");
- DCHECK(m_proxy->IsImplThread());
+void PrioritizedResourceManager::SortBackings() {
+ TRACE_EVENT0("cc", "PrioritizedResourceManager::SortBackings");
+ DCHECK(proxy_->IsImplThread());
- // Put backings in eviction/recycling order.
- m_backings.sort(compareBackings);
- m_backingsTailNotSorted = false;
+ // Put backings in eviction/recycling order.
+ backings_.sort(CompareBackings);
+ backings_tail_not_sorted_ = false;
}
-void PrioritizedResourceManager::clearPriorities()
-{
- DCHECK(m_proxy->IsMainThread());
- for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); ++it) {
- // FIXME: We should remove this and just set all priorities to
- // PriorityCalculator::lowestPriority() once we have priorities
- // for all textures (we can't currently calculate distances for
- // off-screen textures).
- (*it)->set_request_priority(PriorityCalculator::LingeringPriority((*it)->request_priority()));
- }
+void PrioritizedResourceManager::ClearPriorities() {
+ DCHECK(proxy_->IsMainThread());
+ for (TextureSet::iterator it = textures_.begin(); it != textures_.end();
+ ++it) {
+ // FIXME: We should remove this and just set all priorities to
+ // PriorityCalculator::lowestPriority() once we have priorities
+ // for all textures (we can't currently calculate distances for
+ // off-screen textures).
+ (*it)->set_request_priority(
+ PriorityCalculator::LingeringPriority((*it)->request_priority()));
+ }
}
-bool PrioritizedResourceManager::requestLate(PrioritizedResource* texture)
-{
- DCHECK(m_proxy->IsMainThread());
+bool PrioritizedResourceManager::RequestLate(PrioritizedResource* texture) {
+ DCHECK(proxy_->IsMainThread());
- // This is already above cutoff, so don't double count it's memory below.
- if (texture->is_above_priority_cutoff())
- return true;
+ // This is already above cutoff, so don't double count it's memory below.
+ if (texture->is_above_priority_cutoff())
+ return true;
- // Allow textures that have priority equal to the cutoff, but not strictly lower.
- if (PriorityCalculator::priority_is_lower(texture->request_priority(), m_priorityCutoff))
- return false;
+ // Allow textures that have priority equal to the cutoff, but not strictly
+ // lower.
+ if (PriorityCalculator::priority_is_lower(texture->request_priority(),
+ priority_cutoff_))
+ return false;
- // Disallow textures that do not have a priority strictly higher than the external cutoff.
- if (!PriorityCalculator::priority_is_higher(texture->request_priority(), m_externalPriorityCutoff))
- return false;
+ // Disallow textures that do not have a priority strictly higher than the
+ // external cutoff.
+ if (!PriorityCalculator::priority_is_higher(texture->request_priority(),
+ external_priority_cutoff_))
+ return false;
- size_t newMemoryBytes = m_memoryAboveCutoffBytes + texture->bytes();
- if (newMemoryBytes > m_memoryAvailableBytes)
- return false;
+ size_t new_memory_bytes = memory_above_cutoff_bytes_ + texture->bytes();
+ if (new_memory_bytes > memory_available_bytes_)
+ return false;
- m_memoryAboveCutoffBytes = newMemoryBytes;
- texture->set_above_priority_cutoff(true);
- return true;
+ memory_above_cutoff_bytes_ = new_memory_bytes;
+ texture->set_above_priority_cutoff(true);
+ return true;
}
-void PrioritizedResourceManager::acquireBackingTextureIfNeeded(PrioritizedResource* texture, ResourceProvider* resourceProvider)
-{
- DCHECK(m_proxy->IsImplThread() && m_proxy->IsMainThreadBlocked());
- DCHECK(!texture->is_self_managed());
- DCHECK(texture->is_above_priority_cutoff());
- if (texture->backing() || !texture->is_above_priority_cutoff())
- return;
-
- // Find a backing below, by either recycling or allocating.
- PrioritizedResource::Backing* backing = 0;
-
- // First try to recycle
- for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it) {
- if (!(*it)->CanBeRecycled())
- break;
- if (resourceProvider->InUseByConsumer((*it)->id()))
- continue;
- if ((*it)->size() == texture->size() && (*it)->format() == texture->format()) {
- backing = (*it);
- m_backings.erase(it);
- break;
- }
+void PrioritizedResourceManager::AcquireBackingTextureIfNeeded(
+ PrioritizedResource* texture,
+ ResourceProvider* resource_provider) {
+ DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked());
+ DCHECK(!texture->is_self_managed());
+ DCHECK(texture->is_above_priority_cutoff());
+ if (texture->backing() || !texture->is_above_priority_cutoff())
+ return;
+
+ // Find a backing below, by either recycling or allocating.
+ PrioritizedResource::Backing* backing = NULL;
+
+ // First try to recycle
+ for (BackingList::iterator it = backings_.begin(); it != backings_.end();
+ ++it) {
+ if (!(*it)->CanBeRecycled())
+ break;
+ if (resource_provider->InUseByConsumer((*it)->id()))
+ continue;
+ if ((*it)->size() == texture->size() &&
+ (*it)->format() == texture->format()) {
+ backing = (*it);
+ backings_.erase(it);
+ break;
}
+ }
- // Otherwise reduce memory and just allocate a new backing texures.
- if (!backing) {
- evictBackingsToReduceMemory(m_memoryAvailableBytes - texture->bytes(),
- PriorityCalculator::AllowEverythingCutoff(),
- EvictOnlyRecyclable,
- DoNotUnlinkBackings,
- resourceProvider);
- backing = createBacking(texture->size(), texture->format(), resourceProvider);
- }
-
- // Move the used backing to the end of the eviction list, and note that
- // the tail is not sorted.
- if (backing->owner())
- backing->owner()->Unlink();
- texture->Link(backing);
- m_backings.push_back(backing);
- m_backingsTailNotSorted = true;
-
- // Update the backing's priority from its new owner.
- backing->UpdatePriority();
+ // Otherwise reduce memory and just allocate a new backing texures.
+ if (!backing) {
+ EvictBackingsToReduceMemory(memory_available_bytes_ - texture->bytes(),
+ PriorityCalculator::AllowEverythingCutoff(),
+ EVICT_ONLY_RECYCLABLE,
+ DO_NOT_UNLINK_BACKINGS,
+ resource_provider);
+ backing =
+ CreateBacking(texture->size(), texture->format(), resource_provider);
+ }
+
+ // Move the used backing to the end of the eviction list, and note that
+ // the tail is not sorted.
+ if (backing->owner())
+ backing->owner()->Unlink();
+ texture->Link(backing);
+ backings_.push_back(backing);
+ backings_tail_not_sorted_ = true;
+
+ // Update the backing's priority from its new owner.
+ backing->UpdatePriority();
}
-bool PrioritizedResourceManager::evictBackingsToReduceMemory(size_t limitBytes,
- int priorityCutoff,
- EvictionPolicy evictionPolicy,
- UnlinkPolicy unlinkPolicy,
- ResourceProvider* resourceProvider)
-{
- DCHECK(m_proxy->IsImplThread());
- if (unlinkPolicy == UnlinkBackings)
- DCHECK(m_proxy->IsMainThreadBlocked());
- if (memoryUseBytes() <= limitBytes && PriorityCalculator::AllowEverythingCutoff() == priorityCutoff)
- return false;
-
- // Destroy backings until we are below the limit,
- // or until all backings remaining are above the cutoff.
- while (m_backings.size() > 0) {
- PrioritizedResource::Backing* backing = m_backings.front();
- if (memoryUseBytes() <= limitBytes &&
- PriorityCalculator::priority_is_higher(backing->request_priority_at_last_priority_update(), priorityCutoff))
- break;
- if (evictionPolicy == EvictOnlyRecyclable && !backing->CanBeRecycled())
- break;
- if (unlinkPolicy == UnlinkBackings && backing->owner())
- backing->owner()->Unlink();
- evictFirstBackingResource(resourceProvider);
- }
- return true;
-}
+bool PrioritizedResourceManager::EvictBackingsToReduceMemory(
+ size_t limit_bytes,
+ int priority_cutoff,
+ EvictionPolicy eviction_policy,
+ UnlinkPolicy unlink_policy,
+ ResourceProvider* resource_provider) {
+ DCHECK(proxy_->IsImplThread());
+ if (unlink_policy == UNLINK_BACKINGS)
+ DCHECK(proxy_->IsMainThreadBlocked());
+ if (MemoryUseBytes() <= limit_bytes &&
+ PriorityCalculator::AllowEverythingCutoff() == priority_cutoff)
+ return false;
-void PrioritizedResourceManager::reduceWastedMemory(ResourceProvider* resourceProvider)
-{
- // We currently collect backings from deleted textures for later recycling.
- // However, if we do that forever we will always use the max limit even if
- // we really need very little memory. This should probably be solved by reducing the
- // limit externally, but until then this just does some "clean up" of unused
- // backing textures (any more than 10%).
- size_t wastedMemory = 0;
- for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it) {
- if ((*it)->owner())
- break;
- wastedMemory += (*it)->bytes();
- }
- size_t tenPercentOfMemory = m_memoryAvailableBytes / 10;
- if (wastedMemory > tenPercentOfMemory)
- evictBackingsToReduceMemory(memoryUseBytes() - (wastedMemory - tenPercentOfMemory),
- PriorityCalculator::AllowEverythingCutoff(),
- EvictOnlyRecyclable,
- DoNotUnlinkBackings,
- resourceProvider);
+ // Destroy backings until we are below the limit,
+ // or until all backings remaining are above the cutoff.
+ while (backings_.size() > 0) {
+ PrioritizedResource::Backing* backing = backings_.front();
+ if (MemoryUseBytes() <= limit_bytes &&
+ PriorityCalculator::priority_is_higher(
+ backing->request_priority_at_last_priority_update(),
+ priority_cutoff))
+ break;
+ if (eviction_policy == EVICT_ONLY_RECYCLABLE && !backing->CanBeRecycled())
+ break;
+ if (unlink_policy == UNLINK_BACKINGS && backing->owner())
+ backing->owner()->Unlink();
+ EvictFirstBackingResource(resource_provider);
+ }
+ return true;
}
-void PrioritizedResourceManager::reduceMemory(ResourceProvider* resourceProvider)
-{
- DCHECK(m_proxy->IsImplThread() && m_proxy->IsMainThreadBlocked());
- evictBackingsToReduceMemory(m_memoryAvailableBytes,
+void PrioritizedResourceManager::ReduceWastedMemory(
+ ResourceProvider* resource_provider) {
+ // We currently collect backings from deleted textures for later recycling.
+ // However, if we do that forever we will always use the max limit even if
+ // we really need very little memory. This should probably be solved by
+ // reducing the limit externally, but until then this just does some "clean
+ // up" of unused backing textures (any more than 10%).
+ size_t wastedMemory = 0;
+ for (BackingList::iterator it = backings_.begin(); it != backings_.end();
+ ++it) {
+ if ((*it)->owner())
+ break;
+ wastedMemory += (*it)->bytes();
+ }
+ size_t tenPercentOfMemory = memory_available_bytes_ / 10;
+ if (wastedMemory > tenPercentOfMemory)
+ EvictBackingsToReduceMemory(MemoryUseBytes() -
+ (wastedMemory - tenPercentOfMemory),
PriorityCalculator::AllowEverythingCutoff(),
- EvictAnything,
- UnlinkBackings,
- resourceProvider);
- DCHECK(memoryUseBytes() <= m_memoryAvailableBytes);
+ EVICT_ONLY_RECYCLABLE,
+ DO_NOT_UNLINK_BACKINGS,
+ resource_provider);
+}
- reduceWastedMemory(resourceProvider);
+void PrioritizedResourceManager::ReduceMemory(
+ ResourceProvider* resource_provider) {
+ DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked());
+ EvictBackingsToReduceMemory(memory_available_bytes_,
+ PriorityCalculator::AllowEverythingCutoff(),
+ EVICT_ANYTHING,
+ UNLINK_BACKINGS,
+ resource_provider);
+ DCHECK_LE(MemoryUseBytes(), memory_available_bytes_);
+
+ ReduceWastedMemory(resource_provider);
}
-void PrioritizedResourceManager::clearAllMemory(ResourceProvider* resourceProvider)
-{
- DCHECK(m_proxy->IsImplThread() && m_proxy->IsMainThreadBlocked());
- if (!resourceProvider) {
- DCHECK(m_backings.empty());
- return;
- }
- evictBackingsToReduceMemory(0,
- PriorityCalculator::AllowEverythingCutoff(),
- EvictAnything,
- DoNotUnlinkBackings,
- resourceProvider);
+void PrioritizedResourceManager::ClearAllMemory(
+ ResourceProvider* resource_provider) {
+ DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked());
+ if (!resource_provider) {
+ DCHECK(backings_.empty());
+ return;
+ }
+ EvictBackingsToReduceMemory(0,
+ PriorityCalculator::AllowEverythingCutoff(),
+ EVICT_ANYTHING,
+ DO_NOT_UNLINK_BACKINGS,
+ resource_provider);
}
-bool PrioritizedResourceManager::reduceMemoryOnImplThread(size_t limitBytes, int priorityCutoff, ResourceProvider* resourceProvider)
-{
- DCHECK(m_proxy->IsImplThread());
- DCHECK(resourceProvider);
- // If we are in the process of uploading a new frame then the backings at the very end of
- // the list are not sorted by priority. Sort them before doing the eviction.
- if (m_backingsTailNotSorted)
- sortBackings();
- return evictBackingsToReduceMemory(limitBytes,
- priorityCutoff,
- EvictAnything,
- DoNotUnlinkBackings,
- resourceProvider);
+bool PrioritizedResourceManager::ReduceMemoryOnImplThread(
+ size_t limit_bytes,
+ int priority_cutoff,
+ ResourceProvider* resource_provider) {
+ DCHECK(proxy_->IsImplThread());
+ DCHECK(resource_provider);
+ // If we are in the process of uploading a new frame then the backings at the
+ // very end of the list are not sorted by priority. Sort them before doing the
+ // eviction.
+ if (backings_tail_not_sorted_)
+ SortBackings();
+ return EvictBackingsToReduceMemory(limit_bytes,
+ priority_cutoff,
+ EVICT_ANYTHING,
+ DO_NOT_UNLINK_BACKINGS,
+ resource_provider);
}
-void PrioritizedResourceManager::reduceWastedMemoryOnImplThread(ResourceProvider* resourceProvider)
-{
- DCHECK(m_proxy->IsImplThread());
- DCHECK(resourceProvider);
- // If we are in the process of uploading a new frame then the backings at the very end of
- // the list are not sorted by priority. Sort them before doing the eviction.
- if (m_backingsTailNotSorted)
- sortBackings();
- reduceWastedMemory(resourceProvider);
+void PrioritizedResourceManager::ReduceWastedMemoryOnImplThread(
+ ResourceProvider* resource_provider) {
+ DCHECK(proxy_->IsImplThread());
+ DCHECK(resource_provider);
+ // If we are in the process of uploading a new frame then the backings at the
+ // very end of the list are not sorted by priority. Sort them before doing the
+ // eviction.
+ if (backings_tail_not_sorted_)
+ SortBackings();
+ ReduceWastedMemory(resource_provider);
}
-void PrioritizedResourceManager::unlinkAndClearEvictedBackings()
-{
- DCHECK(m_proxy->IsMainThread());
- base::AutoLock scoped_lock(m_evictedBackingsLock);
- for (BackingList::const_iterator it = m_evictedBackings.begin(); it != m_evictedBackings.end(); ++it) {
- PrioritizedResource::Backing* backing = (*it);
- if (backing->owner())
- backing->owner()->Unlink();
- delete backing;
- }
- m_evictedBackings.clear();
+void PrioritizedResourceManager::UnlinkAndClearEvictedBackings() {
+ DCHECK(proxy_->IsMainThread());
+ base::AutoLock scoped_lock(evicted_backings_lock_);
+ for (BackingList::const_iterator it = evicted_backings_.begin();
+ it != evicted_backings_.end();
+ ++it) {
+ PrioritizedResource::Backing* backing = (*it);
+ if (backing->owner())
+ backing->owner()->Unlink();
+ delete backing;
+ }
+ evicted_backings_.clear();
}
-bool PrioritizedResourceManager::linkedEvictedBackingsExist() const
-{
- DCHECK(m_proxy->IsImplThread() && m_proxy->IsMainThreadBlocked());
- base::AutoLock scoped_lock(m_evictedBackingsLock);
- for (BackingList::const_iterator it = m_evictedBackings.begin(); it != m_evictedBackings.end(); ++it) {
- if ((*it)->owner())
- return true;
- }
- return false;
+bool PrioritizedResourceManager::LinkedEvictedBackingsExist() const {
+ DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked());
+ base::AutoLock scoped_lock(evicted_backings_lock_);
+ for (BackingList::const_iterator it = evicted_backings_.begin();
+ it != evicted_backings_.end();
+ ++it) {
+ if ((*it)->owner())
+ return true;
+ }
+ return false;
}
-void PrioritizedResourceManager::registerTexture(PrioritizedResource* texture)
-{
- DCHECK(m_proxy->IsMainThread());
- DCHECK(texture);
- DCHECK(!texture->resource_manager());
- DCHECK(!texture->backing());
- DCHECK(!ContainsKey(m_textures, texture));
+void PrioritizedResourceManager::RegisterTexture(PrioritizedResource* texture) {
+ DCHECK(proxy_->IsMainThread());
+ DCHECK(texture);
+ DCHECK(!texture->resource_manager());
+ DCHECK(!texture->backing());
+ DCHECK(!ContainsKey(textures_, texture));
- texture->set_manager_internal(this);
- m_textures.insert(texture);
+ texture->set_manager_internal(this);
+ textures_.insert(texture);
}
-void PrioritizedResourceManager::unregisterTexture(PrioritizedResource* texture)
-{
- DCHECK(m_proxy->IsMainThread() || (m_proxy->IsImplThread() && m_proxy->IsMainThreadBlocked()));
- DCHECK(texture);
- DCHECK(ContainsKey(m_textures, texture));
-
- returnBackingTexture(texture);
- texture->set_manager_internal(0);
- m_textures.erase(texture);
- texture->set_above_priority_cutoff(false);
+void PrioritizedResourceManager::UnregisterTexture(
+ PrioritizedResource* texture) {
+ DCHECK(proxy_->IsMainThread() ||
+ (proxy_->IsImplThread() && proxy_->IsMainThreadBlocked()));
+ DCHECK(texture);
+ DCHECK(ContainsKey(textures_, texture));
+
+ ReturnBackingTexture(texture);
+ texture->set_manager_internal(NULL);
+ textures_.erase(texture);
+ texture->set_above_priority_cutoff(false);
}
-void PrioritizedResourceManager::returnBackingTexture(PrioritizedResource* texture)
-{
- DCHECK(m_proxy->IsMainThread() || (m_proxy->IsImplThread() && m_proxy->IsMainThreadBlocked()));
- if (texture->backing())
- texture->Unlink();
+void PrioritizedResourceManager::ReturnBackingTexture(
+ PrioritizedResource* texture) {
+ DCHECK(proxy_->IsMainThread() ||
+ (proxy_->IsImplThread() && proxy_->IsMainThreadBlocked()));
+ if (texture->backing())
+ texture->Unlink();
}
-PrioritizedResource::Backing* PrioritizedResourceManager::createBacking(gfx::Size size, GLenum format, ResourceProvider* resourceProvider)
-{
- DCHECK(m_proxy->IsImplThread() && m_proxy->IsMainThreadBlocked());
- DCHECK(resourceProvider);
- ResourceProvider::ResourceId resourceId = resourceProvider->CreateManagedResource(size, format, ResourceProvider::TextureUsageAny);
- PrioritizedResource::Backing* backing = new PrioritizedResource::Backing(resourceId, resourceProvider, size, format);
- m_memoryUseBytes += backing->bytes();
- return backing;
+PrioritizedResource::Backing* PrioritizedResourceManager::CreateBacking(
+ gfx::Size size,
+ GLenum format,
+ ResourceProvider* resource_provider) {
+ DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked());
+ DCHECK(resource_provider);
+ ResourceProvider::ResourceId resource_id =
+ resource_provider->CreateManagedResource(
+ size, format, ResourceProvider::TextureUsageAny);
+ PrioritizedResource::Backing* backing = new PrioritizedResource::Backing(
+ resource_id, resource_provider, size, format);
+ memory_use_bytes_ += backing->bytes();
+ return backing;
}
-void PrioritizedResourceManager::evictFirstBackingResource(ResourceProvider* resourceProvider)
-{
- DCHECK(m_proxy->IsImplThread());
- DCHECK(resourceProvider);
- DCHECK(!m_backings.empty());
- PrioritizedResource::Backing* backing = m_backings.front();
-
- // Note that we create a backing and its resource at the same time, but we
- // delete the backing structure and its resource in two steps. This is because
- // we can delete the resource while the main thread is running, but we cannot
- // unlink backings while the main thread is running.
- backing->DeleteResource(resourceProvider);
- m_memoryUseBytes -= backing->bytes();
- m_backings.pop_front();
- base::AutoLock scoped_lock(m_evictedBackingsLock);
- m_evictedBackings.push_back(backing);
+void PrioritizedResourceManager::EvictFirstBackingResource(
+ ResourceProvider* resource_provider) {
+ DCHECK(proxy_->IsImplThread());
+ DCHECK(resource_provider);
+ DCHECK(!backings_.empty());
+ PrioritizedResource::Backing* backing = backings_.front();
+
+ // Note that we create a backing and its resource at the same time, but we
+ // delete the backing structure and its resource in two steps. This is because
+ // we can delete the resource while the main thread is running, but we cannot
+ // unlink backings while the main thread is running.
+ backing->DeleteResource(resource_provider);
+ memory_use_bytes_ -= backing->bytes();
+ backings_.pop_front();
+ base::AutoLock scoped_lock(evicted_backings_lock_);
+ evicted_backings_.push_back(backing);
}
-void PrioritizedResourceManager::assertInvariants()
-{
+void PrioritizedResourceManager::AssertInvariants() {
#ifndef NDEBUG
- DCHECK(m_proxy->IsImplThread() && m_proxy->IsMainThreadBlocked());
-
- // If we hit any of these asserts, there is a bug in this class. To see
- // where the bug is, call this function at the beginning and end of
- // every public function.
-
- // Backings/textures must be doubly-linked and only to other backings/textures in this manager.
- for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it) {
- if ((*it)->owner()) {
- DCHECK(ContainsKey(m_textures, (*it)->owner()));
- DCHECK((*it)->owner()->backing() == (*it));
- }
+ DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked());
+
+ // If we hit any of these asserts, there is a bug in this class. To see
+ // where the bug is, call this function at the beginning and end of
+ // every public function.
+
+ // Backings/textures must be doubly-linked and only to other backings/textures
+ // in this manager.
+ for (BackingList::iterator it = backings_.begin(); it != backings_.end();
+ ++it) {
+ if ((*it)->owner()) {
+ DCHECK(ContainsKey(textures_, (*it)->owner()));
+ DCHECK((*it)->owner()->backing() == (*it));
}
- for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); ++it) {
- PrioritizedResource* texture = (*it);
- PrioritizedResource::Backing* backing = texture->backing();
- base::AutoLock scoped_lock(m_evictedBackingsLock);
- if (backing) {
- if (backing->ResourceHasBeenDeleted()) {
- DCHECK(std::find(m_backings.begin(), m_backings.end(), backing) == m_backings.end());
- DCHECK(std::find(m_evictedBackings.begin(), m_evictedBackings.end(), backing) != m_evictedBackings.end());
- } else {
- DCHECK(std::find(m_backings.begin(), m_backings.end(), backing) != m_backings.end());
- DCHECK(std::find(m_evictedBackings.begin(), m_evictedBackings.end(), backing) == m_evictedBackings.end());
- }
- DCHECK(backing->owner() == texture);
- }
- }
-
- // At all times, backings that can be evicted must always come before
- // backings that can't be evicted in the backing texture list (otherwise
- // reduceMemory will not find all textures available for eviction/recycling).
- bool reachedUnrecyclable = false;
- PrioritizedResource::Backing* previous_backing = NULL;
- for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it) {
- PrioritizedResource::Backing* backing = *it;
- if (previous_backing && (!m_backingsTailNotSorted || !backing->was_above_priority_cutoff_at_last_priority_update()))
- DCHECK(compareBackings(previous_backing, backing));
- if (!backing->CanBeRecycled())
- reachedUnrecyclable = true;
- if (reachedUnrecyclable)
- DCHECK(!backing->CanBeRecycled());
- else
- DCHECK(backing->CanBeRecycled());
- previous_backing = backing;
+ }
+ for (TextureSet::iterator it = textures_.begin(); it != textures_.end();
+ ++it) {
+ PrioritizedResource* texture = (*it);
+ PrioritizedResource::Backing* backing = texture->backing();
+ base::AutoLock scoped_lock(evicted_backings_lock_);
+ if (backing) {
+ if (backing->ResourceHasBeenDeleted()) {
+ DCHECK(std::find(backings_.begin(), backings_.end(), backing) ==
+ backings_.end());
+ DCHECK(std::find(evicted_backings_.begin(),
+ evicted_backings_.end(),
+ backing) != evicted_backings_.end());
+ } else {
+ DCHECK(std::find(backings_.begin(), backings_.end(), backing) !=
+ backings_.end());
+ DCHECK(std::find(evicted_backings_.begin(),
+ evicted_backings_.end(),
+ backing) == evicted_backings_.end());
+ }
+ DCHECK(backing->owner() == texture);
}
+ }
+
+ // At all times, backings that can be evicted must always come before
+ // backings that can't be evicted in the backing texture list (otherwise
+ // reduceMemory will not find all textures available for eviction/recycling).
+ bool reached_unrecyclable = false;
+ PrioritizedResource::Backing* previous_backing = NULL;
+ for (BackingList::iterator it = backings_.begin(); it != backings_.end();
+ ++it) {
+ PrioritizedResource::Backing* backing = *it;
+ if (previous_backing &&
+ (!backings_tail_not_sorted_ ||
+ !backing->was_above_priority_cutoff_at_last_priority_update()))
+ DCHECK(CompareBackings(previous_backing, backing));
+ if (!backing->CanBeRecycled())
+ reached_unrecyclable = true;
+ if (reached_unrecyclable)
+ DCHECK(!backing->CanBeRecycled());
+ else
+ DCHECK(backing->CanBeRecycled());
+ previous_backing = backing;
+ }
#endif
}
-const Proxy* PrioritizedResourceManager::proxyForDebug() const
-{
- return m_proxy;
+const Proxy* PrioritizedResourceManager::ProxyForDebug() const {
+ return proxy_;
}
} // namespace cc
diff --git a/cc/resources/prioritized_resource_manager.h b/cc/resources/prioritized_resource_manager.h
index 33914ca..820ed41 100644
--- a/cc/resources/prioritized_resource_manager.h
+++ b/cc/resources/prioritized_resource_manager.h
@@ -22,14 +22,13 @@
#if defined(COMPILER_GCC)
namespace BASE_HASH_NAMESPACE {
-template<>
-struct hash<cc::PrioritizedResource*> {
+template <> struct hash<cc::PrioritizedResource*> {
size_t operator()(cc::PrioritizedResource* ptr) const {
return hash<size_t>()(reinterpret_cast<size_t>(ptr));
}
};
-} // namespace BASE_HASH_NAMESPACE
-#endif // COMPILER
+} // namespace BASE_HASH_NAMESPACE
+#endif // COMPILER
namespace cc {
@@ -37,180 +36,199 @@ class PriorityCalculator;
class Proxy;
class CC_EXPORT PrioritizedResourceManager {
-public:
- static scoped_ptr<PrioritizedResourceManager> create(const Proxy* proxy)
- {
- return make_scoped_ptr(new PrioritizedResourceManager(proxy));
- }
- scoped_ptr<PrioritizedResource> createTexture(gfx::Size size, GLenum format)
- {
- return make_scoped_ptr(new PrioritizedResource(this, size, format));
- }
- ~PrioritizedResourceManager();
-
- typedef std::list<PrioritizedResource::Backing*> BackingList;
-
- // FIXME (http://crbug.com/137094): This 64MB default is a straggler from the
- // old texture manager and is just to give us a default memory allocation before
- // we get a callback from the GPU memory manager. We should probaby either:
- // - wait for the callback before rendering anything instead
- // - push this into the GPU memory manager somehow.
- static size_t defaultMemoryAllocationLimit() { return 64 * 1024 * 1024; }
-
- // memoryUseBytes() describes the number of bytes used by existing allocated textures.
- // memoryAboveCutoffBytes() describes the number of bytes that would be used if all
- // textures that are above the cutoff were allocated.
- // memoryUseBytes() <= memoryAboveCutoffBytes() should always be true.
- size_t memoryUseBytes() const { return m_memoryUseBytes; }
- size_t memoryAboveCutoffBytes() const { return m_memoryAboveCutoffBytes; }
- size_t memoryForSelfManagedTextures() const { return m_maxMemoryLimitBytes - m_memoryAvailableBytes; }
-
- void setMaxMemoryLimitBytes(size_t bytes) { m_maxMemoryLimitBytes = bytes; }
- size_t maxMemoryLimitBytes() const { return m_maxMemoryLimitBytes; }
-
- // Sepecify a external priority cutoff. Only textures that have a strictly higher priority
- // than this cutoff will be allowed.
- void setExternalPriorityCutoff(int priorityCutoff) { m_externalPriorityCutoff = priorityCutoff; }
-
- // Return the amount of texture memory required at particular cutoffs.
- size_t memoryVisibleBytes() const;
- size_t memoryVisibleAndNearbyBytes() const;
-
- void prioritizeTextures();
- void clearPriorities();
-
- // Delete contents textures' backing resources until they use only bytesLimit bytes. This may
- // be called on the impl thread while the main thread is running. Returns true if resources are
- // indeed evicted as a result of this call.
- bool reduceMemoryOnImplThread(size_t limitBytes, int priorityCutoff, ResourceProvider*);
-
- // Delete contents textures' backing resources that can be recycled. This
- // may be called on the impl thread while the main thread is running.
- void reduceWastedMemoryOnImplThread(ResourceProvider*);
-
- // Returns true if there exist any textures that are linked to backings that have had their
- // resources evicted. Only when we commit a tree that has no textures linked to evicted backings
- // may we allow drawing. After an eviction, this will not become true until
- // unlinkAndClearEvictedBackings is called.
- bool linkedEvictedBackingsExist() const;
-
- // Unlink the list of contents textures' backings from their owning textures and delete the evicted
- // backings' structures. This is called just before updating layers, and is only ever called on the
- // main thread.
- void unlinkAndClearEvictedBackings();
-
- bool requestLate(PrioritizedResource*);
-
- void reduceWastedMemory(ResourceProvider*);
- void reduceMemory(ResourceProvider*);
- void clearAllMemory(ResourceProvider*);
-
- void acquireBackingTextureIfNeeded(PrioritizedResource*, ResourceProvider*);
-
- void registerTexture(PrioritizedResource*);
- void unregisterTexture(PrioritizedResource*);
- void returnBackingTexture(PrioritizedResource*);
-
- // Update all backings' priorities from their owning texture.
- void pushTexturePrioritiesToBackings();
-
- // Mark all textures' backings as being in the drawing impl tree.
- void updateBackingsInDrawingImplTree();
-
- const Proxy* proxyForDebug() const;
-
-private:
- friend class PrioritizedResourceTest;
-
- enum EvictionPolicy {
- EvictOnlyRecyclable,
- EvictAnything,
- };
- enum UnlinkPolicy {
- DoNotUnlinkBackings,
- UnlinkBackings,
- };
-
- // Compare textures. Highest priority first.
- static inline bool compareTextures(PrioritizedResource* a, PrioritizedResource* b)
- {
- if (a->request_priority() == b->request_priority())
- return a < b;
- return PriorityCalculator::priority_is_higher(a->request_priority(), b->request_priority());
- }
- // Compare backings. Lowest priority first.
- static inline bool compareBackings(PrioritizedResource::Backing* a, PrioritizedResource::Backing* b)
- {
- // Make textures that can be recycled appear first
- if (a->CanBeRecycled() != b->CanBeRecycled())
- return (a->CanBeRecycled() > b->CanBeRecycled());
- // Then sort by being above or below the priority cutoff.
- if (a->was_above_priority_cutoff_at_last_priority_update() != b->was_above_priority_cutoff_at_last_priority_update())
- return (a->was_above_priority_cutoff_at_last_priority_update() < b->was_above_priority_cutoff_at_last_priority_update());
- // Then sort by priority (note that backings that no longer have owners will
- // always have the lowest priority)
- if (a->request_priority_at_last_priority_update() != b->request_priority_at_last_priority_update())
- return PriorityCalculator::priority_is_lower(a->request_priority_at_last_priority_update(), b->request_priority_at_last_priority_update());
- // Finally sort by being in the impl tree versus being completely unreferenced
- if (a->in_drawing_impl_tree() != b->in_drawing_impl_tree())
- return (a->in_drawing_impl_tree() < b->in_drawing_impl_tree());
- return a < b;
- }
-
- PrioritizedResourceManager(const Proxy* proxy);
-
- bool evictBackingsToReduceMemory(size_t limitBytes,
- int priorityCutoff,
- EvictionPolicy,
- UnlinkPolicy,
- ResourceProvider*);
- PrioritizedResource::Backing* createBacking(gfx::Size, GLenum format, ResourceProvider*);
- void evictFirstBackingResource(ResourceProvider*);
- void sortBackings();
-
- void assertInvariants();
-
- size_t m_maxMemoryLimitBytes;
- // The priority cutoff based on memory pressure. This is not a strict
- // cutoff -- requestLate allows textures with priority equal to this
- // cutoff to be allowed.
- int m_priorityCutoff;
- // The priority cutoff based on external memory policy. This is a strict
- // cutoff -- no textures with priority equal to this cutoff will be allowed.
- int m_externalPriorityCutoff;
- size_t m_memoryUseBytes;
- size_t m_memoryAboveCutoffBytes;
- size_t m_memoryAvailableBytes;
-
- typedef base::hash_set<PrioritizedResource*> TextureSet;
- typedef std::vector<PrioritizedResource*> TextureVector;
-
- const Proxy* m_proxy;
-
- TextureSet m_textures;
- // This list is always sorted in eviction order, with the exception the
- // newly-allocated or recycled textures at the very end of the tail that
- // are not sorted by priority.
- BackingList m_backings;
- bool m_backingsTailNotSorted;
-
- // The list of backings that have been evicted, but may still be linked
- // to textures. This can be accessed concurrently by the main and impl
- // threads, and may only be accessed while holding m_evictedBackingsLock.
- mutable base::Lock m_evictedBackingsLock;
- BackingList m_evictedBackings;
-
- TextureVector m_tempTextureVector;
-
- // Statistics about memory usage at priority cutoffs, computed at prioritizeTextures.
- size_t m_memoryVisibleBytes;
- size_t m_memoryVisibleAndNearbyBytes;
-
- // Statistics copied at the time of pushTexturePrioritiesToBackings.
- size_t m_memoryVisibleLastPushedBytes;
- size_t m_memoryVisibleAndNearbyLastPushedBytes;
-
- DISALLOW_COPY_AND_ASSIGN(PrioritizedResourceManager);
+ public:
+ static scoped_ptr<PrioritizedResourceManager> Create(const Proxy* proxy) {
+ return make_scoped_ptr(new PrioritizedResourceManager(proxy));
+ }
+ scoped_ptr<PrioritizedResource> CreateTexture(gfx::Size size, GLenum format) {
+ return make_scoped_ptr(new PrioritizedResource(this, size, format));
+ }
+ ~PrioritizedResourceManager();
+
+ typedef std::list<PrioritizedResource::Backing*> BackingList;
+
+ // TODO (epenner): (http://crbug.com/137094) This 64MB default is a straggler
+ // from the old texture manager and is just to give us a default memory
+ // allocation before we get a callback from the GPU memory manager. We
+ // should probaby either:
+ // - wait for the callback before rendering anything instead
+ // - push this into the GPU memory manager somehow.
+ static size_t DefaultMemoryAllocationLimit() { return 64 * 1024 * 1024; }
+
+ // MemoryUseBytes() describes the number of bytes used by existing allocated
+ // textures. MemoryAboveCutoffBytes() describes the number of bytes that
+ // would be used if all textures that are above the cutoff were allocated.
+ // MemoryUseBytes() <= MemoryAboveCutoffBytes() should always be true.
+ size_t MemoryUseBytes() const { return memory_use_bytes_; }
+ size_t MemoryAboveCutoffBytes() const { return memory_above_cutoff_bytes_; }
+ size_t MemoryForSelfManagedTextures() const {
+ return max_memory_limit_bytes_ - memory_available_bytes_;
+ }
+
+ void SetMaxMemoryLimitBytes(size_t bytes) { max_memory_limit_bytes_ = bytes; }
+ size_t MaxMemoryLimitBytes() const { return max_memory_limit_bytes_; }
+
+ // Sepecify a external priority cutoff. Only textures that have a strictly
+ // higher priority than this cutoff will be allowed.
+ void SetExternalPriorityCutoff(int priority_cutoff) {
+ external_priority_cutoff_ = priority_cutoff;
+ }
+
+ // Return the amount of texture memory required at particular cutoffs.
+ size_t MemoryVisibleBytes() const;
+ size_t MemoryVisibleAndNearbyBytes() const;
+
+ void PrioritizeTextures();
+ void ClearPriorities();
+
+ // Delete contents textures' backing resources until they use only
+ // bytesLimit bytes. This may be called on the impl thread while the main
+ // thread is running. Returns true if resources are indeed evicted as a
+ // result of this call.
+ bool ReduceMemoryOnImplThread(size_t limit_bytes,
+ int priority_cutoff,
+ ResourceProvider* resource_provider);
+
+ // Delete contents textures' backing resources that can be recycled. This
+ // may be called on the impl thread while the main thread is running.
+ void ReduceWastedMemoryOnImplThread(ResourceProvider* resource_provider);
+
+ // Returns true if there exist any textures that are linked to backings that
+ // have had their resources evicted. Only when we commit a tree that has no
+ // textures linked to evicted backings may we allow drawing. After an
+ // eviction, this will not become true until unlinkAndClearEvictedBackings
+ // is called.
+ bool LinkedEvictedBackingsExist() const;
+
+ // Unlink the list of contents textures' backings from their owning textures
+ // and delete the evicted backings' structures. This is called just before
+ // updating layers, and is only ever called on the main thread.
+ void UnlinkAndClearEvictedBackings();
+
+ bool RequestLate(PrioritizedResource* texture);
+
+ void ReduceWastedMemory(ResourceProvider* resource_provider);
+ void ReduceMemory(ResourceProvider* resource_provider);
+ void ClearAllMemory(ResourceProvider* resource_provider);
+
+ void AcquireBackingTextureIfNeeded(PrioritizedResource* texture,
+ ResourceProvider* resource_provider);
+
+ void RegisterTexture(PrioritizedResource* texture);
+ void UnregisterTexture(PrioritizedResource* texture);
+ void ReturnBackingTexture(PrioritizedResource* texture);
+
+ // Update all backings' priorities from their owning texture.
+ void PushTexturePrioritiesToBackings();
+
+ // Mark all textures' backings as being in the drawing impl tree.
+ void UpdateBackingsInDrawingImplTree();
+
+ const Proxy* ProxyForDebug() const;
+
+ private:
+ friend class PrioritizedResourceTest;
+
+ enum EvictionPolicy {
+ EVICT_ONLY_RECYCLABLE,
+ EVICT_ANYTHING,
+ };
+ enum UnlinkPolicy {
+ DO_NOT_UNLINK_BACKINGS,
+ UNLINK_BACKINGS,
+ };
+
+ // Compare textures. Highest priority first.
+ static inline bool CompareTextures(PrioritizedResource* a,
+ PrioritizedResource* b) {
+ if (a->request_priority() == b->request_priority())
+ return a < b;
+ return PriorityCalculator::priority_is_higher(a->request_priority(),
+ b->request_priority());
+ }
+ // Compare backings. Lowest priority first.
+ static inline bool CompareBackings(PrioritizedResource::Backing* a,
+ PrioritizedResource::Backing* b) {
+ // Make textures that can be recycled appear first
+ if (a->CanBeRecycled() != b->CanBeRecycled())
+ return (a->CanBeRecycled() > b->CanBeRecycled());
+ // Then sort by being above or below the priority cutoff.
+ if (a->was_above_priority_cutoff_at_last_priority_update() !=
+ b->was_above_priority_cutoff_at_last_priority_update())
+ return (a->was_above_priority_cutoff_at_last_priority_update() <
+ b->was_above_priority_cutoff_at_last_priority_update());
+ // Then sort by priority (note that backings that no longer have owners will
+ // always have the lowest priority)
+ if (a->request_priority_at_last_priority_update() !=
+ b->request_priority_at_last_priority_update())
+ return PriorityCalculator::priority_is_lower(
+ a->request_priority_at_last_priority_update(),
+ b->request_priority_at_last_priority_update());
+ // Finally sort by being in the impl tree versus being completely
+ // unreferenced
+ if (a->in_drawing_impl_tree() != b->in_drawing_impl_tree())
+ return (a->in_drawing_impl_tree() < b->in_drawing_impl_tree());
+ return a < b;
+ }
+
+ PrioritizedResourceManager(const Proxy* proxy);
+
+ bool EvictBackingsToReduceMemory(size_t limit_bytes,
+ int priority_cutoff,
+ EvictionPolicy eviction_policy,
+ UnlinkPolicy unlink_policy,
+ ResourceProvider* resource_provider);
+ PrioritizedResource::Backing* CreateBacking(
+ gfx::Size size,
+ GLenum format,
+ ResourceProvider* resource_provider);
+ void EvictFirstBackingResource(ResourceProvider* resource_provider);
+ void SortBackings();
+
+ void AssertInvariants();
+
+ size_t max_memory_limit_bytes_;
+ // The priority cutoff based on memory pressure. This is not a strict
+ // cutoff -- requestLate allows textures with priority equal to this
+ // cutoff to be allowed.
+ int priority_cutoff_;
+ // The priority cutoff based on external memory policy. This is a strict
+ // cutoff -- no textures with priority equal to this cutoff will be allowed.
+ int external_priority_cutoff_;
+ size_t memory_use_bytes_;
+ size_t memory_above_cutoff_bytes_;
+ size_t memory_available_bytes_;
+
+ typedef base::hash_set<PrioritizedResource*> TextureSet;
+ typedef std::vector<PrioritizedResource*> TextureVector;
+
+ const Proxy* proxy_;
+
+ TextureSet textures_;
+ // This list is always sorted in eviction order, with the exception the
+ // newly-allocated or recycled textures at the very end of the tail that
+ // are not sorted by priority.
+ BackingList backings_;
+ bool backings_tail_not_sorted_;
+
+ // The list of backings that have been evicted, but may still be linked
+ // to textures. This can be accessed concurrently by the main and impl
+ // threads, and may only be accessed while holding evicted_backings_lock_.
+ mutable base::Lock evicted_backings_lock_;
+ BackingList evicted_backings_;
+
+ TextureVector temp_texture_vector_;
+
+ // Statistics about memory usage at priority cutoffs, computed at
+ // prioritizeTextures.
+ size_t memory_visible_bytes_;
+ size_t memory_visible_and_nearby_bytes_;
+
+ // Statistics copied at the time of pushTexturePrioritiesToBackings.
+ size_t memory_visible_last_pushed_bytes_;
+ size_t memory_visible_and_nearby_last_pushed_bytes_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrioritizedResourceManager);
};
} // namespace cc
diff --git a/cc/resources/prioritized_resource_unittest.cc b/cc/resources/prioritized_resource_unittest.cc
index 8fe3736..51e7df8 100644
--- a/cc/resources/prioritized_resource_unittest.cc
+++ b/cc/resources/prioritized_resource_unittest.cc
@@ -9,294 +9,313 @@
#include "cc/test/fake_output_surface.h"
#include "cc/test/fake_proxy.h"
#include "cc/test/tiled_layer_test_common.h"
-#include "cc/trees/single_thread_proxy.h" // For DebugScopedSetImplThread
+#include "cc/trees/single_thread_proxy.h" // For DebugScopedSetImplThread
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
class PrioritizedResourceTest : public testing::Test {
-public:
+ public:
PrioritizedResourceTest()
- : m_proxy(scoped_ptr<Thread>(NULL))
- , m_textureSize(256, 256)
- , m_textureFormat(GL_RGBA)
- , m_outputSurface(createFakeOutputSurface())
- {
- DebugScopedSetImplThread implThread(&m_proxy);
- m_resourceProvider = ResourceProvider::Create(m_outputSurface.get());
+ : proxy_(scoped_ptr<Thread>(NULL)),
+ texture_size_(256, 256),
+ texture_format_(GL_RGBA),
+ output_surface_(createFakeOutputSurface()) {
+ DebugScopedSetImplThread impl_thread(&proxy_);
+ resource_provider_ = cc::ResourceProvider::Create(output_surface_.get());
}
- virtual ~PrioritizedResourceTest()
- {
- DebugScopedSetImplThread implThread(&m_proxy);
- m_resourceProvider.reset();
+ virtual ~PrioritizedResourceTest() {
+ DebugScopedSetImplThread impl_thread(&proxy_);
+ resource_provider_.reset();
}
- size_t texturesMemorySize(size_t textureCount)
- {
- return Resource::MemorySizeBytes(m_textureSize, m_textureFormat) * textureCount;
+ size_t TexturesMemorySize(size_t texture_count) {
+ return Resource::MemorySizeBytes(texture_size_, texture_format_) *
+ texture_count;
}
- scoped_ptr<PrioritizedResourceManager> createManager(size_t maxTextures)
- {
- scoped_ptr<PrioritizedResourceManager> manager = PrioritizedResourceManager::create(&m_proxy);
- manager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures));
+ scoped_ptr<PrioritizedResourceManager> CreateManager(size_t max_textures) {
+ scoped_ptr<PrioritizedResourceManager> manager =
+ PrioritizedResourceManager::Create(&proxy_);
+ manager->SetMaxMemoryLimitBytes(TexturesMemorySize(max_textures));
return manager.Pass();
}
- bool validateTexture(scoped_ptr<PrioritizedResource>& texture, bool requestLate)
- {
- resourceManagerAssertInvariants(texture->resource_manager());
- if (requestLate)
+ bool ValidateTexture(scoped_ptr<PrioritizedResource>& texture,
+ bool request_late) {
+ ResourceManagerAssertInvariants(texture->resource_manager());
+ if (request_late)
texture->RequestLate();
- resourceManagerAssertInvariants(texture->resource_manager());
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
+ ResourceManagerAssertInvariants(texture->resource_manager());
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
bool success = texture->can_acquire_backing_texture();
if (success)
- texture->AcquireBackingTexture(resourceProvider());
+ texture->AcquireBackingTexture(ResourceProvider());
return success;
}
- void prioritizeTexturesAndBackings(PrioritizedResourceManager* resourceManager)
- {
- resourceManager->prioritizeTextures();
- resourceManagerUpdateBackingsPriorities(resourceManager);
+ void PrioritizeTexturesAndBackings(
+ PrioritizedResourceManager* resource_manager) {
+ resource_manager->PrioritizeTextures();
+ ResourceManagerUpdateBackingsPriorities(resource_manager);
}
- void resourceManagerUpdateBackingsPriorities(PrioritizedResourceManager* resourceManager)
- {
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->pushTexturePrioritiesToBackings();
+ void ResourceManagerUpdateBackingsPriorities(
+ PrioritizedResourceManager* resource_manager) {
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->PushTexturePrioritiesToBackings();
}
- ResourceProvider* resourceProvider()
- {
- return m_resourceProvider.get();
- }
+ cc::ResourceProvider* ResourceProvider() { return resource_provider_.get(); }
- void resourceManagerAssertInvariants(PrioritizedResourceManager* resourceManager)
- {
+ void ResourceManagerAssertInvariants(
+ PrioritizedResourceManager* resource_manager) {
#ifndef NDEBUG
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->assertInvariants();
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->AssertInvariants();
#endif
}
- bool textureBackingIsAbovePriorityCutoff(PrioritizedResource* texture)
- {
- return texture->backing()->was_above_priority_cutoff_at_last_priority_update();
+ bool TextureBackingIsAbovePriorityCutoff(PrioritizedResource* texture) {
+ return texture->backing()->
+ was_above_priority_cutoff_at_last_priority_update();
}
- size_t evictedBackingCount(PrioritizedResourceManager* resourceManager)
- {
- return resourceManager->m_evictedBackings.size();
+ size_t EvictedBackingCount(PrioritizedResourceManager* resource_manager) {
+ return resource_manager->evicted_backings_.size();
}
-protected:
- FakeProxy m_proxy;
- const gfx::Size m_textureSize;
- const GLenum m_textureFormat;
- scoped_ptr<OutputSurface> m_outputSurface;
- scoped_ptr<ResourceProvider> m_resourceProvider;
+ protected:
+ FakeProxy proxy_;
+ const gfx::Size texture_size_;
+ const GLenum texture_format_;
+ scoped_ptr<OutputSurface> output_surface_;
+ scoped_ptr<cc::ResourceProvider> resource_provider_;
};
namespace {
-TEST_F(PrioritizedResourceTest, requestTextureExceedingMaxLimit)
-{
- const size_t maxTextures = 8;
- scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTextures);
+TEST_F(PrioritizedResourceTest, RequestTextureExceedingMaxLimit) {
+ const size_t max_textures = 8;
+ scoped_ptr<PrioritizedResourceManager> resource_manager =
+ CreateManager(max_textures);
// Create textures for double our memory limit.
- scoped_ptr<PrioritizedResource> textures[maxTextures*2];
+ scoped_ptr<PrioritizedResource> textures[max_textures * 2];
- for (size_t i = 0; i < maxTextures*2; ++i)
- textures[i] = resourceManager->createTexture(m_textureSize, m_textureFormat);
+ for (size_t i = 0; i < max_textures * 2; ++i)
+ textures[i] =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
// Set decreasing priorities
- for (size_t i = 0; i < maxTextures*2; ++i)
+ for (size_t i = 0; i < max_textures * 2; ++i)
textures[i]->set_request_priority(100 + i);
// Only lower half should be available.
- prioritizeTexturesAndBackings(resourceManager.get());
- EXPECT_TRUE(validateTexture(textures[0], false));
- EXPECT_TRUE(validateTexture(textures[7], false));
- EXPECT_FALSE(validateTexture(textures[8], false));
- EXPECT_FALSE(validateTexture(textures[15], false));
+ PrioritizeTexturesAndBackings(resource_manager.get());
+ EXPECT_TRUE(ValidateTexture(textures[0], false));
+ EXPECT_TRUE(ValidateTexture(textures[7], false));
+ EXPECT_FALSE(ValidateTexture(textures[8], false));
+ EXPECT_FALSE(ValidateTexture(textures[15], false));
// Set increasing priorities
- for (size_t i = 0; i < maxTextures*2; ++i)
+ for (size_t i = 0; i < max_textures * 2; ++i)
textures[i]->set_request_priority(100 - i);
// Only upper half should be available.
- prioritizeTexturesAndBackings(resourceManager.get());
- EXPECT_FALSE(validateTexture(textures[0], false));
- EXPECT_FALSE(validateTexture(textures[7], false));
- EXPECT_TRUE(validateTexture(textures[8], false));
- EXPECT_TRUE(validateTexture(textures[15], false));
-
- EXPECT_EQ(texturesMemorySize(maxTextures), resourceManager->memoryAboveCutoffBytes());
- EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCutoffBytes());
-
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->clearAllMemory(resourceProvider());
+ PrioritizeTexturesAndBackings(resource_manager.get());
+ EXPECT_FALSE(ValidateTexture(textures[0], false));
+ EXPECT_FALSE(ValidateTexture(textures[7], false));
+ EXPECT_TRUE(ValidateTexture(textures[8], false));
+ EXPECT_TRUE(ValidateTexture(textures[15], false));
+
+ EXPECT_EQ(TexturesMemorySize(max_textures),
+ resource_manager->MemoryAboveCutoffBytes());
+ EXPECT_LE(resource_manager->MemoryUseBytes(),
+ resource_manager->MemoryAboveCutoffBytes());
+
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ClearAllMemory(ResourceProvider());
}
-TEST_F(PrioritizedResourceTest, changeMemoryLimits)
-{
- const size_t maxTextures = 8;
- scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTextures);
- scoped_ptr<PrioritizedResource> textures[maxTextures];
+TEST_F(PrioritizedResourceTest, ChangeMemoryLimits) {
+ const size_t max_textures = 8;
+ scoped_ptr<PrioritizedResourceManager> resource_manager =
+ CreateManager(max_textures);
+ scoped_ptr<PrioritizedResource> textures[max_textures];
- for (size_t i = 0; i < maxTextures; ++i)
- textures[i] = resourceManager->createTexture(m_textureSize, m_textureFormat);
- for (size_t i = 0; i < maxTextures; ++i)
+ for (size_t i = 0; i < max_textures; ++i)
+ textures[i] =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
+ for (size_t i = 0; i < max_textures; ++i)
textures[i]->set_request_priority(100 + i);
// Set max limit to 8 textures
- resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(8));
- prioritizeTexturesAndBackings(resourceManager.get());
- for (size_t i = 0; i < maxTextures; ++i)
- validateTexture(textures[i], false);
- {
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->reduceMemory(resourceProvider());
+ resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(8));
+ PrioritizeTexturesAndBackings(resource_manager.get());
+ for (size_t i = 0; i < max_textures; ++i)
+ ValidateTexture(textures[i], false); {
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ReduceMemory(ResourceProvider());
}
- EXPECT_EQ(texturesMemorySize(8), resourceManager->memoryAboveCutoffBytes());
- EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCutoffBytes());
+ EXPECT_EQ(TexturesMemorySize(8),
+ resource_manager->MemoryAboveCutoffBytes());
+ EXPECT_LE(resource_manager->MemoryUseBytes(),
+ resource_manager->MemoryAboveCutoffBytes());
// Set max limit to 5 textures
- resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(5));
- prioritizeTexturesAndBackings(resourceManager.get());
- for (size_t i = 0; i < maxTextures; ++i)
- EXPECT_EQ(validateTexture(textures[i], false), i < 5);
- {
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->reduceMemory(resourceProvider());
+ resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(5));
+ PrioritizeTexturesAndBackings(resource_manager.get());
+ for (size_t i = 0; i < max_textures; ++i)
+ EXPECT_EQ(ValidateTexture(textures[i], false), i < 5); {
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ReduceMemory(ResourceProvider());
}
- EXPECT_EQ(texturesMemorySize(5), resourceManager->memoryAboveCutoffBytes());
- EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCutoffBytes());
+ EXPECT_EQ(TexturesMemorySize(5),
+ resource_manager->MemoryAboveCutoffBytes());
+ EXPECT_LE(resource_manager->MemoryUseBytes(),
+ resource_manager->MemoryAboveCutoffBytes());
// Set max limit to 4 textures
- resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(4));
- prioritizeTexturesAndBackings(resourceManager.get());
- for (size_t i = 0; i < maxTextures; ++i)
- EXPECT_EQ(validateTexture(textures[i], false), i < 4);
- {
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->reduceMemory(resourceProvider());
+ resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(4));
+ PrioritizeTexturesAndBackings(resource_manager.get());
+ for (size_t i = 0; i < max_textures; ++i)
+ EXPECT_EQ(ValidateTexture(textures[i], false), i < 4); {
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ReduceMemory(ResourceProvider());
}
- EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryAboveCutoffBytes());
- EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCutoffBytes());
+ EXPECT_EQ(TexturesMemorySize(4),
+ resource_manager->MemoryAboveCutoffBytes());
+ EXPECT_LE(resource_manager->MemoryUseBytes(),
+ resource_manager->MemoryAboveCutoffBytes());
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->clearAllMemory(resourceProvider());
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ClearAllMemory(ResourceProvider());
}
-TEST_F(PrioritizedResourceTest, changePriorityCutoff)
-{
- const size_t maxTextures = 8;
- scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTextures);
- scoped_ptr<PrioritizedResource> textures[maxTextures];
+TEST_F(PrioritizedResourceTest, ChangePriorityCutoff) {
+ const size_t max_textures = 8;
+ scoped_ptr<PrioritizedResourceManager> resource_manager =
+ CreateManager(max_textures);
+ scoped_ptr<PrioritizedResource> textures[max_textures];
- for (size_t i = 0; i < maxTextures; ++i)
- textures[i] = resourceManager->createTexture(m_textureSize, m_textureFormat);
- for (size_t i = 0; i < maxTextures; ++i)
+ for (size_t i = 0; i < max_textures; ++i)
+ textures[i] =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
+ for (size_t i = 0; i < max_textures; ++i)
textures[i]->set_request_priority(100 + i);
- // Set the cutoff to drop two textures. Try to requestLate on all textures, and
- // make sure that requestLate doesn't work on a texture with equal priority to
- // the cutoff.
- resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(8));
- resourceManager->setExternalPriorityCutoff(106);
- prioritizeTexturesAndBackings(resourceManager.get());
- for (size_t i = 0; i < maxTextures; ++i)
- EXPECT_EQ(validateTexture(textures[i], true), i < 6);
- {
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->reduceMemory(resourceProvider());
+ // Set the cutoff to drop two textures. Try to request_late on all textures,
+ // and make sure that request_late doesn't work on a texture with equal
+ // priority to the cutoff.
+ resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(8));
+ resource_manager->SetExternalPriorityCutoff(106);
+ PrioritizeTexturesAndBackings(resource_manager.get());
+ for (size_t i = 0; i < max_textures; ++i)
+ EXPECT_EQ(ValidateTexture(textures[i], true), i < 6); {
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ReduceMemory(ResourceProvider());
}
- EXPECT_EQ(texturesMemorySize(6), resourceManager->memoryAboveCutoffBytes());
- EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCutoffBytes());
+ EXPECT_EQ(TexturesMemorySize(6),
+ resource_manager->MemoryAboveCutoffBytes());
+ EXPECT_LE(resource_manager->MemoryUseBytes(),
+ resource_manager->MemoryAboveCutoffBytes());
// Set the cutoff to drop two more textures.
- resourceManager->setExternalPriorityCutoff(104);
- prioritizeTexturesAndBackings(resourceManager.get());
- for (size_t i = 0; i < maxTextures; ++i)
- EXPECT_EQ(validateTexture(textures[i], false), i < 4);
- {
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->reduceMemory(resourceProvider());
+ resource_manager->SetExternalPriorityCutoff(104);
+ PrioritizeTexturesAndBackings(resource_manager.get());
+ for (size_t i = 0; i < max_textures; ++i)
+ EXPECT_EQ(ValidateTexture(textures[i], false), i < 4); {
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ReduceMemory(ResourceProvider());
}
- EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryAboveCutoffBytes());
+ EXPECT_EQ(TexturesMemorySize(4),
+ resource_manager->MemoryAboveCutoffBytes());
// Do a one-time eviction for one more texture based on priority cutoff
- PrioritizedResourceManager::BackingList evictedBackings;
- resourceManager->unlinkAndClearEvictedBackings();
- {
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->reduceMemoryOnImplThread(texturesMemorySize(8), 104, resourceProvider());
- EXPECT_EQ(0, evictedBackingCount(resourceManager.get()));
- resourceManager->reduceMemoryOnImplThread(texturesMemorySize(8), 103, resourceProvider());
- EXPECT_EQ(1, evictedBackingCount(resourceManager.get()));
+ PrioritizedResourceManager::BackingList evicted_backings;
+ resource_manager->UnlinkAndClearEvictedBackings(); {
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ReduceMemoryOnImplThread(
+ TexturesMemorySize(8), 104, ResourceProvider());
+ EXPECT_EQ(0, EvictedBackingCount(resource_manager.get()));
+ resource_manager->ReduceMemoryOnImplThread(
+ TexturesMemorySize(8), 103, ResourceProvider());
+ EXPECT_EQ(1, EvictedBackingCount(resource_manager.get()));
}
- resourceManager->unlinkAndClearEvictedBackings();
- EXPECT_EQ(texturesMemorySize(3), resourceManager->memoryUseBytes());
+ resource_manager->UnlinkAndClearEvictedBackings();
+ EXPECT_EQ(TexturesMemorySize(3), resource_manager->MemoryUseBytes());
// Re-allocate the the texture after the one-time drop.
- prioritizeTexturesAndBackings(resourceManager.get());
- for (size_t i = 0; i < maxTextures; ++i)
- EXPECT_EQ(validateTexture(textures[i], false), i < 4);
- {
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->reduceMemory(resourceProvider());
+ PrioritizeTexturesAndBackings(resource_manager.get());
+ for (size_t i = 0; i < max_textures; ++i)
+ EXPECT_EQ(ValidateTexture(textures[i], false), i < 4); {
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ReduceMemory(ResourceProvider());
}
- EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryAboveCutoffBytes());
+ EXPECT_EQ(TexturesMemorySize(4),
+ resource_manager->MemoryAboveCutoffBytes());
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->clearAllMemory(resourceProvider());
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ClearAllMemory(ResourceProvider());
}
-TEST_F(PrioritizedResourceTest, resourceManagerPartialUpdateTextures)
-{
- const size_t maxTextures = 4;
- const size_t numTextures = 4;
- scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTextures);
- scoped_ptr<PrioritizedResource> textures[numTextures];
- scoped_ptr<PrioritizedResource> moreTextures[numTextures];
-
- for (size_t i = 0; i < numTextures; ++i) {
- textures[i] = resourceManager->createTexture(m_textureSize, m_textureFormat);
- moreTextures[i] = resourceManager->createTexture(m_textureSize, m_textureFormat);
+TEST_F(PrioritizedResourceTest, ResourceManagerPartialUpdateTextures) {
+ const size_t max_textures = 4;
+ const size_t num_textures = 4;
+ scoped_ptr<PrioritizedResourceManager> resource_manager =
+ CreateManager(max_textures);
+ scoped_ptr<PrioritizedResource> textures[num_textures];
+ scoped_ptr<PrioritizedResource> more_textures[num_textures];
+
+ for (size_t i = 0; i < num_textures; ++i) {
+ textures[i] =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
+ more_textures[i] =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
}
- for (size_t i = 0; i < numTextures; ++i)
+ for (size_t i = 0; i < num_textures; ++i)
textures[i]->set_request_priority(200 + i);
- prioritizeTexturesAndBackings(resourceManager.get());
+ PrioritizeTexturesAndBackings(resource_manager.get());
// Allocate textures which are currently high priority.
- EXPECT_TRUE(validateTexture(textures[0], false));
- EXPECT_TRUE(validateTexture(textures[1], false));
- EXPECT_TRUE(validateTexture(textures[2], false));
- EXPECT_TRUE(validateTexture(textures[3], false));
+ EXPECT_TRUE(ValidateTexture(textures[0], false));
+ EXPECT_TRUE(ValidateTexture(textures[1], false));
+ EXPECT_TRUE(ValidateTexture(textures[2], false));
+ EXPECT_TRUE(ValidateTexture(textures[3], false));
EXPECT_TRUE(textures[0]->have_backing_texture());
EXPECT_TRUE(textures[1]->have_backing_texture());
EXPECT_TRUE(textures[2]->have_backing_texture());
EXPECT_TRUE(textures[3]->have_backing_texture());
- for (size_t i = 0; i < numTextures; ++i)
- moreTextures[i]->set_request_priority(100 + i);
- prioritizeTexturesAndBackings(resourceManager.get());
+ for (size_t i = 0; i < num_textures; ++i)
+ more_textures[i]->set_request_priority(100 + i);
+ PrioritizeTexturesAndBackings(resource_manager.get());
// Textures are now below cutoff.
- EXPECT_FALSE(validateTexture(textures[0], false));
- EXPECT_FALSE(validateTexture(textures[1], false));
- EXPECT_FALSE(validateTexture(textures[2], false));
- EXPECT_FALSE(validateTexture(textures[3], false));
+ EXPECT_FALSE(ValidateTexture(textures[0], false));
+ EXPECT_FALSE(ValidateTexture(textures[1], false));
+ EXPECT_FALSE(ValidateTexture(textures[2], false));
+ EXPECT_FALSE(ValidateTexture(textures[3], false));
// But they are still valid to use.
EXPECT_TRUE(textures[0]->have_backing_texture());
@@ -305,10 +324,10 @@ TEST_F(PrioritizedResourceTest, resourceManagerPartialUpdateTextures)
EXPECT_TRUE(textures[3]->have_backing_texture());
// Higher priority textures are finally needed.
- EXPECT_TRUE(validateTexture(moreTextures[0], false));
- EXPECT_TRUE(validateTexture(moreTextures[1], false));
- EXPECT_TRUE(validateTexture(moreTextures[2], false));
- EXPECT_TRUE(validateTexture(moreTextures[3], false));
+ EXPECT_TRUE(ValidateTexture(more_textures[0], false));
+ EXPECT_TRUE(ValidateTexture(more_textures[1], false));
+ EXPECT_TRUE(ValidateTexture(more_textures[2], false));
+ EXPECT_TRUE(ValidateTexture(more_textures[3], false));
// Lower priority have been fully evicted.
EXPECT_FALSE(textures[0]->have_backing_texture());
@@ -316,391 +335,455 @@ TEST_F(PrioritizedResourceTest, resourceManagerPartialUpdateTextures)
EXPECT_FALSE(textures[2]->have_backing_texture());
EXPECT_FALSE(textures[3]->have_backing_texture());
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->clearAllMemory(resourceProvider());
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ClearAllMemory(ResourceProvider());
}
-TEST_F(PrioritizedResourceTest, resourceManagerPrioritiesAreEqual)
-{
- const size_t maxTextures = 16;
- scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTextures);
- scoped_ptr<PrioritizedResource> textures[maxTextures];
+TEST_F(PrioritizedResourceTest, ResourceManagerPrioritiesAreEqual) {
+ const size_t max_textures = 16;
+ scoped_ptr<PrioritizedResourceManager> resource_manager =
+ CreateManager(max_textures);
+ scoped_ptr<PrioritizedResource> textures[max_textures];
- for (size_t i = 0; i < maxTextures; ++i)
- textures[i] = resourceManager->createTexture(m_textureSize, m_textureFormat);
+ for (size_t i = 0; i < max_textures; ++i)
+ textures[i] =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
// All 16 textures have the same priority except 2 higher priority.
- for (size_t i = 0; i < maxTextures; ++i)
+ for (size_t i = 0; i < max_textures; ++i)
textures[i]->set_request_priority(100);
textures[0]->set_request_priority(99);
textures[1]->set_request_priority(99);
// Set max limit to 8 textures
- resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(8));
- prioritizeTexturesAndBackings(resourceManager.get());
+ resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(8));
+ PrioritizeTexturesAndBackings(resource_manager.get());
// The two high priority textures should be available, others should not.
for (size_t i = 0; i < 2; ++i)
- EXPECT_TRUE(validateTexture(textures[i], false));
- for (size_t i = 2; i < maxTextures; ++i)
- EXPECT_FALSE(validateTexture(textures[i], false));
- EXPECT_EQ(texturesMemorySize(2), resourceManager->memoryAboveCutoffBytes());
- EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCutoffBytes());
-
- // Manually reserving textures should only succeed on the higher priority textures,
- // and on remaining textures up to the memory limit.
+ EXPECT_TRUE(ValidateTexture(textures[i], false));
+ for (size_t i = 2; i < max_textures; ++i)
+ EXPECT_FALSE(ValidateTexture(textures[i], false));
+ EXPECT_EQ(TexturesMemorySize(2),
+ resource_manager->MemoryAboveCutoffBytes());
+ EXPECT_LE(resource_manager->MemoryUseBytes(),
+ resource_manager->MemoryAboveCutoffBytes());
+
+ // Manually reserving textures should only succeed on the higher priority
+ // textures, and on remaining textures up to the memory limit.
for (size_t i = 0; i < 8; i++)
- EXPECT_TRUE(validateTexture(textures[i], true));
- for (size_t i = 9; i < maxTextures; i++)
- EXPECT_FALSE(validateTexture(textures[i], true));
- EXPECT_EQ(texturesMemorySize(8), resourceManager->memoryAboveCutoffBytes());
- EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCutoffBytes());
-
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->clearAllMemory(resourceProvider());
+ EXPECT_TRUE(ValidateTexture(textures[i], true));
+ for (size_t i = 9; i < max_textures; i++)
+ EXPECT_FALSE(ValidateTexture(textures[i], true));
+ EXPECT_EQ(TexturesMemorySize(8),
+ resource_manager->MemoryAboveCutoffBytes());
+ EXPECT_LE(resource_manager->MemoryUseBytes(),
+ resource_manager->MemoryAboveCutoffBytes());
+
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ClearAllMemory(ResourceProvider());
}
-TEST_F(PrioritizedResourceTest, resourceManagerDestroyedFirst)
-{
- scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(1);
- scoped_ptr<PrioritizedResource> texture = resourceManager->createTexture(m_textureSize, m_textureFormat);
+TEST_F(PrioritizedResourceTest, ResourceManagerDestroyedFirst) {
+ scoped_ptr<PrioritizedResourceManager> resource_manager = CreateManager(1);
+ scoped_ptr<PrioritizedResource> texture =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
// Texture is initially invalid, but it will become available.
EXPECT_FALSE(texture->have_backing_texture());
texture->set_request_priority(100);
- prioritizeTexturesAndBackings(resourceManager.get());
+ PrioritizeTexturesAndBackings(resource_manager.get());
- EXPECT_TRUE(validateTexture(texture, false));
+ EXPECT_TRUE(ValidateTexture(texture, false));
EXPECT_TRUE(texture->can_acquire_backing_texture());
- EXPECT_TRUE(texture->have_backing_texture());
-
- {
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->clearAllMemory(resourceProvider());
+ EXPECT_TRUE(texture->have_backing_texture()); {
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ClearAllMemory(ResourceProvider());
}
- resourceManager.reset();
+ resource_manager.reset();
EXPECT_FALSE(texture->can_acquire_backing_texture());
EXPECT_FALSE(texture->have_backing_texture());
}
-TEST_F(PrioritizedResourceTest, textureMovedToNewManager)
-{
- scoped_ptr<PrioritizedResourceManager> resourceManagerOne = createManager(1);
- scoped_ptr<PrioritizedResourceManager> resourceManagerTwo = createManager(1);
- scoped_ptr<PrioritizedResource> texture = resourceManagerOne->createTexture(m_textureSize, m_textureFormat);
+TEST_F(PrioritizedResourceTest, TextureMovedToNewManager) {
+ scoped_ptr<PrioritizedResourceManager> resource_manager_one =
+ CreateManager(1);
+ scoped_ptr<PrioritizedResourceManager> resource_manager_two =
+ CreateManager(1);
+ scoped_ptr<PrioritizedResource> texture =
+ resource_manager_one->CreateTexture(texture_size_, texture_format_);
// Texture is initially invalid, but it will become available.
EXPECT_FALSE(texture->have_backing_texture());
texture->set_request_priority(100);
- prioritizeTexturesAndBackings(resourceManagerOne.get());
+ PrioritizeTexturesAndBackings(resource_manager_one.get());
- EXPECT_TRUE(validateTexture(texture, false));
+ EXPECT_TRUE(ValidateTexture(texture, false));
EXPECT_TRUE(texture->can_acquire_backing_texture());
EXPECT_TRUE(texture->have_backing_texture());
- texture->SetTextureManager(0);
-
- {
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManagerOne->clearAllMemory(resourceProvider());
+ texture->SetTextureManager(0); {
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager_one->ClearAllMemory(ResourceProvider());
}
- resourceManagerOne.reset();
+ resource_manager_one.reset();
EXPECT_FALSE(texture->can_acquire_backing_texture());
EXPECT_FALSE(texture->have_backing_texture());
- texture->SetTextureManager(resourceManagerTwo.get());
+ texture->SetTextureManager(resource_manager_two.get());
- prioritizeTexturesAndBackings(resourceManagerTwo.get());
+ PrioritizeTexturesAndBackings(resource_manager_two.get());
- EXPECT_TRUE(validateTexture(texture, false));
+ EXPECT_TRUE(ValidateTexture(texture, false));
EXPECT_TRUE(texture->can_acquire_backing_texture());
EXPECT_TRUE(texture->have_backing_texture());
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManagerTwo->clearAllMemory(resourceProvider());
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager_two->ClearAllMemory(ResourceProvider());
}
-TEST_F(PrioritizedResourceTest, renderSurfacesReduceMemoryAvailableOutsideRootSurface)
-{
- const size_t maxTextures = 8;
- scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTextures);
+TEST_F(PrioritizedResourceTest,
+ RenderSurfacesReduceMemoryAvailableOutsideRootSurface) {
+ const size_t max_textures = 8;
+ scoped_ptr<PrioritizedResourceManager> resource_manager =
+ CreateManager(max_textures);
// Half of the memory is taken by surfaces (with high priority place-holder)
- scoped_ptr<PrioritizedResource> renderSurfacePlaceHolder = resourceManager->createTexture(m_textureSize, m_textureFormat);
- renderSurfacePlaceHolder->SetToSelfManagedMemoryPlaceholder(texturesMemorySize(4));
- renderSurfacePlaceHolder->set_request_priority(PriorityCalculator::RenderSurfacePriority());
+ scoped_ptr<PrioritizedResource> render_surface_place_holder =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
+ render_surface_place_holder->SetToSelfManagedMemoryPlaceholder(
+ TexturesMemorySize(4));
+ render_surface_place_holder->set_request_priority(
+ PriorityCalculator::RenderSurfacePriority());
// Create textures to fill our memory limit.
- scoped_ptr<PrioritizedResource> textures[maxTextures];
+ scoped_ptr<PrioritizedResource> textures[max_textures];
- for (size_t i = 0; i < maxTextures; ++i)
- textures[i] = resourceManager->createTexture(m_textureSize, m_textureFormat);
+ for (size_t i = 0; i < max_textures; ++i)
+ textures[i] =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
// Set decreasing non-visible priorities outside root surface.
- for (size_t i = 0; i < maxTextures; ++i)
+ for (size_t i = 0; i < max_textures; ++i)
textures[i]->set_request_priority(100 + i);
// Only lower half should be available.
- prioritizeTexturesAndBackings(resourceManager.get());
- EXPECT_TRUE(validateTexture(textures[0], false));
- EXPECT_TRUE(validateTexture(textures[3], false));
- EXPECT_FALSE(validateTexture(textures[4], false));
- EXPECT_FALSE(validateTexture(textures[7], false));
+ PrioritizeTexturesAndBackings(resource_manager.get());
+ EXPECT_TRUE(ValidateTexture(textures[0], false));
+ EXPECT_TRUE(ValidateTexture(textures[3], false));
+ EXPECT_FALSE(ValidateTexture(textures[4], false));
+ EXPECT_FALSE(ValidateTexture(textures[7], false));
// Set increasing non-visible priorities outside root surface.
- for (size_t i = 0; i < maxTextures; ++i)
+ for (size_t i = 0; i < max_textures; ++i)
textures[i]->set_request_priority(100 - i);
// Only upper half should be available.
- prioritizeTexturesAndBackings(resourceManager.get());
- EXPECT_FALSE(validateTexture(textures[0], false));
- EXPECT_FALSE(validateTexture(textures[3], false));
- EXPECT_TRUE(validateTexture(textures[4], false));
- EXPECT_TRUE(validateTexture(textures[7], false));
-
- EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryAboveCutoffBytes());
- EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryForSelfManagedTextures());
- EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCutoffBytes());
-
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->clearAllMemory(resourceProvider());
+ PrioritizeTexturesAndBackings(resource_manager.get());
+ EXPECT_FALSE(ValidateTexture(textures[0], false));
+ EXPECT_FALSE(ValidateTexture(textures[3], false));
+ EXPECT_TRUE(ValidateTexture(textures[4], false));
+ EXPECT_TRUE(ValidateTexture(textures[7], false));
+
+ EXPECT_EQ(TexturesMemorySize(4),
+ resource_manager->MemoryAboveCutoffBytes());
+ EXPECT_EQ(TexturesMemorySize(4),
+ resource_manager->MemoryForSelfManagedTextures());
+ EXPECT_LE(resource_manager->MemoryUseBytes(),
+ resource_manager->MemoryAboveCutoffBytes());
+
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ClearAllMemory(ResourceProvider());
}
-TEST_F(PrioritizedResourceTest, renderSurfacesReduceMemoryAvailableForRequestLate)
-{
- const size_t maxTextures = 8;
- scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTextures);
+TEST_F(PrioritizedResourceTest,
+ RenderSurfacesReduceMemoryAvailableForRequestLate) {
+ const size_t max_textures = 8;
+ scoped_ptr<PrioritizedResourceManager> resource_manager =
+ CreateManager(max_textures);
// Half of the memory is taken by surfaces (with high priority place-holder)
- scoped_ptr<PrioritizedResource> renderSurfacePlaceHolder = resourceManager->createTexture(m_textureSize, m_textureFormat);
- renderSurfacePlaceHolder->SetToSelfManagedMemoryPlaceholder(texturesMemorySize(4));
- renderSurfacePlaceHolder->set_request_priority(PriorityCalculator::RenderSurfacePriority());
+ scoped_ptr<PrioritizedResource> render_surface_place_holder =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
+ render_surface_place_holder->SetToSelfManagedMemoryPlaceholder(
+ TexturesMemorySize(4));
+ render_surface_place_holder->set_request_priority(
+ PriorityCalculator::RenderSurfacePriority());
// Create textures to fill our memory limit.
- scoped_ptr<PrioritizedResource> textures[maxTextures];
+ scoped_ptr<PrioritizedResource> textures[max_textures];
- for (size_t i = 0; i < maxTextures; ++i)
- textures[i] = resourceManager->createTexture(m_textureSize, m_textureFormat);
+ for (size_t i = 0; i < max_textures; ++i)
+ textures[i] =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
// Set equal priorities.
- for (size_t i = 0; i < maxTextures; ++i)
+ for (size_t i = 0; i < max_textures; ++i)
textures[i]->set_request_priority(100);
// The first four to be requested late will be available.
- prioritizeTexturesAndBackings(resourceManager.get());
- for (unsigned i = 0; i < maxTextures; ++i)
- EXPECT_FALSE(validateTexture(textures[i], false));
- for (unsigned i = 0; i < maxTextures; i += 2)
- EXPECT_TRUE(validateTexture(textures[i], true));
- for (unsigned i = 1; i < maxTextures; i += 2)
- EXPECT_FALSE(validateTexture(textures[i], true));
-
- EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryAboveCutoffBytes());
- EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryForSelfManagedTextures());
- EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCutoffBytes());
-
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->clearAllMemory(resourceProvider());
+ PrioritizeTexturesAndBackings(resource_manager.get());
+ for (unsigned i = 0; i < max_textures; ++i)
+ EXPECT_FALSE(ValidateTexture(textures[i], false));
+ for (unsigned i = 0; i < max_textures; i += 2)
+ EXPECT_TRUE(ValidateTexture(textures[i], true));
+ for (unsigned i = 1; i < max_textures; i += 2)
+ EXPECT_FALSE(ValidateTexture(textures[i], true));
+
+ EXPECT_EQ(TexturesMemorySize(4),
+ resource_manager->MemoryAboveCutoffBytes());
+ EXPECT_EQ(TexturesMemorySize(4),
+ resource_manager->MemoryForSelfManagedTextures());
+ EXPECT_LE(resource_manager->MemoryUseBytes(),
+ resource_manager->MemoryAboveCutoffBytes());
+
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ClearAllMemory(ResourceProvider());
}
-TEST_F(PrioritizedResourceTest, whenRenderSurfaceNotAvailableTexturesAlsoNotAvailable)
-{
- const size_t maxTextures = 8;
- scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTextures);
+TEST_F(PrioritizedResourceTest,
+ WhenRenderSurfaceNotAvailableTexturesAlsoNotAvailable) {
+ const size_t max_textures = 8;
+ scoped_ptr<PrioritizedResourceManager> resource_manager =
+ CreateManager(max_textures);
// Half of the memory is taken by surfaces (with high priority place-holder)
- scoped_ptr<PrioritizedResource> renderSurfacePlaceHolder = resourceManager->createTexture(m_textureSize, m_textureFormat);
- renderSurfacePlaceHolder->SetToSelfManagedMemoryPlaceholder(texturesMemorySize(4));
- renderSurfacePlaceHolder->set_request_priority(PriorityCalculator::RenderSurfacePriority());
+ scoped_ptr<PrioritizedResource> render_surface_place_holder =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
+ render_surface_place_holder->SetToSelfManagedMemoryPlaceholder(
+ TexturesMemorySize(4));
+ render_surface_place_holder->set_request_priority(
+ PriorityCalculator::RenderSurfacePriority());
// Create textures to fill our memory limit.
- scoped_ptr<PrioritizedResource> textures[maxTextures];
+ scoped_ptr<PrioritizedResource> textures[max_textures];
- for (size_t i = 0; i < maxTextures; ++i)
- textures[i] = resourceManager->createTexture(m_textureSize, m_textureFormat);
+ for (size_t i = 0; i < max_textures; ++i)
+ textures[i] =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
// Set 6 visible textures in the root surface, and 2 in a child surface.
for (size_t i = 0; i < 6; ++i)
- textures[i]->set_request_priority(PriorityCalculator::VisiblePriority(true));
+ textures[i]->
+ set_request_priority(PriorityCalculator::VisiblePriority(true));
for (size_t i = 6; i < 8; ++i)
- textures[i]->set_request_priority(PriorityCalculator::VisiblePriority(false));
+ textures[i]->
+ set_request_priority(PriorityCalculator::VisiblePriority(false));
- prioritizeTexturesAndBackings(resourceManager.get());
+ PrioritizeTexturesAndBackings(resource_manager.get());
- // Unable to requestLate textures in the child surface.
- EXPECT_FALSE(validateTexture(textures[6], true));
- EXPECT_FALSE(validateTexture(textures[7], true));
+ // Unable to request_late textures in the child surface.
+ EXPECT_FALSE(ValidateTexture(textures[6], true));
+ EXPECT_FALSE(ValidateTexture(textures[7], true));
// Root surface textures are valid.
for (size_t i = 0; i < 6; ++i)
- EXPECT_TRUE(validateTexture(textures[i], false));
-
- EXPECT_EQ(texturesMemorySize(6), resourceManager->memoryAboveCutoffBytes());
- EXPECT_EQ(texturesMemorySize(2), resourceManager->memoryForSelfManagedTextures());
- EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCutoffBytes());
-
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->clearAllMemory(resourceProvider());
+ EXPECT_TRUE(ValidateTexture(textures[i], false));
+
+ EXPECT_EQ(TexturesMemorySize(6),
+ resource_manager->MemoryAboveCutoffBytes());
+ EXPECT_EQ(TexturesMemorySize(2),
+ resource_manager->MemoryForSelfManagedTextures());
+ EXPECT_LE(resource_manager->MemoryUseBytes(),
+ resource_manager->MemoryAboveCutoffBytes());
+
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ClearAllMemory(ResourceProvider());
}
-TEST_F(PrioritizedResourceTest, requestLateBackingsSorting)
-{
- const size_t maxTextures = 8;
- scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTextures);
- resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures));
+TEST_F(PrioritizedResourceTest, RequestLateBackingsSorting) {
+ const size_t max_textures = 8;
+ scoped_ptr<PrioritizedResourceManager> resource_manager =
+ CreateManager(max_textures);
+ resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(max_textures));
// Create textures to fill our memory limit.
- scoped_ptr<PrioritizedResource> textures[maxTextures];
- for (size_t i = 0; i < maxTextures; ++i)
- textures[i] = resourceManager->createTexture(m_textureSize, m_textureFormat);
+ scoped_ptr<PrioritizedResource> textures[max_textures];
+ for (size_t i = 0; i < max_textures; ++i)
+ textures[i] =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
// Set equal priorities, and allocate backings for all textures.
- for (size_t i = 0; i < maxTextures; ++i)
+ for (size_t i = 0; i < max_textures; ++i)
textures[i]->set_request_priority(100);
- prioritizeTexturesAndBackings(resourceManager.get());
- for (unsigned i = 0; i < maxTextures; ++i)
- EXPECT_TRUE(validateTexture(textures[i], false));
+ PrioritizeTexturesAndBackings(resource_manager.get());
+ for (unsigned i = 0; i < max_textures; ++i)
+ EXPECT_TRUE(ValidateTexture(textures[i], false));
// Drop the memory limit and prioritize (none will be above the threshold,
// but they still have backings because reduceMemory hasn't been called).
- resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures / 2));
- prioritizeTexturesAndBackings(resourceManager.get());
+ resource_manager->SetMaxMemoryLimitBytes(
+ TexturesMemorySize(max_textures / 2));
+ PrioritizeTexturesAndBackings(resource_manager.get());
// Push half of them back over the limit.
- for (size_t i = 0; i < maxTextures; i += 2)
+ for (size_t i = 0; i < max_textures; i += 2)
EXPECT_TRUE(textures[i]->RequestLate());
// Push the priorities to the backings array and sort the backings array
- resourceManagerUpdateBackingsPriorities(resourceManager.get());
+ ResourceManagerUpdateBackingsPriorities(resource_manager.get());
// Assert that the backings list be sorted with the below-limit backings
// before the above-limit backings.
- resourceManagerAssertInvariants(resourceManager.get());
+ ResourceManagerAssertInvariants(resource_manager.get());
// Make sure that we have backings for all of the textures.
- for (size_t i = 0; i < maxTextures; ++i)
+ for (size_t i = 0; i < max_textures; ++i)
EXPECT_TRUE(textures[i]->have_backing_texture());
- // Make sure that only the requestLate textures are above the priority cutoff
- for (size_t i = 0; i < maxTextures; i += 2)
- EXPECT_TRUE(textureBackingIsAbovePriorityCutoff(textures[i].get()));
- for (size_t i = 1; i < maxTextures; i += 2)
- EXPECT_FALSE(textureBackingIsAbovePriorityCutoff(textures[i].get()));
+ // Make sure that only the request_late textures are above the priority
+ // cutoff
+ for (size_t i = 0; i < max_textures; i += 2)
+ EXPECT_TRUE(TextureBackingIsAbovePriorityCutoff(textures[i].get()));
+ for (size_t i = 1; i < max_textures; i += 2)
+ EXPECT_FALSE(TextureBackingIsAbovePriorityCutoff(textures[i].get()));
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->clearAllMemory(resourceProvider());
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ resource_manager->ClearAllMemory(ResourceProvider());
}
-TEST_F(PrioritizedResourceTest, clearUploadsToEvictedResources)
-{
- const size_t maxTextures = 4;
- scoped_ptr<PrioritizedResourceManager> resourceManager =
- createManager(maxTextures);
- resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures));
+TEST_F(PrioritizedResourceTest, ClearUploadsToEvictedResources) {
+ const size_t max_textures = 4;
+ scoped_ptr<PrioritizedResourceManager> resource_manager =
+ CreateManager(max_textures);
+ resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(max_textures));
// Create textures to fill our memory limit.
- scoped_ptr<PrioritizedResource> textures[maxTextures];
+ scoped_ptr<PrioritizedResource> textures[max_textures];
- for (size_t i = 0; i < maxTextures; ++i)
- textures[i] = resourceManager->createTexture(m_textureSize, m_textureFormat);
+ for (size_t i = 0; i < max_textures; ++i)
+ textures[i] =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
// Set equal priorities, and allocate backings for all textures.
- for (size_t i = 0; i < maxTextures; ++i)
+ for (size_t i = 0; i < max_textures; ++i)
textures[i]->set_request_priority(100);
- prioritizeTexturesAndBackings(resourceManager.get());
- for (unsigned i = 0; i < maxTextures; ++i)
- EXPECT_TRUE(validateTexture(textures[i], false));
+ PrioritizeTexturesAndBackings(resource_manager.get());
+ for (unsigned i = 0; i < max_textures; ++i)
+ EXPECT_TRUE(ValidateTexture(textures[i], false));
ResourceUpdateQueue queue;
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- for (size_t i = 0; i < maxTextures; ++i) {
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked(&proxy_);
+ for (size_t i = 0; i < max_textures; ++i) {
const ResourceUpdate upload = ResourceUpdate::Create(
textures[i].get(), NULL, gfx::Rect(), gfx::Rect(), gfx::Vector2d());
queue.appendFullUpload(upload);
}
// Make sure that we have backings for all of the textures.
- for (size_t i = 0; i < maxTextures; ++i)
+ for (size_t i = 0; i < max_textures; ++i)
EXPECT_TRUE(textures[i]->have_backing_texture());
queue.clearUploadsToEvictedResources();
EXPECT_EQ(4, queue.fullUploadSize());
- resourceManager->reduceMemoryOnImplThread(
- texturesMemorySize(1), PriorityCalculator::AllowEverythingCutoff(), resourceProvider());
+ resource_manager->ReduceMemoryOnImplThread(
+ TexturesMemorySize(1),
+ PriorityCalculator::AllowEverythingCutoff(),
+ ResourceProvider());
queue.clearUploadsToEvictedResources();
EXPECT_EQ(1, queue.fullUploadSize());
- resourceManager->reduceMemoryOnImplThread(0, PriorityCalculator::AllowEverythingCutoff(), resourceProvider());
+ resource_manager->ReduceMemoryOnImplThread(
+ 0, PriorityCalculator::AllowEverythingCutoff(), ResourceProvider());
queue.clearUploadsToEvictedResources();
EXPECT_EQ(0, queue.fullUploadSize());
}
-TEST_F(PrioritizedResourceTest, usageStatistics)
-{
- const size_t maxTextures = 5;
- scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTextures);
- scoped_ptr<PrioritizedResource> textures[maxTextures];
-
- for (size_t i = 0; i < maxTextures; ++i)
- textures[i] = resourceManager->createTexture(m_textureSize, m_textureFormat);
-
- textures[0]->set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff() - 1);
- textures[1]->set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff());
- textures[2]->set_request_priority(PriorityCalculator::AllowVisibleAndNearbyCutoff() - 1);
- textures[3]->set_request_priority(PriorityCalculator::AllowVisibleAndNearbyCutoff());
- textures[4]->set_request_priority(PriorityCalculator::AllowVisibleAndNearbyCutoff() + 1);
+TEST_F(PrioritizedResourceTest, UsageStatistics) {
+ const size_t max_textures = 5;
+ scoped_ptr<PrioritizedResourceManager> resource_manager =
+ CreateManager(max_textures);
+ scoped_ptr<PrioritizedResource> textures[max_textures];
+
+ for (size_t i = 0; i < max_textures; ++i)
+ textures[i] =
+ resource_manager->CreateTexture(texture_size_, texture_format_);
+
+ textures[0]->set_request_priority(
+ PriorityCalculator::AllowVisibleOnlyCutoff() - 1);
+ textures[1]->
+ set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff());
+ textures[2]->set_request_priority(
+ PriorityCalculator::AllowVisibleAndNearbyCutoff() - 1);
+ textures[3]->set_request_priority(
+ PriorityCalculator::AllowVisibleAndNearbyCutoff());
+ textures[4]->set_request_priority(
+ PriorityCalculator::AllowVisibleAndNearbyCutoff() + 1);
// Set max limit to 2 textures.
- resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(2));
- prioritizeTexturesAndBackings(resourceManager.get());
+ resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(2));
+ PrioritizeTexturesAndBackings(resource_manager.get());
// The first two textures should be available, others should not.
for (size_t i = 0; i < 2; ++i)
- EXPECT_TRUE(validateTexture(textures[i], false));
- for (size_t i = 2; i < maxTextures; ++i)
- EXPECT_FALSE(validateTexture(textures[i], false));
+ EXPECT_TRUE(ValidateTexture(textures[i], false));
+ for (size_t i = 2; i < max_textures; ++i)
+ EXPECT_FALSE(ValidateTexture(textures[i], false));
// Validate the statistics.
{
- DebugScopedSetImplThread implThread(&m_proxy);
- EXPECT_EQ(texturesMemorySize(2), resourceManager->memoryUseBytes());
- EXPECT_EQ(texturesMemorySize(1), resourceManager->memoryVisibleBytes());
- EXPECT_EQ(texturesMemorySize(3), resourceManager->memoryVisibleAndNearbyBytes());
+ DebugScopedSetImplThread impl_thread(&proxy_);
+ EXPECT_EQ(TexturesMemorySize(2), resource_manager->MemoryUseBytes());
+ EXPECT_EQ(TexturesMemorySize(1),
+ resource_manager->MemoryVisibleBytes());
+ EXPECT_EQ(TexturesMemorySize(3),
+ resource_manager->MemoryVisibleAndNearbyBytes());
}
// Re-prioritize the textures, but do not push the values to backings.
- textures[0]->set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff() - 1);
- textures[1]->set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff() - 1);
- textures[2]->set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff() - 1);
- textures[3]->set_request_priority(PriorityCalculator::AllowVisibleAndNearbyCutoff() - 1);
- textures[4]->set_request_priority(PriorityCalculator::AllowVisibleAndNearbyCutoff());
- resourceManager->prioritizeTextures();
+ textures[0]->set_request_priority(
+ PriorityCalculator::AllowVisibleOnlyCutoff() - 1);
+ textures[1]->set_request_priority(
+ PriorityCalculator::AllowVisibleOnlyCutoff() - 1);
+ textures[2]->set_request_priority(
+ PriorityCalculator::AllowVisibleOnlyCutoff() - 1);
+ textures[3]->set_request_priority(
+ PriorityCalculator::AllowVisibleAndNearbyCutoff() - 1);
+ textures[4]->set_request_priority(
+ PriorityCalculator::AllowVisibleAndNearbyCutoff());
+ resource_manager->PrioritizeTextures();
// Verify that we still see the old values.
{
- DebugScopedSetImplThread implThread(&m_proxy);
- EXPECT_EQ(texturesMemorySize(2), resourceManager->memoryUseBytes());
- EXPECT_EQ(texturesMemorySize(1), resourceManager->memoryVisibleBytes());
- EXPECT_EQ(texturesMemorySize(3), resourceManager->memoryVisibleAndNearbyBytes());
+ DebugScopedSetImplThread impl_thread (& proxy_);
+ EXPECT_EQ(TexturesMemorySize(2), resource_manager->MemoryUseBytes());
+ EXPECT_EQ(TexturesMemorySize(1),
+ resource_manager->MemoryVisibleBytes());
+ EXPECT_EQ(TexturesMemorySize(3),
+ resource_manager->MemoryVisibleAndNearbyBytes());
}
// Push priorities to backings, and verify we see the new values.
{
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->pushTexturePrioritiesToBackings();
- EXPECT_EQ(texturesMemorySize(2), resourceManager->memoryUseBytes());
- EXPECT_EQ(texturesMemorySize(3), resourceManager->memoryVisibleBytes());
- EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryVisibleAndNearbyBytes());
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked (& proxy_);
+ resource_manager->PushTexturePrioritiesToBackings();
+ EXPECT_EQ(TexturesMemorySize(2), resource_manager->MemoryUseBytes());
+ EXPECT_EQ(TexturesMemorySize(3),
+ resource_manager->MemoryVisibleBytes());
+ EXPECT_EQ(TexturesMemorySize(4),
+ resource_manager->MemoryVisibleAndNearbyBytes());
}
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy);
- resourceManager->clearAllMemory(resourceProvider());
+ DebugScopedSetImplThreadAndMainThreadBlocked
+ impl_thread_and_main_thread_blocked (& proxy_);
+ resource_manager->ClearAllMemory(ResourceProvider());
}
} // namespace
diff --git a/cc/resources/resource_update_controller_unittest.cc b/cc/resources/resource_update_controller_unittest.cc
index 708f3d9..be87115 100644
--- a/cc/resources/resource_update_controller_unittest.cc
+++ b/cc/resources/resource_update_controller_unittest.cc
@@ -63,9 +63,9 @@ private:
class ResourceUpdateControllerTest : public Test {
public:
ResourceUpdateControllerTest()
- : m_proxy(scoped_ptr<Thread>(NULL))
+ : proxy_(scoped_ptr<Thread>(NULL))
, m_queue(make_scoped_ptr(new ResourceUpdateQueue))
- , m_resourceManager(PrioritizedResourceManager::create(&m_proxy))
+ , m_resourceManager(PrioritizedResourceManager::Create(&proxy_))
, m_fullUploadCountExpected(0)
, m_partialCountExpected(0)
, m_totalUploadCountExpected(0)
@@ -81,8 +81,8 @@ public:
virtual ~ResourceUpdateControllerTest()
{
DebugScopedSetImplThreadAndMainThreadBlocked
- implThreadAndMainThreadBlocked(&m_proxy);
- m_resourceManager->clearAllMemory(m_resourceProvider.get());
+ implThreadAndMainThreadBlocked(&proxy_);
+ m_resourceManager->ClearAllMemory(m_resourceProvider.get());
}
public:
@@ -126,12 +126,12 @@ protected:
m_bitmap.allocPixels();
for (int i = 0; i < 4; i++) {
- m_textures[i] = PrioritizedResource::Create(
+ textures_[i] = PrioritizedResource::Create(
m_resourceManager.get(), gfx::Size(300, 150), GL_RGBA);
- m_textures[i]->set_request_priority(
+ textures_[i]->set_request_priority(
PriorityCalculator::VisiblePriority(true));
}
- m_resourceManager->prioritizeTextures();
+ m_resourceManager->PrioritizeTextures();
m_resourceProvider = ResourceProvider::Create(m_outputSurface.get());
}
@@ -144,7 +144,7 @@ protected:
const gfx::Rect rect(0, 0, 300, 150);
const ResourceUpdate upload = ResourceUpdate::Create(
- m_textures[textureIndex].get(), &m_bitmap, rect, rect, gfx::Vector2d());
+ textures_[textureIndex].get(), &m_bitmap, rect, rect, gfx::Vector2d());
for (int i = 0; i < count; i++)
m_queue->appendFullUpload(upload);
}
@@ -161,7 +161,7 @@ protected:
const gfx::Rect rect(0, 0, 100, 100);
const ResourceUpdate upload = ResourceUpdate::Create(
- m_textures[textureIndex].get(), &m_bitmap, rect, rect, gfx::Vector2d());
+ textures_[textureIndex].get(), &m_bitmap, rect, rect, gfx::Vector2d());
for (int i = 0; i < count; i++)
m_queue->appendPartialUpload(upload);
}
@@ -179,11 +179,11 @@ protected:
void updateTextures()
{
DebugScopedSetImplThreadAndMainThreadBlocked
- implThreadAndMainThreadBlocked(&m_proxy);
+ implThreadAndMainThreadBlocked(&proxy_);
scoped_ptr<ResourceUpdateController> updateController =
ResourceUpdateController::Create(
NULL,
- m_proxy.ImplThread(),
+ proxy_.ImplThread(),
m_queue.Pass(),
m_resourceProvider.get());
updateController->Finalize();
@@ -196,11 +196,11 @@ protected:
protected:
// Classes required to interact and test the ResourceUpdateController
- FakeProxy m_proxy;
+ FakeProxy proxy_;
scoped_ptr<OutputSurface> m_outputSurface;
scoped_ptr<ResourceProvider> m_resourceProvider;
scoped_ptr<ResourceUpdateQueue> m_queue;
- scoped_ptr<PrioritizedResource> m_textures[4];
+ scoped_ptr<PrioritizedResource> textures_[4];
scoped_ptr<PrioritizedResourceManager> m_resourceManager;
SkBitmap m_bitmap;
int m_queryResultsAvailable;
@@ -389,7 +389,7 @@ TEST_F(ResourceUpdateControllerTest, UpdateMoreTextures)
appendPartialUploadsToUpdateQueue(0);
DebugScopedSetImplThreadAndMainThreadBlocked
- implThreadAndMainThreadBlocked(&m_proxy);
+ implThreadAndMainThreadBlocked(&proxy_);
scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateController::Create(&client, &thread, m_queue.Pass(), m_resourceProvider.get()));
controller->setNow(
@@ -436,7 +436,7 @@ TEST_F(ResourceUpdateControllerTest, NoMoreUpdates)
appendPartialUploadsToUpdateQueue(0);
DebugScopedSetImplThreadAndMainThreadBlocked
- implThreadAndMainThreadBlocked(&m_proxy);
+ implThreadAndMainThreadBlocked(&proxy_);
scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateController::Create(&client, &thread, m_queue.Pass(), m_resourceProvider.get()));
controller->setNow(
@@ -475,7 +475,7 @@ TEST_F(ResourceUpdateControllerTest, UpdatesCompleteInFiniteTime)
appendPartialUploadsToUpdateQueue(0);
DebugScopedSetImplThreadAndMainThreadBlocked
- implThreadAndMainThreadBlocked(&m_proxy);
+ implThreadAndMainThreadBlocked(&proxy_);
scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateController::Create(&client, &thread, m_queue.Pass(), m_resourceProvider.get()));
controller->setNow(
diff --git a/cc/trees/layer_tree_host.cc b/cc/trees/layer_tree_host.cc
index cb195db..bdba155 100644
--- a/cc/trees/layer_tree_host.cc
+++ b/cc/trees/layer_tree_host.cc
@@ -163,9 +163,9 @@ void LayerTreeHost::InitializeRenderer() {
}
settings_.maxPartialTextureUpdates = max_partial_texture_updates;
- contents_texture_manager_ = PrioritizedResourceManager::create(proxy_.get());
+ contents_texture_manager_ = PrioritizedResourceManager::Create(proxy_.get());
surface_memory_placeholder_ =
- contents_texture_manager_->createTexture(gfx::Size(), GL_RGBA);
+ contents_texture_manager_->CreateTexture(gfx::Size(), GL_RGBA);
renderer_initialized_ = true;
@@ -212,7 +212,7 @@ void LayerTreeHost::DeleteContentsTexturesOnImplThread(
ResourceProvider* resource_provider) {
DCHECK(proxy_->IsImplThread());
if (renderer_initialized_)
- contents_texture_manager_->clearAllMemory(resource_provider);
+ contents_texture_manager_->ClearAllMemory(resource_provider);
}
void LayerTreeHost::AcquireLayerTextures() {
@@ -258,9 +258,9 @@ void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
// into the impl tree, so we can't draw yet. Determine this before clearing
// all evicted backings.
bool new_impl_tree_has_no_evicted_resources =
- !contents_texture_manager_->linkedEvictedBackingsExist();
+ !contents_texture_manager_->LinkedEvictedBackingsExist();
- contents_texture_manager_->updateBackingsInDrawingImplTree();
+ contents_texture_manager_->UpdateBackingsInDrawingImplTree();
// In impl-side painting, synchronize to the pending tree so that it has
// time to raster before being displayed. If no pending tree is needed,
@@ -273,7 +273,7 @@ void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
host_impl->CreatePendingTree();
sync_tree = host_impl->pending_tree();
} else {
- contents_texture_manager_->reduceMemory(host_impl->resource_provider());
+ contents_texture_manager_->ReduceMemory(host_impl->resource_provider());
sync_tree = host_impl->active_tree();
}
@@ -639,7 +639,7 @@ void LayerTreeHost::UpdateLayers(ResourceUpdateQueue* queue,
return;
if (memory_allocation_limit_bytes) {
- contents_texture_manager_->setMaxMemoryLimitBytes(
+ contents_texture_manager_->SetMaxMemoryLimitBytes(
memory_allocation_limit_bytes);
}
@@ -749,7 +749,7 @@ void LayerTreeHost::SetPrioritiesForLayers(const LayerList& update_list) {
void LayerTreeHost::PrioritizeTextures(
const LayerList& render_surface_layer_list, OverdrawMetrics* metrics) {
- contents_texture_manager_->clearPriorities();
+ contents_texture_manager_->ClearPriorities();
size_t memory_for_render_surfaces_metric =
CalculateMemoryForRenderSurfaces(render_surface_layer_list);
@@ -758,11 +758,11 @@ void LayerTreeHost::PrioritizeTextures(
SetPrioritiesForSurfaces(memory_for_render_surfaces_metric);
metrics->DidUseContentsTextureMemoryBytes(
- contents_texture_manager_->memoryAboveCutoffBytes());
+ contents_texture_manager_->MemoryAboveCutoffBytes());
metrics->DidUseRenderSurfaceTextureMemoryBytes(
memory_for_render_surfaces_metric);
- contents_texture_manager_->prioritizeTextures();
+ contents_texture_manager_->PrioritizeTextures();
}
size_t LayerTreeHost::CalculateMemoryForRenderSurfaces(
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index 5cf95cf..e1341f6 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -157,7 +157,7 @@ LayerTreeHostImpl::LayerTreeHostImpl(const LayerTreeSettings& settings,
device_scale_factor_(1.f),
visible_(true),
managed_memory_policy_(
- PrioritizedResourceManager::defaultMemoryAllocationLimit(),
+ PrioritizedResourceManager::DefaultMemoryAllocationLimit(),
ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING,
0,
ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING),
diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc
index 7b4230a..f6e12c9 100644
--- a/cc/trees/layer_tree_host_unittest.cc
+++ b/cc/trees/layer_tree_host_unittest.cc
@@ -2129,7 +2129,7 @@ public:
// One backing should remain unevicted.
EXPECT_EQ(
100 * 100 * 4 * 1,
- m_layerTreeHost->contents_texture_manager()->memoryUseBytes());
+ m_layerTreeHost->contents_texture_manager()->MemoryUseBytes());
// Make sure that contents textures are marked as having been
// purged.
EXPECT_TRUE(hostImpl->active_tree()->ContentsTexturesPurged());
@@ -2145,7 +2145,7 @@ public:
// All three backings should have memory.
EXPECT_EQ(
100 * 100 * 4 * 3,
- m_layerTreeHost->contents_texture_manager()->memoryUseBytes());
+ m_layerTreeHost->contents_texture_manager()->MemoryUseBytes());
// Set a new policy that will kick out 1 of the 3 resources.
// Because a resource was evicted, a commit will be kicked off.
hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy(
@@ -2158,7 +2158,7 @@ public:
// Only two backings should have memory.
EXPECT_EQ(
100 * 100 * 4 * 2,
- m_layerTreeHost->contents_texture_manager()->memoryUseBytes());
+ m_layerTreeHost->contents_texture_manager()->MemoryUseBytes());
// Become backgrounded, which will cause 1 more resource to be
// evicted.
postSetVisibleToMainThread(false);
diff --git a/cc/trees/single_thread_proxy.cc b/cc/trees/single_thread_proxy.cc
index c7a1d24..8dbf352 100644
--- a/cc/trees/single_thread_proxy.cc
+++ b/cc/trees/single_thread_proxy.cc
@@ -199,7 +199,7 @@ void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) {
layer_tree_host_impl_->BeginCommit();
layer_tree_host_->contents_texture_manager()->
- pushTexturePrioritiesToBackings();
+ PushTexturePrioritiesToBackings();
layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get());
scoped_ptr<ResourceUpdateController> updateController =
@@ -304,7 +304,7 @@ bool SingleThreadProxy::ReduceContentsTextureMemoryOnImplThread(
if (!layer_tree_host_->contents_texture_manager())
return false;
- return layer_tree_host_->contents_texture_manager()->reduceMemoryOnImplThread(
+ return layer_tree_host_->contents_texture_manager()->ReduceMemoryOnImplThread(
limit_bytes, priority_cutoff, layer_tree_host_impl_->resource_provider());
}
@@ -323,9 +323,9 @@ void SingleThreadProxy::SendManagedMemoryStats() {
PrioritizedResourceManager* contents_texture_manager =
layer_tree_host_->contents_texture_manager();
layer_tree_host_impl_->SendManagedMemoryStats(
- contents_texture_manager->memoryVisibleBytes(),
- contents_texture_manager->memoryVisibleAndNearbyBytes(),
- contents_texture_manager->memoryUseBytes());
+ contents_texture_manager->MemoryVisibleBytes(),
+ contents_texture_manager->MemoryVisibleAndNearbyBytes(),
+ contents_texture_manager->MemoryUseBytes());
}
bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
@@ -383,7 +383,7 @@ bool SingleThreadProxy::CommitAndComposite(base::TimeTicks frame_begin_time) {
created_offscreen_context_provider_ = true;
}
- layer_tree_host_->contents_texture_manager()->unlinkAndClearEvictedBackings();
+ layer_tree_host_->contents_texture_manager()->UnlinkAndClearEvictedBackings();
scoped_ptr<ResourceUpdateQueue> queue =
make_scoped_ptr(new ResourceUpdateQueue);
diff --git a/cc/trees/thread_proxy.cc b/cc/trees/thread_proxy.cc
index cc14869..0974592 100644
--- a/cc/trees/thread_proxy.cc
+++ b/cc/trees/thread_proxy.cc
@@ -430,7 +430,7 @@ bool ThreadProxy::ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes,
return false;
bool reduce_result = layer_tree_host_->contents_texture_manager()->
- reduceMemoryOnImplThread(limit_bytes,
+ ReduceMemoryOnImplThread(limit_bytes,
priority_cutoff,
layer_tree_host_impl_->resource_provider());
if (!reduce_result)
@@ -451,7 +451,7 @@ void ThreadProxy::ReduceWastedContentsTextureMemoryOnImplThread() {
if (!layer_tree_host_->contents_texture_manager())
return;
- layer_tree_host_->contents_texture_manager()->reduceWastedMemoryOnImplThread(
+ layer_tree_host_->contents_texture_manager()->ReduceWastedMemoryOnImplThread(
layer_tree_host_impl_->resource_provider());
}
@@ -469,10 +469,10 @@ void ThreadProxy::SendManagedMemoryStats() {
return;
layer_tree_host_impl_->SendManagedMemoryStats(
- layer_tree_host_->contents_texture_manager()->memoryVisibleBytes(),
+ layer_tree_host_->contents_texture_manager()->MemoryVisibleBytes(),
layer_tree_host_->contents_texture_manager()->
- memoryVisibleAndNearbyBytes(),
- layer_tree_host_->contents_texture_manager()->memoryUseBytes());
+ MemoryVisibleAndNearbyBytes(),
+ layer_tree_host_->contents_texture_manager()->MemoryUseBytes());
}
bool ThreadProxy::IsInsideDraw() { return inside_draw_; }
@@ -685,7 +685,7 @@ void ThreadProxy::BeginFrame(
// re-paint them in updateLayers.
if (layer_tree_host_->contents_texture_manager()) {
layer_tree_host_->contents_texture_manager()->
- unlinkAndClearEvictedBackings();
+ UnlinkAndClearEvictedBackings();
}
layer_tree_host_->Layout();
@@ -785,7 +785,7 @@ void ThreadProxy::BeginFrameCompleteOnImplThread(
set_offscreen_context_provider(offscreen_context_provider);
if (layer_tree_host_->contents_texture_manager()->
- linkedEvictedBackingsExist()) {
+ LinkedEvictedBackingsExist()) {
// Clear any uploads we were making to textures linked to evicted
// resources
queue->clearUploadsToEvictedResources();
@@ -795,7 +795,7 @@ void ThreadProxy::BeginFrameCompleteOnImplThread(
}
layer_tree_host_->contents_texture_manager()->
- pushTexturePrioritiesToBackings();
+ PushTexturePrioritiesToBackings();
current_resource_update_controller_on_impl_thread_ =
ResourceUpdateController::Create(