| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/gpu/drm_overlay_validator.h" | 5 #include "ui/ozone/platform/drm/gpu/drm_overlay_validator.h" |
| 6 | 6 |
| 7 #include <drm_fourcc.h> | 7 #include <drm_fourcc.h> |
| 8 | 8 |
| 9 #include "ui/gfx/geometry/size_conversions.h" | 9 #include "ui/gfx/geometry/size_conversions.h" |
| 10 #include "ui/ozone/platform/drm/common/drm_util.h" | 10 #include "ui/ozone/platform/drm/common/drm_util.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 97 |
| 98 DrmOverlayValidator::DrmOverlayValidator( | 98 DrmOverlayValidator::DrmOverlayValidator( |
| 99 DrmWindow* window, | 99 DrmWindow* window, |
| 100 ScanoutBufferGenerator* buffer_generator) | 100 ScanoutBufferGenerator* buffer_generator) |
| 101 : window_(window), | 101 : window_(window), |
| 102 buffer_generator_(buffer_generator), | 102 buffer_generator_(buffer_generator), |
| 103 overlay_hints_cache_(kMaxCacheSize) {} | 103 overlay_hints_cache_(kMaxCacheSize) {} |
| 104 | 104 |
| 105 DrmOverlayValidator::~DrmOverlayValidator() {} | 105 DrmOverlayValidator::~DrmOverlayValidator() {} |
| 106 | 106 |
| 107 std::vector<OverlayCheck_Params> DrmOverlayValidator::TestPageFlip( | 107 std::vector<OverlayCheckReturn_Params> DrmOverlayValidator::TestPageFlip( |
| 108 const std::vector<OverlayCheck_Params>& params, | 108 const std::vector<OverlayCheck_Params>& params, |
| 109 const OverlayPlaneList& last_used_planes) { | 109 const OverlayPlaneList& last_used_planes) { |
| 110 std::vector<OverlayCheck_Params> validated_params = params; | 110 std::vector<OverlayCheckReturn_Params> returns(params.size()); |
| 111 HardwareDisplayController* controller = window_->GetController(); | 111 HardwareDisplayController* controller = window_->GetController(); |
| 112 if (!controller) { | 112 if (!controller) { |
| 113 // Nothing much we can do here. | 113 // The controller is not yet installed. |
| 114 for (auto& overlay : validated_params) | 114 for (auto& param : returns) |
| 115 overlay.is_overlay_candidate = false; | 115 param.status = OverlayCheckReturn_Params::Status::NOT; |
| 116 | 116 |
| 117 return validated_params; | 117 return returns; |
| 118 } | 118 } |
| 119 | 119 |
| 120 OverlayPlaneList test_list; | 120 OverlayPlaneList test_list; |
| 121 std::vector<scoped_refptr<ScanoutBuffer>> reusable_buffers; | 121 std::vector<scoped_refptr<ScanoutBuffer>> reusable_buffers; |
| 122 scoped_refptr<DrmDevice> drm = controller->GetAllocationDrmDevice(); | 122 scoped_refptr<DrmDevice> drm = controller->GetAllocationDrmDevice(); |
| 123 | 123 |
| 124 for (const auto& plane : last_used_planes) | 124 for (const auto& plane : last_used_planes) |
| 125 reusable_buffers.push_back(plane.buffer); | 125 reusable_buffers.push_back(plane.buffer); |
| 126 | 126 |
| 127 for (auto& overlay : validated_params) { | 127 for (size_t i = 0; i < params.size(); ++i) { |
| 128 if (!overlay.is_overlay_candidate) | 128 if (!params[i].is_overlay_candidate) { |
| 129 returns[i].status = OverlayCheckReturn_Params::Status::NOT; |
| 129 continue; | 130 continue; |
| 131 } |
| 130 | 132 |
| 131 gfx::Size scaled_buffer_size = GetScaledSize( | 133 gfx::Size scaled_buffer_size = GetScaledSize( |
| 132 overlay.buffer_size, overlay.display_rect, overlay.crop_rect); | 134 params[i].buffer_size, params[i].display_rect, params[i].crop_rect); |
| 133 | 135 |
| 134 uint32_t original_format = | 136 uint32_t original_format = |
| 135 overlay.plane_z_order | 137 params[i].plane_z_order |
| 136 ? GetFourCCFormatFromBufferFormat(overlay.format) | 138 ? GetFourCCFormatFromBufferFormat(params[i].format) |
| 137 : GetFourCCFormatForOpaqueFramebuffer(overlay.format); | 139 : GetFourCCFormatForOpaqueFramebuffer(params[i].format); |
| 138 scoped_refptr<ScanoutBuffer> buffer = | 140 scoped_refptr<ScanoutBuffer> buffer = |
| 139 GetBufferForPageFlipTest(drm, overlay.buffer_size, original_format, | 141 GetBufferForPageFlipTest(drm, params[i].buffer_size, original_format, |
| 140 buffer_generator_, &reusable_buffers); | 142 buffer_generator_, &reusable_buffers); |
| 141 | 143 |
| 142 OverlayPlane plane(buffer, overlay.plane_z_order, overlay.transform, | 144 OverlayPlane plane(buffer, params[i].plane_z_order, params[i].transform, |
| 143 overlay.display_rect, overlay.crop_rect); | 145 params[i].display_rect, params[i].crop_rect); |
| 144 test_list.push_back(plane); | 146 test_list.push_back(plane); |
| 145 | 147 |
| 146 if (buffer && controller->TestPageFlip(test_list)) { | 148 if (buffer && controller->TestPageFlip(test_list)) { |
| 147 overlay.is_overlay_candidate = true; | 149 returns[i].status = OverlayCheckReturn_Params::Status::ABLE; |
| 148 | 150 |
| 149 // If size scaling is needed, find an optimal format. | 151 // If size scaling is needed, find an optimal format. |
| 150 if (overlay.plane_z_order && scaled_buffer_size != overlay.buffer_size) { | 152 if (params[i].plane_z_order && |
| 153 scaled_buffer_size != params[i].buffer_size) { |
| 151 uint32_t optimal_format = FindOptimalBufferFormat( | 154 uint32_t optimal_format = FindOptimalBufferFormat( |
| 152 original_format, overlay.plane_z_order, overlay.display_rect, | 155 original_format, params[i].plane_z_order, params[i].display_rect, |
| 153 window_->bounds(), controller); | 156 window_->bounds(), controller); |
| 154 | 157 |
| 155 if (original_format != optimal_format) { | 158 if (original_format != optimal_format) { |
| 156 OverlayPlane original_plain = test_list.back(); | 159 OverlayPlane original_plain = test_list.back(); |
| 157 test_list.pop_back(); | 160 test_list.pop_back(); |
| 158 scoped_refptr<ScanoutBuffer> optimal_buffer = | 161 scoped_refptr<ScanoutBuffer> optimal_buffer = |
| 159 GetBufferForPageFlipTest(drm, scaled_buffer_size, optimal_format, | 162 GetBufferForPageFlipTest(drm, scaled_buffer_size, optimal_format, |
| 160 buffer_generator_, &reusable_buffers); | 163 buffer_generator_, &reusable_buffers); |
| 161 DCHECK(optimal_buffer); | 164 DCHECK(optimal_buffer); |
| 162 | 165 |
| 163 OverlayPlane optimal_plane(optimal_buffer, overlay.plane_z_order, | 166 OverlayPlane optimal_plane( |
| 164 overlay.transform, overlay.display_rect, | 167 optimal_buffer, params[i].plane_z_order, params[i].transform, |
| 165 overlay.crop_rect); | 168 params[i].display_rect, params[i].crop_rect); |
| 166 test_list.push_back(optimal_plane); | 169 test_list.push_back(optimal_plane); |
| 167 | 170 |
| 168 // If test failed here, it means even though optimal_format is | 171 // If test failed here, it means even though optimal_format is |
| 169 // supported, platform cannot support it with current combination of | 172 // supported, platform cannot support it with current combination of |
| 170 // layers. This is usually the case when optimal_format needs certain | 173 // layers. This is usually the case when optimal_format needs certain |
| 171 // capabilites (i.e. conversion, scaling etc) and needed hardware | 174 // capabilites (i.e. conversion, scaling etc) and needed hardware |
| 172 // resources might be already in use. Fall back to original format. | 175 // resources might be already in use. Fall back to original format. |
| 173 if (!controller->TestPageFlip(test_list)) { | 176 if (!controller->TestPageFlip(test_list)) { |
| 174 test_list.pop_back(); | 177 test_list.pop_back(); |
| 175 test_list.push_back(original_plain); | 178 test_list.push_back(original_plain); |
| 176 } | 179 } |
| 177 } | 180 } |
| 178 } | 181 } |
| 179 } else { | 182 } else { |
| 180 // If test failed here, platform cannot support this configuration | 183 // If test failed here, platform cannot support this configuration |
| 181 // with current combination of layers. This is usually the case when this | 184 // with current combination of layers. This is usually the case when this |
| 182 // plane has requested post processing capability which needs additional | 185 // plane has requested post processing capability which needs additional |
| 183 // hardware resources and they might be already in use by other planes. | 186 // hardware resources and they might be already in use by other planes. |
| 184 // For example this plane has requested scaling capabilities and all | 187 // For example this plane has requested scaling capabilities and all |
| 185 // available scalars are already in use by other planes. | 188 // available scalars are already in use by other planes. |
| 186 overlay.is_overlay_candidate = false; | 189 returns[i].status = OverlayCheckReturn_Params::Status::NOT; |
| 187 test_list.pop_back(); | 190 test_list.pop_back(); |
| 188 } | 191 } |
| 189 } | 192 } |
| 190 | 193 |
| 191 UpdateOverlayHintsCache(test_list); | 194 UpdateOverlayHintsCache(test_list); |
| 192 | 195 |
| 193 return validated_params; | 196 return returns; |
| 194 } | 197 } |
| 195 | 198 |
| 196 OverlayPlaneList DrmOverlayValidator::PrepareBuffersForPageFlip( | 199 OverlayPlaneList DrmOverlayValidator::PrepareBuffersForPageFlip( |
| 197 const OverlayPlaneList& planes) { | 200 const OverlayPlaneList& planes) { |
| 198 if (planes.size() <= 1) | 201 if (planes.size() <= 1) |
| 199 return planes; | 202 return planes; |
| 200 | 203 |
| 201 HardwareDisplayController* controller = window_->GetController(); | 204 HardwareDisplayController* controller = window_->GetController(); |
| 202 if (!controller) | 205 if (!controller) |
| 203 return planes; | 206 return planes; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 267 |
| 265 // Make sure we dont hold reference to buffer when caching this plane list. | 268 // Make sure we dont hold reference to buffer when caching this plane list. |
| 266 plane.buffer = nullptr; | 269 plane.buffer = nullptr; |
| 267 } | 270 } |
| 268 | 271 |
| 269 DCHECK(hints_plane_list.size() == overlay_hints.size()); | 272 DCHECK(hints_plane_list.size() == overlay_hints.size()); |
| 270 overlay_hints_cache_.Put(hints_plane_list, overlay_hints); | 273 overlay_hints_cache_.Put(hints_plane_list, overlay_hints); |
| 271 } | 274 } |
| 272 | 275 |
| 273 } // namespace ui | 276 } // namespace ui |
| OLD | NEW |