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

Side by Side Diff: components/mus/ws/platform_display_unittest.cc

Issue 2099893002: Mus: Fixes rendering of transparent containers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
(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/memory/ptr_util.h"
8 #include "base/test/test_message_loop.h"
9 #include "cc/quads/render_pass.h"
10 #include "cc/quads/shared_quad_state.h"
11 #include "components/mus/ws/platform_display.h"
12 #include "components/mus/ws/server_window.h"
13 #include "components/mus/ws/server_window_surface_manager.h"
14 #include "components/mus/ws/test_server_window_delegate.h"
15 #include "components/mus/ws/test_utils.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace mus {
19 namespace ws {
20 namespace test {
21 namespace {
22
23 // Makes the window visible and creates the default surface for it.
24 void InitWindow(ServerWindow* window) {
25 window->SetVisible(true);
26 ServerWindowSurfaceManager* surface_manager =
27 window->GetOrCreateSurfaceManager();
28 surface_manager->CreateSurface(mojom::SurfaceType::DEFAULT,
29 mojo::InterfaceRequest<mojom::Surface>(),
30 mojom::SurfaceClientPtr());
31 }
32
33 // Gets the RenderPassList from the |delegated_frame_data| of the
34 // CompositorFrame, confirms it has exactly one RenderPass, and returns its
35 // SharedQuadStateList.
36 cc::SharedQuadStateList* GetSharedQuadStateListFromCompositorFrame(
37 cc::CompositorFrame* cf) {
38 cc::DelegatedFrameData* frame_data = cf->delegated_frame_data.get();
39 EXPECT_TRUE(frame_data);
sky 2016/06/27 15:17:08 If frame_data is null then line 40 crashes. I reco
mfomitchev 2016/06/30 22:06:03 Done.
40 EXPECT_EQ(1u, frame_data->render_pass_list.size());
41 cc::RenderPass* render_pass = frame_data->render_pass_list.back().get();
42 EXPECT_TRUE(render_pass);
43 cc::SharedQuadStateList* quad_state_list =
44 &render_pass->shared_quad_state_list;
45 EXPECT_TRUE(quad_state_list);
46 return quad_state_list;
47 }
48
49 } // namespace
50
51 class PlatformDisplayTest : public testing::Test {
52 public:
53 PlatformDisplayTest() {}
54 ~PlatformDisplayTest() override {}
55
56 // Calls GenerateCompositorFrame() on the |platform_display_|.
57 std::unique_ptr<cc::CompositorFrame> GenerateCompositorFrame();
58
59 ServerWindow* root_window() {
60 return platform_display_delegate_->GetRootWindow();
61 }
62
63 TestServerWindowDelegate* test_window_delegate() { return &window_delegate_; }
64
65 private:
66 // testing::Test:
67 void SetUp() override;
68 void TearDown() override;
69
70 std::unique_ptr<DefaultPlatformDisplay> platform_display_;
71 std::unique_ptr<TestPlatformDisplayDelegate> platform_display_delegate_;
72 TestServerWindowDelegate window_delegate_;
73
74 // Needed so that Mojo classes can be initialized.
75 base::TestMessageLoop message_loop_;
76
77 DISALLOW_COPY_AND_ASSIGN(PlatformDisplayTest);
78 };
79
80 std::unique_ptr<cc::CompositorFrame>
81 PlatformDisplayTest::GenerateCompositorFrame() {
82 return platform_display_->GenerateCompositorFrame();
83 }
84
85 void PlatformDisplayTest::SetUp() {
86 testing::Test::SetUp();
87 platform_display_delegate_.reset(new TestPlatformDisplayDelegate(
88 base::WrapUnique(new ServerWindow(&window_delegate_, WindowId()))));
89 platform_display_.reset(
90 new DefaultPlatformDisplay(PlatformDisplayInitParams()));
91 platform_display_->set_delegate_for_testing(platform_display_delegate_.get());
92 InitWindow(root_window());
93 }
94
95 void PlatformDisplayTest::TearDown() {
96 platform_display_.reset();
97 platform_display_delegate_.reset();
98 }
99
100 // Tests correctness of the SharedQuadStateList in the CompositorFrame generated
101 // by DefaultPlatformDisplay::GenerateCompositorFrame() from the window tree.
102 TEST_F(PlatformDisplayTest, GenerateCompositorFrame) {
103 ServerWindow child_window(test_window_delegate(), WindowId());
104 root_window()->Add(&child_window);
105 InitWindow(&child_window);
106 const float root_opacity = .5f;
107 const float child_opacity = .4f;
108 root_window()->SetOpacity(root_opacity);
109 child_window.SetOpacity(child_opacity);
110
111 std::unique_ptr<cc::CompositorFrame> cf = GenerateCompositorFrame();
112 cc::SharedQuadStateList* quad_state_list =
113 GetSharedQuadStateListFromCompositorFrame(cf.get());
114 // Both child and root have a DEFAULT Surface and no underlay Surfaces, so
115 // there should be two SharedQuadStates int he list.
116 EXPECT_EQ(2u, quad_state_list->size());
sky 2016/06/27 15:17:08 How fragile is this code? By that I mean it seems
Fady Samuel 2016/06/27 15:20:03 drive-by +1 I think DrawWindowTree and associated
mfomitchev 2016/06/30 22:06:03 Switched to testing DrawWindowTree directly. I am
117 cc::SharedQuadState* root_sqs = quad_state_list->back();
118 cc::SharedQuadState* child_sqs = quad_state_list->front();
119 EXPECT_EQ(root_opacity, root_sqs->opacity);
120 // Child's SharedQuadState contains the effective opacity of the child layer,
121 // which should be a product of the child and the parent opacity.
122 EXPECT_EQ(child_opacity * root_opacity, child_sqs->opacity);
123
124 // Create the UNDERLAY Surface for the child window, and confirm that this
125 // creates an extra SharedQuadState in the CompositorFrame.
126 child_window.GetOrCreateSurfaceManager()->CreateSurface(
127 mojom::SurfaceType::UNDERLAY, mojo::InterfaceRequest<mojom::Surface>(),
128 mojom::SurfaceClientPtr());
129
130 cf = GenerateCompositorFrame();
131 quad_state_list = GetSharedQuadStateListFromCompositorFrame(cf.get());
132 EXPECT_EQ(3u, quad_state_list->size());
133 auto it = quad_state_list->begin();
134 EXPECT_EQ(child_opacity * root_opacity, (*it)->opacity);
135 EXPECT_EQ(child_opacity * root_opacity, (*++it)->opacity);
136 EXPECT_EQ(root_opacity, (*++it)->opacity);
137 }
138
139 } // namespace test
140 } // namespace ws
141 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698