1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project 3*38e8c45fSAndroid Build Coastguard Worker * 4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*38e8c45fSAndroid Build Coastguard Worker * 8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*38e8c45fSAndroid Build Coastguard Worker * 10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License. 15*38e8c45fSAndroid Build Coastguard Worker */ 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard Worker #include <gui/DisplayEventReceiver.h> 18*38e8c45fSAndroid Build Coastguard Worker #include <utils/Log.h> 19*38e8c45fSAndroid Build Coastguard Worker #include <utils/Looper.h> 20*38e8c45fSAndroid Build Coastguard Worker 21*38e8c45fSAndroid Build Coastguard Worker namespace android { 22*38e8c45fSAndroid Build Coastguard Worker using FrameRateOverride = DisplayEventReceiver::Event::FrameRateOverride; 23*38e8c45fSAndroid Build Coastguard Worker 24*38e8c45fSAndroid Build Coastguard Worker class DisplayEventDispatcher : public LooperCallback { 25*38e8c45fSAndroid Build Coastguard Worker public: 26*38e8c45fSAndroid Build Coastguard Worker explicit DisplayEventDispatcher(const sp<Looper>& looper, 27*38e8c45fSAndroid Build Coastguard Worker gui::ISurfaceComposer::VsyncSource vsyncSource = 28*38e8c45fSAndroid Build Coastguard Worker gui::ISurfaceComposer::VsyncSource::eVsyncSourceApp, 29*38e8c45fSAndroid Build Coastguard Worker EventRegistrationFlags eventRegistration = {}, 30*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& layerHandle = nullptr); 31*38e8c45fSAndroid Build Coastguard Worker 32*38e8c45fSAndroid Build Coastguard Worker status_t initialize(); 33*38e8c45fSAndroid Build Coastguard Worker void dispose(); 34*38e8c45fSAndroid Build Coastguard Worker status_t scheduleVsync(); 35*38e8c45fSAndroid Build Coastguard Worker void injectEvent(const DisplayEventReceiver::Event& event); 36*38e8c45fSAndroid Build Coastguard Worker int getFd() const; 37*38e8c45fSAndroid Build Coastguard Worker virtual int handleEvent(int receiveFd, int events, void* data); 38*38e8c45fSAndroid Build Coastguard Worker status_t getLatestVsyncEventData(ParcelableVsyncEventData* outVsyncEventData) const; 39*38e8c45fSAndroid Build Coastguard Worker 40*38e8c45fSAndroid Build Coastguard Worker protected: 41*38e8c45fSAndroid Build Coastguard Worker virtual ~DisplayEventDispatcher() = default; 42*38e8c45fSAndroid Build Coastguard Worker 43*38e8c45fSAndroid Build Coastguard Worker private: 44*38e8c45fSAndroid Build Coastguard Worker sp<Looper> mLooper; 45*38e8c45fSAndroid Build Coastguard Worker DisplayEventReceiver mReceiver; 46*38e8c45fSAndroid Build Coastguard Worker bool mWaitingForVsync; 47*38e8c45fSAndroid Build Coastguard Worker uint32_t mLastVsyncCount; 48*38e8c45fSAndroid Build Coastguard Worker nsecs_t mLastScheduleVsyncTime; 49*38e8c45fSAndroid Build Coastguard Worker 50*38e8c45fSAndroid Build Coastguard Worker std::vector<FrameRateOverride> mFrameRateOverrides; 51*38e8c45fSAndroid Build Coastguard Worker 52*38e8c45fSAndroid Build Coastguard Worker virtual void dispatchVsync(nsecs_t timestamp, PhysicalDisplayId displayId, uint32_t count, 53*38e8c45fSAndroid Build Coastguard Worker VsyncEventData vsyncEventData) = 0; 54*38e8c45fSAndroid Build Coastguard Worker virtual void dispatchHotplug(nsecs_t timestamp, PhysicalDisplayId displayId, 55*38e8c45fSAndroid Build Coastguard Worker bool connected) = 0; 56*38e8c45fSAndroid Build Coastguard Worker 57*38e8c45fSAndroid Build Coastguard Worker virtual void dispatchHotplugConnectionError(nsecs_t timestamp, int32_t connectionError) = 0; 58*38e8c45fSAndroid Build Coastguard Worker 59*38e8c45fSAndroid Build Coastguard Worker virtual void dispatchModeChanged(nsecs_t timestamp, PhysicalDisplayId displayId, int32_t modeId, 60*38e8c45fSAndroid Build Coastguard Worker nsecs_t vsyncPeriod) = 0; 61*38e8c45fSAndroid Build Coastguard Worker // AChoreographer-specific hook for processing null-events so that looper 62*38e8c45fSAndroid Build Coastguard Worker // can be properly poked. 63*38e8c45fSAndroid Build Coastguard Worker virtual void dispatchNullEvent(nsecs_t timestamp, PhysicalDisplayId displayId) = 0; 64*38e8c45fSAndroid Build Coastguard Worker 65*38e8c45fSAndroid Build Coastguard Worker virtual void dispatchFrameRateOverrides(nsecs_t timestamp, PhysicalDisplayId displayId, 66*38e8c45fSAndroid Build Coastguard Worker std::vector<FrameRateOverride> overrides) = 0; 67*38e8c45fSAndroid Build Coastguard Worker 68*38e8c45fSAndroid Build Coastguard Worker virtual void dispatchHdcpLevelsChanged(PhysicalDisplayId displayId, int32_t connectedLevel, 69*38e8c45fSAndroid Build Coastguard Worker int32_t maxLevel) = 0; 70*38e8c45fSAndroid Build Coastguard Worker 71*38e8c45fSAndroid Build Coastguard Worker virtual void dispatchModeRejected(PhysicalDisplayId displayId, int32_t modeId) = 0; 72*38e8c45fSAndroid Build Coastguard Worker 73*38e8c45fSAndroid Build Coastguard Worker bool processPendingEvents(nsecs_t* outTimestamp, PhysicalDisplayId* outDisplayId, 74*38e8c45fSAndroid Build Coastguard Worker uint32_t* outCount, VsyncEventData* outVsyncEventData); 75*38e8c45fSAndroid Build Coastguard Worker 76*38e8c45fSAndroid Build Coastguard Worker void populateFrameTimelines(const DisplayEventReceiver::Event& event, 77*38e8c45fSAndroid Build Coastguard Worker VsyncEventData* outVsyncEventData) const; 78*38e8c45fSAndroid Build Coastguard Worker }; 79*38e8c45fSAndroid Build Coastguard Worker } // namespace android 80