Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49457ac0 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

Encapsulate textures into their own Texture class

the main reason for doing this is so that we can have
access to informations about a texture (like its dimension)
close to where we generate and use shaders in ES 2.0.
Previously, there wasn't any way to get to a texture's size
from a RenderEngine implementation.

Bug: 8679321

Change-Id: I388b338a70d07e3e8177dde248710ea1e4c82dff
parent e048a437
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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
+6 −1
Original line number Diff line number Diff line
@@ -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();
    }
+3 −0
Original line number Diff line number Diff line
@@ -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
+6 −19
Original line number Diff line number Diff line
@@ -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;
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 */
+6 −8
Original line number Diff line number Diff line
@@ -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;
Loading