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"
15 static void AtomicPageFlipCallback(
16 std::vector
<base::WeakPtr
<CrtcController
>> crtcs
,
19 unsigned int useconds
) {
20 for (auto& crtc
: crtcs
) {
21 auto* crtc_ptr
= crtc
.get();
23 crtc_ptr
->OnPageFlipEvent(frame
, seconds
, useconds
);
27 HardwareDisplayPlaneManagerAtomic::HardwareDisplayPlaneManagerAtomic() {
30 HardwareDisplayPlaneManagerAtomic::~HardwareDisplayPlaneManagerAtomic() {
33 bool HardwareDisplayPlaneManagerAtomic::Commit(
34 HardwareDisplayPlaneList
* plane_list
,
37 for (HardwareDisplayPlane
* plane
: plane_list
->old_plane_list
) {
39 std::find(plane_list
->plane_list
.begin(), plane_list
->plane_list
.end(),
40 plane
) != plane_list
->plane_list
.end();
42 // This plane is being released, so we need to zero it.
43 plane
->set_in_use(false);
44 HardwareDisplayPlaneAtomic
* atomic_plane
=
45 static_cast<HardwareDisplayPlaneAtomic
*>(plane
);
46 atomic_plane
->SetPlaneData(plane_list
->atomic_property_set
.get(), 0, 0,
47 gfx::Rect(), gfx::Rect());
51 std::vector
<base::WeakPtr
<CrtcController
>> crtcs
;
52 for (HardwareDisplayPlane
* plane
: plane_list
->plane_list
) {
53 HardwareDisplayPlaneAtomic
* atomic_plane
=
54 static_cast<HardwareDisplayPlaneAtomic
*>(plane
);
55 if (crtcs
.empty() || crtcs
.back().get() != atomic_plane
->crtc())
56 crtcs
.push_back(atomic_plane
->crtc()->AsWeakPtr());
60 for (HardwareDisplayPlane
* plane
: plane_list
->plane_list
) {
61 plane
->set_in_use(false);
64 plane_list
->plane_list
.swap(plane_list
->old_plane_list
);
66 plane_list
->plane_list
.clear();
67 if (!drm_
->CommitProperties(plane_list
->atomic_property_set
.get(), 0, is_sync
,
69 base::Bind(&AtomicPageFlipCallback
, crtcs
))) {
70 PLOG(ERROR
) << "Failed to commit properties";
73 plane_list
->atomic_property_set
.reset(drmModePropertySetAlloc());
77 bool HardwareDisplayPlaneManagerAtomic::SetPlaneData(
78 HardwareDisplayPlaneList
* plane_list
,
79 HardwareDisplayPlane
* hw_plane
,
80 const OverlayPlane
& overlay
,
82 const gfx::Rect
& src_rect
,
83 CrtcController
* crtc
) {
84 HardwareDisplayPlaneAtomic
* atomic_plane
=
85 static_cast<HardwareDisplayPlaneAtomic
*>(hw_plane
);
86 if (!atomic_plane
->SetPlaneData(plane_list
->atomic_property_set
.get(),
87 crtc_id
, overlay
.buffer
->GetFramebufferId(),
88 overlay
.display_bounds
, src_rect
)) {
89 LOG(ERROR
) << "Failed to set plane properties";
92 atomic_plane
->set_crtc(crtc
);
96 scoped_ptr
<HardwareDisplayPlane
> HardwareDisplayPlaneManagerAtomic::CreatePlane(
98 uint32_t possible_crtcs
) {
99 return scoped_ptr
<HardwareDisplayPlane
>(
100 new HardwareDisplayPlaneAtomic(plane_id
, possible_crtcs
));