OSDN Git Service

2f9d5198d32a8d0f7e9988384ff728f025528329
[android-x86/external-IA-Hardware-Composer.git] / public / gpudevice.h
1 /*
2 // Copyright (c) 2016 Intel Corporation
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 PUBLIC_GPUDEVICE_H_
18 #define PUBLIC_GPUDEVICE_H_
19
20 #ifndef HWC_LOCK_FILE
21 #define HWC_LOCK_FILE "/vendor/hwc.lock"
22 #endif
23
24 #include <stdint.h>
25 #include <fstream>
26 #include <sstream>
27 #include <string>
28
29 #include "displaymanager.h"
30 #include "framebuffermanager.h"
31 #include "hwcthread.h"
32 #include "logicaldisplaymanager.h"
33 #include "nativedisplay.h"
34
35 namespace hwcomposer {
36
37 class NativeDisplay;
38
39 class GpuDevice : public HWCThread {
40  public:
41   static GpuDevice& getInstance();
42
43  public:
44   virtual ~GpuDevice();
45
46   // Open device.
47   bool Initialize();
48
49   FrameBufferManager* GetFrameBufferManager();
50
51   uint32_t GetFD() const;
52
53   NativeDisplay* GetDisplay(uint32_t display);
54
55   NativeDisplay* CreateVirtualDisplay(uint32_t display_index);
56   void DestroyVirtualDisplay(uint32_t display_index);
57
58   // This display can be a client preparing
59   // content which will eventually shown by
60   // another parent display.
61
62   void GetConnectedPhysicalDisplays(std::vector<NativeDisplay*>& displays);
63
64   const std::vector<NativeDisplay*>& GetAllDisplays();
65
66   void RegisterHotPlugEventCallback(
67       std::shared_ptr<DisplayHotPlugEventCallback> callback);
68
69   // Enables the usage of HDCP for all planes supporting this feature
70   // on display. Some displays can support latest HDCP specification and also
71   // have ability to fallback to older specifications i.e. HDCP 2.2 and 1.4
72   // in case latest speicification cannot be supported for some reason.
73   // Content type is defined by content_type.
74   void EnableHDCPSessionForDisplay(uint32_t connector,
75                                    HWCContentType content_type);
76
77   // Enables the usage of HDCP for all planes supporting this feature
78   // on all connected displays. Some displays can support latest HDCP
79   // specification and also have ability to fallback to older
80   // specifications i.e. HDCP 2.2 and 1.4 in case latest speicification
81   // cannot be supported for some reason. Content type is defined by
82   // content_type.
83   void EnableHDCPSessionForAllDisplays(HWCContentType content_type);
84
85   // The control disables the usage of HDCP for all planes supporting this
86   // feature on display.
87   void DisableHDCPSessionForDisplay(uint32_t connector);
88
89   // The control disables the usage of HDCP for all planes supporting this
90   // feature on all connected displays.
91   void DisableHDCPSessionForAllDisplays();
92
93   void SetPAVPSessionStatus(bool enabled, uint32_t pavp_session_id,
94                             uint32_t pavp_instance_id);
95   void SetHDCPSRMForAllDisplays(const int8_t* SRM, uint32_t SRMLength);
96   void SetHDCPSRMForDisplay(uint32_t connector, const int8_t* SRM,
97                             uint32_t SRMLength);
98   uint32_t GetDisplayIDFromConnectorID(const uint32_t connector_id);
99
100   bool IsReservedDrmPlane();
101
102   bool EnableDRMCommit(bool enable, uint32_t display_id);
103
104   bool ResetDrmMaster(bool drop_master);
105
106   std::vector<uint32_t> GetDisplayReservedPlanes(uint32_t display_id);
107
108  private:
109   GpuDevice();
110
111   void ResetAllDisplayCommit(bool enable);
112
113   enum InitializationType {
114     kUnInitialized = 0,    // Nothing Initialized.
115     kInitialized = 1 << 1  // Everything Initialized
116   };
117
118   void HandleHWCSettings();
119   void DisableWatch();
120   void HandleRoutine() override;
121   void HandleWait() override;
122   void ParsePlaneReserveSettings(std::string& value);
123   std::unique_ptr<DisplayManager> display_manager_;
124   std::vector<std::unique_ptr<LogicalDisplayManager>> logical_display_manager_;
125   std::vector<std::unique_ptr<NativeDisplay>> mosaic_displays_;
126 #ifdef ENABLE_PANORAMA
127   std::vector<std::unique_ptr<NativeDisplay>> panorama_displays_;
128   void ParsePanoramaDisplayConfig(
129       std::string& value,
130       std::vector<std::vector<uint32_t>>& panorama_displays);
131   void ParsePanoramaSOSDisplayConfig(
132       std::string& value,
133       std::vector<std::vector<uint32_t>>& panorama_sos_displays);
134   void InitializePanorama(
135       std::vector<NativeDisplay*>& total_displays_,
136       std::vector<NativeDisplay*>& temp_displays,
137       std::vector<std::vector<uint32_t>>& panorama_displays,
138       std::vector<std::vector<uint32_t>>& panorama_sos_displays,
139       std::vector<bool>& available_displays);
140 #endif
141   void ParseLogicalDisplaySetting(std::string& value,
142                                   std::vector<uint32_t>& logical_displays);
143   void ParseMosaicDisplaySetting(
144       std::string& value, std::vector<std::vector<uint32_t>>& mosaic_displays);
145   void ParsePhysicalDisplaySetting(std::string& value,
146                                    std::vector<uint32_t>& physical_displays);
147   void ParseCloneDisplaySetting(
148       std::string& value, std::vector<std::vector<uint32_t>>& cloned_displays);
149   void ParsePhysicalDisplayRotation(
150       std::string& value, std::vector<uint32_t>& display_rotation,
151       std::vector<uint32_t>& rotation_display_index);
152   void ParseFloatDisplaySetting(std::string& value,
153                                 std::vector<HwcRect<int32_t>>& float_displays,
154                                 std::vector<uint32_t>& float_display_indices);
155
156   void InitializeDisplayIndex(std::vector<uint32_t>& physical_displays,
157                               std::vector<NativeDisplay*>& displays);
158   void InitializeLogicalDisplay(std::vector<uint32_t>& logical_displays,
159                                 std::vector<NativeDisplay*>& displays,
160                                 std::vector<NativeDisplay*>& temp_displays,
161                                 bool use_logical);
162   void InitializeDisplayRotation(std::vector<uint32_t>& display_rotation,
163                                  std::vector<uint32_t>& rotation_display_index,
164                                  std::vector<NativeDisplay*>& displays);
165   void InitializeMosaicDisplay(
166       std::vector<NativeDisplay*>& total_displays_,
167       std::vector<std::vector<uint32_t>>& mosaic_displays,
168       std::vector<NativeDisplay*>& temp_displays,
169       std::vector<bool>& available_displays);
170   void InitializeCloneDisplay(
171       std::vector<NativeDisplay*>& total_displays_,
172       std::vector<std::vector<uint32_t>>& cloned_displays);
173   void InitializeFloatDisplay(std::vector<NativeDisplay*>& total_displays_,
174                               std::vector<HwcRect<int32_t>>& float_displays,
175                               std::vector<uint32_t>& float_display_indices);
176   std::vector<NativeDisplay*> total_displays_;
177
178   bool reserve_plane_ = false;
179   bool enable_all_display_ = true;
180   std::map<uint8_t, std::vector<uint32_t>> reserved_drm_display_planes_map_;
181   uint32_t initialization_state_ = kUnInitialized;
182   SpinLock initialization_state_lock_;
183   SpinLock drm_master_lock_;
184   int lock_fd_ = -1;
185   friend class DrmDisplayManager;
186 };
187
188 }  // namespace hwcomposer
189 #endif  // PUBLIC_GPUDEVICE_H_