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

Side by Side Diff: services/ui/ws/frame_generator_unittest.cc

Issue 2613903003: Reland of "Mustash: Ensure surfaces submitted to Mus by WM and embedders contain Surfaces with embe… (Closed)
Patch Set: fix Created 3 years, 11 months 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
« no previous file with comments | « services/ui/ws/frame_generator_delegate.h ('k') | services/ui/ws/platform_display_default.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "services/ui/ws/frame_generator.h" 5 #include "services/ui/ws/frame_generator.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/test/test_message_loop.h" 10 #include "base/test/test_message_loop.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 } // namespace 46 } // namespace
47 47
48 class FrameGeneratorTest : public testing::Test { 48 class FrameGeneratorTest : public testing::Test {
49 public: 49 public:
50 FrameGeneratorTest() 50 FrameGeneratorTest()
51 : root_window_(base::MakeUnique<ServerWindow>(&window_delegate_, 51 : root_window_(base::MakeUnique<ServerWindow>(&window_delegate_,
52 kRootDisplayId)) {} 52 kRootDisplayId)) {}
53 ~FrameGeneratorTest() override {} 53 ~FrameGeneratorTest() override {}
54 54
55 // Calls DrawWindowTree() on |frame_generator_| 55 // Calls DrawWindow() on |frame_generator_|
56 void DrawWindowTree(cc::RenderPass* pass); 56 void DrawWindow(cc::RenderPass* pass);
57 57
58 ServerWindow* root_window() { return root_window_.get(); } 58 ServerWindow* root_window() { return root_window_.get(); }
59 59
60 TestServerWindowDelegate* test_window_delegate() { return &window_delegate_; } 60 TestServerWindowDelegate* test_window_delegate() { return &window_delegate_; }
61 61
62 private: 62 private:
63 // testing::Test: 63 // testing::Test:
64 void SetUp() override; 64 void SetUp() override;
65 void TearDown() override; 65 void TearDown() override;
66 66
67 std::unique_ptr<FrameGenerator> frame_generator_; 67 std::unique_ptr<FrameGenerator> frame_generator_;
68 std::unique_ptr<TestFrameGeneratorDelegate> frame_generator_delegate_; 68 std::unique_ptr<TestFrameGeneratorDelegate> frame_generator_delegate_;
69 TestServerWindowDelegate window_delegate_; 69 TestServerWindowDelegate window_delegate_;
70 std::unique_ptr<ServerWindow> root_window_; 70 std::unique_ptr<ServerWindow> root_window_;
71 71
72 // Needed so that Mojo classes can be initialized for ServerWindow use. 72 // Needed so that Mojo classes can be initialized for ServerWindow use.
73 base::TestMessageLoop message_loop_; 73 base::TestMessageLoop message_loop_;
74 74
75 DISALLOW_COPY_AND_ASSIGN(FrameGeneratorTest); 75 DISALLOW_COPY_AND_ASSIGN(FrameGeneratorTest);
76 }; 76 };
77 77
78 void FrameGeneratorTest::DrawWindowTree(cc::RenderPass* pass) { 78 void FrameGeneratorTest::DrawWindow(cc::RenderPass* pass) {
79 frame_generator_->DrawWindowTree(pass, root_window_.get(), gfx::Vector2d(), 79 frame_generator_->DrawWindow(pass, root_window_.get());
80 1.0f);
81 } 80 }
82 81
83 void FrameGeneratorTest::SetUp() { 82 void FrameGeneratorTest::SetUp() {
84 testing::Test::SetUp(); 83 testing::Test::SetUp();
85 frame_generator_delegate_ = base::MakeUnique<TestFrameGeneratorDelegate>(); 84 frame_generator_delegate_ =
85 base::MakeUnique<TestFrameGeneratorDelegate>(root_window_.get());
86 PlatformDisplayInitParams init_params; 86 PlatformDisplayInitParams init_params;
87 frame_generator_ = base::MakeUnique<FrameGenerator>( 87 frame_generator_ = base::MakeUnique<FrameGenerator>(
88 frame_generator_delegate_.get(), root_window_.get()); 88 frame_generator_delegate_.get(), root_window_.get());
89 frame_generator_->set_device_scale_factor( 89 frame_generator_->set_device_scale_factor(
90 init_params.metrics.device_scale_factor); 90 init_params.metrics.device_scale_factor);
91 InitWindow(root_window()); 91 InitWindow(root_window());
92 } 92 }
93 93
94 void FrameGeneratorTest::TearDown() { 94 void FrameGeneratorTest::TearDown() {
95 frame_generator_.reset(); 95 frame_generator_.reset();
96 frame_generator_delegate_.reset(); 96 frame_generator_delegate_.reset();
97 } 97 }
98 98
99 // Tests correctness of the SharedQuadStateList generated by 99 // Tests correctness of the SharedQuadStateList generated by
100 // FrameGenerator::DrawWindowTree(). 100 // FrameGenerator::DrawWindow().
101 TEST_F(FrameGeneratorTest, DrawWindowTree) { 101 TEST_F(FrameGeneratorTest, DrawWindow) {
102 ServerWindow child_window(test_window_delegate(), WindowId(1, 1)); 102 ServerWindow child_window(test_window_delegate(), WindowId(1, 1));
103 root_window()->Add(&child_window); 103 root_window()->Add(&child_window);
104 InitWindow(&child_window); 104 InitWindow(&child_window);
105 const float root_opacity = .5f;
106 const float child_opacity = .4f; 105 const float child_opacity = .4f;
107 root_window()->SetOpacity(root_opacity);
108 child_window.SetOpacity(child_opacity); 106 child_window.SetOpacity(child_opacity);
109 107
110 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); 108 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create();
111 DrawWindowTree(render_pass.get()); 109 DrawWindow(render_pass.get());
112 cc::SharedQuadStateList* quad_state_list = 110 cc::SharedQuadStateList* quad_state_list =
113 &render_pass->shared_quad_state_list; 111 &render_pass->shared_quad_state_list;
114 112
115 // Both child and root have a DEFAULT Surface and no underlay Surfaces, so 113 EXPECT_EQ(1u, quad_state_list->size());
116 // there should be two SharedQuadStates in the list.
117 EXPECT_EQ(2u, quad_state_list->size());
118 cc::SharedQuadState* root_sqs = quad_state_list->back(); 114 cc::SharedQuadState* root_sqs = quad_state_list->back();
119 cc::SharedQuadState* child_sqs = quad_state_list->front(); 115 // Opacity should always be 1.
120 EXPECT_EQ(root_opacity, root_sqs->opacity); 116 EXPECT_EQ(1.0f, root_sqs->opacity);
121 // Child's SharedQuadState contains the effective opacity of the child layer,
122 // which should be a product of the child and the parent opacity.
123 EXPECT_EQ(child_opacity * root_opacity, child_sqs->opacity);
124
125 // Pretend to create the UNDERLAY Surface for the child window, and confirm
126 // that this creates an extra SharedQuadState in the CompositorFrame.
127 child_window.GetOrCreateCompositorFrameSinkManager()->SetLatestSurfaceInfo(
128 mojom::CompositorFrameSinkType::UNDERLAY,
129 cc::SurfaceInfo(
130 cc::SurfaceId(
131 cc::FrameSinkId(WindowIdToTransportId(child_window.id()),
132 static_cast<uint32_t>(
133 mojom::CompositorFrameSinkType::UNDERLAY)),
134 cc::LocalFrameId(1u, kArbitraryToken)),
135 1.0f, gfx::Size(100, 100)));
136
137 render_pass = cc::RenderPass::Create();
138 DrawWindowTree(render_pass.get());
139 quad_state_list = &render_pass->shared_quad_state_list;
140 EXPECT_EQ(3u, quad_state_list->size());
141 auto it = quad_state_list->begin();
142 EXPECT_EQ(child_opacity * root_opacity, (*it)->opacity);
143 EXPECT_EQ(child_opacity * root_opacity, (*++it)->opacity);
144 EXPECT_EQ(root_opacity, (*++it)->opacity);
145 } 117 }
146 118
147 } // namespace test 119 } // namespace test
148 } // namespace ws 120 } // namespace ws
149 } // namespace ui 121 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/frame_generator_delegate.h ('k') | services/ui/ws/platform_display_default.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698