blob: 04c0baeff2834cd12b5b346c2def3a59ca454fb8 [file] [log] [blame]
Sean Paul98e73c82015-06-24 14:38:49 -07001/*
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
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030020#include <hardware/hardware.h>
21#include <hardware/hwcomposer.h>
Sean Paul98e73c82015-06-24 14:38:49 -070022#include <pthread.h>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030023
Roman Stratiienkod21071f2021-03-09 21:56:50 +020024#include <functional>
Zach Reizner92f8e632015-10-12 17:47:13 -070025#include <memory>
Sean Paul98e73c82015-06-24 14:38:49 -070026#include <sstream>
Zach Reizner92f8e632015-10-12 17:47:13 -070027#include <tuple>
Sean Paul98e73c82015-06-24 14:38:49 -070028
Roman Stratiienko13cc3662020-08-29 21:35:39 +030029#include "DrmDisplayComposition.h"
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030030#include "Planner.h"
Roman Stratiienko13cc3662020-08-29 21:35:39 +030031#include "drm/ResourceManager.h"
32#include "drm/VSyncWorker.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030033#include "drmhwcomposer.h"
Sean Paul98e73c82015-06-24 14:38:49 -070034
35namespace android {
36
37class DrmDisplayCompositor {
38 public:
39 DrmDisplayCompositor();
40 ~DrmDisplayCompositor();
41
Roman Stratiienkoe8c06792021-09-30 10:09:31 +030042 auto Init(ResourceManager *resource_manager, int display) -> int;
Roman Kovalivskyi8fae1562020-01-30 20:20:47 +020043
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +010044 std::unique_ptr<DrmDisplayComposition> CreateInitializedComposition() const;
Sean Pauled45a8e2017-02-28 13:17:34 -050045 int ApplyComposition(std::unique_ptr<DrmDisplayComposition> composition);
Rob Herring4f6c62e2018-05-17 14:33:02 -050046 int TestComposition(DrmDisplayComposition *composition);
Sean Paul98e73c82015-06-24 14:38:49 -070047 int Composite();
48 void Dump(std::ostringstream *out) const;
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030049 void ClearDisplay();
Roman Stratiienko0fade372021-02-20 13:59:55 +020050 UniqueFd TakeOutFence() {
51 if (!active_composition_) {
52 return UniqueFd();
53 }
54 return std::move(active_composition_->out_fence_);
Matteo Franchinc56eede2019-12-03 17:10:38 +000055 }
Sean Paul98e73c82015-06-24 14:38:49 -070056
Zach Reizner92f8e632015-10-12 17:47:13 -070057 std::tuple<uint32_t, uint32_t, int> GetActiveModeResolution();
58
Sean Paul98e73c82015-06-24 14:38:49 -070059 private:
Sean Paul35301f42015-11-17 14:46:56 -050060 struct ModeState {
61 bool needs_modeset = false;
62 DrmMode mode;
63 uint32_t blob_id = 0;
64 uint32_t old_blob_id = 0;
65 };
66
Sean Paul98e73c82015-06-24 14:38:49 -070067 DrmDisplayCompositor(const DrmDisplayCompositor &) = delete;
68
Sean Paul971be152015-10-13 15:44:45 -040069 // We'll wait for acquire fences to fire for kAcquireWaitTimeoutMs,
70 // kAcquireWaitTries times, logging a warning in between.
71 static const int kAcquireWaitTries = 5;
72 static const int kAcquireWaitTimeoutMs = 100;
Sean Pauld106b912015-09-29 00:56:00 -040073
Roman Stratiienko74774712021-02-05 16:32:47 +020074 int CommitFrame(DrmDisplayComposition *display_comp, bool test_only);
Sean Pauldb7a17d2015-06-24 18:46:05 -070075 int ApplyDpms(DrmDisplayComposition *display_comp);
Sean Paul7b1e4bc2015-10-13 15:47:22 -040076 int DisablePlanes(DrmDisplayComposition *display_comp);
Sean Paul98e73c82015-06-24 14:38:49 -070077
Haixia Shidda2fab2015-10-22 18:12:49 -070078 void ApplyFrame(std::unique_ptr<DrmDisplayComposition> composition,
Roman Stratiienko74774712021-02-05 16:32:47 +020079 int status);
Roman Kovalivskyi8fae1562020-01-30 20:20:47 +020080
Sean Paul35301f42015-11-17 14:46:56 -050081 std::tuple<int, uint32_t> CreateModeBlob(const DrmMode &mode);
82
Alexandru Gheorghe6f0030f2018-05-01 17:25:48 +010083 ResourceManager *resource_manager_;
Sean Paul98e73c82015-06-24 14:38:49 -070084 int display_;
85
Sean Paul98e73c82015-06-24 14:38:49 -070086 std::unique_ptr<DrmDisplayComposition> active_composition_;
87
Sean Paul98e73c82015-06-24 14:38:49 -070088 bool initialized_;
Sean Pauldb7a17d2015-06-24 18:46:05 -070089 bool active_;
Sean Paul6c18b3b2015-11-25 11:04:25 -050090 bool use_hw_overlays_;
Sean Paul98e73c82015-06-24 14:38:49 -070091
Sean Paul35301f42015-11-17 14:46:56 -050092 ModeState mode_;
Sean Paul57355412015-09-19 09:14:34 -040093
Sean Paul98e73c82015-06-24 14:38:49 -070094 // State tracking progress since our last Dump(). These are mutable since
95 // we need to reset them on every Dump() call.
96 mutable uint64_t dump_frames_composited_;
97 mutable uint64_t dump_last_timestamp_ns_;
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +010098 std::unique_ptr<Planner> planner_;
Sean Paul98e73c82015-06-24 14:38:49 -070099};
Sean Paulf72cccd2018-08-27 13:59:08 -0400100} // namespace android
Sean Paul98e73c82015-06-24 14:38:49 -0700101
102#endif // ANDROID_DRM_DISPLAY_COMPOSITOR_H_