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

Commit ae5575b3 authored by Romain Guy's avatar Romain Guy
Browse files

Fix gradients rendering and destructor crashes.

This changes binds all textures to GL_TEXTURE0, this will have
to be changed when combining shader capabilities.

Change-Id: I02df4f5ba41e9b01ffa52fd7c26b41477c7ed18f
parent 889f8d14
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -327,7 +327,6 @@ void FontRenderer::initTextTexture() {
    mTextTexture = new unsigned char[mCacheWidth * mCacheHeight];
    mUploadTexture = false;

    glActiveTexture(GL_TEXTURE0);
    glGenTextures(1, &mTextureId);
    glBindTexture(GL_TEXTURE_2D, mTextureId);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+7 −5
Original line number Diff line number Diff line
@@ -34,13 +34,12 @@ template<typename EntryKey, typename EntryValue>
struct Entry: public LightRefBase<Entry<EntryKey, EntryValue> > {
    Entry() { }
    Entry(const Entry<EntryKey, EntryValue>& e):
            key(e.key), value(e.value), index(e.index), parent(e.parent), child(e.child) { }
            key(e.key), value(e.value), parent(e.parent), child(e.child) { }
    Entry(sp<Entry<EntryKey, EntryValue> > e):
            key(e->key), value(e->value), index(e->index), parent(e->parent), child(e->child) { }
            key(e->key), value(e->value), parent(e->parent), child(e->child) { }

    EntryKey key;
    EntryValue value;
    ssize_t index;

    sp<Entry<EntryKey, EntryValue> > parent;
    sp<Entry<EntryKey, EntryValue> > child;
@@ -156,7 +155,7 @@ template<typename K, typename V>
void GenerationCache<K, V>::addToCache(sp<Entry<K, V> > entry, K key, V value) {
    entry->key = key;
    entry->value = value;
    entry->index = mCache.add(key, entry);
    mCache.add(key, entry);
    attachToCache(entry);
}

@@ -185,7 +184,10 @@ V GenerationCache<K, V>::removeAt(ssize_t index) {
template<typename K, typename V>
V GenerationCache<K, V>::removeOldest() {
    if (mOldest.get()) {
        return removeAt(mOldest->index);
        ssize_t index = mCache.indexOfKey(mOldest->key);
        if (index >= 0) {
            return removeAt(index);
        }
    }

    return NULL;
+12 −22
Original line number Diff line number Diff line
@@ -144,11 +144,13 @@ OpenGLRenderer::OpenGLRenderer():

    memcpy(mMeshVertices, gMeshVertices, sizeof(gMeshVertices));

    glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxTextureUnits);
    if (mMaxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) {
    mFirstSnapshot = new Snapshot;

    GLint maxTextureUnits;
    glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
    if (maxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) {
        LOGW("At least %d texture units are required!", REQUIRED_TEXTURE_UNITS_COUNT);
    }
    mLastTexture[0] = mLastTexture[1] = mLastTexture[2] = 0;
}

OpenGLRenderer::~OpenGLRenderer() {
@@ -171,11 +173,11 @@ void OpenGLRenderer::setViewport(int width, int height) {

    mWidth = width;
    mHeight = height;
    mFirstSnapshot.height = height;
    mFirstSnapshot->height = height;
}

void OpenGLRenderer::prepare() {
    mSnapshot = &mFirstSnapshot;
    mSnapshot = mFirstSnapshot;
    mSaveCount = 0;

    glDisable(GL_SCISSOR_TEST);
@@ -265,10 +267,6 @@ void OpenGLRenderer::composeLayer(sp<Snapshot> current, sp<Snapshot> previous) {
    glScissor(clip.left, mHeight - clip.bottom, clip.getWidth(), clip.getHeight());

    Layer* layer = current->layer;

    // Compute the correct texture coordinates for the FBO texture
    // The texture is currently as big as the window but drawn with
    // a quad of the appropriate size
    const Rect& rect = layer->layer;

    drawTextureRect(rect.left, rect.top, rect.right, rect.bottom,
@@ -323,7 +321,6 @@ int OpenGLRenderer::saveLayerAlpha(float left, float top, float right, float bot

bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top,
        float right, float bottom, int alpha, SkXfermode::Mode mode,int flags) {

    LAYER_LOGD("Requesting layer %fx%f", right - left, bottom - top);
    LAYER_LOGD("Layer cache size = %d", mLayerCache.getSize());

@@ -537,8 +534,6 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
        return;
    }

    glActiveTexture(GL_TEXTURE0);

    float length;
    switch (paint->getTextAlign()) {
        case SkPaint::kCenter_Align:
@@ -687,7 +682,6 @@ void OpenGLRenderer::drawColorRect(float left, float top, float right, float bot

void OpenGLRenderer::drawLinearGradientShader(float left, float top, float right, float bottom,
        float alpha, SkXfermode::Mode mode) {
    glActiveTexture(GL_TEXTURE1);
    Texture* texture = mGradientCache.get(mShaderKey);
    if (!texture) {
        SkShader::TileMode tileMode = SkShader::kClamp_TileMode;
@@ -714,8 +708,8 @@ void OpenGLRenderer::drawLinearGradientShader(float left, float top, float right
    mCurrentProgram->set(mOrthoMatrix, mModelView, mSnapshot->transform);

    chooseBlending(mShaderBlend || alpha < 1.0f, mode);
    bindTexture(texture->id, mShaderTileX, mShaderTileY, 1);
    glUniform1i(mCurrentProgram->getUniform("gradientSampler"), 1);
    bindTexture(texture->id, mShaderTileX, mShaderTileY, 0);
    glUniform1i(mCurrentProgram->getUniform("gradientSampler"), 0);

    Rect start(mShaderBounds[0], mShaderBounds[1], mShaderBounds[2], mShaderBounds[3]);
    if (mShaderMatrix) {
@@ -747,7 +741,6 @@ void OpenGLRenderer::drawLinearGradientShader(float left, float top, float right

void OpenGLRenderer::drawBitmapShader(float left, float top, float right, float bottom,
        float alpha, SkXfermode::Mode mode) {
    glActiveTexture(GL_TEXTURE2);
    const Texture* texture = mTextureCache.get(mShaderBitmap);

    const float width = texture->width;
@@ -782,8 +775,8 @@ void OpenGLRenderer::drawBitmapShader(float left, float top, float right, float
    chooseBlending(texture->blend || alpha < 1.0f, mode);

    // Texture
    bindTexture(texture->id, mShaderTileX, mShaderTileY, 2);
    glUniform1i(mCurrentProgram->getUniform("bitmapSampler"), 2);
    bindTexture(texture->id, mShaderTileX, mShaderTileY, 0);
    glUniform1i(mCurrentProgram->getUniform("bitmapSampler"), 0);
    glUniformMatrix4fv(mCurrentProgram->getUniform("textureTransform"), 1,
            GL_FALSE, &textureTransform.data[0]);
    glUniform2f(mCurrentProgram->getUniform("textureDimension"), 1.0f / width, 1.0f / height);
@@ -917,10 +910,7 @@ void OpenGLRenderer::getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermod

void OpenGLRenderer::bindTexture(GLuint texture, GLenum wrapS, GLenum wrapT, GLuint textureUnit) {
    glActiveTexture(gTextureUnits[textureUnit]);
    if (texture != mLastTexture[textureUnit]) {
    glBindTexture(GL_TEXTURE_2D, texture);
        mLastTexture[textureUnit] = texture;
    }
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
}
+1 −5
Original line number Diff line number Diff line
@@ -315,7 +315,7 @@ private:
    // Number of saved states
    int mSaveCount;
    // Base state
    Snapshot mFirstSnapshot;
    sp<Snapshot> mFirstSnapshot;
    // Current state
    sp<Snapshot> mSnapshot;

@@ -325,10 +325,6 @@ private:
    // Used to draw textured quads
    TextureVertex mMeshVertices[4];

    // Current texture state
    GLuint mLastTexture[REQUIRED_TEXTURE_UNITS_COUNT];
    GLint mMaxTextureUnits;

    // Last known blend state
    bool mBlend;
    GLenum mLastSrcMode;
+1 −1
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ public:
     * assumed to be dirty. The specified snapshot is stored as the previous
     * snapshot.
     */
    Snapshot(const sp<Snapshot> s):
    Snapshot(const sp<Snapshot>& s):
            height(s->height),
            transform(s->transform),
            clipRect(s->clipRect),
Loading