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

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

Issue 821023003: [Ozone-DRI] Listen for swap events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@async-swap
Patch Set: . Created 5 years, 11 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
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/crtc_controller.h" 5 #include "ui/ozone/platform/dri/crtc_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "ui/ozone/platform/dri/dri_wrapper.h" 9 #include "ui/ozone/platform/dri/dri_wrapper.h"
10 #include "ui/ozone/platform/dri/page_flip_observer.h"
10 #include "ui/ozone/platform/dri/scanout_buffer.h" 11 #include "ui/ozone/platform/dri/scanout_buffer.h"
11 12
12 namespace ui { 13 namespace ui {
13 14
14 CrtcController::CrtcController(DriWrapper* drm, 15 CrtcController::CrtcController(DriWrapper* drm,
15 uint32_t crtc, 16 uint32_t crtc,
16 uint32_t connector) 17 uint32_t connector)
17 : drm_(drm), 18 : drm_(drm),
18 crtc_(crtc), 19 crtc_(crtc),
19 connector_(connector), 20 connector_(connector),
(...skipping 14 matching lines...) Expand all
34 if (!drm_->SetCrtc(crtc_, plane.buffer->GetFramebufferId(), 35 if (!drm_->SetCrtc(crtc_, plane.buffer->GetFramebufferId(),
35 std::vector<uint32_t>(1, connector_), &mode)) { 36 std::vector<uint32_t>(1, connector_), &mode)) {
36 LOG(ERROR) << "Failed to modeset: error='" << strerror(errno) 37 LOG(ERROR) << "Failed to modeset: error='" << strerror(errno)
37 << "' crtc=" << crtc_ << " connector=" << connector_ 38 << "' crtc=" << crtc_ << " connector=" << connector_
38 << " framebuffer_id=" << plane.buffer->GetFramebufferId() 39 << " framebuffer_id=" << plane.buffer->GetFramebufferId()
39 << " mode=" << mode.hdisplay << "x" << mode.vdisplay << "@" 40 << " mode=" << mode.hdisplay << "x" << mode.vdisplay << "@"
40 << mode.vrefresh; 41 << mode.vrefresh;
41 return false; 42 return false;
42 } 43 }
43 44
44 current_planes_ = std::vector<OverlayPlane>(1, plane);
45 mode_ = mode; 45 mode_ = mode;
46 pending_planes_.clear(); 46 pending_planes_.clear();
47 is_disabled_ = false; 47 is_disabled_ = false;
48 page_flip_pending_ = false; 48
49 // drmModeSetCrtc has an immediate effect, so we can assume that the current
50 // planes have been updated. However if a page flip is still pending, set the
51 // pending planes to the same values so that the callback keeps the correct
52 // state.
53 current_planes_ = std::vector<OverlayPlane>(1, plane);
54 if (page_flip_pending_)
55 pending_planes_ = current_planes_;
49 56
50 return true; 57 return true;
51 } 58 }
52 59
53 bool CrtcController::Disable() { 60 bool CrtcController::Disable() {
54 if (is_disabled_) 61 if (is_disabled_)
55 return true; 62 return true;
56 63
57 is_disabled_ = true; 64 is_disabled_ = true;
58 page_flip_pending_ = false;
59 return drm_->DisableCrtc(crtc_); 65 return drm_->DisableCrtc(crtc_);
60 } 66 }
61 67
62 bool CrtcController::SchedulePageFlip(HardwareDisplayPlaneList* plane_list, 68 bool CrtcController::SchedulePageFlip(HardwareDisplayPlaneList* plane_list,
63 const OverlayPlaneList& overlays) { 69 const OverlayPlaneList& overlays) {
64 DCHECK(!page_flip_pending_); 70 DCHECK(!page_flip_pending_);
65 DCHECK(!is_disabled_); 71 DCHECK(!is_disabled_);
66 const OverlayPlane* primary = OverlayPlane::GetPrimaryPlane(overlays); 72 const OverlayPlane* primary = OverlayPlane::GetPrimaryPlane(overlays);
67 if (!primary) { 73 if (!primary) {
68 LOG(ERROR) << "No primary plane to display on crtc " << crtc_; 74 LOG(ERROR) << "No primary plane to display on crtc " << crtc_;
75 FOR_EACH_OBSERVER(PageFlipObserver, observers_, OnPageFlipEvent());
69 return true; 76 return true;
70 } 77 }
71 DCHECK(primary->buffer.get()); 78 DCHECK(primary->buffer.get());
72 79
73 if (primary->buffer->GetSize() != gfx::Size(mode_.hdisplay, mode_.vdisplay)) { 80 if (primary->buffer->GetSize() != gfx::Size(mode_.hdisplay, mode_.vdisplay)) {
74 LOG(WARNING) << "Trying to pageflip a buffer with the wrong size. Expected " 81 LOG(WARNING) << "Trying to pageflip a buffer with the wrong size. Expected "
75 << mode_.hdisplay << "x" << mode_.vdisplay << " got " 82 << mode_.hdisplay << "x" << mode_.vdisplay << " got "
76 << primary->buffer->GetSize().ToString() << " for" 83 << primary->buffer->GetSize().ToString() << " for"
77 << " crtc=" << crtc_ << " connector=" << connector_; 84 << " crtc=" << crtc_ << " connector=" << connector_;
85 FOR_EACH_OBSERVER(PageFlipObserver, observers_, OnPageFlipEvent());
78 return true; 86 return true;
79 } 87 }
80 88
81 if (!drm_->plane_manager()->AssignOverlayPlanes(plane_list, overlays, crtc_, 89 if (!drm_->plane_manager()->AssignOverlayPlanes(plane_list, overlays, crtc_,
82 this)) { 90 this)) {
83 LOG(ERROR) << "Failed to assign overlay planes for crtc " << crtc_; 91 LOG(ERROR) << "Failed to assign overlay planes for crtc " << crtc_;
84 return false; 92 return false;
85 } 93 }
86 94
87 page_flip_pending_ = true; 95 page_flip_pending_ = true;
(...skipping 10 matching lines...) Expand all
98 void CrtcController::OnPageFlipEvent(unsigned int frame, 106 void CrtcController::OnPageFlipEvent(unsigned int frame,
99 unsigned int seconds, 107 unsigned int seconds,
100 unsigned int useconds) { 108 unsigned int useconds) {
101 page_flip_pending_ = false; 109 page_flip_pending_ = false;
102 time_of_last_flip_ = 110 time_of_last_flip_ =
103 static_cast<uint64_t>(seconds) * base::Time::kMicrosecondsPerSecond + 111 static_cast<uint64_t>(seconds) * base::Time::kMicrosecondsPerSecond +
104 useconds; 112 useconds;
105 113
106 current_planes_.clear(); 114 current_planes_.clear();
107 current_planes_.swap(pending_planes_); 115 current_planes_.swap(pending_planes_);
116
117 FOR_EACH_OBSERVER(PageFlipObserver, observers_, OnPageFlipEvent());
108 } 118 }
109 119
110 bool CrtcController::SetCursor(const scoped_refptr<ScanoutBuffer>& buffer) { 120 bool CrtcController::SetCursor(const scoped_refptr<ScanoutBuffer>& buffer) {
111 DCHECK(!is_disabled_); 121 DCHECK(!is_disabled_);
112 cursor_buffer_ = buffer; 122 cursor_buffer_ = buffer;
113 return drm_->SetCursor(crtc_, buffer->GetHandle(), buffer->GetSize()); 123 return drm_->SetCursor(crtc_, buffer->GetHandle(), buffer->GetSize());
114 } 124 }
115 125
116 bool CrtcController::UnsetCursor() { 126 bool CrtcController::UnsetCursor() {
117 bool state = drm_->SetCursor(crtc_, 0, gfx::Size()); 127 bool state = drm_->SetCursor(crtc_, 0, gfx::Size());
118 cursor_buffer_ = NULL; 128 cursor_buffer_ = NULL;
119 return state; 129 return state;
120 } 130 }
121 131
122 bool CrtcController::MoveCursor(const gfx::Point& location) { 132 bool CrtcController::MoveCursor(const gfx::Point& location) {
123 DCHECK(!is_disabled_); 133 DCHECK(!is_disabled_);
124 return drm_->MoveCursor(crtc_, location); 134 return drm_->MoveCursor(crtc_, location);
125 } 135 }
126 136
137 void CrtcController::AddObserver(PageFlipObserver* observer) {
138 observers_.AddObserver(observer);
139 }
140
141 void CrtcController::RemoveObserver(PageFlipObserver* observer) {
142 observers_.RemoveObserver(observer);
143 }
144
127 } // namespace ui 145 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698