diff options
-rw-r--r-- | services/surfaceflinger/Android.mk | 1 | ||||
-rw-r--r-- | services/surfaceflinger/Layer.cpp | 7 | ||||
-rw-r--r-- | services/surfaceflinger/Layer.h | 3 | ||||
-rw-r--r-- | services/surfaceflinger/RenderEngine/Description.cpp | 25 | ||||
-rw-r--r-- | services/surfaceflinger/RenderEngine/Description.h | 14 | ||||
-rw-r--r-- | services/surfaceflinger/RenderEngine/GLES11RenderEngine.cpp | 19 | ||||
-rw-r--r-- | services/surfaceflinger/RenderEngine/GLES11RenderEngine.h | 3 | ||||
-rw-r--r-- | services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp | 26 | ||||
-rw-r--r-- | services/surfaceflinger/RenderEngine/GLES20RenderEngine.h | 3 | ||||
-rw-r--r-- | services/surfaceflinger/RenderEngine/Program.cpp | 2 | ||||
-rw-r--r-- | services/surfaceflinger/RenderEngine/ProgramCache.cpp | 5 | ||||
-rw-r--r-- | services/surfaceflinger/RenderEngine/RenderEngine.h | 3 | ||||
-rw-r--r-- | services/surfaceflinger/RenderEngine/Texture.cpp | 83 | ||||
-rw-r--r-- | services/surfaceflinger/RenderEngine/Texture.h | 55 |
14 files changed, 193 insertions, 56 deletions
diff --git a/services/surfaceflinger/Android.mk b/services/surfaceflinger/Android.mk index 7a14fb0..873bd5d 100644 --- a/services/surfaceflinger/Android.mk +++ b/services/surfaceflinger/Android.mk @@ -25,6 +25,7 @@ LOCAL_SRC_FILES:= \ RenderEngine/ProgramCache.cpp \ RenderEngine/GLExtensions.cpp \ RenderEngine/RenderEngine.cpp \ + RenderEngine/Texture.cpp \ RenderEngine/GLES10RenderEngine.cpp \ RenderEngine/GLES11RenderEngine.cpp \ RenderEngine/GLES20RenderEngine.cpp diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 531db20..7150fa1 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -82,6 +82,7 @@ Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client, { mCurrentCrop.makeInvalid(); mFlinger->getRenderEngine().genTextures(1, &mTextureName); + mTexture.init(Texture::TEXTURE_EXTERNAL, mTextureName); uint32_t layerFlags = 0; if (flags & ISurfaceComposerClient::eHidden) @@ -483,7 +484,11 @@ void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const mSurfaceFlingerConsumer->getTransformMatrix(textureMatrix); // Set things up for texturing. - engine.setupLayerTexturing(mTextureName, useFiltering, textureMatrix); + mTexture.setDimensions(mActiveBuffer->getWidth(), mActiveBuffer->getHeight()); + mTexture.setFiltering(useFiltering); + mTexture.setMatrix(textureMatrix); + + engine.setupLayerTexturing(mTexture); } else { engine.setupLayerBlackedOut(); } diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index faf3666..ef4a7e9 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -45,6 +45,7 @@ #include "DisplayHardware/HWComposer.h" #include "DisplayHardware/FloatRect.h" #include "RenderEngine/Mesh.h" +#include "RenderEngine/Texture.h" namespace android { @@ -359,6 +360,8 @@ private: bool mNeedsFiltering; // The mesh used to draw the layer in GLES composition mode mutable Mesh mMesh; + // The mesh used to draw the layer in GLES composition mode + mutable Texture mTexture; // page-flip thread (currently main thread) bool mSecure; // no screenshots diff --git a/services/surfaceflinger/RenderEngine/Description.cpp b/services/surfaceflinger/RenderEngine/Description.cpp index 9611b02..8e404b2 100644 --- a/services/surfaceflinger/RenderEngine/Description.cpp +++ b/services/surfaceflinger/RenderEngine/Description.cpp @@ -31,12 +31,11 @@ Description::Description() : mPlaneAlpha = 1.0f; mPremultipliedAlpha = true; mOpaque = true; - mTextureTarget = GL_TEXTURE_EXTERNAL_OES; + mTextureEnabled = false; const GLfloat m[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 }; memset(mColor, 0, sizeof(mColor)); memcpy(mProjectionMatrix, m, sizeof(mProjectionMatrix)); - memcpy(mTextureMatrix, m, sizeof(mTextureMatrix)); } Description::~Description() { @@ -61,21 +60,14 @@ void Description::setOpaque(bool opaque) { } } -void Description::setTextureName(GLenum target, GLuint tname) { - if (target != mTextureTarget) { - mTextureTarget = target; - } - if (tname != mTextureName) { - mTextureName = tname; - mUniformsDirty = true; - } +void Description::setTexture(const Texture& texture) { + mTexture = texture; + mTextureEnabled = true; + mUniformsDirty = true; } void Description::disableTexture() { - if (mTextureTarget != 0) { - mTextureTarget = 0; - } - mTextureName = 0; + mTextureEnabled = false; } void Description::setColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) { @@ -91,9 +83,4 @@ void Description::setProjectionMatrix(GLfloat const* mtx) { mUniformsDirty = true; } -void Description::setTextureMatrix(GLfloat const* mtx) { - memcpy(mTextureMatrix, mtx, sizeof(mTextureMatrix)); - mUniformsDirty = true; -} - } /* namespace android */ diff --git a/services/surfaceflinger/RenderEngine/Description.h b/services/surfaceflinger/RenderEngine/Description.h index 47b0d8e..862301b 100644 --- a/services/surfaceflinger/RenderEngine/Description.h +++ b/services/surfaceflinger/RenderEngine/Description.h @@ -15,6 +15,7 @@ */ #include <GLES2/gl2.h> +#include "Texture.h" #ifndef SF_RENDER_ENGINE_DESCRIPTION_H_ #define SF_RENDER_ENGINE_DESCRIPTION_H_ @@ -40,17 +41,15 @@ class Description { bool mPremultipliedAlpha; // whether this layer is marked as opaque bool mOpaque; - // texture target, TEXTURE_2D or TEXTURE_EXTERNAL - GLenum mTextureTarget; - // name of the texture - GLuint mTextureName; + // Texture this layer uses + Texture mTexture; + bool mTextureEnabled; + // color used when texturing is disabled GLclampf mColor[4]; // projection matrix GLfloat mProjectionMatrix[16]; - // texture matrix - GLfloat mTextureMatrix[16]; public: Description(); @@ -59,11 +58,10 @@ public: void setPlaneAlpha(GLclampf planeAlpha); void setPremultipliedAlpha(bool premultipliedAlpha); void setOpaque(bool opaque); - void setTextureName(GLenum target, GLuint tname); + void setTexture(const Texture& texture); void disableTexture(); void setColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); void setProjectionMatrix(GLfloat const* mtx); - void setTextureMatrix(GLfloat const* mtx); private: bool mUniformsDirty; diff --git a/services/surfaceflinger/RenderEngine/GLES11RenderEngine.cpp b/services/surfaceflinger/RenderEngine/GLES11RenderEngine.cpp index 19f17df..06125b0 100644 --- a/services/surfaceflinger/RenderEngine/GLES11RenderEngine.cpp +++ b/services/surfaceflinger/RenderEngine/GLES11RenderEngine.cpp @@ -22,6 +22,7 @@ #include "GLES11RenderEngine.h" #include "Mesh.h" +#include "Texture.h" // --------------------------------------------------------------------------- namespace android { @@ -147,19 +148,19 @@ void GLES11RenderEngine::setupDimLayerBlending(int alpha) { glColor4f(0, 0, 0, alpha/255.0f); } -void GLES11RenderEngine::setupLayerTexturing(size_t textureName, - bool useFiltering, const float* textureMatrix) { - glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureName); +void GLES11RenderEngine::setupLayerTexturing(const Texture& texture) { + GLuint target = texture.getTextureTarget(); + glBindTexture(target, texture.getTextureName()); GLenum filter = GL_NEAREST; - if (useFiltering) { + if (texture.getFiltering()) { filter = GL_LINEAR; } - glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, filter); - glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, filter); + glTexParameterx(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterx(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameterx(target, GL_TEXTURE_MAG_FILTER, filter); + glTexParameterx(target, GL_TEXTURE_MIN_FILTER, filter); glMatrixMode(GL_TEXTURE); - glLoadMatrixf(textureMatrix); + glLoadMatrixf(texture.getMatrix()); glMatrixMode(GL_MODELVIEW); glDisable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_EXTERNAL_OES); diff --git a/services/surfaceflinger/RenderEngine/GLES11RenderEngine.h b/services/surfaceflinger/RenderEngine/GLES11RenderEngine.h index d20ff1c..90fc82f 100644 --- a/services/surfaceflinger/RenderEngine/GLES11RenderEngine.h +++ b/services/surfaceflinger/RenderEngine/GLES11RenderEngine.h @@ -31,6 +31,7 @@ namespace android { class String8; class Mesh; +class Texture; class GLES11RenderEngine : public RenderEngine { GLuint mProtectedTexName; @@ -51,7 +52,7 @@ protected: virtual void setViewportAndProjection(size_t vpw, size_t vph, size_t w, size_t h, bool yswap); virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha); virtual void setupDimLayerBlending(int alpha); - virtual void setupLayerTexturing(size_t textureName, bool useFiltering, const float* textureMatrix); + virtual void setupLayerTexturing(const Texture& texture); virtual void setupLayerBlackedOut(); virtual void disableTexturing(); virtual void disableBlending(); diff --git a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp index 4add66b..dcad390 100644 --- a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp +++ b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp @@ -29,6 +29,7 @@ #include "ProgramCache.h" #include "Description.h" #include "Mesh.h" +#include "Texture.h" // --------------------------------------------------------------------------- namespace android { @@ -126,27 +127,26 @@ void GLES20RenderEngine::setupDimLayerBlending(int alpha) { disableTexturing(); } -void GLES20RenderEngine::setupLayerTexturing(size_t textureName, - bool useFiltering, const float* textureMatrix) { - glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureName); +void GLES20RenderEngine::setupLayerTexturing(const Texture& texture) { + GLuint target = texture.getTextureTarget(); + glBindTexture(target, texture.getTextureName()); GLenum filter = GL_NEAREST; - if (useFiltering) { + if (texture.getFiltering()) { filter = GL_LINEAR; } - glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, filter); - glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, filter); + 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); - mState.setTextureName(GL_TEXTURE_EXTERNAL_OES, textureName); - mState.setTextureMatrix(textureMatrix); + mState.setTexture(texture); } void GLES20RenderEngine::setupLayerBlackedOut() { - const GLfloat m[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 }; glBindTexture(GL_TEXTURE_2D, mProtectedTexName); - mState.setTextureName(GL_TEXTURE_2D, mProtectedTexName); - mState.setTextureMatrix(m); + Texture texture(Texture::TEXTURE_2D, mProtectedTexName); + texture.setDimensions(1, 1); // FIXME: we should get that from somewhere + mState.setTexture(texture); } void GLES20RenderEngine::disableTexturing() { diff --git a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h index 2998874..3ff6d9f 100644 --- a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h +++ b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h @@ -33,6 +33,7 @@ namespace android { class String8; class Mesh; +class Texture; class GLES20RenderEngine : public RenderEngine { GLuint mProtectedTexName; @@ -55,7 +56,7 @@ protected: virtual void setViewportAndProjection(size_t vpw, size_t vph, size_t w, size_t h, bool yswap); virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha); virtual void setupDimLayerBlending(int alpha); - virtual void setupLayerTexturing(size_t textureName, bool useFiltering, const float* textureMatrix); + virtual void setupLayerTexturing(const Texture& texture); virtual void setupLayerBlackedOut(); virtual void disableTexturing(); virtual void disableBlending(); diff --git a/services/surfaceflinger/RenderEngine/Program.cpp b/services/surfaceflinger/RenderEngine/Program.cpp index 586d1ad..c5691d7 100644 --- a/services/surfaceflinger/RenderEngine/Program.cpp +++ b/services/surfaceflinger/RenderEngine/Program.cpp @@ -129,7 +129,7 @@ void Program::setUniforms(const Description& desc) { if (mSamplerLoc >= 0) { glUniform1i(mSamplerLoc, 0); - glUniformMatrix4fv(mTextureMatrixLoc, 1, GL_FALSE, desc.mTextureMatrix); + glUniformMatrix4fv(mTextureMatrixLoc, 1, GL_FALSE, desc.mTexture.getMatrix()); } if (mAlphaPlaneLoc >= 0) { glUniform1f(mAlphaPlaneLoc, desc.mPlaneAlpha); diff --git a/services/surfaceflinger/RenderEngine/ProgramCache.cpp b/services/surfaceflinger/RenderEngine/ProgramCache.cpp index 4911609..62d2eab 100644 --- a/services/surfaceflinger/RenderEngine/ProgramCache.cpp +++ b/services/surfaceflinger/RenderEngine/ProgramCache.cpp @@ -87,8 +87,9 @@ ProgramCache::~ProgramCache() { ProgramCache::Key ProgramCache::computeKey(const Description& description) { Key needs; needs.set(Key::TEXTURE_MASK, - (description.mTextureTarget == GL_TEXTURE_EXTERNAL_OES) ? Key::TEXTURE_EXT : - (description.mTextureTarget == GL_TEXTURE_2D) ? Key::TEXTURE_2D : + !description.mTextureEnabled ? Key::TEXTURE_OFF : + description.mTexture.getTextureTarget() == GL_TEXTURE_EXTERNAL_OES ? Key::TEXTURE_EXT : + description.mTexture.getTextureTarget() == GL_TEXTURE_2D ? Key::TEXTURE_2D : Key::TEXTURE_OFF) .set(Key::PLANE_ALPHA_MASK, (description.mPlaneAlpha < 1) ? Key::PLANE_ALPHA_LT_ONE : Key::PLANE_ALPHA_EQ_ONE) diff --git a/services/surfaceflinger/RenderEngine/RenderEngine.h b/services/surfaceflinger/RenderEngine/RenderEngine.h index 3c2b2ea..82765c7 100644 --- a/services/surfaceflinger/RenderEngine/RenderEngine.h +++ b/services/surfaceflinger/RenderEngine/RenderEngine.h @@ -32,6 +32,7 @@ class String8; class Rect; class Region; class Mesh; +class Texture; class RenderEngine { enum GlesVersion { @@ -84,7 +85,7 @@ public: virtual void setViewportAndProjection(size_t vpw, size_t vph, size_t w, size_t h, bool yswap) = 0; virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0; virtual void setupDimLayerBlending(int alpha) = 0; - virtual void setupLayerTexturing(size_t textureName, bool useFiltering, const float* textureMatrix) = 0; + virtual void setupLayerTexturing(const Texture& texture) = 0; virtual void setupLayerBlackedOut() = 0; virtual void disableTexturing() = 0; diff --git a/services/surfaceflinger/RenderEngine/Texture.cpp b/services/surfaceflinger/RenderEngine/Texture.cpp new file mode 100644 index 0000000..2cb3b65 --- /dev/null +++ b/services/surfaceflinger/RenderEngine/Texture.cpp @@ -0,0 +1,83 @@ +/* + * Copyright 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <string.h> + +#include "Texture.h" + +namespace android { + +Texture::Texture() : + mTextureName(0), mTextureTarget(TEXTURE_2D), + mWidth(0), mHeight(0), mFiltering(false) { + const float m[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 }; + memcpy(mTextureMatrix, m, sizeof(mTextureMatrix)); +} + +Texture::Texture(Target textureTarget, uint32_t textureName) : + mTextureName(textureName), mTextureTarget(textureTarget), + mWidth(0), mHeight(0), mFiltering(false) { + const float m[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 }; + memcpy(mTextureMatrix, m, sizeof(mTextureMatrix)); +} + +void Texture::init(Target textureTarget, uint32_t textureName) { + mTextureName = textureName; + mTextureTarget = textureTarget; +} + +Texture::~Texture() { +} + + +void Texture::setMatrix(float const* matrix) { + memcpy(mTextureMatrix, matrix, sizeof(mTextureMatrix)); +} + +void Texture::setFiltering(bool enabled) { + mFiltering = enabled; +} + +void Texture::setDimensions(size_t width, size_t height) { + mWidth = width; + mHeight = height; +} + +uint32_t Texture::getTextureName() const { + return mTextureName; +} + +uint32_t Texture::getTextureTarget() const { + return mTextureTarget; +} + +float const* Texture::getMatrix() const { + return mTextureMatrix; +} + +bool Texture::getFiltering() const { + return mFiltering; +} + +size_t Texture::getWidth() const { + return mWidth; +} + +size_t Texture::getHeight() const { + return mHeight; +} + +} /* namespace android */ diff --git a/services/surfaceflinger/RenderEngine/Texture.h b/services/surfaceflinger/RenderEngine/Texture.h new file mode 100644 index 0000000..981b475 --- /dev/null +++ b/services/surfaceflinger/RenderEngine/Texture.h @@ -0,0 +1,55 @@ +/* + * Copyright 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdint.h> + +#ifndef SF_RENDER_ENGINE_TEXTURE_H +#define SF_RENDER_ENGINE_TEXTURE_H + +namespace android { + +class Texture { + uint32_t mTextureName; + uint32_t mTextureTarget; + size_t mWidth; + size_t mHeight; + bool mFiltering; + float mTextureMatrix[16]; + +public: + enum Target { TEXTURE_2D = 0x0DE1, TEXTURE_EXTERNAL = 0x8D65 }; + + Texture(); + Texture(Target textureTarget, uint32_t textureName); + ~Texture(); + + void init(Target textureTarget, uint32_t textureName); + + void setMatrix(float const* matrix); + void setFiltering(bool enabled); + void setDimensions(size_t width, size_t height); + + uint32_t getTextureName() const; + uint32_t getTextureTarget() const; + + float const* getMatrix() const; + bool getFiltering() const; + size_t getWidth() const; + size_t getHeight() const; +}; + +} /* namespace android */ +#endif /* SF_RENDER_ENGINE_TEXTURE_H */ |