| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/ozone/platform/dri/screen_manager.h" | 5 #include "ui/ozone/platform/dri/screen_manager.h" |
| 6 | 6 |
| 7 #include <xf86drmMode.h> | 7 #include <xf86drmMode.h> |
| 8 | 8 |
| 9 #include "ui/gfx/geometry/point.h" | 9 #include "ui/gfx/geometry/point.h" |
| 10 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
| 11 #include "ui/gfx/geometry/size.h" | 11 #include "ui/gfx/geometry/size.h" |
| 12 #include "ui/ozone/platform/dri/crtc_state.h" | 12 #include "ui/ozone/platform/dri/crtc_state.h" |
| 13 #include "ui/ozone/platform/dri/dri_util.h" | 13 #include "ui/ozone/platform/dri/dri_util.h" |
| 14 #include "ui/ozone/platform/dri/hardware_display_controller.h" | 14 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
| 15 #include "ui/ozone/platform/dri/scanout_buffer.h" | 15 #include "ui/ozone/platform/dri/scanout_buffer.h" |
| 16 | 16 |
| 17 namespace ui { | 17 namespace ui { |
| 18 | 18 |
| 19 namespace { | |
| 20 | |
| 21 gfx::Size GetModeSize(const drmModeModeInfo& mode) { | |
| 22 return gfx::Size(mode.hdisplay, mode.vdisplay); | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 ScreenManager::ScreenManager(DriWrapper* dri, | 19 ScreenManager::ScreenManager(DriWrapper* dri, |
| 28 ScanoutBufferGenerator* buffer_generator) | 20 ScanoutBufferGenerator* buffer_generator) |
| 29 : dri_(dri), buffer_generator_(buffer_generator) { | 21 : dri_(dri), buffer_generator_(buffer_generator) { |
| 30 } | 22 } |
| 31 | 23 |
| 32 ScreenManager::~ScreenManager() { | 24 ScreenManager::~ScreenManager() { |
| 33 } | 25 } |
| 34 | 26 |
| 35 void ScreenManager::RemoveDisplayController(uint32_t crtc) { | 27 void ScreenManager::RemoveDisplayController(uint32_t crtc) { |
| 36 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); | 28 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); |
| 37 if (it != controllers_.end()) { | 29 if (it != controllers_.end()) { |
| 38 bool is_mirrored = (*it)->IsMirrored(); | 30 bool is_mirrored = (*it)->IsMirrored(); |
| 39 (*it)->RemoveCrtc(crtc); | 31 (*it)->RemoveCrtc(crtc); |
| 40 if (!is_mirrored) | 32 if (!is_mirrored) |
| 41 controllers_.erase(it); | 33 controllers_.erase(it); |
| 42 } | 34 } |
| 43 } | 35 } |
| 44 | 36 |
| 45 bool ScreenManager::ConfigureDisplayController(uint32_t crtc, | 37 bool ScreenManager::ConfigureDisplayController(uint32_t crtc, |
| 46 uint32_t connector, | 38 uint32_t connector, |
| 47 const gfx::Point& origin, | 39 const gfx::Point& origin, |
| 48 const drmModeModeInfo& mode) { | 40 const drmModeModeInfo& mode) { |
| 49 gfx::Rect modeset_bounds(origin, GetModeSize(mode)); | 41 gfx::Rect modeset_bounds( |
| 42 origin.x(), origin.y(), mode.hdisplay, mode.vdisplay); |
| 50 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); | 43 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); |
| 51 HardwareDisplayController* controller = NULL; | 44 HardwareDisplayController* controller = NULL; |
| 52 if (it != controllers_.end()) { | 45 if (it != controllers_.end()) { |
| 53 controller = *it; | 46 controller = *it; |
| 54 // If nothing changed just enable the controller. Note, we perform an exact | 47 // If nothing changed just enable the controller. Note, we perform an exact |
| 55 // comparison on the mode since the refresh rate may have changed. | 48 // comparison on the mode since the refresh rate may have changed. |
| 56 if (SameMode(mode, controller->get_mode()) && | 49 if (SameMode(mode, controller->get_mode()) && |
| 57 origin == controller->origin() && !controller->IsDisabled()) | 50 origin == controller->origin() && !controller->IsDisabled()) |
| 58 return controller->Enable(); | 51 return controller->Enable(); |
| 59 | 52 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 129 } |
| 137 | 130 |
| 138 return controllers_.end(); | 131 return controllers_.end(); |
| 139 } | 132 } |
| 140 | 133 |
| 141 ScreenManager::HardwareDisplayControllers::iterator | 134 ScreenManager::HardwareDisplayControllers::iterator |
| 142 ScreenManager::FindActiveDisplayControllerByLocation(const gfx::Rect& bounds) { | 135 ScreenManager::FindActiveDisplayControllerByLocation(const gfx::Rect& bounds) { |
| 143 for (HardwareDisplayControllers::iterator it = controllers_.begin(); | 136 for (HardwareDisplayControllers::iterator it = controllers_.begin(); |
| 144 it != controllers_.end(); | 137 it != controllers_.end(); |
| 145 ++it) { | 138 ++it) { |
| 146 gfx::Rect controller_bounds((*it)->origin(), | 139 gfx::Rect controller_bounds((*it)->origin(), (*it)->GetModeSize()); |
| 147 GetModeSize((*it)->get_mode())); | |
| 148 // We don't perform a strict check since content_shell will have windows | 140 // We don't perform a strict check since content_shell will have windows |
| 149 // smaller than the display size. | 141 // smaller than the display size. |
| 150 if (controller_bounds.Contains(bounds) && !(*it)->IsDisabled()) | 142 if (controller_bounds.Contains(bounds) && !(*it)->IsDisabled()) |
| 151 return it; | 143 return it; |
| 152 } | 144 } |
| 153 | 145 |
| 154 return controllers_.end(); | 146 return controllers_.end(); |
| 155 } | 147 } |
| 156 | 148 |
| 157 void ScreenManager::ForceInitializationOfPrimaryDisplay() { | 149 void ScreenManager::ForceInitializationOfPrimaryDisplay() { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 203 |
| 212 // When things go wrong revert back to the previous configuration since | 204 // When things go wrong revert back to the previous configuration since |
| 213 // it is expected that the configuration would not have changed if | 205 // it is expected that the configuration would not have changed if |
| 214 // things fail. | 206 // things fail. |
| 215 (*original)->AddCrtc((*mirror)->RemoveCrtc(crtc)); | 207 (*original)->AddCrtc((*mirror)->RemoveCrtc(crtc)); |
| 216 (*original)->Enable(); | 208 (*original)->Enable(); |
| 217 return false; | 209 return false; |
| 218 } | 210 } |
| 219 | 211 |
| 220 } // namespace ui | 212 } // namespace ui |
| OLD | NEW |