Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: ui/ozone/platform/drm/gpu/crtc_controller.cc

Issue 1285183008: Ozone integration. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add missing license header Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/ozone/platform/drm/gpu/crtc_controller.h ('k') | ui/ozone/platform/drm/gpu/drm_buffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/drm/gpu/crtc_controller.h"
6
7 #include "base/logging.h"
8 #include "base/time/time.h"
9 #include "ui/ozone/platform/drm/gpu/drm_device.h"
10 #include "ui/ozone/platform/drm/gpu/page_flip_request.h"
11 #include "ui/ozone/platform/drm/gpu/scanout_buffer.h"
12
13 namespace ui {
14
15 CrtcController::CrtcController(const scoped_refptr<DrmDevice>& drm,
16 uint32_t crtc,
17 uint32_t connector)
18 : drm_(drm), crtc_(crtc), connector_(connector) {
19 }
20
21 CrtcController::~CrtcController() {
22 if (!is_disabled_) {
23 SetCursor(nullptr);
24 drm_->DisableCrtc(crtc_);
25 SignalPageFlipRequest();
26 }
27 }
28
29 bool CrtcController::Modeset(const OverlayPlane& plane, drmModeModeInfo mode) {
30 if (!drm_->SetCrtc(crtc_, plane.buffer->GetFramebufferId(),
31 std::vector<uint32_t>(1, connector_), &mode)) {
32 PLOG(ERROR) << "Failed to modeset: crtc=" << crtc_
33 << " connector=" << connector_
34 << " framebuffer_id=" << plane.buffer->GetFramebufferId()
35 << " mode=" << mode.hdisplay << "x" << mode.vdisplay << "@"
36 << mode.vrefresh;
37 return false;
38 }
39
40 mode_ = mode;
41 pending_planes_.clear();
42 is_disabled_ = false;
43
44 // drmModeSetCrtc has an immediate effect, so we can assume that the current
45 // planes have been updated. However if a page flip is still pending, set the
46 // pending planes to the same values so that the callback keeps the correct
47 // state.
48 current_planes_ = std::vector<OverlayPlane>(1, plane);
49 if (page_flip_request_.get())
50 pending_planes_ = current_planes_;
51
52 ResetCursor();
53
54 return true;
55 }
56
57 bool CrtcController::Disable() {
58 if (is_disabled_)
59 return true;
60
61 is_disabled_ = true;
62 return drm_->DisableCrtc(crtc_);
63 }
64
65 bool CrtcController::SchedulePageFlip(
66 HardwareDisplayPlaneList* plane_list,
67 const OverlayPlaneList& overlays,
68 bool test_only,
69 scoped_refptr<PageFlipRequest> page_flip_request) {
70 DCHECK(!page_flip_request_.get() || test_only);
71 DCHECK(!is_disabled_);
72 const OverlayPlane* primary = OverlayPlane::GetPrimaryPlane(overlays);
73 if (!primary) {
74 LOG(ERROR) << "No primary plane to display on crtc " << crtc_;
75 page_flip_request->Signal(gfx::SwapResult::SWAP_ACK);
76 return true;
77 }
78 DCHECK(primary->buffer.get());
79
80 if (primary->buffer->GetSize() != gfx::Size(mode_.hdisplay, mode_.vdisplay)) {
81 VLOG(2) << "Trying to pageflip a buffer with the wrong size. Expected "
82 << mode_.hdisplay << "x" << mode_.vdisplay << " got "
83 << primary->buffer->GetSize().ToString() << " for"
84 << " crtc=" << crtc_ << " connector=" << connector_;
85 page_flip_request->Signal(gfx::SwapResult::SWAP_ACK);
86 return true;
87 }
88
89 if (!drm_->plane_manager()->AssignOverlayPlanes(plane_list, overlays, crtc_,
90 this)) {
91 PLOG(ERROR) << "Failed to assign overlay planes for crtc " << crtc_;
92 page_flip_request->Signal(gfx::SwapResult::SWAP_FAILED);
93 return false;
94 }
95
96 if (test_only) {
97 page_flip_request->Signal(gfx::SwapResult::SWAP_ACK);
98 } else {
99 pending_planes_ = overlays;
100 page_flip_request_ = page_flip_request;
101 }
102
103 return true;
104 }
105
106 void CrtcController::PageFlipFailed() {
107 pending_planes_.clear();
108 SignalPageFlipRequest();
109 }
110
111 void CrtcController::OnPageFlipEvent(unsigned int frame,
112 unsigned int seconds,
113 unsigned int useconds) {
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 SignalPageFlipRequest();
122 }
123
124 bool CrtcController::SetCursor(const scoped_refptr<ScanoutBuffer>& buffer) {
125 DCHECK(!is_disabled_ || !buffer);
126 cursor_buffer_ = buffer;
127
128 return ResetCursor();
129 }
130
131 bool CrtcController::MoveCursor(const gfx::Point& location) {
132 DCHECK(!is_disabled_);
133 return drm_->MoveCursor(crtc_, location);
134 }
135
136 bool CrtcController::ResetCursor() {
137 uint32_t handle = 0;
138 gfx::Size size;
139
140 if (cursor_buffer_) {
141 handle = cursor_buffer_->GetHandle();
142 size = cursor_buffer_->GetSize();
143 }
144
145 bool status = drm_->SetCursor(crtc_, handle, size);
146 if (!status) {
147 PLOG(ERROR) << "drmModeSetCursor: device " << drm_->device_path().value()
148 << " crtc " << crtc_ << " handle " << handle << " size "
149 << size.ToString();
150 }
151
152 return status;
153 }
154
155 void CrtcController::SignalPageFlipRequest() {
156 if (page_flip_request_.get()) {
157 // If another frame is queued up and available immediately, calling Signal()
158 // may result in a call to SchedulePageFlip(), which will override
159 // page_flip_request_ and possibly release the ref. Stash previous request
160 // locally to avoid deleting the object we are making a call on.
161 scoped_refptr<PageFlipRequest> last_request;
162 last_request.swap(page_flip_request_);
163 last_request->Signal(gfx::SwapResult::SWAP_ACK);
164 }
165 }
166
167 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/gpu/crtc_controller.h ('k') | ui/ozone/platform/drm/gpu/drm_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698