OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ui/ozone/platform/drm/host/drm_overlay_candidates_host.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 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" |
| 12 |
| 13 namespace ui { |
| 14 |
| 15 namespace { |
| 16 const size_t kMaxCacheSize = 100; |
| 17 } // namespace |
| 18 |
| 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) |
| 23 return true; |
| 24 if (l.plane_z_order > r.plane_z_order) |
| 25 return false; |
| 26 if (l.display_rect < r.display_rect) |
| 27 return true; |
| 28 if (l.display_rect != r.display_rect) |
| 29 return false; |
| 30 if (l.format < r.format) |
| 31 return true; |
| 32 if (l.format > r.format) |
| 33 return false; |
| 34 if (l.transform < r.transform) |
| 35 return true; |
| 36 if (l.transform > r.transform) |
| 37 return false; |
| 38 if (l.buffer_size.width() < r.buffer_size.width()) |
| 39 return true; |
| 40 if (l.buffer_size.width() > r.buffer_size.width()) |
| 41 return false; |
| 42 return l.buffer_size.height() < r.buffer_size.height(); |
| 43 } |
| 44 |
| 45 DrmOverlayCandidatesHost::DrmOverlayCandidatesHost( |
| 46 gfx::AcceleratedWidget widget, |
| 47 DrmGpuPlatformSupportHost* platform_support) |
| 48 : widget_(widget), |
| 49 platform_support_(platform_support), |
| 50 cache_(kMaxCacheSize) { |
| 51 platform_support_->RegisterHandler(this); |
| 52 } |
| 53 |
| 54 DrmOverlayCandidatesHost::~DrmOverlayCandidatesHost() { |
| 55 platform_support_->UnregisterHandler(this); |
| 56 } |
| 57 |
| 58 void DrmOverlayCandidatesHost::CheckOverlaySupport( |
| 59 OverlaySurfaceCandidateList* candidates) { |
| 60 if (candidates->size() == 2) |
| 61 CheckSingleOverlay(candidates); |
| 62 } |
| 63 |
| 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) { |
| 70 overlay = second; |
| 71 } else if (second->plane_z_order == 0) { |
| 72 overlay = first; |
| 73 } else { |
| 74 return; |
| 75 } |
| 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)) |
| 79 return; |
| 80 if (overlay->transform == gfx::OVERLAY_TRANSFORM_INVALID) |
| 81 return; |
| 82 |
| 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); |
| 88 } else { |
| 89 overlay->overlay_handled = iter->second; |
| 90 } |
| 91 } |
| 92 |
| 93 void DrmOverlayCandidatesHost::OnChannelEstablished( |
| 94 int host_id, |
| 95 scoped_refptr<base::SingleThreadTaskRunner> send_runner, |
| 96 const base::Callback<void(IPC::Message*)>& sender) { |
| 97 } |
| 98 |
| 99 void DrmOverlayCandidatesHost::OnChannelDestroyed(int host_id) { |
| 100 } |
| 101 |
| 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() |
| 108 return handled; |
| 109 } |
| 110 |
| 111 void DrmOverlayCandidatesHost::SendRequest( |
| 112 const OverlaySurfaceCandidateList& candidates, |
| 113 const OverlayCheck_Params& check) { |
| 114 if (!platform_support_->IsConnected()) |
| 115 return; |
| 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)); |
| 122 } |
| 123 |
| 124 void DrmOverlayCandidatesHost::OnOverlayResult(bool* handled, |
| 125 gfx::AcceleratedWidget widget, |
| 126 bool result) { |
| 127 if (widget != widget_) |
| 128 return; |
| 129 *handled = true; |
| 130 DCHECK(!pending_checks_.empty()); |
| 131 ProcessResult(pending_checks_.front(), result); |
| 132 pending_checks_.pop_front(); |
| 133 } |
| 134 |
| 135 void DrmOverlayCandidatesHost::ProcessResult(const OverlayCheck_Params& check, |
| 136 bool result) { |
| 137 if (result) |
| 138 cache_.Put(check, true); |
| 139 } |
| 140 |
| 141 } // namespace ui |
OLD | NEW |