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 "autofd.h" 21 #include "worker.h" 22 23 #include <sys/epoll.h> 24 25 namespace android { 26 27 class DrmDevice; 28 29 class DrmEventHandler { 30 public: DrmEventHandler()31 DrmEventHandler() { 32 } ~DrmEventHandler()33 virtual ~DrmEventHandler() { 34 } 35 36 virtual void handleEvent(uint64_t timestamp_us) = 0; 37 }; 38 39 class DrmHistogramEventHandler { 40 public: DrmHistogramEventHandler()41 DrmHistogramEventHandler() {} ~DrmHistogramEventHandler()42 virtual ~DrmHistogramEventHandler() {} 43 44 virtual void handleHistogramEvent(uint32_t crtc_id, void *) = 0; 45 }; 46 47 class DrmTUIEventHandler { 48 public: DrmTUIEventHandler()49 DrmTUIEventHandler() { 50 } ~DrmTUIEventHandler()51 virtual ~DrmTUIEventHandler() { 52 } 53 54 virtual void handleTUIEvent() = 0; 55 }; 56 57 class DrmPanelIdleEventHandler { 58 public: DrmPanelIdleEventHandler()59 DrmPanelIdleEventHandler() {} ~DrmPanelIdleEventHandler()60 virtual ~DrmPanelIdleEventHandler() {} 61 62 virtual void handleIdleEnterEvent(char const *event) = 0; 63 }; 64 65 class DrmEventListener : public Worker { 66 static constexpr const char kTUIStatusPath[] = "/sys/devices/platform/exynos-drm/tui_status"; 67 static const uint32_t maxFds = 3; 68 public: 69 DrmEventListener(DrmDevice *drm); 70 virtual ~DrmEventListener(); 71 72 int Init(); 73 74 void RegisterHotplugHandler(DrmEventHandler *handler); 75 void UnRegisterHotplugHandler(DrmEventHandler *handler); 76 void RegisterHistogramHandler(DrmHistogramEventHandler *handler); 77 void UnRegisterHistogramHandler(DrmHistogramEventHandler *handler); 78 void RegisterTUIHandler(DrmTUIEventHandler *handler); 79 void UnRegisterTUIHandler(DrmTUIEventHandler *handler); 80 void RegisterPanelIdleHandler(DrmPanelIdleEventHandler *handler); 81 void UnRegisterPanelIdleHandler(DrmPanelIdleEventHandler *handler); 82 83 bool IsDrmInTUI(); 84 85 static void FlipHandler(int fd, unsigned int sequence, unsigned int tv_sec, 86 unsigned int tv_usec, void *user_data); 87 88 protected: 89 virtual void Routine(); 90 91 private: 92 void UEventHandler(); 93 void DRMEventHandler(); 94 void TUIEventHandler(); 95 96 UniqueFd epoll_fd_; 97 UniqueFd uevent_fd_; 98 UniqueFd tuievent_fd_; 99 100 DrmDevice *drm_; 101 std::unique_ptr<DrmEventHandler> hotplug_handler_; 102 std::unique_ptr<DrmHistogramEventHandler> histogram_handler_; 103 std::unique_ptr<DrmTUIEventHandler> tui_handler_; 104 std::unique_ptr<DrmPanelIdleEventHandler> panel_idle_handler_; 105 }; 106 } // namespace android 107 108 #endif 109