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

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

Merge "Properly refcount SurfaceTexture in the JNI layer."

parents 576715c7 e5e0c50f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.graphics.Shader;
import android.graphics.SurfaceTexture;
import android.graphics.TemporaryBuffer;
import android.text.GraphicsOperations;
import android.text.SpannableString;
@@ -163,7 +164,7 @@ class GLES20Canvas extends HardwareCanvas {
    static native int nCreateTextureLayer(int[] layerInfo);
    static native int nCreateLayer(int width, int height, boolean isOpaque, int[] layerInfo);
    static native void nResizeLayer(int layerId, int width, int height, int[] layerInfo);
    static native void nUpdateTextureLayer(int layerId, int width, int height, int surface);
    static native void nUpdateTextureLayer(int layerId, int width, int height, SurfaceTexture surface);
    static native void nDestroyLayer(int layerId);
    static native void nDestroyLayerDeferred(int layerId);
    static native boolean nCopyLayer(int layerId, int bitmap);
+2 −2
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ class GLES20TextureLayer extends GLES20Layer {
        return mSurface;
    }

    void update(int width, int height, int surface) {
        GLES20Canvas.nUpdateTextureLayer(mLayer, width, height, surface);
    void update(int width, int height) {
        GLES20Canvas.nUpdateTextureLayer(mLayer, width, height, mSurface);
    }
}
+5 −8
Original line number Diff line number Diff line
@@ -194,7 +194,7 @@ public abstract class HardwareRenderer {
     * 
     * @return A {@link SurfaceTexture}
     */
    abstract SurfaceTexture createSuraceTexture(HardwareLayer layer);
    abstract SurfaceTexture createSurfaceTexture(HardwareLayer layer);

    /**
     * Updates the specified layer.
@@ -202,10 +202,8 @@ public abstract class HardwareRenderer {
     * @param layer The hardware layer to update
     * @param width The layer's width
     * @param height The layer's height
     * @param surface The surface to update
     */
    abstract void updateTextureLayer(HardwareLayer layer, int width, int height,
            SurfaceTexture surface);
    abstract void updateTextureLayer(HardwareLayer layer, int width, int height);

    /**
     * Copies the content of the specified layer into the specified bitmap.
@@ -815,14 +813,13 @@ public abstract class HardwareRenderer {
        }

        @Override
        SurfaceTexture createSuraceTexture(HardwareLayer layer) {
        SurfaceTexture createSurfaceTexture(HardwareLayer layer) {
            return ((GLES20TextureLayer) layer).getSurfaceTexture();
        }

        @Override
        void updateTextureLayer(HardwareLayer layer, int width, int height,
                SurfaceTexture surface) {
            ((GLES20TextureLayer) layer).update(width, height, surface.mSurfaceTexture);
        void updateTextureLayer(HardwareLayer layer, int width, int height) {
            ((GLES20TextureLayer) layer).update(width, height);
        }

        @Override
+5 −5
Original line number Diff line number Diff line
@@ -232,7 +232,7 @@ public class TextureView extends View {
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        if (mSurface != null) {
            nSetDefaultBufferSize(mSurface.mSurfaceTexture, getWidth(), getHeight());
            nSetDefaultBufferSize(mSurface, getWidth(), getHeight());
            if (mListener != null) {
                mListener.onSurfaceTextureSizeChanged(mSurface, getWidth(), getHeight());
            }
@@ -247,8 +247,8 @@ public class TextureView extends View {

        if (mLayer == null) {
            mLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer();
            mSurface = mAttachInfo.mHardwareRenderer.createSuraceTexture(mLayer);
            nSetDefaultBufferSize(mSurface.mSurfaceTexture, getWidth(), getHeight());
            mSurface = mAttachInfo.mHardwareRenderer.createSurfaceTexture(mLayer);
            nSetDefaultBufferSize(mSurface, getWidth(), getHeight());

            mUpdateListener = new SurfaceTexture.OnFrameAvailableListener() {
                @Override
@@ -290,7 +290,7 @@ public class TextureView extends View {
            return;
        }

        mAttachInfo.mHardwareRenderer.updateTextureLayer(mLayer, getWidth(), getHeight(), mSurface);
        mAttachInfo.mHardwareRenderer.updateTextureLayer(mLayer, getWidth(), getHeight());

        invalidate();
    }
@@ -447,5 +447,5 @@ public class TextureView extends View {
        public void onSurfaceTextureDestroyed(SurfaceTexture surface);
    }

    private static native void nSetDefaultBufferSize(int surfaceTexture, int width, int height);
    private static native void nSetDefaultBufferSize(SurfaceTexture surfaceTexture, int width, int height);
}
+9 −5
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include "GraphicsJNI.h"
#include <nativehelper/JNIHelp.h>
#include <android_runtime/AndroidRuntime.h>
#include <android_runtime/android_graphics_SurfaceTexture.h>
#include <utils/ResourceTypes.h>

#include <gui/SurfaceTexture.h>
@@ -644,11 +645,13 @@ static void android_view_GLES20Canvas_resizeLayer(JNIEnv* env, jobject clazz,
}

static void android_view_GLES20Canvas_updateTextureLayer(JNIEnv* env, jobject clazz,
        Layer* layer, jint width, jint height, SurfaceTexture* surface) {
        Layer* layer, jint width, jint height, jobject surface) {
    float transform[16];
    surface->updateTexImage();
    surface->getTransformMatrix(transform);
    GLenum renderTarget = surface->getCurrentTextureTarget();
    sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, surface));

    surfaceTexture->updateTexImage();
    surfaceTexture->getTransformMatrix(transform);
    GLenum renderTarget = surfaceTexture->getCurrentTextureTarget();

    LayerRenderer::updateTextureLayer(layer, width, height, renderTarget, transform);
}
@@ -793,7 +796,8 @@ static JNINativeMethod gMethods[] = {
    { "nCreateLayer",            "(IIZ[I)I",   (void*) android_view_GLES20Canvas_createLayer },
    { "nResizeLayer",            "(III[I)V" ,  (void*) android_view_GLES20Canvas_resizeLayer },
    { "nCreateTextureLayer",     "([I)I",      (void*) android_view_GLES20Canvas_createTextureLayer },
    { "nUpdateTextureLayer",     "(IIII)V",    (void*) android_view_GLES20Canvas_updateTextureLayer },
    { "nUpdateTextureLayer",     "(IIILjava/lang/String;)V",
                                               (void*) android_view_GLES20Canvas_updateTextureLayer },
    { "nDestroyLayer",           "(I)V",       (void*) android_view_GLES20Canvas_destroyLayer },
    { "nDestroyLayerDeferred",   "(I)V",       (void*) android_view_GLES20Canvas_destroyLayerDeferred },
    { "nDrawLayer",              "(IIFFI)V",   (void*) android_view_GLES20Canvas_drawLayer },
Loading