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

Side by Side Diff: ui/ozone/platform/dri/hardware_display_controller.cc

Issue 393233005: [Ozone-DRI] Convert HardwareDisplayController to use scanout buffers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
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>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "third_party/skia/include/core/SkCanvas.h" 16 #include "third_party/skia/include/core/SkCanvas.h"
17 #include "ui/gfx/geometry/point.h" 17 #include "ui/gfx/geometry/point.h"
18 #include "ui/gfx/geometry/size.h" 18 #include "ui/gfx/geometry/size.h"
19 #include "ui/ozone/platform/dri/dri_buffer.h" 19 #include "ui/ozone/platform/dri/dri_buffer.h"
20 #include "ui/ozone/platform/dri/dri_wrapper.h" 20 #include "ui/ozone/platform/dri/dri_wrapper.h"
21 #include "ui/ozone/platform/dri/scanout_surface.h"
22 #include "ui/ozone/public/native_pixmap.h" 21 #include "ui/ozone/public/native_pixmap.h"
23 22
24 namespace ui { 23 namespace ui {
25 24
26 namespace { 25 namespace {
27 26
28 // DRM callback on page flip events. This callback is triggered after the 27 // DRM callback on page flip events. This callback is triggered after the
29 // page flip has happened and the backbuffer is now the new frontbuffer 28 // page flip has happened and the backbuffer is now the new frontbuffer
30 // The old frontbuffer is no longer used by the hardware and can be used for 29 // The old frontbuffer is no longer used by the hardware and can be used for
31 // future draw operations. 30 // future draw operations.
32 // 31 //
33 // |device| will contain a reference to the |ScanoutSurface| object which 32 // |device| will contain a reference to the |ScanoutSurface| object which
34 // the event belongs to. 33 // the event belongs to.
35 // 34 //
36 // TODO(dnicoara) When we have a FD handler for the DRM calls in the message 35 // TODO(dnicoara) When we have a FD handler for the DRM calls in the message
37 // loop, we can move this function in the handler. 36 // loop, we can move this function in the handler.
38 void HandlePageFlipEvent(int fd, 37 void HandlePageFlipEvent(int fd,
39 unsigned int frame, 38 unsigned int frame,
40 unsigned int seconds, 39 unsigned int seconds,
41 unsigned int useconds, 40 unsigned int useconds,
42 void* controller) { 41 void* controller) {
43 TRACE_EVENT0("dri", "HandlePageFlipEvent"); 42 TRACE_EVENT0("dri", "HandlePageFlipEvent");
44 static_cast<HardwareDisplayController*>(controller) 43 static_cast<HardwareDisplayController*>(controller)
45 ->OnPageFlipEvent(frame, seconds, useconds); 44 ->OnPageFlipEvent(frame, seconds, useconds);
46 } 45 }
47 46
47 const OverlayPlane& GetPrimaryPlane(const OverlayPlaneList& overlays) {
48 for (size_t i = 0; i < overlays.size(); ++i) {
49 if (overlays[i].z_order == 0)
50 return overlays[i];
51 }
52
53 NOTREACHED();
54 return overlays[0];
55 }
56
48 } // namespace 57 } // namespace
49 58
50 OzoneOverlayPlane::OzoneOverlayPlane(ScanoutSurface* scanout, 59 OverlayPlane::OverlayPlane(scoped_refptr<ScanoutBuffer> buffer)
51 int z_order, 60 : buffer(buffer),
52 gfx::OverlayTransform plane_transform, 61 z_order(0),
53 const gfx::Rect& display_bounds, 62 display_bounds(gfx::Point(), buffer->GetSize()),
54 const gfx::RectF& crop_rect) 63 crop_rect(0, 0, 1, 1),
55 : scanout(scanout), 64 overlay_plane(0) {}
65
66 OverlayPlane::OverlayPlane(scoped_refptr<ScanoutBuffer> buffer,
67 int z_order,
68 gfx::OverlayTransform plane_transform,
69 const gfx::Rect& display_bounds,
70 const gfx::RectF& crop_rect)
71 : buffer(buffer),
56 z_order(z_order), 72 z_order(z_order),
57 plane_transform(plane_transform), 73 plane_transform(plane_transform),
58 display_bounds(display_bounds), 74 display_bounds(display_bounds),
59 crop_rect(crop_rect), 75 crop_rect(crop_rect),
60 overlay_plane(0) { 76 overlay_plane(0) {
61 } 77 }
62 78
79 OverlayPlane::~OverlayPlane() {}
80
63 HardwareDisplayController::HardwareDisplayController( 81 HardwareDisplayController::HardwareDisplayController(
64 DriWrapper* drm, 82 DriWrapper* drm,
65 uint32_t connector_id, 83 uint32_t connector_id,
66 uint32_t crtc_id) 84 uint32_t crtc_id)
67 : drm_(drm), 85 : drm_(drm),
68 connector_id_(connector_id), 86 connector_id_(connector_id),
69 crtc_id_(crtc_id), 87 crtc_id_(crtc_id),
70 surface_(),
71 time_of_last_flip_(0), 88 time_of_last_flip_(0),
72 is_disabled_(true), 89 is_disabled_(true),
73 saved_crtc_(drm_->GetCrtc(crtc_id_)) {} 90 saved_crtc_(drm_->GetCrtc(crtc_id_)) {}
74 91
75 HardwareDisplayController::~HardwareDisplayController() { 92 HardwareDisplayController::~HardwareDisplayController() {
76 if (!is_disabled_) 93 if (!is_disabled_)
77 drm_->SetCrtc(saved_crtc_.get(), &connector_id_); 94 drm_->SetCrtc(saved_crtc_.get(), &connector_id_);
78 95
79 // Reset the cursor. 96 // Reset the cursor.
80 UnsetCursor(); 97 UnsetCursor();
81 UnbindSurfaceFromController();
82 } 98 }
83 99
84 bool 100 bool HardwareDisplayController::Modeset(const OverlayPlane& primary,
85 HardwareDisplayController::BindSurfaceToController( 101 drmModeModeInfo mode) {
86 scoped_ptr<ScanoutSurface> surface, drmModeModeInfo mode) { 102 CHECK(primary.buffer);
87 CHECK(surface);
88
89 if (!drm_->SetCrtc(crtc_id_, 103 if (!drm_->SetCrtc(crtc_id_,
90 surface->GetFramebufferId(), 104 primary.buffer->GetFramebufferId(),
91 &connector_id_, 105 &connector_id_,
92 &mode)) { 106 &mode)) {
93 LOG(ERROR) << "Failed to modeset: error='" << strerror(errno) 107 LOG(ERROR) << "Failed to modeset: error='" << strerror(errno)
94 << "' crtc=" << crtc_id_ << " connector=" << connector_id_ 108 << "' crtc=" << crtc_id_ << " connector=" << connector_id_
95 << " framebuffer_id=" << surface->GetFramebufferId() 109 << " framebuffer_id=" << primary.buffer->GetFramebufferId()
96 << " mode=" << mode.hdisplay << "x" << mode.vdisplay << "@" 110 << " mode=" << mode.hdisplay << "x" << mode.vdisplay << "@"
97 << mode.vrefresh; 111 << mode.vrefresh;
98 return false; 112 return false;
99 } 113 }
100 114
101 surface_.reset(surface.release()); 115 current_planes_ = std::vector<OverlayPlane>(1, primary);
116 pending_planes_.clear();
102 mode_ = mode; 117 mode_ = mode;
103 is_disabled_ = false; 118 is_disabled_ = false;
104 return true; 119 return true;
105 } 120 }
106 121
107 void HardwareDisplayController::UnbindSurfaceFromController() {
108 drm_->SetCrtc(crtc_id_, 0, 0, NULL);
109 surface_.reset();
110 memset(&mode_, 0, sizeof(mode_));
111 is_disabled_ = true;
112 }
113
114 bool HardwareDisplayController::Enable() { 122 bool HardwareDisplayController::Enable() {
115 CHECK(surface_); 123 OverlayPlane primary = GetPrimaryPlane(current_planes_);
116 if (is_disabled_) { 124 CHECK(primary.buffer);
117 scoped_ptr<ScanoutSurface> surface(surface_.release()); 125 if (is_disabled_)
118 return BindSurfaceToController(surface.Pass(), mode_); 126 return Modeset(primary, mode_);
119 }
120 127
121 return true; 128 return true;
122 } 129 }
123 130
124 void HardwareDisplayController::Disable() { 131 void HardwareDisplayController::Disable() {
125 drm_->SetCrtc(crtc_id_, 0, 0, NULL); 132 drm_->SetCrtc(crtc_id_, 0, 0, NULL);
126 is_disabled_ = true; 133 is_disabled_ = true;
127 } 134 }
128 135
129 ScanoutSurface* HardwareDisplayController::GetPrimaryPlane(
130 const std::vector<OzoneOverlayPlane>& overlays) {
131 ScanoutSurface* primary = surface_.get();
132 for (size_t i = 0; i < overlays.size(); i++) {
133 const OzoneOverlayPlane& plane = overlays[i];
134 if (plane.z_order == 0) {
135 return plane.scanout;
136 }
137 }
138
139 return primary;
140 }
141
142 bool HardwareDisplayController::SchedulePageFlip( 136 bool HardwareDisplayController::SchedulePageFlip(
143 const std::vector<OzoneOverlayPlane>& overlays, 137 const OverlayPlaneList& overlays) {
144 NativePixmapList* references) { 138 CHECK_LE(1u, overlays.size());
145 ScanoutSurface* primary = GetPrimaryPlane(overlays); 139 const OverlayPlane& primary = GetPrimaryPlane(overlays);
146 CHECK(primary); 140 CHECK(primary.buffer);
147
148 primary->PreSwapBuffers();
149 141
150 if (!is_disabled_ && 142 if (!is_disabled_ &&
151 !drm_->PageFlip(crtc_id_, primary->GetFramebufferId(), this)) { 143 !drm_->PageFlip(crtc_id_, primary.buffer->GetFramebufferId(), this)) {
152 LOG(ERROR) << "Cannot page flip: " << strerror(errno); 144 LOG(ERROR) << "Cannot page flip: " << strerror(errno);
153 return false; 145 return false;
154 } 146 }
155 147
156 current_overlay_references_.clear(); 148 pending_planes_ = overlays;
157 if (references)
158 current_overlay_references_.swap(*references);
159 149
160 for (size_t i = 0; i < overlays.size(); i++) { 150 for (size_t i = 0; i < overlays.size(); i++) {
161 const OzoneOverlayPlane& plane = overlays[i]; 151 const OverlayPlane& plane = overlays[i];
162 if (!plane.overlay_plane) 152 if (!plane.overlay_plane)
163 continue; 153 continue;
164 const gfx::Size& size = plane.scanout->Size(); 154 const gfx::Size& size = plane.buffer->GetSize();
165 gfx::RectF crop_rect = plane.crop_rect; 155 gfx::RectF crop_rect = plane.crop_rect;
166 crop_rect.Scale(size.width(), size.height()); 156 crop_rect.Scale(size.width(), size.height());
167 if (!drm_->PageFlipOverlay(crtc_id_, 157 if (!drm_->PageFlipOverlay(crtc_id_,
168 plane.scanout->GetFramebufferId(), 158 plane.buffer->GetFramebufferId(),
169 plane.display_bounds, 159 plane.display_bounds,
170 crop_rect, 160 crop_rect,
171 plane.overlay_plane)) { 161 plane.overlay_plane)) {
172 LOG(ERROR) << "Cannot display on overlay: " << strerror(errno); 162 LOG(ERROR) << "Cannot display on overlay: " << strerror(errno);
173 return false; 163 return false;
174 } 164 }
175 } 165 }
176 166
177 return true; 167 return true;
178 } 168 }
(...skipping 13 matching lines...) Expand all
192 drm_->HandleEvent(drm_event); 182 drm_->HandleEvent(drm_event);
193 } 183 }
194 184
195 void HardwareDisplayController::OnPageFlipEvent(unsigned int frame, 185 void HardwareDisplayController::OnPageFlipEvent(unsigned int frame,
196 unsigned int seconds, 186 unsigned int seconds,
197 unsigned int useconds) { 187 unsigned int useconds) {
198 time_of_last_flip_ = 188 time_of_last_flip_ =
199 static_cast<uint64_t>(seconds) * base::Time::kMicrosecondsPerSecond + 189 static_cast<uint64_t>(seconds) * base::Time::kMicrosecondsPerSecond +
200 useconds; 190 useconds;
201 191
202 surface_->SwapBuffers(); 192 current_planes_ = pending_planes_;
193 pending_planes_.clear();
203 } 194 }
204 195
205 bool HardwareDisplayController::SetCursor(scoped_refptr<ScanoutBuffer> buffer) { 196 bool HardwareDisplayController::SetCursor(scoped_refptr<ScanoutBuffer> buffer) {
206 bool ret = drm_->SetCursor(crtc_id_, 197 bool ret = drm_->SetCursor(crtc_id_,
207 buffer->GetHandle(), 198 buffer->GetHandle(),
208 buffer->GetSize()); 199 buffer->GetSize());
209 cursor_buffer_ = buffer; 200 cursor_buffer_ = buffer;
210 return ret; 201 return ret;
211 } 202 }
212 203
213 bool HardwareDisplayController::UnsetCursor() { 204 bool HardwareDisplayController::UnsetCursor() {
214 cursor_buffer_ = NULL; 205 cursor_buffer_ = NULL;
215 return drm_->SetCursor(crtc_id_, 0, gfx::Size()); 206 return drm_->SetCursor(crtc_id_, 0, gfx::Size());
216 } 207 }
217 208
218 bool HardwareDisplayController::MoveCursor(const gfx::Point& location) { 209 bool HardwareDisplayController::MoveCursor(const gfx::Point& location) {
219 if (is_disabled_) 210 if (is_disabled_)
220 return true; 211 return true;
221 212
222 return drm_->MoveCursor(crtc_id_, location); 213 return drm_->MoveCursor(crtc_id_, location);
223 } 214 }
224 215
225 } // namespace ui 216 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/dri/hardware_display_controller.h ('k') | ui/ozone/platform/dri/hardware_display_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698