zoukankan      html  css  js  c++  java
  • Android 3D emulation 架构理解

    Android Emulator 给用户提供  GPU on 选项,意思是利用 Host ( 就是执行 Emulator 的PC机) 的 GPU. 当然PC机必须把 OpenGL 的驱动装好


    在实现上就是把 libGLESv1_CM.so  libGLESv2.so 替换掉,当system调用 gl的函数的时候,把调用打包为stream,并通过 pipe 发送到 host端处理,进入转化为对 host opengl的调用。

    光这样还不够,还要把 libegl, libgralloc 都替换了,由于要调用 host 端的 opengl 必须有 rendercontext, 所以要把 android egl 也转化为host 的 xgl的调用(假设你用 ubuntu).


    创建

    正常情况下,当一个apk进程须要创建窗口的时候,它调用egl的函数创建 Surface, 也要调用 gralloc的中函数创建内存来存放Surface须要的光栅 , 而后把 两者关联,这些都是在本进程中完毕的,但在 Android 3D emulation 的体系结构中,窗口不能直接创建了,而必需通过发命令给 host 端 render 让它来调用 xgl 的命令来创建

    Surface相应 3D Emulation 中的 WindowSurface, 光栅内存相应 3D Emulation 中的 ColorBuffer.



    这里的FrameBuffer 是 3D emulation 中的虚拟 FrameBuffer, 他对 ColorBuffer, WindowSurface, RenderContext进行集中管理


    更新

    当APK调用swapBuffers (就是把已经画的上屏, 这须要各Surface提供图象内存,有SurfaceFlinger做处理并显示到屏幕上),能够想象使用opengl的画图已经结束,如今就是运行一系列内存 copy, ColorBuffer 把opengl绘好图的 image 读取出来.

    elg的eglMakeCurrent參数提供第一个surface是用来画东西的,而第二个就是读取的

    public boolean eglMakeCurrent(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context) ;

    应用程序画东西的时候使用的应该是 EGLSurface draw, 这个 Surface是后台的,看不见,仅仅是为了能成功调用opengl的进行硬件渲染

    如今上屏了,须要曾经draw的 surface光栅数据读取回来,当然这是eglMakeCurrent 參数提供的

    读取的Surface光栅内存供SurfaceFlinger操作,最后生成的屏幕图像在FrameBuffer中,能够直接上屏



    最后你在emulator 中,跑赛车游戏也没有问题


  • 相关阅读:
    网络协议栈(6)RFC793TCP连接时部分异常流程及实现
    网络协议栈(5)sendto/send返回成功意味着什么
    LeetCode——Detect Capital
    LeetCode——Find All Numbers Disappeared in an Array
    LeetCode——Single Number
    LeetCode——Max Consecutive Ones
    LeetCode——Nim Game
    LeetCode——Reverse String
    LeetCode——Next Greater Element I
    LeetCode——Fizz Buzz
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/3774689.html
Copyright © 2011-2022 走看看