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

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

Merge "Optimize FBO drawing with regions. This optimization is currently...

Merge "Optimize FBO drawing with regions. This optimization is currently disabled until Launcher is modified to take advantage of it. The optimization can be enabled by turning on RENDER_LAYERS_AS_REGIONS in the OpenGLRenderer.h file."
parents acc863ca 5b3b3529
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ public class LockPatternView extends View {
    private long[] mVibePattern;

    private int mAspect;
    private final Matrix mArrowMatrix = new Matrix();

    /**
     * Represents a cell in the 3 X 3 matrix of the unlock pattern view.
@@ -923,7 +924,6 @@ public class LockPatternView extends View {
        // This assumes that the arrow image is drawn at 12:00 with it's top edge
        // coincident with the circle bitmap's top edge.
        Bitmap arrow = green ? mBitmapArrowGreenUp : mBitmapArrowRedUp;
        Matrix matrix = new Matrix();
        final int cellWidth = mBitmapCircleDefault.getWidth();
        final int cellHeight = mBitmapCircleDefault.getHeight();

@@ -933,10 +933,10 @@ public class LockPatternView extends View {
        final float angle = (float) Math.toDegrees(theta) + 90.0f;

        // compose matrix
        matrix.setTranslate(leftX + offsetX, topY + offsetY); // transform to cell position
        matrix.preRotate(angle, cellWidth / 2.0f, cellHeight / 2.0f);  // rotate about cell center
        matrix.preTranslate((cellWidth - arrow.getWidth()) / 2.0f, 0.0f); // translate to 12:00 pos
        canvas.drawBitmap(arrow, matrix, mPaint);
        mArrowMatrix.setTranslate(leftX + offsetX, topY + offsetY); // transform to cell position
        mArrowMatrix.preRotate(angle, cellWidth / 2.0f, cellHeight / 2.0f);  // rotate about cell center
        mArrowMatrix.preTranslate((cellWidth - arrow.getWidth()) / 2.0f, 0.0f); // translate to 12:00 pos
        canvas.drawBitmap(arrow, mArrowMatrix, mPaint);
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ ifeq ($(USE_OPENGL_RENDERER),true)

	LOCAL_CFLAGS += -DUSE_OPENGL_RENDERER
	LOCAL_MODULE_CLASS := SHARED_LIBRARIES
	LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 libskia
	LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 libskia libui
	LOCAL_MODULE := libhwui
	LOCAL_MODULE_TAGS := optional
	LOCAL_PRELINK_MODULE := false
+39 −9
Original line number Diff line number Diff line
@@ -46,18 +46,21 @@ Caches::Caches(): Singleton<Caches>(), blend(false), lastSrcMode(GL_ZERO),
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);

    mCurrentBuffer = meshBuffer;
    mRegionMesh = NULL;
}

/**
 * Binds the VBO used to render simple textured quads.
 */
Caches::~Caches() {
    delete[] mRegionMesh;
}

///////////////////////////////////////////////////////////////////////////////
// VBO
///////////////////////////////////////////////////////////////////////////////

void Caches::bindMeshBuffer() {
    bindMeshBuffer(meshBuffer);
}

/**
 * Binds the specified VBO.
 */
void Caches::bindMeshBuffer(const GLuint buffer) {
    if (mCurrentBuffer != buffer) {
        glBindBuffer(GL_ARRAY_BUFFER, buffer);
@@ -65,9 +68,6 @@ void Caches::bindMeshBuffer(const GLuint buffer) {
    }
}

/**
 * Unbinds the VBO used to render simple textured quads.
 */
void Caches::unbindMeshBuffer() {
    if (mCurrentBuffer) {
        glBindBuffer(GL_ARRAY_BUFFER, 0);
@@ -75,5 +75,35 @@ void Caches::unbindMeshBuffer() {
    }
}

TextureVertex* Caches::getRegionMesh() {
    // Create the mesh, 2 triangles and 4 vertices per rectangle in the region
    if (!mRegionMesh) {
        mRegionMesh = new TextureVertex[REGION_MESH_QUAD_COUNT * 4];

        uint16_t* regionIndices = new uint16_t[REGION_MESH_QUAD_COUNT * 6];
        for (int i = 0; i < REGION_MESH_QUAD_COUNT; i++) {
            uint16_t quad = i * 4;
            int index = i * 6;
            regionIndices[index    ] = quad;       // top-left
            regionIndices[index + 1] = quad + 1;   // top-right
            regionIndices[index + 2] = quad + 2;   // bottom-left
            regionIndices[index + 3] = quad + 2;   // bottom-left
            regionIndices[index + 4] = quad + 1;   // top-right
            regionIndices[index + 5] = quad + 3;   // bottom-right
        }

        glGenBuffers(1, &mRegionMeshIndices);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mRegionMeshIndices);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, REGION_MESH_QUAD_COUNT * 6 * sizeof(uint16_t),
                regionIndices, GL_STATIC_DRAW);

        delete[] regionIndices;
    } else {
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mRegionMeshIndices);
    }

    return mRegionMesh;
}

}; // namespace uirenderer
}; // namespace android
+28 −4
Original line number Diff line number Diff line
@@ -14,8 +14,8 @@
 * limitations under the License.
 */

#ifndef ANDROID_UI_CACHES_H
#define ANDROID_UI_CACHES_H
#ifndef ANDROID_HWUI_CACHES_H
#define ANDROID_HWUI_CACHES_H

#ifndef LOG_TAG
    #define LOG_TAG "OpenGLRenderer"
@@ -46,6 +46,8 @@ namespace uirenderer {

#define REQUIRED_TEXTURE_UNITS_COUNT 3

#define REGION_MESH_QUAD_COUNT 512

// Generates simple and textured vertices
#define FV(x, y, u, v) { { x, y }, { u, v } }

@@ -77,6 +79,7 @@ struct CacheLogger {

class Caches: public Singleton<Caches> {
    Caches();
    ~Caches();

    friend class Singleton<Caches>;

@@ -84,11 +87,33 @@ class Caches: public Singleton<Caches> {

    GLuint mCurrentBuffer;

    // Used to render layers
    TextureVertex* mRegionMesh;
    GLuint mRegionMeshIndices;

public:
    /**
     * Binds the VBO used to render simple textured quads.
     */
    void bindMeshBuffer();

    /**
     * Binds the specified VBO if needed.
     */
    void bindMeshBuffer(const GLuint buffer);

    /**
     * Unbinds the VBO used to render simple textured quads.
     */
    void unbindMeshBuffer();

    /**
     * Returns the mesh used to draw regions. Calling this method will
     * bind a VBO of type GL_ELEMENT_ARRAY_BUFFER that contains the
     * indices for the region mesh.
     */
    TextureVertex* getRegionMesh();

    bool blend;
    GLenum lastSrcMode;
    GLenum lastDstMode;
@@ -118,7 +143,6 @@ public:
}; // class Caches

}; // namespace uirenderer

}; // namespace android

#endif // ANDROID_UI_CACHES_H
#endif // ANDROID_HWUI_CACHES_H
+16 −1
Original line number Diff line number Diff line
@@ -169,7 +169,8 @@ void DisplayList::replay(OpenGLRenderer& renderer) {
    int saveCount = renderer.getSaveCount() - 1;

    while (!mReader.eof()) {
        switch (mReader.readInt()) {
        int op = mReader.readInt();
        switch (op) {
            case AcquireContext: {
                renderer.acquireContext();
            }
@@ -195,6 +196,11 @@ void DisplayList::replay(OpenGLRenderer& renderer) {
                        getPaint(), getInt());
            }
            break;
            case SaveLayerAlpha: {
                renderer.saveLayerAlpha(getFloat(), getFloat(), getFloat(), getFloat(),
                        getInt(), getInt());
            }
            break;
            case Translate: {
                renderer.translate(getFloat(), getFloat());
            }
@@ -400,6 +406,15 @@ int DisplayListRenderer::saveLayer(float left, float top, float right, float bot
    return OpenGLRenderer::save(flags);
}

int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
        int alpha, int flags) {
    addOp(DisplayList::SaveLayerAlpha);
    addBounds(left, top, right, bottom);
    addInt(alpha);
    addInt(flags);
    return OpenGLRenderer::save(flags);
}

void DisplayListRenderer::translate(float dx, float dy) {
    addOp(DisplayList::Translate);
    addPoint(dx, dy);
Loading