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