Index: cc/DecorationLayerChromiumTest.cpp |
diff --git a/cc/DecorationLayerChromiumTest.cpp b/cc/DecorationLayerChromiumTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fb737774f27cb60b55affdeab600e875cdba24cb |
--- /dev/null |
+++ b/cc/DecorationLayerChromiumTest.cpp |
@@ -0,0 +1,140 @@ |
+// Copyright 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+ |
+#include "DecorationLayerChromium.h" |
+ |
+#include "CCLayerTreeHost.h" |
+#include "CCOcclusionTracker.h" |
+#include "CCOverdrawMetrics.h" |
+#include "CCRenderingStats.h" |
+#include "CCResourceProvider.h" |
+#include "CCSingleThreadProxy.h" |
+#include "CCTextureUpdateQueue.h" |
+#include "FakeCCGraphicsContext.h" |
+#include "FakeCCLayerTreeHostClient.h" |
+#include "SkBitmap.h" |
+#include "WebCompositorInitializer.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using namespace cc; |
+using ::testing::Mock; |
+using ::testing::_; |
+using ::testing::AtLeast; |
+using ::testing::AnyNumber; |
+ |
+namespace { |
+ |
+class MockCCLayerTreeHost : public CCLayerTreeHost { |
+public: |
+ MockCCLayerTreeHost() |
+ : CCLayerTreeHost(&m_fakeClient, CCLayerTreeSettings()) |
+ { |
+ initialize(); |
+ } |
+ |
+private: |
+ FakeCCLayerTreeHostClient m_fakeClient; |
+}; |
+ |
+ |
+class DecorationLayerChromiumTest : public testing::Test { |
+public: |
+ DecorationLayerChromiumTest() |
+ : m_compositorInitializer(0) |
+ { |
+ } |
+ |
+protected: |
+ virtual void SetUp() |
+ { |
+ m_layerTreeHost = adoptPtr(new MockCCLayerTreeHost); |
+ } |
+ |
+ virtual void TearDown() |
+ { |
+ Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
+ |
+ m_layerTreeHost->setRootLayer(0); |
+ m_layerTreeHost.clear(); |
+ } |
+ |
+ OwnPtr<MockCCLayerTreeHost> m_layerTreeHost; |
+private: |
+ WebKitTests::WebCompositorInitializer m_compositorInitializer; |
+}; |
+ |
+TEST_F(DecorationLayerChromiumTest, triggerFullUploadOnceWhenChangingBitmap) |
+{ |
+ scoped_refptr<DecorationLayerChromium> testLayer = DecorationLayerChromium::create(); |
+ ASSERT_TRUE(testLayer); |
+ testLayer->setIsDrawable(true); |
+ testLayer->setBounds(IntSize(100, 100)); |
+ |
+ m_layerTreeHost->setRootLayer(testLayer); |
+ Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
+ EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get()); |
+ |
+ m_layerTreeHost->initializeRendererIfNeeded(); |
+ |
+ CCPriorityCalculator calculator; |
+ CCTextureUpdateQueue queue; |
+ CCOcclusionTracker occlusionTracker(IntRect(), false); |
+ CCRenderingStats stats; |
+ |
+ // No bitmap set should not trigger any uploads. |
+ testLayer->setTexturePriorities(calculator); |
+ testLayer->update(queue, &occlusionTracker, stats); |
+ EXPECT_EQ(queue.fullUploadSize(), 0); |
+ EXPECT_EQ(queue.partialUploadSize(), 0); |
+ |
+ // Setting a bitmap set should trigger a single full upload. |
+ SkBitmap bitmap; |
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); |
+ bitmap.allocPixels(); |
+ testLayer->setBitmap(bitmap, IntRect(5, 5, 1, 1)); |
+ testLayer->setTexturePriorities(calculator); |
+ testLayer->update(queue, &occlusionTracker, stats); |
+ EXPECT_EQ(queue.fullUploadSize(), 1); |
+ EXPECT_EQ(queue.partialUploadSize(), 0); |
+ TextureUploader::Parameters params = queue.takeFirstFullUpload(); |
+ EXPECT_TRUE(params.texture != NULL); |
+ |
+ // Upload the texture. |
+ m_layerTreeHost->contentsTextureManager()->setMaxMemoryLimitBytes(1024 * 1024); |
+ m_layerTreeHost->contentsTextureManager()->prioritizeTextures(); |
+ |
+ // Hack: Create a ResourceProvider here, because we cannot get to the one |
+ // owned by the CCLayerTreeHostImpl. |
+ CCProxy::setCurrentThreadIsImplThread(true); |
+ CCProxy::setMainThreadBlocked(true); |
+ scoped_ptr<CCGraphicsContext> context(WebKit::createFakeCCGraphicsContext()); |
+ OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(context.get())); |
+ params.texture->texture()->acquireBackingTexture(resourceProvider.get()); |
+ ASSERT_TRUE(params.texture->texture()->haveBackingTexture()); |
+ CCProxy::setCurrentThreadIsImplThread(false); |
+ CCProxy::setMainThreadBlocked(false); |
+ |
+ // Nothing changed, so no repeated upload. |
+ testLayer->setTexturePriorities(calculator); |
+ testLayer->update(queue, &occlusionTracker, stats); |
+ EXPECT_EQ(queue.fullUploadSize(), 0); |
+ EXPECT_EQ(queue.partialUploadSize(), 0); |
+ |
+ { |
+ DebugScopedSetImplThread implThread; |
+ DebugScopedSetMainThreadBlocked mainThreadBlocked; |
+ m_layerTreeHost->contentsTextureManager()->clearAllMemory(resourceProvider.get()); |
+ } |
+ |
+ // Reupload after eviction |
+ testLayer->setTexturePriorities(calculator); |
+ testLayer->update(queue, &occlusionTracker, stats); |
+ EXPECT_EQ(queue.fullUploadSize(), 1); |
+ EXPECT_EQ(queue.partialUploadSize(), 0); |
+} |
+ |
+} // anonymous namespace |