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 | acb2a44 | 2015-06-24 18:43:01 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 40 | typedef struct DrmCompositionLayer { |
| 41 | DrmCompositionLayer(); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 42 | |
| 43 | hwc_layer_1_t layer; |
| 44 | hwc_drm_bo_t bo; |
| 45 | DrmCrtc *crtc; |
| 46 | DrmPlane *plane; |
Zach Reizner | b44fd10 | 2015-08-07 16:00:01 -0700 | [diff] [blame] | 47 | native_handle_t *handle; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 48 | } DrmCompositionLayer_t; |
| 49 | typedef std::vector<DrmCompositionLayer_t> DrmCompositionLayerVector_t; |
| 50 | |
| 51 | class DrmDisplayComposition { |
| 52 | public: |
| 53 | DrmDisplayComposition(); |
| 54 | ~DrmDisplayComposition(); |
| 55 | |
Sean Paul | bdc67bf | 2015-09-21 10:04:02 -0400 | [diff] [blame^] | 56 | int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer, |
| 57 | uint64_t frame_no); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 58 | |
Sean Paul | acb2a44 | 2015-06-24 18:43:01 -0700 | [diff] [blame] | 59 | DrmCompositionType type() const; |
| 60 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 61 | int SetLayers(hwc_layer_1_t *layers, size_t num_layers, size_t *layer_indices, |
| 62 | std::vector<DrmPlane *> *primary_planes, |
| 63 | std::vector<DrmPlane *> *overlay_planes); |
Sean Paul | 2e46fbd | 2015-07-09 17:22:22 -0400 | [diff] [blame] | 64 | int AddPlaneDisable(DrmPlane *plane); |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 65 | int SetDpmsMode(uint32_t dpms_mode); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 66 | |
Zach Reizner | b44fd10 | 2015-08-07 16:00:01 -0700 | [diff] [blame] | 67 | void RemoveNoPlaneLayers(); |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 68 | int SignalPreCompositionDone(); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 69 | int FinishComposition(); |
| 70 | |
| 71 | DrmCompositionLayerVector_t *GetCompositionLayers(); |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 72 | int pre_composition_layer_index() const; |
Sean Paul | db7a17d | 2015-06-24 18:46:05 -0700 | [diff] [blame] | 73 | uint32_t dpms_mode() const; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 74 | |
Sean Paul | bdc67bf | 2015-09-21 10:04:02 -0400 | [diff] [blame^] | 75 | uint64_t frame_no() const; |
| 76 | |
Zach Reizner | 46ddd45 | 2015-07-30 08:10:14 -0700 | [diff] [blame] | 77 | Importer *importer() const; |
| 78 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 79 | private: |
| 80 | DrmDisplayComposition(const DrmDisplayComposition &) = delete; |
| 81 | |
Sean Paul | acb2a44 | 2015-06-24 18:43:01 -0700 | [diff] [blame] | 82 | bool validate_composition_type(DrmCompositionType desired); |
| 83 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 84 | int CreateNextTimelineFence(); |
| 85 | int IncreaseTimelineToPoint(int point); |
| 86 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 87 | DrmResources *drm_; |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 88 | DrmCrtc *crtc_; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 89 | Importer *importer_; |
Zach Reizner | b44fd10 | 2015-08-07 16:00:01 -0700 | [diff] [blame] | 90 | const gralloc_module_t *gralloc_; |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 91 | EGLDisplay egl_display_; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 92 | |
Sean Paul | acb2a44 | 2015-06-24 18:43:01 -0700 | [diff] [blame] | 93 | DrmCompositionType type_; |
| 94 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 95 | int timeline_fd_; |
| 96 | int timeline_; |
Zach Reizner | ece0489 | 2015-07-17 14:13:28 -0700 | [diff] [blame] | 97 | int timeline_current_; |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 98 | int timeline_pre_comp_done_; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 99 | |
| 100 | DrmCompositionLayerVector_t layers_; |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 101 | int pre_composition_layer_index_; |
Sean Paul | db7a17d | 2015-06-24 18:46:05 -0700 | [diff] [blame] | 102 | uint32_t dpms_mode_; |
Sean Paul | bdc67bf | 2015-09-21 10:04:02 -0400 | [diff] [blame^] | 103 | |
| 104 | uint64_t frame_no_; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 105 | }; |
| 106 | } |
| 107 | |
| 108 | #endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_ |