Пример #1
0
/*! \internal
  Attaches to the named device \a name.
*/
static bool attachDevice(QQnxScreenContext * const d, const char *name)
{
    int ret = gf_dev_attach(&d->device, name, &d->deviceInfo);
    if (ret != GF_ERR_OK) {
        qWarning("QQnxScreen: gf_dev_attach(%s) failed with error code %d", name, ret);
        return false;
    }
    return true;
}
Пример #2
0
int main(int argc, char** argv)
{
    gf_3d_target_t      target;
    gf_display_t        gf_disp;
    EGLConfig           config;
    EGLContext          econtext;
    EGLint              num_config;
    gf_dev_info_t       info;
    gf_layer_info_t     linfo;
    gf_display_info_t   disp_info;
    GLuint              width, height;
    GLuint              it;

    /* initialize the graphics device */
    if (gf_dev_attach(&gfdev, NULL, &info)!=GF_ERR_OK)
    {
        perror("gf_dev_attach()");
        return -1;
    }

    /* Setup the layer we will use */
    if (gf_display_attach(&gf_disp, gfdev, 0, &disp_info)!=GF_ERR_OK)
    {
        fprintf(stderr, "gf_display_attach() failed\n");
        return -1;
    }

    width=disp_info.xres;
    height=disp_info.yres;

    layer_idx=disp_info.main_layer_index;

    /* get an EGL display connection */
    display=eglGetDisplay(gfdev);
    if (display==EGL_NO_DISPLAY)
    {
        fprintf(stderr, "eglGetDisplay() failed\n");
        return -1;
    }

    if (gf_layer_attach(&layer, gf_disp, layer_idx, 0)!=GF_ERR_OK)
    {
        fprintf(stderr, "gf_layer_attach() failed\n");
        return -1;
    }

    /* initialize the EGL display connection */
    if (eglInitialize(display, NULL, NULL)!=EGL_TRUE)
    {
        fprintf(stderr, "eglInitialize: error 0x%x\n", eglGetError());
        return -1;
    }

    for (it=0;; it++)
    {
        /* Walk through all possible pixel formats for this layer */
        if (gf_layer_query(layer, it, &linfo)==-1)
        {
            fprintf(stderr, "Couldn't find a compatible frame "
                    "buffer configuration on layer %d\n", layer_idx);
            return -1;
        }

        /*
         * We want the color buffer format to match the layer format,
         * so request the layer format through EGL_NATIVE_VISUAL_ID.
         */
        attribute_list[1]=linfo.format;

        /* Look for a compatible EGL frame buffer configuration */
        if (eglChooseConfig(display, attribute_list, &config, 1, &num_config)==EGL_TRUE)
        {
            if (num_config>0)
            {
                break;
            }
        }
    }

    /* create a 3D rendering target */
    if (gf_3d_target_create(&target, layer, NULL, 0, width, height, linfo.format)!=GF_ERR_OK)
    {
        fprintf(stderr, "Unable to create rendering target\n");
        return -1;
    }

    gf_layer_set_src_viewport(layer, 0, 0, width-1, height-1);
    gf_layer_set_dst_viewport(layer, 0, 0, width-1, height-1);
    gf_layer_enable(layer);

    /*
     * The layer settings haven't taken effect yet since we haven't
     * called gf_layer_update() yet.  This is exactly what we want,
     * since we haven't supplied a valid surface to display yet.
     * Later, the OpenGL ES library calls will call gf_layer_update()
     * internally, when  displaying the rendered 3D content.
     */

    /* create an EGL rendering context */
    econtext=eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
    if (econtext==EGL_NO_CONTEXT)
    {
        fprintf(stderr, "Create context failed: 0x%x\n", eglGetError());
        return -1;
    }

    /* create an EGL window surface */
    surface=eglCreateWindowSurface(display, config, target, NULL);
    if (surface==EGL_NO_SURFACE)
    {
        fprintf(stderr, "Create surface failed: 0x%x\n", eglGetError());
        return -1;
    }

    /* connect the context to the surface */
    if (eglMakeCurrent(display, surface, surface, econtext)==EGL_FALSE)
    {
        fprintf(stderr, "Make current failed: 0x%x\n", eglGetError());
        return -1;
    }

    init_scene(width, height);

    do {
        render_scene();
        glFinish();
        eglWaitGL();
        eglSwapBuffers(display, surface);
    } while(1);

    return 0;
}
Пример #3
0
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;
}
Пример #4
0
/*
 * 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;
}