Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(737)

Side by Side Diff: ui/ozone/platform/drm/host/drm_host_overlay_candidates.cc

Issue 1157793004: ozone: Add overlay candidate implementation that queries support via IPC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #include "ui/ozone/platform/drm/host/drm_host_overlay_candidates.h"
2
3 #include <algorithm>
4
5 #include "ui/gfx/geometry/rect_conversions.h"
6 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
7 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h"
8
9 namespace ui {
10
11 namespace {
12 const size_t kMaxCacheSize = 10000;
13 } // namespace
14
15 DrmHostOverlayCandidates::PendingCheck::PendingCheck(
16 uint32_t id,
17 const OverlayCheck_Params& overlay)
18 : request_id(id), overlay(overlay) {
19 }
20 DrmHostOverlayCandidates::PendingCheck::~PendingCheck() {
21 }
22
23 bool DrmHostOverlayCandidates::OverlayCompare::operator()(
24 const OverlayCheck_Params& l,
25 const OverlayCheck_Params& r) {
26 return l.plane_z_order < r.plane_z_order ||
27 (l.plane_z_order == r.plane_z_order &&
28 (l.display_rect < r.display_rect ||
29 (l.display_rect == r.display_rect &&
30 (l.format < r.format ||
31 (l.format == r.format &&
32 (l.transform < r.transform ||
33 (l.transform == r.transform &&
34 (l.buffer_size.width() < r.buffer_size.width() ||
35 (l.buffer_size.width() == r.buffer_size.width() &&
36 l.buffer_size.height() < r.buffer_size.height())))))))));
37 }
38
39 DrmHostOverlayCandidates::DrmHostOverlayCandidates(
40 gfx::AcceleratedWidget widget,
41 DrmGpuPlatformSupportHost* platform_support)
42 : channel_established_(false),
43 next_request_id_(1),
44 widget_(widget),
45 platform_support_(platform_support) {
46 platform_support_->RegisterHandler(this);
47 }
48
49 DrmHostOverlayCandidates::~DrmHostOverlayCandidates() {
50 platform_support_->UnregisterHandler(this);
51 }
52
53 void DrmHostOverlayCandidates::CheckOverlaySupport(
54 OverlaySurfaceCandidateList* candidates) {
55 if (candidates->size() == 2)
56 CheckSingleOverlay(candidates);
57 }
58
59 void DrmHostOverlayCandidates::CheckSingleOverlay(
60 OverlaySurfaceCandidateList* candidates) {
61 OverlayCandidatesOzone::OverlaySurfaceCandidate* first = &(*candidates)[0];
62 OverlayCandidatesOzone::OverlaySurfaceCandidate* second = &(*candidates)[1];
63 OverlayCandidatesOzone::OverlaySurfaceCandidate* overlay;
64 if (first->plane_z_order == 0) {
65 overlay = second;
66 } else if (second->plane_z_order == 0) {
67 overlay = first;
68 } else {
69 return;
70 }
71 // 0.01 constant chosen to match DCHECKs in gfx::ToNearestRect and avoid
72 // that code asserting on quads that we accept.
73 if (!gfx::IsNearestRectWithinDistance(overlay->display_rect, 0.01f))
74 return;
75 if (overlay->transform == gfx::OVERLAY_TRANSFORM_INVALID)
76 return;
77
78 OverlayCheck_Params lookup(*overlay);
79 auto iter = cache_.find(lookup);
80 if (iter == cache_.end()) {
81 if (cache_.size() > kMaxCacheSize)
82 cache_.clear();
83 cache_[lookup] = false;
84 SendRequest(*candidates, PendingCheck(next_request_id_++, lookup));
dnicoara 2015/05/28 21:09:54 The more I read, the clearer it is to me that the
achaulk 2015/05/29 18:49:20 Done.
85 } else {
86 overlay->overlay_handled = iter->second;
87 }
88 }
89
90 void DrmHostOverlayCandidates::OnChannelEstablished(
dnicoara 2015/05/28 21:09:54 Also, you'll want to clear all pending requests if
achaulk 2015/05/29 18:49:20 If the GPU process goes away nothing matters becau
dnicoara 2015/05/29 19:28:23 I thought the compositor for the primary widget ju
achaulk 2015/05/29 19:36:36 No, the OutputSurface at least gets re-created in
91 int host_id,
92 scoped_refptr<base::SingleThreadTaskRunner> send_runner,
93 const base::Callback<void(IPC::Message*)>& sender) {
94 channel_established_ = true;
dnicoara 2015/05/28 21:09:54 You can use DrmGpuPlatformSupportHost::IsConnected
achaulk 2015/05/29 18:49:20 Done.
95 send_callback_ = sender;
96 }
97
98 void DrmHostOverlayCandidates::OnChannelDestroyed(int host_id) {
99 channel_established_ = false;
100 }
101
102 bool DrmHostOverlayCandidates::OnMessageReceived(const IPC::Message& message) {
103 bool handled = false;
104 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(DrmHostOverlayCandidates, message, &handled)
105 IPC_MESSAGE_FORWARD(OzoneHostMsg_OverlayCapabilitiesReceived, this,
106 DrmHostOverlayCandidates::OnOverlayResult)
107 IPC_END_MESSAGE_MAP()
108 return handled;
109 }
110
111 void DrmHostOverlayCandidates::SendRequest(
112 const OverlaySurfaceCandidateList& candidates,
113 const PendingCheck& check) {
114 if (!channel_established_)
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 send_callback_.Run(new OzoneGpuMsg_CheckOverlayCapabilities(
dnicoara 2015/05/28 21:09:54 Should this post taks using the |send_runner|? FY
achaulk 2015/05/29 18:49:20 Done.
121 widget_, check.request_id, list));
122 }
123
124 void DrmHostOverlayCandidates::OnOverlayResult(bool* handled,
125 gfx::AcceleratedWidget widget,
126 uint32_t id,
127 bool result) {
128 if (widget != widget_)
129 return;
130 *handled = true;
131 auto iter =
132 std::find_if(pending_checks_.begin(), pending_checks_.end(),
133 [id](const PendingCheck& l) { return l.request_id == id; });
134 if (iter == pending_checks_.end())
135 return;
136 ProcessResult(*iter, result);
137 pending_checks_.erase(iter);
138 }
139
140 void DrmHostOverlayCandidates::ProcessResult(const PendingCheck& check,
141 bool result) {
142 if (result)
143 cache_[check.overlay] = true;
144 }
145
146 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698