Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Unified Diff: cc/tiled_layer_unittest.cc

Issue 11232051: Remove static thread pointers from CC (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address code review comments and fix all cc_unittests Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/tiled_layer_unittest.cc
diff --git a/cc/tiled_layer_unittest.cc b/cc/tiled_layer_unittest.cc
index dec320964b3b82b79c940be08e2ef41541b01c41..60b0e371d0f3e7e9bc8eaea97f2e906827909024 100644
--- a/cc/tiled_layer_unittest.cc
+++ b/cc/tiled_layer_unittest.cc
@@ -14,6 +14,7 @@
#include "cc/test/animation_test_common.h"
#include "cc/test/fake_graphics_context.h"
#include "cc/test/fake_layer_tree_host_client.h"
+#include "cc/test/fake_proxy.h"
#include "cc/test/geometry_test_utils.h"
#include "cc/test/tiled_layer_test_common.h"
#include "cc/test/web_compositor_initializer.h"
@@ -49,35 +50,37 @@ private:
class TiledLayerTest : public testing::Test {
public:
TiledLayerTest()
- : m_compositorInitializer(0)
+ : m_proxy(0)
+ , m_compositorInitializer(0)
, m_context(WebKit::createFakeGraphicsContext())
, m_queue(make_scoped_ptr(new TextureUpdateQueue))
- , m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024, Renderer::ContentPool))
, m_occlusion(0)
{
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
+ LayerTreeSettings settings;
+ settings.maxPartialTextureUpdates = 4;
+ m_layerTreeHost = LayerTreeHost::create(&m_fakeLayerImplTreeHostClient, settings, NULL);
+ m_proxy = m_layerTreeHost->proxy();
+ m_textureManager = PrioritizedTextureManager::create(60*1024*1024, 1024, Renderer::ContentPool, m_proxy);
+ m_layerTreeHost->initializeRendererIfNeeded();
+ DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy);
m_resourceProvider = ResourceProvider::create(m_context.get());
}
virtual ~TiledLayerTest()
{
textureManagerClearAllMemory(m_textureManager.get(), m_resourceProvider.get());
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
+ DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy);
m_resourceProvider.reset();
}
- // Helper classes and functions that set the current thread to be the impl thread
- // before doing the action that they wrap.
class ScopedFakeTiledLayerImpl {
public:
ScopedFakeTiledLayerImpl(int id)
{
- DebugScopedSetImplThread implThread;
m_layerImpl = new FakeTiledLayerImpl(id);
}
~ScopedFakeTiledLayerImpl()
{
- DebugScopedSetImplThread implThread;
delete m_layerImpl;
}
FakeTiledLayerImpl* get()
@@ -93,31 +96,32 @@ public:
};
void textureManagerClearAllMemory(PrioritizedTextureManager* textureManager, ResourceProvider* resourceProvider)
{
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
+ DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy);
textureManager->clearAllMemory(resourceProvider);
textureManager->reduceMemory(resourceProvider);
}
void updateTextures()
{
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
+ DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy);
DCHECK(m_queue);
scoped_ptr<TextureUpdateController> updateController =
TextureUpdateController::create(
NULL,
- Proxy::implThread(),
+ m_proxy->implThread(),
m_queue.Pass(),
- m_resourceProvider.get());
+ m_resourceProvider.get(),
+ m_proxy->hasImplThread());
updateController->finalize();
m_queue = make_scoped_ptr(new TextureUpdateQueue);
}
void layerPushPropertiesTo(FakeTiledLayer* layer, FakeTiledLayerImpl* layerImpl)
{
- DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
+ DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy);
layer->pushPropertiesTo(layerImpl);
}
void layerUpdate(FakeTiledLayer* layer, TestOcclusionTracker* occluded)
{
- DebugScopedSetMainThread mainThread;
+ DebugScopedSetMainThread mainThread(m_proxy);
layer->update(*m_queue.get(), occluded, m_stats);
}
@@ -157,12 +161,15 @@ public:
}
public:
+ Proxy* m_proxy;
WebKitTests::WebCompositorInitializer m_compositorInitializer;
scoped_ptr<GraphicsContext> m_context;
scoped_ptr<ResourceProvider> m_resourceProvider;
scoped_ptr<TextureUpdateQueue> m_queue;
RenderingStats m_stats;
PriorityCalculator m_priorityCalculator;
+ FakeLayerImplTreeHostClient m_fakeLayerImplTreeHostClient;
+ scoped_ptr<LayerTreeHost> m_layerTreeHost;
scoped_ptr<PrioritizedTextureManager> m_textureManager;
TestOcclusionTracker* m_occlusion;
};
@@ -513,7 +520,7 @@ TEST_F(TiledLayerTest, paintSmallAnimatedLayersImmediately)
// Create a LayerTreeHost that has the right viewportsize,
// so the layer is considered small enough.
FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient;
- scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerImplTreeHostClient, LayerTreeSettings());
+ scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerImplTreeHostClient, LayerTreeSettings(), NULL);
bool runOutOfMemory[2] = {false, true};
for (int i = 0; i < 2; i++) {
@@ -779,10 +786,6 @@ TEST_F(TiledLayerTest, verifyInvalidationWhenContentsScaleChanges)
TEST_F(TiledLayerTest, skipsDrawGetsReset)
{
- FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient;
- scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerImplTreeHostClient, LayerTreeSettings());
- ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded());
-
// Create two 300 x 300 tiled layers.
IntSize contentBounds(300, 300);
IntRect contentRect(IntPoint::zero(), contentBounds);
@@ -790,8 +793,8 @@ TEST_F(TiledLayerTest, skipsDrawGetsReset)
// We have enough memory for only one of the two layers.
int memoryLimit = 4 * 300 * 300; // 4 bytes per pixel.
- scoped_refptr<FakeTiledLayer> rootLayer = make_scoped_refptr(new FakeTiledLayer(layerTreeHost->contentsTextureManager()));
- scoped_refptr<FakeTiledLayer> childLayer = make_scoped_refptr(new FakeTiledLayer(layerTreeHost->contentsTextureManager()));
+ scoped_refptr<FakeTiledLayer> rootLayer = make_scoped_refptr(new FakeTiledLayer(m_layerTreeHost->contentsTextureManager()));
+ scoped_refptr<FakeTiledLayer> childLayer = make_scoped_refptr(new FakeTiledLayer(m_layerTreeHost->contentsTextureManager()));
rootLayer->addChild(childLayer);
rootLayer->setBounds(contentBounds);
@@ -803,25 +806,25 @@ TEST_F(TiledLayerTest, skipsDrawGetsReset)
rootLayer->invalidateContentRect(contentRect);
childLayer->invalidateContentRect(contentRect);
- layerTreeHost->setRootLayer(rootLayer);
- layerTreeHost->setViewportSize(IntSize(300, 300), IntSize(300, 300));
+ m_layerTreeHost->setRootLayer(rootLayer);
+ m_layerTreeHost->setViewportSize(IntSize(300, 300), IntSize(300, 300));
- layerTreeHost->updateLayers(*m_queue.get(), memoryLimit);
+ m_layerTreeHost->updateLayers(*m_queue.get(), memoryLimit);
// We'll skip the root layer.
EXPECT_TRUE(rootLayer->skipsDraw());
EXPECT_FALSE(childLayer->skipsDraw());
- layerTreeHost->commitComplete();
+ m_layerTreeHost->commitComplete();
// Remove the child layer.
rootLayer->removeAllChildren();
- layerTreeHost->updateLayers(*m_queue.get(), memoryLimit);
+ m_layerTreeHost->updateLayers(*m_queue.get(), memoryLimit);
EXPECT_FALSE(rootLayer->skipsDraw());
- textureManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_resourceProvider.get());
- layerTreeHost->setRootLayer(0);
+ textureManagerClearAllMemory(m_layerTreeHost->contentsTextureManager(), m_resourceProvider.get());
+ m_layerTreeHost->setRootLayer(0);
}
TEST_F(TiledLayerTest, resizeToSmaller)
@@ -857,28 +860,21 @@ TEST_F(TiledLayerTest, hugeLayerUpdateCrash)
TEST_F(TiledLayerTest, partialUpdates)
{
- LayerTreeSettings settings;
- settings.maxPartialTextureUpdates = 4;
danakj 2012/10/25 05:06:06 Don't really like this being set for the whole tes
-
- FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient;
- scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerImplTreeHostClient, settings);
- ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded());
-
// Create one 300 x 200 tiled layer with 3 x 2 tiles.
IntSize contentBounds(300, 200);
IntRect contentRect(IntPoint::zero(), contentBounds);
- scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(layerTreeHost->contentsTextureManager()));
+ scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_layerTreeHost->contentsTextureManager()));
layer->setBounds(contentBounds);
layer->setPosition(FloatPoint(0, 0));
layer->setVisibleContentRect(contentRect);
layer->invalidateContentRect(contentRect);
- layerTreeHost->setRootLayer(layer);
- layerTreeHost->setViewportSize(IntSize(300, 200), IntSize(300, 200));
+ m_layerTreeHost->setRootLayer(layer);
+ m_layerTreeHost->setViewportSize(IntSize(300, 200), IntSize(300, 200));
// Full update of all 6 tiles.
- layerTreeHost->updateLayers(
+ m_layerTreeHost->updateLayers(
*m_queue.get(), std::numeric_limits<size_t>::max());
{
ScopedFakeTiledLayerImpl layerImpl(1);
@@ -890,11 +886,11 @@ TEST_F(TiledLayerTest, partialUpdates)
layer->fakeLayerUpdater()->clearUpdateCount();
layerPushPropertiesTo(layer.get(), layerImpl.get());
}
- layerTreeHost->commitComplete();
+ m_layerTreeHost->commitComplete();
// Full update of 3 tiles and partial update of 3 tiles.
layer->invalidateContentRect(IntRect(0, 0, 300, 150));
- layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max());
+ m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max());
{
ScopedFakeTiledLayerImpl layerImpl(1);
EXPECT_EQ(3, m_queue->fullUploadSize());
@@ -905,13 +901,13 @@ TEST_F(TiledLayerTest, partialUpdates)
layer->fakeLayerUpdater()->clearUpdateCount();
layerPushPropertiesTo(layer.get(), layerImpl.get());
}
- layerTreeHost->commitComplete();
+ m_layerTreeHost->commitComplete();
// Partial update of 6 tiles.
layer->invalidateContentRect(IntRect(50, 50, 200, 100));
{
ScopedFakeTiledLayerImpl layerImpl(1);
- layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max());
+ m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max());
EXPECT_EQ(2, m_queue->fullUploadSize());
EXPECT_EQ(4, m_queue->partialUploadSize());
updateTextures();
@@ -920,7 +916,7 @@ TEST_F(TiledLayerTest, partialUpdates)
layer->fakeLayerUpdater()->clearUpdateCount();
layerPushPropertiesTo(layer.get(), layerImpl.get());
}
- layerTreeHost->commitComplete();
+ m_layerTreeHost->commitComplete();
// Checkerboard all tiles.
layer->invalidateContentRect(IntRect(0, 0, 300, 200));
@@ -928,13 +924,13 @@ TEST_F(TiledLayerTest, partialUpdates)
ScopedFakeTiledLayerImpl layerImpl(1);
layerPushPropertiesTo(layer.get(), layerImpl.get());
}
- layerTreeHost->commitComplete();
+ m_layerTreeHost->commitComplete();
// Partial update of 6 checkerboard tiles.
layer->invalidateContentRect(IntRect(50, 50, 200, 100));
{
ScopedFakeTiledLayerImpl layerImpl(1);
- layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max());
+ m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max());
EXPECT_EQ(6, m_queue->fullUploadSize());
EXPECT_EQ(0, m_queue->partialUploadSize());
updateTextures();
@@ -943,13 +939,13 @@ TEST_F(TiledLayerTest, partialUpdates)
layer->fakeLayerUpdater()->clearUpdateCount();
layerPushPropertiesTo(layer.get(), layerImpl.get());
}
- layerTreeHost->commitComplete();
+ m_layerTreeHost->commitComplete();
// Partial update of 4 tiles.
layer->invalidateContentRect(IntRect(50, 50, 100, 100));
{
ScopedFakeTiledLayerImpl layerImpl(1);
- layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max());
+ m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max());
EXPECT_EQ(0, m_queue->fullUploadSize());
EXPECT_EQ(4, m_queue->partialUploadSize());
updateTextures();
@@ -958,10 +954,10 @@ TEST_F(TiledLayerTest, partialUpdates)
layer->fakeLayerUpdater()->clearUpdateCount();
layerPushPropertiesTo(layer.get(), layerImpl.get());
}
- layerTreeHost->commitComplete();
+ m_layerTreeHost->commitComplete();
- textureManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_resourceProvider.get());
- layerTreeHost->setRootLayer(0);
+ textureManagerClearAllMemory(m_layerTreeHost->contentsTextureManager(), m_resourceProvider.get());
+ m_layerTreeHost->setRootLayer(0);
}
TEST_F(TiledLayerTest, tilesPaintedWithoutOcclusion)
@@ -1379,15 +1375,10 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated)
IntRect childRect(0, 0, 300, 100);
IntRect child2Rect(0, 100, 300, 100);
- LayerTreeSettings settings;
- FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient;
- scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerImplTreeHostClient, settings);
- ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded());
-
- scoped_refptr<FakeTiledLayer> root = make_scoped_refptr(new FakeTiledLayer(layerTreeHost->contentsTextureManager()));
+ scoped_refptr<FakeTiledLayer> root = make_scoped_refptr(new FakeTiledLayer(m_layerTreeHost->contentsTextureManager()));
scoped_refptr<Layer> surface = Layer::create();
- scoped_refptr<FakeTiledLayer> child = make_scoped_refptr(new FakeTiledLayer(layerTreeHost->contentsTextureManager()));
- scoped_refptr<FakeTiledLayer> child2 = make_scoped_refptr(new FakeTiledLayer(layerTreeHost->contentsTextureManager()));
+ scoped_refptr<FakeTiledLayer> child = make_scoped_refptr(new FakeTiledLayer(m_layerTreeHost->contentsTextureManager()));
+ scoped_refptr<FakeTiledLayer> child2 = make_scoped_refptr(new FakeTiledLayer(m_layerTreeHost->contentsTextureManager()));
root->setBounds(rootRect.size());
root->setAnchorPoint(FloatPoint());
@@ -1413,14 +1404,14 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated)
child2->setVisibleContentRect(child2Rect);
child2->setDrawableContentRect(rootRect);
- layerTreeHost->setRootLayer(root);
- layerTreeHost->setViewportSize(rootRect.size(), rootRect.size());
+ m_layerTreeHost->setRootLayer(root);
+ m_layerTreeHost->setViewportSize(rootRect.size(), rootRect.size());
// With a huge memory limit, all layers should update and push their textures.
root->invalidateContentRect(rootRect);
child->invalidateContentRect(childRect);
child2->invalidateContentRect(child2Rect);
- layerTreeHost->updateLayers(
+ m_layerTreeHost->updateLayers(
*m_queue.get(), std::numeric_limits<size_t>::max());
{
updateTextures();
@@ -1447,7 +1438,7 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated)
EXPECT_TRUE(child2Impl->hasResourceIdForTileAt(i, 0));
}
}
- layerTreeHost->commitComplete();
+ m_layerTreeHost->commitComplete();
// With a memory limit that includes only the root layer (3x2 tiles) and half the surface that
// the child layers draw into, the child layers will not be allocated. If the surface isn't
@@ -1455,7 +1446,7 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated)
root->invalidateContentRect(rootRect);
child->invalidateContentRect(childRect);
child2->invalidateContentRect(child2Rect);
- layerTreeHost->updateLayers(
+ m_layerTreeHost->updateLayers(
*m_queue.get(), (3 * 2 + 3 * 1) * (100 * 100) * 4);
{
updateTextures();
@@ -1482,7 +1473,7 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated)
EXPECT_FALSE(child2Impl->hasResourceIdForTileAt(i, 0));
}
}
- layerTreeHost->commitComplete();
+ m_layerTreeHost->commitComplete();
// With a memory limit that includes only half the root layer, no contents will be
// allocated. If render surface memory wasn't accounted for, there is enough space
@@ -1491,7 +1482,7 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated)
root->invalidateContentRect(rootRect);
child->invalidateContentRect(childRect);
child2->invalidateContentRect(child2Rect);
- layerTreeHost->updateLayers(
+ m_layerTreeHost->updateLayers(
*m_queue.get(), (3 * 1) * (100 * 100) * 4);
{
updateTextures();
@@ -1518,10 +1509,10 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated)
EXPECT_FALSE(child2Impl->hasResourceIdForTileAt(i, 0));
}
}
- layerTreeHost->commitComplete();
+ m_layerTreeHost->commitComplete();
- textureManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_resourceProvider.get());
- layerTreeHost->setRootLayer(0);
+ textureManagerClearAllMemory(m_layerTreeHost->contentsTextureManager(), m_resourceProvider.get());
+ m_layerTreeHost->setRootLayer(0);
}
class TrackingLayerPainter : public LayerPainter {

Powered by Google App Engine
This is Rietveld 408576698