OSDN Git Service

c8b2fc374a3aeb6f1c762b2f6020d95bf2712cc1
[android-x86/external-IA-Hardware-Composer.git] / os / alios / hwf_alioshal.h
1 /*
2 // Copyright (c) 2018 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 _ALIOS_HWC1_H_
18 #define _ALIOS_HWC1_H_
19
20 #include <cutils/hwflinger.h>
21 #include <cutils/hwflinger_defs.h>
22
23 #include <nativedisplay.h>
24 #include <hwclayer.h>
25 #include <gpudevice.h>
26 #include <fcntl.h>
27
28 #include <Hal.h>
29
30 #include <memory>
31
32 #define USER_FENCE_SYNC 0
33
34 #if 0
35 typedef struct hwf_module_wrapper_t
36 {
37     hwf_module_t base;
38     void *priv;          /**< Driver private data */
39 } hwf_module_wrapper_t;
40 #endif
41
42 namespace hwcomposer {
43
44 class DisplayTimeLine {
45  public:
46   int Init() {
47 #if USER_FENCE_SYNC
48     timeline_fd_ = open("/dev/sw_sync", O_RDWR);
49     if (timeline_fd_ < 0)
50       return -1;
51
52     return 0;
53
54 #else
55     return -1;
56 #endif
57   }
58
59   ~DisplayTimeLine() {
60 #if USER_FENCE_SYNC
61     if (timeline_fd_ > 0) {
62       close(timeline_fd_);
63     }
64 #endif
65   }
66
67   int32_t IncrementTimeLine() {
68 #if USER_FENCE_SYNC
69     int ret =
70         sw_sync_fence_create(timeline_fd_, "display fence", timeline_pt_ + 1);
71     if (ret < 0) {
72       LOG_E("Failed to create display fence %d %d", ret, timeline_fd_);
73       return ret;
74     }:
75
76       int32_t ret_fd(ret);
77
78     ret = sw_sync_timeline_inc(timeline_fd_, 1);
79     if (ret) {
80       LOG_E("Failed to increment display sync timeline %d", ret);
81       return ret;
82     }
83
84     ++timeline_pt_;
85     return ret_fd;
86
87 #else
88     return -1;
89 #endif
90   }
91
92  private:
93   int32_t timeline_fd_;
94   int timeline_pt_ = 0;
95 };
96
97 typedef struct HwfLayer {
98   ~HwfLayer() {
99     delete hwc_layer_;  // TO DO
100     hwc_layer_ = NULL;
101   }
102
103   HwfLayer() = default;
104
105   HwfLayer(const HwfLayer& rhs) = delete;
106   HwfLayer& operator=(const HwfLayer& rhs) = delete;
107
108   struct yalloc_handle native_handle_;  // TO DO
109   hwcomposer::HwcLayer* hwc_layer_ = NULL;
110   uint32_t index_ = 0;
111
112   int InitFromHwcLayer(hwf_layer_t* sf_layer);
113 } HwfLayer;
114
115 typedef struct HwfDisplay {
116   // struct HwfDevice *ctx;
117   hwcomposer::NativeDisplay* display_ = NULL;  // TO DO
118   uint32_t display_id_ = 0;
119   int32_t fence_ = -1;
120   int last_render_layers_size = -1;
121   std::vector<HwfLayer*> layers_;
122   DisplayTimeLine timeline_;
123   bool gl_composition_ = false;
124 } HwfDisplay;
125
126 struct HwfDevice {
127   hwf_device_t base;
128
129   ~HwfDevice() {
130   }
131
132   hwcomposer::GpuDevice device_;
133   std::vector<HwfDisplay> extended_displays_;
134   HwfDisplay primary_display_;
135   HwfDisplay virtual_display_;
136
137   /* Note: explicit sync isn't implemented currently, set it to 'false' just
138      let the logic run, all the fence is set as -1.
139   */
140   bool disable_explicit_sync_ = false;
141
142   hwf_callback* m_phwf_callback;
143
144   HwfDisplay* GetDisplay(int display);
145
146   static int detect(struct hwf_device_t* device, int dispCount,
147                     hwf_display_t** displays);
148
149   static int flip(struct hwf_device_t* device, int dispCount,
150                   hwf_display_t** displays);
151
152   static int setEventState(struct hwf_device_t* device, int disp, int event,
153                            int enabled);
154
155   static int setDisplayState(struct hwf_device_t* device, int disp, int state);
156
157   static int lookup(struct hwf_device_t* device, int what, int* value);
158
159   static void registerCallback(struct hwf_device_t* device,
160                                hwf_callback_t const* callback);
161
162   static int queryDispConfigs(struct hwf_device_t* device, int disp,
163                               uint32_t* configs, int* numConfigs);
164
165   static int queryDispAttribs(struct hwf_device_t* device, int disp,
166                               uint32_t config, const uint32_t* attributes,
167                               int32_t* values);
168
169   static void dump(struct hwf_device_t* device, char* buff, int buff_len);
170 };
171
172 class ia_hwf_yunhal {
173  private:
174   HwfDevice m_Device;
175
176  public:
177   ia_hwf_yunhal();
178   ~ia_hwf_yunhal();
179
180   HwfDevice* get_hwf_hw();
181 };
182 }
183
184 #endif