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_COMPOSITOR_H_ |
| 18 | #define ANDROID_DRM_DISPLAY_COMPOSITOR_H_ |
| 19 | |
Zach Reizner | 7642c92 | 2015-10-29 10:11:16 -0700 | [diff] [blame] | 20 | #include "drmhwcomposer.h" |
Sean Paul | ed45a8e | 2017-02-28 13:17:34 -0500 | [diff] [blame] | 21 | #include "drmdisplaycomposition.h" |
Zach Reizner | 713a678 | 2015-07-31 15:12:44 -0700 | [diff] [blame] | 22 | #include "drmframebuffer.h" |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 23 | |
| 24 | #include <pthread.h> |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 25 | #include <memory> |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 26 | #include <sstream> |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 27 | #include <tuple> |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 28 | |
| 29 | #include <hardware/hardware.h> |
| 30 | #include <hardware/hwcomposer.h> |
| 31 | |
Sean Paul | 647beb2 | 2015-11-19 13:55:48 -0500 | [diff] [blame] | 32 | // One for the front, one for the back, and one for cases where we need to |
| 33 | // squash a frame that the hw can't display with hw overlays. |
| 34 | #define DRM_DISPLAY_BUFFERS 3 |
Zach Reizner | 713a678 | 2015-07-31 15:12:44 -0700 | [diff] [blame] | 35 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 36 | namespace android { |
| 37 | |
| 38 | class DrmDisplayCompositor { |
| 39 | public: |
| 40 | DrmDisplayCompositor(); |
| 41 | ~DrmDisplayCompositor(); |
| 42 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame^] | 43 | int Init(DrmDevice *drm, int display); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 44 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 45 | std::unique_ptr<DrmDisplayComposition> CreateComposition() const; |
Sean Paul | ed45a8e | 2017-02-28 13:17:34 -0500 | [diff] [blame] | 46 | int ApplyComposition(std::unique_ptr<DrmDisplayComposition> composition); |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 47 | int TestComposition(DrmDisplayComposition *composition); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 48 | int Composite(); |
| 49 | void Dump(std::ostringstream *out) const; |
| 50 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 51 | std::tuple<uint32_t, uint32_t, int> GetActiveModeResolution(); |
| 52 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 53 | private: |
Sean Paul | 35301f4 | 2015-11-17 14:46:56 -0500 | [diff] [blame] | 54 | struct ModeState { |
| 55 | bool needs_modeset = false; |
| 56 | DrmMode mode; |
| 57 | uint32_t blob_id = 0; |
| 58 | uint32_t old_blob_id = 0; |
| 59 | }; |
| 60 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 61 | DrmDisplayCompositor(const DrmDisplayCompositor &) = delete; |
| 62 | |
Sean Paul | 971be15 | 2015-10-13 15:44:45 -0400 | [diff] [blame] | 63 | // We'll wait for acquire fences to fire for kAcquireWaitTimeoutMs, |
| 64 | // kAcquireWaitTries times, logging a warning in between. |
| 65 | static const int kAcquireWaitTries = 5; |
| 66 | static const int kAcquireWaitTimeoutMs = 100; |
Sean Paul | d106b91 | 2015-09-29 00:56:00 -0400 | [diff] [blame] | 67 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 68 | int PrepareFramebuffer(DrmFramebuffer &fb, |
| 69 | DrmDisplayComposition *display_comp); |
Haixia Shi | dda2fab | 2015-10-22 18:12:49 -0700 | [diff] [blame] | 70 | int PrepareFrame(DrmDisplayComposition *display_comp); |
Sean Paul | c07b211 | 2015-11-17 16:38:10 -0500 | [diff] [blame] | 71 | int CommitFrame(DrmDisplayComposition *display_comp, bool test_only); |
Sean Paul | db7a17d | 2015-06-24 18:46:05 -0700 | [diff] [blame] | 72 | int ApplyDpms(DrmDisplayComposition *display_comp); |
Sean Paul | 7b1e4bc | 2015-10-13 15:47:22 -0400 | [diff] [blame] | 73 | int DisablePlanes(DrmDisplayComposition *display_comp); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 74 | |
Sean Paul | 137a6a8 | 2016-06-22 22:48:22 -0400 | [diff] [blame] | 75 | void ClearDisplay(); |
Haixia Shi | dda2fab | 2015-10-22 18:12:49 -0700 | [diff] [blame] | 76 | void ApplyFrame(std::unique_ptr<DrmDisplayComposition> composition, |
| 77 | int status); |
| 78 | |
Sean Paul | 35301f4 | 2015-11-17 14:46:56 -0500 | [diff] [blame] | 79 | std::tuple<int, uint32_t> CreateModeBlob(const DrmMode &mode); |
| 80 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame^] | 81 | DrmDevice *drm_; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 82 | int display_; |
| 83 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 84 | std::unique_ptr<DrmDisplayComposition> active_composition_; |
| 85 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 86 | bool initialized_; |
Sean Paul | db7a17d | 2015-06-24 18:46:05 -0700 | [diff] [blame] | 87 | bool active_; |
Sean Paul | 6c18b3b | 2015-11-25 11:04:25 -0500 | [diff] [blame] | 88 | bool use_hw_overlays_; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 89 | |
Sean Paul | 35301f4 | 2015-11-17 14:46:56 -0500 | [diff] [blame] | 90 | ModeState mode_; |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame] | 91 | |
Zach Reizner | 713a678 | 2015-07-31 15:12:44 -0700 | [diff] [blame] | 92 | int framebuffer_index_; |
| 93 | DrmFramebuffer framebuffers_[DRM_DISPLAY_BUFFERS]; |
Zach Reizner | 5757e82 | 2015-10-16 19:06:31 -0700 | [diff] [blame] | 94 | |
Sean Paul | ed45a8e | 2017-02-28 13:17:34 -0500 | [diff] [blame] | 95 | // mutable since we need to acquire in Dump() |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 96 | mutable pthread_mutex_t lock_; |
| 97 | |
| 98 | // State tracking progress since our last Dump(). These are mutable since |
| 99 | // we need to reset them on every Dump() call. |
| 100 | mutable uint64_t dump_frames_composited_; |
| 101 | mutable uint64_t dump_last_timestamp_ns_; |
| 102 | }; |
| 103 | } |
| 104 | |
| 105 | #endif // ANDROID_DRM_DISPLAY_COMPOSITOR_H_ |