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

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

Merge "Add error checking to LayerRenderer::copyLayer"

parents 1a81a16a d6b2a00d
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -306,6 +306,8 @@ public class TextureView extends View {
     * <p><strong>Do not</strong> invoke this method from a drawing method
     * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
     * 
     * <p>If an error occurs during the copy, an empty bitmap will be returned.</p>
     * 
     * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface
     *         texture is not available or the width &lt;= 0 or the height &lt;= 0
     * 
@@ -328,6 +330,8 @@ public class TextureView extends View {
     * <p><strong>Do not</strong> invoke this method from a drawing method
     * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
     * 
     * <p>If an error occurs during the copy, an empty bitmap will be returned.</p>
     * 
     * @param width The width of the bitmap to create
     * @param height The height of the bitmap to create
     * 
@@ -354,6 +358,8 @@ public class TextureView extends View {
     * <p><strong>Do not</strong> invoke this method from a drawing method
     * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
     * 
     * <p>If an error occurs, the bitmap is left unchanged.</p>
     * 
     * @param bitmap The bitmap to copy the content of the surface texture into,
     *               cannot be null, all configurations are supported
     * 
@@ -447,5 +453,6 @@ public class TextureView extends View {
        public void onSurfaceTextureDestroyed(SurfaceTexture surface);
    }

    private static native void nSetDefaultBufferSize(SurfaceTexture surfaceTexture, int width, int height);
    private static native void nSetDefaultBufferSize(SurfaceTexture surfaceTexture,
            int width, int height);
}
+1 −1
Original line number Diff line number Diff line
@@ -4479,7 +4479,7 @@ public final class ViewAncestor extends Handler implements ViewParent,
                ArrayList<View> foundViews = mAttachInfo.mFocusablesTempList;
                foundViews.clear();

                View root = null;
                View root;
                if (accessibilityViewId != View.NO_ID) {
                    root = findViewByAccessibilityId(accessibilityViewId);
                } else {
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ static const GLsizei gMeshCount = 4;

struct CacheLogger {
    CacheLogger() {
        LOGD("Creating OpenGL renderer caches");
        INIT_LOGD("Creating OpenGL renderer caches");
    }
}; // struct CacheLogger

+39 −17
Original line number Diff line number Diff line
@@ -326,12 +326,17 @@ bool LayerRenderer::copyLayer(Layer* layer, SkBitmap* bitmap) {
            return false;
        }

        SkAutoLockPixels alp(*bitmap);

        GLuint texture;
        GLuint previousFbo;

        GLenum format;
        GLenum type;

        GLenum error = GL_NO_ERROR;
        bool status = false;

        switch (bitmap->config()) {
            case SkBitmap::kA8_Config:
                format = GL_ALPHA;
@@ -352,10 +357,18 @@ bool LayerRenderer::copyLayer(Layer* layer, SkBitmap* bitmap) {
                break;
        }

        float alpha = layer->alpha;
        SkXfermode::Mode mode = layer->mode;

        layer->mode = SkXfermode::kSrc_Mode;
        layer->alpha = 255;
        layer->fbo = fbo;

        glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*) &previousFbo);
        glBindFramebuffer(GL_FRAMEBUFFER, fbo);

        glGenTextures(1, &texture);
        if ((error = glGetError()) != GL_NO_ERROR) goto error;

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, texture);
@@ -368,39 +381,48 @@ bool LayerRenderer::copyLayer(Layer* layer, SkBitmap* bitmap) {

        glTexImage2D(GL_TEXTURE_2D, 0, format, bitmap->width(), bitmap->height(),
                0, format, type, NULL);
        if ((error = glGetError()) != GL_NO_ERROR) goto error;

        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                GL_TEXTURE_2D, texture, 0);
        if ((error = glGetError()) != GL_NO_ERROR) goto error;

        glBindTexture(GL_TEXTURE_2D, layer->texture);

        float alpha = layer->alpha;
        SkXfermode::Mode mode = layer->mode;

        layer->mode = SkXfermode::kSrc_Mode;
        layer->alpha = 255;
        layer->fbo = fbo;

        {
            LayerRenderer renderer(layer);
            renderer.setViewport(bitmap->width(), bitmap->height());
            renderer.OpenGLRenderer::prepareDirty(0.0f, 0.0f,
                    bitmap->width(), bitmap->height(), !layer->blend);
            if ((error = glGetError()) != GL_NO_ERROR) goto error;

            {
                Rect bounds;
                bounds.set(0.0f, 0.0f, bitmap->width(), bitmap->height());
                renderer.drawTextureLayer(layer, bounds);

        SkAutoLockPixels alp(*bitmap);
        glReadPixels(0, 0, bitmap->width(), bitmap->height(), format, type, bitmap->getPixels());
                glReadPixels(0, 0, bitmap->width(), bitmap->height(), format,
                        type, bitmap->getPixels());

        glBindFramebuffer(GL_FRAMEBUFFER, previousFbo);
                if ((error = glGetError()) != GL_NO_ERROR) goto error;
            }

            status = true;
        }

error:
#if DEBUG_OPENGL
        if (error != GL_NO_ERROR) {
            LOGD("GL error while copying layer into bitmap = 0x%x", error);
        }
#endif

        glBindFramebuffer(GL_FRAMEBUFFER, previousFbo);
        layer->mode = mode;
        layer->alpha = alpha;
        layer->fbo = 0;
        glDeleteTextures(1, &texture);
        caches.fboCache.put(fbo);

        return true;
        return status;
    }
    return false;
}
+0 −1
Original line number Diff line number Diff line
@@ -151,7 +151,6 @@ void OpenGLRenderer::prepareDirty(float left, float top, float right, float bott
    mSaveCount = 1;

    glViewport(0, 0, mWidth, mHeight);

    glDisable(GL_DITHER);

    glEnable(GL_SCISSOR_TEST);
Loading