Languages

Menu
Sites
Language
SDL_Surface on screen

Hi,

I'm trying to port a Nintendo GameBoy emulator, written in C, to Tizen. The emulator uses SDL. So I ported it and managed to get it running. 

Now I want to control the position of the emulator window through the Tizen app, instead of depending on the SDL library. How can I make the SDL_Surface objects generated by the emulator render on screen using Tizen APIs, preferrably in a box like container that can be positioned on screen easily?

Responses

3 Replies
Jean Yang

To porting your SDL surface game to Tizen, you need to read following documents:

The Tizen Buffer Manager (TBM) surface provides functions for the graphic buffer in Tizen.

https://developer.tizen.org/development/guides/native-application/graphics/tbm-surface-0

 

OpenGL ES is a standard specification defining a cross-language, cross-platform OpenGL ES API for writing applications that produce 2D and 3D computer graphics. OpenGL ES 1.1 and 2.0 are supported in Tizen 2.3. (OpenGL ES 3.0 will be supported in the next Tizen version.)

https://developer.tizen.org/development/guides/native-application/graphics/opengl-es-0

 

Evas Cairo is the connection between the Cairo buffer and the Evas buffer. An external library is the Cairo API. It is one of the most famous open source libraries for 2D graphics. Evas and EFL already have most of Cairo features, but if you want to display Bezier curves on screen it is advisable to use Cairo.

https://developer.tizen.org/development/guides/native-application/graphics/cairo-integration

pius lee

When I make animation with Cairo Surface, I had used ecore_animator_add() and evas_object_image_data_set().

typedef struct appdata {                                                           
    Ecore_Animator* animator;                                                      
    cairo_surface_t *surface;                                                      
    Evas_Object *graph;                                                            
    /* other properties... */                                                   
} appdata_s;                                                                       
                                                                                   
Eina_Bool on_anim(void* data)                                                      
{                                                                                  
    appdata_s *ad = data;                                                          
                                                                                   
    cairo_t *cr = cairo_create(ad->surface);                                       
                                                                                
    // do painting with cairo in here                                              
                                                                                   
    unsigned char* pixels = cairo_image_surface_get_data(ad->surface);             
    evas_object_image_data_set(ad->graph, pixels);                                 
    evas_object_image_data_update_add(ad->graph, 0, 0, GRAPH_WIDTH, GRAPH_HEIGHT);
                                                                                   
    cairo_destroy(cr);                                                             
                                                                                
    return EINA_TRUE;                                                           
}                                                                                  
                                                                                   
/* ad is only instance of appdata_s */                                          
ad->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, GRAPH_WIDTH, GRAPH_HEIGHT);
ecore_animator_add(on_anim, ad);                                                   

And according to following url 

http://cairographics.org/SDL/

SDL_Surface can be convert with cairo_srface_t

So I think following source could work.

typedef struct appdata {                                                           
    Ecore_Animator* animator;                                                      
    cairo_surface_t *surface;                                                      
    Evas_Object *graph;                                                            
    /* other properties... */                                                   
} appdata_s;                                                                       
                                                                                   
Eina_Bool on_anim(void* data)                                                      
{                                                                                  
    appdata_s *ad = data;                                                          
                                                                                   
    unsigned char* pixels = cairo_image_surface_get_data(ad->surface);             
    evas_object_image_data_set(ad->graph, pixels);                                 
    evas_object_image_data_update_add(ad->graph, 0, 0, GRAPH_WIDTH, GRAPH_HEIGHT);
                                                                                
    return EINA_TRUE;                                                           
}                                                                                  
                                                                                
SDL_Surface *sdlsurf = SDL_CreateRGBSurface (                                   
        flags, width, height, 32,                                               
        0x00FF0000, /* Rmask */                                                 
        0x0000FF00, /* Gmask */                                                 
        0x000000FF, /* Bmask */                                                 
        0); /* Amask */                                                         
                                                                                
/* Do Somthing with SDL_Surface */                                              
                                                                                
ad->surface = cairo_image_surface_create_for_data (                             
        sdlsurf->pixels,                                                        
        CAIRO_FORMAT_RGB24,                                                     
        sdlsurf->w,                                                             
        sdlsurf->h,                                                             
        sdlsurf->pitch);                                                        
                                                                                   
/* ad is only instance of appdata_s */                                          
ecore_animator_add(on_anim, ad);                                                   

 

I don't test it because I didn't have ported SDL yet. Anyway I think it will be work.

HM Mehrab

Cairo is not working for me. I tried the Temperature Graph from the Cairo tutorial section. I get a blank screen whenever I run the app. However, when I write the Cairo surface to a PNG file, instead of displaying it on screen with evas_object_image_data_update_add(), I do get the temperature graph correctly.