Prepare Demo software

Through previous steps, you have installed DirectFB to SH-4 Linux environment. To confirm everything created and installed properly use DirectFB demo program. You can download these demo program from DirectFB project website, that name is "DirectFB-examples". We used version 0.9.18. You can download from following Web site.

Do make in src directory ( If you do make at the upper directory, it seems not works correctly )

Install Demo program

Now demo program binary images was generated in src directory, you can copy manually these binary to target root_fs's your preferred location. Then copy all data file located under data directory to /usr/local/share/directfb-examples It seems you do not maintain/modift these file (just copy) except Makefile.

Benchmark program

Demo program named df_dok is DirectFB benchmark. If you run this without any options, it automatically runs set of benchmark program using graphics acceleration capability, and display result as graph. We use this benchmark score to tune DirectFB library for SM501.

Cross compiling

Like other Linux application program, DirectFB is designed to compile only on x86 Linux. We struggled this time to compile DirectFB for SH-4 Linux and finally we success this cross porting. However we think this is a kind of handwork way. When you try to run demo program on non-x86 Linux, x86 reference looks mandatory. I suggest you start DirectFB implementation from x86 Linux.

Writing DirectFB driver

Graphics driver detection procedure

Graphics chip drivers are located under /usr/local/lib/directfb-0.9.20/gfxdrivers There is no special installation procedure to add your own driver. DirectFB checks all drivers in driver_probe routine. When DirectFB detect correct driver in this process, DirectFB enables this driver. If driver does not works then move to next driver check, if all drivers does not much, DirectFB runs software mode without dedicated graphics driver. We have tentatively modified this process force to use SM501 driver.

Enabling hardware graphics acceleration capability

Drawing routine set command parameters to use 2D acceleration capability. Graphic driver returns TRUE or FALSE as return-value. If FALSE returned, DirectFB thinks hardware acceleration does not built-in, and use whole software drawing. Not all drawing routine has this acceleration detection mechanism, it is sure to define in `CheckState` routine. You can write your own driver as you like except command parameters and return value.

SM501 driver development

reference driver

We use i810 graphics driver as a reference, because it is small and looks easy to implement. Finally we need to refer other drivers because i810 has limited numbers of draw routine. If you want to support full drawing capabilities, Matrox driver may be better reference.

Drawing API prepared for SM501

API

Operations

`sm501_set_src`

Set source address for BLIT operation. You need to assign VRAM physical address to source address.

`sm501_set_dest`

Set destination physical address and color depth for BLIT and drawing operation.

`sm501_set_colorkey`

colorkey setting, it defines transparent color for colorkeyed BLIT operation. Color compare regiser is used in SM501 to enable this operation. You can define transparent color to the SM501 color compare register, then SM501 does not transfer this color when doing BLIT operation. So it looks transparent.

`sm501_set_color`

Define drawing color setting

`sm501_set_clip`

Save clipping coordinates value to the structure, and set SM501 clipping register as well

`sm501CheckState`

This bit returns hardware acceleration capability. You need to refer each graphics spec, and you also care for color format that graphics supports

`sm501SetState`

Do pre-process for acceleration

`sm501FillRectangle`

Do fill rectangle, using SM501 2D drawing engine

`sm501DrawRectangle`

Draw rectangles. SM501 does not have rectangle drawing capability, so draw four lines to draw rectangle in this driver

`sm501Blit`

Do BLIT operation, using SM501 2D drawing engine

`sm501StretchBlit`

Do Stretch BLIT To avoid SM501 2D engine stretch function limitation, we use CSC (color space conversion) function instead. Colorkeyed stretch BLIT can not be support in this driver.

`sm501DrawLine`

Draw line, using SM501 2D drawing engine. Use shortstroke command for simple vertical / holizontal line,and use line command for other kind of line.

`sm501fill_tri`

Draw triangle with filling inside. As SM501 does not have hardware triangle drawing capability,we draw triangle by software. However we can use horizontal line draw capability in SM501, so seems to achieved a little better performance than all software drawing.

`sm501FillTriangle`

Fill triangle, actual operation execute in subroutine sm501fill_tri

`driver_get_abi_version`

Returns version information

`driver_probe`

This should return check result of expected graphics chip is exist or not. At this moment, this driver retunes always TRUE (=SM501 exist)

`driver_get_info`

Returns driver's information

`sm501_release_resource`

Do close operation

`driver_init_driver`

Initialize SM501 2D engine and create function table

`driver_init_device`

Initialize device structure

`driver_close_device`

Do nothing at this moment

`driver_close_driver`

Do nothing at this moment

DirectFB porting notes

DirectFB requires display resolution capability built in frame buffer driver.
So initially we modify SM501 generic frame buffer driver to support resolution
and color depth setting. We did not care for pixel_clock, left/right margin and
vertical/horizontal sync, because DirectFB does not works when frame buffer
drivers return FALSE to these parameter. It looks no problem using without
these parameters.

Initially we modify reference gfxdriver (=i810) source code so that SH-4 gcc
compiler can compile properly. Actually we maintain filename, display character
and source code comment to fit SM501. And commented out driver code that operate
2D graphics engine. After you compile SM501 driver, copy it to the proper location
so that DirectFB can load this new driver. If DirectFB boot message does not comes
driver location missing nor driver_probe process returns error.

Then merge 2D engine sample program that works. In SM501 initialization call
2D engine initialization and modify simple graphics API like line. You need to
activate bit in `CheckState`, that has hardware acceleration in SM501.
Remove unused program in driver_init_driver, to eliminate unexpected initialization.

Once SM501 hardware acceleration works, replace other drawing API.
If SM501 command support DirectFB drawing API, just use SM501 command. If SM501
does not support it, you need to find out alternative way to implement this API.
If your reference driver does not support required API, you need to refer other
graphics driver and you need to add this function by yourself.

If you added new hardware drawing API, you need to enable bit in `CheckState`
and need to maintain function table list. Due to the limitations of graphics
controller if some hardware acceleration can not be used, you need to disable
corresponded bit in `CheckState`. For example SM501 can not handle ARGB format.
If BLIT source format does not much target format, SM501 can not use hardware
BLIT capability. In such case you need to disable bit in `CheckState`.

To achieve better performance, we modify to use /dev/mem access instead of
usual ioctl call, that was originally used in reference driver. After we
maintained to read/write 2D engine register directly use /dev/mem, drawing
performance increased dramatically especially `FillRect` type simple parameter
command.

Finally we removed un-used function built in reference driver. For example i810 driver include UMA setting. PCI initialization does not need when SM501 connect to SH-4 using SH-BUS. So we remove these portion.

Reference

Unfortunately we can not find any useful information to DirectFB port to SH-4 Linux. So we do it using step-by-step way using printk(). For 2D acceleration portion, sample program and device document were helpful. But sometime it is difficult to understand actual drawing limitations. So x86 DirectFB is mandatory as a reference when you port DirectFB to the Linux runs on embedded CPU like SH-4.

Resources

You can download original source, patches and pre-compiled DirectFB program for `RTS7751R2D` platform