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"
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"
17 void AtomicPageFlipCallback(std::vector
<base::WeakPtr
<CrtcController
>> crtcs
,
20 unsigned int useconds
) {
21 for (auto& crtc
: crtcs
) {
22 auto* crtc_ptr
= crtc
.get();
24 crtc_ptr
->OnPageFlipEvent(frame
, seconds
, useconds
);
30 HardwareDisplayPlaneManagerAtomic::HardwareDisplayPlaneManagerAtomic() {
33 HardwareDisplayPlaneManagerAtomic::~HardwareDisplayPlaneManagerAtomic() {
36 bool HardwareDisplayPlaneManagerAtomic::Commit(
37 HardwareDisplayPlaneList
* plane_list
,
39 for (HardwareDisplayPlane
* plane
: plane_list
->old_plane_list
) {
41 std::find(plane_list
->plane_list
.begin(), plane_list
->plane_list
.end(),
42 plane
) != plane_list
->plane_list
.end();
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());
62 for (HardwareDisplayPlane
* plane
: plane_list
->plane_list
) {
63 plane
->set_in_use(false);
66 plane_list
->plane_list
.swap(plane_list
->old_plane_list
);
68 plane_list
->plane_list
.clear();
72 flags
= DRM_MODE_ATOMIC_TEST_ONLY
;
74 flags
= DRM_MODE_PAGE_FLIP_EVENT
| DRM_MODE_ATOMIC_NONBLOCK
;
77 if (!drm_
->CommitProperties(plane_list
->atomic_property_set
.get(), flags
,
79 base::Bind(&AtomicPageFlipCallback
, crtcs
))) {
80 PLOG(ERROR
) << "Failed to commit properties";
83 plane_list
->atomic_property_set
.reset(drmModeAtomicAlloc());
87 bool HardwareDisplayPlaneManagerAtomic::SetPlaneData(
88 HardwareDisplayPlaneList
* plane_list
,
89 HardwareDisplayPlane
* hw_plane
,
90 const OverlayPlane
& overlay
,
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";
102 atomic_plane
->set_crtc(crtc
);
106 scoped_ptr
<HardwareDisplayPlane
> HardwareDisplayPlaneManagerAtomic::CreatePlane(
108 uint32_t possible_crtcs
) {
109 return scoped_ptr
<HardwareDisplayPlane
>(
110 new HardwareDisplayPlaneAtomic(plane_id
, possible_crtcs
));