• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 #pragma once
18 
19 #include <cstring>
20 #include <mutex>
21 
22 #include "DrmDevice.h"
23 #include "DrmDisplayPipeline.h"
24 #include "DrmFbImporter.h"
25 #include "UEventListener.h"
26 
27 namespace android {
28 
29 enum class CtmHandling {
30   kDrmOrGpu,    /* Handled by DRM is possible, otherwise by GPU */
31   kDrmOrIgnore, /* Handled by DRM is possible, otherwise displayed as is */
32 };
33 
34 class PipelineToFrontendBindingInterface {
35  public:
36   virtual ~PipelineToFrontendBindingInterface() = default;
37   virtual bool BindDisplay(std::shared_ptr<DrmDisplayPipeline>);
38   virtual bool UnbindDisplay(std::shared_ptr<DrmDisplayPipeline>);
39   virtual void FinalizeDisplayBinding();
40 };
41 
42 class ResourceManager {
43  public:
44   explicit ResourceManager(
45       PipelineToFrontendBindingInterface *p2f_bind_interface);
46   ResourceManager(const ResourceManager &) = delete;
47   ResourceManager &operator=(const ResourceManager &) = delete;
48   ResourceManager(const ResourceManager &&) = delete;
49   ResourceManager &&operator=(const ResourceManager &&) = delete;
50   ~ResourceManager() = default;
51 
52   void Init();
53 
54   void DeInit();
55 
ForcedScalingWithGpu()56   bool ForcedScalingWithGpu() const {
57     return scale_with_gpu_;
58   }
59 
GetCtmHandling()60   auto &GetCtmHandling() const {
61     return ctm_handling_;
62   }
63 
GetMainLock()64   auto &GetMainLock() {
65     return main_lock_;
66   }
67 
68   auto GetVirtualDisplayPipeline() -> std::shared_ptr<DrmDisplayPipeline>;
69   auto GetWritebackConnectorsCount() -> uint32_t;
70 
71   static auto GetTimeMonotonicNs() -> int64_t;
72 
73  private:
74   auto GetOrderedConnectors() -> std::vector<DrmConnector *>;
75   void UpdateFrontendDisplays();
76   void DetachAllFrontendDisplays();
77 
78   std::vector<std::unique_ptr<DrmDevice>> drms_;
79 
80   // Android properties:
81   bool scale_with_gpu_{};
82   CtmHandling ctm_handling_{};
83 
84   std::shared_ptr<UEventListener> uevent_listener_;
85 
86   std::recursive_mutex main_lock_;
87 
88   std::map<DrmConnector *, std::shared_ptr<DrmDisplayPipeline>>
89       attached_pipelines_;
90 
91   PipelineToFrontendBindingInterface *const frontend_interface_;
92 
93   bool initialized_{};
94 };
95 }  // namespace android
96