DirectFB源代码阅读(六)各个核心子系统的初始化

dfb_core_create接着调用fusion_arena_enter,它会调用dfb_core_arena_initialize,最终调到了dfb_core_initialize
  1. static DFBResult dfb_core_initialize( CoreDFB *core )  
  2. {  
  3.      int            i;  
  4.      DFBResult      ret;  
  5.      CoreDFBShared *shared;  
  6.   
  7.   
  8.      D_MAGIC_ASSERT( core, CoreDFB );  
  9.   
  10.   
  11.      shared = core->shared;  
  12.   
  13.   
  14.      D_MAGIC_ASSERT( shared, CoreDFBShared );  
  15.   
  16.   
  17.      ret = fusion_shm_pool_create( core->world, "DirectFB Data Pool", 0x1000000,  
  18.                                    fusion_config->debugshm, &shared->shmpool_data );  
  19.      if (ret)  
  20.           return ret;  
  21.   
  22.   
  23.      shared->layer_context_pool = dfb_layer_context_pool_create( core->world );  
  24.      shared->layer_region_pool  = dfb_layer_region_pool_create( core->world );  
  25.      shared->palette_pool       = dfb_palette_pool_create( core->world );  
  26.      shared->surface_pool       = dfb_surface_pool_create( core->world );  
  27.      shared->window_pool        = dfb_window_pool_create( core->world );  
  28.   
  29.   
  30.      for (i=0; i<D_ARRAY_SIZE(core_parts); i++) {  
  31.           DFBResult ret;  
  32.         //调用每一个子系统的初始化函数   
  33.           if ((ret = dfb_core_part_initialize( core, core_parts[i] ))) {  
  34.                dfb_core_shutdown( core, true );  
  35.                return ret;  
  36.           }  
  37.      }  
  38.   
  39.   
  40.      return DFB_OK;  
  41. }  
static DFBResult dfb_core_initialize( CoreDFB *core )
{
     int            i;
     DFBResult      ret;
     CoreDFBShared *shared;


     D_MAGIC_ASSERT( core, CoreDFB );


     shared = core->shared;


     D_MAGIC_ASSERT( shared, CoreDFBShared );


     ret = fusion_shm_pool_create( core->world, "DirectFB Data Pool", 0x1000000,
                                   fusion_config->debugshm, &shared->shmpool_data );
     if (ret)
          return ret;


     shared->layer_context_pool = dfb_layer_context_pool_create( core->world );
     shared->layer_region_pool  = dfb_layer_region_pool_create( core->world );
     shared->palette_pool       = dfb_palette_pool_create( core->world );
     shared->surface_pool       = dfb_surface_pool_create( core->world );
     shared->window_pool        = dfb_window_pool_create( core->world );


     for (i=0; i<D_ARRAY_SIZE(core_parts); i++) {
          DFBResult ret;
	    //调用每一个子系统的初始化函数
          if ((ret = dfb_core_part_initialize( core, core_parts[i] ))) {
               dfb_core_shutdown( core, true );
               return ret;
          }
     }


     return DFB_OK;
}
而这些子系统数组在文件头部:
  1. static CorePart *core_parts[] = {  
  2.      &dfb_clipboard_core,//剪切板   
  3.      &dfb_colorhash_core,//颜色hash表   
  4.      &dfb_surface_core,//显示   
  5.      &dfb_system_core,//输出显示的图形系统   
  6.      &dfb_input_core,//各种外设抽象处理   
  7.      &dfb_graphics_core,//显卡设备    
  8.      &dfb_screen_core,//屏幕的抽象   
  9.      &dfb_layer_core,//层   
  10.      &dfb_wm_core//窗口管理   
  11. };  
static CorePart *core_parts[] = {
     &dfb_clipboard_core,//剪切板
     &dfb_colorhash_core,//颜色hash表
     &dfb_surface_core,//显示
     &dfb_system_core,//输出显示的图形系统
     &dfb_input_core,//各种外设抽象处理
     &dfb_graphics_core,//显卡设备 
     &dfb_screen_core,//屏幕的抽象
     &dfb_layer_core,//层
     &dfb_wm_core//窗口管理
};
这些变量是在哪里进行初始化的呢?可以看到在每个子系统中都调用了这么一个宏
  1. #define DFB_CORE_PART(part,Type)                                               \   
  2.                                                                                \  
  3. static DFBResult dfb_##part##_initialize( CoreDFB           *core,             \  
  4.                                           DFB##Type         *local,            \  
  5.                                           DFB##Type##Shared *shared );         \  
  6.                                                                                \  
  7. static DFBResult dfb_##part##_join      ( CoreDFB           *core,             \  
  8.                                           DFB##Type         *local,            \  
  9.                                           DFB##Type##Shared *shared );         \  
  10.                                                                                \  
  11. static DFBResult dfb_##part##_shutdown  ( DFB##Type         *local,            \  
  12.                                           bool               emergency );      \  
  13.                                                                                \  
  14. static DFBResult dfb_##part##_leave     ( DFB##Type         *local,            \  
  15.                                           bool               emergency );      \  
  16.                                                                                \  
  17. static DFBResult dfb_##part##_suspend   ( DFB##Type         *local );          \  
  18.                                                                                \  
  19. static DFBResult dfb_##part##_resume    ( DFB##Type         *local );          \  
  20.                                                                                \  
  21. CorePart dfb_##part = {                                                        \  
  22.      .name        = #part,                                                     \  
  23.                                                                                \  
  24.      .size_local  = sizeof(DFB##Type),                                         \  
  25.      .size_shared = sizeof(DFB##Type##Shared),                                 \  
  26.                                                                                \  
  27.      .Initialize  = (void*)dfb_##part##_initialize,                            \  
  28.      .Join        = (void*)dfb_##part##_join,                                  \  
  29.      .Shutdown    = (void*)dfb_##part##_shutdown,                              \  
  30.      .Leave       = (void*)dfb_##part##_leave,                                 \  
  31.      .Suspend     = (void*)dfb_##part##_suspend,                               \  
  32.      .Resume      = (void*)dfb_##part##_resume,                                \  
  33. }  
#define DFB_CORE_PART(part,Type)                                               \
                                                                               \
static DFBResult dfb_##part##_initialize( CoreDFB           *core,             \
                                          DFB##Type         *local,            \
                                          DFB##Type##Shared *shared );         \
                                                                               \
static DFBResult dfb_##part##_join      ( CoreDFB           *core,             \
                                          DFB##Type         *local,            \
                                          DFB##Type##Shared *shared );         \
                                                                               \
static DFBResult dfb_##part##_shutdown  ( DFB##Type         *local,            \
                                          bool               emergency );      \
                                                                               \
static DFBResult dfb_##part##_leave     ( DFB##Type         *local,            \
                                          bool               emergency );      \
                                                                               \
static DFBResult dfb_##part##_suspend   ( DFB##Type         *local );          \
                                                                               \
static DFBResult dfb_##part##_resume    ( DFB##Type         *local );          \
                                                                               \
CorePart dfb_##part = {                                                        \
     .name        = #part,                                                     \
                                                                               \
     .size_local  = sizeof(DFB##Type),                                         \
     .size_shared = sizeof(DFB##Type##Shared),                                 \
                                                                               \
     .Initialize  = (void*)dfb_##part##_initialize,                            \
     .Join        = (void*)dfb_##part##_join,                                  \
     .Shutdown    = (void*)dfb_##part##_shutdown,                              \
     .Leave       = (void*)dfb_##part##_leave,                                 \
     .Suspend     = (void*)dfb_##part##_suspend,                               \
     .Resume      = (void*)dfb_##part##_resume,                                \
}
这样就完成了各个子系统的初始化.
而每个子系统又是如何初始化的,完成了怎样的功能,在下面会再一一讲述.

有几个重要的概念说明:
surface:一块画布区域,绘制操作都在这上面进行.
layer:显卡的物理特性,数量多少由显卡决定,每个层对应显卡中的不同的内存.最终由硬件使用合适的alpha值进行混合,然后显示.
screen:系统中的特定的一块内存,写到这块内存的东西会自动显示到屏幕上,图形系统可以操作这块内存,如x11,framebuffer.
window:可进行窗口管理的surface
下面是来自网上的文档:
1.Surface
A Surface is a reserved area in memory where pixel data for one image is stored in a
specific pixel format. A Surface can reside in video and/or system memory. It is possible
to perform drawing operations on a surface or to Blit the surface to another.
In fullscreen mode, the visible screen is represented by the ”‘Primary Surface”’, so it is
possible to perform graphics operations directly on the visible screen.
Every Surface can optionally use double buffering, graphics operations are then first executed
on a secondary buffer and become valid after Flip() is called. To prevent flickering it is
advised to use Doublebuffering on the primary Surface in most cases.
2.SubSurface
A SubSurface uses the same interface as a regular Surface. It represents a part of a parent
Surface and does not allocate any system or video memory itself.
3.Layer
Depending on the graphics hardware, there are one or more display Layers. A standard
PC graphics card has only one Layer, but sophisticated devices like TV set top boxes may
support two or more layers. Layers occupy different areas in video ram, and are usually
combined by using alpha blending. This in done automatically by the display hardware. If
the content of the lowest Layer changes, no repaint has to be done and the contents of the
above layers remain untouched. Today, most PC graphics cards also support an additional
layer (a ”‘video layer”’), which can be scaled and does color conversion from YUV to RGB.
This layer cannot usually be blended and has to remain fully opaque. Video layers are
supported by varios DirectFB graphics drivers.
4.Window / Windowstack
Normally the contents of a layer’s surface is controlled by the integrated windowing system
that shows the windows belonging to the layer on a configurable background. Each window
has its own surface that is used by the windowing system to produce the composed image of
overlapping windows. Alternatively applications, especially games, can get exclusive access
to the layer. This way the application has direct control over the layer’s surface and it’s
contents, no windows are shown.

关系:
1 IDirectFB (顶层) <--> N 屏幕(Screens)
1 屏幕(Screen) <--> N 层(Layers)
1 层(Layer) <--> 1 主表面(Primary Surface)
1 层(Layer) <--> N 窗口(Windows)
1 窗口(Window) <--> 1 窗口表面(Window Surface)
1 表面(Surface) <--> N 子表面(Subsurfaces)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值