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_plane_manager_legacy.h" | 5 #include "ui/ozone/platform/dri/hardware_display_plane_manager_legacy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "ui/ozone/platform/dri/crtc_controller.h" | 8 #include "ui/ozone/platform/dri/crtc_controller.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/scanout_buffer.h" | 10 #include "ui/ozone/platform/dri/scanout_buffer.h" |
11 | 11 |
12 namespace ui { | 12 namespace ui { |
13 | 13 |
14 HardwareDisplayPlaneManagerLegacy::HardwareDisplayPlaneManagerLegacy() { | 14 HardwareDisplayPlaneManagerLegacy::HardwareDisplayPlaneManagerLegacy() { |
15 } | 15 } |
16 | 16 |
17 HardwareDisplayPlaneManagerLegacy::~HardwareDisplayPlaneManagerLegacy() { | 17 HardwareDisplayPlaneManagerLegacy::~HardwareDisplayPlaneManagerLegacy() { |
18 } | 18 } |
19 | 19 |
20 bool HardwareDisplayPlaneManagerLegacy::Commit( | 20 bool HardwareDisplayPlaneManagerLegacy::Commit( |
21 HardwareDisplayPlaneList* plane_list) { | 21 HardwareDisplayPlaneList* plane_list) { |
22 if (plane_list->plane_list.empty()) // No assigned planes, nothing to do. | 22 if (plane_list->plane_list.empty()) // No assigned planes, nothing to do. |
23 return true; | 23 return true; |
24 bool ret = true; | 24 bool ret = true; |
25 plane_list->plane_list.swap(plane_list->old_plane_list); | 25 // The order of operations here (set new planes, pageflip, clear old planes) |
26 plane_list->plane_list.clear(); | 26 // is designed to minimze the chance of a significant artifact occurring. |
| 27 // The planes must be updated first because the main plane no longer contains |
| 28 // their content. The old planes are removed last because the previous primary |
| 29 // plane used them as overlays and thus didn't contain their content, so we |
| 30 // must first flip to the new primary plane, which does. The error here will |
| 31 // be the delta of (new contents, old contents), but it should be barely |
| 32 // noticeable. |
27 for (const auto& flip : plane_list->legacy_page_flips) { | 33 for (const auto& flip : plane_list->legacy_page_flips) { |
28 // Permission Denied is a legitimate error | 34 // Permission Denied is a legitimate error |
| 35 for (const auto& plane : flip.planes) { |
| 36 if (!drm_->PageFlipOverlay(flip.crtc_id, plane.framebuffer, plane.bounds, |
| 37 plane.src_rect, plane.plane)) { |
| 38 LOG(ERROR) << "Cannot display plane on overlay: error=" |
| 39 << strerror(errno) << "crtc=" << flip.crtc |
| 40 << " plane=" << plane.plane; |
| 41 ret = false; |
| 42 flip.crtc->PageFlipFailed(); |
| 43 break; |
| 44 } |
| 45 } |
29 if (!drm_->PageFlip(flip.crtc_id, flip.framebuffer, | 46 if (!drm_->PageFlip(flip.crtc_id, flip.framebuffer, |
30 base::Bind(&CrtcController::OnPageFlipEvent, | 47 base::Bind(&CrtcController::OnPageFlipEvent, |
31 flip.crtc->AsWeakPtr()))) { | 48 flip.crtc->AsWeakPtr()))) { |
32 if (errno != EACCES) { | 49 if (errno != EACCES) { |
33 LOG(ERROR) << "Cannot page flip: error='" << strerror(errno) << "'" | 50 LOG(ERROR) << "Cannot page flip: error='" << strerror(errno) << "'" |
34 << " crtc=" << flip.crtc_id | 51 << " crtc=" << flip.crtc_id |
35 << " framebuffer=" << flip.framebuffer; | 52 << " framebuffer=" << flip.framebuffer; |
36 LOG(ERROR) << "Failed to commit planes"; | 53 LOG(ERROR) << "Failed to commit planes"; |
37 ret = false; | 54 ret = false; |
38 } | 55 } |
39 flip.crtc->PageFlipFailed(); | 56 flip.crtc->PageFlipFailed(); |
40 } else { | 57 } |
41 for (const auto& plane : flip.planes) { | 58 } |
42 if (!drm_->PageFlipOverlay(flip.crtc_id, plane.framebuffer, | 59 // For each element in |old_plane_list|, if it hasn't been reclaimed (by |
43 plane.bounds, plane.src_rect, plane.plane)) { | 60 // this or any other HDPL), clear the overlay contents. |
44 LOG(ERROR) << "Cannot display plane on overlay: error=" | 61 for (HardwareDisplayPlane* plane : plane_list->old_plane_list) { |
45 << strerror(errno); | 62 if (!plane->in_use()) { |
46 ret = false; | 63 // This plane is being released, so we need to zero it. |
47 flip.crtc->PageFlipFailed(); | 64 if (!drm_->PageFlipOverlay(plane->owning_crtc(), 0, gfx::Rect(), |
48 break; | 65 gfx::Rect(), plane->plane_id())) { |
49 } | 66 LOG(ERROR) << "Cannot free overlay: error=" << strerror(errno) |
| 67 << "crtc=" << plane->owning_crtc() |
| 68 << " plane=" << plane->plane_id(); |
| 69 ret = false; |
| 70 break; |
50 } | 71 } |
51 } | 72 } |
52 } | 73 } |
| 74 plane_list->plane_list.swap(plane_list->old_plane_list); |
| 75 plane_list->plane_list.clear(); |
53 plane_list->legacy_page_flips.clear(); | 76 plane_list->legacy_page_flips.clear(); |
| 77 plane_list->committed = true; |
54 return ret; | 78 return ret; |
55 } | 79 } |
56 | 80 |
57 bool HardwareDisplayPlaneManagerLegacy::SetPlaneData( | 81 bool HardwareDisplayPlaneManagerLegacy::SetPlaneData( |
58 HardwareDisplayPlaneList* plane_list, | 82 HardwareDisplayPlaneList* plane_list, |
59 HardwareDisplayPlane* hw_plane, | 83 HardwareDisplayPlane* hw_plane, |
60 const OverlayPlane& overlay, | 84 const OverlayPlane& overlay, |
61 uint32_t crtc_id, | 85 uint32_t crtc_id, |
62 const gfx::Rect& src_rect, | 86 const gfx::Rect& src_rect, |
63 CrtcController* crtc) { | 87 CrtcController* crtc) { |
64 if (plane_list->legacy_page_flips.empty() || | 88 if (plane_list->legacy_page_flips.empty() || |
65 plane_list->legacy_page_flips.back().crtc_id != crtc_id) { | 89 plane_list->legacy_page_flips.back().crtc_id != crtc_id) { |
66 plane_list->legacy_page_flips.push_back( | 90 plane_list->legacy_page_flips.push_back( |
67 HardwareDisplayPlaneList::PageFlipInfo( | 91 HardwareDisplayPlaneList::PageFlipInfo( |
68 crtc_id, overlay.buffer->GetFramebufferId(), hw_plane->plane_id(), | 92 crtc_id, overlay.buffer->GetFramebufferId(), hw_plane->plane_id(), |
69 crtc)); | 93 crtc)); |
70 } else { | 94 } else { |
71 plane_list->legacy_page_flips.back().planes.push_back( | 95 plane_list->legacy_page_flips.back().planes.push_back( |
72 HardwareDisplayPlaneList::PageFlipInfo::Plane( | 96 HardwareDisplayPlaneList::PageFlipInfo::Plane( |
73 hw_plane->plane_id(), overlay.buffer->GetFramebufferId(), | 97 hw_plane->plane_id(), overlay.buffer->GetFramebufferId(), |
74 overlay.display_bounds, src_rect)); | 98 overlay.display_bounds, src_rect)); |
75 } | 99 } |
76 return true; | 100 return true; |
77 } | 101 } |
78 | 102 |
79 } // namespace ui | 103 } // namespace ui |
OLD | NEW |