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

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

Merge "New widget: TextureView Bug #4343984"

parents efe2a0e6 aa6c24c2
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -21010,6 +21010,21 @@ package android.view {
    method public void setZOrderOnTop(boolean);
  }
  public class TextureView extends android.view.View {
    ctor public TextureView(android.content.Context);
    ctor public TextureView(android.content.Context, android.util.AttributeSet);
    ctor public TextureView(android.content.Context, android.util.AttributeSet, int);
    method public final void draw(android.graphics.Canvas);
    method public android.graphics.SurfaceTexture getSurfaceTexture();
    method public android.view.TextureView.SurfaceTextureListener getSurfaceTextureListener();
    method protected final void onDraw(android.graphics.Canvas);
    method public void setSurfaceTextureListener(android.view.TextureView.SurfaceTextureListener);
  }
  public static abstract interface TextureView.SurfaceTextureListener {
    method public abstract void onSurfaceTextureAvailable(android.graphics.SurfaceTexture);
  }
  public class TouchDelegate {
    ctor public TouchDelegate(android.graphics.Rect, android.view.View);
    method public boolean onTouchEvent(android.view.MotionEvent);
+4 −1
Original line number Diff line number Diff line
@@ -160,8 +160,11 @@ class GLES20Canvas extends HardwareCanvas {
    // Hardware layers
    ///////////////////////////////////////////////////////////////////////////
    
    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,
            float[] textureTransform);
    static native void nDestroyLayer(int layerId);
    static native void nDestroyLayerDeferred(int layerId);

+11 −70
Original line number Diff line number Diff line
@@ -14,39 +14,21 @@
 * limitations under the License.
 */

package android.view;

import android.graphics.Canvas;
package android.view;

/**
 * An OpenGL ES 2.0 implementation of {@link HardwareLayer}.
 */
class GLES20Layer extends HardwareLayer {
    private int mLayer;

    private int mLayerWidth;
    private int mLayerHeight;

    private final GLES20Canvas mCanvas;
abstract class GLES20Layer extends HardwareLayer {
    int mLayer;
    Finalizer mFinalizer;

    @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
    private final Finalizer mFinalizer;

    GLES20Layer(int width, int height, boolean isOpaque) {
        super(width, height, isOpaque);

        int[] layerInfo = new int[2];
        mLayer = GLES20Canvas.nCreateLayer(width, height, isOpaque, layerInfo);
        if (mLayer != 0) {
            mLayerWidth = layerInfo[0];
            mLayerHeight = layerInfo[1];

            mCanvas = new GLES20Canvas(mLayer, !isOpaque);
            mFinalizer = new Finalizer(mLayer);
        } else {
            mCanvas = null;
            mFinalizer = null;
    GLES20Layer() {
    }

    GLES20Layer(int width, int height, boolean opaque) {
        super(width, height, opaque);
    }

    /**
@@ -58,55 +40,14 @@ class GLES20Layer extends HardwareLayer {
        return mLayer;
    }

    @Override
    boolean isValid() {
        return mLayer != 0 && mLayerWidth > 0 && mLayerHeight > 0;
    }

    @Override
    void resize(int width, int height) {
        if (!isValid() || width <= 0 || height <= 0) return;

        mWidth = width;
        mHeight = height;
        
        if (width != mLayerWidth || height != mLayerHeight) {
            int[] layerInfo = new int[2];

            GLES20Canvas.nResizeLayer(mLayer, width, height, layerInfo);

            mLayerWidth = layerInfo[0];
            mLayerHeight = layerInfo[1];
        }
    }

    @Override
    HardwareCanvas getCanvas() {
        return mCanvas;
    }

    @Override
    void end(Canvas currentCanvas) {
        if (currentCanvas instanceof GLES20Canvas) {
            ((GLES20Canvas) currentCanvas).resume();
        }
    }

    @Override
    HardwareCanvas start(Canvas currentCanvas) {
        if (currentCanvas instanceof GLES20Canvas) {
            ((GLES20Canvas) currentCanvas).interrupt();
        }
        return getCanvas();
    }
    
    @Override
    void destroy() {
        mFinalizer.destroy();
        if (mFinalizer != null) mFinalizer.destroy();
        mLayer = 0;
    }

    private static class Finalizer {
    static class Finalizer {
        private int mLayerId;

        public Finalizer(int layerId) {
+91 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view;

import android.graphics.Canvas;

/**
 * An OpenGL ES 2.0 implementation of {@link HardwareLayer}. This
 * implementation can be used a rendering target. It generates a
 * {@link Canvas} that can be used to render into an FBO using OpenGL.
 */
class GLES20RenderLayer extends GLES20Layer {

    private int mLayerWidth;
    private int mLayerHeight;

    private final GLES20Canvas mCanvas;

    GLES20RenderLayer(int width, int height, boolean isOpaque) {
        super(width, height, isOpaque);

        int[] layerInfo = new int[2];
        mLayer = GLES20Canvas.nCreateLayer(width, height, isOpaque, layerInfo);
        if (mLayer != 0) {
            mLayerWidth = layerInfo[0];
            mLayerHeight = layerInfo[1];

            mCanvas = new GLES20Canvas(mLayer, !isOpaque);
            mFinalizer = new Finalizer(mLayer);
        } else {
            mCanvas = null;
            mFinalizer = null;
        }
    }

    @Override
    boolean isValid() {
        return mLayer != 0 && mLayerWidth > 0 && mLayerHeight > 0;
    }

    @Override
    void resize(int width, int height) {
        if (!isValid() || width <= 0 || height <= 0) return;

        mWidth = width;
        mHeight = height;
        
        if (width != mLayerWidth || height != mLayerHeight) {
            int[] layerInfo = new int[2];

            GLES20Canvas.nResizeLayer(mLayer, width, height, layerInfo);

            mLayerWidth = layerInfo[0];
            mLayerHeight = layerInfo[1];
        }
    }

    @Override
    HardwareCanvas getCanvas() {
        return mCanvas;
    }

    @Override
    void end(Canvas currentCanvas) {
        if (currentCanvas instanceof GLES20Canvas) {
            ((GLES20Canvas) currentCanvas).resume();
        }
    }

    @Override
    HardwareCanvas start(Canvas currentCanvas) {
        if (currentCanvas instanceof GLES20Canvas) {
            ((GLES20Canvas) currentCanvas).interrupt();
        }
        return getCanvas();
    }
}
+76 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view;

import android.graphics.Canvas;
import android.graphics.SurfaceTexture;

/**
 * An OpenGL ES 2.0 implementation of {@link HardwareLayer}. This
 * implementation can be used as a texture. Rendering into this
 * layer is not controlled by a {@link HardwareCanvas}.
 */
class GLES20TextureLayer extends GLES20Layer {
    private int mTexture;
    private SurfaceTexture mSurface;

    GLES20TextureLayer() {
        int[] layerInfo = new int[2];
        mLayer = GLES20Canvas.nCreateTextureLayer(layerInfo);

        if (mLayer != 0) {
            mTexture = layerInfo[0];
            mFinalizer = new Finalizer(mLayer);
        } else {
            mFinalizer = null;
        }        
    }

    @Override
    boolean isValid() {
        return mLayer != 0 && mTexture != 0;
    }

    @Override
    void resize(int width, int height) {
    }

    @Override
    HardwareCanvas getCanvas() {
        return null;
    }

    @Override
    HardwareCanvas start(Canvas currentCanvas) {
        return null;
    }

    @Override
    void end(Canvas currentCanvas) {
    }

    SurfaceTexture getSurfaceTexture() {
        if (mSurface == null) {
            mSurface = new SurfaceTexture(mTexture);
        }
        return mSurface;
    }

    void update(int width, int height, float[] textureTransform) {
        GLES20Canvas.nUpdateTextureLayer(mLayer, width, height, textureTransform);
    }
}
Loading