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

Commit d7328ae7 authored by Chris Craik's avatar Chris Craik Committed by Android (Google) Code Review
Browse files

Merge "Refactor blending and texture gl state"

parents 0e0b7310 44eb2c00
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -7,11 +7,13 @@ LOCAL_CLANG_CFLAGS += \
LOCAL_SRC_FILES := \
LOCAL_SRC_FILES := \
    font/CacheTexture.cpp \
    font/CacheTexture.cpp \
    font/Font.cpp \
    font/Font.cpp \
    renderstate/Blend.cpp \
    renderstate/MeshState.cpp \
    renderstate/MeshState.cpp \
    renderstate/PixelBufferState.cpp \
    renderstate/PixelBufferState.cpp \
    renderstate/RenderState.cpp \
    renderstate/RenderState.cpp \
    renderstate/Scissor.cpp \
    renderstate/Scissor.cpp \
    renderstate/Stencil.cpp \
    renderstate/Stencil.cpp \
    renderstate/TextureState.cpp \
    renderthread/CanvasContext.cpp \
    renderthread/CanvasContext.cpp \
    renderthread/DrawFrameTask.cpp \
    renderthread/DrawFrameTask.cpp \
    renderthread/EglManager.cpp \
    renderthread/EglManager.cpp \
+7 −79
Original line number Original line Diff line number Diff line
@@ -49,6 +49,7 @@ Caches* Caches::sInstance = nullptr;


Caches::Caches(RenderState& renderState)
Caches::Caches(RenderState& renderState)
        : patchCache(renderState)
        : patchCache(renderState)
        , dither(*this)
        , mRenderState(&renderState)
        , mRenderState(&renderState)
        , mExtensions(Extensions::getInstance())
        , mExtensions(Extensions::getInstance())
        , mInitialized(false) {
        , mInitialized(false) {
@@ -71,13 +72,8 @@ bool Caches::init() {


    ATRACE_NAME("Caches::init");
    ATRACE_NAME("Caches::init");


    glActiveTexture(gTextureUnits[0]);
    mTextureUnit = 0;


    mRegionMesh = nullptr;
    mRegionMesh = nullptr;
    blend = false;
    lastSrcMode = GL_ZERO;
    lastDstMode = GL_ZERO;
    currentProgram = nullptr;
    currentProgram = nullptr;


    mFunctorsCount = 0;
    mFunctorsCount = 0;
@@ -90,8 +86,8 @@ bool Caches::init() {


    mInitialized = true;
    mInitialized = true;


    resetBoundTextures();
    mPixelBufferState = new PixelBufferState();
    mPixelBufferState.reset(new PixelBufferState());
    mTextureState = new TextureState();


    return true;
    return true;
}
}
@@ -122,12 +118,6 @@ void Caches::initExtensions() {
}
}


void Caches::initConstraints() {
void Caches::initConstraints() {
    GLint maxTextureUnits;
    glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
    if (maxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) {
        ALOGW("At least %d texture units are required!", REQUIRED_TEXTURE_UNITS_COUNT);
    }

    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
}
}


@@ -216,8 +206,10 @@ void Caches::terminate() {


    clearGarbage();
    clearGarbage();


    mPixelBufferState.release();
    delete mPixelBufferState;

    mPixelBufferState = nullptr;
    delete mTextureState;
    mTextureState = nullptr;
    mInitialized = false;
    mInitialized = false;
}
}


@@ -347,70 +339,6 @@ void Caches::flush(FlushMode mode) {
    glFinish();
    glFinish();
}
}


///////////////////////////////////////////////////////////////////////////////
// Textures
///////////////////////////////////////////////////////////////////////////////

void Caches::activeTexture(GLuint textureUnit) {
    if (mTextureUnit != textureUnit) {
        glActiveTexture(gTextureUnits[textureUnit]);
        mTextureUnit = textureUnit;
    }
}

void Caches::resetActiveTexture() {
    mTextureUnit = -1;
}

void Caches::bindTexture(GLuint texture) {
    if (mBoundTextures[mTextureUnit] != texture) {
        glBindTexture(GL_TEXTURE_2D, texture);
        mBoundTextures[mTextureUnit] = texture;
    }
}

void Caches::bindTexture(GLenum target, GLuint texture) {
    if (target == GL_TEXTURE_2D) {
        bindTexture(texture);
    } else {
        // GLConsumer directly calls glBindTexture() with
        // target=GL_TEXTURE_EXTERNAL_OES, don't cache this target
        // since the cached state could be stale
        glBindTexture(target, texture);
    }
}

void Caches::deleteTexture(GLuint texture) {
    // When glDeleteTextures() is called on a currently bound texture,
    // OpenGL ES specifies that the texture is then considered unbound
    // Consider the following series of calls:
    //
    // glGenTextures -> creates texture name 2
    // glBindTexture(2)
    // glDeleteTextures(2) -> 2 is now unbound
    // glGenTextures -> can return 2 again
    //
    // If we don't call glBindTexture(2) after the second glGenTextures
    // call, any texture operation will be performed on the default
    // texture (name=0)

    unbindTexture(texture);

    glDeleteTextures(1, &texture);
}

void Caches::resetBoundTextures() {
    memset(mBoundTextures, 0, REQUIRED_TEXTURE_UNITS_COUNT * sizeof(GLuint));
}

void Caches::unbindTexture(GLuint texture) {
    for (int i = 0; i < REQUIRED_TEXTURE_UNITS_COUNT; i++) {
        if (mBoundTextures[i] == texture) {
            mBoundTextures[i] = 0;
        }
    }
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Tiling
// Tiling
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
+5 −67
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@
#include "PathCache.h"
#include "PathCache.h"
#include "RenderBufferCache.h"
#include "RenderBufferCache.h"
#include "renderstate/PixelBufferState.h"
#include "renderstate/PixelBufferState.h"
#include "renderstate/TextureState.h"
#include "ResourceCache.h"
#include "ResourceCache.h"
#include "TessellationCache.h"
#include "TessellationCache.h"
#include "TextDropShadowCache.h"
#include "TextDropShadowCache.h"
@@ -58,20 +59,6 @@ namespace uirenderer {


class GammaFontRenderer;
class GammaFontRenderer;


///////////////////////////////////////////////////////////////////////////////
// Globals
///////////////////////////////////////////////////////////////////////////////

// GL ES 2.0 defines that at least 16 texture units must be supported
#define REQUIRED_TEXTURE_UNITS_COUNT 3

// Must define as many texture units as specified by REQUIRED_TEXTURE_UNITS_COUNT
static const GLenum gTextureUnits[] = {
    GL_TEXTURE0,
    GL_TEXTURE1,
    GL_TEXTURE2
};

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Caches
// Caches
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -155,49 +142,6 @@ public:
    void deleteLayerDeferred(Layer* layer);
    void deleteLayerDeferred(Layer* layer);




    /**
     * Activate the specified texture unit. The texture unit must
     * be specified using an integer number (0 for GL_TEXTURE0 etc.)
     */
    void activeTexture(GLuint textureUnit);

    /**
     * Invalidate the cached value of the active texture unit.
     */
    void resetActiveTexture();

    /**
     * Binds the specified texture as a GL_TEXTURE_2D texture.
     * All texture bindings must be performed with this method or
     * bindTexture(GLenum, GLuint).
     */
    void bindTexture(GLuint texture);

    /**
     * Binds the specified texture with the specified render target.
     * All texture bindings must be performed with this method or
     * bindTexture(GLuint).
     */
    void bindTexture(GLenum target, GLuint texture);

    /**
     * Deletes the specified texture and clears it from the cache
     * of bound textures.
     * All textures must be deleted using this method.
     */
    void deleteTexture(GLuint texture);

    /**
     * Signals that the cache of bound textures should be cleared.
     * Other users of the context may have altered which textures are bound.
     */
    void resetBoundTextures();

    /**
     * Clear the cache of bound textures.
     */
    void unbindTexture(GLuint texture);

    void startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool discard);
    void startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool discard);
    void endTiling();
    void endTiling();


@@ -218,9 +162,6 @@ public:
    void registerFunctors(uint32_t functorCount);
    void registerFunctors(uint32_t functorCount);
    void unregisterFunctors(uint32_t functorCount);
    void unregisterFunctors(uint32_t functorCount);


    bool blend;
    GLenum lastSrcMode;
    GLenum lastDstMode;
    Program* currentProgram;
    Program* currentProgram;


    bool drawDeferDisabled;
    bool drawDeferDisabled;
@@ -278,7 +219,8 @@ public:
    int propertyAmbientShadowStrength;
    int propertyAmbientShadowStrength;
    int propertySpotShadowStrength;
    int propertySpotShadowStrength;


    PixelBufferState& pixelBuffer() { return *mPixelBufferState; }
    PixelBufferState& pixelBufferState() { return *mPixelBufferState; }
    TextureState& textureState() { return *mTextureState; }


private:
private:
    enum OverdrawColorSet {
    enum OverdrawColorSet {
@@ -305,9 +247,8 @@ private:


    RenderState* mRenderState;
    RenderState* mRenderState;


    std::unique_ptr<PixelBufferState> mPixelBufferState; // TODO: move to RenderState
    PixelBufferState* mPixelBufferState = nullptr; // TODO: move to RenderState

    TextureState* mTextureState = nullptr; // TODO: move to RenderState
    GLuint mTextureUnit;


    Extensions& mExtensions;
    Extensions& mExtensions;


@@ -322,9 +263,6 @@ private:


    uint32_t mFunctorsCount;
    uint32_t mFunctorsCount;


    // Caches texture bindings for the GL_TEXTURE_2D target
    GLuint mBoundTextures[REQUIRED_TEXTURE_UNITS_COUNT];

    OverdrawColorSet mOverdrawDebugColorSet;
    OverdrawColorSet mOverdrawDebugColorSet;
}; // class Caches
}; // class Caches


+8 −7
Original line number Original line Diff line number Diff line
@@ -24,7 +24,10 @@ namespace uirenderer {
// Lifecycle
// Lifecycle
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////


Dither::Dither(): mCaches(nullptr), mInitialized(false), mDitherTexture(0) {
Dither::Dither(Caches& caches)
        : mCaches(caches)
        , mInitialized(false)
        , mDitherTexture(0) {
}
}


void Dither::bindDitherTexture() {
void Dither::bindDitherTexture() {
@@ -32,7 +35,7 @@ void Dither::bindDitherTexture() {
        bool useFloatTexture = Extensions::getInstance().hasFloatTextures();
        bool useFloatTexture = Extensions::getInstance().hasFloatTextures();


        glGenTextures(1, &mDitherTexture);
        glGenTextures(1, &mDitherTexture);
        mCaches->bindTexture(mDitherTexture);
        mCaches.textureState().bindTexture(mDitherTexture);


        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -71,13 +74,13 @@ void Dither::bindDitherTexture() {


        mInitialized = true;
        mInitialized = true;
    } else {
    } else {
        mCaches->bindTexture(mDitherTexture);
        mCaches.textureState().bindTexture(mDitherTexture);
    }
    }
}
}


void Dither::clear() {
void Dither::clear() {
    if (mInitialized) {
    if (mInitialized) {
        mCaches->deleteTexture(mDitherTexture);
        mCaches.textureState().deleteTexture(mDitherTexture);
        mInitialized = false;
        mInitialized = false;
    }
    }
}
}
@@ -87,10 +90,8 @@ void Dither::clear() {
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////


void Dither::setupProgram(Program* program, GLuint* textureUnit) {
void Dither::setupProgram(Program* program, GLuint* textureUnit) {
    if (!mCaches) mCaches = &Caches::getInstance();

    GLuint textureSlot = (*textureUnit)++;
    GLuint textureSlot = (*textureUnit)++;
    mCaches->activeTexture(textureSlot);
    mCaches.textureState().activateTexture(textureSlot);


    bindDitherTexture();
    bindDitherTexture();


+2 −2
Original line number Original line Diff line number Diff line
@@ -36,7 +36,7 @@ class Program;
 */
 */
class Dither {
class Dither {
public:
public:
    Dither();
    Dither(Caches& caches);


    void clear();
    void clear();
    void setupProgram(Program* program, GLuint* textureUnit);
    void setupProgram(Program* program, GLuint* textureUnit);
@@ -44,7 +44,7 @@ public:
private:
private:
    void bindDitherTexture();
    void bindDitherTexture();


    Caches* mCaches;
    Caches& mCaches;
    bool mInitialized;
    bool mInitialized;
    GLuint mDitherTexture;
    GLuint mDitherTexture;
};
};
Loading