diff options
| author | 2017-10-31 18:40:00 +0000 | |
|---|---|---|
| committer | 2017-10-31 18:40:00 +0000 | |
| commit | ffbf2d94a1838126f05fcebb6a90a7d6cdf9601f (patch) | |
| tree | b11994718f74be808abe052ec3388e031c20723d | |
| parent | a14443fac49543abda174f8c3457ab0b60021b01 (diff) | |
| parent | 6200eacdc927776483d775562db11cce284cc7e0 (diff) | |
surfaceflinger: make vsync injection more robust
am: 6200eacdc9
Change-Id: Ie04e3e56b035ea9e52038de49a2e5c2e67c8abe2
| -rw-r--r-- | services/surfaceflinger/MessageQueue.cpp | 8 | ||||
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 37 | ||||
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.h | 3 |
3 files changed, 41 insertions, 7 deletions
diff --git a/services/surfaceflinger/MessageQueue.cpp b/services/surfaceflinger/MessageQueue.cpp index bca3430794..0b1199c2d0 100644 --- a/services/surfaceflinger/MessageQueue.cpp +++ b/services/surfaceflinger/MessageQueue.cpp @@ -91,6 +91,14 @@ void MessageQueue::init(const sp<SurfaceFlinger>& flinger) void MessageQueue::setEventThread(const sp<EventThread>& eventThread) { + if (mEventThread == eventThread) { + return; + } + + if (mEventTube.getFd() >= 0) { + mLooper->removeFd(mEventTube.getFd()); + } + mEventThread = eventThread; mEvents = eventThread->createEventConnection(); mEvents->stealReceiveChannel(&mEventTube); diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 8c90c39245..fee552e6a8 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -528,7 +528,9 @@ public: virtual void onInjectSyncEvent(nsecs_t when) { std::lock_guard<std::mutex> lock(mCallbackMutex); - mCallback->onVSyncEvent(when); + if (mCallback != nullptr) { + mCallback->onVSyncEvent(when); + } } virtual void setVSyncEnabled(bool) {} @@ -1017,13 +1019,14 @@ status_t SurfaceFlinger::getHdrCapabilities(const sp<IBinder>& display, return NO_ERROR; } -status_t SurfaceFlinger::enableVSyncInjections(bool enable) { - if (enable == mInjectVSyncs) { - return NO_ERROR; +void SurfaceFlinger::enableVSyncInjectionsInternal(bool enable) { + Mutex::Autolock _l(mStateLock); + + if (mInjectVSyncs == enable) { + return; } if (enable) { - mInjectVSyncs = enable; ALOGV("VSync Injections enabled"); if (mVSyncInjector.get() == nullptr) { mVSyncInjector = new InjectVSyncSource(); @@ -1031,15 +1034,33 @@ status_t SurfaceFlinger::enableVSyncInjections(bool enable) { } mEventQueue.setEventThread(mInjectorEventThread); } else { - mInjectVSyncs = enable; ALOGV("VSync Injections disabled"); mEventQueue.setEventThread(mSFEventThread); - mVSyncInjector.clear(); } + + mInjectVSyncs = enable; +} + +status_t SurfaceFlinger::enableVSyncInjections(bool enable) { + class MessageEnableVSyncInjections : public MessageBase { + SurfaceFlinger* mFlinger; + bool mEnable; + public: + MessageEnableVSyncInjections(SurfaceFlinger* flinger, bool enable) + : mFlinger(flinger), mEnable(enable) { } + virtual bool handler() { + mFlinger->enableVSyncInjectionsInternal(mEnable); + return true; + } + }; + sp<MessageBase> msg = new MessageEnableVSyncInjections(this, enable); + postMessageSync(msg); return NO_ERROR; } status_t SurfaceFlinger::injectVSync(nsecs_t when) { + Mutex::Autolock _l(mStateLock); + if (!mInjectVSyncs) { ALOGE("VSync Injections not enabled"); return BAD_VALUE; @@ -3866,6 +3887,8 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { case GET_ANIMATION_FRAME_STATS: case SET_POWER_MODE: case GET_HDR_CAPABILITIES: + case ENABLE_VSYNC_INJECTIONS: + case INJECT_VSYNC: { // codes that require permission check IPCThreadState* ipc = IPCThreadState::self(); diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index e75d9dcdde..e65a227158 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -337,6 +337,9 @@ private: // Called on the main thread in response to setActiveColorMode() void setActiveColorModeInternal(const sp<DisplayDevice>& hw, android_color_mode_t colorMode); + // Called on the main thread in response to enableVSyncInjections() + void enableVSyncInjectionsInternal(bool enable); + // Returns whether the transaction actually modified any state bool handleMessageTransaction(); |