Index: ui/ozone/platform/drm/host/drm_host_overlay_candidates.cc |
diff --git a/ui/ozone/platform/drm/host/drm_host_overlay_candidates.cc b/ui/ozone/platform/drm/host/drm_host_overlay_candidates.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a54bdf95deaa83393751eac60e073fa5292108e2 |
--- /dev/null |
+++ b/ui/ozone/platform/drm/host/drm_host_overlay_candidates.cc |
@@ -0,0 +1,127 @@ |
+#include "ui/ozone/platform/drm/host/drm_host_overlay_candidates.h" |
+ |
+#include <algorithm> |
+ |
+#include "ui/gfx/geometry/rect_conversions.h" |
+#include "ui/ozone/common/gpu/ozone_gpu_messages.h" |
+#include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h" |
+ |
+namespace ui { |
+ |
+namespace { |
+const size_t kMaxCacheSize = 10000; |
+} // namespace |
+ |
+bool DrmHostOverlayCandidates::OverlayCompare::operator()( |
+ const OverlayCheck_Params& l, |
+ const OverlayCheck_Params& r) { |
+ return l.plane_z_order < r.plane_z_order || |
+ (l.plane_z_order == r.plane_z_order && |
+ (l.display_rect < r.display_rect || |
+ (l.display_rect == r.display_rect && |
+ (l.format < r.format || |
+ (l.format == r.format && |
+ (l.transform < r.transform || |
+ (l.transform == r.transform && |
+ (l.buffer_size.width() < r.buffer_size.width() || |
+ (l.buffer_size.width() == r.buffer_size.width() && |
+ l.buffer_size.height() < r.buffer_size.height()))))))))); |
+} |
+ |
+DrmHostOverlayCandidates::DrmHostOverlayCandidates( |
+ gfx::AcceleratedWidget widget, |
+ DrmGpuPlatformSupportHost* platform_support) |
+ : widget_(widget), platform_support_(platform_support) { |
+ platform_support_->RegisterHandler(this); |
+} |
+ |
+DrmHostOverlayCandidates::~DrmHostOverlayCandidates() { |
+ platform_support_->UnregisterHandler(this); |
+} |
+ |
+void DrmHostOverlayCandidates::CheckOverlaySupport( |
+ OverlaySurfaceCandidateList* candidates) { |
+ if (candidates->size() == 2) |
+ CheckSingleOverlay(candidates); |
+} |
+ |
+void DrmHostOverlayCandidates::CheckSingleOverlay( |
+ OverlaySurfaceCandidateList* candidates) { |
+ OverlayCandidatesOzone::OverlaySurfaceCandidate* first = &(*candidates)[0]; |
+ OverlayCandidatesOzone::OverlaySurfaceCandidate* second = &(*candidates)[1]; |
+ OverlayCandidatesOzone::OverlaySurfaceCandidate* overlay; |
+ if (first->plane_z_order == 0) { |
+ overlay = second; |
+ } else if (second->plane_z_order == 0) { |
+ overlay = first; |
+ } else { |
+ return; |
+ } |
+ // 0.01 constant chosen to match DCHECKs in gfx::ToNearestRect and avoid |
+ // that code asserting on quads that we accept. |
+ if (!gfx::IsNearestRectWithinDistance(overlay->display_rect, 0.01f)) |
+ return; |
+ if (overlay->transform == gfx::OVERLAY_TRANSFORM_INVALID) |
+ return; |
+ |
+ OverlayCheck_Params lookup(*overlay); |
+ auto iter = cache_.find(lookup); |
+ if (iter == cache_.end()) { |
+ if (cache_.size() > kMaxCacheSize) |
+ cache_.clear(); |
+ cache_[lookup] = false; |
+ SendRequest(*candidates, lookup); |
+ } else { |
+ overlay->overlay_handled = iter->second; |
+ } |
+} |
+ |
+void DrmHostOverlayCandidates::OnChannelEstablished( |
+ int host_id, |
+ scoped_refptr<base::SingleThreadTaskRunner> send_runner, |
+ const base::Callback<void(IPC::Message*)>& sender) { |
+} |
+ |
+void DrmHostOverlayCandidates::OnChannelDestroyed(int host_id) { |
+} |
+ |
+bool DrmHostOverlayCandidates::OnMessageReceived(const IPC::Message& message) { |
+ bool handled = false; |
+ IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(DrmHostOverlayCandidates, message, &handled) |
+ IPC_MESSAGE_FORWARD(OzoneHostMsg_OverlayCapabilitiesReceived, this, |
+ DrmHostOverlayCandidates::OnOverlayResult) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+void DrmHostOverlayCandidates::SendRequest( |
+ const OverlaySurfaceCandidateList& candidates, |
+ const OverlayCheck_Params& check) { |
+ if (!platform_support_->IsConnected()) |
+ return; |
+ pending_checks_.push_back(check); |
+ std::vector<OverlayCheck_Params> list; |
+ for (const auto& candidate : candidates) |
+ list.push_back(OverlayCheck_Params(candidate)); |
+ platform_support_->Send( |
+ new OzoneGpuMsg_CheckOverlayCapabilities(widget_, list)); |
+} |
+ |
+void DrmHostOverlayCandidates::OnOverlayResult(bool* handled, |
+ gfx::AcceleratedWidget widget, |
+ bool result) { |
+ if (widget != widget_) |
+ return; |
+ *handled = true; |
+ DCHECK(!pending_checks_.empty()); |
+ ProcessResult(pending_checks_.front(), result); |
+ pending_checks_.pop_front(); |
+} |
+ |
+void DrmHostOverlayCandidates::ProcessResult(const OverlayCheck_Params& check, |
+ bool result) { |
+ if (result) |
+ cache_[check] = true; |
+} |
+ |
+} // namespace ui |