| OLD | NEW |
| 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 "CCLayerTreeHost.h" | 7 #include "CCLayerTreeHost.h" |
| 8 | 8 |
| 9 #include "CCGeometryTestUtils.h" | 9 #include "CCGeometryTestUtils.h" |
| 10 #include "CCGraphicsContext.h" | 10 #include "CCGraphicsContext.h" |
| (...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 } | 1252 } |
| 1253 | 1253 |
| 1254 class MockContentLayerChromiumClient : public ContentLayerChromiumClient { | 1254 class MockContentLayerChromiumClient : public ContentLayerChromiumClient { |
| 1255 public: | 1255 public: |
| 1256 bool drawsContent() const { return true; } | 1256 bool drawsContent() const { return true; } |
| 1257 MOCK_CONST_METHOD0(preserves3D, bool()); | 1257 MOCK_CONST_METHOD0(preserves3D, bool()); |
| 1258 void paintContents(SkCanvas*, const IntRect&, FloatRect&) OVERRIDE { } | 1258 void paintContents(SkCanvas*, const IntRect&, FloatRect&) OVERRIDE { } |
| 1259 void notifySyncRequired() { } | 1259 void notifySyncRequired() { } |
| 1260 }; | 1260 }; |
| 1261 | 1261 |
| 1262 class NoScaleContentLayerChromium : public ContentLayerChromium { |
| 1263 public: |
| 1264 static PassRefPtr<NoScaleContentLayerChromium> create(ContentLayerChromiumCl
ient* client) { return adoptRef(new NoScaleContentLayerChromium(client)); } |
| 1265 |
| 1266 virtual bool needsContentsScale() const OVERRIDE { return false; } |
| 1267 |
| 1268 private: |
| 1269 explicit NoScaleContentLayerChromium(ContentLayerChromiumClient* client) |
| 1270 : ContentLayerChromium(client) { } |
| 1271 }; |
| 1272 |
| 1262 class CCLayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers : public CCLay
erTreeHostTest { | 1273 class CCLayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers : public CCLay
erTreeHostTest { |
| 1263 public: | 1274 public: |
| 1264 | 1275 |
| 1265 CCLayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers() | 1276 CCLayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers() |
| 1266 : m_rootLayer(ContentLayerChromium::create(&m_client)) | 1277 : m_rootLayer(NoScaleContentLayerChromium::create(&m_client)) |
| 1267 , m_childLayer(ContentLayerChromium::create(&m_client)) | 1278 , m_childLayer(ContentLayerChromium::create(&m_client)) |
| 1268 { | 1279 { |
| 1269 } | 1280 } |
| 1270 | 1281 |
| 1271 virtual void beginTest() OVERRIDE | 1282 virtual void beginTest() OVERRIDE |
| 1272 { | 1283 { |
| 1273 m_layerTreeHost->setViewportSize(IntSize(40, 40), IntSize(60, 60)); | 1284 m_layerTreeHost->setViewportSize(IntSize(40, 40), IntSize(60, 60)); |
| 1274 m_layerTreeHost->setDeviceScaleFactor(1.5); | 1285 m_layerTreeHost->setDeviceScaleFactor(1.5); |
| 1275 EXPECT_EQ(IntSize(40, 40), m_layerTreeHost->layoutViewportSize()); | 1286 EXPECT_EQ(IntSize(40, 40), m_layerTreeHost->layoutViewportSize()); |
| 1276 EXPECT_EQ(IntSize(60, 60), m_layerTreeHost->deviceViewportSize()); | 1287 EXPECT_EQ(IntSize(60, 60), m_layerTreeHost->deviceViewportSize()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 mockImpl->calculateRenderSurfaceLayerList(renderSurfaceLayerList); | 1329 mockImpl->calculateRenderSurfaceLayerList(renderSurfaceLayerList); |
| 1319 | 1330 |
| 1320 // Both layers should be drawing into the root render surface. | 1331 // Both layers should be drawing into the root render surface. |
| 1321 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | 1332 ASSERT_EQ(1u, renderSurfaceLayerList.size()); |
| 1322 ASSERT_EQ(root->renderSurface(), renderSurfaceLayerList[0]->renderSurfac
e()); | 1333 ASSERT_EQ(root->renderSurface(), renderSurfaceLayerList[0]->renderSurfac
e()); |
| 1323 ASSERT_EQ(2u, root->renderSurface()->layerList().size()); | 1334 ASSERT_EQ(2u, root->renderSurface()->layerList().size()); |
| 1324 | 1335 |
| 1325 // The root render surface is the size of the viewport. | 1336 // The root render surface is the size of the viewport. |
| 1326 EXPECT_RECT_EQ(IntRect(0, 0, 60, 60), root->renderSurface()->contentRect
()); | 1337 EXPECT_RECT_EQ(IntRect(0, 0, 60, 60), root->renderSurface()->contentRect
()); |
| 1327 | 1338 |
| 1339 // The content bounds of the child should be scaled. |
| 1340 IntSize childBoundsScaled = child->bounds(); |
| 1341 childBoundsScaled.scale(1.5); |
| 1342 EXPECT_EQ(childBoundsScaled, child->contentBounds()); |
| 1343 |
| 1328 WebTransformationMatrix scaleTransform; | 1344 WebTransformationMatrix scaleTransform; |
| 1329 scaleTransform.scale(impl->deviceScaleFactor()); | 1345 scaleTransform.scale(impl->deviceScaleFactor()); |
| 1330 | 1346 |
| 1331 // The root layer is scaled by 2x. | 1347 // The root layer is scaled by 2x. |
| 1332 WebTransformationMatrix rootScreenSpaceTransform = scaleTransform; | 1348 WebTransformationMatrix rootScreenSpaceTransform = scaleTransform; |
| 1333 WebTransformationMatrix rootDrawTransform = scaleTransform; | 1349 WebTransformationMatrix rootDrawTransform = scaleTransform; |
| 1334 | 1350 |
| 1335 EXPECT_EQ(rootDrawTransform, root->drawTransform()); | 1351 EXPECT_EQ(rootDrawTransform, root->drawTransform()); |
| 1336 EXPECT_EQ(rootScreenSpaceTransform, root->screenSpaceTransform()); | 1352 EXPECT_EQ(rootScreenSpaceTransform, root->screenSpaceTransform()); |
| 1337 | 1353 |
| 1338 // The child is at position 2,2, so translate by 2,2 before applying the
scale by 2x. | 1354 // The child is at position 2,2, which is transformed to 3,3 after the s
cale |
| 1339 WebTransformationMatrix childScreenSpaceTransform = scaleTransform; | 1355 WebTransformationMatrix childScreenSpaceTransform; |
| 1340 childScreenSpaceTransform.translate(2, 2); | 1356 childScreenSpaceTransform.translate(3, 3); |
| 1341 WebTransformationMatrix childDrawTransform = scaleTransform; | 1357 WebTransformationMatrix childDrawTransform = childScreenSpaceTransform; |
| 1342 childDrawTransform.translate(2, 2); | |
| 1343 | 1358 |
| 1344 EXPECT_EQ(childDrawTransform, child->drawTransform()); | 1359 EXPECT_EQ(childDrawTransform, child->drawTransform()); |
| 1345 EXPECT_EQ(childScreenSpaceTransform, child->screenSpaceTransform()); | 1360 EXPECT_EQ(childScreenSpaceTransform, child->screenSpaceTransform()); |
| 1346 | 1361 |
| 1347 endTest(); | 1362 endTest(); |
| 1348 } | 1363 } |
| 1349 | 1364 |
| 1350 virtual void afterTest() OVERRIDE | 1365 virtual void afterTest() OVERRIDE |
| 1351 { | 1366 { |
| 1352 m_rootLayer.clear(); | 1367 m_rootLayer.clear(); |
| 1353 m_childLayer.clear(); | 1368 m_childLayer.clear(); |
| 1354 } | 1369 } |
| 1355 | 1370 |
| 1356 private: | 1371 private: |
| 1357 MockContentLayerChromiumClient m_client; | 1372 MockContentLayerChromiumClient m_client; |
| 1358 RefPtr<ContentLayerChromium> m_rootLayer; | 1373 RefPtr<NoScaleContentLayerChromium> m_rootLayer; |
| 1359 RefPtr<ContentLayerChromium> m_childLayer; | 1374 RefPtr<ContentLayerChromium> m_childLayer; |
| 1360 }; | 1375 }; |
| 1361 | 1376 |
| 1362 TEST_F(CCLayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers, runMultiThre
ad) | 1377 TEST_F(CCLayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers, runMultiThre
ad) |
| 1363 { | 1378 { |
| 1364 runTest(true); | 1379 runTest(true); |
| 1365 } | 1380 } |
| 1366 | 1381 |
| 1367 // Verify atomicity of commits and reuse of textures. | 1382 // Verify atomicity of commits and reuse of textures. |
| 1368 class CCLayerTreeHostTestAtomicCommit : public CCLayerTreeHostTest { | 1383 class CCLayerTreeHostTestAtomicCommit : public CCLayerTreeHostTest { |
| (...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2327 m_surfaceLayer2->setReplicaLayer(m_replicaLayer2.get()); | 2342 m_surfaceLayer2->setReplicaLayer(m_replicaLayer2.get()); |
| 2328 | 2343 |
| 2329 m_rootLayer->addChild(m_surfaceLayer1); | 2344 m_rootLayer->addChild(m_surfaceLayer1); |
| 2330 m_surfaceLayer1->addChild(m_surfaceLayer2); | 2345 m_surfaceLayer1->addChild(m_surfaceLayer2); |
| 2331 m_layerTreeHost->setRootLayer(m_rootLayer); | 2346 m_layerTreeHost->setRootLayer(m_rootLayer); |
| 2332 } | 2347 } |
| 2333 | 2348 |
| 2334 virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* hostImpl) OVERRIDE | 2349 virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* hostImpl) OVERRIDE |
| 2335 { | 2350 { |
| 2336 CCRenderer* renderer = hostImpl->renderer(); | 2351 CCRenderer* renderer = hostImpl->renderer(); |
| 2337 unsigned surface1RenderPassId = hostImpl->rootLayer()->children()[0]->id
(); | 2352 CCRenderPass::Id surface1RenderPassId = hostImpl->rootLayer()->children(
)[0]->renderSurface()->renderPassId(); |
| 2338 unsigned surface2RenderPassId = hostImpl->rootLayer()->children()[0]->ch
ildren()[0]->id(); | 2353 CCRenderPass::Id surface2RenderPassId = hostImpl->rootLayer()->children(
)[0]->children()[0]->renderSurface()->renderPassId(); |
| 2339 | 2354 |
| 2340 switch (hostImpl->sourceFrameNumber()) { | 2355 switch (hostImpl->sourceFrameNumber()) { |
| 2341 case 0: | 2356 case 0: |
| 2342 EXPECT_TRUE(renderer->haveCachedResourcesForRenderPassId(surface1Ren
derPassId)); | 2357 EXPECT_TRUE(renderer->haveCachedResourcesForRenderPassId(surface1Ren
derPassId)); |
| 2343 EXPECT_TRUE(renderer->haveCachedResourcesForRenderPassId(surface2Ren
derPassId)); | 2358 EXPECT_TRUE(renderer->haveCachedResourcesForRenderPassId(surface2Ren
derPassId)); |
| 2344 | 2359 |
| 2345 // Reduce the memory limit to only fit the root layer and one render
surface. This | 2360 // Reduce the memory limit to only fit the root layer and one render
surface. This |
| 2346 // prevents any contents drawing into surfaces from being allocated. | 2361 // prevents any contents drawing into surfaces from being allocated. |
| 2347 hostImpl->setMemoryAllocationLimitBytes(100 * 100 * 4 * 2); | 2362 hostImpl->setMemoryAllocationLimitBytes(100 * 100 * 4 * 2); |
| 2348 break; | 2363 break; |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2808 int m_numChildren; | 2823 int m_numChildren; |
| 2809 Vector<RefPtr<ContentLayerChromiumWithUpdateTracking> > m_children; | 2824 Vector<RefPtr<ContentLayerChromiumWithUpdateTracking> > m_children; |
| 2810 }; | 2825 }; |
| 2811 | 2826 |
| 2812 TEST_F(CCLayerTreeHostTestLostContextWhileUpdatingResources, runMultiThread) | 2827 TEST_F(CCLayerTreeHostTestLostContextWhileUpdatingResources, runMultiThread) |
| 2813 { | 2828 { |
| 2814 runTest(true); | 2829 runTest(true); |
| 2815 } | 2830 } |
| 2816 | 2831 |
| 2817 } // namespace | 2832 } // namespace |
| OLD | NEW |