1 /* 2 * Copyright (C) 2015 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 #include <gui/DisplayEventReceiver.h> 18 #include <utils/Log.h> 19 #include <utils/Looper.h> 20 21 namespace android { 22 using FrameRateOverride = DisplayEventReceiver::Event::FrameRateOverride; 23 24 class DisplayEventDispatcher : public LooperCallback { 25 public: 26 status_t initialize(); 27 void dispose(); 28 status_t scheduleVsync(); 29 void injectEvent(const DisplayEventReceiver::Event& event); 30 int getFd() const; 31 virtual int handleEvent(int receiveFd, int events, void* data); 32 status_t getLatestVsyncEventData(ParcelableVsyncEventData* outVsyncEventData) const; 33 34 protected: 35 explicit DisplayEventDispatcher(const sp<Looper>& looper, 36 gui::ISurfaceComposer::VsyncSource vsyncSource = 37 gui::ISurfaceComposer::VsyncSource::eVsyncSourceApp, 38 EventRegistrationFlags eventRegistration = {}, 39 const sp<IBinder>& layerHandle = nullptr); 40 41 friend class sp<DisplayEventDispatcher>; 42 43 virtual ~DisplayEventDispatcher() = default; 44 45 private: 46 sp<Looper> mLooper; 47 DisplayEventReceiver mReceiver; 48 bool mWaitingForVsync; 49 uint32_t mLastVsyncCount; 50 nsecs_t mLastScheduleVsyncTime; 51 52 std::vector<FrameRateOverride> mFrameRateOverrides; 53 54 virtual void dispatchVsync(nsecs_t timestamp, PhysicalDisplayId displayId, uint32_t count, 55 VsyncEventData vsyncEventData) = 0; 56 virtual void dispatchHotplug(nsecs_t timestamp, PhysicalDisplayId displayId, 57 bool connected) = 0; 58 59 virtual void dispatchHotplugConnectionError(nsecs_t timestamp, int32_t connectionError) = 0; 60 61 virtual void dispatchModeChanged(nsecs_t timestamp, PhysicalDisplayId displayId, int32_t modeId, 62 nsecs_t vsyncPeriod) = 0; 63 // AChoreographer-specific hook for processing null-events so that looper 64 // can be properly poked. 65 virtual void dispatchNullEvent(nsecs_t timestamp, PhysicalDisplayId displayId) = 0; 66 67 virtual void dispatchFrameRateOverrides(nsecs_t timestamp, PhysicalDisplayId displayId, 68 std::vector<FrameRateOverride> overrides) = 0; 69 70 virtual void dispatchHdcpLevelsChanged(PhysicalDisplayId displayId, int32_t connectedLevel, 71 int32_t maxLevel) = 0; 72 73 virtual void dispatchModeRejected(PhysicalDisplayId displayId, int32_t modeId) = 0; 74 75 bool processPendingEvents(nsecs_t* outTimestamp, PhysicalDisplayId* outDisplayId, 76 uint32_t* outCount, VsyncEventData* outVsyncEventData); 77 78 void populateFrameTimelines(const DisplayEventReceiver::Event& event, 79 VsyncEventData* outVsyncEventData) const; 80 }; 81 } // namespace android 82