DisplayHardware

DisplayHardware
 SurfaceFlinger调用DisplayHardware部分初始化Framebuffer、EGL和OpenGL ES。

1 DisplayHardware的参数
 DIRECT_TEXTURE          = 0x00000002,  //
 COPY_BITS_EXTENSION     = 0x00000008, //
 NPOT_EXTENSION          = 0x00000100,  //
 DRAW_TEXTURE_EXTENSION  = 0x00000200, //
 BUFFER_PRESERVED        = 0x00010000,  //
 PARTIAL_UPDATES         = 0x00020000,    // 部分更新
 SLOW_CONFIG             = 0x00040000,    // 软件
 SWAP_RECTANGLE          = 0x00080000, // 矩形框交换
 CACHED_BUFFERS          = 0x00100000  //

 

2 DisplayHardware初始化过程
1)初始化DisplayHardwareBase结构
 new DisplayEventThread(flinger);
 new ConsoleManagerThread(flinger);
2)DisplayEventThreadBase(flinger)
 读取"/sys/power/wait_for_fb_sleep"和"/sys/power/wait_for_fb_wake"判断系统状态。
3)ConsoleManagerThread(flinger)
 (1)创建一个新的控制台;
 (2)进入text模式;
 (3)获取当前控制台;
 (4)切换至控制台7(X串口常用的串口);
 (5)打开新的控制台;
 (6)关闭控制台的行缓冲、回显等功能;
 (7)设置信号;
 (8)切换至图形模式;
4)执行DisplayHardware::init(dpy)
 (1)new FramebufferNativeWindow(),调用libui.so初始化Framebuffer;
 (2)如果有Overlay模块,加载Overlay模块并打开控制接口;
 (3)调用libEGL.so,初始化EGL;
  eglGetDisplay(EGL_DEFAULT_DISPLAY);
  eglInitialize(display, NULL, NULL);
  eglGetConfigs(display, NULL, 0, &numConfigs);
  selectConfigForNativeWindow(display, attribs, mNativeWindow.get(), &config);
 (4)获取并打印EGL版本信息;
    LOGI("EGL informations:");
    LOGI("# of configs : %d", numConfigs);
    LOGI("vendor    : %s", eglQueryString(display, EGL_VENDOR));
    LOGI("version   : %s", eglQueryString(display, EGL_VERSION));
    LOGI("extensions: %s", egl_extensions);
    LOGI("Client API: %s", eglQueryString(display, EGL_CLIENT_APIS)?:"Not Supported");
    LOGI("EGLSurface: %d-%d-%d-%d, config=%p", r, g, b, a, config);
 (5)判断LCD是否支持局部更新功能(PARTIAL_UPDATES),如果LCD支持局部更新,则不需要保存backbuffer,并不需要使用SWAP_RECTANGLE。目前并不支持PARTIAL_UPDATES;
 (6)创建主界面;
 eglCreateWindowSurface(display, config, mNativeWindow.get(), NULL);
 (7)获取DisplayHardware参数,目前支持的参数为:SWAP_RECTANGLE、CACHED_BUFFERS和SLOW_CONFIG;
 (8)读取LCD density参数;
    if (property_get("qemu.sf.lcd_density", property, NULL) <= 0) {
        if (property_get("ro.sf.lcd_density", property, NULL) <= 0) {
            LOGW("ro.sf.lcd_density not defined, using 160 dpi by default.");
            strcpy(property, "160");
        }
    } else {
        /* for the emulator case, reset the dpi values too */
        mDpiX = mDpiY = atoi(property);
    }
mDensity = atoi(property) * (1.0f/160.0f);
(9)创建OpenGL ES上下文;
context = eglCreateContext(display, config, NULL, NULL);
(10)将创建的上下文和EGL surface相绑定;
eglMakeCurrent(display, surface, surface, context);
(11)获取OpenGL参数,根据参数重新配置DisplayHardware参数;
    LOGI("OpenGL informations:");
    LOGI("vendor    : %s", glGetString(GL_VENDOR));
    LOGI("renderer  : %s", gl_renderer);
    LOGI("version   : %s", glGetString(GL_VERSION));
    LOGI("extensions: %s", gl_extensions);
 (12)暂时解除EGL与当前线程的绑定;
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);

 

3 DisplayHardware::flip
(1)flip有两条路线:
 A. SWAP_RECTANGLE路线
 调用eglSetSwapRectangleANDROID(dpy, surface, b.left, b.top, b.width(), b.height());
 B. PARTIAL_UPDATES路线
 调用mNativeWindow->setUpdateRectangle(dirty.getBounds());
(2)调用eglSwapBuffers(dpy, surface)将数据贴到屏幕上;

 

 

初始化LOG
I/SurfaceFlinger(  831): SurfaceFlinger is starting
I/SurfaceFlinger(  831): SurfaceFlinger's main thread ready to run. Initializing graphics H/W...
E/SurfaceFlinger(  831): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
I/gralloc (  831): ky6410 grallocusing (fd=22)
I/gralloc (  831): id           = s3cfb
I/gralloc (  831): xres         = 480 px
I/gralloc (  831): yres         = 272 px
I/gralloc (  831): xres_virtual = 480 px
I/gralloc (  831): yres_virtual = 544 px
I/gralloc (  831): bpp          = 16
I/gralloc (  831): r            = 11:5
I/gralloc (  831): g            =  5:6
I/gralloc (  831): b            =  0:5
I/gralloc (  831): width        = 480 mm (25.400000 dpi)
I/gralloc (  831): height       = 272 mm (25.400000 dpi)
I/gralloc (  831): refresh rate = 0.83 Hz
E/Overlay (  831): Overlay open!
E/Overlay (  831):
D/Overlay (  831):  overlay_device_open 1 : OVERLAY_HARDWARE_CONTROL
D/libEGL  (  831): egl.cfg not found, using default config
D/libEGL  (  831): loaded /system/lib/egl/libGLES_android.so
I/SurfaceFlinger(  831): EGL informations:
I/SurfaceFlinger(  831): # of configs : 8
I/SurfaceFlinger(  831): vendor    : Android
I/SurfaceFlinger(  831): version   : 1.4 Android META-EGL
I/SurfaceFlinger(  831): extensions: EGL_KHR_image EGL_KHR_image_base EGL_KHR_image_pixmap EGL_ANDROID_image_native_buffer EGL_ANDROID_swap_rectangle EGL_ANDROID_get_render_buffer
I/SurfaceFlinger(  831): Client API: OpenGL ES
I/SurfaceFlinger(  831): EGLSurface: 5-6-5-0, config=0x1000000
I/SurfaceFlinger(  831): flags     : 001c0000
W/SurfaceFlinger(  831): ro.sf.lcd_density not defined, using 160 dpi by default.
I/SurfaceFlinger(  831): OpenGL informations:
I/SurfaceFlinger(  831): vendor    : Android
I/SurfaceFlinger(  831): renderer  : Android PixelFlinger 1.2
I/SurfaceFlinger(  831): version   : OpenGL ES-CM 1.0
I/SurfaceFlinger(  831): extensions: GL_OES_byte_coordinates GL_OES_fixed_point GL_OES_single_precision GL_OES_read_format GL_OES_compressed_paletted_texture GL_OES_draw_texture GL_OES_matrix_get GL_OES_query_matrix GL_OES_EGL_image GL_ARB_texture_compression GL_ARB_texture_non_power_of_two GL_ANDROID_user_clip_plane GL_ANDROID_vertex_buffer_object GL_ANDROID_generate_mipmap

Rockie Cheng

你可能感兴趣的:(DisplayHardware)