Mobile/DFBPorting

From MozillaWiki
Jump to: navigation, search

Porting Goals

  • Firefox running with full functionality (including SVG) on DirectFB (web site, Wikipedia) -based platforms
  • Use GDK as much as possible so that the backend (X, DFB etc) dependencies are abstracted out
  • Use DirectFB calls only if absolutely necessary
    • Functionality not mappable to GDK
    • Any other compelling reasons related to performance

Porting Items

Native Surface Creation

Current State

cairo_xlib_* functions are used for creating surfaces on X. These cairo_xlib_* funtions are implemented in cairo and are specific to X backend.

Related files
  • gfx/thebes/public/gfxXlibSurface.h
  • gfx/thebes/public/gfxXlibSurface.cpp
  • All callers of gfxXlibSurface
    • widget/src/gtk2/nsWindow.cpp
    • gfx/thebes/src/gfxPlatformGtk.cpp
    • gfx/thebes/src/gfxASurface.cpp
    • layout/generic/nsObjectFrame.cpp


Proposed Porting Approach

  • Clone gfxXlibSurface to gfxGdkCairoSurface
  • Callers of gfxXlibSurface will now call gfxGdkCairoSurface.
  • gfxGdkCairoSurface implementation calls Xlib specific functions under MOZ_X11 switch and calls DirectFB specific functions under MOZ_DFB switch.
  • This approach will abstract out all backend specific functions and move them to a single place
  • Users of gfxXlibSurface to create cairo surface for a GdkWindow will simply call gfxGdkCairoSurface with GdkDrawable
  • Users of gfxXlibSurface to create cairo surface for an offscreen buffer (pixmap) will undergo some changes:
    • A gdk pixmap of required depth will be created and corresponding GdkDrawable will be passed to gfxGdkCairoSurface for creating cairo surface
    • All other x11 dependent code (checking for xrender extension etc) will be removed as gfxGdkCairoSurface will take care of all required functionality .
  • The actual cairo-xlib surface creation will use GdkDrawable's depth to call correct cairo_xlib functions:
    • cairo_xlib_surface_create() will be called if the GdkDrawable has non-NULL visual
    • else: cairo_xlib_surface_create_for_bitmap() will be called if the depth is 1
    • else : cairo_xlib_surface_create_with_xrender_format() will be called
  • The actual cairo-dfb surface creation will use type of GdkDrawable (Window or pixmap) to call correct cairo-dfb functions
    • cairo_directfb_surface_create() will be called with the DFB Surface returned from gdk_directfb_surface_lookup (), if the GdkDrawable is a Window
    • cairo_directfb_surface_create() will be called with a newly created DFB Surface. The new DFB Surface will be created using CreateSurface() with the GdkDrawable's depth mapped to DFB pixel format.

NativeRenderer

Current State

NativeRenderer's Draw function is called for drawing a GTK widget composited with cairo state. NativeRenderer calls cairo_draw_with_xlib that has lot of dependencies on cairo_xlib*. cairo_draw_with_xlib does all the fancy stuff (complex transforms) and finally calls NativeDraw with the Drawable associated with the cairo surface. cairo_xlib provides API to obtain Drawable associated with a given Cairo surface.

According to Vlad (on irc), cairo_draw_with_xlib is really there for supporting complex transforms (rotation, affine-transformations etc) that gfx natively doesn't support but depends on cairo. Effect of disabling cairo_draw_with_xlib is that the SVG and Canvas will not work; but native theming will work fine.


Related files
  • gfx/thebes/public/gfxXlibNativeRenderer.h
  • gfx/thebes/src/gfxXlibNativeRenderer.cpp
  • All callers of gfxXlibNativeRenderer
    • widget/src/gtk2/nsNativeThemeGTK.cpp
    • layout/generic/nsObjectFrame.cpp

Proposed Porting Approach

  • gfxXlibNativeRenderer will be cloned to gfxGdkNativeRenderer
    • GdkDrawable will replace (Display, Visual, Drawable) touple
  • All the users of gfxXlibNativeRenderer will use gfxGdkNativeRenderer
  • Getting GdkDrawable from cairo surface
    • A new static const field will be added to gfxASurface class
      • static const cairo_user_data_key_t backendRenderingContext;
    • During the surface creation time, gfxGdkCairoSurface.cpp will store the GdkDrawable as user data in cairo surface
      • SetData (&gfxASurface::backendRenderingContext, (void *) mDrawable, nsnull);
    • Draw function in gfxGdknativeRenderer.cpp will obtain the GdkDrawable by calling GetData() function
      • (GdkDrawable *) ctx->OriginalSurface()->GetData(&gfxASurface::backendRenderingContext);
  • cairo-xlib-utils.c and cairo-xlib-utils.h will be taken out from the build
  • cairo_draw_with_xlib call in Draw function inside gfxGdkNativeRenderer.cpp will be replaced with the following code snippet.
   double device_offset_x, device_offset_y;
   short offset_x = 0, offset_y = 0;
   cairo_surface_t * target = cairo_get_target (cr);
   cairo_matrix_t matrix;
   cairo_surface_get_device_offset (target, &device_offset_x, &device_offset_y);
   cairo_get_matrix (cr, &matrix);
   _convert_coord_to_short (matrix.x0 + device_offset_x, &offset_x);
   _convert_coord_to_short (matrix.y0 + device_offset_y, &offset_y);
   cairo_surface_flush (target);
   NativeDraw ((GdkDrawable *) ctx->OriginalSurface()->GetData(&gfxASurface::backendRenderingContext),
           offset_x, offset_y, NULL, 0);
   cairo_surface_mark_dirty (target);

TODO

In the current proposal we are ignoring cairo_draw_with_xlib; i.e., it will be disabled in the beginning phases of the porting. After the basic functionality is working on DFB, then we will work on this. Meanwhile, any input to port cairo_draw_with_xlib to GDK will be greatly appreciated.

Previous Work

GTK-DFB Package Installation

Using script

Note: This has been tested on Fedora Core 8 and a Mandrake 9.1.

  • Download and unpack Install-gtk-cross-20081106.tar.zip ( or this previous version Install_gtk_101708.zip doesn't support --html option and not optimized to cross compilation)
  • Edit your install.sh or install-cross.sh to adjust parameters to your needs. You can use the --html option to check what will be executed by the script before installation.
  • When you are ready, suppress the --html option in install.sh then run it, that downloads all source packages and patchs, applies cairo and gtk patches, builds and installs. If you want to change parametrers, try install_gtk.py --help for usage instructions then modify install.sh
  • Copy this .directfbrc to ~/.directfbrc then edit it to ajust parameters to your needs

Note: Installation might fail if the packages are not available from the download link mentioned in config.py.

Manual Installation

We are going to install under /usr/local/dfb to avoid confusion when X and DFB apps are running simultaneously.

Create installation directories under /usr/local/dfb:

  • mkdir /usr/local/dfb
  • mkdir -p /usr/local/dfb/man/man1
  • mkdir /usr/local/dfb/bin
  • mkdir /usr/local/dfb/lib
  • mkdir /usr/local/dfb/etc
  • mkdir /usr/local/dfb/include
  • mkdir /usr/local/dfb/info
  • mkdir /usr/local/dfb/sbin
  • mkdir /usr/local/dfb/share
  • mkdir /usr/local/dfb/src

Set the following environment variables in the build terminal

  • export LD_LIBRARY_PATH=/usr/local/dfb/lib
  • export PATH=/usr/local/dfb/bin/:$PATH
  • export PKG_CONFIG=/usr/local/dfb/bin/pkg-config
  • export PKG_CONFIG_PATH=/usr/local/dfb/lib/pkgconfig
  • export CPPFLAGS=-I/usr/local/dfb/include
  • export LDFLAGS=-L/usr/local/dfb/lib

jpeg

tiff

zlib

libpng

pkg-config

gettext

Note: This package might not be required.

glib

atk

freetype

DirectFB

After installing DirectFB, set it up to run over SDL on X11.

  • Create .directfbrc under home directory.
  • Add following lines to .directfbrc
    • wm=default
    • mode=800x600
    • depth=32
    • system=sdl
  • As root user, run the following command
    • touch /usr/local/dfb/lib/libgdk-x11-2.0.so.0

libexpat

fontconfig

  • Package Name: fontconfig-2.4.91.tar.gz
  • Download URL: http://www.fontconfig.org/release/fontconfig-2.4.91.tar.gz
  • Installation:
    • tar zxvf fontconfig-2.4.91.tar.gz
    • cd fontconfig-2.4.91
    • ./configure --prefix=/usr/local/dfb --without-x --enable-directfb --disable-xlib --disable-win32
    • make
    • make install

pixman

cairo

pango

gtk

libIDL

Test

  • Existing examples
    • Try running test applications under gtk+-2.12.9/tests directory
  • New Examples
    • Setup pkg-config and library paths
      • export LD_LIBRARY_PATH=/usr/local/dfb/lib
      • export PKG_CONFIG_PATH=/usr/local/dfb/lib/pkgconfig
    • Write a “Hello world” GTK application: hello_world.c and compile it
      • gcc `pkg-config --cflags --libs gtk+-2.0` hello_world.c –o hello_world
    • Run hello_world
      • A DirectFB window with hello_world widget inside should pop-up

Building and testing Firefox-DFB

Getting mozilla-dfb sources from hg

Build mozilla-dfb

  • Copy this .mozconfig to mozilla-dfb-src/.mozconfig
  • set LD_LIBRARY_PATH and PKG_CONFIG_PATH to installed gtk-dfb packages
  • make -f client.mk build in the mozilla-dfb-src directory

Issues

Bugs

A good bug search term is [dfb].

As of November 2010, all these bugs were marked fixed in 2008 or 2009.

  • Port Mozilla to Gtk-DirectFB : bug 422221
  • Some parts of content area not painted when scrolled : bug 435471
  • Toolbar icons disappear randomly when other toolbar buttons are clicked : bug 435492
  • Entire browser flickers when mouse is hovered over a toolbar menu popup : bug 435494
  • Menu items are not selectable using mouse in toolbar menu popup : bug 435499

Comments

A "how to report a bug" section is needed.