| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/hardware_display_plane_manager.h" | 5 #include "ui/ozone/platform/drm/gpu/hardware_display_plane_manager.h" |
| 6 | 6 |
| 7 #include <drm_fourcc.h> | 7 #include <drm_fourcc.h> |
| 8 | 8 |
| 9 #include <algorithm> |
| 9 #include <set> | 10 #include <set> |
| 10 #include <utility> | 11 #include <utility> |
| 11 | 12 |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
| 14 #include "ui/ozone/platform/drm/gpu/drm_device.h" | 15 #include "ui/ozone/platform/drm/gpu/drm_device.h" |
| 15 #include "ui/ozone/platform/drm/gpu/scanout_buffer.h" | 16 #include "ui/ozone/platform/drm/gpu/scanout_buffer.h" |
| 16 | 17 |
| 17 namespace ui { | 18 namespace ui { |
| 18 namespace { | 19 namespace { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 86 |
| 86 crtcs_.clear(); | 87 crtcs_.clear(); |
| 87 for (int i = 0; i < resources->count_crtcs; ++i) { | 88 for (int i = 0; i < resources->count_crtcs; ++i) { |
| 88 crtcs_.push_back(resources->crtcs[i]); | 89 crtcs_.push_back(resources->crtcs[i]); |
| 89 } | 90 } |
| 90 | 91 |
| 91 uint32_t num_planes = plane_resources->count_planes; | 92 uint32_t num_planes = plane_resources->count_planes; |
| 92 std::set<uint32_t> plane_ids; | 93 std::set<uint32_t> plane_ids; |
| 93 for (uint32_t i = 0; i < num_planes; ++i) { | 94 for (uint32_t i = 0; i < num_planes; ++i) { |
| 94 ScopedDrmPlanePtr drm_plane( | 95 ScopedDrmPlanePtr drm_plane( |
| 95 drmModeGetPlane(drm->get_fd(), plane_resources->planes[i])); | 96 drmModeGetPlane2(drm->get_fd(), plane_resources->planes[i])); |
| 96 if (!drm_plane) { | 97 if (!drm_plane) { |
| 97 PLOG(ERROR) << "Failed to get plane " << i; | 98 PLOG(ERROR) << "Failed to get plane " << i; |
| 98 return false; | 99 return false; |
| 99 } | 100 } |
| 100 | 101 |
| 101 uint32_t formats_size = drm_plane->count_formats; | 102 uint32_t formats_size = drm_plane->count_formats; |
| 103 uint32_t format_modifiers_size = drm_plane->count_format_modifiers; |
| 102 plane_ids.insert(drm_plane->plane_id); | 104 plane_ids.insert(drm_plane->plane_id); |
| 103 std::unique_ptr<HardwareDisplayPlane> plane( | 105 std::unique_ptr<HardwareDisplayPlane> plane( |
| 104 CreatePlane(drm_plane->plane_id, drm_plane->possible_crtcs)); | 106 CreatePlane(drm_plane->plane_id, drm_plane->possible_crtcs)); |
| 105 | 107 |
| 106 std::vector<uint32_t> supported_formats(formats_size); | 108 std::vector<uint32_t> supported_formats(formats_size); |
| 107 for (uint32_t j = 0; j < formats_size; j++) | 109 for (uint32_t j = 0; j < formats_size; j++) |
| 108 supported_formats[j] = drm_plane->formats[j]; | 110 supported_formats[j] = drm_plane->formats[j]; |
| 109 | 111 |
| 110 if (plane->Initialize(drm, supported_formats, false, false)) { | 112 std::vector<drm_format_modifier> supported_format_modifiers( |
| 113 format_modifiers_size); |
| 114 for (uint32_t j = 0; j < format_modifiers_size; j++) |
| 115 supported_format_modifiers[j] = drm_plane->format_modifiers[j]; |
| 116 std::sort(supported_format_modifiers.begin(), |
| 117 supported_format_modifiers.end(), |
| 118 [](drm_format_modifier l, drm_format_modifier r) { |
| 119 return l.modifier < r.modifier; |
| 120 }); |
| 121 |
| 122 if (plane->Initialize(drm, supported_formats, supported_format_modifiers, |
| 123 false, false)) { |
| 111 // CRTC controllers always assume they have a cursor plane and the cursor | 124 // CRTC controllers always assume they have a cursor plane and the cursor |
| 112 // plane is updated via cursor specific DRM API. Hence, we dont keep | 125 // plane is updated via cursor specific DRM API. Hence, we dont keep |
| 113 // track of Cursor plane here to avoid re-using it for any other purpose. | 126 // track of Cursor plane here to avoid re-using it for any other purpose. |
| 114 if (plane->type() != HardwareDisplayPlane::kCursor) | 127 if (plane->type() != HardwareDisplayPlane::kCursor) |
| 115 planes_.push_back(std::move(plane)); | 128 planes_.push_back(std::move(plane)); |
| 116 } | 129 } |
| 117 } | 130 } |
| 118 | 131 |
| 119 // crbug.com/464085: if driver reports no primary planes for a crtc, create a | 132 // crbug.com/464085: if driver reports no primary planes for a crtc, create a |
| 120 // dummy plane for which we can assign exactly one overlay. | 133 // dummy plane for which we can assign exactly one overlay. |
| 121 // TODO(dnicoara): refactor this to simplify AssignOverlayPlanes and move | 134 // TODO(dnicoara): refactor this to simplify AssignOverlayPlanes and move |
| 122 // this workaround into HardwareDisplayPlaneLegacy. | 135 // this workaround into HardwareDisplayPlaneLegacy. |
| 123 if (!has_universal_planes) { | 136 if (!has_universal_planes) { |
| 124 for (int i = 0; i < resources->count_crtcs; ++i) { | 137 for (int i = 0; i < resources->count_crtcs; ++i) { |
| 125 if (plane_ids.find(resources->crtcs[i] - 1) == plane_ids.end()) { | 138 if (plane_ids.find(resources->crtcs[i] - 1) == plane_ids.end()) { |
| 126 std::unique_ptr<HardwareDisplayPlane> dummy_plane( | 139 std::unique_ptr<HardwareDisplayPlane> dummy_plane( |
| 127 CreatePlane(resources->crtcs[i] - 1, (1 << i))); | 140 CreatePlane(resources->crtcs[i] - 1, (1 << i))); |
| 128 if (dummy_plane->Initialize(drm, std::vector<uint32_t>(), true, | 141 if (dummy_plane->Initialize(drm, std::vector<uint32_t>(), |
| 142 std::vector<drm_format_modifier>(), true, |
| 129 false)) { | 143 false)) { |
| 130 planes_.push_back(std::move(dummy_plane)); | 144 planes_.push_back(std::move(dummy_plane)); |
| 131 } | 145 } |
| 132 } | 146 } |
| 133 } | 147 } |
| 134 } | 148 } |
| 135 | 149 |
| 136 std::sort(planes_.begin(), planes_.end(), | 150 std::sort(planes_.begin(), planes_.end(), |
| 137 [](const std::unique_ptr<HardwareDisplayPlane>& l, | 151 [](const std::unique_ptr<HardwareDisplayPlane>& l, |
| 138 const std::unique_ptr<HardwareDisplayPlane>& r) { | 152 const std::unique_ptr<HardwareDisplayPlane>& r) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 315 |
| 302 break; | 316 break; |
| 303 } else { | 317 } else { |
| 304 plane_z_order++; | 318 plane_z_order++; |
| 305 } | 319 } |
| 306 } | 320 } |
| 307 | 321 |
| 308 return format_supported; | 322 return format_supported; |
| 309 } | 323 } |
| 310 | 324 |
| 325 std::vector<uint64_t> HardwareDisplayPlaneManager::GetFormatModifiers( |
| 326 uint32_t crtc_id, |
| 327 uint32_t format) { |
| 328 int crtc_index = LookupCrtcIndex(crtc_id); |
| 329 |
| 330 for (const auto& plane : planes_) { |
| 331 if (plane->CanUseForCrtc(crtc_index) && |
| 332 plane->type() == HardwareDisplayPlane::kPrimary) { |
| 333 return plane->ModifiersForFormat(format); |
| 334 } |
| 335 } |
| 336 |
| 337 return std::vector<uint64_t>(); |
| 338 } |
| 339 |
| 311 } // namespace ui | 340 } // namespace ui |
| OLD | NEW |