From 534f85743096c2ac853329ab239b204d96efe665 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Mon, 1 Aug 2016 01:31:00 -0700 Subject: surfaceflinger: Cleanups for blur * Dynamically load it so no direct linkage or headers are required. Change-Id: I4eba035f527ae4f0fa2485e24a8586145baf0adc --- services/surfaceflinger/Android.mk | 6 --- services/surfaceflinger/LayerBlur.cpp | 93 +++++++++++++++++++++++++++++------ services/surfaceflinger/LayerBlur.h | 38 +++++++++++--- 3 files changed, 109 insertions(+), 28 deletions(-) diff --git a/services/surfaceflinger/Android.mk b/services/surfaceflinger/Android.mk index 4a6d320..2d907fa 100644 --- a/services/surfaceflinger/Android.mk +++ b/services/surfaceflinger/Android.mk @@ -129,12 +129,6 @@ ifeq ($(TARGET_USES_QCOM_BSP), true) ExSurfaceFlinger/ExHWComposer.cpp endif -ifeq ($(TARGET_HAVE_UI_BLUR),true) - LOCAL_C_INCLUDES += $(TARGET_OUT_HEADERS)/ui - LOCAL_SHARED_LIBRARIES += libuiblur - LOCAL_CFLAGS += -DUI_BLUR -endif - LOCAL_MODULE := libsurfaceflinger LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code diff --git a/services/surfaceflinger/LayerBlur.cpp b/services/surfaceflinger/LayerBlur.cpp index 4f5a72d..a49ff39 100644 --- a/services/surfaceflinger/LayerBlur.cpp +++ b/services/surfaceflinger/LayerBlur.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -90,16 +91,11 @@ static void setupMesh(Mesh& mesh, int width, int height, int viewportHeight) { texCoords[3] = vec2(1.0f, 1.0f); } - LayerBlur::LayerBlur(SurfaceFlinger* flinger, const sp& client, const String8& name, uint32_t w, uint32_t h, uint32_t flags) - : Layer(flinger, client, name, w, h, flags), mBlurMaskSampling(1), mBlurMaskAlphaThreshold(0.0f) - ,mLastFrameSequence(0) + : Layer(flinger, client, name, w, h, flags), mBlurMaskSampling(1), + mBlurMaskAlphaThreshold(0.0f) ,mLastFrameSequence(0) { -#ifdef UI_BLUR - mBlurToken = qtiblur::initBlurToken(); -#endif - GLuint texnames[3]; mFlinger->getRenderEngine().genTextures(3, texnames); mTextureCapture.init(Texture::TEXTURE_2D, texnames[0]); @@ -108,9 +104,6 @@ LayerBlur::LayerBlur(SurfaceFlinger* flinger, const sp& client, } LayerBlur::~LayerBlur() { -#ifdef UI_BLUR - qtiblur::releaseBlurToken(mBlurToken); -#endif releaseFbo(mFboCapture); releaseFbo(mFboMasking); @@ -168,18 +161,15 @@ void LayerBlur::onDraw(const sp& hw, const Region& /*clip*/ // blur size_t outTexWidth = mTextureBlur.getWidth(); size_t outTexHeight = mTextureBlur.getHeight(); -#ifdef UI_BLUR - if (!qtiblur::blur(mBlurToken, - s.blur, + if (mBlurImpl.blur(s.blur, mTextureCapture.getTextureName(), mTextureCapture.getWidth(), mTextureCapture.getHeight(), mTextureBlur.getTextureName(), &outTexWidth, - &outTexHeight)) { + &outTexHeight) != OK) { return; } -#endif // mTextureBlur now has "Blurred image" mTextureBlur.setDimensions(outTexWidth, outTexHeight); @@ -411,6 +401,79 @@ void LayerBlur::ensureFbo(FBO& fbo, int width, int height, int textureName) { } } +// --------------------------------------------------------------------------- + +void* LayerBlur::BlurImpl::sLibHandle = NULL; + +LayerBlur::BlurImpl::initBlurTokenFn LayerBlur::BlurImpl::initBlurToken = NULL; +LayerBlur::BlurImpl::releaseBlurTokenFn LayerBlur::BlurImpl::releaseBlurToken = NULL; +LayerBlur::BlurImpl::blurFn LayerBlur::BlurImpl::doBlur = NULL; +Mutex LayerBlur::BlurImpl::sLock; + +void LayerBlur::BlurImpl::closeBlurImpl() { + if (sLibHandle != NULL) { + dlclose(sLibHandle); + sLibHandle = NULL; + } +} + +status_t LayerBlur::BlurImpl::initBlurImpl() { + if (sLibHandle != NULL) { + return OK; + } + sLibHandle = dlopen("libuiblur.so", RTLD_NOW); + if (sLibHandle == NULL) { + return NO_INIT; + } + + // happy happy joy joy! + + initBlurToken = (initBlurTokenFn)dlsym(sLibHandle, + "_ZN7qtiblur13initBlurTokenEv"); + releaseBlurToken = (releaseBlurTokenFn)dlsym(sLibHandle, + "_ZN7qtiblur16releaseBlurTokenEPv"); + + if (sizeof(size_t) == 4) { + doBlur = (blurFn)dlsym(sLibHandle, + "_ZN7qtiblur4blurEPvijjjjPjS1_"); + } else if (sizeof(size_t) == 8) { + doBlur = (blurFn)dlsym(sLibHandle, + "_ZN7qtiblur4blurEPvijmmjPmS1_"); + } + + if (!initBlurToken || !releaseBlurToken || !doBlur) { + ALOGE("dlsym failed for blur impl!: %s", dlerror()); + closeBlurImpl(); + return NO_INIT; + } + + return OK; +} + +LayerBlur::BlurImpl::BlurImpl() { + Mutex::Autolock _l(sLock); + if (initBlurImpl() == OK) { + mToken = initBlurToken(); + } +} + +LayerBlur::BlurImpl::~BlurImpl() { + Mutex::Autolock _l(sLock); + if (mToken != NULL) { + releaseBlurToken(mToken); + } +} + +status_t LayerBlur::BlurImpl::blur(int level, uint32_t inId, size_t inWidth, size_t inHeight, + uint32_t outId, size_t* outWidth, size_t* outHeight) { + Mutex::Autolock _l(sLock); + if (mToken == NULL) { + return NO_INIT; + } + return doBlur(mToken, level, inId, inWidth, inHeight, + outId, outWidth, outHeight) ? OK : NO_INIT; +} + // --------------------------------------------------------------------------- diff --git a/services/surfaceflinger/LayerBlur.h b/services/surfaceflinger/LayerBlur.h index 251423e..63138c4 100644 --- a/services/surfaceflinger/LayerBlur.h +++ b/services/surfaceflinger/LayerBlur.h @@ -20,15 +20,12 @@ #ifndef ANDROID_LAYER_BLUR_H #define ANDROID_LAYER_BLUR_H +#include #include #include #include "Layer.h" -#ifdef UI_BLUR -#include "Blur.h" // libuiblur.so -#endif - // --------------------------------------------------------------------------- namespace android { @@ -58,9 +55,36 @@ public: virtual bool setBlurMaskAlphaThreshold(float alpha) { mBlurMaskAlphaThreshold = alpha; return true; } private: -#ifdef UI_BLUR - qtiblur::BLUR_TOKEN mBlurToken; -#endif + class BlurImpl { + public: + + BlurImpl(); + ~BlurImpl(); + + status_t blur(int level, uint32_t inId, size_t inWidth, size_t inheight, + uint32_t outId, size_t* outWidth, size_t* outHeight); + + protected: + static status_t initBlurImpl(); + static void closeBlurImpl(); + static void* sLibHandle; + + typedef void* (*initBlurTokenFn)(); + typedef void* (*releaseBlurTokenFn)(void*); + typedef void* (*blurFn)(void*, int, uint32_t, size_t, size_t, uint32_t, size_t*, size_t*); + + static initBlurTokenFn initBlurToken; + static releaseBlurTokenFn releaseBlurToken; + static blurFn doBlur; + + static Mutex sLock; + + private: + void* mToken; + }; + + BlurImpl mBlurImpl; + wp mBlurMaskLayer; int32_t mBlurMaskSampling; float mBlurMaskAlphaThreshold; -- cgit v1.1