| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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/mus/ws/platform_screen_impl_ozone.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/sys_info.h" |
| 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "ui/display/types/display_snapshot.h" |
| 13 #include "ui/display/types/native_display_delegate.h" |
| 14 #include "ui/ozone/public/ozone_platform.h" |
| 15 |
| 16 namespace mus { |
| 17 |
| 18 namespace ws { |
| 19 namespace { |
| 20 |
| 21 // TODO(rjkroege): Remove this code once ozone oxygen has the same |
| 22 // display creation semantics as ozone drm. |
| 23 // Some ozone platforms do not configure physical displays and so do not |
| 24 // callback into this class via the implementation of NativeDisplayObserver. |
| 25 // FixedSizeScreenConfiguration() short-circuits the implementation of display |
| 26 // configuration in this case by calling the |callback| provided to |
| 27 // ConfigurePhysicalDisplay() with a hard-coded |id| and |bounds|. |
| 28 void FixedSizeScreenConfiguration( |
| 29 const PlatformScreen::ConfiguredDisplayCallback& callback) { |
| 30 callback.Run(1, gfx::Rect(1024, 768)); |
| 31 } |
| 32 |
| 33 // The display subsystem calls |OnDisplayConfigured| for each display that has |
| 34 // been successfully configured. This in turn calls |callback_| with the |
| 35 // identity and bounds of each physical display. |
| 36 void OnDisplayConfigured( |
| 37 const PlatformScreen::ConfiguredDisplayCallback& callback, |
| 38 int64_t id, |
| 39 const gfx::Rect& bounds, |
| 40 bool success) { |
| 41 if (success) |
| 42 callback.Run(id, bounds); |
| 43 else |
| 44 LOG(FATAL) << "Failed to configure display at " << bounds.ToString(); |
| 45 } |
| 46 |
| 47 } // namespace |
| 48 |
| 49 // static |
| 50 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { |
| 51 return base::WrapUnique(new PlatformScreenImplOzone); |
| 52 } |
| 53 |
| 54 PlatformScreenImplOzone::PlatformScreenImplOzone() : weak_ptr_factory_(this) {} |
| 55 |
| 56 PlatformScreenImplOzone::~PlatformScreenImplOzone() {} |
| 57 |
| 58 void PlatformScreenImplOzone::Init() { |
| 59 native_display_delegate_ = |
| 60 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); |
| 61 native_display_delegate_->AddObserver(this); |
| 62 native_display_delegate_->Initialize(); |
| 63 } |
| 64 |
| 65 void PlatformScreenImplOzone::ConfigurePhysicalDisplay( |
| 66 const PlatformScreen::ConfiguredDisplayCallback& callback) { |
| 67 #if defined(OS_CHROMEOS) |
| 68 if (base::SysInfo::IsRunningOnChromeOS()) { |
| 69 // Kick off the configuration of the physical displays comprising the |
| 70 // |PlatformScreenImplOzone| |
| 71 |
| 72 DCHECK(native_display_delegate_) << "DefaultDisplayManager::" |
| 73 "OnConfigurationChanged requires a " |
| 74 "native_display_delegate_ to work."; |
| 75 |
| 76 native_display_delegate_->GetDisplays( |
| 77 base::Bind(&PlatformScreenImplOzone::OnDisplaysAquired, |
| 78 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 79 |
| 80 } else |
| 81 #endif // defined(OS_CHROMEOS) |
| 82 // PostTask()ed to maximize control flow similarity with the ChromeOS case. |
| 83 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 84 FROM_HERE, base::Bind(&FixedSizeScreenConfiguration, callback)); |
| 85 } |
| 86 |
| 87 void PlatformScreenImplOzone::OnConfigurationChanged() {} |
| 88 |
| 89 // The display subsystem calls |OnDisplaysAquired| to deliver |displays| |
| 90 // describing the attached displays. |
| 91 void PlatformScreenImplOzone::OnDisplaysAquired( |
| 92 const ConfiguredDisplayCallback& callback, |
| 93 const std::vector<ui::DisplaySnapshot*>& displays) { |
| 94 DCHECK(native_display_delegate_) << "DefaultDisplayManager::" |
| 95 "OnConfigurationChanged requires a " |
| 96 "native_display_delegate_ to work."; |
| 97 CHECK(displays.size() == 1) << "Mus only supports one 1 display\n"; |
| 98 gfx::Point origin; |
| 99 for (auto display : displays) { |
| 100 if (!display->native_mode()) { |
| 101 LOG(ERROR) << "Display " << display->display_id() |
| 102 << " doesn't have a native mode"; |
| 103 continue; |
| 104 } |
| 105 // Setup each native display. This places a task on the DRM thread's |
| 106 // runqueue that configures the window size correctly before the call to |
| 107 // Configure. |
| 108 native_display_delegate_->Configure( |
| 109 *display, display->native_mode(), origin, |
| 110 base::Bind(&OnDisplayConfigured, callback, display->display_id(), |
| 111 gfx::Rect(origin, display->native_mode()->size()))); |
| 112 origin.Offset(display->native_mode()->size().width(), 0); |
| 113 } |
| 114 } |
| 115 |
| 116 } // namespace ws |
| 117 } // namespace mus |
| OLD | NEW |