10
DirectFB Overview (v0.1) Andreas Hundt [email protected] September 11, 2001 Abstract This document discusses features and concepts of DirectFB. It is work in progress. Contents 1 Introduction 2 1.1 Goals ................................ 2 1.2 Features ............................... 2 1.2.1 Graphic Operations ..................... 2 1.2.2 Windowing System ..................... 3 1.2.3 Resource Management ................... 3 1.2.4 Graphic Drivers ....................... 3 1.2.5 Input Drivers ........................ 3 1.2.6 Image Loading ....................... 4 1.2.7 Video Playback ....................... 4 1.2.8 Font Rendering ....................... 4 2 DirectFB architecture 5 2.1 Access to the graphics hardware by DirectFB ........... 5 2.2 Access to input devices by DirectFB ................ 5 2.3 Important terms used by DirectFB ................. 5 2.3.1 Blitting ........................... 5 2.3.2 Surface ........................... 6 2.3.3 SubSurface ......................... 6 2.3.4 Layer ............................ 6 2.3.5 Window / Windowstack .................. 7 2.4 Example of a Layer/Window configuration ............. 7 3 DirectFB API Concept 8 3.1 The DirectFB Super Interface .................... 8 3.2 Interface Diagram .......................... 8 3.3 Loadable Modules ......................... 8 3.4 Example code ............................ 9 1

DirectFB Overview (v0.1) -

  • Upload
    others

  • View
    24

  • Download
    0

Embed Size (px)

Citation preview

Page 1: DirectFB Overview (v0.1) -

DirectFBOverview (v0.1)

AndreasHundt � [email protected]

September11,2001

Abstract

Thisdocumentdiscussesfeaturesandconceptsof DirectFB.It is work inprogress.

Contents

1 Intr oduction 21.1 Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.2 Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.2.1 GraphicOperations. . . . . . . . . . . . . . . . . . . . . 21.2.2 Windowing System. . . . . . . . . . . . . . . . . . . . . 31.2.3 ResourceManagement. . . . . . . . . . . . . . . . . . . 31.2.4 GraphicDrivers. . . . . . . . . . . . . . . . . . . . . . . 31.2.5 Input Drivers . . . . . . . . . . . . . . . . . . . . . . . . 31.2.6 ImageLoading . . . . . . . . . . . . . . . . . . . . . . . 41.2.7 VideoPlayback. . . . . . . . . . . . . . . . . . . . . . . 41.2.8 FontRendering. . . . . . . . . . . . . . . . . . . . . . . 4

2 Dir ectFB architecture 52.1 Accessto thegraphicshardwareby DirectFB . . . . . . . . . . . 52.2 Accessto input devicesby DirectFB . . . . . . . . . . . . . . . . 52.3 Importanttermsusedby DirectFB . . . . . . . . . . . . . . . . . 5

2.3.1 Blitting . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.3.2 Surface . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.3.3 SubSurface . . . . . . . . . . . . . . . . . . . . . . . . . 62.3.4 Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.3.5 Window / Windowstack . . . . . . . . . . . . . . . . . . 7

2.4 Exampleof aLayer/Window configuration. . . . . . . . . . . . . 7

3 Dir ectFB API Concept 83.1 TheDirectFBSuperInterface. . . . . . . . . . . . . . . . . . . . 83.2 InterfaceDiagram. . . . . . . . . . . . . . . . . . . . . . . . . . 83.3 LoadableModules . . . . . . . . . . . . . . . . . . . . . . . . . 83.4 Examplecode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

1

Page 2: DirectFB Overview (v0.1) -

1 Intr oduction

DirectFB is a thin library that provides hardware graphicsacceleration,inputdevice handlingand abstraction,integratedwindowing systemwith supportfortranslucentwindows andmultiple displaylayerson top of theLinux FramebufferDevice. It is a completehardwareabstractionlayerwith softwarefallbacksfor ev-ery graphicsoperationthatis not supportedby theunderlyinghardware.DirectFBwasdesignedwith embeddedsystemsin mind. It offersmaximumhardwareaccel-eratedperformanceataminimumof resourceusageandoverhead.

1.1 Goals� smallmemoryfootprint

� maximumpossiblehardwareacceleration

� supportof advancedgraphicsoperationsincudingmultiple alphablendingmodes

� no kernelmodifications,make useof existing standards

� no library dependencies(exceptlibc)

� meettherequirementsof MHP R�

1.2 Features

1.2.1 Graphic Operations

DirectFB supportsthe the following graphicsoperations.Thesecanbe doneinhardwareif supportedby thechipsetdriver, or assoftwarefallback:

� Rectanglefilling/drawing

� Trianglefilling/drawing

� Line drawing

� (Stretched)blitting

� Blendingwith analphachannel(a.k.a.texturealpha)

� Blendingwith aconstantalphablendfactor(a.k.a.alphamodulation)

� Nine differentblendingfunctionsrespectively for sourceanddestination,soall Porter/Duff rulesaresupported

� Colorizing(a.k.a.colormodulation)

� Sourcecolor keying

� Destinationcolor keying

2

Page 3: DirectFB Overview (v0.1) -

1.2.2 Windowing System

DirectFB hasa fast integratedwindowing system,that supportstranslucentwin-dows. Windows usingARGB Surfacescanbeblendedon perpixel basis.In addi-tion eachwindow hasits own globaltransparency.

1.2.3 ResourceManagement

DirectFBhasits own resourcemanagementfor videomemory. Resourceslikedis-play layersor input devicescanbelockedfor exclusive access,e.g. for fullscreengames.DirectFB provides abstractionfor the differentgraphicstargetslike dis-play layers,windows andany generalpurposesurfaces.Theprogrammingeffortfor switchingfrom windowed to fullscreenandbackis minimizedto settingthedesiredcooperative level.

1.2.4 Graphic Dri vers

For hardwareaccelerationDirectFB usesloadabledriver modules.Currectly thefollowing chipsetsaresupported:

� Matrox G200/G400/G450

� ATI Rage128

� 3dfx Voodoo3/Banshee

� igs CyberPro(not releasedto thepublic)

� S3Savage3/4series(not releasedto thepublic)

� NeoMagic

� nVidia TNT/Radeonseries

Otherchipsetswill work, but thereis noaccelerationsupport.

1.2.5 Input Dri vers

DirectFBsupportsthefollowing inputdevices:

� standardkeyboards

� serialandPS/2mice

� joysticks

� infraredremotecontrols(usinglirc)

It is possibleto querythehardwaredirectlyor to useaneventbuffer.

3

Page 4: DirectFB Overview (v0.1) -

1.2.6 ImageLoading

DirectFB includesimageproviders,which allow loadingof the following imageformatsdirectly into DirectFBsurfaces:

� JPEG(usinglibjpeg)

� PNG(usinglibpng2)

� GIF

1.2.7 VideoPlayback

DirectFB includesvideoproviders,which allow renderingof the following videoformatsinto DirectFBsurfaces:

� video4linux(/dev/video)

� mpeg1/2(usinglibmpeg3)

� AVI (usingavifile)

� macromediaflash(usinglibflash)

1.2.8 Font Rendering

DirectFB supportsanti aliasedtext drawing and includesfont providers, whichallow loadingof thefollwing font formats:

� DirectFBbitmapfont

� TrueType(usingFreeType2)

4

Page 5: DirectFB Overview (v0.1) -

2 Dir ectFB architecture

2.1 Accessto the graphicshardware by Dir ectFB

To accessthe graphicshardwareDirectFB relieson theexisting kernel interface,which theframebuffer device provides(/dev/fb). ThatmeansthatDirectFBneedsa working framebuffer driver to work. For somechipsetsthereis a specialframe-buffer driver in thelinux kernel.For unsupportedchipsetsa vesaframebuffer willalsowork (althoughwith somelimitations). No matterif graphicsaccelerationisusedor not, DirectFB will usethe framebuffer device to perform the followingtasks:

� settingup thevideomode(resolution,colordepth,timings)

� memorymappingof thecardstheframebuffer

� changingof theviewport of theframebuffer (for doublebuffering)

If a cardis supportedby DirectFBanda framebuffer driver for aspecialchipsetispresentin thelinux kernel,DirectFBwill usetheframebuffer device in additiontothetasksmentionedabove to do performthefollowing tasks:

� memorymappingof thecardsmemorymappedio ports

� turningoff theframebuffer driver’s internalacceleration

To executea specificgraphicsoperation(e.g. blitting of a surface),theDirectFBchipsetdriverwill accessthememorymappedio portsof thegraphicshardwaretosubmitthecommandto thecard’s accelerationengine.Thatmeansthat theactualhardwareaccelerationis doneentirelyfrom userspace.

Seefigure1 on page 6.

2.2 Accessto input devicesby Dir ectFB

To accessinputdevicesDirectFBusesthestandarddevice interfacesthatthelinuxkernelprovides.No input hardwareis accesseddirectly by DirectFB.

2.3 Important terms usedby Dir ectFB

2.3.1 Blitting

Blitting refersto theprocessof copying imagedata.Thesimplestexampleis to BlitaSurfacetoanotherwhilebothSurfaceshavethesamesize,depthandpixel format.In this casethememoryhasto be only copiedwithout beingprocessed(just likecopying any othertype of data). Advacedtypesof Blitting includeBlitting withanalphachannel,or Bliting from onepixel formatto another. Mostgraphicscardsincludeahardwareblitter thatis capableto performvariouskindsof Blitting.

5

Page 6: DirectFB Overview (v0.1) -

DirectFB Application

DirectFB API

chipsetdriver

framebuffer

linuxframebuffer driver

user space

kernel space

graphics hardwaretiming andmode registers

acceleration engine

= only applicable while using the framebuffer console,disabled while a DirectFB

application runs.

Figure1: Accessto the framebuffer device and the graphicshardwareby a Di-rectFBapplication

2.3.2 Surface

A Surfaceis a reserved areain memorywherepixel datafor oneimageis storedin a specificpixel format. A Surfacecanresidein video and/orsystemmemory.It is possibleto performdrawing operationson a surfaceor to Blit thesurfacetoanother(seesection1.2.1).

In fullscreenmode,thevisiblescreenis representedby the”PrimarySurface”,soit is possibleto performgraphicsoperationsdirectlyon thevisiblescreen.

EverySurfacecanoptionallyusedoublebuffering,graphicsoperationsarethenfirst executedon a secondarybuffer andbecomevalid after Flip() is called. Toprevent flickering it is advisedto useDoublebuffering on the primary Surfaceinmostcases.

2.3.3 SubSurface

A SubSurfaceusesthesameinterfaceasa regularSurface.It representsapartof aparentSurfaceanddoesnotallocateany systemor videomemoryitself.

2.3.4 Layer

Dependingon the graphicshardware, thereareone or more display Layers. AstandardPCgraphicscardhasonly oneLayer, but sophisticateddeviceslikeTV settop boxesmaysupporttwo or morelayers.Layersoccupy differentareasin videoram,andareusuallycombinedby usingalphablending.Thisin doneautomatically

6

Page 7: DirectFB Overview (v0.1) -

by thedisplayhardware.If thecontentof thelowestLayerchanges,norepainthasto bedoneandthecontentsof theabove layersremainuntouched.

2.3.5 Window / Windowstack

Normally thecontentsof a layer’s surfaceis controlledby theintegratedwindow-ing systemthatshows thewindows belongingto thelayeron a configurableback-ground.Eachwindow hasits own surfacethatis usedby thewindowing systemtoproducethecomposedimageof overlappingwindows. Alternatively applications,especiallygames,cangetexclusive accessto the layer. This way theapplicationhasdirectcontrolover thelayer’s surfaceandit’scontents,nowindowsareshown.

2.4 Exampleof a Layer/Window configuration

Figure2: ThelowerLayeris in fullscreenmode,abackgroundimagehasbeenren-deredto its primarySurface.Thevideoareais a SubSurfacewherea live videoisdisplayed.TheupperLayerusesaWindowstack,whereanapplicationhasopeneda Window. Thevideo is visible throughtheapplicationWindow, sincetheupperLayerusesaglobalalphavalue.

7

Page 8: DirectFB Overview (v0.1) -

3 Dir ectFB API Concept

TheDirectFBAPI is structuredusingInterfaces.An Interfaceis a C structurethatcontainsfunctionpointers.Dependingontheimplementationof theInterfacethesepointerspoint to differentcorefunctions. A goodexampleis IDirectFBSurface,which canrepresentthewholescreen,thecontentsof a Window or a SubSurface.TheapplicationusesthesameAPI andthesamecodecanbeusedin eachcase.

3.1 The Dir ectFBSuper Interface

IDirectFB is the SuperInterface,which is the only onethat canbe createdby aglobalfunction(DirectFBCreate()).All otherInterfacesarereachablethroughthisInterface. New Interfacescanbe createdby calling a function of the IDirectFBinterface(e.g. IDirectFBSurface). Existing interfaces(like interfacesto existinginput devices)canalsobeenumeratedandaccessedthoughIDirectFB.

3.2 Interface Diagram

«Super Interface»IDirectFB

IDirectFBDisplayLayer IDirectFBSurface IDirectFBInputDevice

IDirectFBWindow IDirectFBInputBuffer

Create

GetGet

Create

Get

Get Create

Create

IDirectFBImageProvider

IDirectFBFont

IDirectFBVideoProvider

Figure3: TherelationshipbetweenDirectFBInterfaces

3.3 Loadable Modules

Thefollowing DirectFBInterfacesareimplementedasloadablemodules:

� IDirectFBImageProvider (see1.2.6for currentimplemtentations)

� IDirectFBVideoProvider (see1.2.7for currentimplementations)

� IDirectFBFont (see1.2.8for currentimplementations)

A specificimplementationof theseInterfacesis only loadedat run time if needed.For exampleif animageis loaded,theavailible implementationsof IDirectFBIm-ageProvider will beprobed.If the imageis a PNGimagetheProbe()functionof

8

Page 9: DirectFB Overview (v0.1) -

thePNG modulewill noticethat it canhandlethefile. Finding a suitableimple-mentationfor videoformatsworksthesameway.

� IDirectFBInputDevice (see1.2.5for currentimplementations)

� GfxCard(internalinterfaceonly, notaccessibleby applications,see1.2.4forsupportedcards)

Input andandgraphicscarddrivers are loadedduring initialization of DirectFBdependingon thehardwareconfigurationof thesystemDirectFBrunson.

It is possibleto implementandusenew graphicscarddrivers,inputdriversandmediaproviderswithoutchangingor recompilingDirectFB.

3.4 Examplecode

Thefollowing listing is a smallcompleteDirectFBprogramthatshows theusageof DirectFBInterfaces.It loadsanimageanddisplaysit.

#include <directfb.h>

/* DirectFB interfaces */IDirectFB *dfb;IDirectFBSurface *primary;IDirectFBImageProvider *provider;

/* describes size, pixel format and capabilities of a surface*/DFBSurfaceDescription dsc;

int main( int argc, char *argv[] ){

/* initalize DirectFB and pass arguments */DirectFBInit( &argc, &argv );

/* create the super interface */DirectFBCreate( &dfb );

/* set cooperative level to DFSCL_FULLSCREEN for exclusive access to theprimary layer */

dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );

/* get the primary surface, i.e. the surface of the primary layer we haveexclusive access to */

memset( &dsc, 0, sizeof(DFBSurfaceDescription) );dsc.flags = DSDESC_CAPS; /* only the caps field of the description is valid.

height, width and pixelformat are not set, sincethe resolution and pixel are determined by thecurrent video mode */

dsc.caps = DSCAPS_PRIMARY; /* we want the primary surface (the whole screen) */

/* Since we are in fullscreen mode no new surface will be created,the whole screen will be made accessible through a IDirectFBSurface */

dfb->CreateSurface( dfb, &dsc, &primary );

/* create the image provider that will load the image */dfb->CreateImageProvider( dfb, "tux.png", &provider );

/* render the image to the screen */

9

Page 10: DirectFB Overview (v0.1) -

provider->RenderTo( provider, primary );

/* release the image provider, it is no longer necessary */provider->Release( provider );

sleep (5);

/* clean up */primary->Release( primary );dfb->Release( dfb );

}

10