| Index: cc/tiled_layer_unittest.cc
|
| diff --git a/cc/tiled_layer_unittest.cc b/cc/tiled_layer_unittest.cc
|
| index 8e62bb72384437e37bbc996727c1fe87a1875fae..ae53a4e45b6e15b1581f0514c92337152875dcff 100644
|
| --- a/cc/tiled_layer_unittest.cc
|
| +++ b/cc/tiled_layer_unittest.cc
|
| @@ -15,6 +15,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 "testing/gtest/include/gtest/gtest.h"
|
| @@ -49,34 +50,38 @@ private:
|
| class TiledLayerTest : public testing::Test {
|
| public:
|
| TiledLayerTest()
|
| - : m_context(WebKit::createFakeGraphicsContext())
|
| + : m_proxy(NULL)
|
| + , m_context(WebKit::createFakeGraphicsContext())
|
| , m_queue(make_scoped_ptr(new ResourceUpdateQueue))
|
| - , m_resourceManager(PrioritizedResourceManager::create(60*1024*1024, 1024, Renderer::ContentPool))
|
| , m_occlusion(0)
|
| {
|
| - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
|
| + }
|
| +
|
| + virtual void SetUp()
|
| + {
|
| + m_layerTreeHost = LayerTreeHost::create(&m_fakeLayerImplTreeHostClient, m_settings, scoped_ptr<Thread>(NULL));
|
| + m_proxy = m_layerTreeHost->proxy();
|
| + m_resourceManager = PrioritizedResourceManager::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()
|
| {
|
| resourceManagerClearAllMemory(m_resourceManager.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()
|
| @@ -92,31 +97,32 @@ public:
|
| };
|
| void resourceManagerClearAllMemory(PrioritizedResourceManager* resourceManager, ResourceProvider* resourceProvider)
|
| {
|
| - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
|
| + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy);
|
| resourceManager->clearAllMemory(resourceProvider);
|
| resourceManager->reduceMemory(resourceProvider);
|
| }
|
| void updateTextures()
|
| {
|
| - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
|
| + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy);
|
| DCHECK(m_queue);
|
| scoped_ptr<ResourceUpdateController> updateController =
|
| ResourceUpdateController::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 ResourceUpdateQueue);
|
| }
|
| 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);
|
| }
|
|
|
| @@ -156,11 +162,15 @@ public:
|
| }
|
|
|
| public:
|
| + Proxy* m_proxy;
|
| + LayerTreeSettings m_settings;
|
| scoped_ptr<GraphicsContext> m_context;
|
| scoped_ptr<ResourceProvider> m_resourceProvider;
|
| scoped_ptr<ResourceUpdateQueue> m_queue;
|
| RenderingStats m_stats;
|
| PriorityCalculator m_priorityCalculator;
|
| + FakeLayerImplTreeHostClient m_fakeLayerImplTreeHostClient;
|
| + scoped_ptr<LayerTreeHost> m_layerTreeHost;
|
| scoped_ptr<PrioritizedResourceManager> m_resourceManager;
|
| TestOcclusionTracker* m_occlusion;
|
| };
|
| @@ -512,7 +522,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(), scoped_ptr<Thread>(NULL));
|
|
|
| bool runOutOfMemory[2] = {false, true};
|
| for (int i = 0; i < 2; i++) {
|
| @@ -778,10 +788,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.
|
| gfx::Size contentBounds(300, 300);
|
| gfx::Rect contentRect(gfx::Point(), contentBounds);
|
| @@ -789,8 +795,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);
|
| @@ -802,25 +808,25 @@ TEST_F(TiledLayerTest, skipsDrawGetsReset)
|
| rootLayer->invalidateContentRect(contentRect);
|
| childLayer->invalidateContentRect(contentRect);
|
|
|
| - layerTreeHost->setRootLayer(rootLayer);
|
| - layerTreeHost->setViewportSize(gfx::Size(300, 300), gfx::Size(300, 300));
|
| + m_layerTreeHost->setRootLayer(rootLayer);
|
| + m_layerTreeHost->setViewportSize(gfx::Size(300, 300), gfx::Size(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());
|
|
|
| - resourceManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_resourceProvider.get());
|
| - layerTreeHost->setRootLayer(0);
|
| + resourceManagerClearAllMemory(m_layerTreeHost->contentsTextureManager(), m_resourceProvider.get());
|
| + m_layerTreeHost->setRootLayer(0);
|
| }
|
|
|
| TEST_F(TiledLayerTest, resizeToSmaller)
|
| @@ -854,30 +860,31 @@ TEST_F(TiledLayerTest, hugeLayerUpdateCrash)
|
| layer->update(*m_queue.get(), 0, m_stats);
|
| }
|
|
|
| -TEST_F(TiledLayerTest, partialUpdates)
|
| -{
|
| - LayerTreeSettings settings;
|
| - settings.maxPartialTextureUpdates = 4;
|
| -
|
| - FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient;
|
| - scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerImplTreeHostClient, settings);
|
| - ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded());
|
| +class TiledLayerPartialUpdateTest : public TiledLayerTest {
|
| +public:
|
| + TiledLayerPartialUpdateTest()
|
| + {
|
| + m_settings.maxPartialTextureUpdates = 4;
|
| + }
|
| +};
|
|
|
| +TEST_F(TiledLayerPartialUpdateTest, partialUpdates)
|
| +{
|
| // Create one 300 x 200 tiled layer with 3 x 2 tiles.
|
| gfx::Size contentBounds(300, 200);
|
| gfx::Rect contentRect(gfx::Point(), 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(gfx::PointF(0, 0));
|
| layer->setVisibleContentRect(contentRect);
|
| layer->invalidateContentRect(contentRect);
|
|
|
| - layerTreeHost->setRootLayer(layer);
|
| - layerTreeHost->setViewportSize(gfx::Size(300, 200), gfx::Size(300, 200));
|
| + m_layerTreeHost->setRootLayer(layer);
|
| + m_layerTreeHost->setViewportSize(gfx::Size(300, 200), gfx::Size(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);
|
| @@ -889,11 +896,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(gfx::Rect(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());
|
| @@ -904,13 +911,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(gfx::Rect(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();
|
| @@ -919,7 +926,7 @@ TEST_F(TiledLayerTest, partialUpdates)
|
| layer->fakeLayerUpdater()->clearUpdateCount();
|
| layerPushPropertiesTo(layer.get(), layerImpl.get());
|
| }
|
| - layerTreeHost->commitComplete();
|
| + m_layerTreeHost->commitComplete();
|
|
|
| // Checkerboard all tiles.
|
| layer->invalidateContentRect(gfx::Rect(0, 0, 300, 200));
|
| @@ -927,13 +934,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(gfx::Rect(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();
|
| @@ -942,13 +949,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(gfx::Rect(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();
|
| @@ -957,10 +964,10 @@ TEST_F(TiledLayerTest, partialUpdates)
|
| layer->fakeLayerUpdater()->clearUpdateCount();
|
| layerPushPropertiesTo(layer.get(), layerImpl.get());
|
| }
|
| - layerTreeHost->commitComplete();
|
| + m_layerTreeHost->commitComplete();
|
|
|
| - resourceManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_resourceProvider.get());
|
| - layerTreeHost->setRootLayer(0);
|
| + resourceManagerClearAllMemory(m_layerTreeHost->contentsTextureManager(), m_resourceProvider.get());
|
| + m_layerTreeHost->setRootLayer(0);
|
| }
|
|
|
| TEST_F(TiledLayerTest, tilesPaintedWithoutOcclusion)
|
| @@ -1381,15 +1388,10 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated)
|
| gfx::Rect childRect(0, 0, 300, 100);
|
| gfx::Rect 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(gfx::PointF());
|
| @@ -1415,14 +1417,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();
|
| @@ -1449,7 +1451,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
|
| @@ -1457,7 +1459,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();
|
| @@ -1484,7 +1486,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
|
| @@ -1493,7 +1495,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();
|
| @@ -1520,10 +1522,10 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated)
|
| EXPECT_FALSE(child2Impl->hasResourceIdForTileAt(i, 0));
|
| }
|
| }
|
| - layerTreeHost->commitComplete();
|
| + m_layerTreeHost->commitComplete();
|
|
|
| - resourceManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_resourceProvider.get());
|
| - layerTreeHost->setRootLayer(0);
|
| + resourceManagerClearAllMemory(m_layerTreeHost->contentsTextureManager(), m_resourceProvider.get());
|
| + m_layerTreeHost->setRootLayer(0);
|
| }
|
|
|
| class TrackingLayerPainter : public LayerPainter {
|
|
|