| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/ozone/platform/dri/crtc_controller.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/time/time.h" | |
| 9 #include "ui/ozone/platform/dri/dri_wrapper.h" | |
| 10 #include "ui/ozone/platform/dri/scanout_buffer.h" | |
| 11 | |
| 12 namespace ui { | |
| 13 | |
| 14 CrtcController::CrtcController(DriWrapper* drm, | |
| 15 uint32_t crtc, | |
| 16 uint32_t connector) | |
| 17 : drm_(drm), | |
| 18 crtc_(crtc), | |
| 19 connector_(connector), | |
| 20 saved_crtc_(drm->GetCrtc(crtc)), | |
| 21 is_disabled_(true), | |
| 22 page_flip_pending_(false), | |
| 23 time_of_last_flip_(0) { | |
| 24 } | |
| 25 | |
| 26 CrtcController::~CrtcController() { | |
| 27 if (!is_disabled_) { | |
| 28 drm_->SetCrtc(saved_crtc_.get(), std::vector<uint32_t>(1, connector_)); | |
| 29 UnsetCursor(); | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 bool CrtcController::Modeset(const OverlayPlane& plane, drmModeModeInfo mode) { | |
| 34 if (!drm_->SetCrtc(crtc_, | |
| 35 plane.buffer->GetFramebufferId(), | |
| 36 std::vector<uint32_t>(1, connector_), | |
| 37 &mode)) { | |
| 38 LOG(ERROR) << "Failed to modeset: error='" << strerror(errno) | |
| 39 << "' crtc=" << crtc_ << " connector=" << connector_ | |
| 40 << " framebuffer_id=" << plane.buffer->GetFramebufferId() | |
| 41 << " mode=" << mode.hdisplay << "x" << mode.vdisplay << "@" | |
| 42 << mode.vrefresh; | |
| 43 return false; | |
| 44 } | |
| 45 | |
| 46 current_planes_ = std::vector<OverlayPlane>(1, plane); | |
| 47 mode_ = mode; | |
| 48 pending_planes_.clear(); | |
| 49 is_disabled_ = false; | |
| 50 page_flip_pending_ = false; | |
| 51 | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 bool CrtcController::Disable() { | |
| 56 if (is_disabled_) | |
| 57 return true; | |
| 58 | |
| 59 is_disabled_ = true; | |
| 60 page_flip_pending_ = false; | |
| 61 return drm_->DisableCrtc(crtc_); | |
| 62 } | |
| 63 | |
| 64 bool CrtcController::SchedulePageFlip(const OverlayPlaneList& overlays) { | |
| 65 DCHECK(!page_flip_pending_); | |
| 66 DCHECK(!is_disabled_); | |
| 67 const OverlayPlane& primary = OverlayPlane::GetPrimaryPlane(overlays); | |
| 68 DCHECK(primary.buffer.get()); | |
| 69 | |
| 70 if (primary.buffer->GetSize() != gfx::Size(mode_.hdisplay, mode_.vdisplay)) { | |
| 71 LOG(WARNING) << "Trying to pageflip a buffer with the wrong size. Expected " | |
| 72 << mode_.hdisplay << "x" << mode_.vdisplay << " got " | |
| 73 << primary.buffer->GetSize().ToString() << " for" | |
| 74 << " crtc=" << crtc_ << " connector=" << connector_; | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 78 if (!drm_->PageFlip(crtc_, primary.buffer->GetFramebufferId(), this)) { | |
| 79 LOG(ERROR) << "Cannot page flip: error='" << strerror(errno) << "'" | |
| 80 << " crtc=" << crtc_ | |
| 81 << " framebuffer=" << primary.buffer->GetFramebufferId() | |
| 82 << " size=" << primary.buffer->GetSize().ToString(); | |
| 83 return false; | |
| 84 } | |
| 85 | |
| 86 page_flip_pending_ = true; | |
| 87 pending_planes_ = overlays; | |
| 88 | |
| 89 for (size_t i = 0; i < overlays.size(); i++) { | |
| 90 const OverlayPlane& plane = overlays[i]; | |
| 91 if (!plane.overlay_plane) | |
| 92 continue; | |
| 93 | |
| 94 const gfx::Size& size = plane.buffer->GetSize(); | |
| 95 gfx::RectF crop_rect = plane.crop_rect; | |
| 96 crop_rect.Scale(size.width(), size.height()); | |
| 97 if (!drm_->PageFlipOverlay(crtc_, | |
| 98 plane.buffer->GetFramebufferId(), | |
| 99 plane.display_bounds, | |
| 100 crop_rect, | |
| 101 plane.overlay_plane)) { | |
| 102 LOG(ERROR) << "Cannot display on overlay: " << strerror(errno); | |
| 103 return false; | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 return true; | |
| 108 } | |
| 109 | |
| 110 void CrtcController::OnPageFlipEvent(unsigned int frame, | |
| 111 unsigned int seconds, | |
| 112 unsigned int useconds) { | |
| 113 page_flip_pending_ = false; | |
| 114 time_of_last_flip_ = | |
| 115 static_cast<uint64_t>(seconds) * base::Time::kMicrosecondsPerSecond + | |
| 116 useconds; | |
| 117 | |
| 118 current_planes_.clear(); | |
| 119 current_planes_.swap(pending_planes_); | |
| 120 } | |
| 121 | |
| 122 bool CrtcController::SetCursor(const scoped_refptr<ScanoutBuffer>& buffer) { | |
| 123 DCHECK(!is_disabled_); | |
| 124 cursor_buffer_ = buffer; | |
| 125 return drm_->SetCursor(crtc_, buffer->GetHandle(), buffer->GetSize()); | |
| 126 } | |
| 127 | |
| 128 bool CrtcController::UnsetCursor() { | |
| 129 bool state = drm_->SetCursor(crtc_, 0, gfx::Size()); | |
| 130 cursor_buffer_ = NULL; | |
| 131 return state; | |
| 132 } | |
| 133 | |
| 134 bool CrtcController::MoveCursor(const gfx::Point& location) { | |
| 135 DCHECK(!is_disabled_); | |
| 136 return drm_->MoveCursor(crtc_, location); | |
| 137 } | |
| 138 | |
| 139 } // namespace ui | |
| OLD | NEW |