1 // Copyright 2015 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 "components/exo/test/exo_test_base.h"
6 
7 #include "ash/shell.h"
8 #include "components/exo/buffer.h"
9 #include "components/exo/shell_surface.h"
10 #include "components/exo/surface.h"
11 #include "components/exo/wm_helper.h"
12 #include "components/exo/wm_helper_chromeos.h"
13 #include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
14 #include "components/viz/service/surfaces/surface_manager.h"
15 #include "ui/aura/env.h"
16 #include "ui/base/ime/init/input_method_factory.h"
17 #include "ui/compositor/test/in_process_context_factory.h"
18 #include "ui/wm/core/wm_core_switches.h"
19 
20 namespace exo {
21 namespace test {
22 
23 ////////////////////////////////////////////////////////////////////////////////
24 // ExoTestBase, public:
25 
ShellSurfaceHolder(std::unique_ptr<Buffer> buffer,std::unique_ptr<Surface> surface,std::unique_ptr<ShellSurface> shell_surface)26 ExoTestBase::ShellSurfaceHolder::ShellSurfaceHolder(
27     std::unique_ptr<Buffer> buffer,
28     std::unique_ptr<Surface> surface,
29     std::unique_ptr<ShellSurface> shell_surface)
30     : buffer_(std::move(buffer)),
31       surface_(std::move(surface)),
32       shell_surface_(std::move(shell_surface)) {}
33 
34 ExoTestBase::ShellSurfaceHolder::~ShellSurfaceHolder() = default;
35 
36 ExoTestBase::ExoTestBase() = default;
37 
38 ExoTestBase::~ExoTestBase() = default;
39 
SetUp()40 void ExoTestBase::SetUp() {
41   AshTestBase::SetUp();
42   wm_helper_ = std::make_unique<WMHelperChromeOS>();
43 }
44 
TearDown()45 void ExoTestBase::TearDown() {
46   wm_helper_.reset();
47   AshTestBase::TearDown();
48 }
49 
GetSurfaceManager()50 viz::SurfaceManager* ExoTestBase::GetSurfaceManager() {
51   return static_cast<ui::InProcessContextFactory*>(
52              aura::Env::GetInstance()->context_factory())
53       ->GetFrameSinkManager()
54       ->surface_manager();
55 }
56 
57 std::unique_ptr<ExoTestBase::ShellSurfaceHolder>
CreateShellSurfaceHolder(const gfx::Size & buffer_size,ShellSurface * parent)58 ExoTestBase::CreateShellSurfaceHolder(const gfx::Size& buffer_size,
59                                       ShellSurface* parent) {
60   auto buffer = std::make_unique<Buffer>(
61       exo_test_helper()->CreateGpuMemoryBuffer(buffer_size));
62   auto surface = std::make_unique<Surface>();
63   auto shell_surface = std::make_unique<ShellSurface>(surface.get());
64   if (parent)
65     shell_surface->SetParent(parent);
66   surface->Attach(buffer.get());
67   surface->Commit();
68   return std::make_unique<ShellSurfaceHolder>(
69       std::move(buffer), std::move(surface), std::move(shell_surface));
70 }
71 
72 }  // namespace test
73 }  // namespace exo
74