1 // Copyright 2015 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/host/drm_overlay_candidates_host.h"
9 #include "ui/gfx/geometry/rect_conversions.h"
10 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
11 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h"
16 const size_t kMaxCacheSize
= 100;
19 bool DrmOverlayCandidatesHost::OverlayCompare::operator()(
20 const OverlayCheck_Params
& l
,
21 const OverlayCheck_Params
& r
) {
22 if (l
.plane_z_order
< r
.plane_z_order
)
24 if (l
.plane_z_order
> r
.plane_z_order
)
26 if (l
.display_rect
< r
.display_rect
)
28 if (l
.display_rect
!= r
.display_rect
)
30 if (l
.format
< r
.format
)
32 if (l
.format
> r
.format
)
34 if (l
.transform
< r
.transform
)
36 if (l
.transform
> r
.transform
)
38 if (l
.buffer_size
.width() < r
.buffer_size
.width())
40 if (l
.buffer_size
.width() > r
.buffer_size
.width())
42 return l
.buffer_size
.height() < r
.buffer_size
.height();
45 DrmOverlayCandidatesHost::DrmOverlayCandidatesHost(
46 gfx::AcceleratedWidget widget
,
47 DrmGpuPlatformSupportHost
* platform_support
)
49 platform_support_(platform_support
),
50 cache_(kMaxCacheSize
) {
51 platform_support_
->RegisterHandler(this);
54 DrmOverlayCandidatesHost::~DrmOverlayCandidatesHost() {
55 platform_support_
->UnregisterHandler(this);
58 void DrmOverlayCandidatesHost::CheckOverlaySupport(
59 OverlaySurfaceCandidateList
* candidates
) {
60 if (candidates
->size() == 2)
61 CheckSingleOverlay(candidates
);
64 void DrmOverlayCandidatesHost::CheckSingleOverlay(
65 OverlaySurfaceCandidateList
* candidates
) {
66 OverlayCandidatesOzone::OverlaySurfaceCandidate
* first
= &(*candidates
)[0];
67 OverlayCandidatesOzone::OverlaySurfaceCandidate
* second
= &(*candidates
)[1];
68 OverlayCandidatesOzone::OverlaySurfaceCandidate
* overlay
;
69 if (first
->plane_z_order
== 0) {
71 } else if (second
->plane_z_order
== 0) {
76 // 0.01 constant chosen to match DCHECKs in gfx::ToNearestRect and avoid
77 // that code asserting on quads that we accept.
78 if (!gfx::IsNearestRectWithinDistance(overlay
->display_rect
, 0.01f
))
80 if (overlay
->transform
== gfx::OVERLAY_TRANSFORM_INVALID
)
83 OverlayCheck_Params
lookup(*overlay
);
84 auto iter
= cache_
.Get(lookup
);
85 if (iter
== cache_
.end()) {
86 cache_
.Put(lookup
, false);
87 SendRequest(*candidates
, lookup
);
89 overlay
->overlay_handled
= iter
->second
;
93 void DrmOverlayCandidatesHost::OnChannelEstablished(
95 scoped_refptr
<base::SingleThreadTaskRunner
> send_runner
,
96 const base::Callback
<void(IPC::Message
*)>& sender
) {
99 void DrmOverlayCandidatesHost::OnChannelDestroyed(int host_id
) {
102 bool DrmOverlayCandidatesHost::OnMessageReceived(const IPC::Message
& message
) {
103 bool handled
= false;
104 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(DrmOverlayCandidatesHost
, message
, &handled
)
105 IPC_MESSAGE_FORWARD(OzoneHostMsg_OverlayCapabilitiesReceived
, this,
106 DrmOverlayCandidatesHost::OnOverlayResult
)
107 IPC_END_MESSAGE_MAP()
111 void DrmOverlayCandidatesHost::SendRequest(
112 const OverlaySurfaceCandidateList
& candidates
,
113 const OverlayCheck_Params
& check
) {
114 if (!platform_support_
->IsConnected())
116 pending_checks_
.push_back(check
);
117 std::vector
<OverlayCheck_Params
> list
;
118 for (const auto& candidate
: candidates
)
119 list
.push_back(OverlayCheck_Params(candidate
));
120 platform_support_
->Send(
121 new OzoneGpuMsg_CheckOverlayCapabilities(widget_
, list
));
124 void DrmOverlayCandidatesHost::OnOverlayResult(bool* handled
,
125 gfx::AcceleratedWidget widget
,
127 if (widget
!= widget_
)
130 DCHECK(!pending_checks_
.empty());
131 ProcessResult(pending_checks_
.front(), result
);
132 pending_checks_
.pop_front();
135 void DrmOverlayCandidatesHost::ProcessResult(const OverlayCheck_Params
& check
,
138 cache_
.Put(check
, true);