| 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/hardware_display_controller.h" | 5 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
| 6 | 6 |
| 7 #include <drm.h> | 7 #include <drm.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <xf86drm.h> | 10 #include <xf86drm.h> |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 crop_rect(crop_rect), | 75 crop_rect(crop_rect), |
| 76 overlay_plane(0) { | 76 overlay_plane(0) { |
| 77 } | 77 } |
| 78 | 78 |
| 79 OverlayPlane::~OverlayPlane() {} | 79 OverlayPlane::~OverlayPlane() {} |
| 80 | 80 |
| 81 HardwareDisplayController::HardwareDisplayController( | 81 HardwareDisplayController::HardwareDisplayController( |
| 82 DriWrapper* drm, | 82 DriWrapper* drm, |
| 83 scoped_ptr<CrtcState> state) | 83 scoped_ptr<CrtcState> state) |
| 84 : drm_(drm), | 84 : drm_(drm), |
| 85 is_disabled_(true), |
| 85 time_of_last_flip_(0), | 86 time_of_last_flip_(0), |
| 86 pending_page_flips_(0) { | 87 pending_page_flips_(0) { |
| 87 crtc_states_.push_back(state.release()); | 88 crtc_states_.push_back(state.release()); |
| 88 } | 89 } |
| 89 | 90 |
| 90 HardwareDisplayController::~HardwareDisplayController() { | 91 HardwareDisplayController::~HardwareDisplayController() { |
| 91 // Reset the cursor. | 92 // Reset the cursor. |
| 92 UnsetCursor(); | 93 UnsetCursor(); |
| 93 } | 94 } |
| 94 | 95 |
| 95 bool HardwareDisplayController::Modeset(const OverlayPlane& primary, | 96 bool HardwareDisplayController::Modeset(const OverlayPlane& primary, |
| 96 drmModeModeInfo mode) { | 97 drmModeModeInfo mode) { |
| 97 TRACE_EVENT0("dri", "HDC::Modeset"); | 98 TRACE_EVENT0("dri", "HDC::Modeset"); |
| 98 DCHECK(primary.buffer); | 99 DCHECK(primary.buffer); |
| 99 pending_page_flips_ = 0; | 100 pending_page_flips_ = 0; |
| 100 bool status = true; | 101 bool status = true; |
| 101 for (size_t i = 0; i < crtc_states_.size(); ++i) | 102 for (size_t i = 0; i < crtc_states_.size(); ++i) { |
| 102 status &= ModesetCrtc(primary.buffer, mode, crtc_states_[i]); | 103 status &= ModesetCrtc(primary.buffer, mode, crtc_states_[i]); |
| 104 crtc_states_[i]->set_is_disabled(false); |
| 105 } |
| 103 | 106 |
| 104 // Since a subset of controllers may be actively using |primary|, just keep | 107 // Since a subset of controllers may be actively using |primary|, just keep |
| 105 // track of it. | 108 // track of it. |
| 106 current_planes_ = std::vector<OverlayPlane>(1, primary); | 109 current_planes_ = std::vector<OverlayPlane>(1, primary); |
| 107 pending_planes_.clear(); | 110 pending_planes_.clear(); |
| 111 is_disabled_ = false; |
| 108 mode_ = mode; | 112 mode_ = mode; |
| 109 return status; | 113 return status; |
| 110 } | 114 } |
| 111 | 115 |
| 112 bool HardwareDisplayController::Enable() { | 116 bool HardwareDisplayController::Enable() { |
| 113 TRACE_EVENT0("dri", "HDC::Enable"); | 117 TRACE_EVENT0("dri", "HDC::Enable"); |
| 114 DCHECK(!current_planes_.empty()); | 118 DCHECK(!current_planes_.empty()); |
| 115 OverlayPlane primary = GetPrimaryPlane(current_planes_); | 119 OverlayPlane primary = GetPrimaryPlane(current_planes_); |
| 116 DCHECK(primary.buffer); | 120 DCHECK(primary.buffer); |
| 117 pending_page_flips_ = 0; | 121 pending_page_flips_ = 0; |
| 118 bool status = true; | 122 bool status = true; |
| 119 for (size_t i = 0; i < crtc_states_.size(); ++i) | 123 for (size_t i = 0; i < crtc_states_.size(); ++i) |
| 120 status &= ModesetCrtc(primary.buffer, mode_, crtc_states_[i]); | 124 status &= ModesetCrtc(primary.buffer, mode_, crtc_states_[i]); |
| 121 | 125 |
| 122 return status; | 126 return status; |
| 123 } | 127 } |
| 124 | 128 |
| 125 void HardwareDisplayController::Disable() { | 129 void HardwareDisplayController::Disable() { |
| 126 TRACE_EVENT0("dri", "HDC::Disable"); | 130 TRACE_EVENT0("dri", "HDC::Disable"); |
| 127 pending_page_flips_ = 0; | 131 pending_page_flips_ = 0; |
| 128 for (size_t i = 0; i < crtc_states_.size(); ++i) { | 132 for (size_t i = 0; i < crtc_states_.size(); ++i) { |
| 129 drm_->DisableCrtc(crtc_states_[i]->crtc()); | 133 drm_->DisableCrtc(crtc_states_[i]->crtc()); |
| 130 crtc_states_[i]->set_is_disabled(true); | 134 crtc_states_[i]->set_is_disabled(true); |
| 131 } | 135 } |
| 136 |
| 137 is_disabled_ = true; |
| 132 } | 138 } |
| 133 | 139 |
| 134 void HardwareDisplayController::QueueOverlayPlane(const OverlayPlane& plane) { | 140 void HardwareDisplayController::QueueOverlayPlane(const OverlayPlane& plane) { |
| 135 pending_planes_.push_back(plane); | 141 pending_planes_.push_back(plane); |
| 136 } | 142 } |
| 137 | 143 |
| 138 bool HardwareDisplayController::SchedulePageFlip() { | 144 bool HardwareDisplayController::SchedulePageFlip() { |
| 139 DCHECK(!pending_planes_.empty()); | 145 DCHECK(!pending_planes_.empty()); |
| 140 DCHECK_EQ(0u, pending_page_flips_); | 146 DCHECK_EQ(0u, pending_page_flips_); |
| 141 | 147 |
| 148 if (is_disabled_) |
| 149 return true; |
| 150 |
| 142 bool status = true; | 151 bool status = true; |
| 143 for (size_t i = 0; i < crtc_states_.size(); ++i) { | 152 for (size_t i = 0; i < crtc_states_.size(); ++i) |
| 144 if (crtc_states_[i]->is_disabled()) | |
| 145 continue; | |
| 146 | |
| 147 status &= SchedulePageFlipOnCrtc(pending_planes_, crtc_states_[i]); | 153 status &= SchedulePageFlipOnCrtc(pending_planes_, crtc_states_[i]); |
| 148 } | |
| 149 | 154 |
| 150 return status; | 155 return status; |
| 151 } | 156 } |
| 152 | 157 |
| 153 void HardwareDisplayController::WaitForPageFlipEvent() { | 158 void HardwareDisplayController::WaitForPageFlipEvent() { |
| 154 TRACE_EVENT1("dri", "HDC::WaitForPageFlipEvent", | 159 TRACE_EVENT1("dri", "HDC::WaitForPageFlipEvent", |
| 155 "pending_pageflips", pending_page_flips_); | 160 "pending_pageflips", pending_page_flips_); |
| 156 | 161 |
| 157 bool has_pending_page_flips = pending_page_flips_ != 0; | 162 bool has_pending_page_flips = pending_page_flips_ != 0; |
| 158 drmEventContext drm_event; | 163 drmEventContext drm_event; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 179 | 184 |
| 180 --pending_page_flips_; | 185 --pending_page_flips_; |
| 181 time_of_last_flip_ = | 186 time_of_last_flip_ = |
| 182 static_cast<uint64_t>(seconds) * base::Time::kMicrosecondsPerSecond + | 187 static_cast<uint64_t>(seconds) * base::Time::kMicrosecondsPerSecond + |
| 183 useconds; | 188 useconds; |
| 184 } | 189 } |
| 185 | 190 |
| 186 bool HardwareDisplayController::SetCursor(scoped_refptr<ScanoutBuffer> buffer) { | 191 bool HardwareDisplayController::SetCursor(scoped_refptr<ScanoutBuffer> buffer) { |
| 187 bool status = true; | 192 bool status = true; |
| 188 cursor_buffer_ = buffer; | 193 cursor_buffer_ = buffer; |
| 194 |
| 195 if (is_disabled_) |
| 196 return true; |
| 197 |
| 189 for (size_t i = 0; i < crtc_states_.size(); ++i) { | 198 for (size_t i = 0; i < crtc_states_.size(); ++i) { |
| 190 if (!crtc_states_[i]->is_disabled()) | 199 status &= drm_->SetCursor( |
| 191 status &= drm_->SetCursor(crtc_states_[i]->crtc(), | 200 crtc_states_[i]->crtc(), buffer->GetHandle(), buffer->GetSize()); |
| 192 buffer->GetHandle(), | |
| 193 buffer->GetSize()); | |
| 194 } | 201 } |
| 195 | 202 |
| 196 return status; | 203 return status; |
| 197 } | 204 } |
| 198 | 205 |
| 199 bool HardwareDisplayController::UnsetCursor() { | 206 bool HardwareDisplayController::UnsetCursor() { |
| 200 bool status = true; | 207 bool status = true; |
| 201 cursor_buffer_ = NULL; | 208 cursor_buffer_ = NULL; |
| 202 for (size_t i = 0; i < crtc_states_.size(); ++i) | 209 for (size_t i = 0; i < crtc_states_.size(); ++i) |
| 203 status &= drm_->SetCursor(crtc_states_[i]->crtc(), 0, gfx::Size()); | 210 status &= drm_->SetCursor(crtc_states_[i]->crtc(), 0, gfx::Size()); |
| 204 | 211 |
| 205 return status; | 212 return status; |
| 206 } | 213 } |
| 207 | 214 |
| 208 bool HardwareDisplayController::MoveCursor(const gfx::Point& location) { | 215 bool HardwareDisplayController::MoveCursor(const gfx::Point& location) { |
| 216 if (is_disabled_) |
| 217 return true; |
| 218 |
| 209 bool status = true; | 219 bool status = true; |
| 210 for (size_t i = 0; i < crtc_states_.size(); ++i) | 220 for (size_t i = 0; i < crtc_states_.size(); ++i) |
| 211 if (!crtc_states_[i]->is_disabled()) | 221 status &= drm_->MoveCursor(crtc_states_[i]->crtc(), location); |
| 212 status &= drm_->MoveCursor(crtc_states_[i]->crtc(), location); | |
| 213 | 222 |
| 214 return status; | 223 return status; |
| 215 } | 224 } |
| 216 | 225 |
| 217 void HardwareDisplayController::AddCrtc( | 226 void HardwareDisplayController::AddCrtc( |
| 218 scoped_ptr<CrtcState> state) { | 227 scoped_ptr<CrtcState> state) { |
| 219 crtc_states_.push_back(state.release()); | 228 crtc_states_.push_back(state.release()); |
| 220 } | 229 } |
| 221 | 230 |
| 222 scoped_ptr<CrtcState> HardwareDisplayController::RemoveCrtc(uint32_t crtc) { | 231 scoped_ptr<CrtcState> HardwareDisplayController::RemoveCrtc(uint32_t crtc) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 234 } | 243 } |
| 235 | 244 |
| 236 bool HardwareDisplayController::HasCrtc(uint32_t crtc) const { | 245 bool HardwareDisplayController::HasCrtc(uint32_t crtc) const { |
| 237 for (size_t i = 0; i < crtc_states_.size(); ++i) | 246 for (size_t i = 0; i < crtc_states_.size(); ++i) |
| 238 if (crtc_states_[i]->crtc() == crtc) | 247 if (crtc_states_[i]->crtc() == crtc) |
| 239 return true; | 248 return true; |
| 240 | 249 |
| 241 return false; | 250 return false; |
| 242 } | 251 } |
| 243 | 252 |
| 244 bool HardwareDisplayController::HasCrtcs() const { | 253 bool HardwareDisplayController::IsMirrored() const { |
| 245 return !crtc_states_.empty(); | 254 return crtc_states_.size() > 1; |
| 246 } | 255 } |
| 247 | 256 |
| 248 void HardwareDisplayController::RemoveMirroredCrtcs() { | 257 bool HardwareDisplayController::IsDisabled() const { |
| 249 if (crtc_states_.size() > 1) | 258 return is_disabled_; |
| 250 crtc_states_.erase(crtc_states_.begin() + 1, crtc_states_.end()); | |
| 251 } | 259 } |
| 252 | 260 |
| 253 bool HardwareDisplayController::ModesetCrtc( | 261 bool HardwareDisplayController::ModesetCrtc( |
| 254 const scoped_refptr<ScanoutBuffer>& buffer, | 262 const scoped_refptr<ScanoutBuffer>& buffer, |
| 255 drmModeModeInfo mode, | 263 drmModeModeInfo mode, |
| 256 CrtcState* state) { | 264 CrtcState* state) { |
| 257 if (!drm_->SetCrtc(state->crtc(), | 265 if (!drm_->SetCrtc(state->crtc(), |
| 258 buffer->GetFramebufferId(), | 266 buffer->GetFramebufferId(), |
| 259 std::vector<uint32_t>(1, state->connector()), | 267 std::vector<uint32_t>(1, state->connector()), |
| 260 &mode)) { | 268 &mode)) { |
| 261 LOG(ERROR) << "Failed to modeset: error='" << strerror(errno) | 269 LOG(ERROR) << "Failed to modeset: error='" << strerror(errno) |
| 262 << "' crtc=" << state->crtc() | 270 << "' crtc=" << state->crtc() |
| 263 << " connector=" << state->connector() | 271 << " connector=" << state->connector() |
| 264 << " framebuffer_id=" << buffer->GetFramebufferId() | 272 << " framebuffer_id=" << buffer->GetFramebufferId() |
| 265 << " mode=" << mode.hdisplay << "x" << mode.vdisplay << "@" | 273 << " mode=" << mode.hdisplay << "x" << mode.vdisplay << "@" |
| 266 << mode.vrefresh; | 274 << mode.vrefresh; |
| 267 return false; | 275 return false; |
| 268 } | 276 } |
| 269 | 277 |
| 270 state->set_is_disabled(false); | |
| 271 return true; | 278 return true; |
| 272 } | 279 } |
| 273 | 280 |
| 274 bool HardwareDisplayController::SchedulePageFlipOnCrtc( | 281 bool HardwareDisplayController::SchedulePageFlipOnCrtc( |
| 275 const OverlayPlaneList& overlays, | 282 const OverlayPlaneList& overlays, |
| 276 CrtcState* state) { | 283 CrtcState* state) { |
| 277 const OverlayPlane& primary = GetPrimaryPlane(overlays); | 284 const OverlayPlane& primary = GetPrimaryPlane(overlays); |
| 278 DCHECK(primary.buffer); | 285 DCHECK(primary.buffer); |
| 279 | 286 |
| 280 if (primary.buffer->GetSize() != gfx::Size(mode_.hdisplay, mode_.vdisplay)) { | 287 if (primary.buffer->GetSize() != gfx::Size(mode_.hdisplay, mode_.vdisplay)) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 plane.overlay_plane)) { | 320 plane.overlay_plane)) { |
| 314 LOG(ERROR) << "Cannot display on overlay: " << strerror(errno); | 321 LOG(ERROR) << "Cannot display on overlay: " << strerror(errno); |
| 315 return false; | 322 return false; |
| 316 } | 323 } |
| 317 } | 324 } |
| 318 | 325 |
| 319 return true; | 326 return true; |
| 320 } | 327 } |
| 321 | 328 |
| 322 } // namespace ui | 329 } // namespace ui |
| OLD | NEW |