在SurfaceView上重叠GLSurfaceView,反之亦然

问题描述 投票:0回答:1

ExoPlayer-SurfaceView

Camera2 + MediaCodec-GLSurfaceView

我正在使用上述视图组来播放视频和摄像机记录。

UI-1: Exo-Surf位于中心,并且Cam-GLS位于右上角。

UI-2: Cam-GLS位于中心,并且Exo-Surf位于右上角。

enter image description here

为了实现这一点,我正在使用setZOrderOnTop设置z-index,因为它们都在RelativeLayout中。

(exoPlayerView.videoSurfaceView as? SurfaceView)?.setZOrderOnTop(true/false)

[在具有API 29-Android 10的Samsung S9 +上以及在API 28上似乎运行良好。

但是对于API 21-27,它的行为带有一些随机问题。

  • << [Dash-A SurfaceView / GLSurfaceView的顶部不可见
  • << [Dash-B SurfaceView / GLSurfaceView的底部不可见
  • 整个SurfaceView / GLSurfaceView在右上角变得完全透明
也尝试使用setZOrderMediaOverlay,但没有运气。
  • [我确定两个表面视图可以一起使用,因为Whatsapp和google duo应用正在视频通话中使用它们。但我想知道GLSurfaceView是否引起问题“有关锁定GL线程的问题”,如下面this answer中所述。

    希望为API 21+或任何参考链接提供一个可行的解决方案,建议将受到高度赞赏。

  • android surfaceview exoplayer android-camera2 glsurfaceview
    1个回答
    0
    投票
    Grafika代码(我在对您链接的答案的评论中提到):https://github.com/google/grafika/blob/master/app/src/main/java/com/android/grafika/MultiSurfaceActivity.java

    在该代码中,onCreate创建了曲面:

    @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_multi_surface_test); // #1 is at the bottom; mark it as secure just for fun. By default, this will use // the RGB565 color format. mSurfaceView1 = (SurfaceView) findViewById(R.id.multiSurfaceView1); mSurfaceView1.getHolder().addCallback(this); mSurfaceView1.setSecure(true); // #2 is above it, in the "media overlay"; must be translucent or we will totally // obscure #1 and it will be ignored by the compositor. The addition of the alpha // plane should switch us to RGBA8888. mSurfaceView2 = (SurfaceView) findViewById(R.id.multiSurfaceView2); mSurfaceView2.getHolder().addCallback(this); mSurfaceView2.getHolder().setFormat(PixelFormat.TRANSLUCENT); mSurfaceView2.setZOrderMediaOverlay(true); // #3 is above everything, including the UI. Also translucent. mSurfaceView3 = (SurfaceView) findViewById(R.id.multiSurfaceView3); mSurfaceView3.getHolder().addCallback(this); mSurfaceView3.getHolder().setFormat(PixelFormat.TRANSLUCENT); mSurfaceView3.setZOrderOnTop(true); }

    初始绘图代码位于:

    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
    

    根据某些本地标志调用不同的本地方法。例如,它在此处调用GL绘图的示例:

    private void drawRectSurface(Surface surface, int left, int top, int width, int height) {
        EglCore eglCore = new EglCore();
        WindowSurface win = new WindowSurface(eglCore, surface, false);
        win.makeCurrent();
        GLES20.glClearColor(0, 0, 0, 0);
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    
        GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
        for (int i = 0; i < 4; i++) {
            int x, y, w, h;
            if (width < height) {
                // vertical
                w = width / 4;
                h = height;
                x = left + w * i;
                y = top;
            } else {
                // horizontal
                w = width;
                h = height / 4;
                x = left;
                y = top + h * i;
            }
            GLES20.glScissor(x, y, w, h);
            switch (i) {
                case 0:     // 50% blue at 25% alpha, pre-multiplied
                    GLES20.glClearColor(0.0f, 0.0f, 0.125f, 0.25f);
                    break;
                case 1:     // 100% blue at 25% alpha, pre-multiplied
                    GLES20.glClearColor(0.0f, 0.0f, 0.25f, 0.25f);
                    break;
                case 2:     // 200% blue at 25% alpha, pre-multiplied (should get clipped)
                    GLES20.glClearColor(0.0f, 0.0f, 0.5f, 0.25f);
                    break;
                case 3:     // 100% white at 25% alpha, pre-multiplied
                    GLES20.glClearColor(0.25f, 0.25f, 0.25f, 0.25f);
                    break;
            }
            GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
        }
        GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
    
        win.swapBuffers();
        win.release();
        eglCore.release();
    }
    

    我没有使用此代码,所以我只能建议您搜索有关在该代码中看到的各种呼叫的其他详细信息。

    首先,尝试获得一个简单的示例,该示例具有两个重叠的SurfaceView,没有任何OpenGL调用。例如。重叠的纯色背景色视图。我重申要点:不要将它们中的任何一个都设为GLSurfaceView

    尝试更改其中一个视图以初始化和使用OpenGL。 (使用类似于我上面描述的代码的逻辑;仍然不是GLSurfaceView。)

    © www.soinside.com 2019 - 2024. All rights reserved.