Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Sean Paul | 5d8acfc | 2016-04-21 16:26:27 -0400 | [diff] [blame] | 17 | #ifndef ANDROID_DRM_PLATFORM_H_ |
| 18 | #define ANDROID_DRM_PLATFORM_H_ |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 19 | |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 20 | #include <hardware/hardware.h> |
| 21 | #include <hardware/hwcomposer.h> |
| 22 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 23 | #include <map> |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 24 | #include <memory> |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 25 | #include <vector> |
| 26 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 27 | #include "compositor/DrmDisplayComposition.h" |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 28 | #include "drmhwcomposer.h" |
| 29 | |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 30 | namespace android { |
| 31 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 32 | class DrmDevice; |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 33 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 34 | class Planner { |
Roman Stratiienko | 9a6c9de | 2021-12-17 15:01:18 +0200 | [diff] [blame] | 35 | private: |
| 36 | // Removes and returns the next available plane from planes |
| 37 | static DrmPlane *PopPlane(std::vector<DrmPlane *> *planes) { |
| 38 | if (planes->empty()) |
Roman Stratiienko | e78235c | 2021-12-23 17:36:12 +0200 | [diff] [blame] | 39 | return nullptr; |
Roman Stratiienko | 9a6c9de | 2021-12-17 15:01:18 +0200 | [diff] [blame] | 40 | DrmPlane *plane = planes->front(); |
| 41 | planes->erase(planes->begin()); |
| 42 | return plane; |
| 43 | } |
| 44 | |
| 45 | // Inserts the given layer:plane in the composition at the back |
| 46 | static int Emplace(std::vector<DrmCompositionPlane> *composition, |
| 47 | std::vector<DrmPlane *> *planes, |
| 48 | std::pair<size_t, DrmHwcLayer *> layer) { |
| 49 | DrmPlane *plane = PopPlane(planes); |
| 50 | std::vector<DrmPlane *> unused_planes; |
| 51 | int ret = -ENOENT; |
Roman Stratiienko | fc014f5 | 2021-12-23 19:04:29 +0200 | [diff] [blame] | 52 | while (plane != nullptr) { |
Roman Stratiienko | 9a6c9de | 2021-12-17 15:01:18 +0200 | [diff] [blame] | 53 | ret = plane->IsValidForLayer(layer.second) ? 0 : -EINVAL; |
Roman Stratiienko | fc014f5 | 2021-12-23 19:04:29 +0200 | [diff] [blame] | 54 | if (ret == 0) |
Roman Stratiienko | 9a6c9de | 2021-12-17 15:01:18 +0200 | [diff] [blame] | 55 | break; |
Roman Stratiienko | fc014f5 | 2021-12-23 19:04:29 +0200 | [diff] [blame] | 56 | if (!plane->GetZPosProperty().is_immutable()) |
Roman Stratiienko | 9a6c9de | 2021-12-17 15:01:18 +0200 | [diff] [blame] | 57 | unused_planes.push_back(plane); |
| 58 | plane = PopPlane(planes); |
| 59 | } |
| 60 | |
Roman Stratiienko | fc014f5 | 2021-12-23 19:04:29 +0200 | [diff] [blame] | 61 | if (ret == 0) { |
Roman Stratiienko | 9a6c9de | 2021-12-17 15:01:18 +0200 | [diff] [blame] | 62 | composition->emplace_back(plane, layer.first); |
| 63 | planes->insert(planes->begin(), unused_planes.begin(), |
| 64 | unused_planes.end()); |
| 65 | } |
| 66 | |
| 67 | return ret; |
| 68 | } |
| 69 | |
Roman Stratiienko | fc014f5 | 2021-12-23 19:04:29 +0200 | [diff] [blame] | 70 | static int ProvisionPlanesInternal( |
| 71 | std::vector<DrmCompositionPlane> *composition, |
| 72 | std::map<size_t, DrmHwcLayer *> &layers, std::vector<DrmPlane *> *planes); |
Roman Stratiienko | 9a6c9de | 2021-12-17 15:01:18 +0200 | [diff] [blame] | 73 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 74 | public: |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 75 | // Takes a stack of layers and provisions hardware planes for them. If the |
Rob Herring | af0d975 | 2018-05-04 16:34:19 -0500 | [diff] [blame] | 76 | // entire stack can't fit in hardware, FIXME |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 77 | // |
| 78 | // @layers: a map of index:layer of layers to composite |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 79 | // @primary_planes: a vector of primary planes available for this frame |
| 80 | // @overlay_planes: a vector of overlay planes available for this frame |
| 81 | // |
| 82 | // Returns: A tuple with the status of the operation (0 for success) and |
| 83 | // a vector of the resulting plan (ie: layer->plane mapping). |
Roman Stratiienko | fc014f5 | 2021-12-23 19:04:29 +0200 | [diff] [blame] | 84 | static std::tuple<int, std::vector<DrmCompositionPlane>> ProvisionPlanes( |
Rob Herring | af0d975 | 2018-05-04 16:34:19 -0500 | [diff] [blame] | 85 | std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc, |
| 86 | std::vector<DrmPlane *> *primary_planes, |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 87 | std::vector<DrmPlane *> *overlay_planes); |
| 88 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 89 | private: |
Roman Stratiienko | fc014f5 | 2021-12-23 19:04:29 +0200 | [diff] [blame] | 90 | static std::vector<DrmPlane *> GetUsablePlanes( |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 91 | DrmCrtc *crtc, std::vector<DrmPlane *> *primary_planes, |
| 92 | std::vector<DrmPlane *> *overlay_planes); |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 93 | }; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 94 | } // namespace android |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 95 | #endif |