Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [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 | |
| 17 | #ifndef ANDROID_DRM_DISPLAY_COMPOSITION_H_ |
| 18 | #define ANDROID_DRM_DISPLAY_COMPOSITION_H_ |
| 19 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 20 | #include "drmcrtc.h" |
Haixia Shi | 6afbb6a | 2015-11-24 12:42:45 -0800 | [diff] [blame] | 21 | #include "drmhwcomposer.h" |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 22 | #include "drmplane.h" |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 23 | |
Zach Reizner | fd6dc33 | 2015-10-13 21:12:48 -0700 | [diff] [blame] | 24 | #include <sstream> |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 25 | #include <vector> |
| 26 | |
| 27 | #include <hardware/hardware.h> |
| 28 | #include <hardware/hwcomposer.h> |
| 29 | |
| 30 | namespace android { |
| 31 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 32 | class Importer; |
Sean Paul | aa18d91 | 2016-05-12 14:28:05 -0400 | [diff] [blame] | 33 | class Planner; |
Sean Paul | 5325e10 | 2016-03-29 13:55:35 -0400 | [diff] [blame] | 34 | class SquashState; |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 35 | |
Sean Paul | acb2a44 | 2015-06-24 18:43:01 -0700 | [diff] [blame] | 36 | enum DrmCompositionType { |
| 37 | DRM_COMPOSITION_TYPE_EMPTY, |
| 38 | DRM_COMPOSITION_TYPE_FRAME, |
Sean Paul | db7a17d | 2015-06-24 18:46:05 -0700 | [diff] [blame] | 39 | DRM_COMPOSITION_TYPE_DPMS, |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame] | 40 | DRM_COMPOSITION_TYPE_MODESET, |
Sean Paul | acb2a44 | 2015-06-24 18:43:01 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Sean Paul | ed45a8e | 2017-02-28 13:17:34 -0500 | [diff] [blame] | 43 | struct DrmCompositionDisplayLayersMap { |
| 44 | int display; |
| 45 | bool geometry_changed = true; |
| 46 | std::vector<DrmHwcLayer> layers; |
| 47 | |
| 48 | DrmCompositionDisplayLayersMap() = default; |
| 49 | DrmCompositionDisplayLayersMap(DrmCompositionDisplayLayersMap &&rhs) = |
| 50 | default; |
| 51 | }; |
| 52 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 53 | struct DrmCompositionRegion { |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 54 | std::vector<size_t> source_layers; |
| 55 | }; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 56 | |
Sean Paul | ca699be | 2016-05-11 16:29:45 -0400 | [diff] [blame] | 57 | class DrmCompositionPlane { |
| 58 | public: |
Sean Paul | bbe39db | 2016-05-11 16:57:26 -0400 | [diff] [blame] | 59 | enum class Type : int32_t { |
| 60 | kDisable, |
| 61 | kLayer, |
Sean Paul | bbe39db | 2016-05-11 16:57:26 -0400 | [diff] [blame] | 62 | }; |
| 63 | |
Sean Paul | ca699be | 2016-05-11 16:29:45 -0400 | [diff] [blame] | 64 | DrmCompositionPlane() = default; |
| 65 | DrmCompositionPlane(DrmCompositionPlane &&rhs) = default; |
| 66 | DrmCompositionPlane &operator=(DrmCompositionPlane &&other) = default; |
Sean Paul | bbe39db | 2016-05-11 16:57:26 -0400 | [diff] [blame] | 67 | DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc) |
Sean Paul | ca699be | 2016-05-11 16:29:45 -0400 | [diff] [blame] | 68 | : type_(type), plane_(plane), crtc_(crtc) { |
| 69 | } |
Sean Paul | bbe39db | 2016-05-11 16:57:26 -0400 | [diff] [blame] | 70 | DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc, |
| 71 | size_t source_layer) |
Sean Paul | ca699be | 2016-05-11 16:29:45 -0400 | [diff] [blame] | 72 | : type_(type), |
| 73 | plane_(plane), |
| 74 | crtc_(crtc), |
| 75 | source_layers_(1, source_layer) { |
| 76 | } |
| 77 | |
Sean Paul | bbe39db | 2016-05-11 16:57:26 -0400 | [diff] [blame] | 78 | Type type() const { |
Sean Paul | ca699be | 2016-05-11 16:29:45 -0400 | [diff] [blame] | 79 | return type_; |
| 80 | } |
| 81 | |
| 82 | DrmPlane *plane() const { |
| 83 | return plane_; |
| 84 | } |
| 85 | void set_plane(DrmPlane *plane) { |
| 86 | plane_ = plane; |
| 87 | } |
| 88 | |
| 89 | DrmCrtc *crtc() const { |
| 90 | return crtc_; |
| 91 | } |
| 92 | |
| 93 | std::vector<size_t> &source_layers() { |
| 94 | return source_layers_; |
| 95 | } |
| 96 | |
| 97 | const std::vector<size_t> &source_layers() const { |
| 98 | return source_layers_; |
| 99 | } |
| 100 | |
| 101 | private: |
Sean Paul | bbe39db | 2016-05-11 16:57:26 -0400 | [diff] [blame] | 102 | Type type_ = Type::kDisable; |
Sean Paul | ca699be | 2016-05-11 16:29:45 -0400 | [diff] [blame] | 103 | DrmPlane *plane_ = NULL; |
| 104 | DrmCrtc *crtc_ = NULL; |
| 105 | std::vector<size_t> source_layers_; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 106 | }; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 107 | |
| 108 | class DrmDisplayComposition { |
| 109 | public: |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 110 | DrmDisplayComposition() = default; |
| 111 | DrmDisplayComposition(const DrmDisplayComposition &) = delete; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 112 | ~DrmDisplayComposition(); |
| 113 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 114 | int Init(DrmDevice *drm, DrmCrtc *crtc, Importer *importer, Planner *planner, |
| 115 | uint64_t frame_no); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 116 | |
Zach Reizner | 5757e82 | 2015-10-16 19:06:31 -0700 | [diff] [blame] | 117 | int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed); |
Sean Paul | 4f4ef69 | 2016-05-03 16:40:59 -0700 | [diff] [blame] | 118 | int AddPlaneComposition(DrmCompositionPlane plane); |
Sean Paul | 2e46fbd | 2015-07-09 17:22:22 -0400 | [diff] [blame] | 119 | int AddPlaneDisable(DrmPlane *plane); |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 120 | int SetDpmsMode(uint32_t dpms_mode); |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame] | 121 | int SetDisplayMode(const DrmMode &display_mode); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 122 | |
Rob Herring | af0d975 | 2018-05-04 16:34:19 -0500 | [diff] [blame] | 123 | int Plan(std::vector<DrmPlane *> *primary_planes, |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 124 | std::vector<DrmPlane *> *overlay_planes); |
Sean Paul | acb2a44 | 2015-06-24 18:43:01 -0700 | [diff] [blame] | 125 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 126 | std::vector<DrmHwcLayer> &layers() { |
| 127 | return layers_; |
| 128 | } |
| 129 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 130 | std::vector<DrmCompositionPlane> &composition_planes() { |
| 131 | return composition_planes_; |
| 132 | } |
| 133 | |
Haixia Shi | 6afbb6a | 2015-11-24 12:42:45 -0800 | [diff] [blame] | 134 | bool geometry_changed() const { |
| 135 | return geometry_changed_; |
| 136 | } |
| 137 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 138 | uint64_t frame_no() const { |
| 139 | return frame_no_; |
| 140 | } |
| 141 | |
| 142 | DrmCompositionType type() const { |
| 143 | return type_; |
| 144 | } |
| 145 | |
| 146 | uint32_t dpms_mode() const { |
| 147 | return dpms_mode_; |
| 148 | } |
| 149 | |
| 150 | const DrmMode &display_mode() const { |
| 151 | return display_mode_; |
| 152 | } |
| 153 | |
| 154 | DrmCrtc *crtc() const { |
| 155 | return crtc_; |
| 156 | } |
| 157 | |
| 158 | Importer *importer() const { |
| 159 | return importer_; |
| 160 | } |
| 161 | |
Sean Paul | aa18d91 | 2016-05-12 14:28:05 -0400 | [diff] [blame] | 162 | Planner *planner() const { |
| 163 | return planner_; |
| 164 | } |
| 165 | |
Robert Foss | a1ade4e | 2017-09-27 19:28:15 +0200 | [diff] [blame] | 166 | int take_out_fence() { |
| 167 | return out_fence_.Release(); |
| 168 | } |
| 169 | |
| 170 | void set_out_fence(int out_fence) { |
| 171 | out_fence_.Set(out_fence); |
| 172 | } |
| 173 | |
Zach Reizner | fd6dc33 | 2015-10-13 21:12:48 -0700 | [diff] [blame] | 174 | void Dump(std::ostringstream *out) const; |
| 175 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 176 | private: |
| 177 | bool validate_composition_type(DrmCompositionType desired); |
| 178 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 179 | DrmDevice *drm_ = NULL; |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 180 | DrmCrtc *crtc_ = NULL; |
| 181 | Importer *importer_ = NULL; |
Sean Paul | aa18d91 | 2016-05-12 14:28:05 -0400 | [diff] [blame] | 182 | Planner *planner_ = NULL; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 183 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 184 | DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY; |
| 185 | uint32_t dpms_mode_ = DRM_MODE_DPMS_ON; |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame] | 186 | DrmMode display_mode_; |
Sean Paul | bdc67bf | 2015-09-21 10:04:02 -0400 | [diff] [blame] | 187 | |
Robert Foss | a1ade4e | 2017-09-27 19:28:15 +0200 | [diff] [blame] | 188 | UniqueFd out_fence_ = -1; |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 189 | |
Zach Reizner | 5757e82 | 2015-10-16 19:06:31 -0700 | [diff] [blame] | 190 | bool geometry_changed_; |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 191 | std::vector<DrmHwcLayer> layers_; |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 192 | std::vector<DrmCompositionPlane> composition_planes_; |
| 193 | |
| 194 | uint64_t frame_no_ = 0; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 195 | }; |
| 196 | } |
| 197 | |
| 198 | #endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_ |