surfaceflinger: Cleanups for blur

* Dynamically load it so no direct linkage or headers are required.

Change-Id: I4eba035f527ae4f0fa2485e24a8586145baf0adc
This commit is contained in:
Steve Kondik 2016-08-01 01:31:00 -07:00
parent f5486d6f47
commit 534f857430
3 changed files with 109 additions and 28 deletions

View File

@ -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

View File

@ -25,6 +25,7 @@
#include <stdint.h>
#include <sys/types.h>
#include <time.h>
#include <dlfcn.h>
#include <utils/Errors.h>
#include <utils/Log.h>
@ -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>& 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>& client,
}
LayerBlur::~LayerBlur() {
#ifdef UI_BLUR
qtiblur::releaseBlurToken(mBlurToken);
#endif
releaseFbo(mFboCapture);
releaseFbo(mFboMasking);
@ -168,18 +161,15 @@ void LayerBlur::onDraw(const sp<const DisplayDevice>& 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;
}
// ---------------------------------------------------------------------------

View File

@ -20,15 +20,12 @@
#ifndef ANDROID_LAYER_BLUR_H
#define ANDROID_LAYER_BLUR_H
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#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<Layer> mBlurMaskLayer;
int32_t mBlurMaskSampling;
float mBlurMaskAlphaThreshold;