RenderEngine/ProgramCache.cpp \
RenderEngine/GLExtensions.cpp \
RenderEngine/RenderEngine.cpp \
+ RenderEngine/Texture.cpp \
RenderEngine/GLES10RenderEngine.cpp \
RenderEngine/GLES11RenderEngine.cpp \
RenderEngine/GLES20RenderEngine.cpp
{
mCurrentCrop.makeInvalid();
mFlinger->getRenderEngine().genTextures(1, &mTextureName);
+ mTexture.init(Texture::TEXTURE_EXTERNAL, mTextureName);
uint32_t layerFlags = 0;
if (flags & ISurfaceComposerClient::eHidden)
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();
}
#include "DisplayHardware/HWComposer.h"
#include "DisplayHardware/FloatRect.h"
#include "RenderEngine/Mesh.h"
+#include "RenderEngine/Texture.h"
namespace android {
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
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() {
}
}
-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) {
mUniformsDirty = true;
}
-void Description::setTextureMatrix(GLfloat const* mtx) {
- memcpy(mTextureMatrix, mtx, sizeof(mTextureMatrix));
- mUniformsDirty = true;
-}
-
} /* namespace android */
*/
#include <GLES2/gl2.h>
+#include "Texture.h"
#ifndef SF_RENDER_ENGINE_DESCRIPTION_H_
#define SF_RENDER_ENGINE_DESCRIPTION_H_
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();
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;
#include "GLES11RenderEngine.h"
#include "Mesh.h"
+#include "Texture.h"
// ---------------------------------------------------------------------------
namespace android {
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);
class String8;
class Mesh;
+class Texture;
class GLES11RenderEngine : public RenderEngine {
GLuint mProtectedTexName;
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();
#include "ProgramCache.h"
#include "Description.h"
#include "Mesh.h"
+#include "Texture.h"
// ---------------------------------------------------------------------------
namespace android {
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() {
class String8;
class Mesh;
+class Texture;
class GLES20RenderEngine : public RenderEngine {
GLuint mProtectedTexName;
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();
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);
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)
class Rect;
class Region;
class Mesh;
+class Texture;
class RenderEngine {
enum GlesVersion {
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;
--- /dev/null
+/*
+ * 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 */
--- /dev/null
+/*
+ * 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 */