Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <memory> | |
| 6 | |
| 7 #include "base/test/test_message_loop.h" | |
| 8 #include "cc/quads/render_pass.h" | |
| 9 #include "cc/quads/shared_quad_state.h" | |
| 10 #include "components/mus/gles2/gpu_state.h" | |
| 11 #include "components/mus/ws/frame_generator.h" | |
|
sky
2016/07/01 16:04:13
nit: this should be your first include, just like
mfomitchev
2016/07/07 14:49:56
Done.
| |
| 12 #include "components/mus/ws/platform_display_init_params.h" | |
| 13 #include "components/mus/ws/server_window.h" | |
| 14 #include "components/mus/ws/server_window_surface_manager.h" | |
| 15 #include "components/mus/ws/test_server_window_delegate.h" | |
| 16 #include "components/mus/ws/test_utils.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | |
| 18 | |
| 19 namespace mus { | |
| 20 namespace ws { | |
| 21 namespace test { | |
| 22 namespace { | |
| 23 | |
| 24 // Makes the window visible and creates the default surface for it. | |
| 25 void InitWindow(ServerWindow* window) { | |
| 26 window->SetVisible(true); | |
| 27 ServerWindowSurfaceManager* surface_manager = | |
| 28 window->GetOrCreateSurfaceManager(); | |
| 29 surface_manager->CreateSurface(mojom::SurfaceType::DEFAULT, | |
| 30 mojo::InterfaceRequest<mojom::Surface>(), | |
| 31 mojom::SurfaceClientPtr()); | |
| 32 } | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 class FrameGeneratorTest : public testing::Test { | |
| 37 public: | |
| 38 FrameGeneratorTest() {} | |
| 39 ~FrameGeneratorTest() override {} | |
| 40 | |
| 41 // Calls DrawWindowTree() on |frame_generator_| | |
| 42 void DrawWindowTree(cc::RenderPass* pass); | |
| 43 | |
| 44 ServerWindow* root_window() { | |
| 45 return frame_generator_delegate_->GetRootWindow(); | |
| 46 } | |
| 47 | |
| 48 TestServerWindowDelegate* test_window_delegate() { return &window_delegate_; } | |
| 49 | |
| 50 private: | |
| 51 // testing::Test: | |
| 52 void SetUp() override; | |
| 53 void TearDown() override; | |
| 54 | |
| 55 std::unique_ptr<FrameGenerator> frame_generator_; | |
| 56 std::unique_ptr<TestFrameGeneratorDelegate> frame_generator_delegate_; | |
| 57 TestServerWindowDelegate window_delegate_; | |
| 58 | |
| 59 // Needed so that Mojo classes can be initialized for ServerWindow use. | |
| 60 base::TestMessageLoop message_loop_; | |
| 61 | |
| 62 DISALLOW_COPY_AND_ASSIGN(FrameGeneratorTest); | |
| 63 }; | |
| 64 | |
| 65 void FrameGeneratorTest::DrawWindowTree(cc::RenderPass* pass) { | |
| 66 frame_generator_->DrawWindowTree(pass, | |
| 67 frame_generator_delegate_->GetRootWindow(), | |
| 68 gfx::Vector2d(), | |
| 69 1.0f); | |
| 70 } | |
| 71 | |
| 72 void FrameGeneratorTest::SetUp() { | |
| 73 testing::Test::SetUp(); | |
| 74 frame_generator_delegate_.reset(new TestFrameGeneratorDelegate( | |
| 75 base::WrapUnique(new ServerWindow(&window_delegate_, WindowId())))); | |
| 76 PlatformDisplayInitParams init_params; | |
| 77 frame_generator_.reset( | |
| 78 new FrameGenerator(frame_generator_delegate_.get(), | |
| 79 init_params.gpu_state, | |
| 80 init_params.surfaces_state)); | |
| 81 InitWindow(root_window()); | |
| 82 } | |
| 83 | |
| 84 void FrameGeneratorTest::TearDown() { | |
| 85 frame_generator_.reset(); | |
| 86 frame_generator_delegate_.reset(); | |
| 87 } | |
| 88 | |
| 89 // Tests correctness of the SharedQuadStateList generated by | |
| 90 // FrameGenerator::DrawWindowTree(). | |
| 91 TEST_F(FrameGeneratorTest, DrawWindowTree) { | |
| 92 ServerWindow child_window(test_window_delegate(), WindowId()); | |
| 93 root_window()->Add(&child_window); | |
| 94 InitWindow(&child_window); | |
| 95 const float root_opacity = .5f; | |
| 96 const float child_opacity = .4f; | |
| 97 root_window()->SetOpacity(root_opacity); | |
| 98 child_window.SetOpacity(child_opacity); | |
| 99 | |
| 100 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); | |
| 101 DrawWindowTree(render_pass.get()); | |
| 102 cc::SharedQuadStateList* quad_state_list = | |
| 103 &render_pass->shared_quad_state_list; | |
| 104 | |
| 105 // Both child and root have a DEFAULT Surface and no underlay Surfaces, so | |
| 106 // there should be two SharedQuadStates in the list. | |
| 107 EXPECT_EQ(2u, quad_state_list->size()); | |
| 108 cc::SharedQuadState* root_sqs = quad_state_list->back(); | |
| 109 cc::SharedQuadState* child_sqs = quad_state_list->front(); | |
| 110 EXPECT_EQ(root_opacity, root_sqs->opacity); | |
| 111 // Child's SharedQuadState contains the effective opacity of the child layer, | |
| 112 // which should be a product of the child and the parent opacity. | |
| 113 EXPECT_EQ(child_opacity * root_opacity, child_sqs->opacity); | |
| 114 | |
| 115 // Create the UNDERLAY Surface for the child window, and confirm that this | |
| 116 // creates an extra SharedQuadState in the CompositorFrame. | |
| 117 child_window.GetOrCreateSurfaceManager()->CreateSurface( | |
| 118 mojom::SurfaceType::UNDERLAY, mojo::InterfaceRequest<mojom::Surface>(), | |
| 119 mojom::SurfaceClientPtr()); | |
| 120 | |
| 121 render_pass = cc::RenderPass::Create(); | |
| 122 DrawWindowTree(render_pass.get()); | |
| 123 quad_state_list = &render_pass->shared_quad_state_list; | |
| 124 EXPECT_EQ(3u, quad_state_list->size()); | |
| 125 auto it = quad_state_list->begin(); | |
| 126 EXPECT_EQ(child_opacity * root_opacity, (*it)->opacity); | |
| 127 EXPECT_EQ(child_opacity * root_opacity, (*++it)->opacity); | |
| 128 EXPECT_EQ(root_opacity, (*++it)->opacity); | |
| 129 } | |
| 130 | |
| 131 } // namespace test | |
| 132 } // namespace ws | |
| 133 } // namespace mus | |
| OLD | NEW |