blob: bff3de73bd729387b370aa9f45a04c449db5d817 [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>
Roman Stratiienkof81d2c82022-01-11 19:47:24 +020026#include <optional>
Sean Paul98e73c82015-06-24 14:38:49 -070027#include <sstream>
Zach Reizner92f8e632015-10-12 17:47:13 -070028#include <tuple>
Sean Paul98e73c82015-06-24 14:38:49 -070029
Roman Stratiienko13cc3662020-08-29 21:35:39 +030030#include "DrmDisplayComposition.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
Roman Stratiienkodccc6fb2021-10-23 17:35:44 +030037struct AtomicCommitArgs {
38 /* inputs. All fields are optional, but at least one has to be specified */
39 bool test_only = false;
40 std::optional<DrmMode> display_mode;
41 std::optional<bool> active;
42 std::shared_ptr<DrmDisplayComposition> composition;
43 /* 'clear' should never be used together with 'composition' */
44 bool clear_active_composition = false;
45
46 /* out */
47 UniqueFd out_fence;
48
49 /* helpers */
50 auto HasInputs() -> bool {
51 return display_mode || active || composition || clear_active_composition;
52 }
53};
54
Sean Paul98e73c82015-06-24 14:38:49 -070055class DrmDisplayCompositor {
56 public:
Roman Stratiienko19c162f2022-02-01 09:35:08 +020057 explicit DrmDisplayCompositor(DrmDisplayPipeline *pipe) : pipe_(pipe){};
Roman Stratiienkodccc6fb2021-10-23 17:35:44 +030058 ~DrmDisplayCompositor() = default;
Roman Kovalivskyi8fae1562020-01-30 20:20:47 +020059
Roman Stratiienkodccc6fb2021-10-23 17:35:44 +030060 auto ExecuteAtomicCommit(AtomicCommitArgs &args) -> int;
Sean Paul98e73c82015-06-24 14:38:49 -070061
Sean Paul98e73c82015-06-24 14:38:49 -070062 DrmDisplayCompositor(const DrmDisplayCompositor &) = delete;
63
Roman Stratiienkod37b3082022-01-13 16:37:27 +020064 auto ActivateDisplayUsingDPMS() -> int;
65
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020066 private:
Roman Stratiienkodccc6fb2021-10-23 17:35:44 +030067 auto CommitFrame(AtomicCommitArgs &args) -> int;
Sean Paul98e73c82015-06-24 14:38:49 -070068
Roman Stratiienko32685ba2021-12-15 13:46:05 +020069 struct KmsState {
70 /* Required to cleanup unused planes */
71 std::vector<DrmPlane *> used_planes;
72 /* We have to hold a reference to framebuffer while displaying it ,
73 * otherwise picture will blink */
74 std::vector<std::shared_ptr<DrmFbIdHandle>> used_framebuffers;
75
Roman Stratiienkodccc6fb2021-10-23 17:35:44 +030076 DrmModeUserPropertyBlobUnique mode_blob;
Roman Stratiienko32685ba2021-12-15 13:46:05 +020077
78 /* To avoid setting the inactive state twice, which will fail the commit */
79 bool crtc_active_state{};
Roman Stratiienkof815d382021-12-30 19:23:14 +020080 } active_frame_state_;
Roman Stratiienko32685ba2021-12-15 13:46:05 +020081
82 auto NewFrameState() -> KmsState {
83 return (KmsState){
Roman Stratiienkof815d382021-12-30 19:23:14 +020084 .used_planes = active_frame_state_.used_planes,
85 .used_framebuffers = active_frame_state_.used_framebuffers,
86 .crtc_active_state = active_frame_state_.crtc_active_state,
Roman Stratiienko32685ba2021-12-15 13:46:05 +020087 };
88 }
Sean Paul98e73c82015-06-24 14:38:49 -070089
Roman Stratiienko19c162f2022-02-01 09:35:08 +020090 DrmDisplayPipeline *const pipe_;
Sean Paul98e73c82015-06-24 14:38:49 -070091};
Sean Paulf72cccd2018-08-27 13:59:08 -040092} // namespace android
Sean Paul98e73c82015-06-24 14:38:49 -070093
94#endif // ANDROID_DRM_DISPLAY_COMPOSITOR_H_