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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/mus/ws/platform_display_unittest.cc
diff --git a/components/mus/ws/platform_display_unittest.cc b/components/mus/ws/platform_display_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ad0e660a51e97b3aecd63571d2eb7f015a647f8d
--- /dev/null
+++ b/components/mus/ws/platform_display_unittest.cc
@@ -0,0 +1,141 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <memory>
+
+#include "base/memory/ptr_util.h"
+#include "base/test/test_message_loop.h"
+#include "cc/quads/render_pass.h"
+#include "cc/quads/shared_quad_state.h"
+#include "components/mus/ws/platform_display.h"
+#include "components/mus/ws/server_window.h"
+#include "components/mus/ws/server_window_surface_manager.h"
+#include "components/mus/ws/test_server_window_delegate.h"
+#include "components/mus/ws/test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace mus {
+namespace ws {
+namespace test {
+namespace {
+
+// Makes the window visible and creates the default surface for it.
+void InitWindow(ServerWindow* window) {
+ window->SetVisible(true);
+ ServerWindowSurfaceManager* surface_manager =
+ window->GetOrCreateSurfaceManager();
+ surface_manager->CreateSurface(mojom::SurfaceType::DEFAULT,
+ mojo::InterfaceRequest<mojom::Surface>(),
+ mojom::SurfaceClientPtr());
+}
+
+// Gets the RenderPassList from the |delegated_frame_data| of the
+// CompositorFrame, confirms it has exactly one RenderPass, and returns its
+// SharedQuadStateList.
+cc::SharedQuadStateList* GetSharedQuadStateListFromCompositorFrame(
+ cc::CompositorFrame* cf) {
+ cc::DelegatedFrameData* frame_data = cf->delegated_frame_data.get();
+ 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.
+ EXPECT_EQ(1u, frame_data->render_pass_list.size());
+ cc::RenderPass* render_pass = frame_data->render_pass_list.back().get();
+ EXPECT_TRUE(render_pass);
+ cc::SharedQuadStateList* quad_state_list =
+ &render_pass->shared_quad_state_list;
+ EXPECT_TRUE(quad_state_list);
+ return quad_state_list;
+}
+
+} // namespace
+
+class PlatformDisplayTest : public testing::Test {
+ public:
+ PlatformDisplayTest() {}
+ ~PlatformDisplayTest() override {}
+
+ // Calls GenerateCompositorFrame() on the |platform_display_|.
+ std::unique_ptr<cc::CompositorFrame> GenerateCompositorFrame();
+
+ ServerWindow* root_window() {
+ return platform_display_delegate_->GetRootWindow();
+ }
+
+ TestServerWindowDelegate* test_window_delegate() { return &window_delegate_; }
+
+ private:
+ // testing::Test:
+ void SetUp() override;
+ void TearDown() override;
+
+ std::unique_ptr<DefaultPlatformDisplay> platform_display_;
+ std::unique_ptr<TestPlatformDisplayDelegate> platform_display_delegate_;
+ TestServerWindowDelegate window_delegate_;
+
+ // Needed so that Mojo classes can be initialized.
+ base::TestMessageLoop message_loop_;
+
+ DISALLOW_COPY_AND_ASSIGN(PlatformDisplayTest);
+};
+
+std::unique_ptr<cc::CompositorFrame>
+PlatformDisplayTest::GenerateCompositorFrame() {
+ return platform_display_->GenerateCompositorFrame();
+}
+
+void PlatformDisplayTest::SetUp() {
+ testing::Test::SetUp();
+ platform_display_delegate_.reset(new TestPlatformDisplayDelegate(
+ base::WrapUnique(new ServerWindow(&window_delegate_, WindowId()))));
+ platform_display_.reset(
+ new DefaultPlatformDisplay(PlatformDisplayInitParams()));
+ platform_display_->set_delegate_for_testing(platform_display_delegate_.get());
+ InitWindow(root_window());
+}
+
+void PlatformDisplayTest::TearDown() {
+ platform_display_.reset();
+ platform_display_delegate_.reset();
+}
+
+// Tests correctness of the SharedQuadStateList in the CompositorFrame generated
+// by DefaultPlatformDisplay::GenerateCompositorFrame() from the window tree.
+TEST_F(PlatformDisplayTest, GenerateCompositorFrame) {
+ ServerWindow child_window(test_window_delegate(), WindowId());
+ root_window()->Add(&child_window);
+ InitWindow(&child_window);
+ const float root_opacity = .5f;
+ const float child_opacity = .4f;
+ root_window()->SetOpacity(root_opacity);
+ child_window.SetOpacity(child_opacity);
+
+ std::unique_ptr<cc::CompositorFrame> cf = GenerateCompositorFrame();
+ cc::SharedQuadStateList* quad_state_list =
+ GetSharedQuadStateListFromCompositorFrame(cf.get());
+ // Both child and root have a DEFAULT Surface and no underlay Surfaces, so
+ // there should be two SharedQuadStates int he list.
+ 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
+ cc::SharedQuadState* root_sqs = quad_state_list->back();
+ cc::SharedQuadState* child_sqs = quad_state_list->front();
+ EXPECT_EQ(root_opacity, root_sqs->opacity);
+ // Child's SharedQuadState contains the effective opacity of the child layer,
+ // which should be a product of the child and the parent opacity.
+ EXPECT_EQ(child_opacity * root_opacity, child_sqs->opacity);
+
+ // Create the UNDERLAY Surface for the child window, and confirm that this
+ // creates an extra SharedQuadState in the CompositorFrame.
+ child_window.GetOrCreateSurfaceManager()->CreateSurface(
+ mojom::SurfaceType::UNDERLAY, mojo::InterfaceRequest<mojom::Surface>(),
+ mojom::SurfaceClientPtr());
+
+ cf = GenerateCompositorFrame();
+ quad_state_list = GetSharedQuadStateListFromCompositorFrame(cf.get());
+ EXPECT_EQ(3u, quad_state_list->size());
+ auto it = quad_state_list->begin();
+ EXPECT_EQ(child_opacity * root_opacity, (*it)->opacity);
+ EXPECT_EQ(child_opacity * root_opacity, (*++it)->opacity);
+ EXPECT_EQ(root_opacity, (*++it)->opacity);
+}
+
+} // namespace test
+} // namespace ws
+} // namespace mus

Powered by Google App Engine
This is Rietveld 408576698