blob: bb5b511655cb667c80eba49d7be71f0c472d43ca [file] [log] [blame]
revemanb195f41d2015-11-19 22:16:481// 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_helper.h"
6
denniskempin31a496e2016-12-17 00:20:577#include "ash/public/cpp/shell_window_ids.h"
James Cookb0bf8e82017-04-09 17:01:448#include "ash/wm/window_positioner.h"
9#include "ash/wm/window_positioning_utils.h"
denniskempin31a496e2016-12-17 00:20:5710#include "components/exo/buffer.h"
11#include "components/exo/shell_surface.h"
12#include "components/exo/surface.h"
revemanb195f41d2015-11-19 22:16:4813#include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
14#include "ui/aura/env.h"
15#include "ui/compositor/compositor.h"
denniskempin31a496e2016-12-17 00:20:5716#include "ui/views/widget/widget.h"
revemanb195f41d2015-11-19 22:16:4817
18namespace exo {
19namespace test {
20
21////////////////////////////////////////////////////////////////////////////////
22// ExoTestHelper, public:
23
denniskempin31a496e2016-12-17 00:20:5724ExoTestWindow::ExoTestWindow(std::unique_ptr<gfx::GpuMemoryBuffer> gpu_buffer,
25 bool is_modal) {
26 surface_.reset(new Surface());
27 int container = is_modal ? ash::kShellWindowId_SystemModalContainer
28 : ash::kShellWindowId_DefaultContainer;
29 shell_surface_.reset(new ShellSurface(surface_.get(), nullptr,
domlaskowski886e1c82017-02-15 01:08:0430 ShellSurface::BoundsMode::SHELL,
31 gfx::Point(), true, false, container));
denniskempin31a496e2016-12-17 00:20:5732
33 buffer_.reset(new Buffer(std::move(gpu_buffer)));
34 surface_->Attach(buffer_.get());
35 surface_->Commit();
36
varkha5b729812017-05-25 18:51:4737 ash::wm::CenterWindow(shell_surface_->GetWidget()->GetNativeWindow());
denniskempin31a496e2016-12-17 00:20:5738}
39
40ExoTestWindow::ExoTestWindow(ExoTestWindow&& other) {
41 surface_ = std::move(other.surface_);
42 buffer_ = std::move(other.buffer_);
43 shell_surface_ = std::move(other.shell_surface_);
44}
45
46ExoTestWindow::~ExoTestWindow() {}
47
48gfx::Point ExoTestWindow::origin() {
49 return surface_->window()->GetBoundsInScreen().origin();
50}
51
52////////////////////////////////////////////////////////////////////////////////
53// ExoTestHelper, public:
54
55ExoTestHelper::ExoTestHelper() {
56 ash::WindowPositioner::DisableAutoPositioning(true);
57}
revemanb195f41d2015-11-19 22:16:4858
59ExoTestHelper::~ExoTestHelper() {}
60
dcheng31759da2016-04-21 01:26:3161std::unique_ptr<gfx::GpuMemoryBuffer> ExoTestHelper::CreateGpuMemoryBuffer(
revemanca132dc2017-01-31 22:35:5462 const gfx::Size& size,
63 gfx::BufferFormat format) {
revemanb195f41d2015-11-19 22:16:4864 return aura::Env::GetInstance()
65 ->context_factory()
66 ->GetGpuMemoryBufferManager()
revemanca132dc2017-01-31 22:35:5467 ->CreateGpuMemoryBuffer(size, format, gfx::BufferUsage::GPU_READ,
sadrul86a858ab2016-11-23 20:49:0668 gpu::kNullSurfaceHandle);
revemanb195f41d2015-11-19 22:16:4869}
70
denniskempin31a496e2016-12-17 00:20:5771ExoTestWindow ExoTestHelper::CreateWindow(int width,
72 int height,
73 bool is_modal) {
74 return ExoTestWindow(CreateGpuMemoryBuffer(gfx::Size(width, height)),
75 is_modal);
76}
77
revemanb195f41d2015-11-19 22:16:4878} // namespace test
79} // namespace exo