📄 2d_engine.c
字号:
* PARAMETERS
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void g2d_deinit(void)
{
#ifdef __MTK_TARGET__
g2d_power_off();
IRQMask(IRQ_G2D_CODE);
#endif
} /* g2d_deinit() */
void wait_cmq_start(void)
{
volatile kal_uint16 i;
for (i=0;i<0x100;i++);
} /* wait_cmq_start() */
/*************************************************************************
* FUNCTION
* g2d_set_clip_window
*
* DESCRIPTION
* This function set the g2d clip window.
*
* PARAMETERS
* g2d_data : the parameter data structure of G2D module
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void g2d_set_clip_window(g2d_parameter_struct *g2d_data)
{
#ifdef __MTK_TARGET__
if (g2d_data->clip_mode==G2D_CLIP_ENABLE)
{
if ((g2d_data->clip_start_x>g2d_data->clip_end_x) ||
(g2d_data->clip_start_y>g2d_data->clip_end_y))
ASSERT(0);
}
if (G2D_ENGINE_IS_BUSY)
{
ENABLE_G2D_CMQ;
#if (defined(MT6219)||defined(MT6226)||defined(MT6226M)||defined(MT6227))
while (G2D_CMQ_FREE_SPACE<4)
{}; /* wait until command queue free space >4 */
DRV_WriteReg32(G2D_CMQ_DATA_REG,(G2D_CMQ_CLIP_TOP_Y_ADDR | g2d_data->clip_start_y));
DRV_WriteReg32(G2D_CMQ_DATA_REG,(G2D_CMQ_CLIP_LEFT_X_ADDR | g2d_data->clip_start_x));
DRV_WriteReg32(G2D_CMQ_DATA_REG,(G2D_CMQ_CLIP_BOTTOM_Y_ADDR | g2d_data->clip_end_y));
DRV_WriteReg32(G2D_CMQ_DATA_REG,(G2D_CMQ_CLIP_RIGHT_X_ADDR | g2d_data->clip_end_x));
if (g2d_data->clip_mode==G2D_CLIP_ENABLE)
DRV_WriteReg32(G2D_CMQ_DATA_REG,(G2D_CMQ_2D_COMMON_CTRL_REG_ADDR |
(DRV_Reg32(G2D_COMM_CTRL_REG)|REG_COMMON_CTRL_G2D_CLIP_ENABLE_BIT)));
else
DRV_WriteReg32(G2D_CMQ_DATA_REG,(G2D_CMQ_2D_COMMON_CTRL_REG_ADDR |
(DRV_Reg32(G2D_COMM_CTRL_REG)&(~REG_COMMON_CTRL_G2D_CLIP_ENABLE_BIT))));
#elif (defined(MT6228)||defined(MT6229)||defined(MT6230))
while (G2D_CMQ_FREE_SPACE<4)
{}; /* wait until command queue free space >4 */
ENABLE_G2D_CMQ_WRITE;
G2D_WRITE_CMQ(G2D_CMQ_CLIP_TOP_Y_ADDR | g2d_data->clip_start_y);
G2D_WRITE_CMQ(G2D_CMQ_CLIP_LEFT_X_ADDR | g2d_data->clip_start_x);
G2D_WRITE_CMQ(G2D_CMQ_CLIP_BOTTOM_Y_ADDR | g2d_data->clip_end_y);
G2D_WRITE_CMQ(G2D_CMQ_CLIP_RIGHT_X_ADDR | g2d_data->clip_end_x);
DISABLE_G2D_CMQ_WRITE;
#endif
}
else
{
DISABLE_G2D_CMQ;
DRV_WriteReg32(G2D_CLP_LT_REG,((g2d_data->clip_start_x <<16) | g2d_data->clip_start_y));
DRV_WriteReg32(G2D_CLP_RB_REG,((g2d_data->clip_end_x <<16) | g2d_data->clip_end_y));
if (g2d_data->clip_mode==G2D_CLIP_ENABLE)
{
ENABLE_G2D_ENGINE_CLIP;
}
else
{
DISABLE_G2D_ENGINE_CLIP;
}
}
#endif
} /* g2d_set_clip_window() */
/*************************************************************************
* FUNCTION
* g2d_set_tilt_data
*
* DESCRIPTION
* This function set the g2d tilt parameter for font caching operation.
*
* PARAMETERS
* color_mode : 16BPP mode (G2D_DEST_16BPP_LUT_DISABLE) or 8BPP mode (G2D_DEST_8BPP_LUT_DISABLE)
* index : the index of tilt parameter
* tilt_value : tilt pixel of index-th tilt parameter.
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void g2d_set_tilt_data(kal_uint8 index, kal_uint8 tilt_value)
{
#ifdef __MTK_TARGET__
#if (defined(MT6228)||defined(MT6229)||defined(MT6230))
if (G2D_CMQ_IS_ENABLE)
{
while (G2D_CMQ_FREE_SPACE!=G2D_CMQ_LENGTH) {};
DISABLE_G2D_CMQ;
SET_G2D_TILT(index,tilt_value);
ENABLE_G2D_CMQ;
}
else
SET_G2D_TILT(index,tilt_value);
#endif
#else
g2d_sw_tilt_value[index]=tilt_value;
#endif
} /* g2d_set_tilt_data() */
/*************************************************************************
* FUNCTION
* g2d_set_color_palette
*
* DESCRIPTION
* This function set the color palette of G2D module.
*
* PARAMETERS
* index : color palette index
* color : color of specified color palette in RGB565 format.
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void g2d_set_color_palette(kal_uint8 index, kal_uint32 color)
{
#ifdef __MTK_TARGET__
#if (defined (MT6219)||defined(MT6226)||defined(MT6226M)||defined(MT6227))
ENABLE_G2D_ENGINE_PALETTE;
DRV_WriteReg32((G2D_PALETTE_BASE+(index<<2)),color);
DISABLE_G2D_ENGINE_PALETTE;
#elif (defined(MT6228)||defined(MT6229)||defined(MT6230))
#endif
#endif
} /* g2d_set_color_palette() */
void g2d_multi_bitblt_operation(g2d_parameter_struct *g2d_data)
{
#ifdef __MTK_TARGET__
#if (defined (MT6219)||defined(MT6226)||defined(MT6226M)||defined(MT6227))
switch (g2d_data->dest_color_mode)
{
case G2D_DEST_16BPP_LUT_DISABLE:
case G2D_DEST_16BPP_LUT_ENABLE:
g2d_data->dest_pitch=(g2d_data->dest_pitch_width<<1);
g2d_data->dest_base_address += ((g2d_data->dest_pitch_width * g2d_data->dest_y + g2d_data->dest_x)<<1);
break;
case G2D_DEST_8BPP_LUT_DISABLE:
g2d_data->dest_pitch=g2d_data->dest_pitch_width;
g2d_data->dest_base_address += ((g2d_data->dest_pitch_width * g2d_data->dest_y + g2d_data->dest_x));
break;
}
switch (g2d_data->src_color_mode)
{
case G2D_SRC_16BPP_LUT_DISABLE:
g2d_data->src_pitch=(g2d_data->src_pitch_width<<1);
g2d_data->src_base_address += ((g2d_data->src_pitch_width * g2d_data->src_y + g2d_data->src_x)<<1);
break;
case G2D_SRC_8BPP_LUT_DISABLE:
case G2D_SRC_8BPP_LUT_ENABLE:
g2d_data->src_pitch=g2d_data->src_pitch_width;
g2d_data->src_base_address += (g2d_data->src_pitch_width * g2d_data->src_y + g2d_data->src_x);
break;
}
g2d_bitblt(g2d_data);
#endif
#endif
} /* g2d_multi_bitblt_operation() */
void g2d_multi_bitblt(g2d_parameter_struct *g2d_data)
{
#ifdef __MTK_TARGET__
#if (defined (MT6219)||defined(MT6226)||defined(MT6226M)||defined(MT6227))
kal_uint16 temp_data,temp_src_x,temp_src_y;
short temp_dest_x,temp_dest_y;
kal_uint16 temp_src_width,temp_src_height,temp_dest_width,temp_dest_height;
if (((g2d_data->dest_x+g2d_data->dest_width)<0)||
((g2d_data->dest_y+g2d_data->dest_height)<0))
return;
if (g2d_data->dest_x<0)
{
temp_data=(0-g2d_data->dest_x)/g2d_data->src_width;
g2d_data->dest_x+=(temp_data * g2d_data->src_width);
g2d_data->dest_width-=(temp_data * g2d_data->src_width);
}
if (g2d_data->dest_y<0)
{
temp_data=(0-g2d_data->dest_y)/g2d_data->src_height;
g2d_data->dest_y+=(temp_data * g2d_data->src_height);
g2d_data->dest_height-=(temp_data * g2d_data->src_height);
}
temp_src_x=g2d_data->src_x;
temp_src_y=g2d_data->src_y;
temp_src_width=g2d_data->src_width;
temp_src_height=g2d_data->src_height;
temp_dest_x=g2d_data->dest_x;
temp_dest_y=g2d_data->dest_y;
temp_dest_width=g2d_data->dest_width;
temp_dest_height=g2d_data->dest_height;
if ((g2d_data->dest_x<0)&&(g2d_data->dest_y<0))
{
g2d_data->src_x-=g2d_data->dest_x;
g2d_data->src_y-=g2d_data->dest_y;
g2d_data->src_width+=g2d_data->dest_x;
g2d_data->src_height+=g2d_data->dest_y;
g2d_data->dest_x=0;
g2d_data->dest_y=0;
g2d_data->dest_width=g2d_data->src_width;
g2d_data->dest_height=g2d_data->src_height;
g2d_multi_bitblt_operation(g2d_data);
g2d_data->src_x=temp_src_x;
g2d_data->src_width=temp_src_width;
g2d_data->dest_x=temp_src_width+temp_dest_x;
g2d_data->dest_width=temp_dest_width-temp_src_width;
g2d_multi_bitblt_operation(g2d_data);
g2d_data->src_x=temp_src_x-temp_dest_x;
g2d_data->src_y=temp_src_y;
g2d_data->src_width=temp_src_width+temp_dest_x;
g2d_data->src_height=temp_src_height;
g2d_data->dest_x=0;
g2d_data->dest_y=temp_dest_y+temp_src_height;
g2d_data->dest_width=temp_src_width+temp_dest_x;
g2d_data->dest_height=temp_dest_height-temp_src_height;
g2d_multi_bitblt_operation(g2d_data);
}
else if (g2d_data->dest_y<0)
{
g2d_data->src_y-=g2d_data->dest_y;
g2d_data->src_height+=g2d_data->dest_y;
g2d_data->dest_y=0;
g2d_data->dest_height=g2d_data->src_height;
g2d_multi_bitblt_operation(g2d_data);
}
else if (g2d_data->dest_x<0)
{
g2d_data->src_x-=g2d_data->dest_x;
g2d_data->src_width+=g2d_data->dest_x;
g2d_data->dest_x=0;
g2d_data->dest_width=g2d_data->src_width;
g2d_multi_bitblt_operation(g2d_data);
}
g2d_data->src_x=temp_src_x;
g2d_data->src_y=temp_src_y;
g2d_data->src_width=temp_src_width;
g2d_data->src_height=temp_src_height;
if (temp_dest_x<0)
{
g2d_data->dest_x=temp_dest_x+temp_src_width;
g2d_data->dest_width=(temp_dest_width-temp_src_width);
}
else
{
g2d_data->dest_x=temp_dest_x;
g2d_data->dest_width=temp_dest_width;
}
if (temp_dest_y<0)
{
g2d_data->dest_y=temp_dest_y+temp_src_height;
g2d_data->dest_height=(temp_dest_height-temp_src_height);
}
else
{
g2d_data->dest_y=temp_dest_y;
g2d_data->dest_height=temp_dest_height;
}
g2d_multi_bitblt_operation(g2d_data);
#endif
#endif
} /* g2d_multi_bitblt() */
#ifdef __MTK_TARGET__
void g2d_sw_font_caching(g2d_parameter_struct *g2d_data)
{
#if (defined (MT6219)||defined(MT6226)||defined(MT6226M)||defined(MT6227))
kal_uint16 font_bit,font_bit_count,font_count=0;
kal_uint16 i,j;
kal_uint16 *font_buff_ptr;
kal_uint8 *font_buff_ptr1,*font_data_ptr,font_data;
short x_pos,y_pos;
font_data_ptr=(kal_uint8 *) g2d_data->src_base_address;
font_data=*(font_data_ptr+font_count);
font_bit_count=0;
font_count++;
if (g2d_data->dest_color_mode==G2D_DEST_16BPP_LUT_DISABLE)
g2d_data->dest_pitch=(g2d_data->dest_pitch_width<<1);
else
g2d_data->dest_pitch=(g2d_data->dest_pitch_width);
if (g2d_data->dest_x<0)
{
if (g2d_data->dest_y>0)
{
if (g2d_data->dest_color_mode==G2D_DEST_16BPP_LUT_DISABLE)
g2d_data->dest_base_address += (g2d_data->dest_y * g2d_data->dest_pitch);
else
g2d_data->dest_base_address += (g2d_data->dest_y * g2d_data->dest_pitch);
}
}
else
{
if (g2d_data->dest_color_mode==G2D_DEST_16BPP_LUT_DISABLE)
g2d_data->dest_base_address += (g2d_data->dest_x<<1);
else
g2d_data->dest_base_address += g2d_data->dest_x;
}
if (g2d_data->dest_color_mode==G2D_DEST_16BPP_LUT_DISABLE)
{
for (i=0;i<g2d_data->src_height;i++)
{
if (g2d_data->italic_mode==0)
{
x_pos=g2d_data->dest_x;
y_pos=g2d_data->dest_y+i;
}
else
{
x_pos=g2d_data->dest_x+ (GET_G2D_TILT(i)>>1);
y_pos=g2d_data->dest_y+i;
}
font_buff_ptr=(kal_uint16 *)(g2d_data->dest_base_address + ((y_pos*g2d_data->dest_pitch+x_pos)));
for (j=0;j<g2d_data->src_width;j++)
{
font_bit = font_data & 0x01;
if ((x_pos>=0)&&(y_pos>=0))
{
if (g2d_data->clip_mode)
{
if ((x_pos>=g2d_data->clip_start_x) && (x_pos <=g2d_data->clip_end_x) &&
(y_pos>=g2d_data->clip_start_y) && (y_pos <=g2d_data->clip_end_y))
{ /* in clip range */
if (font_bit)
{
*(font_buff_ptr+j) = g2d_data->pat_fg_color;
}
else
{
if (g2d_data->font_background_mode)
*(font_buff_ptr+j) = g2d_data->pat_bg_color;
}
}
}
else
{
if (font_bit)
{
*(font_buff_ptr+j) = g2d_data->pat_fg_color;
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -