| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/mus/ws/platform_screen_impl_ozone.h" | 5 #include "components/mus/ws/platform_screen_impl_ozone.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // Some ozone platforms do not configure physical displays and so do not | 23 // Some ozone platforms do not configure physical displays and so do not |
| 24 // callback into this class via the implementation of NativeDisplayObserver. | 24 // callback into this class via the implementation of NativeDisplayObserver. |
| 25 // FixedSizeScreenConfiguration() short-circuits the implementation of display | 25 // FixedSizeScreenConfiguration() short-circuits the implementation of display |
| 26 // configuration in this case by calling the |callback| provided to | 26 // configuration in this case by calling the |callback| provided to |
| 27 // ConfigurePhysicalDisplay() with a hard-coded |id| and |bounds|. | 27 // ConfigurePhysicalDisplay() with a hard-coded |id| and |bounds|. |
| 28 void FixedSizeScreenConfiguration( | 28 void FixedSizeScreenConfiguration( |
| 29 const PlatformScreen::ConfiguredDisplayCallback& callback) { | 29 const PlatformScreen::ConfiguredDisplayCallback& callback) { |
| 30 callback.Run(1, gfx::Rect(1024, 768)); | 30 callback.Run(1, gfx::Rect(1024, 768)); |
| 31 } | 31 } |
| 32 | 32 |
| 33 // The display subsystem calls |OnDisplayConfigured| for each display that has | 33 void GetDisplaysFinished(const std::vector<ui::DisplaySnapshot*>& displays) { |
| 34 // been successfully configured. This in turn calls |callback_| with the | 34 // We don't really care about list of displays, we just want the snapshots |
| 35 // identity and bounds of each physical display. | 35 // held by DrmDisplayManager to be updated. This only only happens when we |
| 36 void OnDisplayConfigured( | 36 // call NativeDisplayDelegate::GetDisplays(). Although, this would be a good |
| 37 const PlatformScreen::ConfiguredDisplayCallback& callback, | 37 // place to have PlatformScreen cache the snapshots if need be. |
| 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 } | 38 } |
| 46 | 39 |
| 47 } // namespace | 40 } // namespace |
| 48 | 41 |
| 49 // static | 42 // static |
| 50 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { | 43 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { |
| 51 return base::WrapUnique(new PlatformScreenImplOzone); | 44 return base::WrapUnique(new PlatformScreenImplOzone); |
| 52 } | 45 } |
| 53 | 46 |
| 54 PlatformScreenImplOzone::PlatformScreenImplOzone() : weak_ptr_factory_(this) {} | 47 PlatformScreenImplOzone::PlatformScreenImplOzone() : weak_ptr_factory_(this) {} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 70 // |PlatformScreenImplOzone| | 63 // |PlatformScreenImplOzone| |
| 71 | 64 |
| 72 DCHECK(native_display_delegate_) << "DefaultDisplayManager::" | 65 DCHECK(native_display_delegate_) << "DefaultDisplayManager::" |
| 73 "OnConfigurationChanged requires a " | 66 "OnConfigurationChanged requires a " |
| 74 "native_display_delegate_ to work."; | 67 "native_display_delegate_ to work."; |
| 75 | 68 |
| 76 native_display_delegate_->GetDisplays( | 69 native_display_delegate_->GetDisplays( |
| 77 base::Bind(&PlatformScreenImplOzone::OnDisplaysAquired, | 70 base::Bind(&PlatformScreenImplOzone::OnDisplaysAquired, |
| 78 weak_ptr_factory_.GetWeakPtr(), callback)); | 71 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 79 | 72 |
| 80 } else | 73 return; |
| 81 #endif // defined(OS_CHROMEOS) | 74 } |
| 82 // PostTask()ed to maximize control flow similarity with the ChromeOS case. | 75 #endif // defined(OS_CHROMEOS) |
| 83 base::ThreadTaskRunnerHandle::Get()->PostTask( | 76 // PostTask()ed to maximize control flow similarity with the ChromeOS case. |
| 84 FROM_HERE, base::Bind(&FixedSizeScreenConfiguration, callback)); | 77 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 78 FROM_HERE, base::Bind(&FixedSizeScreenConfiguration, callback)); |
| 85 } | 79 } |
| 86 | 80 |
| 87 void PlatformScreenImplOzone::OnConfigurationChanged() {} | 81 void PlatformScreenImplOzone::OnConfigurationChanged() {} |
| 88 | 82 |
| 89 // The display subsystem calls |OnDisplaysAquired| to deliver |displays| | 83 // The display subsystem calls |OnDisplaysAquired| to deliver |displays| |
| 90 // describing the attached displays. | 84 // describing the attached displays. |
| 91 void PlatformScreenImplOzone::OnDisplaysAquired( | 85 void PlatformScreenImplOzone::OnDisplaysAquired( |
| 92 const ConfiguredDisplayCallback& callback, | 86 const ConfiguredDisplayCallback& callback, |
| 93 const std::vector<ui::DisplaySnapshot*>& displays) { | 87 const std::vector<ui::DisplaySnapshot*>& displays) { |
| 94 DCHECK(native_display_delegate_) << "DefaultDisplayManager::" | 88 DCHECK(native_display_delegate_) << "DefaultDisplayManager::" |
| 95 "OnConfigurationChanged requires a " | 89 "OnConfigurationChanged requires a " |
| 96 "native_display_delegate_ to work."; | 90 "native_display_delegate_ to work."; |
| 97 CHECK(displays.size() == 1) << "Mus only supports one 1 display\n"; | 91 CHECK(displays.size() == 1) << "Mus only supports one 1 display\n"; |
| 98 gfx::Point origin; | 92 gfx::Point origin; |
| 99 for (auto display : displays) { | 93 for (auto display : displays) { |
| 100 if (!display->native_mode()) { | 94 if (!display->native_mode()) { |
| 101 LOG(ERROR) << "Display " << display->display_id() | 95 LOG(ERROR) << "Display " << display->display_id() |
| 102 << " doesn't have a native mode"; | 96 << " doesn't have a native mode"; |
| 103 continue; | 97 continue; |
| 104 } | 98 } |
| 105 // Setup each native display. This places a task on the DRM thread's | 99 // 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 | 100 // runqueue that configures the window size correctly before the call to |
| 107 // Configure. | 101 // Configure. |
| 108 native_display_delegate_->Configure( | 102 native_display_delegate_->Configure( |
| 109 *display, display->native_mode(), origin, | 103 *display, display->native_mode(), origin, |
| 110 base::Bind(&OnDisplayConfigured, callback, display->display_id(), | 104 base::Bind(&PlatformScreenImplOzone::OnDisplayConfigured, |
| 105 weak_ptr_factory_.GetWeakPtr(), callback, |
| 106 display->display_id(), |
| 111 gfx::Rect(origin, display->native_mode()->size()))); | 107 gfx::Rect(origin, display->native_mode()->size()))); |
| 112 origin.Offset(display->native_mode()->size().width(), 0); | 108 origin.Offset(display->native_mode()->size().width(), 0); |
| 113 } | 109 } |
| 114 } | 110 } |
| 115 | 111 |
| 112 void PlatformScreenImplOzone::OnDisplayConfigured( |
| 113 const ConfiguredDisplayCallback& callback, |
| 114 int64_t id, |
| 115 const gfx::Rect& bounds, |
| 116 bool success) { |
| 117 if (success) { |
| 118 native_display_delegate_->GetDisplays(base::Bind(&GetDisplaysFinished)); |
| 119 callback.Run(id, bounds); |
| 120 } else { |
| 121 LOG(FATAL) << "Failed to configure display at " << bounds.ToString(); |
| 122 } |
| 123 } |
| 124 |
| 116 } // namespace ws | 125 } // namespace ws |
| 117 } // namespace mus | 126 } // namespace mus |
| OLD | NEW |