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

Commit 10c0aa24 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Implement support for drawBitmapMesh's colors array"

parents 45dc56f3 ff316ec7
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -901,9 +901,9 @@ class GLES20Canvas extends HardwareCanvas {
        final int count = (meshWidth + 1) * (meshHeight + 1);
        final int count = (meshWidth + 1) * (meshHeight + 1);
        checkRange(verts.length, vertOffset, count * 2);
        checkRange(verts.length, vertOffset, count * 2);


        // TODO: Colors are ignored for now
        if (colors != null) {
        colors = null;
            checkRange(colors.length, colorOffset, count);
        colorOffset = 0;
        }


        int modifiers = paint != null ? setupModifiers(bitmap, paint) : MODIFIER_NONE;
        int modifiers = paint != null ? setupModifiers(bitmap, paint) : MODIFIER_NONE;
        try {
        try {
+5 −4
Original line number Original line Diff line number Diff line
@@ -365,11 +365,12 @@ void Caches::bindPositionVertexPointer(bool force, GLvoid* vertices, GLsizei str
    }
    }
}
}


void Caches::bindTexCoordsVertexPointer(bool force, GLvoid* vertices) {
void Caches::bindTexCoordsVertexPointer(bool force, GLvoid* vertices, GLsizei stride) {
    if (force || vertices != mCurrentTexCoordsPointer) {
    if (force || vertices != mCurrentTexCoordsPointer || stride != mCurrentTexCoordsStride) {
        GLuint slot = currentProgram->texCoords;
        GLuint slot = currentProgram->texCoords;
        glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, gMeshStride, vertices);
        glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices);
        mCurrentTexCoordsPointer = vertices;
        mCurrentTexCoordsPointer = vertices;
        mCurrentTexCoordsStride = stride;
    }
    }
}
}


@@ -390,7 +391,7 @@ void Caches::enableTexCoordsVertexArray() {
    }
    }
}
}


void Caches::disbaleTexCoordsVertexArray() {
void Caches::disableTexCoordsVertexArray() {
    if (mTexCoordsArrayEnabled) {
    if (mTexCoordsArrayEnabled) {
        glDisableVertexAttribArray(Program::kBindingTexCoords);
        glDisableVertexAttribArray(Program::kBindingTexCoords);
        mTexCoordsArrayEnabled = false;
        mTexCoordsArrayEnabled = false;
+3 −2
Original line number Original line Diff line number Diff line
@@ -183,7 +183,7 @@ public:
     * Binds an attrib to the specified float vertex pointer.
     * Binds an attrib to the specified float vertex pointer.
     * Assumes a stride of gMeshStride and a size of 2.
     * Assumes a stride of gMeshStride and a size of 2.
     */
     */
    void bindTexCoordsVertexPointer(bool force, GLvoid* vertices);
    void bindTexCoordsVertexPointer(bool force, GLvoid* vertices, GLsizei stride = gMeshStride);


    /**
    /**
     * Resets the vertex pointers.
     * Resets the vertex pointers.
@@ -192,7 +192,7 @@ public:
    void resetTexCoordsVertexPointer();
    void resetTexCoordsVertexPointer();


    void enableTexCoordsVertexArray();
    void enableTexCoordsVertexArray();
    void disbaleTexCoordsVertexArray();
    void disableTexCoordsVertexArray();


    /**
    /**
     * Activate the specified texture unit. The texture unit must
     * Activate the specified texture unit. The texture unit must
@@ -299,6 +299,7 @@ private:
    void* mCurrentPositionPointer;
    void* mCurrentPositionPointer;
    GLsizei mCurrentPositionStride;
    GLsizei mCurrentPositionStride;
    void* mCurrentTexCoordsPointer;
    void* mCurrentTexCoordsPointer;
    GLsizei mCurrentTexCoordsStride;


    bool mTexCoordsArrayEnabled;
    bool mTexCoordsArrayEnabled;


+71 −15
Original line number Original line Diff line number Diff line
@@ -317,7 +317,7 @@ void OpenGLRenderer::interrupt() {
    mCaches.unbindMeshBuffer();
    mCaches.unbindMeshBuffer();
    mCaches.unbindIndicesBuffer();
    mCaches.unbindIndicesBuffer();
    mCaches.resetVertexPointers();
    mCaches.resetVertexPointers();
    mCaches.disbaleTexCoordsVertexArray();
    mCaches.disableTexCoordsVertexArray();
    debugOverdraw(false, false);
    debugOverdraw(false, false);
}
}


@@ -1469,12 +1469,18 @@ void OpenGLRenderer::setupDrawWithTexture(bool isAlpha8) {
    mDescription.hasAlpha8Texture = isAlpha8;
    mDescription.hasAlpha8Texture = isAlpha8;
}
}


void OpenGLRenderer::setupDrawWithTextureAndColor(bool isAlpha8) {
    mDescription.hasTexture = true;
    mDescription.hasColors = true;
    mDescription.hasAlpha8Texture = isAlpha8;
}

void OpenGLRenderer::setupDrawWithExternalTexture() {
void OpenGLRenderer::setupDrawWithExternalTexture() {
    mDescription.hasExternalTexture = true;
    mDescription.hasExternalTexture = true;
}
}


void OpenGLRenderer::setupDrawNoTexture() {
void OpenGLRenderer::setupDrawNoTexture() {
    mCaches.disbaleTexCoordsVertexArray();
    mCaches.disableTexCoordsVertexArray();
}
}


void OpenGLRenderer::setupDrawAA() {
void OpenGLRenderer::setupDrawAA() {
@@ -1682,6 +1688,23 @@ void OpenGLRenderer::setupDrawMesh(GLvoid* vertices, GLvoid* texCoords, GLuint v
    mCaches.unbindIndicesBuffer();
    mCaches.unbindIndicesBuffer();
}
}


void OpenGLRenderer::setupDrawMesh(GLvoid* vertices, GLvoid* texCoords, GLvoid* colors) {
    bool force = mCaches.unbindMeshBuffer();
    GLsizei stride = sizeof(ColorTextureVertex);

    mCaches.bindPositionVertexPointer(force, vertices, stride);
    if (mCaches.currentProgram->texCoords >= 0) {
        mCaches.bindTexCoordsVertexPointer(force, texCoords, stride);
    }
    int slot = mCaches.currentProgram->getAttrib("colors");
    if (slot >= 0) {
        glEnableVertexAttribArray(slot);
        glVertexAttribPointer(slot, 4, GL_FLOAT, GL_FALSE, stride, colors);
    }

    mCaches.unbindIndicesBuffer();
}

void OpenGLRenderer::setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords) {
void OpenGLRenderer::setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords) {
    bool force = mCaches.unbindMeshBuffer();
    bool force = mCaches.unbindMeshBuffer();
    mCaches.bindPositionVertexPointer(force, vertices);
    mCaches.bindPositionVertexPointer(force, vertices);
@@ -1833,9 +1856,16 @@ status_t OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int mes


    const uint32_t count = meshWidth * meshHeight * 6;
    const uint32_t count = meshWidth * meshHeight * 6;


    // TODO: Support the colors array
    ColorTextureVertex mesh[count];
    TextureVertex mesh[count];
    ColorTextureVertex* vertex = mesh;
    TextureVertex* vertex = mesh;

    bool cleanupColors = false;
    if (!colors) {
        uint32_t colorsCount = (meshWidth + 1) * (meshHeight + 1);
        colors = new int[colorsCount];
        memset(colors, 0xff, colorsCount * sizeof(int));
        cleanupColors = true;
    }


    for (int32_t y = 0; y < meshHeight; y++) {
    for (int32_t y = 0; y < meshHeight; y++) {
        for (int32_t x = 0; x < meshWidth; x++) {
        for (int32_t x = 0; x < meshWidth; x++) {
@@ -1855,13 +1885,13 @@ status_t OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int mes
            int dx = i + (meshWidth + 1) * 2 + 2;
            int dx = i + (meshWidth + 1) * 2 + 2;
            int dy = dx + 1;
            int dy = dx + 1;


            TextureVertex::set(vertex++, vertices[ax], vertices[ay], u1, v2);
            ColorTextureVertex::set(vertex++, vertices[dx], vertices[dy], u2, v2, colors[dx / 2]);
            TextureVertex::set(vertex++, vertices[bx], vertices[by], u1, v1);
            ColorTextureVertex::set(vertex++, vertices[ax], vertices[ay], u1, v2, colors[ax / 2]);
            TextureVertex::set(vertex++, vertices[cx], vertices[cy], u2, v1);
            ColorTextureVertex::set(vertex++, vertices[bx], vertices[by], u1, v1, colors[bx / 2]);


            TextureVertex::set(vertex++, vertices[ax], vertices[ay], u1, v2);
            ColorTextureVertex::set(vertex++, vertices[dx], vertices[dy], u2, v2, colors[dx / 2]);
            TextureVertex::set(vertex++, vertices[cx], vertices[cy], u2, v1);
            ColorTextureVertex::set(vertex++, vertices[bx], vertices[by], u1, v1, colors[bx / 2]);
            TextureVertex::set(vertex++, vertices[dx], vertices[dy], u2, v2);
            ColorTextureVertex::set(vertex++, vertices[cx], vertices[cy], u2, v1, colors[cx / 2]);


            left = fminf(left, fminf(vertices[ax], fminf(vertices[bx], vertices[cx])));
            left = fminf(left, fminf(vertices[ax], fminf(vertices[bx], vertices[cx])));
            top = fminf(top, fminf(vertices[ay], fminf(vertices[by], vertices[cy])));
            top = fminf(top, fminf(vertices[ay], fminf(vertices[by], vertices[cy])));
@@ -1871,12 +1901,16 @@ status_t OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int mes
    }
    }


    if (quickReject(left, top, right, bottom)) {
    if (quickReject(left, top, right, bottom)) {
        if (cleanupColors) delete[] colors;
        return DrawGlInfo::kStatusDone;
        return DrawGlInfo::kStatusDone;
    }
    }


    mCaches.activeTexture(0);
    mCaches.activeTexture(0);
    Texture* texture = mCaches.textureCache.get(bitmap);
    Texture* texture = mCaches.textureCache.get(bitmap);
    if (!texture) return DrawGlInfo::kStatusDone;
    if (!texture) {
        if (cleanupColors) delete[] colors;
        return DrawGlInfo::kStatusDone;
    }
    const AutoTexture autoCleanup(texture);
    const AutoTexture autoCleanup(texture);


    texture->setWrap(GL_CLAMP_TO_EDGE, true);
    texture->setWrap(GL_CLAMP_TO_EDGE, true);
@@ -1886,13 +1920,35 @@ status_t OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int mes
    SkXfermode::Mode mode;
    SkXfermode::Mode mode;
    getAlphaAndMode(paint, &alpha, &mode);
    getAlphaAndMode(paint, &alpha, &mode);


    float a = alpha / 255.0f;

    if (hasLayer()) {
    if (hasLayer()) {
        dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
        dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
    }
    }


    drawTextureMesh(0.0f, 0.0f, 1.0f, 1.0f, texture->id, alpha / 255.0f,
    setupDraw();
            mode, texture->blend, &mesh[0].position[0], &mesh[0].texture[0],
    setupDrawWithTextureAndColor();
            GL_TRIANGLES, count, false, false, 0, false, false);
    setupDrawColor(a, a, a, a);
    setupDrawColorFilter();
    setupDrawBlending(true, mode, false);
    setupDrawProgram();
    setupDrawDirtyRegionsDisabled();
    setupDrawModelView(0.0f, 0.0f, 1.0f, 1.0f, false);
    setupDrawTexture(texture->id);
    setupDrawPureColorUniforms();
    setupDrawColorFilterUniforms();
    setupDrawMesh(&mesh[0].position[0], &mesh[0].texture[0], &mesh[0].color[0]);

    glDrawArrays(GL_TRIANGLES, 0, count);

    finishDrawTexture();

    int slot = mCaches.currentProgram->getAttrib("colors");
    if (slot >= 0) {
        glDisableVertexAttribArray(slot);
    }

    if (cleanupColors) delete[] colors;


    return DrawGlInfo::kStatusDrew;
    return DrawGlInfo::kStatusDrew;
}
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -777,6 +777,7 @@ private:
     * Various methods to setup OpenGL rendering.
     * Various methods to setup OpenGL rendering.
     */
     */
    void setupDrawWithTexture(bool isAlpha8 = false);
    void setupDrawWithTexture(bool isAlpha8 = false);
    void setupDrawWithTextureAndColor(bool isAlpha8 = false);
    void setupDrawWithExternalTexture();
    void setupDrawWithExternalTexture();
    void setupDrawNoTexture();
    void setupDrawNoTexture();
    void setupDrawAA();
    void setupDrawAA();
@@ -811,6 +812,7 @@ private:
    void setupDrawTextureTransformUniforms(mat4& transform);
    void setupDrawTextureTransformUniforms(mat4& transform);
    void setupDrawTextGammaUniforms();
    void setupDrawTextGammaUniforms();
    void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords = NULL, GLuint vbo = 0);
    void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords = NULL, GLuint vbo = 0);
    void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords, GLvoid* colors);
    void setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords);
    void setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords);
    void setupDrawVertices(GLvoid* vertices);
    void setupDrawVertices(GLvoid* vertices);
    void finishDrawTexture();
    void finishDrawTexture();
Loading