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()) |
| 39 | return NULL; |
| 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; |
| 52 | while (plane) { |
| 53 | ret = plane->IsValidForLayer(layer.second) ? 0 : -EINVAL; |
| 54 | if (!ret) |
| 55 | break; |
| 56 | if (!plane->zpos_property().is_immutable()) |
| 57 | unused_planes.push_back(plane); |
| 58 | plane = PopPlane(planes); |
| 59 | } |
| 60 | |
| 61 | if (!ret) { |
| 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 | |
| 70 | int ProvisionPlanesInternal(std::vector<DrmCompositionPlane> *composition, |
| 71 | std::map<size_t, DrmHwcLayer *> &layers, |
| 72 | std::vector<DrmPlane *> *planes); |
| 73 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 74 | public: |
Roman Stratiienko | 9a6c9de | 2021-12-17 15:01:18 +0200 | [diff] [blame^] | 75 | // Creates a planner instance |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 76 | static std::unique_ptr<Planner> CreateInstance(DrmDevice *drm); |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 77 | |
| 78 | // 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] | 79 | // entire stack can't fit in hardware, FIXME |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 80 | // |
| 81 | // @layers: a map of index:layer of layers to composite |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 82 | // @primary_planes: a vector of primary planes available for this frame |
| 83 | // @overlay_planes: a vector of overlay planes available for this frame |
| 84 | // |
| 85 | // Returns: A tuple with the status of the operation (0 for success) and |
| 86 | // a vector of the resulting plan (ie: layer->plane mapping). |
| 87 | std::tuple<int, std::vector<DrmCompositionPlane>> ProvisionPlanes( |
Rob Herring | af0d975 | 2018-05-04 16:34:19 -0500 | [diff] [blame] | 88 | std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc, |
| 89 | std::vector<DrmPlane *> *primary_planes, |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 90 | std::vector<DrmPlane *> *overlay_planes); |
| 91 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 92 | private: |
| 93 | std::vector<DrmPlane *> GetUsablePlanes( |
| 94 | DrmCrtc *crtc, std::vector<DrmPlane *> *primary_planes, |
| 95 | std::vector<DrmPlane *> *overlay_planes); |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 96 | }; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 97 | } // namespace android |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 98 | #endif |