Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / ozone / platform / drm / gpu / hardware_display_plane_manager_atomic.cc
blobc7b93c990867984510a383f31af8cca7430a6705
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_atomic.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/hardware_display_plane_atomic.h"
11 #include "ui/ozone/platform/drm/gpu/scanout_buffer.h"
13 namespace ui {
15 namespace {
17 void AtomicPageFlipCallback(std::vector<base::WeakPtr<CrtcController>> crtcs,
18 unsigned int frame,
19 unsigned int seconds,
20 unsigned int useconds) {
21 for (auto& crtc : crtcs) {
22 auto* crtc_ptr = crtc.get();
23 if (crtc_ptr)
24 crtc_ptr->OnPageFlipEvent(frame, seconds, useconds);
28 } // namespace
30 HardwareDisplayPlaneManagerAtomic::HardwareDisplayPlaneManagerAtomic() {
33 HardwareDisplayPlaneManagerAtomic::~HardwareDisplayPlaneManagerAtomic() {
36 bool HardwareDisplayPlaneManagerAtomic::Commit(
37 HardwareDisplayPlaneList* plane_list,
38 bool test_only) {
39 for (HardwareDisplayPlane* plane : plane_list->old_plane_list) {
40 bool found =
41 std::find(plane_list->plane_list.begin(), plane_list->plane_list.end(),
42 plane) != plane_list->plane_list.end();
43 if (!found) {
44 // This plane is being released, so we need to zero it.
45 plane->set_in_use(false);
46 HardwareDisplayPlaneAtomic* atomic_plane =
47 static_cast<HardwareDisplayPlaneAtomic*>(plane);
48 atomic_plane->SetPlaneData(plane_list->atomic_property_set.get(), 0, 0,
49 gfx::Rect(), gfx::Rect());
53 std::vector<base::WeakPtr<CrtcController>> crtcs;
54 for (HardwareDisplayPlane* plane : plane_list->plane_list) {
55 HardwareDisplayPlaneAtomic* atomic_plane =
56 static_cast<HardwareDisplayPlaneAtomic*>(plane);
57 if (crtcs.empty() || crtcs.back().get() != atomic_plane->crtc())
58 crtcs.push_back(atomic_plane->crtc()->AsWeakPtr());
61 if (test_only) {
62 for (HardwareDisplayPlane* plane : plane_list->plane_list) {
63 plane->set_in_use(false);
65 } else {
66 plane_list->plane_list.swap(plane_list->old_plane_list);
68 plane_list->plane_list.clear();
70 uint32_t flags = 0;
71 if (test_only) {
72 flags = DRM_MODE_ATOMIC_TEST_ONLY;
73 } else {
74 flags = DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_NONBLOCK;
77 if (!drm_->CommitProperties(plane_list->atomic_property_set.get(), flags,
78 crtcs.size(),
79 base::Bind(&AtomicPageFlipCallback, crtcs))) {
80 PLOG(ERROR) << "Failed to commit properties";
81 return false;
83 plane_list->atomic_property_set.reset(drmModeAtomicAlloc());
84 return true;
87 bool HardwareDisplayPlaneManagerAtomic::SetPlaneData(
88 HardwareDisplayPlaneList* plane_list,
89 HardwareDisplayPlane* hw_plane,
90 const OverlayPlane& overlay,
91 uint32_t crtc_id,
92 const gfx::Rect& src_rect,
93 CrtcController* crtc) {
94 HardwareDisplayPlaneAtomic* atomic_plane =
95 static_cast<HardwareDisplayPlaneAtomic*>(hw_plane);
96 if (!atomic_plane->SetPlaneData(plane_list->atomic_property_set.get(),
97 crtc_id, overlay.buffer->GetFramebufferId(),
98 overlay.display_bounds, src_rect)) {
99 LOG(ERROR) << "Failed to set plane properties";
100 return false;
102 atomic_plane->set_crtc(crtc);
103 return true;
106 scoped_ptr<HardwareDisplayPlane> HardwareDisplayPlaneManagerAtomic::CreatePlane(
107 uint32_t plane_id,
108 uint32_t possible_crtcs) {
109 return scoped_ptr<HardwareDisplayPlane>(
110 new HardwareDisplayPlaneAtomic(plane_id, possible_crtcs));
113 } // namespace ui