| 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/drm/gpu/hardware_display_controller.h" | 5 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h" |
| 6 | 6 |
| 7 #include <drm.h> | 7 #include <drm.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <xf86drm.h> | 9 #include <xf86drm.h> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "ui/gfx/geometry/point.h" | 15 #include "ui/gfx/geometry/point.h" |
| 16 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
| 17 #include "ui/gfx/native_widget_types.h" |
| 17 #include "ui/ozone/platform/drm/gpu/crtc_controller.h" | 18 #include "ui/ozone/platform/drm/gpu/crtc_controller.h" |
| 18 #include "ui/ozone/platform/drm/gpu/drm_buffer.h" | 19 #include "ui/ozone/platform/drm/gpu/drm_buffer.h" |
| 19 #include "ui/ozone/platform/drm/gpu/drm_device.h" | 20 #include "ui/ozone/platform/drm/gpu/drm_device.h" |
| 20 #include "ui/ozone/public/native_pixmap.h" | 21 #include "ui/ozone/public/native_pixmap.h" |
| 21 | 22 |
| 22 namespace ui { | 23 namespace ui { |
| 24 namespace { |
| 25 void EmptyPageFlipCallback(int result) { |
| 26 } |
| 27 } // namespace |
| 23 | 28 |
| 24 HardwareDisplayController::PageFlipRequest::PageFlipRequest( | 29 HardwareDisplayController::PageFlipRequest::PageFlipRequest( |
| 25 const OverlayPlaneList& planes, | 30 const OverlayPlaneList& planes, |
| 26 bool is_sync, | 31 bool is_sync, |
| 27 const base::Closure& callback) | 32 const PageFlipCallback& callback) |
| 28 : planes(planes), is_sync(is_sync), callback(callback) { | 33 : planes(planes), is_sync(is_sync), callback(callback) { |
| 29 } | 34 } |
| 30 | 35 |
| 31 HardwareDisplayController::PageFlipRequest::~PageFlipRequest() { | 36 HardwareDisplayController::PageFlipRequest::~PageFlipRequest() { |
| 32 } | 37 } |
| 33 | 38 |
| 34 HardwareDisplayController::HardwareDisplayController( | 39 HardwareDisplayController::HardwareDisplayController( |
| 35 scoped_ptr<CrtcController> controller) | 40 scoped_ptr<CrtcController> controller) |
| 36 : is_disabled_(true) { | 41 : is_disabled_(true) { |
| 37 memset(&mode_, 0, sizeof(mode_)); | 42 memset(&mode_, 0, sizeof(mode_)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 49 TRACE_EVENT0("drm", "HDC::Modeset"); | 54 TRACE_EVENT0("drm", "HDC::Modeset"); |
| 50 DCHECK(primary.buffer.get()); | 55 DCHECK(primary.buffer.get()); |
| 51 bool status = true; | 56 bool status = true; |
| 52 for (size_t i = 0; i < crtc_controllers_.size(); ++i) | 57 for (size_t i = 0; i < crtc_controllers_.size(); ++i) |
| 53 status &= crtc_controllers_[i]->Modeset(primary, mode); | 58 status &= crtc_controllers_[i]->Modeset(primary, mode); |
| 54 | 59 |
| 55 is_disabled_ = false; | 60 is_disabled_ = false; |
| 56 mode_ = mode; | 61 mode_ = mode; |
| 57 | 62 |
| 58 current_planes_ = std::vector<OverlayPlane>(1, primary); | 63 current_planes_ = std::vector<OverlayPlane>(1, primary); |
| 64 pending_planes_.clear(); |
| 59 ClearPendingRequests(); | 65 ClearPendingRequests(); |
| 60 | 66 |
| 61 // Because a page flip is pending we need to leave some state for the | 67 // Because a page flip is pending we need to leave some state for the |
| 62 // callback. We use the modeset state since it is the only valid state. | 68 // callback. We use the modeset state since it is the only valid state. |
| 63 if (HasPendingPageFlips()) | 69 if (HasPendingPageFlips()) |
| 64 requests_.push_back( | 70 requests_.push_back(PageFlipRequest(current_planes_, false, |
| 65 PageFlipRequest(current_planes_, false, base::Bind(&base::DoNothing))); | 71 base::Bind(&EmptyPageFlipCallback))); |
| 66 | 72 |
| 67 return status; | 73 return status; |
| 68 } | 74 } |
| 69 | 75 |
| 70 bool HardwareDisplayController::Enable() { | 76 bool HardwareDisplayController::Enable() { |
| 71 TRACE_EVENT0("drm", "HDC::Enable"); | 77 TRACE_EVENT0("drm", "HDC::Enable"); |
| 72 DCHECK(!current_planes_.empty()); | 78 DCHECK(!current_planes_.empty()); |
| 73 | 79 const OverlayPlane* primary = OverlayPlane::GetPrimaryPlane(current_planes_); |
| 74 const OverlayPlane* primary = nullptr; | |
| 75 // Use the last scheduled buffer to modeset to preserve request order. | |
| 76 if (!requests_.empty()) | |
| 77 primary = OverlayPlane::GetPrimaryPlane(requests_.back().planes); | |
| 78 else | |
| 79 primary = OverlayPlane::GetPrimaryPlane(current_planes_); | |
| 80 | 80 |
| 81 return Modeset(*primary, mode_); | 81 return Modeset(*primary, mode_); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void HardwareDisplayController::Disable() { | 84 void HardwareDisplayController::Disable() { |
| 85 TRACE_EVENT0("drm", "HDC::Disable"); | 85 TRACE_EVENT0("drm", "HDC::Disable"); |
| 86 for (size_t i = 0; i < crtc_controllers_.size(); ++i) | 86 for (size_t i = 0; i < crtc_controllers_.size(); ++i) |
| 87 crtc_controllers_[i]->Disable(); | 87 crtc_controllers_[i]->Disable(); |
| 88 | 88 |
| 89 is_disabled_ = true; | 89 is_disabled_ = true; |
| 90 } | 90 } |
| 91 | 91 |
| 92 void HardwareDisplayController::QueueOverlayPlane(const OverlayPlane& plane) { | 92 void HardwareDisplayController::QueueOverlayPlane(const OverlayPlane& plane) { |
| 93 pending_planes_.push_back(plane); | 93 pending_planes_.push_back(plane); |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool HardwareDisplayController::SchedulePageFlip( | 96 bool HardwareDisplayController::SchedulePageFlip( |
| 97 bool is_sync, | 97 bool is_sync, |
| 98 const base::Closure& callback) { | 98 const PageFlipCallback& callback) { |
| 99 TRACE_EVENT0("drm", "HDC::SchedulePageFlip"); | 99 TRACE_EVENT0("drm", "HDC::SchedulePageFlip"); |
| 100 | 100 |
| 101 // Ignore requests with no planes to schedule. | 101 // Ignore requests with no planes to schedule. |
| 102 if (pending_planes_.empty()) { | 102 if (pending_planes_.empty()) { |
| 103 callback.Run(); | 103 callback.Run(gfx::SwapAck); |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| 106 | 106 |
| 107 requests_.push_back(PageFlipRequest(pending_planes_, is_sync, callback)); | 107 requests_.push_back(PageFlipRequest(pending_planes_, is_sync, callback)); |
| 108 pending_planes_.clear(); | 108 pending_planes_.clear(); |
| 109 | 109 |
| 110 // A request is being serviced right now. | 110 // A request is being serviced right now. |
| 111 if (HasPendingPageFlips()) | 111 if (HasPendingPageFlips()) |
| 112 return true; | 112 return true; |
| 113 | 113 |
| 114 bool status = ActualSchedulePageFlip(); | 114 bool status = ActualSchedulePageFlip(); |
| 115 | 115 |
| 116 // No page flip event on failure so discard failed request. | 116 // No page flip event on failure so discard failed request. |
| 117 if (!status) | 117 if (!status) |
| 118 requests_.pop_front(); | 118 requests_.pop_front(); |
| 119 | 119 |
| 120 return status; | 120 return status; |
| 121 } | 121 } |
| 122 | 122 |
| 123 bool HardwareDisplayController::SchedulePageFlipWithoutCallback(bool is_sync) { |
| 124 return SchedulePageFlip(is_sync, base::Bind(&EmptyPageFlipCallback)); |
| 125 } |
| 126 |
| 123 bool HardwareDisplayController::SetCursor( | 127 bool HardwareDisplayController::SetCursor( |
| 124 const scoped_refptr<ScanoutBuffer>& buffer) { | 128 const scoped_refptr<ScanoutBuffer>& buffer) { |
| 125 bool status = true; | 129 bool status = true; |
| 126 | 130 |
| 127 if (is_disabled_) | 131 if (is_disabled_) |
| 128 return true; | 132 return true; |
| 129 | 133 |
| 130 for (size_t i = 0; i < crtc_controllers_.size(); ++i) | 134 for (size_t i = 0; i < crtc_controllers_.size(); ++i) |
| 131 status &= crtc_controllers_[i]->SetCursor(buffer); | 135 status &= crtc_controllers_[i]->SetCursor(buffer); |
| 132 | 136 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 257 |
| 254 // At this point we still have requests pending, so schedule the next request. | 258 // At this point we still have requests pending, so schedule the next request. |
| 255 bool status = ActualSchedulePageFlip(); | 259 bool status = ActualSchedulePageFlip(); |
| 256 if (!status) { | 260 if (!status) { |
| 257 PageFlipRequest request = requests_.front(); | 261 PageFlipRequest request = requests_.front(); |
| 258 requests_.pop_front(); | 262 requests_.pop_front(); |
| 259 | 263 |
| 260 // Normally the caller would handle the error call, but because we're in a | 264 // Normally the caller would handle the error call, but because we're in a |
| 261 // delayed schedule the initial SchedulePageFlip() already returned true, | 265 // delayed schedule the initial SchedulePageFlip() already returned true, |
| 262 // thus we need to run the callback. | 266 // thus we need to run the callback. |
| 263 request.callback.Run(); | 267 request.callback.Run(gfx::SwapFailed); |
| 264 } | 268 } |
| 265 } | 269 } |
| 266 | 270 |
| 267 scoped_refptr<DrmDevice> HardwareDisplayController::GetAllocationDrmDevice() | 271 scoped_refptr<DrmDevice> HardwareDisplayController::GetAllocationDrmDevice() |
| 268 const { | 272 const { |
| 269 DCHECK(!crtc_controllers_.empty()); | 273 DCHECK(!crtc_controllers_.empty()); |
| 270 // TODO(dnicoara) When we support mirroring across DRM devices, figure out | 274 // TODO(dnicoara) When we support mirroring across DRM devices, figure out |
| 271 // which device should be used for allocations. | 275 // which device should be used for allocations. |
| 272 return crtc_controllers_[0]->drm(); | 276 return crtc_controllers_[0]->drm(); |
| 273 } | 277 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 315 |
| 312 return status; | 316 return status; |
| 313 } | 317 } |
| 314 | 318 |
| 315 void HardwareDisplayController::ProcessPageFlipRequest() { | 319 void HardwareDisplayController::ProcessPageFlipRequest() { |
| 316 DCHECK(!requests_.empty()); | 320 DCHECK(!requests_.empty()); |
| 317 PageFlipRequest request = requests_.front(); | 321 PageFlipRequest request = requests_.front(); |
| 318 requests_.pop_front(); | 322 requests_.pop_front(); |
| 319 | 323 |
| 320 current_planes_.swap(request.planes); | 324 current_planes_.swap(request.planes); |
| 321 request.callback.Run(); | 325 request.callback.Run(gfx::SwapAck); |
| 322 } | 326 } |
| 323 | 327 |
| 324 void HardwareDisplayController::ClearPendingRequests() { | 328 void HardwareDisplayController::ClearPendingRequests() { |
| 325 while (!requests_.empty()) { | 329 while (!requests_.empty()) { |
| 326 PageFlipRequest request = requests_.front(); | 330 PageFlipRequest request = requests_.front(); |
| 327 requests_.pop_front(); | 331 requests_.pop_front(); |
| 328 request.callback.Run(); | 332 request.callback.Run(gfx::SwapAck); |
| 329 } | 333 } |
| 330 } | 334 } |
| 331 | 335 |
| 332 } // namespace ui | 336 } // namespace ui |
| OLD | NEW |