android - Android OpenGL是否有drawbitmap性能的离屏功能

标签 android performance opengl-es android-camera android-mediarecorder

我有一个 Android 应用程序 (targetSdkVersion 28),它将 2 个 TextureViews 每个显示一个相机 View 组合成 1 个位图,然后使用 drawbitmap 到 mediarecorder 表面进行记录。这是从 onSurfaceTextureUpdated 调用的。在最终视频中,这似乎将其限制在每秒 8 到 10 帧左右。

有谁知道 OpenGL 是否可以以更高效的帧速率方式实现这一点,或者下面的代码是否可以提高性能?

我尝试在函数之外移动创建位图和 Canvas ,虽然它稍微好一点,但组合位图有闪烁。

class thScreenShot extends AsyncTask{

    @Override
    protected Object doInBackground(Object... params) {

        try {

            List<TextureView> tilingViews = getAllTextureViews(rootLayout);
            if (tilingViews.size() > 0) {
                final Bitmap bitmap = Bitmap.createBitmap(DISPLAY_WIDTH, DISPLAY_HEIGHT, Bitmap.Config.RGB_565);
                final Canvas canvas = new Canvas(bitmap);
                for (TextureView tilingTextureView : tilingViews) {
                    Bitmap bitmap1 = tilingTextureView.getBitmap(tilingTextureView.getWidth(), tilingTextureView.getHeight());
                    int[] location = new int[2];
                    tilingTextureView.getLocationInWindow(location);
                    Rect dest = new Rect(location[0], location[1], bitmap.getWidth(), bitmap.getHeight());
                    canvas.drawBitmap(bitmap1, dest, dest, null);
                }
                if (isRecording) {
                     if (surfaceS == null)
                     {
                          surfaceS = mMediaRecorder.getSurface();
                     }
                     synchronized (surfaceS) {
                          canvasS = surfaceS.lockHardwareCanvas();
                          canvasS.drawBitmap(bitmap, 0, 0, null);
                          surfaceS.unlockCanvasAndPost(canvasS);
                          FPSCount++;
                     }
                }
            }
            return null;
        }
        catch (Exception ex)
        {
            return null;
        }
    }
}

public List<TextureView> getAllTextureViews(View view)
{
    List<TextureView> tilingViews = new ArrayList<TextureView>();
    if (view instanceof TextureView) {
        tilingViews.add((TextureView)view);
    }
    else if(view instanceof ViewGroup)
    {
        ViewGroup viewGroup = (ViewGroup)view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            tilingViews.addAll(getAllTextureViews(viewGroup.getChildAt(i)));
        }
    }
    return tilingViews;
}

最佳答案

我不确定您是需要 UI 渲染到纹理还是普通渲染到纹理,可能是其中之一。您可以检查例如 Is it possible to render an Android View to an OpenGL FBO or texture?https://gamedev.stackexchange.com/questions/41887/how-to-render-small-texture-on-another-texture

还记得经常检查 https://www.khronos.org/opengl/wiki/Common_Mistakes

关于android - Android OpenGL是否有drawbitmap性能的离屏功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54373779/

相关文章:

java - FloatingActionButton - 滚动后不正确的 z-index

安卓工作室 : Cannot resolve symbol ‘RequestConfiguration’

sql - Postgres 一贯偏爱嵌套循环连接而不是合并连接

javascript - 最好是一次加载 javascript 导航层次结构还是逐级加载?

ios - 无法在 opengl es 2.0 中加载多个纹理

android - 如何在构建时忽略一个类 Gradle

android - ExoPlayer 无法与相机 IP 地址建立连接

c++ - 使用嵌套结构时是否有任何性能损失?

opengl-es - 如何有效地将深度缓冲区复制到 OpenGL ES 上的纹理

iPhone:当上下文消失时,我需要进行多少 OpenGL 清理?