diff options
| -rw-r--r-- | services/surfaceflinger/MessageQueue.cpp | 8 | ||||
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 79 | ||||
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.h | 4 |
3 files changed, 76 insertions, 15 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 624fda27f4..ee85e387b5 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -568,7 +568,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) {} @@ -682,6 +684,12 @@ void SurfaceFlinger::readPersistentProperties() { property_get("persist.sys.sf.color_saturation", value, "1.0"); mSaturation = atof(value); ALOGV("Saturation is set to %.2f", mSaturation); + + property_get("persist.sys.sf.native_mode", value, "0"); + mForceNativeColorMode = atoi(value) == 1; + if (mForceNativeColorMode) { + ALOGV("Forcing native color mode"); + } } void SurfaceFlinger::startBootAnim() { @@ -1057,13 +1065,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(); @@ -1071,15 +1080,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; @@ -1288,12 +1315,13 @@ void SurfaceFlinger::createDefaultDisplayDevice() { break; } } + bool useWideColorMode = hasWideColorModes && hasWideColorDisplay && !mForceNativeColorMode; sp<DisplayDevice> hw = new DisplayDevice(this, DisplayDevice::DISPLAY_PRIMARY, type, isSecure, token, fbs, producer, mRenderEngine->getEGLConfig(), - hasWideColorModes && hasWideColorDisplay); + useWideColorMode); mDisplays.add(token, hw); android_color_mode defaultColorMode = HAL_COLOR_MODE_NATIVE; - if (hasWideColorModes && hasWideColorDisplay) { + if (useWideColorMode) { defaultColorMode = HAL_COLOR_MODE_SRGB; } setActiveColorModeInternal(hw, defaultColorMode); @@ -1826,6 +1854,10 @@ mat4 SurfaceFlinger::computeSaturationMatrix() const { // pickColorMode translates a given dataspace into the best available color mode. // Currently only support sRGB and Display-P3. android_color_mode SurfaceFlinger::pickColorMode(android_dataspace dataSpace) const { + if (mForceNativeColorMode) { + return HAL_COLOR_MODE_NATIVE; + } + switch (dataSpace) { // treat Unknown as regular SRGB buffer, since that's what the rest of the // system expects. @@ -2681,8 +2713,10 @@ bool SurfaceFlinger::doComposeSurfaces( ALOGV("hasClientComposition"); #ifdef USE_HWC2 - mRenderEngine->setWideColor(displayDevice->getWideColorSupport()); - mRenderEngine->setColorMode(displayDevice->getActiveColorMode()); + mRenderEngine->setWideColor( + displayDevice->getWideColorSupport() && !mForceNativeColorMode); + mRenderEngine->setColorMode(mForceNativeColorMode ? + HAL_COLOR_MODE_NATIVE : displayDevice->getActiveColorMode()); #endif if (!displayDevice->makeCurrent(mEGLDisplay, mEGLContext)) { ALOGW("DisplayDevice::makeCurrent failed. Aborting surface composition for display %s", @@ -3726,6 +3760,7 @@ void SurfaceFlinger::dumpBufferingStats(String8& result) const { void SurfaceFlinger::dumpWideColorInfo(String8& result) const { result.appendFormat("hasWideColorDisplay: %d\n", hasWideColorDisplay); + result.appendFormat("forceNativeColorMode: %d\n", mForceNativeColorMode); // TODO: print out if wide-color mode is active or not @@ -3971,6 +4006,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(); @@ -4179,6 +4216,17 @@ status_t SurfaceFlinger::onTransact( repaintEverything(); return NO_ERROR; } + case 1023: { // Set native mode + mForceNativeColorMode = data.readInt32() == 1; + + invalidateHwcGeometry(); + repaintEverything(); + return NO_ERROR; + } + case 1024: { // Is wide color gamut rendering/color management supported? + reply->writeBool(hasWideColorDisplay); + return NO_ERROR; + } } } return err; @@ -4336,8 +4384,9 @@ status_t SurfaceFlinger::captureScreen(const sp<IBinder>& display, WindowDisconnector disconnector(window, NATIVE_WINDOW_API_EGL); ANativeWindowBuffer* buffer = nullptr; - result = getWindowBuffer(window, reqWidth, reqHeight, hasWideColorDisplay, - getRenderEngine().usesWideColor(), &buffer); + result = getWindowBuffer(window, reqWidth, reqHeight, + hasWideColorDisplay && !mForceNativeColorMode, + getRenderEngine().usesWideColor(), &buffer); if (result != NO_ERROR) { return result; } @@ -4439,8 +4488,8 @@ void SurfaceFlinger::renderScreenImplLocked( } #ifdef USE_HWC2 - engine.setWideColor(hw->getWideColorSupport()); - engine.setColorMode(hw->getActiveColorMode()); + engine.setWideColor(hw->getWideColorSupport() && !mForceNativeColorMode); + engine.setColorMode(mForceNativeColorMode ? HAL_COLOR_MODE_NATIVE : hw->getActiveColorMode()); #endif // make sure to clear all GL error flags diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 821e15c84c..0dfa916cbb 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -367,6 +367,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(); @@ -819,6 +822,7 @@ private: #endif float mSaturation = 1.0f; + bool mForceNativeColorMode = false; }; }; // namespace android |