blob: 32d0011d79e7d1cdbd06edf16ffe08e52636e168 [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 Paul4c4646e2016-05-10 04:19:24 -040020#include "drmdisplaycomposition.h"
Zach Reizner7642c922015-10-29 10:11:16 -070021#include "drmhwcomposer.h"
Sean Paulda6270d2015-06-01 14:11:52 -040022
23#include <hardware/hardware.h>
24#include <hardware/hwcomposer.h>
25
Sean Paul4c4646e2016-05-10 04:19:24 -040026#include <map>
27#include <vector>
28
Sean Paulda6270d2015-06-01 14:11:52 -040029namespace android {
30
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010031class DrmDevice;
Sean Paulda6270d2015-06-01 14:11:52 -040032
33class Importer {
34 public:
35 virtual ~Importer() {
36 }
37
38 // Creates a platform-specific importer instance
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010039 static Importer *CreateInstance(DrmDevice *drm);
Sean Paulda6270d2015-06-01 14:11:52 -040040
41 // Imports the buffer referred to by handle into bo.
42 //
43 // Note: This can be called from a different thread than ReleaseBuffer. The
44 // implementation is responsible for ensuring thread safety.
45 virtual int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) = 0;
46
47 // Releases the buffer object (ie: does the inverse of ImportBuffer)
48 //
49 // Note: This can be called from a different thread than ImportBuffer. The
50 // implementation is responsible for ensuring thread safety.
51 virtual int ReleaseBuffer(hwc_drm_bo_t *bo) = 0;
52};
Sean Paul4c4646e2016-05-10 04:19:24 -040053
54class Planner {
55 public:
56 class PlanStage {
57 public:
58 virtual ~PlanStage() {
59 }
60
61 virtual int ProvisionPlanes(std::vector<DrmCompositionPlane> *composition,
62 std::map<size_t, DrmHwcLayer *> &layers,
63 DrmCrtc *crtc,
64 std::vector<DrmPlane *> *planes) = 0;
65
66 protected:
67 // Removes and returns the next available plane from planes
68 static DrmPlane *PopPlane(std::vector<DrmPlane *> *planes) {
69 if (planes->empty())
70 return NULL;
71 DrmPlane *plane = planes->front();
72 planes->erase(planes->begin());
73 return plane;
74 }
75
Rob Herringaf0d9752018-05-04 16:34:19 -050076 // Inserts the given layer:plane in the composition at the back
Sean Paul4c4646e2016-05-10 04:19:24 -040077 static int Emplace(std::vector<DrmCompositionPlane> *composition,
78 std::vector<DrmPlane *> *planes,
79 DrmCompositionPlane::Type type, DrmCrtc *crtc,
80 size_t source_layer) {
81 DrmPlane *plane = PopPlane(planes);
82 if (!plane)
83 return -ENOENT;
84
Rob Herringaf0d9752018-05-04 16:34:19 -050085 composition->emplace_back(type, plane, crtc, source_layer);
Sean Paul4c4646e2016-05-10 04:19:24 -040086 return 0;
87 }
Sean Paul4c4646e2016-05-10 04:19:24 -040088 };
89
90 // Creates a planner instance with platform-specific planning stages
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010091 static std::unique_ptr<Planner> CreateInstance(DrmDevice *drm);
Sean Paul4c4646e2016-05-10 04:19:24 -040092
93 // Takes a stack of layers and provisions hardware planes for them. If the
Rob Herringaf0d9752018-05-04 16:34:19 -050094 // entire stack can't fit in hardware, FIXME
Sean Paul4c4646e2016-05-10 04:19:24 -040095 //
96 // @layers: a map of index:layer of layers to composite
Sean Paul4c4646e2016-05-10 04:19:24 -040097 // @primary_planes: a vector of primary planes available for this frame
98 // @overlay_planes: a vector of overlay planes available for this frame
99 //
100 // Returns: A tuple with the status of the operation (0 for success) and
101 // a vector of the resulting plan (ie: layer->plane mapping).
102 std::tuple<int, std::vector<DrmCompositionPlane>> ProvisionPlanes(
Rob Herringaf0d9752018-05-04 16:34:19 -0500103 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
104 std::vector<DrmPlane *> *primary_planes,
Sean Paul4c4646e2016-05-10 04:19:24 -0400105 std::vector<DrmPlane *> *overlay_planes);
106
107 template <typename T, typename... A>
108 void AddStage(A &&... args) {
109 stages_.emplace_back(
110 std::unique_ptr<PlanStage>(new T(std::forward(args)...)));
111 }
112
113 private:
114 std::vector<DrmPlane *> GetUsablePlanes(
115 DrmCrtc *crtc, std::vector<DrmPlane *> *primary_planes,
116 std::vector<DrmPlane *> *overlay_planes);
117
118 std::vector<std::unique_ptr<PlanStage>> stages_;
119};
120
121// This plan stage extracts all protected layers and places them on dedicated
122// planes.
123class PlanStageProtected : public Planner::PlanStage {
124 public:
125 int ProvisionPlanes(std::vector<DrmCompositionPlane> *composition,
126 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
127 std::vector<DrmPlane *> *planes);
128};
129
130// This plan stage places as many layers on dedicated planes as possible (first
131// come first serve), and then sticks the rest in a precomposition plane (if
132// needed).
133class PlanStageGreedy : public Planner::PlanStage {
134 public:
135 int ProvisionPlanes(std::vector<DrmCompositionPlane> *composition,
136 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
137 std::vector<DrmPlane *> *planes);
138};
Sean Paulda6270d2015-06-01 14:11:52 -0400139}
Sean Paulda6270d2015-06-01 14:11:52 -0400140#endif