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 | |
| 20 | #include "drm_hwcomposer.h" |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 21 | #include "drmcrtc.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 | #include "importer.h" |
| 25 | |
| 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 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 34 | struct SquashState; |
| 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 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 43 | struct DrmCompositionRegion { |
| 44 | DrmHwcRect<int> frame; |
| 45 | std::vector<size_t> source_layers; |
| 46 | }; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 47 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 48 | struct DrmCompositionPlane { |
| 49 | const static size_t kSourceNone = SIZE_MAX; |
| 50 | const static size_t kSourcePreComp = kSourceNone - 1; |
| 51 | const static size_t kSourceSquash = kSourcePreComp - 1; |
| 52 | const static size_t kSourceLayerMax = kSourceSquash - 1; |
| 53 | DrmPlane *plane; |
| 54 | DrmCrtc *crtc; |
| 55 | size_t source_layer; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 56 | }; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 57 | |
| 58 | class DrmDisplayComposition { |
| 59 | public: |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 60 | DrmDisplayComposition() = default; |
| 61 | DrmDisplayComposition(const DrmDisplayComposition &) = delete; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 62 | ~DrmDisplayComposition(); |
| 63 | |
Sean Paul | bdc67bf | 2015-09-21 10:04:02 -0400 | [diff] [blame] | 64 | int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer, |
| 65 | uint64_t frame_no); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 66 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 67 | int SetLayers(DrmHwcLayer *layers, size_t num_layers); |
Sean Paul | 2e46fbd | 2015-07-09 17:22:22 -0400 | [diff] [blame] | 68 | int AddPlaneDisable(DrmPlane *plane); |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 69 | int SetDpmsMode(uint32_t dpms_mode); |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame] | 70 | int SetDisplayMode(const DrmMode &display_mode); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 71 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 72 | int Plan(SquashState *squash, std::vector<DrmPlane *> *primary_planes, |
| 73 | std::vector<DrmPlane *> *overlay_planes); |
Sean Paul | acb2a44 | 2015-06-24 18:43:01 -0700 | [diff] [blame] | 74 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 75 | int CreateNextTimelineFence(); |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 76 | int SignalSquashDone() { |
| 77 | return IncreaseTimelineToPoint(timeline_squash_done_); |
| 78 | } |
| 79 | int SignalPreCompDone() { |
| 80 | return IncreaseTimelineToPoint(timeline_pre_comp_done_); |
| 81 | } |
| 82 | int SignalCompositionDone() { |
| 83 | return IncreaseTimelineToPoint(timeline_); |
| 84 | } |
| 85 | |
| 86 | std::vector<DrmHwcLayer> &layers() { |
| 87 | return layers_; |
| 88 | } |
| 89 | |
| 90 | std::vector<DrmCompositionRegion> &squash_regions() { |
| 91 | return squash_regions_; |
| 92 | } |
| 93 | |
| 94 | std::vector<DrmCompositionRegion> &pre_comp_regions() { |
| 95 | return pre_comp_regions_; |
| 96 | } |
| 97 | |
| 98 | std::vector<DrmCompositionPlane> &composition_planes() { |
| 99 | return composition_planes_; |
| 100 | } |
| 101 | |
| 102 | uint64_t frame_no() const { |
| 103 | return frame_no_; |
| 104 | } |
| 105 | |
| 106 | DrmCompositionType type() const { |
| 107 | return type_; |
| 108 | } |
| 109 | |
| 110 | uint32_t dpms_mode() const { |
| 111 | return dpms_mode_; |
| 112 | } |
| 113 | |
| 114 | const DrmMode &display_mode() const { |
| 115 | return display_mode_; |
| 116 | } |
| 117 | |
| 118 | DrmCrtc *crtc() const { |
| 119 | return crtc_; |
| 120 | } |
| 121 | |
| 122 | Importer *importer() const { |
| 123 | return importer_; |
| 124 | } |
| 125 | |
| 126 | private: |
| 127 | bool validate_composition_type(DrmCompositionType desired); |
| 128 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 129 | int IncreaseTimelineToPoint(int point); |
| 130 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 131 | DrmResources *drm_ = NULL; |
| 132 | DrmCrtc *crtc_ = NULL; |
| 133 | Importer *importer_ = NULL; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 134 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 135 | DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY; |
| 136 | uint32_t dpms_mode_ = DRM_MODE_DPMS_ON; |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame] | 137 | DrmMode display_mode_; |
Sean Paul | bdc67bf | 2015-09-21 10:04:02 -0400 | [diff] [blame] | 138 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 139 | int timeline_fd_ = -1; |
| 140 | int timeline_ = 0; |
| 141 | int timeline_current_ = 0; |
| 142 | int timeline_squash_done_ = 0; |
| 143 | int timeline_pre_comp_done_ = 0; |
| 144 | |
| 145 | std::vector<DrmHwcLayer> layers_; |
| 146 | std::vector<DrmCompositionRegion> squash_regions_; |
| 147 | std::vector<DrmCompositionRegion> pre_comp_regions_; |
| 148 | std::vector<DrmCompositionPlane> composition_planes_; |
| 149 | |
| 150 | uint64_t frame_no_ = 0; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 151 | }; |
| 152 | } |
| 153 | |
| 154 | #endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_ |