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