/*! \internal Creates a new hardware surface (usually on the Gfx card memory) with the dimensions \a w * \a h. */ static inline bool createHwSurface(QQnxScreenContext * const d, int w, int h) { int ret = gf_surface_create_layer(&d->hwSurface, &d->layer, 1, 0, w, h, d->displayInfo.format, 0, 0); if (ret != GF_ERR_OK) { qWarning("QQnxScreen: gf_surface_create_layer(%dx%d) failed with error code %d", w, h, ret); return false; } gf_layer_set_surfaces(d->layer, &d->hwSurface, 1); gf_layer_enable(d->layer); ret = gf_layer_update(d->layer, 0); if (ret != GF_ERR_OK) { qWarning("QQnxScreen: gf_layer_update() failed with error code %d\n", ret); return false; } ret = gf_context_create(&d->context); if (ret != GF_ERR_OK) { qWarning("QQnxScreen: gf_context_create() failed with error code %d", ret); return false; } ret = gf_context_set_surface(d->context, d->hwSurface); if (ret != GF_ERR_OK) { qWarning("QQnxScreen: gf_context_set_surface() failed with error code %d", ret); return false; } return true; }
/*! \internal Creates a new hardware surface (usually on the Gfx card memory) with the dimensions \a w * \a h. */ static bool createHwSurface(QQnxScreenContext * const d, int w, int h) { int ret = gf_surface_create_layer(&d->hwSurface, &d->layer, 1, 0, w, h, GF_FORMAT_ARGB8888, 0, 0); if (ret != GF_ERR_OK) { qWarning("QQnxScreen: gf_surface_create_layer(%dx%d) failed with error code %d", w, h, ret); return false; } gf_layer_set_surfaces(d->layer, &d->hwSurface, 1); ret = gf_layer_update(d->layer, 0); if (ret != GF_ERR_OK) { qWarning("QQnxScreen: gf_layer_update() failed with error code %d\n", ret); return false; } return true; }
static SDL_Renderer* gf_createrenderer(SDL_Window* window, Uint32 flags) { SDL_VideoDisplay* display = SDL_GetDisplayFromWindow(window); SDL_DisplayData* didata = (SDL_DisplayData*)display->driverdata; SDL_WindowData* wdata = (SDL_WindowData*)window->driverdata; SDL_Renderer* renderer = NULL; SDL_RenderData* rdata = NULL; uint32_t it; int32_t jt; int32_t status; /* Check if it is OpenGL ES window */ if ((window->flags & SDL_WINDOW_OPENGL)==SDL_WINDOW_OPENGL) { /* No error, just no need to create 2D renderer for OpenGL ES window */ return NULL; } /* Allocate new renderer structure */ renderer=(SDL_Renderer*)SDL_calloc(1, sizeof(SDL_Renderer)); if (renderer==NULL) { SDL_OutOfMemory(); return NULL; } /* Allocate renderer data */ rdata=(SDL_RenderData*)SDL_calloc(1, sizeof(SDL_RenderData)); if (rdata==NULL) { SDL_free(renderer); SDL_OutOfMemory(); return NULL; } renderer->DisplayModeChanged=gf_displaymodechanged; renderer->ActivateRenderer=gf_activaterenderer; renderer->CreateTexture=gf_createtexture; renderer->QueryTexturePixels=gf_querytexturepixels; renderer->SetTexturePalette=gf_settexturepalette; renderer->GetTexturePalette=gf_gettexturepalette; renderer->SetTextureAlphaMod=gf_settexturealphamod; renderer->SetTextureColorMod=gf_settexturecolormod; renderer->SetTextureBlendMode=gf_settextureblendmode; renderer->SetTextureScaleMode=gf_settexturescalemode; renderer->UpdateTexture=gf_updatetexture; renderer->LockTexture=gf_locktexture; renderer->UnlockTexture=gf_unlocktexture; renderer->DirtyTexture=gf_dirtytexture; renderer->RenderPoint=gf_renderpoint; renderer->RenderLine=gf_renderline; renderer->RenderFill=gf_renderfill; renderer->RenderCopy=gf_rendercopy; renderer->RenderPresent = gf_renderpresent; renderer->DestroyTexture = gf_destroytexture; renderer->DestroyRenderer = gf_destroyrenderer; renderer->info = gf_renderdriver.info; renderer->window = window->id; renderer->driverdata = rdata; /* Set render acceleration flag in case it is accelerated */ if ((didata->caps & SDL_GF_ACCELERATED)==SDL_GF_ACCELERATED) { renderer->info.flags=SDL_RENDERER_ACCELERATED; } else { renderer->info.flags&=~(SDL_RENDERER_ACCELERATED); } rdata->window=window; /* Check if upper level requested synchronization on vsync signal */ if ((flags & SDL_RENDERER_PRESENTVSYNC)==SDL_RENDERER_PRESENTVSYNC) { rdata->enable_vsync=SDL_TRUE; } else { rdata->enable_vsync=SDL_FALSE; } /* Check what buffer copy/flip scheme is requested */ rdata->surfaces_count=0; if ((flags & SDL_RENDERER_SINGLEBUFFER)==SDL_RENDERER_SINGLEBUFFER) { if ((flags & SDL_RENDERER_PRESENTDISCARD)==SDL_RENDERER_PRESENTDISCARD) { renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD; } else { renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY; } rdata->surfaces_count=1; rdata->surface_visible_idx=0; rdata->surface_render_idx=0; } else { if ((flags & SDL_RENDERER_PRESENTFLIP2)==SDL_RENDERER_PRESENTFLIP2) { renderer->info.flags|=SDL_RENDERER_PRESENTFLIP2; rdata->surfaces_count=2; rdata->surface_visible_idx=0; rdata->surface_render_idx=1; } else { if ((flags & SDL_RENDERER_PRESENTFLIP3)==SDL_RENDERER_PRESENTFLIP3) { renderer->info.flags|=SDL_RENDERER_PRESENTFLIP3; rdata->surfaces_count=3; rdata->surface_visible_idx=0; rdata->surface_render_idx=1; } else { renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY; rdata->surfaces_count=1; rdata->surface_visible_idx=0; rdata->surface_render_idx=0; } } } /* Create layer surfaces, which could be visible */ for (it=0; it<rdata->surfaces_count; it++) { /* TODO: add palette creation */ /* Create displayable surfaces */ status=gf_surface_create_layer(&rdata->surface[it], &didata->layer, 1, 0, didata->current_mode.w, didata->current_mode.h, qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format), NULL, GF_SURFACE_CREATE_2D_ACCESSIBLE); if (status!=GF_ERR_OK) { /* Free already allocated surfaces */ for (jt=it-1; jt>0; jt--) { gf_surface_free(rdata->surface[jt]); rdata->surface[jt]=NULL; } SDL_free(rdata); SDL_free(renderer); if (status==GF_ERR_MEM) { SDL_SetError("unsufficient free video memory"); } else { SDL_SetError("error during displayable surface creation"); } return NULL; } /* Get detailed information about allocated surface */ gf_surface_get_info(rdata->surface[it], &rdata->surface_info[it]); } return renderer; }
int gf_setup(gf_setup_t *setup, int argc, char * const argv[], unsigned flags) { gf_dev_t gdev; unsigned dispno = 0; const char *dev_name = NULL; int layer_idx = GF_SETUP_LAYER_MAIN, rc, verbose = 0; gf_sid_t sid = GF_SID_INVALID; unsigned vx1 = 0, vx2 = ~0, vy1 = 0, vy2 = ~0; memset(setup, 0, sizeof *setup); setup->fname = strdup("tt0419m_.ttf"); #ifdef _MSC_VER #else opterr = 0; while ((rc = getopt(argc, argv, "d:D:l:s:vx:y:f:")) != -1) { switch (rc) { case 'd': if (isdigit(*optarg)) { dev_name = GF_DEVICE_INDEX(atoi(optarg)); } else { dev_name = optarg; } break; case 'D': dispno = atoi(optarg); break; case 'l': layer_idx = atoi(optarg); break; case 's': sid = (gf_sid_t)atoi(optarg); break; case 'v': verbose = ~0; break; case 'x': switch (*optarg++) { case '1': vx1 = atoi(optarg); break; case '2': vx2 = atoi(optarg); break; default: break; } break; case 'y': switch (*optarg++) { case '1': vy1 = atoi(optarg); break; case '2': vy2 = atoi(optarg); break; default: break; } break; case 'f': setup->fname = strdup(optarg); break; default: break; } } #endif if ((rc = gf_dev_attach(&gdev, dev_name, NULL)) == GF_ERR_OK) { if (sid != GF_SID_INVALID) { gf_surface_t surface; if ((rc = gf_surface_attach_by_sid(&surface, gdev, sid)) == GF_ERR_OK) { gf_context_t context; if ((rc = gf_context_create(&context)) == GF_ERR_OK) { if ((rc = gf_context_set_surface(context, surface)) == GF_ERR_OK) { gf_surface_info_t sinfo; gf_surface_get_info(surface, &sinfo); --sinfo.w; --sinfo.h; if (vx2 > sinfo.w) { vx2 = sinfo.w; } if (vy2 > sinfo.h) { vy2 = sinfo.h; } if (vx1 <= vx2 && vy1 <= vy2 && (vx1 || vy1 || vx2 < sinfo.w || vy2 < sinfo.h)) { gf_context_set_clipping(context, vx1, vy1, vx2, vy2); setup->x1 = vx1; setup->x2 = vx2; setup->y1 = vy1; setup->y2 = vy2; } setup->surface1 = surface; setup->context = context; setup->gdev = gdev; return GF_ERR_OK; } gf_context_free(context); } gf_surface_free(surface); } } else { gf_display_t display; gf_display_info_t dinfo; if ((rc = gf_display_attach(&display, gdev, dispno, &dinfo)) == GF_ERR_OK) { gf_layer_t layer; if (verbose) { fprintf(stderr, "Display %d:\n\tResolution: %dX%d\n", dispno, dinfo.xres, dinfo.yres); fprintf(stderr, "\tRefresh rate: %d\n\tPixel format: ", dinfo.refresh); switch (dinfo.format) { case GF_FORMAT_PAL8: fprintf(stderr, "PAL8"); break; case GF_FORMAT_PACK_ARGB1555: fprintf(stderr, "ARGB1555"); break; case GF_FORMAT_PACK_RGB565: fprintf(stderr, "RGB565"); break; case GF_FORMAT_BGR888: fprintf(stderr, "BGR888"); break; case GF_FORMAT_BGRA8888: fprintf(stderr, "BGRA8888"); break; default: fprintf(stderr, "%x", (unsigned)dinfo.format); break; } fprintf(stderr, "\n\tNumber of layers: %d\n", dinfo.nlayers); fprintf(stderr, "\tMain layer index: %d\n", dinfo.main_layer_index); } if ((rc = gf_layer_attach(&layer, display, layer_idx == GF_SETUP_LAYER_MAIN ? dinfo.main_layer_index : layer_idx, 0)) == GF_ERR_OK) { gf_surface_t surface1, surface2 = NULL; int layer_format; layer_format = find_rgb_format(layer); if(verbose && layer_format != dinfo.format) { fprintf(stderr, "\tChoosing non-default layer format: "); switch (layer_format) { case GF_FORMAT_PAL8: fprintf(stderr, "PAL8"); break; case GF_FORMAT_PACK_ARGB1555: fprintf(stderr, "ARGB1555"); break; case GF_FORMAT_PACK_RGB565: fprintf(stderr, "RGB565"); break; case GF_FORMAT_BGR888: fprintf(stderr, "BGR888"); break; case GF_FORMAT_BGRA8888: fprintf(stderr, "BGRA8888"); break; default: fprintf(stderr, "%x", (unsigned)layer_format); break; } fprintf(stderr, "\n"); } dinfo.format = layer_format; if ((rc = gf_surface_create_layer(&surface1, &layer, 1, 0, dinfo.xres, dinfo.yres, dinfo.format, NULL, 0)) == GF_ERR_OK && (!(flags & GF_SETUP_FLAG_DBLBUFFER) || (rc = gf_surface_create_layer(&surface2, &layer, 1, 0, dinfo.xres, dinfo.yres, dinfo.format, NULL, 0)) == GF_ERR_OK)) { if (verbose) { gf_surface_info_t sinfo; gf_surface_get_info(surface1, &sinfo); fprintf(stderr, "Surface:\n\tSID = %d\n", (unsigned)sinfo.sid); fprintf(stderr, "\tFlags = %x\n", sinfo.flags); } gf_layer_set_surfaces(layer, &surface1, 1); if ((rc = gf_layer_update(layer, 0)) == GF_ERR_OK) { gf_context_t context = NULL; if ((flags & GF_SETUP_FLAG_NOCONTEXT) || ((rc = gf_context_create(&context)) == GF_ERR_OK && (rc = gf_context_set_surface(context, surface1)) == GF_ERR_OK)) { setup->gdev = gdev; setup->display = display; memcpy(&setup->display_info, &dinfo, sizeof dinfo); setup->layer = layer; setup->surface1 = surface1; setup->surface2 = surface2; setup->context = context; return GF_ERR_OK; } if (context != NULL) { gf_context_free(context); } } } } } } gf_dev_detach(gdev); } return rc; }
/* * Function : Framebuffer Driver Initializer * */ byte QNXGF_init(LIBAROMA_FBP me) { /* Allocating Internal Data */ ALOGV("QNXGF Initialized Internal Data"); QNXGF_INTERNALP mi = (QNXGF_INTERNALP) calloc(sizeof(QNXGF_INTERNAL),1); if (!mi) { ALOGE("QNXGF malloc internal data - Memory Error"); return 0; } libaroma_mutex_init(___qnxfbmutex); /* Set Internal Address */ me->internal = (voidp) mi; me->release = &QNXGF_release; me->double_buffer = 0; // 1; /************************* Init of Init QNX GF ******************************/ /* Device Attach */ if (gf_dev_attach( &mi->gdev, GF_DEVICE_INDEX(0), &mi->gdev_info ) != GF_ERR_OK) { ALOGE("QNXGF gf_dev_attach failed"); goto error; } /* Display Attach */ if (gf_display_attach( &mi->display, mi->gdev, 0, &mi->display_info ) != GF_ERR_OK) { ALOGE("QNXGF gf_display_attach failed"); gf_dev_detach(mi->gdev); goto error; } /* Layer Attach */ if (gf_layer_attach( &mi->layer, mi->display, 0, 0 ) != GF_ERR_OK) { ALOGE("QNXGF gf_layer_attach failed"); gf_display_detach(mi->display); gf_dev_detach(mi->gdev); goto error; } /* Create Surface */ if (gf_surface_create_layer( &mi->surface, &mi->layer, 1, 0, mi->display_info.xres, mi->display_info.yres, GF_FORMAT_PKLE_RGB565, NULL, 0 ) != GF_ERR_OK) { ALOGE("QNXGF gf_surface_create_layer failed"); gf_layer_detach(mi->layer); gf_display_detach(mi->display); gf_dev_detach(mi->gdev); goto error; } /* Set Surface */ gf_layer_set_surfaces(mi->layer, &mi->surface, 1); /* Create Context */ if (gf_context_create(&mi->context) != GF_ERR_OK) { ALOGE("QNXGF gf_context_create failed"); gf_surface_free(mi->surface); gf_layer_detach(mi->layer); gf_display_detach(mi->display); gf_dev_detach(mi->gdev); goto error; } /* Context Set Layer */ if (gf_context_set_surface(mi->context, mi->surface) != GF_ERR_OK) { ALOGE("QNXGF gf_context_set_surface failed"); gf_context_free(mi->context); gf_surface_free(mi->surface); gf_layer_detach(mi->layer); gf_display_detach(mi->display); gf_dev_detach(mi->gdev); goto error; } /* if (gf_display_set_dpms(mi->display,GF_DPMS_ON) != GF_ERR_OK) { ALOGI("QNXGF gf_display_set_dpms failed"); } else{ ALOGI("QNXGF gf_display_set_dpms OK"); } */ /************************* End of Init QNX GF *******************************/ /* Set AROMA Core Framebuffer Instance Values */ me->w = mi->display_info.xres; /* Width */ me->h = mi->display_info.yres; /* Height */ me->sz = me->w * me->h; /* Width x Height */ /* Set Callbacks */ me->start_post = &QNXGF_start_post; me->post = &QNXGF_post; me->end_post = &QNXGF_end_post; me->snapshoot = NULL; /* DUMP INFO */ QNXGF_dump(mi); /* Fixed DPI */ me->dpi = 160; /* OK */ goto ok; /* Return */ error: free(mi); return 0; ok: return 1; }