博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MSTAR虚函数表(以IBitmap为例),以及快速查找函数实现的方法:FUNCTBL(IBitmap
阅读量:2221 次
发布时间:2019-05-08

本文共 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/

你可能感兴趣的文章
深入理解JVM虚拟机5:虚拟机字节码执行引擎
查看>>
深入理解JVM虚拟机6:深入理解JVM类加载机制
查看>>
深入了解JVM虚拟机8:Java的编译期优化与运行期优化
查看>>
深入理解JVM虚拟机9:JVM监控工具与诊断实践
查看>>
深入理解JVM虚拟机10:JVM常用参数以及调优实践
查看>>
深入理解JVM虚拟机12:JVM性能管理神器VisualVM介绍与实战
查看>>
深入理解JVM虚拟机13:再谈四种引用及GC实践
查看>>
Spring源码剖析1:Spring概述
查看>>
Spring源码剖析2:初探Spring IOC核心流程
查看>>
Spring源码剖析5:JDK和cglib动态代理原理详解
查看>>
Spring源码剖析6:Spring AOP概述
查看>>
Spring源码剖析8:Spring事务概述
查看>>
Spring源码剖析9:Spring事务源码剖析
查看>>
重新学习Mysql数据库1:无废话MySQL入门
查看>>
探索Redis设计与实现2:Redis内部数据结构详解——dict
查看>>
探索Redis设计与实现3:Redis内部数据结构详解——sds
查看>>
探索Redis设计与实现4:Redis内部数据结构详解——ziplist
查看>>
探索Redis设计与实现6:Redis内部数据结构详解——skiplist
查看>>
探索Redis设计与实现5:Redis内部数据结构详解——quicklist
查看>>
探索Redis设计与实现8:连接底层与表面的数据结构robj
查看>>