| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/exo/test/exo_test_helper.h" | 5 #include "components/exo/test/exo_test_helper.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" |
| 8 #include "ash/common/wm/window_positioner.h" |
| 9 #include "ash/common/wm/window_positioning_utils.h" |
| 10 #include "ash/public/cpp/shell_window_ids.h" |
| 11 #include "components/exo/buffer.h" |
| 12 #include "components/exo/shell_surface.h" |
| 13 #include "components/exo/surface.h" |
| 7 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 14 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
| 8 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
| 9 #include "ui/compositor/compositor.h" | 16 #include "ui/compositor/compositor.h" |
| 17 #include "ui/views/widget/widget.h" |
| 10 | 18 |
| 11 namespace exo { | 19 namespace exo { |
| 12 namespace test { | 20 namespace test { |
| 13 | 21 |
| 14 //////////////////////////////////////////////////////////////////////////////// | 22 //////////////////////////////////////////////////////////////////////////////// |
| 15 // ExoTestHelper, public: | 23 // ExoTestHelper, public: |
| 16 | 24 |
| 17 ExoTestHelper::ExoTestHelper() {} | 25 ExoTestWindow::ExoTestWindow(std::unique_ptr<gfx::GpuMemoryBuffer> gpu_buffer, |
| 26 bool is_modal) { |
| 27 surface_.reset(new Surface()); |
| 28 int container = is_modal ? ash::kShellWindowId_SystemModalContainer |
| 29 : ash::kShellWindowId_DefaultContainer; |
| 30 shell_surface_.reset(new ShellSurface(surface_.get(), nullptr, |
| 31 gfx::Rect(gpu_buffer->GetSize()), true, |
| 32 false, container)); |
| 33 |
| 34 buffer_.reset(new Buffer(std::move(gpu_buffer))); |
| 35 surface_->Attach(buffer_.get()); |
| 36 surface_->Commit(); |
| 37 |
| 38 ash::wm::CenterWindow( |
| 39 ash::WmWindowAura::Get(shell_surface_->GetWidget()->GetNativeWindow())); |
| 40 } |
| 41 |
| 42 ExoTestWindow::ExoTestWindow(ExoTestWindow&& other) { |
| 43 surface_ = std::move(other.surface_); |
| 44 buffer_ = std::move(other.buffer_); |
| 45 shell_surface_ = std::move(other.shell_surface_); |
| 46 } |
| 47 |
| 48 ExoTestWindow::~ExoTestWindow() {} |
| 49 |
| 50 gfx::Point ExoTestWindow::origin() { |
| 51 return surface_->window()->GetBoundsInScreen().origin(); |
| 52 } |
| 53 |
| 54 //////////////////////////////////////////////////////////////////////////////// |
| 55 // ExoTestHelper, public: |
| 56 |
| 57 ExoTestHelper::ExoTestHelper() { |
| 58 ash::WindowPositioner::DisableAutoPositioning(true); |
| 59 } |
| 18 | 60 |
| 19 ExoTestHelper::~ExoTestHelper() {} | 61 ExoTestHelper::~ExoTestHelper() {} |
| 20 | 62 |
| 21 std::unique_ptr<gfx::GpuMemoryBuffer> ExoTestHelper::CreateGpuMemoryBuffer( | 63 std::unique_ptr<gfx::GpuMemoryBuffer> ExoTestHelper::CreateGpuMemoryBuffer( |
| 22 const gfx::Size& size) { | 64 const gfx::Size& size) { |
| 23 return aura::Env::GetInstance() | 65 return aura::Env::GetInstance() |
| 24 ->context_factory() | 66 ->context_factory() |
| 25 ->GetGpuMemoryBufferManager() | 67 ->GetGpuMemoryBufferManager() |
| 26 ->CreateGpuMemoryBuffer(size, gfx::BufferFormat::RGBA_8888, | 68 ->CreateGpuMemoryBuffer(size, gfx::BufferFormat::RGBA_8888, |
| 27 gfx::BufferUsage::GPU_READ, | 69 gfx::BufferUsage::GPU_READ, |
| 28 gpu::kNullSurfaceHandle); | 70 gpu::kNullSurfaceHandle); |
| 29 } | 71 } |
| 30 | 72 |
| 73 ExoTestWindow ExoTestHelper::CreateWindow(int width, |
| 74 int height, |
| 75 bool is_modal) { |
| 76 return ExoTestWindow(CreateGpuMemoryBuffer(gfx::Size(width, height)), |
| 77 is_modal); |
| 78 } |
| 79 |
| 31 } // namespace test | 80 } // namespace test |
| 32 } // namespace exo | 81 } // namespace exo |
| OLD | NEW |