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