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