blob: f1958d7bc116024f7084a056a71564b310b50dda [file] [log] [blame]
Sean Paul98e73c82015-06-24 14:38:49 -07001/*
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
17#ifndef ANDROID_DRM_DISPLAY_COMPOSITION_H_
18#define ANDROID_DRM_DISPLAY_COMPOSITION_H_
19
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030020#include <hardware/hardware.h>
21#include <hardware/hwcomposer.h>
Sean Paul98e73c82015-06-24 14:38:49 -070022
Zach Reiznerfd6dc332015-10-13 21:12:48 -070023#include <sstream>
Sean Paul98e73c82015-06-24 14:38:49 -070024#include <vector>
25
Roman Stratiienko13cc3662020-08-29 21:35:39 +030026#include "drm/DrmCrtc.h"
27#include "drm/DrmPlane.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030028#include "drmhwcomposer.h"
Sean Paul98e73c82015-06-24 14:38:49 -070029
30namespace android {
31
Sean Paul4c4646e2016-05-10 04:19:24 -040032class Importer;
Sean Paulaa18d912016-05-12 14:28:05 -040033class Planner;
Zach Reizner92f8e632015-10-12 17:47:13 -070034
Sean Paulca699be2016-05-11 16:29:45 -040035class DrmCompositionPlane {
36 public:
Sean Paulbbe39db2016-05-11 16:57:26 -040037 enum class Type : int32_t {
38 kDisable,
39 kLayer,
Sean Paulbbe39db2016-05-11 16:57:26 -040040 };
41
Sean Paulca699be2016-05-11 16:29:45 -040042 DrmCompositionPlane() = default;
43 DrmCompositionPlane(DrmCompositionPlane &&rhs) = default;
44 DrmCompositionPlane &operator=(DrmCompositionPlane &&other) = default;
Matvii Zorinf0757c22021-01-18 15:54:22 +020045 DrmCompositionPlane(Type type, DrmPlane *plane) : type_(type), plane_(plane) {
Sean Paulca699be2016-05-11 16:29:45 -040046 }
Matvii Zorinf0757c22021-01-18 15:54:22 +020047 DrmCompositionPlane(Type type, DrmPlane *plane, size_t source_layer)
48 : type_(type), plane_(plane), source_layers_(1, source_layer) {
Sean Paulca699be2016-05-11 16:29:45 -040049 }
50
Sean Paulbbe39db2016-05-11 16:57:26 -040051 Type type() const {
Sean Paulca699be2016-05-11 16:29:45 -040052 return type_;
53 }
54
55 DrmPlane *plane() const {
56 return plane_;
57 }
58 void set_plane(DrmPlane *plane) {
59 plane_ = plane;
60 }
61
Sean Paulca699be2016-05-11 16:29:45 -040062 std::vector<size_t> &source_layers() {
63 return source_layers_;
64 }
65
66 const std::vector<size_t> &source_layers() const {
67 return source_layers_;
68 }
69
70 private:
Sean Paulbbe39db2016-05-11 16:57:26 -040071 Type type_ = Type::kDisable;
Sean Paulca699be2016-05-11 16:29:45 -040072 DrmPlane *plane_ = NULL;
Sean Paulca699be2016-05-11 16:29:45 -040073 std::vector<size_t> source_layers_;
Zach Reizner4a253652015-09-10 18:30:54 -070074};
Sean Paul98e73c82015-06-24 14:38:49 -070075
76class DrmDisplayComposition {
77 public:
Zach Reizner92f8e632015-10-12 17:47:13 -070078 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
Matvii Zorin704ea0e2021-01-08 12:55:45 +020079 DrmDisplayComposition(DrmCrtc *crtc, Planner *planner);
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020080 ~DrmDisplayComposition() = default;
Sean Paul98e73c82015-06-24 14:38:49 -070081
Roman Stratiienko36a7f282021-10-05 18:17:53 +030082 int SetLayers(DrmHwcLayer *layers, size_t num_layers);
Sean Paul4f4ef692016-05-03 16:40:59 -070083 int AddPlaneComposition(DrmCompositionPlane plane);
Sean Paul2e46fbd2015-07-09 17:22:22 -040084 int AddPlaneDisable(DrmPlane *plane);
Sean Paul98e73c82015-06-24 14:38:49 -070085
Rob Herringaf0d9752018-05-04 16:34:19 -050086 int Plan(std::vector<DrmPlane *> *primary_planes,
Zach Reizner92f8e632015-10-12 17:47:13 -070087 std::vector<DrmPlane *> *overlay_planes);
Sean Paulacb2a442015-06-24 18:43:01 -070088
Zach Reizner92f8e632015-10-12 17:47:13 -070089 std::vector<DrmHwcLayer> &layers() {
90 return layers_;
91 }
92
Zach Reizner92f8e632015-10-12 17:47:13 -070093 std::vector<DrmCompositionPlane> &composition_planes() {
94 return composition_planes_;
95 }
96
Zach Reizner92f8e632015-10-12 17:47:13 -070097 DrmCrtc *crtc() const {
98 return crtc_;
99 }
100
Sean Paulaa18d912016-05-12 14:28:05 -0400101 Planner *planner() const {
102 return planner_;
103 }
104
Zach Reizner92f8e632015-10-12 17:47:13 -0700105 private:
Zach Reizner92f8e632015-10-12 17:47:13 -0700106 DrmCrtc *crtc_ = NULL;
Sean Paulaa18d912016-05-12 14:28:05 -0400107 Planner *planner_ = NULL;
Sean Paul98e73c82015-06-24 14:38:49 -0700108
Zach Reizner92f8e632015-10-12 17:47:13 -0700109 std::vector<DrmHwcLayer> layers_;
Zach Reizner92f8e632015-10-12 17:47:13 -0700110 std::vector<DrmCompositionPlane> composition_planes_;
Sean Paul98e73c82015-06-24 14:38:49 -0700111};
Sean Paulf72cccd2018-08-27 13:59:08 -0400112} // namespace android
Sean Paul98e73c82015-06-24 14:38:49 -0700113
114#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_