本文共 6639 字,大约阅读时间需要 22 分钟。
MSTAR的EMMI中跟BREW类似,采用虚函数表的方式定义各种对象及其接口,这有点面向对象的思想。 而其实现方法,全是用C语言,通过宏定义来实现的。将各种宏带入还原一下,其结构就很清新了,下面以以IBitmap为例:Mmi_mae_bitmap.h (proj\sc\application\mmi\mae\pub): DEFINE_INTERFACE(IBitmap); Mmi_mae_interface_def.h (proj\sc\application\mmi\mae\pub): #define DEFINE_INTERFACE(IName) \ typedef struct IName##_tag IName; \ DEFINE_FUNCTBL(IName) \ { INHERIT_##IName(IName); }; \ struct IName##_tag \ { DECLARE_FUNCTBL(IName); } -----------------------------> typedef struct IBitmap_tag IBitmap; \ DEFINE_FUNCTBL(IBitmap) \ { INHERIT_IBitmap(IBitmap); }; \ struct IBitmap_tag \ { DECLARE_FUNCTBL(IBitmap); };#define DEFINE_FUNCTBL(IName) \ typedef struct IName##_Vtbl_tag FUNCTBL(IName); \ struct IName##_Vtbl_tag -----------------------------> typedef struct IBitmap_tag IBitmap; \ typedef struct IBitmap_Vtbl_tag FUNCTBL(IBitmap); \ struct IBitmap_Vtbl_tag \ { INHERIT_IBitmap(IBitmap); }; \ struct IBitmap_tag \ { DECLARE_FUNCTBL(IBitmap); };#define DECLARE_FUNCTBL(IName) const IName##_Vtbl *Vtbl_Ptr -----------------------------> typedef struct IBitmap_tag IBitmap; \ typedef struct IBitmap_Vtbl_tag FUNCTBL(IBitmap); \ struct IBitmap_Vtbl_tag \ { INHERIT_IBitmap(IBitmap); }; \ struct IBitmap_tag \ { const IBitmap_Vtbl *Vtbl_Ptr; } #define FUNCTBL(IName) IName##_Vtbl -----------------------------> typedef struct IBitmap_tag IBitmap; \ typedef struct IBitmap_Vtbl_tag IBitmap_Vtbl; \ struct IBitmap_Vtbl_tag \ { INHERIT_IBitmap(IBitmap); }; \ struct IBitmap_tag \ { const IBitmap_Vtbl *Vtbl_Ptr; };Mmi_mae_bitmap.h (proj\sc\application\mmi\mae\pub): #define INHERIT_IBitmap(IName) \ INHERIT_IBase(IName); \ MAE_Ret (*GetInfo) (IName*, BitmapInfo_t*); \ MAE_Ret (*GetPixel) (IName*, u32, u32, RGBColor_t*); \ MAE_Ret (*SetPixel) (IName*, u32, u32, RGBColor_t, RasterOp_t); \ MAE_Ret (*SetPixels) (IName*, u32, Point_t*, RGBColor_t, RasterOp_t); \ MAE_Ret (*GetTransInfo) (IName*, TransparentInfo_t*); \ MAE_Ret (*SetTransInfo) (IName*, TransparentInfo_t*); \ MAE_Ret (*GetTransType) (IName*, u32*); \ MAE_Ret (*SetTransType) (IName*, u32); \ MAE_Ret (*GetTransColor) (IName*, RGBColor_t*); \ MAE_Ret (*SetTransColor) (IName*, RGBColor_t*); \ MAE_Ret (*GetTransMask) (IName*, u8**, u32*); \ MAE_Ret (*SetTransMask) (IName*, u32, u8*, u32); \ MAE_Ret (*GetTransparency) (IName*, u8*); \ MAE_Ret (*SetTransparency) (IName*, u8); \ MAE_Ret (*DrawHLine) (IName*, u32, u32, u32, RGBColor_t, RasterOp_t); \ MAE_Ret (*DrawVLine) (IName*, u32, u32, u32, RGBColor_t, RasterOp_t); \ MAE_Ret (*FillRect) (IName*, const Rect_t*, RGBColor_t, RasterOp_t); \ MAE_Ret (*BltIn) (IName*, const Rect_t*, IBitmap*, const Rect_t*, RasterOp_t); \ MAE_Ret (*GetDib) (IName*, void**);\ MAE_Ret (*StretchBlt) (IName*, const Rect_t*, IBitmap*, const Rect_t*, RasterOp_t, u32);\ MAE_Ret (*PerspectiveBlt) (IName*, const Rect_t*, IBitmap*, const Rect_t*, RasterOp_t, u32, u16) -----------------------------> typedef struct IBitmap_tag IBitmap; \ typedef struct IBitmap_Vtbl_tag IBitmap_Vtbl; \ struct IBitmap_Vtbl_tag \ { INHERIT_IBase(IBitmap); \ MAE_Ret (*GetInfo) (IBitmap*, BitmapInfo_t*); \ MAE_Ret (*GetPixel) (IBitmap*, u32, u32, RGBColor_t*); \ MAE_Ret (*SetPixel) (IBitmap*, u32, u32, RGBColor_t, RasterOp_t); \ MAE_Ret (*SetPixels) (IBitmap*, u32, Point_t*, RGBColor_t, RasterOp_t); \ MAE_Ret (*GetTransInfo) (IBitmap*, TransparentInfo_t*); \ MAE_Ret (*SetTransInfo) (IBitmap*, TransparentInfo_t*); \ MAE_Ret (*GetTransType) (IBitmap*, u32*); \ MAE_Ret (*SetTransType) (IBitmap*, u32); \ MAE_Ret (*GetTransColor) (IBitmap*, RGBColor_t*); \ MAE_Ret (*SetTransColor) (IBitmap*, RGBColor_t*); \ MAE_Ret (*GetTransMask) (IBitmap*, u8**, u32*); \ MAE_Ret (*SetTransMask) (IBitmap*, u32, u8*, u32); \ MAE_Ret (*GetTransparency) (IBitmap*, u8*); \ MAE_Ret (*SetTransparency) (IBitmap*, u8); \ MAE_Ret (*DrawHLine) (IBitmap*, u32, u32, u32, RGBColor_t, RasterOp_t); \ MAE_Ret (*DrawVLine) (IBitmap*, u32, u32, u32, RGBColor_t, RasterOp_t); \ MAE_Ret (*FillRect) (IBitmap*, const Rect_t*, RGBColor_t, RasterOp_t); \ MAE_Ret (*BltIn) (IBitmap*, const Rect_t*, IBitmap*, const Rect_t*, RasterOp_t); \ MAE_Ret (*GetDib) (IBitmap*, void**);\ MAE_Ret (*StretchBlt) (IBitmap*, const Rect_t*, IBitmap*, const Rect_t*, RasterOp_t, u32);\ MAE_Ret (*PerspectiveBlt) (IBitmap*, const Rect_t*, IBitmap*, const Rect_t*, RasterOp_t, u32, u16); }; \ struct IBitmap_tag \ { const IBitmap_Vtbl *Vtbl_Ptr; };Mmi_mae_interface_def.h (proj\sc\application\mmi\mae\pub): #define INHERIT_IBase(IName) \ u32 (*AddRef)(IName*); \ u32 (*Release)(IName*); \ MAERet_t (*QueryInterface)(IName*, MAEIId_t, void**, IBase*) -----------------------------> typedef struct IBitmap_tag IBitmap; \ typedef struct IBitmap_Vtbl_tag IBitmap_Vtbl; \ struct IBitmap_Vtbl_tag \ { u32 (*AddRef)(IBitmap*); \ u32 (*Release)(IBitmap*); \ MAERet_t (*QueryInterface)(IBitmap*, MAEIId_t, void**, IBase*); \ MAE_Ret (*GetInfo) (IBitmap*, BitmapInfo_t*); \ MAE_Ret (*GetPixel) (IBitmap*, u32, u32, RGBColor_t*); \ MAE_Ret (*SetPixel) (IBitmap*, u32, u32, RGBColor_t, RasterOp_t); \ MAE_Ret (*SetPixels) (IBitmap*, u32, Point_t*, RGBColor_t, RasterOp_t); \ MAE_Ret (*GetTransInfo) (IBitmap*, TransparentInfo_t*); \ MAE_Ret (*SetTransInfo) (IBitmap*, TransparentInfo_t*); \ MAE_Ret (*GetTransType) (IBitmap*, u32*); \ MAE_Ret (*SetTransType) (IBitmap*, u32); \ MAE_Ret (*GetTransColor) (IBitmap*, RGBColor_t*); \ MAE_Ret (*SetTransColor) (IBitmap*, RGBColor_t*); \ MAE_Ret (*GetTransMask) (IBitmap*, u8**, u32*); \ MAE_Ret (*SetTransMask) (IBitmap*, u32, u8*, u32); \ MAE_Ret (*GetTransparency) (IBitmap*, u8*); \ MAE_Ret (*SetTransparency) (IBitmap*, u8); \ MAE_Ret (*DrawHLine) (IBitmap*, u32, u32, u32, RGBColor_t, RasterOp_t); \ MAE_Ret (*DrawVLine) (IBitmap*, u32, u32, u32, RGBColor_t, RasterOp_t); \ MAE_Ret (*FillRect) (IBitmap*, const Rect_t*, RGBColor_t, RasterOp_t); \ MAE_Ret (*BltIn) (IBitmap*, const Rect_t*, IBitmap*, const Rect_t*, RasterOp_t); \ MAE_Ret (*GetDib) (IBitmap*, void**);\ MAE_Ret (*StretchBlt) (IBitmap*, const Rect_t*, IBitmap*, const Rect_t*, RasterOp_t, u32);\ MAE_Ret (*PerspectiveBlt) (IBitmap*, const Rect_t*, IBitmap*, const Rect_t*, RasterOp_t, u32, u16); }; \ struct IBitmap_tag \ { const IBitmap_Vtbl *Vtbl_Ptr; };由上可知,IBitmap就是一个成员只有一个虚函数表IBitmap_Vtbl的结构体。 在这个虚函数表中,可以看到类IBitmap所提供的各种接口。 给用户使用的接口,在头文件Mmi_mae_bitmap.h (proj\sc\application\mmi\mae\pub)中,如下定义: #define IBITMAP_SetTransparency(pIbmp,t) GET_FUNCTBL(pIbmp,IBitmap)->SetTransparency(pIbmp,t)要想找到IBITMAP_xxx的实现,可以搜索:FUNCTBL(IBitmap,比如IBitmap虚函数表的定义在这里: Mae_bitmap.c (proj\sc\application\mmi\mae\src)而用DECLARE_FUNCTBL(IBitmap)可以查到该虚函数表的声明,比如IBitmap虚函数表的声明在这里: Mae_bitmap_priv.h (proj\sc\application\mmi\mae\src): |
转载地址:http://dbifb.baihongyu.com/