Index: ui/ozone/platform/drm/host/drm_overlay_candidates_host.cc |
diff --git a/ui/ozone/platform/drm/host/drm_overlay_candidates_host.cc b/ui/ozone/platform/drm/host/drm_overlay_candidates_host.cc |
index 9957af22e0633d5723845502f1d3450163afd9d3..5b054bbfa7eb131214ce4a730662ddb78519c1db 100644 |
--- a/ui/ozone/platform/drm/host/drm_overlay_candidates_host.cc |
+++ b/ui/ozone/platform/drm/host/drm_overlay_candidates_host.cc |
@@ -43,13 +43,6 @@ bool DrmOverlayCandidatesHost::OverlayCompare::operator()( |
return l.buffer_size.height() < r.buffer_size.height(); |
} |
-DrmOverlayCandidatesHost::HardwareDisplayPlaneProxy::HardwareDisplayPlaneProxy( |
- uint32_t id) |
- : plane_id(id) {} |
- |
-DrmOverlayCandidatesHost::HardwareDisplayPlaneProxy:: |
- ~HardwareDisplayPlaneProxy() {} |
- |
DrmOverlayCandidatesHost::DrmOverlayCandidatesHost( |
DrmGpuPlatformSupportHost* platform_support, |
DrmWindowHost* window) |
@@ -67,32 +60,31 @@ DrmOverlayCandidatesHost::~DrmOverlayCandidatesHost() { |
void DrmOverlayCandidatesHost::CheckOverlaySupport( |
OverlaySurfaceCandidateList* candidates) { |
- uint32_t compatible_candidates = 0; |
- uint32_t planes_in_use = 0; |
- bool force_validation = false; |
- std::vector<OverlayCheck_Params> new_candidates; |
+ bool validate_params = false; |
for (auto& candidate : *candidates) { |
if (!CanHandleCandidate(candidate)) |
continue; |
+ if (candidate.plane_z_order == 0) |
+ candidate.buffer_size = window_->GetBounds().size(); |
+ |
+ // TODO(kalyank): We should get correct storage format used for Video from |
+ // GPU process. |
+ if (candidate.format == gfx::BufferFormat::BGRA_8888) |
+ candidate.format = gfx::BufferFormat::BGRX_8888; |
+ |
OverlayCheck_Params lookup(candidate); |
- if (!force_validation) { |
- CompatibleParams::const_iterator last_iter = |
- in_use_compatible_params_.find(lookup); |
- if (last_iter != in_use_compatible_params_.end()) { |
- candidate.overlay_handled = last_iter->second; |
- compatible_candidates++; |
- if (candidate.overlay_handled) |
- planes_in_use++; |
- |
- continue; |
- } |
+ |
+ std::vector<OverlayCheck_Params>::iterator it; |
+ it = std::find(in_use_params_.begin(), in_use_params_.end(), lookup); |
+ if (it != in_use_params_.end()) { |
+ candidate.overlay_handled = it->state == OverlayCheck_Params::kOverlay; |
+ continue; |
} |
- auto iter = cache_.Get(lookup); |
+ auto iter = cache_.Peek(lookup); |
if (iter == cache_.end()) { |
lookup.weight = CalculateCandidateWeight(candidate); |
- cache_.Put(lookup, false); |
// It is possible that the cc rect we get actually falls off the edge of |
// the screen. Usually this is prevented via things like status bars |
// blocking overlaying or cc clipping it, but in case it wasn't properly |
@@ -100,37 +92,20 @@ void DrmOverlayCandidatesHost::CheckOverlaySupport( |
// This should be an extremely rare occurrance. |
if (lookup.plane_z_order != 0 && |
!window_->GetBounds().Contains(lookup.display_rect)) { |
- continue; |
+ lookup.state = OverlayCheck_Params::kInvalid; |
+ } else { |
+ lookup.state = OverlayCheck_Params::kTest; |
+ validate_params = true; |
} |
- new_candidates.push_back(lookup); |
- } else if (iter->second) { |
- force_validation = true; |
+ cache_.Put(lookup, lookup.state); |
+ } else if (iter->second == OverlayCheck_Params::kCompatible) { |
+ validate_params = true; |
} |
} |
- // We have new candidates whose configuration needs to be validated in GPU |
- // side. |
- if (!new_candidates.empty()) |
- SendRequest(new_candidates); |
- |
- if (compatible_candidates > planes_in_use && |
- planes_in_use < hardware_plane_proxy_.size()) { |
- force_validation = true; |
- } |
- |
- if (!force_validation) { |
- DCHECK(planes_in_use <= hardware_plane_proxy_.size()) |
- << "Total layers promoted to use Overlay:" << planes_in_use |
- << "While the maximum layers which can be actually supported are:" |
- << hardware_plane_proxy_.size(); |
- return; |
- } |
- |
- // A new layer has been added or removed from the last validation. We expect |
- // this to be very rare situation, hence not fully optimized. We always |
- // validate the new combination of layers. |
- ValidateCandidates(candidates); |
+ if (validate_params) |
+ ValidateCandidates(*candidates); |
} |
void DrmOverlayCandidatesHost::OnChannelEstablished( |
@@ -155,17 +130,17 @@ bool DrmOverlayCandidatesHost::OnMessageReceived(const IPC::Message& message) { |
void DrmOverlayCandidatesHost::ResetCache() { |
cache_.Clear(); |
- in_use_compatible_params_.clear(); |
- hardware_plane_proxy_.clear(); |
+ in_use_params_.clear(); |
} |
void DrmOverlayCandidatesHost::SendRequest( |
- const std::vector<OverlayCheck_Params>& list) { |
+ const std::vector<OverlayCheck_Params>& current_list, |
+ const std::vector<OverlayCheck_Params>& new_list) { |
if (!platform_support_->IsConnected()) |
return; |
platform_support_->Send(new OzoneGpuMsg_CheckOverlayCapabilities( |
- window_->GetAcceleratedWidget(), list)); |
+ window_->GetAcceleratedWidget(), current_list, new_list)); |
} |
void DrmOverlayCandidatesHost::OnOverlayResult( |
@@ -176,23 +151,18 @@ void DrmOverlayCandidatesHost::OnOverlayResult( |
return; |
*handled = true; |
- for (const auto& check : params) { |
- // We expect params to contain only supported configurations. |
- cache_.Put(check, true); |
- for (const auto& plane_id : check.plane_ids) { |
- bool plane_found = false; |
- for (const auto* plane : hardware_plane_proxy_) { |
- if (plane->plane_id == plane_id) { |
- plane_found = true; |
- break; |
- } |
- } |
+ for (const auto& compatible_param : in_use_params_) { |
+ OverlayCheck_Params param = compatible_param; |
+ if (param.state == OverlayCheck_Params::kOverlay) |
+ param.state = OverlayCheck_Params::kCompatible; |
- if (!plane_found) { |
- hardware_plane_proxy_.push_back( |
- make_scoped_ptr(new HardwareDisplayPlaneProxy(plane_id))); |
- } |
- } |
+ cache_.Put(param, OverlayCheck_Params::kCompatible); |
+ } |
+ |
+ in_use_params_.clear(); |
+ for (const auto& check : params) { |
+ in_use_params_.push_back(check); |
+ cache_.Put(check, OverlayCheck_Params::kCompatible); |
} |
} |
@@ -240,71 +210,37 @@ uint32_t DrmOverlayCandidatesHost::CalculateCandidateWeight( |
} |
void DrmOverlayCandidatesHost::ValidateCandidates( |
- OverlaySurfaceCandidateList* candidates) { |
- // Make sure params being currently used are in cache. They might have been |
- // removed in case we haven't tried to get them from cache for a while. |
- for (const auto& param : in_use_compatible_params_) |
- cache_.Put(param.first, true); |
- |
- in_use_compatible_params_.clear(); |
- typedef std::pair<OverlaySurfaceCandidate*, OverlayCheck_Params> |
- CandidatePair; |
- std::vector<CandidatePair> compatible_candidates; |
- for (auto& candidate : *candidates) { |
- candidate.overlay_handled = false; |
+ const OverlaySurfaceCandidateList& candidates) { |
+ std::vector<OverlayCheck_Params> current_overlay_params; |
+ std::vector<OverlayCheck_Params> new_params; |
+ for (const auto& param : in_use_params_) { |
+ if (param.state == OverlayCheck_Params::kOverlay) |
+ current_overlay_params.push_back(param); |
+ |
+ // Make sure params being currently used are in cache. They might have |
+ // been removed in case we haven't tried to get them from cache for a |
+ // while. |
+ cache_.Put(param, OverlayCheck_Params::kCompatible); |
+ } |
+ for (const auto& candidate : candidates) { |
if (!CanHandleCandidate(candidate)) |
continue; |
OverlayCheck_Params lookup(candidate); |
- auto iter = cache_.Peek(lookup); |
+ auto iter = cache_.Get(lookup); |
DCHECK(iter != cache_.end()); |
- if (!iter->second) |
- continue; |
- |
- in_use_compatible_params_[iter->first] = false; |
- compatible_candidates.push_back(std::make_pair(&candidate, iter->first)); |
+ if (iter->second != OverlayCheck_Params::kInvalid) |
+ new_params.push_back(lookup); |
} |
- uint32_t available_overlays = hardware_plane_proxy_.size(); |
- for (auto* plane : hardware_plane_proxy_) |
- plane->in_use = false; |
- |
// Sort in decending order w.r.t weight. |
- std::sort(compatible_candidates.begin(), compatible_candidates.end(), |
- [](const CandidatePair& l, const CandidatePair& r) { |
- return l.second.weight > r.second.weight; |
+ std::sort(new_params.begin(), new_params.end(), |
+ [](const OverlayCheck_Params& l, const OverlayCheck_Params& r) { |
+ return l.weight > r.weight; |
}); |
- // Make sure we don't handle more candidates than what we can support in |
- // GPU side. |
- for (const auto& candidate : compatible_candidates) { |
- for (auto* plane : hardware_plane_proxy_) { |
- // Plane is already in use. |
- if (plane->in_use) |
- continue; |
- |
- for (const auto& plane_id : candidate.second.plane_ids) { |
- if (plane->plane_id == plane_id) { |
- available_overlays--; |
- auto iter = in_use_compatible_params_.find(candidate.second); |
- DCHECK(iter != in_use_compatible_params_.end()); |
- iter->second = true; |
- candidate.first->overlay_handled = true; |
- plane->in_use = true; |
- break; |
- } |
- } |
- |
- // We have succefully found a plane. |
- if (plane->in_use) |
- break; |
- } |
- |
- // We dont have any free hardware resources. |
- if (!available_overlays) |
- break; |
- } |
+ SendRequest(current_overlay_params, new_params); |
} |
} // namespace ui |