#ifndef __MSTAR__TYPES_H__
#define __MSTAR__TYPES_H__

#include <core/layers.h>


#define MSTAR_MULTI_GOP_SUPPORT          TRUE
#define MSTARGFX_MAX_LAYER_BUFFER        24
#define MAX_PALETTE_ENTRY_CNT  256
#define MAX_PALETTE_INTENSITY_I4_CNT  16
#define MAX_PALETTE_INTENSITY_I2_CNT  4
#define MAX_PALETTE_INTENSITY_I1_CNT  2





#if MSTAR_MULTI_GOP_SUPPORT
#define MSTAR_MAX_GOP_COUNT 6
#define MSTAR_MAX_OUTPUT_LAYER_COUNT MSTAR_MAX_GOP_COUNT
#else
#define MSTAR_MAX_OUTPUT_LAYER_COUNT  6
#endif

typedef enum
{
    SLF_SHADOW_LAYER_BOOLEAN    =  0x80000000,
    SLF_SHADOW_LAYER_INDEX0     =  0X00000001,
    SLF_SHADOW_LAYER_INDEX1     =  0X00000002,
    SLF_SHADOW_LAYER_INDEX2     =  0X00000004,
    SLF_SHADOW_LAYER_INDEX3     =  0X00000008,
    SLF_SHADOW_LAYER_INDEXALL   =  0X0000000F,   
    
}ShadowLayerFlag;


typedef struct{
     u32  Hstart;
     u32  Vstart;
     u32  width;
     u32  height;
}ScreenSize;


typedef struct {
     u8            layer_index;
     u8            gop_index;
     u8            gop_index_r;
     u8            gop_dst;
     ScreenSize    screen_size;
     FusionReactor               *reactor;       /* event dispatcher */
     FusionCall                   call;          /* driver call via master */
     u8            VideoFiledMode; 
     ShadowLayerFlag          ShadowFlags;      /*if the layer has shadow layer, show all the shadow layers*/
     int                   layer_displayMode;
     u8            GopDstMode; 
} MSTARLayerData;

typedef struct {
     int                      magic;

     CoreLayerRegionConfig    config;
     CoreLayerRegionConfigFlags config_dirtyFlag; //which configuration need to update to hw

} MSTARRegionData;


typedef struct {
     int                      lcd_width;
     int                      lcd_height;
     int                      lcd_offset;
     int                      lcd_pitch;
     int                      lcd_size;
     DFBSurfacePixelFormat    lcd_format;

     /* locking */
     FusionSkirmish           beu_lock;

     bool                           b_hwclip;

     /* gop */
     int                     gfx_gop_index;
     int                     gfx_h_offset;
     int                     gfx_v_offset;
     int                     gfx_max_width;
     int                     gfx_max_height;
     unsigned long           mst_miu1_hal_offset;
     unsigned long           mst_miu1_cpu_offset;

     int                     layer_refcnt[MSTAR_MAX_OUTPUT_LAYER_COUNT];
     int                     layer_zorder[MSTAR_MAX_OUTPUT_LAYER_COUNT];
     bool                    layer_active[MSTAR_MAX_OUTPUT_LAYER_COUNT];
     int                     layer_gwin_id[MSTAR_MAX_OUTPUT_LAYER_COUNT];
     int                     layer_gwin_id_r[MSTAR_MAX_OUTPUT_LAYER_COUNT];
     bool                   layer_pinpon_mode[MSTAR_MAX_OUTPUT_LAYER_COUNT];
     ScreenSize              layer_screen_size[MSTAR_MAX_OUTPUT_LAYER_COUNT];
     FusionReactor           *reactor[MSTAR_MAX_OUTPUT_LAYER_COUNT];       /* event dispatcher */

     bool                   a8_palette;
     GFX_PaletteEntry       palette_tbl[MAX_PALETTE_ENTRY_CNT];
     int                    num_entries;

     u32                   palette_intensity[MAX_PALETTE_INTENSITY_I4_CNT];
     int                   num_intensity;
    
} MSTARDeviceData;

typedef struct
{
   CoreSurface *pCoDFBCoreSurface;
   CoreSurfaceBuffer *pCoDFBBuffer;
   unsigned long physAddr;
   u16               u16GOPFBID;
   u16               u16SlotUsed;
   u8                 u8GWinID;
   DFBSurfacePixelFormat    format;
   unsigned long pitch;
}LayerBufferInfo;

typedef struct
{
    u16 tagID;
    u32 CurPhysAddr;
} FlipInfo;

typedef struct {
     MSTARDeviceData        *dev;

     u32                      ge_src_colorkey_enabled  : 1;
     u32                      ge_draw_dst_colorkey_enabled  : 1;
     u32                      ge_blit_dst_colorkey_enabled  : 1;
     u32                      ge_draw_alpha_blend_enabled  : 1;
     u32                      ge_blit_alpha_blend_enabled  : 1;
     u32                      ge_palette_enabled   :1;
     u32                      ge_blit_nearestmode_enabled :1;
     u32                      ge_render_alpha_cmp_enabled :1;
     u32                      ge_blit_xmirror               :1;
     u32                      ge_blit_ymirror               :1;
     u32                      ge_palette_intensity_enabled:1;
     u32                      reserved_mask                 :21;

     /* cached values */
     unsigned long            dst_phys;
     int                      dst_pitch;
     int                      dst_bpp;
     int                      dst_index;
     unsigned int             dst_ge_format ;
     unsigned int             dst_w ;
     unsigned int             dst_h ;

     u32             src_ge_clr_key ;
     u32             dst_ge_clr_key;

     GFX_YUV_422     src_ge_yuv_fmt;
     GFX_YUV_422     dst_ge_yuv_fmt;

     unsigned long            src_phys;
     int                      src_pitch;
     int                      src_bpp;
     int                      src_index;
     unsigned int             src_ge_format ;
     unsigned int             src_w ;
     unsigned int             src_h ;
     DFBRegion                clip;

     DFBSurfaceDrawingFlags   dflags;
     DFBSurfaceBlittingFlags  bflags;

     u8                      ge_last_render_op;
     /* ge */
     DFBSurfaceBlittingFlags gfx_supported_bld_flags;
     DFBSurfaceDrawingFlags  gfx_supported_draw_flags;

     GFX_DFBBldOP            ge_src_blend;
     GFX_DFBBldOP            ge_dst_blend;
     u16                     ge_draw_bld_flags;
     u16                     ge_blit_bld_flags;

     u32                     ge_render_alpha_cmp;

     DFBColor                 color;
     DFBColor                 color2;//for gradient fill

     CoreDFB                 *core;
     CardState               *state;
     CoreGraphicsDevice      *device;

     CoreScreen              *op_screen;
     CoreScreen              *ip0_screen;
     CoreScreen              *ve_screen;
     CoreScreen              *oc_screen;  

     CoreLayer               *layers[MSTAR_MAX_OUTPUT_LAYER_COUNT];

     LayerBufferInfo  mstarLayerBuffer[MSTARGFX_MAX_LAYER_BUFFER];

     volatile void           *mmio_base;

     int                      num_inputs;

     volatile void           *lcd_virt;

     FlipInfo                layerFlipInfo[MSTAR_MAX_OUTPUT_LAYER_COUNT];
} MSTARDriverData;

typedef enum
{
    E_VIDEO_FIELD_INTERLACE = 1,
    E_VIDEO_FIELD_PROGRESSIVE = 2,
}E_VIDEO_FIELD_MODE;
#endif

