diff options
author | Byunghun Jeon <bjeon@codeaurora.org> | 2014-12-05 18:28:32 -0800 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-11-08 01:07:13 -0800 |
commit | 987034b5633d0eb7fca806acfe00ddbe3305b159 (patch) | |
tree | 9d186252541a857729a9f3920bd8369d4a056e0d /services/surfaceflinger/RenderEngine | |
parent | b53d92c3eb9319dbf725b3e59b3c52acfa6d77f0 (diff) | |
download | frameworks_native-987034b5633d0eb7fca806acfe00ddbe3305b159.zip frameworks_native-987034b5633d0eb7fca806acfe00ddbe3305b159.tar.gz frameworks_native-987034b5633d0eb7fca806acfe00ddbe3305b159.tar.bz2 |
SurfaceFlinger: Native changes to add blur effect
Native changes to add blur-behind and blur mask effect
Change-Id: I54faf82d750e8299de6d261f6a893ab26d08df84
SurfaceFlinger: Adding template for LayerBlur files
Change-Id: I444009113b7bdd6c5284863fd1f56358e67d9fe6
SurfaceFlinger: Featurize libuiblur module for OSS build
Change-Id: Ifdc176e699434125d17b111c044b8ba954cf717c
Diffstat (limited to 'services/surfaceflinger/RenderEngine')
10 files changed, 129 insertions, 10 deletions
diff --git a/services/surfaceflinger/RenderEngine/Description.cpp b/services/surfaceflinger/RenderEngine/Description.cpp index 0dab872..14607ca 100644 --- a/services/surfaceflinger/RenderEngine/Description.cpp +++ b/services/surfaceflinger/RenderEngine/Description.cpp @@ -33,6 +33,8 @@ Description::Description() : mOpaque = true; mTextureEnabled = false; mColorMatrixEnabled = false; + mMaskTextureEnabled = false; + mMaskAlphaThreshold = 0.0f; memset(mColor, 0, sizeof(mColor)); } @@ -92,5 +94,14 @@ const mat4& Description::getColorMatrix() const { return mColorMatrix; } +void Description::setMasking(const Texture& maskTexture, float alphaThreshold) { + mMaskTexture = maskTexture; + mMaskTextureEnabled = true; + mMaskAlphaThreshold = alphaThreshold; +} + +void Description::disableMasking() { + mMaskTextureEnabled = false; +} } /* namespace android */ diff --git a/services/surfaceflinger/RenderEngine/Description.h b/services/surfaceflinger/RenderEngine/Description.h index 8a3447c..2bfb632 100644 --- a/services/surfaceflinger/RenderEngine/Description.h +++ b/services/surfaceflinger/RenderEngine/Description.h @@ -53,6 +53,9 @@ class Description { bool mColorMatrixEnabled; mat4 mColorMatrix; + Texture mMaskTexture; + bool mMaskTextureEnabled; + GLclampf mMaskAlphaThreshold; public: Description(); @@ -67,6 +70,8 @@ public: void setProjectionMatrix(const mat4& mtx); void setColorMatrix(const mat4& mtx); const mat4& getColorMatrix() const; + void setMasking(const Texture& maskTexture, float alphaThreshold); + void disableMasking(); private: bool mUniformsDirty; diff --git a/services/surfaceflinger/RenderEngine/GLES11RenderEngine.h b/services/surfaceflinger/RenderEngine/GLES11RenderEngine.h index 77824ce..cb13ee0 100644 --- a/services/surfaceflinger/RenderEngine/GLES11RenderEngine.h +++ b/services/surfaceflinger/RenderEngine/GLES11RenderEngine.h @@ -60,6 +60,8 @@ protected: virtual void setupFillWithColor(float r, float g, float b, float a) ; virtual void disableTexturing(); virtual void disableBlending(); + virtual void setupLayerMasking(const Texture& /*maskTexture*/, float /*alphaThreshold*/) {} + virtual void disableLayerMasking() {} virtual void drawMesh(const Mesh& mesh); diff --git a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp index a35aa78..6333a41 100644 --- a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp +++ b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp @@ -40,7 +40,7 @@ namespace android { // --------------------------------------------------------------------------- GLES20RenderEngine::GLES20RenderEngine() : - mVpWidth(0), mVpHeight(0) { + mVpWidth(0), mVpHeight(0), mProjectionRotation(Transform::ROT_0) { glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims); @@ -115,6 +115,9 @@ void GLES20RenderEngine::setViewportAndProjection( mState.setProjectionMatrix(m); mVpWidth = vpw; mVpHeight = vph; + mProjectionSourceCrop = sourceCrop; + mProjectionYSwap = yswap; + mProjectionRotation = rotation; } void GLES20RenderEngine::setupLayerBlending( @@ -264,6 +267,30 @@ void GLES20RenderEngine::dump(String8& result) { RenderEngine::dump(result); } +void GLES20RenderEngine::setupLayerMasking(const Texture& maskTexture, float alphaThreshold) { + glActiveTexture(GL_TEXTURE0 + 1); + GLuint target = maskTexture.getTextureTarget(); + glBindTexture(target, maskTexture.getTextureName()); + GLenum filter = GL_NEAREST; + if (maskTexture.getFiltering()) { + filter = GL_LINEAR; + } + glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, filter); + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, filter); + + if (alphaThreshold < 0) alphaThreshold = 0; + if (alphaThreshold > 1.0f) alphaThreshold = 1.0f; + + mState.setMasking(maskTexture, alphaThreshold); + glActiveTexture(GL_TEXTURE0); +} + +void GLES20RenderEngine::disableLayerMasking() { + mState.disableMasking(); +} + // --------------------------------------------------------------------------- }; // namespace android // --------------------------------------------------------------------------- diff --git a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h index 6074a3d..414a999 100644 --- a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h +++ b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h @@ -42,6 +42,9 @@ class GLES20RenderEngine : public RenderEngine { GLint mMaxTextureSize; GLuint mVpWidth; GLuint mVpHeight; + Rect mProjectionSourceCrop; + bool mProjectionYSwap; + Transform::orientation_flags mProjectionRotation; struct Group { GLuint texture; @@ -76,11 +79,18 @@ protected: virtual mat4 setupColorTransform(const mat4& colorTransform); virtual void disableTexturing(); virtual void disableBlending(); + virtual void setupLayerMasking(const Texture& maskTexture, float alphaThreshold); + virtual void disableLayerMasking(); virtual void drawMesh(const Mesh& mesh); virtual size_t getMaxTextureSize() const; virtual size_t getMaxViewportDims() const; + virtual bool getProjectionYSwap() { return mProjectionYSwap; } + virtual size_t getViewportWidth() const { return mVpWidth; } + virtual size_t getViewportHeight() const { return mVpHeight; } + virtual Rect getProjectionSourceCrop() const { return mProjectionSourceCrop; } + virtual Transform::orientation_flags getProjectionRotation() const { return mProjectionRotation; } }; // --------------------------------------------------------------------------- diff --git a/services/surfaceflinger/RenderEngine/Program.cpp b/services/surfaceflinger/RenderEngine/Program.cpp index 0424e0c..936cb1b 100644 --- a/services/surfaceflinger/RenderEngine/Program.cpp +++ b/services/surfaceflinger/RenderEngine/Program.cpp @@ -64,6 +64,8 @@ Program::Program(const ProgramCache::Key& /*needs*/, const char* vertex, const c mSamplerLoc = glGetUniformLocation(programId, "sampler"); mColorLoc = glGetUniformLocation(programId, "color"); mAlphaPlaneLoc = glGetUniformLocation(programId, "alphaPlane"); + mSamplerMaskLoc = glGetUniformLocation(programId, "samplerMask"); + mMaskAlphaThresholdLoc = glGetUniformLocation(programId, "maskAlphaThreshold"); // set-up the default values for our uniforms glUseProgram(programId); @@ -143,6 +145,12 @@ void Program::setUniforms(const Description& desc) { } // these uniforms are always present glUniformMatrix4fv(mProjectionMatrixLoc, 1, GL_FALSE, desc.mProjectionMatrix.asArray()); + if (mSamplerMaskLoc >= 0) { + glUniform1i(mSamplerMaskLoc, 1); + } + if (mMaskAlphaThresholdLoc >= 0) { + glUniform1f(mMaskAlphaThresholdLoc, desc.mMaskAlphaThreshold); + } } } /* namespace android */ diff --git a/services/surfaceflinger/RenderEngine/Program.h b/services/surfaceflinger/RenderEngine/Program.h index 36bd120..08dee59 100644 --- a/services/surfaceflinger/RenderEngine/Program.h +++ b/services/surfaceflinger/RenderEngine/Program.h @@ -84,6 +84,9 @@ private: /* location of the color uniform */ GLint mColorLoc; + + GLint mSamplerMaskLoc; + GLint mMaskAlphaThresholdLoc; }; diff --git a/services/surfaceflinger/RenderEngine/ProgramCache.cpp b/services/surfaceflinger/RenderEngine/ProgramCache.cpp index ba11259..33ff7d0 100644 --- a/services/surfaceflinger/RenderEngine/ProgramCache.cpp +++ b/services/surfaceflinger/RenderEngine/ProgramCache.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +//#define LOG_NDEBUG 0 + #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> @@ -110,9 +112,27 @@ void ProgramCache::primeCache() { shaderCount++; } } + + // Keys that are actually used by blurring. + // This is obtained by log msg from useProgram() + uint32_t blurringKeys[] = { + 0x01000015, + 0x01000011, + }; + for (size_t i=0; i<sizeof(blurringKeys)/sizeof(blurringKeys[0]); ++i) { + Key shaderKey; + shaderKey.set(blurringKeys[i], blurringKeys[i]); + Program* program = mCache.valueFor(shaderKey); + if (program == NULL) { + program = generateProgram(shaderKey); + mCache.add(shaderKey, program); + shaderCount++; + } + } + nsecs_t timeAfter = systemTime(); float compileTimeMs = static_cast<float>(timeAfter - timeBefore) / 1.0E6; - ALOGD("shader cache generated - %u shaders in %f ms\n", shaderCount, compileTimeMs); + ALOGD("SF. shader cache generated - %u shaders in %f ms\n", shaderCount, compileTimeMs); } ProgramCache::Key ProgramCache::computeKey(const Description& description) { @@ -129,15 +149,20 @@ ProgramCache::Key ProgramCache::computeKey(const Description& description) { .set(Key::OPACITY_MASK, description.mOpaque ? Key::OPACITY_OPAQUE : Key::OPACITY_TRANSLUCENT) .set(Key::COLOR_MATRIX_MASK, - description.mColorMatrixEnabled ? Key::COLOR_MATRIX_ON : Key::COLOR_MATRIX_OFF); + description.mColorMatrixEnabled ? Key::COLOR_MATRIX_ON : Key::COLOR_MATRIX_OFF) + .set(Key::TEXTURE_MASKING_MASK, + !description.mMaskTextureEnabled ? Key::TEXTURE_MASKING_OFF : + description.mMaskTexture.getTextureTarget() == GL_TEXTURE_EXTERNAL_OES ? Key::TEXTURE_MASKING_EXT : + description.mMaskTexture.getTextureTarget() == GL_TEXTURE_2D ? Key::TEXTURE_MASKING_2D : + Key::TEXTURE_MASKING_OFF); return needs; } String8 ProgramCache::generateVertexShader(const Key& needs) { Formatter vs; if (needs.isTexturing()) { - vs << "attribute vec4 texCoords;" - << "varying vec2 outTexCoords;"; + vs << "attribute vec4 texCoords;" + << "varying vec2 outTexCoords;"; } vs << "attribute vec4 position;" << "uniform mat4 projection;" @@ -145,7 +170,7 @@ String8 ProgramCache::generateVertexShader(const Key& needs) { << "void main(void) {" << indent << "gl_Position = projection * position;"; if (needs.isTexturing()) { - vs << "outTexCoords = (texture * texCoords).st;"; + vs << "outTexCoords = (texture * texCoords).st;"; } vs << dedent << "}"; return vs.getString(); @@ -169,6 +194,14 @@ String8 ProgramCache::generateFragmentShader(const Key& needs) { } else if (needs.getTextureTarget() == Key::TEXTURE_OFF) { fs << "uniform vec4 color;"; } + if (needs.getTextureMaskingTarget() == Key::TEXTURE_MASKING_EXT) { + fs << "uniform samplerExternalOES samplerMask;"; + } else if (needs.getTextureMaskingTarget() == Key::TEXTURE_MASKING_2D) { + fs << "uniform sampler2D samplerMask;"; + } + if (needs.getTextureMaskingTarget() != Key::TEXTURE_MASKING_OFF) { + fs << "uniform float maskAlphaThreshold;"; + } if (needs.hasPlaneAlpha()) { fs << "uniform float alphaPlane;"; } @@ -177,7 +210,12 @@ String8 ProgramCache::generateFragmentShader(const Key& needs) { } fs << "void main(void) {" << indent; if (needs.isTexturing()) { - fs << "gl_FragColor = texture2D(sampler, outTexCoords);"; + if (needs.getTextureMaskingTarget() != Key::TEXTURE_MASKING_OFF) { + fs << "if (texture2D(samplerMask, outTexCoords).a <= maskAlphaThreshold) discard;" + << "gl_FragColor = texture2D(sampler, outTexCoords);"; + } else { + fs << "gl_FragColor = texture2D(sampler, outTexCoords);"; + } } else { fs << "gl_FragColor = color;"; } @@ -235,9 +273,6 @@ void ProgramCache::useProgram(const Description& description) { program = generateProgram(needs); mCache.add(needs, program); time += systemTime(); - - //ALOGD(">>> generated new program: needs=%08X, time=%u ms (%d programs)", - // needs.mNeeds, uint32_t(ns2ms(time)), mCache.size()); } // here we have a suitable program for this description diff --git a/services/surfaceflinger/RenderEngine/ProgramCache.h b/services/surfaceflinger/RenderEngine/ProgramCache.h index 1fa53d3..3824e73 100644 --- a/services/surfaceflinger/RenderEngine/ProgramCache.h +++ b/services/surfaceflinger/RenderEngine/ProgramCache.h @@ -69,6 +69,11 @@ public: COLOR_MATRIX_OFF = 0x00000000, COLOR_MATRIX_ON = 0x00000020, COLOR_MATRIX_MASK = 0x00000020, + + TEXTURE_MASKING_OFF = 0x00000000, + TEXTURE_MASKING_EXT = 0x00800000, + TEXTURE_MASKING_2D = 0x01000000, + TEXTURE_MASKING_MASK = 0x01800000, }; inline Key() : mKey(0) { } @@ -97,6 +102,12 @@ public: inline bool hasColorMatrix() const { return (mKey & COLOR_MATRIX_MASK) == COLOR_MATRIX_ON; } + inline bool isTextureMasking() const { + return (mKey & TEXTURE_MASKING_MASK) != TEXTURE_MASKING_OFF; + } + inline int getTextureMaskingTarget() const { + return (mKey & TEXTURE_MASKING_MASK); + } // this is the definition of a friend function -- not a method of class Needs friend inline int strictly_order_type(const Key& lhs, const Key& rhs) { diff --git a/services/surfaceflinger/RenderEngine/RenderEngine.h b/services/surfaceflinger/RenderEngine/RenderEngine.h index c9a043a..a669fdd 100644 --- a/services/surfaceflinger/RenderEngine/RenderEngine.h +++ b/services/surfaceflinger/RenderEngine/RenderEngine.h @@ -110,6 +110,8 @@ public: virtual void disableTexturing() = 0; virtual void disableBlending() = 0; + virtual void setupLayerMasking(const Texture& maskTexture, float alphaThreshold) = 0; + virtual void disableLayerMasking() = 0; // drawing virtual void drawMesh(const Mesh& mesh) = 0; @@ -117,6 +119,11 @@ public: // queries virtual size_t getMaxTextureSize() const = 0; virtual size_t getMaxViewportDims() const = 0; + virtual bool getProjectionYSwap() { return 0; } + virtual size_t getViewportWidth() const { return 1; } + virtual size_t getViewportHeight() const { return 1; } + virtual Rect getProjectionSourceCrop() const { return Rect(0, 0, 1, 1); } + virtual Transform::orientation_flags getProjectionRotation() const { return Transform::ROT_0; } EGLConfig getEGLConfig() const; EGLContext getEGLContext() const; |