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
)
82 if (overlay
->is_clipped
&&
83 !overlay
->clip_rect
.Contains(overlay
->quad_rect_in_target_space
))
86 OverlayCheck_Params
lookup(*overlay
);
87 auto iter
= cache_
.Get(lookup
);
88 if (iter
== cache_
.end()) {
89 cache_
.Put(lookup
, false);
90 SendRequest(*candidates
, lookup
);
92 overlay
->overlay_handled
= iter
->second
;
96 void DrmOverlayCandidatesHost::OnChannelEstablished(
98 scoped_refptr
<base::SingleThreadTaskRunner
> send_runner
,
99 const base::Callback
<void(IPC::Message
*)>& sender
) {
102 void DrmOverlayCandidatesHost::OnChannelDestroyed(int host_id
) {
105 bool DrmOverlayCandidatesHost::OnMessageReceived(const IPC::Message
& message
) {
106 bool handled
= false;
107 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(DrmOverlayCandidatesHost
, message
, &handled
)
108 IPC_MESSAGE_FORWARD(OzoneHostMsg_OverlayCapabilitiesReceived
, this,
109 DrmOverlayCandidatesHost::OnOverlayResult
)
110 IPC_END_MESSAGE_MAP()
114 void DrmOverlayCandidatesHost::SendRequest(
115 const OverlaySurfaceCandidateList
& candidates
,
116 const OverlayCheck_Params
& check
) {
117 if (!platform_support_
->IsConnected())
119 pending_checks_
.push_back(check
);
120 std::vector
<OverlayCheck_Params
> list
;
121 for (const auto& candidate
: candidates
)
122 list
.push_back(OverlayCheck_Params(candidate
));
123 platform_support_
->Send(
124 new OzoneGpuMsg_CheckOverlayCapabilities(widget_
, list
));
127 void DrmOverlayCandidatesHost::OnOverlayResult(bool* handled
,
128 gfx::AcceleratedWidget widget
,
130 if (widget
!= widget_
)
133 DCHECK(!pending_checks_
.empty());
134 ProcessResult(pending_checks_
.front(), result
);
135 pending_checks_
.pop_front();
138 void DrmOverlayCandidatesHost::ProcessResult(const OverlayCheck_Params
& check
,
141 cache_
.Put(check
, true);