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/dri/hardware_display_controller.h" | 5 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 // Reset the cursor. | 33 // Reset the cursor. |
34 UnsetCursor(); | 34 UnsetCursor(); |
35 UnbindSurfaceFromController(); | 35 UnbindSurfaceFromController(); |
36 } | 36 } |
37 | 37 |
38 bool | 38 bool |
39 HardwareDisplayController::BindSurfaceToController( | 39 HardwareDisplayController::BindSurfaceToController( |
40 scoped_ptr<DriSurface> surface, drmModeModeInfo mode) { | 40 scoped_ptr<DriSurface> surface, drmModeModeInfo mode) { |
41 CHECK(surface); | 41 CHECK(surface); |
42 | 42 |
43 if (!RegisterFramebuffers(surface.get(), mode)) | |
44 return false; | |
45 | |
46 if (!drm_->SetCrtc(crtc_id_, | 43 if (!drm_->SetCrtc(crtc_id_, |
47 surface->GetFramebufferId(), | 44 surface->GetFramebufferId(), |
48 &connector_id_, | 45 &connector_id_, |
49 &mode)) { | 46 &mode)) { |
50 LOG(ERROR) << "Failed to modeset: crtc=" << crtc_id_ << " connector=" | 47 LOG(ERROR) << "Failed to modeset: crtc=" << crtc_id_ << " connector=" |
51 << connector_id_ << " framebuffer_id=" | 48 << connector_id_ << " framebuffer_id=" |
52 << surface->GetFramebufferId(); | 49 << surface->GetFramebufferId(); |
53 return false; | 50 return false; |
54 } | 51 } |
55 | 52 |
56 surface_.reset(surface.release()); | 53 surface_.reset(surface.release()); |
57 mode_ = mode; | 54 mode_ = mode; |
58 return true; | 55 return true; |
59 } | 56 } |
60 | 57 |
61 void HardwareDisplayController::UnbindSurfaceFromController() { | 58 void HardwareDisplayController::UnbindSurfaceFromController() { |
62 if (surface_) | |
63 UnregisterFramebuffers(surface_.get()); | |
64 surface_.reset(); | 59 surface_.reset(); |
65 } | 60 } |
66 | 61 |
67 bool HardwareDisplayController::SchedulePageFlip() { | 62 bool HardwareDisplayController::SchedulePageFlip() { |
68 CHECK(surface_); | 63 CHECK(surface_); |
69 | 64 |
70 if (!drm_->PageFlip(crtc_id_, | 65 if (!drm_->PageFlip(crtc_id_, |
71 surface_->GetFramebufferId(), | 66 surface_->GetFramebufferId(), |
72 this)) { | 67 this)) { |
73 LOG(ERROR) << "Cannot page flip: " << strerror(errno); | 68 LOG(ERROR) << "Cannot page flip: " << strerror(errno); |
(...skipping 23 matching lines...) Expand all Loading... |
97 } | 92 } |
98 | 93 |
99 bool HardwareDisplayController::UnsetCursor() { | 94 bool HardwareDisplayController::UnsetCursor() { |
100 return drm_->SetCursor(crtc_id_, 0, 0, 0); | 95 return drm_->SetCursor(crtc_id_, 0, 0, 0); |
101 } | 96 } |
102 | 97 |
103 bool HardwareDisplayController::MoveCursor(const gfx::Point& location) { | 98 bool HardwareDisplayController::MoveCursor(const gfx::Point& location) { |
104 return drm_->MoveCursor(crtc_id_, location.x(), location.y()); | 99 return drm_->MoveCursor(crtc_id_, location.x(), location.y()); |
105 } | 100 } |
106 | 101 |
107 bool HardwareDisplayController::RegisterFramebuffers(DriSurface* surface, | |
108 drmModeModeInfo mode) { | |
109 // Register the buffers. | |
110 for (size_t i = 0; i < arraysize(surface->bitmaps_); ++i) { | |
111 uint32_t fb_id; | |
112 if (!drm_->AddFramebuffer( | |
113 mode, | |
114 surface->bitmaps_[i]->GetColorDepth(), | |
115 surface->bitmaps_[i]->canvas()->imageInfo().bytesPerPixel() << 3, | |
116 surface->bitmaps_[i]->stride(), | |
117 surface->bitmaps_[i]->handle(), | |
118 &fb_id)) { | |
119 DLOG(ERROR) << "Failed to register framebuffer: " << strerror(errno); | |
120 return false; | |
121 } | |
122 surface->bitmaps_[i]->set_framebuffer(fb_id); | |
123 } | |
124 | |
125 return true; | |
126 } | |
127 | |
128 void HardwareDisplayController::UnregisterFramebuffers(DriSurface* surface) { | |
129 // Unregister the buffers. | |
130 for (size_t i = 0; i < arraysize(surface->bitmaps_); ++i) { | |
131 if (!drm_->RemoveFramebuffer(surface->bitmaps_[i]->framebuffer())) | |
132 DLOG(ERROR) << "Failed to remove FB: " << strerror(errno); | |
133 } | |
134 } | |
135 | |
136 } // namespace ui | 102 } // namespace ui |
OLD | NEW |