blob: ff059f550450bf8a5b5d4bad831e73f5b6c16ff0 [file] [log] [blame]
Sean Paulda6270d2015-06-01 14:11:52 -04001/*
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 Paul5d8acfc2016-04-21 16:26:27 -040017#ifndef ANDROID_DRM_PLATFORM_H_
18#define ANDROID_DRM_PLATFORM_H_
Sean Paulda6270d2015-06-01 14:11:52 -040019
Sean Paulda6270d2015-06-01 14:11:52 -040020#include <hardware/hardware.h>
21#include <hardware/hwcomposer.h>
22
Sean Paul4c4646e2016-05-10 04:19:24 -040023#include <map>
Roman Stratiienkod21071f2021-03-09 21:56:50 +020024#include <memory>
Sean Paul4c4646e2016-05-10 04:19:24 -040025#include <vector>
26
Roman Stratiienko13cc3662020-08-29 21:35:39 +030027#include "compositor/DrmDisplayComposition.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030028#include "drmhwcomposer.h"
29
Sean Paulda6270d2015-06-01 14:11:52 -040030namespace android {
31
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010032class DrmDevice;
Sean Paulda6270d2015-06-01 14:11:52 -040033
Sean Paul4c4646e2016-05-10 04:19:24 -040034class Planner {
Roman Stratiienko9a6c9de2021-12-17 15:01:18 +020035 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 Paul4c4646e2016-05-10 04:19:24 -040074 public:
Roman Stratiienko9a6c9de2021-12-17 15:01:18 +020075 // Creates a planner instance
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010076 static std::unique_ptr<Planner> CreateInstance(DrmDevice *drm);
Sean Paul4c4646e2016-05-10 04:19:24 -040077
78 // Takes a stack of layers and provisions hardware planes for them. If the
Rob Herringaf0d9752018-05-04 16:34:19 -050079 // entire stack can't fit in hardware, FIXME
Sean Paul4c4646e2016-05-10 04:19:24 -040080 //
81 // @layers: a map of index:layer of layers to composite
Sean Paul4c4646e2016-05-10 04:19:24 -040082 // @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 Herringaf0d9752018-05-04 16:34:19 -050088 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
89 std::vector<DrmPlane *> *primary_planes,
Sean Paul4c4646e2016-05-10 04:19:24 -040090 std::vector<DrmPlane *> *overlay_planes);
91
Sean Paul4c4646e2016-05-10 04:19:24 -040092 private:
93 std::vector<DrmPlane *> GetUsablePlanes(
94 DrmCrtc *crtc, std::vector<DrmPlane *> *primary_planes,
95 std::vector<DrmPlane *> *overlay_planes);
Sean Paul4c4646e2016-05-10 04:19:24 -040096};
Sean Paulf72cccd2018-08-27 13:59:08 -040097} // namespace android
Sean Paulda6270d2015-06-01 14:11:52 -040098#endif