G G raphic raphic D D evice evice I I nterface nterface
GGraphic raphic DDevice evice IInterfacenterface
What is GDI• GDI is a graphic interface to perform drawings
MMI WAP JAVA
GDI
Pixtel_UI Pixtel_UI Pixtel_UI
2D HW accelerator
HWdecoder
LCD IF
LCM
GDI Features• Primitive drawing• Image decoding\drawing• Multi-Layer management (6218B\6219...)
• Multi-LCD management• Access LCD interface(BLT and etc.)• Access HW decoder\accelerator.
GDI vs. Pixtel_UI• Pixtel_UI is old interface
– Do not support multi-layer– Do not have new features such as JPEG,etc
• GDI is new interface– Complete features (except drawing string)
GDI Overview (1/3)
• GDI use handle– gdi_handle, GDI_HANDLE– Use handles to manipulate GDI object– Ex: a layer, an animation gif, a decoding jpeg, etc
• GDI function will return GDI_RESULT– Use this result to determine if the request action is
succeeded or not– Success : result >= 0– Failed : result < 0
• GDI is thread safe– GDI function is protected by MUTEX
GDI Overview (2/3)
• GDI Data Type– typedef U16 gdi_color;– typedef S32 gdi_handle;– typedef S32 gdi_result;
– #define GDI_COLOR gdi_color– #define GDI_HANDLE gdi_handle– #define GDI_RESULT gdi_result
GDI Overview (3/3)
• GDI PRIMITIVE– Draw point, line, rectangle, etc
• GDI IMAGE– Draw gif, bmp, wbmp, jpeg, etc
• GDI FONT– Draw font
• GDI LAYER– Multi-Layer management
• GDI LCD– Multi-LCD management
• GDI UTIL– Some utility functions
GDI PRIMITVE (1/3)
• Function– Color format transform– Draw pixel– Draw line, style line– Draw rectangle, style rectangle– 2D memory copy
• Files– gdi_primitive.c– gdi_primitive.h (interface)– gdi_2d_engine.c– gdi_2d_engine.h
GDI PRIMITVE (2/3)
• Color Format Transform (Macro)– GDI_RGB_TO_BUFFER_FORMAT(R,G,B)– GDI_BUFFER_FORMAT_TO_RGB_R(VALUE)– GDI_BUFFER_FORMAT_TO_RGB_G(VALUE)– GDI_BUFFER_FORMAT_TO_RGB_B(VALUE)
– Example
GDI PRIMITVE (3/3)
• Draw pixel– gdi_draw_point
• Draw line & style line– gdi_draw_line– gdi_draw_line_style
• Draw rectangle & style rectangle – gdi_draw_rect– gdi_draw_solid_rect– gdi_draw_frame_rect– gdi_draw_round_rect– gdi_draw_button_rect– gdi_draw_shadow_rect– gdi_draw_gradient_rect
GDI IMAGE (1/5)
• Funtions– Draw static gif, draw gif animation– Draw bmp– Draw wbmp– Draw pbm– Draw jpeg– Get image size– Get animation frame count– Source from files or internal resource
• Files– gdi_image.c– gdi_image.h (interface)– gdi_image_xxxx.c– gdi_image_xxxx.h
GDI IMAGE (2/5)
• API naming rule– Draw type– Source
gdi_image_drawgdi_image_draw_animation_idgdi_image_draw_resized_file
GDI IMAGE (3/5)
• Decoder Capability– BMP
• 1bit, 4bit, 8bit, 16bit, 24bit, 32bit• Do not support core header of Microsoft
– GIF • GIF87, GIF89a• Static image or animation• Normal and Interlaced mode
– JPEG• Do not support progressive mode
– WBMP• Black&white image
– PBM• MTK property format
GDI IMAGE (4/5)
• APIs– gdi_image_draw (_id, _file)– gdi_image_draw_resized– gdi_image_draw_animation– gdi_image_draw_animation_once– gdi_image_draw_animation_frames– gdi_image_draw_animation_single_frame
– gdi_image_get_dimension
– gdi_image_stop_animation– gdi_image_stop_animation_all
GDI IMAGE (5/5)
• No-Blocking Decoder– Decode JPEG in Media Task– Used by file manager to show thumbnail image
• Avoid UI blocked by decoding process
– Files• gdi_image_decoder.c• gdi_image_decoder.h (interface)
– APIs• gdi_image_decoder_create• gdi_image_decoder_free• gdi_image_decoder_decode_file• gdi_image_decoder_decode_file_with_output_clipping• gdi_image_decoder_get_dimension_file• gdi_image_decoder_stop• gdi_image_decoder_stop_all
GDI Font• Font drawing function• HW accelerator in MT6219 and after
• Use pixtel_UI interface to draw font
GDI LAYER (1/3)
• MTK chipset all support multi-layer except MT6205 series– MT6218B (4 layers)– MT6217 (4 layers)– MT6219 (4 layers)– …
• Multi-layer allows programmer to design more fancy UI presentation with better performance
• Files– gdi_layer.c– gdi_layer.h
GDI LAYER (2/3)
• Drawing a submenu with background image– WITHOUT multi-layer– NEED REDRAW EVERYTHING include BACKGROUD
GDI LAYER (3/3)
• Drawing a submenu with background image– WITH multi-layer– NO NEED TO REDRAW BACKGROUD
Blue is transparentcolor
What is BLT?• Send Frame buffer data to LCM
Frame Buffer LCM
Drawings
BLT
DrawingsFrame Buffer
LCM
Merge & BLT
GDI LAYER – Base Layer• There is always one layer exist
– Base Layer– Same size as LCM size– By default – this is the ACTIVE layer– All drawings will draw to ACTIVE layer– There is a base layer for Main LCD and a base layer
for Sub LCD– Use gdi_layer_get_active to get base layer’s handle– Base layer handle
• GDI_LAYER_MAIN_BASE_LAYER_HANDLE• GDI_LAYER_SUB_BASE_LAYER_HANDLE
HOW TO USE – Init (1/2)
• Start Using Multi-layer– gdi_layer_multi_layer_enable
• Create Multi-layer– gdi_layer_create– gdi_layer_create_using_outside_memory– gdi_layer_create_double– gdi_layer_create_double_using_outside_memory
– You will get a handle when create layer successful
HOW TO USE – Init (2/2)
• Set The Layer ACTIVE– gdi_layer_push_and_set_active
• gdi_layer_get_active - get previous active layer handle• gdi_layer_set_active – set this layer active
• Set Layer’s Property– gdi_layer_set_source_key
• GDI_COLOR_TRANSPARENCY (0, 0, 255)– gdi_layer_set_opacity
Previous
active layer stack
HOW TO USE – Drawing• Input
– Screen need to redraw
• Drawing – Draw line, draw images, etc
• BLT to LCM– gdi_layer_blt– Tell which layers and what region will be blt to LCM– gdi_layer_set_blt_layer– gdi_layer_blt_previous Layer 0
Layer 1
Layer 2
GDI LAYER – DeInit• Restore to Previous ACTIVE Layer
– gdi_layer_pop_and_restore_active• gdi_layer_set_active – set previous active layer active again
• Flatten Layers– gdi_layer_flatten_to_base
• Free Layer– gdi_layer_free
• End Using Multi-layer– gdi_layer_multi_layer_disable
Previous
active layer stack
OTHER GDI LAYER APIs• Clip Region
– gdi_layer_get_clip– gdi_layer_set_clip– gdi_layer_push_clip– gdi_layer_pop_clip– gdi_layer_reset_clip
– gdi_layer_get_text_clip– gdi_layer_set_text_clip– gdi_layer_reset_text_clip– gdi_layer_push_text_clip– gdi_layer_pop_text_clip
Rules! (1/3)
• RULE 1– Multi layer only support under chip 6218& 6219
• Define in MMI_feature.h , _GDI_MEMORY_PROFILE_2_
• Number indicate layer buffer count (LCD_WIDTH x LCD_HEIGHT x 2)
• RULE 2– All action will take effect on the layer after you set it active.
• Drawing.• Set clip, transparency, source key.• Move…etc.
• RULE 3– DO restore to base layer after leaving a function.
• This should always work if you use – gdi_layer_push_and_set_active– gdi_layer_pop_and_restore_active.
Rules! (2/3)
• RULE 4– Some function should be PAIRED!
• gdi_layer_lock_frame_buffer• gdi_layer_unlock_frame_buffer
• gdi_layer_push_clip• gdi_layer_pop_clip
• gdi_layer_push_text_clip• gdi_layer_pop_text_clip
• gdi_layer_push_and_set_active• gdi_layer_pop_and_restore_active
– Be careful when return in the middle of a function.
Rules! (3/3)
• RULE 5– Each GDI function is protected by recursive mutex.– You should use GDI_LOCK / GDI_UNLOCK to speed
up your application.– Example:
GDI_LOCKgdi_layer_lock_frame_bufferpixtel_UI_reset_clipshow_status_icons….gdi_layer_unlock_frame_buffergdi_layer_blt
GDI_UNLOCK
WGUI • For backward compatible reason, wgui use
layers with base layer above newly created layer• All old component can only draw on base layer
wgui_base_layer
wgui_layer1Opacity = 40
src_key = GDI_COLOR_TRANSPARENCY
GUI Multi-layer Interface• GUI add an interface for categories
• Files– Gui_window.h– Gui_window.c
GDI LCD• Support multiple LCD• Files
– gdi_lcd.c– gdi_lcd.h
• APIs – gdi_lcd_set_active– gdi_lcd_get_active
– UI_set_sub_LCD_graphics_context()– UI_set_main_LCD_graphics_context()
Q&A