#include #include #include #include #include #include #include #include #include #include #include static int find_rgb_format(gf_layer_t layer); int main() { //device & display gf_dev_t gdev; gf_dev_info_t gdev_info; gf_display_t display; gf_display_info_t display_info; int i; //layer gf_layer_t layer; //surface gf_surface_t surface; unsigned height; unsigned width; gf_layer_info_t layer_info; //context gf_context_t context; if (gf_dev_attach(&gdev, GF_DEVICE_INDEX(0), &gdev_info) != GF_ERR_OK) { printf("gf_dev_attach() failed\n"); perror( "gf_dev_attach()" ); return (-1); } printf("Number of displays: %d\n",gdev_info.ndisplays); for (i = 0; i < gdev_info.ndisplays; i++) { printf("Display %d: ", i); if (gf_display_attach(&display, gdev, i, &display_info) == GF_ERR_OK) { printf("%dX%d, refresh = %dHz\n", display_info.xres, display_info.yres, display_info.refresh); printf("Number of layers: %d\n", display_info.nlayers); } else { printf("gf_display_attach() failed\n"); perror( "gf_display_attach()" ); gf_dev_detach(gdev); } } if (display != NULL) { // if (gf_layer_attach(&layer,display,display_info.main_layer_index, 0) == GF_ERR_OK) { if(gf_layer_attach(&layer,display,2, 0) == GF_ERR_OK) { printf("Attaching to Layer : 2\n "); } else { printf("gf_layer_attach() failed\n"); gf_dev_detach( gdev ); return (-1); } } int ret_format = find_rgb_format(layer); printf("Format returned by find_rgb_format = %d\n",ret_format); /* Create and set surfaces In this snippet, the application creates a surface for the layer attached in the previous step using gf_surface_create_layer(). This surface has the same dimensions as the display (the xres and yres members of display_info), and the same format (which you can retrieve from an attached layer using gf_layer_query(), and by inspecting the format member of the information structure). The surface is then displayed on the layer using gf_layer_set_surfaces(). */ //int gf_layer_query( gf_layer_t layer,int format_index,gf_layer_info_t *info ); if((gf_layer_query(layer,0,&layer_info))==GF_ERR_OK){ printf("Layer is of Format %d\n",layer_info.format); } else{ printf(" gf_layer_query() failed"); return (-1); } width = display_info.xres; height = display_info.yres; if (gf_surface_create_layer(&surface, &layer, 1, 0, width, height, layer_info.format, NULL, 0) == GF_ERR_OK) { printf("Succesfully created surface on top of layer\n"); gf_layer_set_surfaces(layer, &surface, 1); /* draw stuff here */ } else { printf("gf_surface_create_layer() failed\n"); return (-1); } /* Once you've created a surface, you can fill in a gf_surface_info structure with the surface information (most importantly, the surface ID), using gf_surface_get_info(). */ /* Create a draw context The final step is to create a draw context, and set a previously created surface for the context. */ if (gf_context_create(&context) != GF_ERR_OK) { fprintf(stderr, "gf_context_create failed\n"); return -1; } else{ printf(" Created the context succefully\n"); } //if (gf_context_set_surface(context, surface[cursurf]) != GF_ERR_OK) { if (gf_context_set_surface(context,surface)!= GF_ERR_OK) { fprintf(stderr, "gf_context_set_surface failed\n"); return -1; } else{ printf("Context Surface is Set Succesfully\n"); } gf_draw_begin(context); /* gf_context_set_fgcolor(context,0xFFFFFF); gf_draw_rect(context,50,50,100,100); gf_context_set_fgcolor(context,0x000000); gf_draw_rect(context,40,40,120,120); */ gf_context_set_fgcolor( context, 0xFFffFF ); gf_context_set_bgcolor( context, 0xFFffFF ); gf_context_set_penwidth(context, 1 ); gf_draw_rect( context, 0, 0, width-1, height-1 ); gf_draw_flush(context ); gf_draw_end(context); /* uint8_t pattern[]={ 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f }; unsigned short rop = GF_ROP_PDSnaon; gf_context_set_fgcolor(context, 0xff0000); gf_context_set_bgcolor(context, 0x0000ff); gf_context_set_pattern(context,pattern,0,0,GF_CONTEXT_PATTERN_BACKFILL); gf_context_set_rop(context, rop); gf_draw_rect (context,50,50,200,200 ); gf_draw_flush(context); gf_draw_end(context); */ gf_layer_update( layer, 0 ); //sleep(10); printf( "Press ENTER to continue\n" ); getchar(); /* uint8_t pattern[]={ 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f }; unsigned short rop = GF_ROP_PDSnaon; gf_context_set_fgcolor(context, 0xff0000); gf_context_set_bgcolor(context, 0x0000ff); gf_context_set_pattern(context,pattern,0,0,GF_CONTEXT_PATTERN_BACKFILL); gf_context_set_rop(context, rop); gf_draw_rect (context,50,50,200,200 ); gf_draw_flush(context); gf_draw_end(context); */ gf_dev_detach(gdev); return 0; } static int find_rgb_format(gf_layer_t layer) { gf_layer_info_t info; int i; for (i = 0; gf_layer_query(layer, i, &info) == GF_ERR_OK; ++i) { switch (info.format) { case GF_FORMAT_PKLE_ARGB1555: case GF_FORMAT_PKLE_RGB565: case GF_FORMAT_BGR888: case GF_FORMAT_BGRA8888: return info.format; default: continue; } } return -1; }