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 | |
Sean Paul | acb2a44 | 2015-06-24 18:43:01 -0700 | [diff] [blame] | 34 | enum DrmCompositionType { |
| 35 | DRM_COMPOSITION_TYPE_EMPTY, |
| 36 | DRM_COMPOSITION_TYPE_FRAME, |
Sean Paul | db7a17d | 2015-06-24 18:46:05 -0700 | [diff] [blame] | 37 | DRM_COMPOSITION_TYPE_DPMS, |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame^] | 38 | DRM_COMPOSITION_TYPE_MODESET, |
Sean Paul | acb2a44 | 2015-06-24 18:43:01 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 41 | struct DrmCompositionLayer { |
| 42 | DrmCrtc *crtc = NULL; |
| 43 | DrmPlane *plane = NULL; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 44 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 45 | buffer_handle_t sf_handle = NULL; |
| 46 | DrmHwcBuffer buffer; |
| 47 | DrmHwcNativeHandle handle; |
| 48 | DrmHwcTransform transform = DrmHwcTransform::kIdentity; |
| 49 | DrmHwcBlending blending = DrmHwcBlending::kNone; |
| 50 | uint8_t alpha = 0xff; |
| 51 | DrmHwcRect<float> source_crop; |
| 52 | DrmHwcRect<int> display_frame; |
| 53 | std::vector<DrmHwcRect<int>> source_damage; |
| 54 | |
| 55 | UniqueFd acquire_fence; |
| 56 | |
| 57 | DrmCompositionLayer() = default; |
| 58 | DrmCompositionLayer(DrmCrtc *crtc, DrmHwcLayer &&l); |
| 59 | DrmCompositionLayer(DrmCompositionLayer &&l) = default; |
| 60 | |
| 61 | DrmCompositionLayer &operator=(DrmCompositionLayer &&l) = default; |
| 62 | |
| 63 | buffer_handle_t get_usable_handle() const { |
| 64 | return handle.get() != NULL ? handle.get() : sf_handle; |
| 65 | } |
| 66 | }; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 67 | |
| 68 | class DrmDisplayComposition { |
| 69 | public: |
| 70 | DrmDisplayComposition(); |
| 71 | ~DrmDisplayComposition(); |
| 72 | |
Sean Paul | bdc67bf | 2015-09-21 10:04:02 -0400 | [diff] [blame] | 73 | int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer, |
| 74 | uint64_t frame_no); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 75 | |
Sean Paul | acb2a44 | 2015-06-24 18:43:01 -0700 | [diff] [blame] | 76 | DrmCompositionType type() const; |
| 77 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 78 | int SetLayers(DrmHwcLayer *layers, size_t num_layers, |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 79 | std::vector<DrmPlane *> *primary_planes, |
| 80 | std::vector<DrmPlane *> *overlay_planes); |
Sean Paul | 2e46fbd | 2015-07-09 17:22:22 -0400 | [diff] [blame] | 81 | int AddPlaneDisable(DrmPlane *plane); |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 82 | int SetDpmsMode(uint32_t dpms_mode); |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame^] | 83 | int SetDisplayMode(const DrmMode &display_mode); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 84 | |
Zach Reizner | b44fd10 | 2015-08-07 16:00:01 -0700 | [diff] [blame] | 85 | void RemoveNoPlaneLayers(); |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 86 | int SignalPreCompositionDone(); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 87 | int FinishComposition(); |
| 88 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 89 | std::vector<DrmCompositionLayer> *GetCompositionLayers(); |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 90 | int pre_composition_layer_index() const; |
Sean Paul | db7a17d | 2015-06-24 18:46:05 -0700 | [diff] [blame] | 91 | uint32_t dpms_mode() const; |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame^] | 92 | const DrmMode &display_mode() const; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 93 | |
Sean Paul | bdc67bf | 2015-09-21 10:04:02 -0400 | [diff] [blame] | 94 | uint64_t frame_no() const; |
| 95 | |
Zach Reizner | 46ddd45 | 2015-07-30 08:10:14 -0700 | [diff] [blame] | 96 | Importer *importer() const; |
| 97 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 98 | private: |
| 99 | DrmDisplayComposition(const DrmDisplayComposition &) = delete; |
| 100 | |
Sean Paul | acb2a44 | 2015-06-24 18:43:01 -0700 | [diff] [blame] | 101 | bool validate_composition_type(DrmCompositionType desired); |
| 102 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 103 | int CreateNextTimelineFence(); |
| 104 | int IncreaseTimelineToPoint(int point); |
| 105 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 106 | DrmResources *drm_; |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 107 | DrmCrtc *crtc_; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 108 | Importer *importer_; |
Zach Reizner | b44fd10 | 2015-08-07 16:00:01 -0700 | [diff] [blame] | 109 | const gralloc_module_t *gralloc_; |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 110 | EGLDisplay egl_display_; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 111 | |
Sean Paul | acb2a44 | 2015-06-24 18:43:01 -0700 | [diff] [blame] | 112 | DrmCompositionType type_; |
| 113 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 114 | int timeline_fd_; |
| 115 | int timeline_; |
Zach Reizner | ece0489 | 2015-07-17 14:13:28 -0700 | [diff] [blame] | 116 | int timeline_current_; |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 117 | int timeline_pre_comp_done_; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 118 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 119 | std::vector<DrmCompositionLayer> layers_; |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 120 | int pre_composition_layer_index_; |
Sean Paul | db7a17d | 2015-06-24 18:46:05 -0700 | [diff] [blame] | 121 | uint32_t dpms_mode_; |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame^] | 122 | DrmMode display_mode_; |
Sean Paul | bdc67bf | 2015-09-21 10:04:02 -0400 | [diff] [blame] | 123 | |
| 124 | uint64_t frame_no_; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 125 | }; |
| 126 | } |
| 127 | |
| 128 | #endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_ |