blob: 08a1c137fd4943fc9d609b33e384f556333f7f4e [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
Roman Stratiienko4e994052022-02-09 17:40:35 +020017#ifndef ANDROID_DRM_ATOMIC_STATE_MANAGER_H_
18#define ANDROID_DRM_ATOMIC_STATE_MANAGER_H_
Sean Paul98e73c82015-06-24 14:38:49 -070019
Sean Paul98e73c82015-06-24 14:38:49 -070020#include <pthread.h>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030021
Roman Stratiienkod21071f2021-03-09 21:56:50 +020022#include <functional>
Zach Reizner92f8e632015-10-12 17:47:13 -070023#include <memory>
Roman Stratiienkof81d2c82022-01-11 19:47:24 +020024#include <optional>
Sean Paul98e73c82015-06-24 14:38:49 -070025#include <sstream>
Zach Reizner92f8e632015-10-12 17:47:13 -070026#include <tuple>
Sean Paul98e73c82015-06-24 14:38:49 -070027
Roman Stratiienko4e994052022-02-09 17:40:35 +020028#include "compositor/DrmKmsPlan.h"
Roman Stratiienko9362cef2022-02-02 09:53:50 +020029#include "drm/DrmPlane.h"
Roman Stratiienko13cc3662020-08-29 21:35:39 +030030#include "drm/ResourceManager.h"
31#include "drm/VSyncWorker.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030032#include "drmhwcomposer.h"
Sean Paul98e73c82015-06-24 14:38:49 -070033
34namespace android {
35
Roman Stratiienkodccc6fb2021-10-23 17:35:44 +030036struct AtomicCommitArgs {
37 /* inputs. All fields are optional, but at least one has to be specified */
38 bool test_only = false;
39 std::optional<DrmMode> display_mode;
40 std::optional<bool> active;
Roman Stratiienko9362cef2022-02-02 09:53:50 +020041 std::shared_ptr<DrmKmsPlan> composition;
Roman Stratiienkodccc6fb2021-10-23 17:35:44 +030042
43 /* out */
44 UniqueFd out_fence;
45
46 /* helpers */
47 auto HasInputs() -> bool {
Roman Stratiienkoef5348b2022-02-09 17:19:56 +020048 return display_mode || active || composition;
Roman Stratiienkodccc6fb2021-10-23 17:35:44 +030049 }
50};
51
Roman Stratiienko4e994052022-02-09 17:40:35 +020052class DrmAtomicStateManager {
Sean Paul98e73c82015-06-24 14:38:49 -070053 public:
Roman Stratiienko4e994052022-02-09 17:40:35 +020054 explicit DrmAtomicStateManager(DrmDisplayPipeline *pipe) : pipe_(pipe){};
55 DrmAtomicStateManager(const DrmAtomicStateManager &) = delete;
56 ~DrmAtomicStateManager() = default;
Roman Kovalivskyi8fae1562020-01-30 20:20:47 +020057
Roman Stratiienkodccc6fb2021-10-23 17:35:44 +030058 auto ExecuteAtomicCommit(AtomicCommitArgs &args) -> int;
Roman Stratiienkod37b3082022-01-13 16:37:27 +020059 auto ActivateDisplayUsingDPMS() -> int;
60
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020061 private:
Roman Stratiienkodccc6fb2021-10-23 17:35:44 +030062 auto CommitFrame(AtomicCommitArgs &args) -> int;
Sean Paul98e73c82015-06-24 14:38:49 -070063
Roman Stratiienko32685ba2021-12-15 13:46:05 +020064 struct KmsState {
65 /* Required to cleanup unused planes */
Roman Stratiienko9362cef2022-02-02 09:53:50 +020066 std::vector<std::shared_ptr<BindingOwner<DrmPlane>>> used_planes;
Roman Stratiienko32685ba2021-12-15 13:46:05 +020067 /* We have to hold a reference to framebuffer while displaying it ,
68 * otherwise picture will blink */
69 std::vector<std::shared_ptr<DrmFbIdHandle>> used_framebuffers;
70
Roman Stratiienkodccc6fb2021-10-23 17:35:44 +030071 DrmModeUserPropertyBlobUnique mode_blob;
Roman Stratiienko32685ba2021-12-15 13:46:05 +020072
73 /* To avoid setting the inactive state twice, which will fail the commit */
74 bool crtc_active_state{};
Roman Stratiienkof815d382021-12-30 19:23:14 +020075 } active_frame_state_;
Roman Stratiienko32685ba2021-12-15 13:46:05 +020076
77 auto NewFrameState() -> KmsState {
78 return (KmsState){
Roman Stratiienkof815d382021-12-30 19:23:14 +020079 .used_planes = active_frame_state_.used_planes,
80 .used_framebuffers = active_frame_state_.used_framebuffers,
81 .crtc_active_state = active_frame_state_.crtc_active_state,
Roman Stratiienko32685ba2021-12-15 13:46:05 +020082 };
83 }
Sean Paul98e73c82015-06-24 14:38:49 -070084
Roman Stratiienko19c162f2022-02-01 09:35:08 +020085 DrmDisplayPipeline *const pipe_;
Sean Paul98e73c82015-06-24 14:38:49 -070086};
Sean Paulf72cccd2018-08-27 13:59:08 -040087} // namespace android
Sean Paul98e73c82015-06-24 14:38:49 -070088
89#endif // ANDROID_DRM_DISPLAY_COMPOSITOR_H_