OLD | NEW |
(Empty) | |
| 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 "base/bind.h" |
| 6 #include "base/location.h" |
| 7 #include "base/thread_task_runner_handle.h" |
| 8 #include "services/native_viewport/ozone/display_manager.h" |
| 9 #include "ui/display/types/display_snapshot.h" |
| 10 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h" |
| 11 #include "ui/ozone/platform/drm/host/drm_window_host.h" |
| 12 #include "ui/ozone/public/ozone_platform.h" |
| 13 |
| 14 namespace native_viewport { |
| 15 |
| 16 DisplayManager::DisplayManager() |
| 17 : delegate_(ui::OzonePlatform::GetInstance() |
| 18 ->CreateNativeDisplayDelegate()), |
| 19 is_configuring_(false), |
| 20 should_configure_(false), |
| 21 weak_factory_(this) { |
| 22 delegate_->AddObserver(this); |
| 23 delegate_->Initialize(); |
| 24 OnConfigurationChanged(); |
| 25 } |
| 26 |
| 27 DisplayManager::~DisplayManager() { |
| 28 if (delegate_) |
| 29 delegate_->RemoveObserver(this); |
| 30 } |
| 31 |
| 32 void DisplayManager::OnConfigurationChanged() { |
| 33 VLOG(1) << "DisplayManager::OnConfigurationChanged is_configuring_ " |
| 34 << is_configuring_; |
| 35 if (is_configuring_) { |
| 36 should_configure_ = true; |
| 37 return; |
| 38 } |
| 39 |
| 40 is_configuring_ = true; |
| 41 delegate_->GrabServer(); |
| 42 delegate_->GetDisplays(base::Bind(&DisplayManager::OnDisplaysAcquired, |
| 43 weak_factory_.GetWeakPtr())); |
| 44 } |
| 45 |
| 46 void DisplayManager::OnDisplaysAcquired( |
| 47 const std::vector<ui::DisplaySnapshot*>& displays) { |
| 48 gfx::Point origin; |
| 49 VLOG(1) << "OnDisplaysAcquired displays " << displays.size(); |
| 50 |
| 51 for (auto display : displays) { |
| 52 if (!display->native_mode()) { |
| 53 LOG(ERROR) << "Display " << display->display_id() |
| 54 << " doesn't have a native mode"; |
| 55 continue; |
| 56 } |
| 57 |
| 58 delegate_->Configure( |
| 59 *display, display->native_mode(), origin, |
| 60 base::Bind(&DisplayManager::OnDisplayConfigured, |
| 61 weak_factory_.GetWeakPtr(), |
| 62 gfx::Rect(origin, display->native_mode()->size()))); |
| 63 origin.Offset(display->native_mode()->size().width(), 0); |
| 64 } |
| 65 delegate_->UngrabServer(); |
| 66 is_configuring_ = false; |
| 67 |
| 68 VLOG(1) << "OnDisplaysAcquired should_configure_ " << should_configure_; |
| 69 if (should_configure_) { |
| 70 should_configure_ = false; |
| 71 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 72 FROM_HERE, base::Bind(&DisplayManager::OnConfigurationChanged, |
| 73 base::Unretained(this))); |
| 74 } |
| 75 } |
| 76 |
| 77 void DisplayManager::OnDisplayConfigured(const gfx::Rect& bounds, |
| 78 bool success) { |
| 79 auto platform_support_host = static_cast<ui::DrmGpuPlatformSupportHost*>( |
| 80 ui::OzonePlatform::GetInstance()->GetGpuPlatformSupportHost()); |
| 81 platform_support_host->get_window_manager()->GetPrimaryWindow()->SetBounds( |
| 82 bounds); |
| 83 } |
| 84 |
| 85 } // namespace native_viewport |
OLD | NEW |