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

Side by Side Diff: cc/layer_tree_host_unittest.cc

Issue 11264056: cc: Use gfx:: Geometry types for positions, bounds, and related things. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some missed intstuff Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 6
7 #include "cc/layer_tree_host.h" 7 #include "cc/layer_tree_host.h"
8 8
9 #include "base/synchronization/lock.h" 9 #include "base/synchronization/lock.h"
10 #include "cc/content_layer.h" 10 #include "cc/content_layer.h"
11 #include "cc/content_layer_client.h" 11 #include "cc/content_layer_client.h"
12 #include "cc/graphics_context.h" 12 #include "cc/graphics_context.h"
13 #include "cc/layer_tree_host_impl.h" 13 #include "cc/layer_tree_host_impl.h"
14 #include "cc/settings.h" 14 #include "cc/settings.h"
15 #include "cc/single_thread_proxy.h" 15 #include "cc/single_thread_proxy.h"
16 #include "cc/test/fake_web_compositor_output_surface.h" 16 #include "cc/test/fake_web_compositor_output_surface.h"
17 #include "cc/test/geometry_test_utils.h" 17 #include "cc/test/geometry_test_utils.h"
18 #include "cc/test/layer_tree_test_common.h" 18 #include "cc/test/layer_tree_test_common.h"
19 #include "cc/test/occlusion_tracker_test_common.h" 19 #include "cc/test/occlusion_tracker_test_common.h"
20 #include "cc/texture_update_queue.h" 20 #include "cc/texture_update_queue.h"
21 #include "cc/timing_function.h" 21 #include "cc/timing_function.h"
22 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "third_party/khronos/GLES2/gl2.h" 23 #include "third_party/khronos/GLES2/gl2.h"
24 #include "third_party/khronos/GLES2/gl2ext.h" 24 #include "third_party/khronos/GLES2/gl2ext.h"
25 #include "ui/gfx/size_conversions.h"
25 #include <public/Platform.h> 26 #include <public/Platform.h>
26 #include <public/WebLayerScrollClient.h> 27 #include <public/WebLayerScrollClient.h>
27 #include <public/WebSize.h> 28 #include <public/WebSize.h>
28 29
29 using namespace cc; 30 using namespace cc;
30 using namespace WebKit; 31 using namespace WebKit;
31 using namespace WebKitTests; 32 using namespace WebKitTests;
32 33
33 namespace { 34 namespace {
34 35
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 // After the first commit, we should not be able to draw. 304 // After the first commit, we should not be able to draw.
304 EXPECT_FALSE(impl->canDraw()); 305 EXPECT_FALSE(impl->canDraw());
305 } 306 }
306 } 307 }
307 308
308 virtual void didCommit() OVERRIDE 309 virtual void didCommit() OVERRIDE
309 { 310 {
310 m_numCommits++; 311 m_numCommits++;
311 if (m_numCommits == 1) { 312 if (m_numCommits == 1) {
312 // Make the viewport empty so the host says it can't draw. 313 // Make the viewport empty so the host says it can't draw.
313 m_layerTreeHost->setViewportSize(IntSize(0, 0), IntSize(0, 0)); 314 m_layerTreeHost->setViewportSize(gfx::Size(0, 0), gfx::Size(0, 0));
314 315
315 scoped_array<char> pixels(new char[4]); 316 scoped_array<char> pixels(new char[4]);
316 m_layerTreeHost->compositeAndReadback(static_cast<void*>(pixels.get( )), IntRect(0, 0, 1, 1)); 317 m_layerTreeHost->compositeAndReadback(static_cast<void*>(pixels.get( )), IntRect(0, 0, 1, 1));
317 } else if (m_numCommits == 2) { 318 } else if (m_numCommits == 2) {
318 m_layerTreeHost->setNeedsRedraw(); 319 m_layerTreeHost->setNeedsRedraw();
319 m_layerTreeHost->setNeedsCommit(); 320 m_layerTreeHost->setNeedsCommit();
320 } else 321 } else
321 endTest(); 322 endTest();
322 } 323 }
323 324
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 // Ensures that when opacity is being animated, this value does not cause the su btree to be skipped. 768 // Ensures that when opacity is being animated, this value does not cause the su btree to be skipped.
768 class LayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity : public LayerTreeHost Test { 769 class LayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity : public LayerTreeHost Test {
769 public: 770 public:
770 LayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity() 771 LayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity()
771 { 772 {
772 } 773 }
773 774
774 virtual void beginTest() OVERRIDE 775 virtual void beginTest() OVERRIDE
775 { 776 {
776 m_layerTreeHost->rootLayer()->setDrawOpacity(1); 777 m_layerTreeHost->rootLayer()->setDrawOpacity(1);
777 m_layerTreeHost->setViewportSize(IntSize(10, 10), IntSize(10, 10)); 778 m_layerTreeHost->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10));
778 m_layerTreeHost->rootLayer()->setOpacity(0); 779 m_layerTreeHost->rootLayer()->setOpacity(0);
779 postAddAnimationToMainThread(); 780 postAddAnimationToMainThread();
780 } 781 }
781 782
782 virtual void commitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE 783 virtual void commitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE
783 { 784 {
784 // If the subtree was skipped when preparing to draw, the layer's draw o pacity 785 // If the subtree was skipped when preparing to draw, the layer's draw o pacity
785 // will not have been updated. It should be set to 0 due to the animatio n. 786 // will not have been updated. It should be set to 0 due to the animatio n.
786 // Without the animation, the layer will be skipped since it has zero op acity. 787 // Without the animation, the layer will be skipped since it has zero op acity.
787 EXPECT_EQ(0, m_layerTreeHost->rootLayer()->drawOpacity()); 788 EXPECT_EQ(0, m_layerTreeHost->rootLayer()->drawOpacity());
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 } 1022 }
1022 1023
1023 // This test verifies that properties on the layer tree host are commited to the impl side. 1024 // This test verifies that properties on the layer tree host are commited to the impl side.
1024 class LayerTreeHostTestCommit : public LayerTreeHostTest { 1025 class LayerTreeHostTestCommit : public LayerTreeHostTest {
1025 public: 1026 public:
1026 1027
1027 LayerTreeHostTestCommit() { } 1028 LayerTreeHostTestCommit() { }
1028 1029
1029 virtual void beginTest() OVERRIDE 1030 virtual void beginTest() OVERRIDE
1030 { 1031 {
1031 m_layerTreeHost->setViewportSize(IntSize(20, 20), IntSize(20, 20)); 1032 m_layerTreeHost->setViewportSize(gfx::Size(20, 20), gfx::Size(20, 20));
1032 m_layerTreeHost->setBackgroundColor(SK_ColorGRAY); 1033 m_layerTreeHost->setBackgroundColor(SK_ColorGRAY);
1033 m_layerTreeHost->setPageScaleFactorAndLimits(5, 5, 5); 1034 m_layerTreeHost->setPageScaleFactorAndLimits(5, 5, 5);
1034 1035
1035 postSetNeedsCommitToMainThread(); 1036 postSetNeedsCommitToMainThread();
1036 } 1037 }
1037 1038
1038 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE 1039 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE
1039 { 1040 {
1040 EXPECT_EQ(IntSize(20, 20), impl->layoutViewportSize()); 1041 EXPECT_EQ(gfx::Size(20, 20), impl->layoutViewportSize());
1041 EXPECT_EQ(SK_ColorGRAY, impl->backgroundColor()); 1042 EXPECT_EQ(SK_ColorGRAY, impl->backgroundColor());
1042 EXPECT_EQ(5, impl->pageScaleFactor()); 1043 EXPECT_EQ(5, impl->pageScaleFactor());
1043 1044
1044 endTest(); 1045 endTest();
1045 } 1046 }
1046 1047
1047 virtual void afterTest() OVERRIDE { } 1048 virtual void afterTest() OVERRIDE { }
1048 }; 1049 };
1049 1050
1050 TEST_F(LayerTreeHostTestCommit, runTest) 1051 TEST_F(LayerTreeHostTestCommit, runTest)
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 { 1185 {
1185 ContentLayer::update(queue, occlusion, stats); 1186 ContentLayer::update(queue, occlusion, stats);
1186 m_paintContentsCount++; 1187 m_paintContentsCount++;
1187 } 1188 }
1188 1189
1189 private: 1190 private:
1190 explicit ContentLayerWithUpdateTracking(ContentLayerClient* client) 1191 explicit ContentLayerWithUpdateTracking(ContentLayerClient* client)
1191 : ContentLayer(client) 1192 : ContentLayer(client)
1192 , m_paintContentsCount(0) 1193 , m_paintContentsCount(0)
1193 { 1194 {
1194 setAnchorPoint(FloatPoint(0, 0)); 1195 setAnchorPoint(gfx::PointF(0, 0));
1195 setBounds(IntSize(10, 10)); 1196 setBounds(gfx::Size(10, 10));
1196 setIsDrawable(true); 1197 setIsDrawable(true);
1197 } 1198 }
1198 virtual ~ContentLayerWithUpdateTracking() 1199 virtual ~ContentLayerWithUpdateTracking()
1199 { 1200 {
1200 } 1201 }
1201 1202
1202 int m_paintContentsCount; 1203 int m_paintContentsCount;
1203 }; 1204 };
1204 1205
1205 // Layer opacity change during paint should not prevent compositor resources fro m being updated during commit. 1206 // Layer opacity change during paint should not prevent compositor resources fro m being updated during commit.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 virtual void beginTest() OVERRIDE 1276 virtual void beginTest() OVERRIDE
1276 { 1277 {
1277 m_layerTreeHost->setViewportSize(IntSize(40, 40), IntSize(60, 60)); 1278 m_layerTreeHost->setViewportSize(IntSize(40, 40), IntSize(60, 60));
1278 m_layerTreeHost->setDeviceScaleFactor(1.5); 1279 m_layerTreeHost->setDeviceScaleFactor(1.5);
1279 EXPECT_EQ(IntSize(40, 40), m_layerTreeHost->layoutViewportSize()); 1280 EXPECT_EQ(IntSize(40, 40), m_layerTreeHost->layoutViewportSize());
1280 EXPECT_EQ(IntSize(60, 60), m_layerTreeHost->deviceViewportSize()); 1281 EXPECT_EQ(IntSize(60, 60), m_layerTreeHost->deviceViewportSize());
1281 1282
1282 m_rootLayer->addChild(m_childLayer); 1283 m_rootLayer->addChild(m_childLayer);
1283 1284
1284 m_rootLayer->setIsDrawable(true); 1285 m_rootLayer->setIsDrawable(true);
1285 m_rootLayer->setBounds(IntSize(30, 30)); 1286 m_rootLayer->setBounds(gfx::Size(30, 30));
1286 m_rootLayer->setAnchorPoint(FloatPoint(0, 0)); 1287 m_rootLayer->setAnchorPoint(FloatPoint(0, 0));
1287 1288
1288 m_childLayer->setIsDrawable(true); 1289 m_childLayer->setIsDrawable(true);
1289 m_childLayer->setPosition(IntPoint(2, 2)); 1290 m_childLayer->setPosition(gfx::Point(2, 2));
1290 m_childLayer->setBounds(IntSize(10, 10)); 1291 m_childLayer->setBounds(gfx::Size(10, 10));
1291 m_childLayer->setAnchorPoint(FloatPoint(0, 0)); 1292 m_childLayer->setAnchorPoint(FloatPoint(0, 0));
1292 1293
1293 m_layerTreeHost->setRootLayer(m_rootLayer); 1294 m_layerTreeHost->setRootLayer(m_rootLayer);
1294 } 1295 }
1295 1296
1296 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE 1297 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE
1297 { 1298 {
1298 // Get access to protected methods. 1299 // Get access to protected methods.
1299 MockLayerTreeHostImpl* mockImpl = static_cast<MockLayerTreeHostImpl*>(im pl); 1300 MockLayerTreeHostImpl* mockImpl = static_cast<MockLayerTreeHostImpl*>(im pl);
1300 1301
1301 // Should only do one commit. 1302 // Should only do one commit.
1302 EXPECT_EQ(0, impl->sourceFrameNumber()); 1303 EXPECT_EQ(0, impl->sourceFrameNumber());
1303 // Device scale factor should come over to impl. 1304 // Device scale factor should come over to impl.
1304 EXPECT_NEAR(impl->deviceScaleFactor(), 1.5, 0.00001); 1305 EXPECT_NEAR(impl->deviceScaleFactor(), 1.5, 0.00001);
1305 1306
1306 // Both layers are on impl. 1307 // Both layers are on impl.
1307 ASSERT_EQ(1u, impl->rootLayer()->children().size()); 1308 ASSERT_EQ(1u, impl->rootLayer()->children().size());
1308 1309
1309 // Device viewport is scaled. 1310 // Device viewport is scaled.
1310 EXPECT_EQ(IntSize(40, 40), impl->layoutViewportSize()); 1311 EXPECT_EQ(IntSize(40, 40), impl->layoutViewportSize());
1311 EXPECT_EQ(IntSize(60, 60), impl->deviceViewportSize()); 1312 EXPECT_EQ(IntSize(60, 60), impl->deviceViewportSize());
1312 1313
1313 LayerImpl* root = impl->rootLayer(); 1314 LayerImpl* root = impl->rootLayer();
1314 LayerImpl* child = impl->rootLayer()->children()[0]; 1315 LayerImpl* child = impl->rootLayer()->children()[0];
1315 1316
1316 // Positions remain in layout pixels. 1317 // Positions remain in layout pixels.
1317 EXPECT_EQ(IntPoint(0, 0), root->position()); 1318 EXPECT_EQ(gfx::Point(0, 0), root->position());
1318 EXPECT_EQ(IntPoint(2, 2), child->position()); 1319 EXPECT_EQ(gfx::Point(2, 2), child->position());
1319 1320
1320 // Compute all the layer transforms for the frame. 1321 // Compute all the layer transforms for the frame.
1321 MockLayerTreeHostImpl::LayerList renderSurfaceLayerList; 1322 MockLayerTreeHostImpl::LayerList renderSurfaceLayerList;
1322 mockImpl->calculateRenderSurfaceLayerList(renderSurfaceLayerList); 1323 mockImpl->calculateRenderSurfaceLayerList(renderSurfaceLayerList);
1323 1324
1324 // Both layers should be drawing into the root render surface. 1325 // Both layers should be drawing into the root render surface.
1325 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 1326 ASSERT_EQ(1u, renderSurfaceLayerList.size());
1326 ASSERT_EQ(root->renderSurface(), renderSurfaceLayerList[0]->renderSurfac e()); 1327 ASSERT_EQ(root->renderSurface(), renderSurfaceLayerList[0]->renderSurfac e());
1327 ASSERT_EQ(2u, root->renderSurface()->layerList().size()); 1328 ASSERT_EQ(2u, root->renderSurface()->layerList().size());
1328 1329
1329 // The root render surface is the size of the viewport. 1330 // The root render surface is the size of the viewport.
1330 EXPECT_RECT_EQ(IntRect(0, 0, 60, 60), root->renderSurface()->contentRect ()); 1331 EXPECT_RECT_EQ(IntRect(0, 0, 60, 60), root->renderSurface()->contentRect ());
1331 1332
1332 // The content bounds of the child should be scaled. 1333 // The content bounds of the child should be scaled.
1333 IntSize childBoundsScaled = child->bounds(); 1334 gfx::Size childBoundsScaled = child->bounds();
1334 childBoundsScaled.scale(1.5); 1335 childBoundsScaled = gfx::ToRoundedSize(childBoundsScaled.Scale(1.5));
1335 EXPECT_EQ(childBoundsScaled, child->contentBounds()); 1336 EXPECT_EQ(childBoundsScaled, child->contentBounds());
1336 1337
1337 WebTransformationMatrix scaleTransform; 1338 WebTransformationMatrix scaleTransform;
1338 scaleTransform.scale(impl->deviceScaleFactor()); 1339 scaleTransform.scale(impl->deviceScaleFactor());
1339 1340
1340 // The root layer is scaled by 2x. 1341 // The root layer is scaled by 2x.
1341 WebTransformationMatrix rootScreenSpaceTransform = scaleTransform; 1342 WebTransformationMatrix rootScreenSpaceTransform = scaleTransform;
1342 WebTransformationMatrix rootDrawTransform = scaleTransform; 1343 WebTransformationMatrix rootDrawTransform = scaleTransform;
1343 1344
1344 EXPECT_EQ(rootDrawTransform, root->drawTransform()); 1345 EXPECT_EQ(rootDrawTransform, root->drawTransform());
(...skipping 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after
3073 , m_numDrawLayers(0) 3074 , m_numDrawLayers(0)
3074 { 3075 {
3075 } 3076 }
3076 3077
3077 virtual void beginTest() OVERRIDE 3078 virtual void beginTest() OVERRIDE
3078 { 3079 {
3079 m_layerTreeHost->setViewportSize(IntSize(10, 10), IntSize(10, 10)); 3080 m_layerTreeHost->setViewportSize(IntSize(10, 10), IntSize(10, 10));
3080 m_layerTreeHost->rootLayer()->setBounds(IntSize(10, 10)); 3081 m_layerTreeHost->rootLayer()->setBounds(IntSize(10, 10));
3081 3082
3082 m_contentLayer = ContentLayer::create(&m_mockDelegate); 3083 m_contentLayer = ContentLayer::create(&m_mockDelegate);
3083 m_contentLayer->setBounds(IntSize(10, 10)); 3084 m_contentLayer->setBounds(gfx::Size(10, 10));
3084 m_contentLayer->setPosition(FloatPoint(0, 0)); 3085 m_contentLayer->setPosition(gfx::PointF(0, 0));
3085 m_contentLayer->setAnchorPoint(FloatPoint(0, 0)); 3086 m_contentLayer->setAnchorPoint(gfx::PointF(0, 0));
3086 m_contentLayer->setIsDrawable(true); 3087 m_contentLayer->setIsDrawable(true);
3087 m_layerTreeHost->rootLayer()->addChild(m_contentLayer); 3088 m_layerTreeHost->rootLayer()->addChild(m_contentLayer);
3088 3089
3089 postSetNeedsCommitToMainThread(); 3090 postSetNeedsCommitToMainThread();
3090 } 3091 }
3091 3092
3092 virtual void didCommit() OVERRIDE 3093 virtual void didCommit() OVERRIDE
3093 { 3094 {
3094 m_contentLayer->setNeedsDisplay(); 3095 m_contentLayer->setNeedsDisplay();
3095 } 3096 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
3177 int m_numCommitComplete; 3178 int m_numCommitComplete;
3178 int m_numDrawLayers; 3179 int m_numDrawLayers;
3179 }; 3180 };
3180 3181
3181 TEST_F(LayerTreeHostTestContinuousAnimate, runMultiThread) 3182 TEST_F(LayerTreeHostTestContinuousAnimate, runMultiThread)
3182 { 3183 {
3183 runTest(true); 3184 runTest(true);
3184 } 3185 }
3185 3186
3186 } // namespace 3187 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698