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