OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "platform/graphics/compositing/PaintArtifactCompositor.h" | 5 #include "platform/graphics/compositing/PaintArtifactCompositor.h" |
6 | 6 |
7 #include "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
9 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
10 #include "cc/test/fake_output_surface.h" | 10 #include "cc/test/fake_output_surface.h" |
11 #include "cc/trees/layer_tree_host.h" | 11 #include "cc/trees/layer_tree_host.h" |
12 #include "cc/trees/layer_tree_settings.h" | 12 #include "cc/trees/layer_tree_settings.h" |
13 #include "platform/RuntimeEnabledFeatures.h" | 13 #include "platform/RuntimeEnabledFeatures.h" |
14 #include "platform/graphics/paint/PaintArtifact.h" | 14 #include "platform/graphics/paint/PaintArtifact.h" |
15 #include "platform/testing/PictureMatchers.h" | 15 #include "platform/testing/PictureMatchers.h" |
16 #include "platform/testing/TestPaintArtifact.h" | 16 #include "platform/testing/TestPaintArtifact.h" |
17 #include "platform/testing/WebLayerTreeViewImplForTesting.h" | 17 #include "platform/testing/WebLayerTreeViewImplForTesting.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "wtf/PtrUtil.h" |
| 21 #include <memory> |
20 | 22 |
21 namespace blink { | 23 namespace blink { |
22 namespace { | 24 namespace { |
23 | 25 |
24 using ::testing::Pointee; | 26 using ::testing::Pointee; |
25 | 27 |
26 gfx::Transform translation(SkMScalar x, SkMScalar y) | 28 gfx::Transform translation(SkMScalar x, SkMScalar y) |
27 { | 29 { |
28 gfx::Transform transform; | 30 gfx::Transform transform; |
29 transform.Translate(x, y); | 31 transform.Translate(x, y); |
30 return transform; | 32 return transform; |
31 } | 33 } |
32 | 34 |
33 class PaintArtifactCompositorTest : public ::testing::Test { | 35 class PaintArtifactCompositorTest : public ::testing::Test { |
34 protected: | 36 protected: |
35 void SetUp() override | 37 void SetUp() override |
36 { | 38 { |
37 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); | 39 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); |
38 | 40 |
39 // Delay constructing the compositor until after the feature is set. | 41 // Delay constructing the compositor until after the feature is set. |
40 m_paintArtifactCompositor = adoptPtr(new PaintArtifactCompositor); | 42 m_paintArtifactCompositor = wrapUnique(new PaintArtifactCompositor); |
41 } | 43 } |
42 | 44 |
43 void TearDown() override | 45 void TearDown() override |
44 { | 46 { |
45 m_featuresBackup.restore(); | 47 m_featuresBackup.restore(); |
46 } | 48 } |
47 | 49 |
48 PaintArtifactCompositor& getPaintArtifactCompositor() { return *m_paintArtif
actCompositor; } | 50 PaintArtifactCompositor& getPaintArtifactCompositor() { return *m_paintArtif
actCompositor; } |
49 cc::Layer* rootLayer() { return m_paintArtifactCompositor->rootLayer(); } | 51 cc::Layer* rootLayer() { return m_paintArtifactCompositor->rootLayer(); } |
50 void update(const PaintArtifact& artifact) { m_paintArtifactCompositor->upda
te(artifact); } | 52 void update(const PaintArtifact& artifact) { m_paintArtifactCompositor->upda
te(artifact); } |
51 | 53 |
52 private: | 54 private: |
53 RuntimeEnabledFeatures::Backup m_featuresBackup; | 55 RuntimeEnabledFeatures::Backup m_featuresBackup; |
54 OwnPtr<PaintArtifactCompositor> m_paintArtifactCompositor; | 56 std::unique_ptr<PaintArtifactCompositor> m_paintArtifactCompositor; |
55 }; | 57 }; |
56 | 58 |
57 TEST_F(PaintArtifactCompositorTest, EmptyPaintArtifact) | 59 TEST_F(PaintArtifactCompositorTest, EmptyPaintArtifact) |
58 { | 60 { |
59 PaintArtifact emptyArtifact; | 61 PaintArtifact emptyArtifact; |
60 update(emptyArtifact); | 62 update(emptyArtifact); |
61 EXPECT_TRUE(rootLayer()->children().empty()); | 63 EXPECT_TRUE(rootLayer()->children().empty()); |
62 } | 64 } |
63 | 65 |
64 TEST_F(PaintArtifactCompositorTest, OneChunkWithAnOffset) | 66 TEST_F(PaintArtifactCompositorTest, OneChunkWithAnOffset) |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 { | 380 { |
379 } | 381 } |
380 | 382 |
381 void SetUp() override | 383 void SetUp() override |
382 { | 384 { |
383 PaintArtifactCompositorTest::SetUp(); | 385 PaintArtifactCompositorTest::SetUp(); |
384 | 386 |
385 cc::LayerTreeSettings settings = WebLayerTreeViewImplForTesting::default
LayerTreeSettings(); | 387 cc::LayerTreeSettings settings = WebLayerTreeViewImplForTesting::default
LayerTreeSettings(); |
386 settings.single_thread_proxy_scheduler = false; | 388 settings.single_thread_proxy_scheduler = false; |
387 settings.use_layer_lists = true; | 389 settings.use_layer_lists = true; |
388 m_webLayerTreeView = adoptPtr(new WebLayerTreeViewWithOutputSurface(sett
ings)); | 390 m_webLayerTreeView = wrapUnique(new WebLayerTreeViewWithOutputSurface(se
ttings)); |
389 m_webLayerTreeView->setRootLayer(*getPaintArtifactCompositor().getWebLay
er()); | 391 m_webLayerTreeView->setRootLayer(*getPaintArtifactCompositor().getWebLay
er()); |
390 } | 392 } |
391 | 393 |
392 const cc::PropertyTrees& propertyTrees() | 394 const cc::PropertyTrees& propertyTrees() |
393 { | 395 { |
394 return *m_webLayerTreeView->layerTreeHost()->property_trees(); | 396 return *m_webLayerTreeView->layerTreeHost()->property_trees(); |
395 } | 397 } |
396 | 398 |
397 void update(const PaintArtifact& artifact) | 399 void update(const PaintArtifact& artifact) |
398 { | 400 { |
399 PaintArtifactCompositorTest::update(artifact); | 401 PaintArtifactCompositorTest::update(artifact); |
400 m_webLayerTreeView->layerTreeHost()->LayoutAndUpdateLayers(); | 402 m_webLayerTreeView->layerTreeHost()->LayoutAndUpdateLayers(); |
401 } | 403 } |
402 | 404 |
403 private: | 405 private: |
404 scoped_refptr<base::TestSimpleTaskRunner> m_taskRunner; | 406 scoped_refptr<base::TestSimpleTaskRunner> m_taskRunner; |
405 base::ThreadTaskRunnerHandle m_taskRunnerHandle; | 407 base::ThreadTaskRunnerHandle m_taskRunnerHandle; |
406 OwnPtr<WebLayerTreeViewWithOutputSurface> m_webLayerTreeView; | 408 std::unique_ptr<WebLayerTreeViewWithOutputSurface> m_webLayerTreeView; |
407 }; | 409 }; |
408 | 410 |
409 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EmptyPaintArtifact) | 411 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EmptyPaintArtifact) |
410 { | 412 { |
411 PaintArtifact emptyArtifact; | 413 PaintArtifact emptyArtifact; |
412 update(emptyArtifact); | 414 update(emptyArtifact); |
413 EXPECT_TRUE(rootLayer()->children().empty()); | 415 EXPECT_TRUE(rootLayer()->children().empty()); |
414 } | 416 } |
415 | 417 |
416 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneChunkWithAnOffset) | 418 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneChunkWithAnOffset) |
417 { | 419 { |
418 TestPaintArtifact artifact; | 420 TestPaintArtifact artifact; |
419 artifact.chunk(PaintChunkProperties()) | 421 artifact.chunk(PaintChunkProperties()) |
420 .rectDrawing(FloatRect(50, -50, 100, 100), Color::white); | 422 .rectDrawing(FloatRect(50, -50, 100, 100), Color::white); |
421 update(artifact.build()); | 423 update(artifact.build()); |
422 | 424 |
423 ASSERT_EQ(1u, rootLayer()->children().size()); | 425 ASSERT_EQ(1u, rootLayer()->children().size()); |
424 const cc::Layer* child = rootLayer()->child_at(0); | 426 const cc::Layer* child = rootLayer()->child_at(0); |
425 EXPECT_THAT(child->GetPicture(), | 427 EXPECT_THAT(child->GetPicture(), |
426 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white))); | 428 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white))); |
427 EXPECT_EQ(translation(50, -50), child->screen_space_transform()); | 429 EXPECT_EQ(translation(50, -50), child->screen_space_transform()); |
428 EXPECT_EQ(gfx::Size(100, 100), child->bounds()); | 430 EXPECT_EQ(gfx::Size(100, 100), child->bounds()); |
429 } | 431 } |
430 | 432 |
431 } // namespace | 433 } // namespace |
432 } // namespace blink | 434 } // namespace blink |
OLD | NEW |