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

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

Issue 1661783002: Centralize all gbm ozone host IPC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 10 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/ozone/platform/drm/host/drm_overlay_manager.h" 5 #include "ui/ozone/platform/drm/host/drm_overlay_manager.h"
6 6
7 #include <stddef.h>
8
9 #include <algorithm>
10
11 #include "base/command_line.h"
7 #include "ui/gfx/geometry/rect_conversions.h" 12 #include "ui/gfx/geometry/rect_conversions.h"
8 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
9 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h"
10 #include "ui/ozone/platform/drm/host/drm_overlay_candidates_host.h" 13 #include "ui/ozone/platform/drm/host/drm_overlay_candidates_host.h"
11 #include "ui/ozone/platform/drm/host/drm_window_host.h" 14 #include "ui/ozone/platform/drm/host/drm_window_host.h"
12 #include "ui/ozone/platform/drm/host/drm_window_host_manager.h" 15 #include "ui/ozone/platform/drm/host/drm_window_host_manager.h"
13 #include "ui/ozone/public/overlay_candidates_ozone.h" 16 #include "ui/ozone/public/ozone_switches.h"
14 17
15 namespace ui { 18 namespace ui {
16 19
17 DrmOverlayManager::DrmOverlayManager( 20 typedef OverlayCandidatesOzone::OverlaySurfaceCandidateList
18 DrmGpuPlatformSupportHost* platform_support_host, 21 OverlaySurfaceCandidateList;
19 DrmWindowHostManager* window_manager) 22 typedef OverlayCandidatesOzone::OverlaySurfaceCandidate OverlaySurfaceCandidate;
20 : sender_(new OverlayCandidatesIPC(platform_support_host, this)), 23
21 core_(new DrmOverlayManagerCore(sender_.get(), window_manager)) {} 24 namespace {
25 const size_t kMaxCacheSize = 200;
26 } // namespace
27
28 DrmOverlayManager::DrmOverlayManager(GpuThreadAdapter* proxy,
29 DrmWindowHostManager* window_manager)
30 : proxy_(proxy), window_manager_(window_manager), cache_(kMaxCacheSize) {
31 is_supported_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
32 switches::kOzoneTestSingleOverlaySupport);
33 proxy_->RegisterHandlerForDrmOverlayManager(this);
34 }
22 35
23 DrmOverlayManager::~DrmOverlayManager() { 36 DrmOverlayManager::~DrmOverlayManager() {
37 proxy_->UnRegisterHandlerForDrmOverlayManager();
24 } 38 }
25 39
26 scoped_ptr<OverlayCandidatesOzone> DrmOverlayManager::CreateOverlayCandidates( 40 scoped_ptr<OverlayCandidatesOzone> DrmOverlayManager::CreateOverlayCandidates(
27 gfx::AcceleratedWidget w) { 41 gfx::AcceleratedWidget w) {
28 return core_->CreateOverlayCandidates(w); 42 if (!is_supported_)
43 return nullptr;
44 return make_scoped_ptr(new DrmOverlayCandidatesHost(this, w));
29 } 45 }
30 46
31 void DrmOverlayManager::OnChannelEstablished( 47 void DrmOverlayManager::CheckOverlaySupport(
32 int host_id, 48 OverlayCandidatesOzone::OverlaySurfaceCandidateList* candidates,
33 scoped_refptr<base::SingleThreadTaskRunner> send_runner, 49 gfx::AcceleratedWidget widget) {
34 const base::Callback<void(IPC::Message*)>& sender) { 50 std::vector<OverlayCheck_Params> overlay_params;
35 core_->ResetCache(); 51 for (auto& candidate : *candidates) {
36 } 52 // Reject candidates that don't fall on a pixel boundary.
53 if (!gfx::IsNearestRectWithinDistance(candidate.display_rect, 0.01f)) {
54 DCHECK(candidate.plane_z_order != 0);
55 overlay_params.push_back(OverlayCheck_Params());
56 overlay_params.back().is_overlay_candidate = false;
57 continue;
58 }
37 59
38 void DrmOverlayManager::OnChannelDestroyed(int host_id) {} 60 // Compositor doesn't have information about the total size of primary
61 // candidate. We get this information from display rect.
62 if (candidate.plane_z_order == 0)
63 candidate.buffer_size = gfx::ToNearestRect(candidate.display_rect).size();
39 64
40 bool DrmOverlayManager::OnMessageReceived(const IPC::Message& message) { 65 overlay_params.push_back(OverlayCheck_Params(candidate));
41 bool handled = true; 66 }
42 IPC_BEGIN_MESSAGE_MAP(DrmOverlayManager, message) 67
43 IPC_MESSAGE_HANDLER(OzoneHostMsg_OverlayCapabilitiesReceived, 68 const auto& iter = cache_.Get(overlay_params);
44 OnOverlayResult) 69 // We are still waiting on results for this candidate list from GPU.
45 IPC_MESSAGE_UNHANDLED(handled = false) 70 if (iter != cache_.end() && iter->second)
46 IPC_END_MESSAGE_MAP() 71 return;
47 return handled; 72
73 size_t size = candidates->size();
74
75 if (iter == cache_.end()) {
76 // We can skip GPU side validation in case all candidates are invalid.
77 bool needs_gpu_validation = false;
78 for (size_t i = 0; i < size; i++) {
79 if (!overlay_params.at(i).is_overlay_candidate)
80 continue;
81
82 const OverlaySurfaceCandidate& candidate = candidates->at(i);
83 if (!CanHandleCandidate(candidate, widget)) {
84 DCHECK(candidate.plane_z_order != 0);
85 overlay_params.at(i).is_overlay_candidate = false;
86 continue;
87 }
88
89 needs_gpu_validation = true;
90 }
91
92 cache_.Put(overlay_params, needs_gpu_validation);
93
94 if (needs_gpu_validation)
95 SendOverlayValidationRequest(overlay_params, widget);
96 } else {
97 const std::vector<OverlayCheck_Params>& validated_params = iter->first;
98 DCHECK(size == validated_params.size());
99
100 for (size_t i = 0; i < size; i++) {
101 candidates->at(i).overlay_handled =
102 validated_params.at(i).is_overlay_candidate;
103 }
104 }
48 } 105 }
49 106
50 void DrmOverlayManager::ResetCache() { 107 void DrmOverlayManager::ResetCache() {
51 core_->ResetCache(); 108 cache_.Clear();
52 } 109 }
53 110
54 void DrmOverlayManager::OnOverlayResult( 111 void DrmOverlayManager::SendOverlayValidationRequest(
112 const std::vector<OverlayCheck_Params>& new_params,
113 gfx::AcceleratedWidget widget) const {
114 if (!proxy_->IsConnected())
115 return;
116
117 proxy_->GpuCheckOverlayCapabilities(widget, new_params);
118 }
119
120 void DrmOverlayManager::GpuSentOverlayResult(
55 gfx::AcceleratedWidget widget, 121 gfx::AcceleratedWidget widget,
56 const std::vector<OverlayCheck_Params>& params) { 122 const std::vector<OverlayCheck_Params>& params) {
57 core_->GpuSentOverlayResult(widget, params); 123 cache_.Put(params, false);
58 } 124 }
59 125
60 // TODO(rjkroege): There is a refactoring opportunity in the sender pattern. 126 bool DrmOverlayManager::CanHandleCandidate(
61 DrmOverlayManager::OverlayCandidatesIPC::OverlayCandidatesIPC( 127 const OverlaySurfaceCandidate& candidate,
62 DrmGpuPlatformSupportHost* platform_support, 128 gfx::AcceleratedWidget widget) const {
63 DrmOverlayManager* parent) 129 if (candidate.buffer_size.IsEmpty())
64 : platform_support_(platform_support), parent_(parent) {} 130 return false;
65 131
66 DrmOverlayManager::OverlayCandidatesIPC::~OverlayCandidatesIPC() {} 132 if (candidate.transform == gfx::OVERLAY_TRANSFORM_INVALID)
133 return false;
67 134
68 void DrmOverlayManager::OverlayCandidatesIPC::UnregisterHandler() { 135 if (candidate.plane_z_order != 0) {
69 platform_support_->UnregisterHandler(parent_); 136 // It is possible that the cc rect we get actually falls off the edge of
70 } 137 // the screen. Usually this is prevented via things like status bars
138 // blocking overlaying or cc clipping it, but in case it wasn't properly
139 // clipped (since GL will render this situation fine) just ignore it
140 // here. This should be an extremely rare occurrance.
141 DrmWindowHost* window = window_manager_->GetWindow(widget);
142 if (!window->GetBounds().Contains(
143 gfx::ToNearestRect(candidate.display_rect))) {
144 return false;
145 }
146 }
71 147
72 void DrmOverlayManager::OverlayCandidatesIPC::RegisterHandler() { 148 if (candidate.is_clipped &&
73 platform_support_->RegisterHandler(parent_); 149 !candidate.clip_rect.Contains(candidate.quad_rect_in_target_space))
74 } 150 return false;
75 151
76 bool DrmOverlayManager::OverlayCandidatesIPC::IsConnected() { 152 return true;
77 return platform_support_->IsConnected();
78 }
79
80 bool DrmOverlayManager::OverlayCandidatesIPC::CheckOverlayCapabilities(
81 gfx::AcceleratedWidget widget,
82 const std::vector<OverlayCheck_Params>& new_params) {
83 return platform_support_->Send(
84 new OzoneGpuMsg_CheckOverlayCapabilities(widget, new_params));
85 } 153 }
86 154
87 } // namespace ui 155 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/host/drm_overlay_manager.h ('k') | ui/ozone/platform/drm/host/drm_overlay_manager_core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698