OSDN Git Service

drm_hwcomposer: Remove supported()/unsupported() functions
[android-x86/external-drm_hwcomposer.git] / compositor / DrmDisplayCompositor.h
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
20 #include <hardware/hardware.h>
21 #include <hardware/hwcomposer.h>
22 #include <pthread.h>
23
24 #include <functional>
25 #include <memory>
26 #include <sstream>
27 #include <tuple>
28
29 #include "DrmDisplayComposition.h"
30 #include "Planner.h"
31 #include "drm/ResourceManager.h"
32 #include "drm/VSyncWorker.h"
33 #include "drmhwcomposer.h"
34
35 namespace android {
36
37 struct 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
55 class DrmDisplayCompositor {
56  public:
57   DrmDisplayCompositor() = default;
58   ~DrmDisplayCompositor() = default;
59   auto Init(ResourceManager *resource_manager, int display) -> int;
60
61   std::unique_ptr<DrmDisplayComposition> CreateInitializedComposition() const;
62
63   auto ExecuteAtomicCommit(AtomicCommitArgs &args) -> int;
64
65  private:
66   DrmDisplayCompositor(const DrmDisplayCompositor &) = delete;
67
68   auto CommitFrame(AtomicCommitArgs &args) -> int;
69
70   struct KmsState {
71     /* Required to cleanup unused planes */
72     std::vector<DrmPlane *> used_planes;
73     /* We have to hold a reference to framebuffer while displaying it ,
74      * otherwise picture will blink */
75     std::vector<std::shared_ptr<DrmFbIdHandle>> used_framebuffers;
76
77     DrmModeUserPropertyBlobUnique mode_blob;
78
79     /* To avoid setting the inactive state twice, which will fail the commit */
80     bool crtc_active_state{};
81   } active_frame_state;
82
83   auto NewFrameState() -> KmsState {
84     return (KmsState){
85         .used_planes = active_frame_state.used_planes,
86         .used_framebuffers = active_frame_state.used_framebuffers,
87         .crtc_active_state = active_frame_state.crtc_active_state,
88     };
89   }
90
91   ResourceManager *resource_manager_ = nullptr;
92   std::unique_ptr<Planner> planner_;
93   bool initialized_{};
94   int display_ = -1;
95 };
96 }  // namespace android
97
98 #endif  // ANDROID_DRM_DISPLAY_COMPOSITOR_H_