• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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_EVENT_LISTENER_H_
18 #define ANDROID_DRM_EVENT_LISTENER_H_
19 
20 #include <sys/epoll.h>
21 
22 #include <map>
23 
24 #include "autofd.h"
25 #include "worker.h"
26 
27 namespace android {
28 
29 class DrmDevice;
30 
31 class DrmEventHandler {
32  public:
DrmEventHandler()33   DrmEventHandler() {
34   }
~DrmEventHandler()35   virtual ~DrmEventHandler() {
36   }
37 
38   virtual void handleEvent(uint64_t timestamp_us) = 0;
39 };
40 
41 class DrmHistogramEventHandler {
42 public:
DrmHistogramEventHandler()43     DrmHistogramEventHandler() {}
~DrmHistogramEventHandler()44     virtual ~DrmHistogramEventHandler() {}
45 
46     virtual void handleHistogramEvent(uint32_t crtc_id, void *) = 0;
47 };
48 
49 class DrmHistogramChannelEventHandler {
50    public:
DrmHistogramChannelEventHandler()51     DrmHistogramChannelEventHandler() {}
~DrmHistogramChannelEventHandler()52     virtual ~DrmHistogramChannelEventHandler() {}
53 
54     virtual void handleHistogramChannelEvent(void *) = 0;
55 };
56 
57 class DrmTUIEventHandler {
58  public:
DrmTUIEventHandler()59   DrmTUIEventHandler() {
60   }
~DrmTUIEventHandler()61   virtual ~DrmTUIEventHandler() {
62   }
63 
64   virtual void handleTUIEvent() = 0;
65 };
66 
67 class DrmPanelIdleEventHandler {
68  public:
DrmPanelIdleEventHandler()69   DrmPanelIdleEventHandler() {}
~DrmPanelIdleEventHandler()70   virtual ~DrmPanelIdleEventHandler() {}
71 
72   virtual void handleIdleEnterEvent(char const *event) = 0;
73 };
74 
75 class DrmSysfsEventHandler {
76  public:
DrmSysfsEventHandler()77   DrmSysfsEventHandler() {}
~DrmSysfsEventHandler()78   virtual ~DrmSysfsEventHandler() {}
79 
80   virtual void handleSysfsEvent() = 0;
81   virtual int getFd() = 0;
82 };
83 
84 class DrmEventListener : public Worker {
85   static constexpr const char kTUIStatusPath[] = "/sys/devices/platform/exynos-drm/tui_status";
86   static const uint32_t maxFds = 4;
87 
88  public:
89   DrmEventListener(DrmDevice *drm);
90   virtual ~DrmEventListener();
91 
92   int Init();
93 
94   void RegisterHotplugHandler(DrmEventHandler *handler);
95   void UnRegisterHotplugHandler(DrmEventHandler *handler);
96   void RegisterHistogramHandler(DrmHistogramEventHandler *handler);
97   void UnRegisterHistogramHandler(DrmHistogramEventHandler *handler);
98   void RegisterHistogramChannelHandler(DrmHistogramChannelEventHandler *handler);
99   void UnRegisterHistogramChannelHandler(DrmHistogramChannelEventHandler *handler);
100   void RegisterTUIHandler(DrmTUIEventHandler *handler);
101   void UnRegisterTUIHandler(DrmTUIEventHandler *handler);
102   void RegisterPanelIdleHandler(DrmPanelIdleEventHandler *handler);
103   void UnRegisterPanelIdleHandler(DrmPanelIdleEventHandler *handler);
104   int RegisterSysfsHandler(std::shared_ptr<DrmSysfsEventHandler> handler);
105   int UnRegisterSysfsHandler(int sysfs_fd);
106 
107   bool IsDrmInTUI();
108 
109   static void FlipHandler(int fd, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec,
110                           void *user_data);
111 
112  protected:
113   virtual void Routine();
114 
115  private:
116   void UEventHandler();
117   void DRMEventHandler();
118   void TUIEventHandler();
119   void SysfsEventHandler(int fd);
120 
121   UniqueFd epoll_fd_;
122   UniqueFd uevent_fd_;
123   UniqueFd tuievent_fd_;
124 
125   DrmDevice *drm_;
126   std::unique_ptr<DrmEventHandler> hotplug_handler_;
127   std::unique_ptr<DrmHistogramEventHandler> histogram_handler_;
128   std::unique_ptr<DrmHistogramChannelEventHandler> histogram_channel_handler_;
129   std::unique_ptr<DrmTUIEventHandler> tui_handler_;
130   std::unique_ptr<DrmPanelIdleEventHandler> panel_idle_handler_;
131   std::mutex mutex_;
132   std::map<int, std::shared_ptr<DrmSysfsEventHandler>> sysfs_handlers_;
133 };
134 
135 }  // namespace android
136 
137 #endif
138