Пример #1
0
/// On Linux, according to eglplatform.h, EGLNativeDisplayType and intptr_t
/// have the same size regardless of platform.
bool
wegl_display_init(struct wegl_display *dpy,
                  struct wcore_platform *wc_plat,
                  intptr_t native_display)
{
    bool ok;
    EGLint major, minor;

    ok = wcore_display_init(&dpy->wcore, wc_plat);
    if (!ok)
        goto fail;

    dpy->egl = eglGetDisplay((EGLNativeDisplayType) native_display);
    if (!dpy->egl) {
        wegl_emit_error("eglGetDisplay");
        goto fail;
    }

    ok = eglInitialize(dpy->egl, &major, &minor);
    if (!ok) {
        wegl_emit_error("eglInitialize");
        goto fail;
    }

    ok = get_extensions(dpy);
    if (!ok)
	goto fail;

    return true;

fail:
    wegl_display_teardown(dpy);
    return false;
}
Пример #2
0
window::window(int width, int height, std::string const &title, int major, int minor)
{
   (void)width;
   (void)height;
   (void)title;
   (void)major;
   (void)minor;
   m_running = true;

   get_extensions();
}
Пример #3
0
static int open_dir(menu_t* menu,char* args) {
  char **namelist, **tp;
  struct dirent *dp;
  struct stat st;
  int n;
  int path_fp;
  char* p = NULL;
  list_entry_t* e;
  DIR* dirp;
  extern int file_filter;
  char **extensions, **elem, *ext;

  menu_list_init(menu);

  if(mpriv->dir)
    free(mpriv->dir);
  mpriv->dir = strdup(args);
  if(mpriv->p.title && mpriv->p.title != mpriv->title && mpriv->p.title != cfg_dflt.p.title)
    free(mpriv->p.title);
  p = strstr(mpriv->title,"%p");

  mpriv->p.title = replace_path(mpriv->title,mpriv->dir,0);

  if ((dirp = opendir (mpriv->dir)) == NULL){
    mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_OpendirError, strerror(errno));
    return 0;
  }

  if (menu_keepdir) {
    path_fp = open (MENU_KEEP_PATH, O_CREAT | O_WRONLY | O_TRUNC, 0666);
    if (path_fp >= 0) {
      write (path_fp, mpriv->dir, strlen (mpriv->dir));
      close (path_fp);
    }
  }

  namelist = malloc(sizeof(char *));
  extensions = get_extensions(menu);

  n=0;
  while ((dp = readdir(dirp)) != NULL) {
    if(dp->d_name[0] == '.' && strcmp(dp->d_name,"..") != 0)
      continue;
    if (menu_chroot && !strcmp (dp->d_name,"..")) {
      size_t len = strlen (menu_chroot);
      if ((strlen (mpriv->dir) == len || strlen (mpriv->dir) == len + 1)
          && !strncmp (mpriv->dir, menu_chroot, len))
        continue;
    }
    if (mylstat(args,dp->d_name,&st))
      continue;
    if (file_filter && extensions && !S_ISDIR(st.st_mode)) {
      if((ext = strrchr(dp->d_name,'.')) == NULL)
        continue;
      ext++;
      elem = extensions;
      do {
        if (!strcasecmp(ext, *elem))
          break;
      } while (*++elem);
      if (*elem == NULL)
        continue;
    }
    if(n%20 == 0){ // Get some more mem
      if((tp = realloc(namelist, (n+20) * sizeof (char *)))
         == NULL) {
        mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ReallocError, strerror(errno));
	n--;
        goto bailout;
      }
      namelist=tp;
    }

    namelist[n] = malloc(strlen(dp->d_name) + 2);
    if(namelist[n] == NULL){
      mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_MallocError, strerror(errno));
      n--;
      goto bailout;
    }

    strcpy(namelist[n], dp->d_name);
    if(S_ISDIR(st.st_mode))
      strcat(namelist[n], "/");
    n++;
  }

bailout:
  free_extensions (extensions);
  closedir(dirp);

  qsort(namelist, n, sizeof(char *), (kill_warn)compare);

  if (n < 0) {
    mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ReaddirError,strerror(errno));
    return 0;
  }
  while(n--) {
    if((e = calloc(1,sizeof(list_entry_t))) != NULL){
    e->p.next = NULL;
    e->p.txt = strdup(namelist[n]);
    if(strchr(namelist[n], '/') != NULL)
      e->d = 1;
    menu_list_add_entry(menu,e);
    }else{
      mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_MallocError, strerror(errno));
    }
    free(namelist[n]);
  }
  free(namelist);

  return 1;
}
Пример #4
0
Файл: ocl.c Проект: nasa/QuIP
static void init_ocl_device(QSP_ARG_DECL  cl_device_id dev_id,
							Compute_Platform *cpp)
{
	cl_int status;
	//long param_data[MAX_PARAM_SIZE/sizeof(long)];	// force alignment
	//char name[LLEN];
	static int n_ocl_devs=0;
	Platform_Device *pdp;
	CGLContextObj cgl_ctx=NULL;
	cl_context context;
	cl_command_queue command_queue; //"stream" in CUDA
	cl_context_properties props[3]={
		CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
		0,	// need to put cgl_ctx here
		0
		};

	pdp = create_ocl_device(QSP_ARG  dev_id, cpp);
	if( pdp == NULL ) return;

	/* Remember this name in case the default is not found */
	if( first_ocl_dev_name == NULL )
		first_ocl_dev_name = PFDEV_NAME(pdp);

	/* Compare this name against the default name set in
	 * the environment, if it exists...
	 */
	if( default_ocl_dev_name != NULL && ! default_ocl_dev_found ){
		if( !strcmp(PFDEV_NAME(pdp),default_ocl_dev_name) )
			default_ocl_dev_found=1;
	}

	get_extensions(QSP_ARG  pdp);
	SET_OCLDEV_DEV_ID(pdp,dev_id);
	SET_PFDEV_PLATFORM(pdp,cpp);
	if( n_ocl_devs >= MAX_OPENCL_DEVICES ){
		sprintf(ERROR_STRING,"More than %d OpenCL devices found;"
			"need to increase MAX_OPENCL_DEVICES and recompile",
			MAX_OPENCL_DEVICES);
		error1(ERROR_STRING);
	}
fprintf(stderr,"Setting %s device index to %d\n",PFDEV_NAME(pdp),n_ocl_devs);
	SET_PFDEV_SERIAL(pdp,n_ocl_devs++);

	SET_PFDEV_MAX_DIMS(pdp,DEFAULT_PFDEV_MAX_DIMS);

	// On the new MacBook Pro, with two devices, the Iris_Pro
	// throws an error at clCreateCommandQueue *iff* we set
	// the share group property here...  Presumably because
	// that device doesn't handle the display?
	// We insert a hack below by excluding that device name,
	// but maybe there is another model where that would be
	// inappropriate?

	if( extension_supported(pdp,"cl_APPLE_gl_sharing") &&
			strcmp(PFDEV_NAME(pdp),"Iris_Pro")){

		CGLShareGroupObj share_group;
	
		cgl_ctx = CGLGetCurrentContext();
		if( cgl_ctx != NULL){
			// This means that we have an OpenGL window available...
			share_group = CGLGetShareGroup(cgl_ctx);
			assert( share_group != NULL );
			props[1] = (cl_context_properties) share_group;
		} else {
			// If we let this go, it sometimes causes a seg fault
			// when we try to set the GL window afterwards!?
			//
			// But it should not be an error, because we don't know
			// for sure that we will ever attempt it.
			// We need to set a flag to prohibit it later...
			advise("init_ocl_device:  OpenCL initialized without an OpenGL context;");
			advise("init_ocl_device:  Prohibiting OpenGL operations.");
			prohibit_opengl();
		}
	}


	// Check for OpenGL capabilities
	//opengl_check(pdp);

#ifdef TAKEN_FROM_DEMO_PROG
#if (USE_GL_ATTACHMENTS)

	printf(SEPARATOR);
	printf("Using active OpenGL context...\n");

	CGLContextObj kCGLContext = CGLGetCurrentContext();			  
	CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);
	
	cl_context_properties properties[] = { 
		CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, 
		(cl_context_properties)kCGLShareGroup, 0 
	};
		
	// Create a context from a CGL share group
	//
	ComputeContext = clCreateContext(properties, 0, 0, clLogMessagesToStdoutAPPLE, 0, 0);
	if(!ComputeContext)
		return -2;

#else	// ! USE_GL_ATTACHMENTS	

	// Connect to a compute device
	//
	err = clGetDeviceIDs(NULL, ComputeDeviceType, 1, &ComputeDeviceId, NULL);
	if (err != CL_SUCCESS)
	{
		printf("Error: Failed to locate compute device!\n");
		return EXIT_FAILURE;
	}
  
	// Create a compute context 
	//
	ComputeContext = clCreateContext(0, 1, &ComputeDeviceId, clLogMessagesToStdoutAPPLE, NULL, &err);
	if (!ComputeContext)
	{
		printf("Error: Failed to create a compute context!\n");
		return EXIT_FAILURE;
	}
#endif	// ! USE_GL_ATTACHMENTS	

#endif // TAKEN_FROM_DEMO_PROG

	//create context on the specified device
//if( cgl_ctx != NULL )
//fprintf(stderr,"creating clContext with share properties for %s...\n",PFDEV_NAME(pdp));
	if( cgl_ctx == NULL ){
		context = clCreateContext(
			NULL,		// cl_context_properties *properties
			1,		// num_devices
			&dev_id,	// devices
			NULL,		// void *pfn_notify(const char *errinfo, const void *private_info, size_t cb, void *user_data )
			NULL,		// void *user_data
			&status		// cl_int *errcode_ret
		);
	} else {
		context = clCreateContext(
			props,		// cl_context_properties *properties
			0,		// num_devices
			NULL,	// devices
			clLogMessagesToStdoutAPPLE,	// void *pfn_notify(const char *errinfo, const void *private_info, size_t cb, void *user_data )
			NULL,		// void *user_data
			&status		// cl_int *errcode_ret
		);
	}
	if( status != CL_SUCCESS ){
		report_ocl_error(status, "clCreateContext");
		SET_OCLDEV_CTX(pdp,NULL);
		//return;
	}
	// BUG check return value for error

	SET_OCLDEV_CTX(pdp,context);

	//create the command_queue (stream)
//fprintf(stderr,"clContext = 0x%lx...\n",(long)context);
//fprintf(stderr,"init_ocl_device:  dev_id = 0x%lx\n",(long)dev_id);

	// At least once we have gotten an invalid value error here,
	// after receiving the advisory "OpenCL initialized without an OpenGL context
	// (which may or may not be relevant).  This behavior was not repeatable,
	// perhaps because of different stack contents???

	// The third arg is a properties bit field, with valid values being:
	// CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE
	// CL_QUEUE_PROFILING_ENABLE
	command_queue = clCreateCommandQueue(context, dev_id, 0, &status);
	if( status != CL_SUCCESS ){
		report_ocl_error(status, "clCreateCommandQueue");
		SET_OCLDEV_QUEUE(pdp,NULL);
		//return;
	} else {
		SET_OCLDEV_QUEUE(pdp,command_queue);
	}
	// set a ready flag?

	init_ocl_dev_memory(QSP_ARG  pdp);

	curr_pdp = pdp;
}
Пример #5
0
int main(int argc , char *argv[])
{
   int sock, command;
   int idx, i, pp, l, len;
   cmdCmd_t cmd;
   uint32_t p[CMD_P_ARR];
   cmdCtlParse_t ctl;
   cmdScript_t s;
   char v[CMD_MAX_EXTENSION];

   sock = openSocket();

   command_buf[0] = 0;
   l = 0;
   pp = 0;

   for (i=1; i<argc; i++)
   {
      l += (strlen(argv[i]) + 1);
      if (l < sizeof(command_buf))
         {sprintf(command_buf+pp, "%s ", argv[i]); pp=l;}
   }

   if (pp) {command_buf[--pp] = 0;}

   ctl.eaten = 0;

   len = strlen(command_buf);
   idx = 0;

   while ((idx >= 0) && (ctl.eaten < len))
   {
      if ((idx=cmdParse(command_buf, p, CMD_MAX_EXTENSION, v, &ctl)) >= 0)
      {
         command = p[0];

         if (command < PI_CMD_SCRIPT)
         {
            if (command == PI_CMD_HELP)
            {
               printf(cmdUsage);
            }
            else if (command == PI_CMD_PARSE)
            {
               cmdParseScript(v, &s, 1);
               if (s.par) free (s.par);
            }
            else
            {
               cmd.cmd = command;
               cmd.p1 = p[1];
               cmd.p2 = p[2];
               cmd.p3 = p[3];

               if (sock != SOCKET_OPEN_FAILED)
               {
                  if (send(sock, &cmd, sizeof(cmdCmd_t), 0) ==
                     sizeof(cmdCmd_t))
                  {
                     if (p[3]) send(sock, v, p[3], 0); /* send extensions */

                     if (recv(sock, &cmd, sizeof(cmdCmd_t), MSG_WAITALL) ==
                        sizeof(cmdCmd_t))
                     {
                        get_extensions(sock, command, cmd.res);

                        print_result(sock, cmdInfo[idx].rv, cmd);
                     }
                     else fatal("socket receive failed");
                  }
                  else fatal("socket send failed");
               }
               else fatal("socket connect failed");
            }
         }
         else fatal("%s only allowed within a script", cmdInfo[idx].name);
      }
      else
      {
         if (idx == CMD_UNKNOWN_CMD)
            fatal("%s? unknown command, pigs h for help", cmdStr());
         else
            fatal("%s: bad parameter, pigs h for help", cmdStr());
      }
   }

   if (sock >= 0) close(sock);

   return 0;
}
Пример #6
0
void *
glxProbeDriver(const char *driverName,
               void **coreExt, const char *coreName, int coreVersion,
               void **renderExt, const char *renderName, int renderVersion)
{
    int i;
    void *driver;
    char filename[PATH_MAX];
    char *get_extensions_name;
    const __DRIextension **extensions = NULL;

    snprintf(filename, sizeof filename, "%s/%s_dri.so",
             dri_driver_path, driverName);

    driver = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
    if (driver == NULL) {
        LogMessage(X_ERROR, "AIGLX error: dlopen of %s failed (%s)\n",
                   filename, dlerror());
        goto cleanup_failure;
    }

    if (asprintf(&get_extensions_name, "%s_%s",
                 __DRI_DRIVER_GET_EXTENSIONS, driverName) != -1) {
        const __DRIextension **(*get_extensions)(void);

        get_extensions = dlsym(driver, get_extensions_name);
        if (get_extensions)
            extensions = get_extensions();
        free(get_extensions_name);
    }

    if (!extensions)
        extensions = dlsym(driver, __DRI_DRIVER_EXTENSIONS);
    if (extensions == NULL) {
        LogMessage(X_ERROR, "AIGLX error: %s exports no extensions (%s)\n",
                   driverName, dlerror());
        goto cleanup_failure;
    }

    for (i = 0; extensions[i]; i++) {
        if (strcmp(extensions[i]->name, coreName) == 0 &&
            extensions[i]->version >= coreVersion) {
            *coreExt = (void *) extensions[i];
        }

        if (strcmp(extensions[i]->name, renderName) == 0 &&
            extensions[i]->version >= renderVersion) {
            *renderExt = (void *) extensions[i];
        }
    }

    if (*coreExt == NULL || *renderExt == NULL) {
        LogMessage(X_ERROR,
                   "AIGLX error: %s does not export required DRI extension\n",
                   driverName);
        goto cleanup_failure;
    }
    return driver;

 cleanup_failure:
    if (driver)
        dlclose(driver);
    *coreExt = *renderExt = NULL;
    return NULL;
}
Пример #7
0
bool window::open(int width, int height, string const &title, int major, int minor)
{
   if (!::glfwInit())
   {
      ::fprintf(stderr, "Failed to initialize GLFW\n");
      return false;
   }

#if defined(RENDERSTACK_GL_API_OPENGL)
   ::glfwWindowHint(GLFW_CLIENT_API,   GLFW_OPENGL_API);
   ::glfwWindowHint(GLFW_RED_BITS,     8);
   ::glfwWindowHint(GLFW_GREEN_BITS,   8);
   ::glfwWindowHint(GLFW_BLUE_BITS,    8);
   ::glfwWindowHint(GLFW_DEPTH_BITS,   24);
   //::glfwWindowHint(GLFW_SAMPLES,      4);
   ::glfwWindowHint(GLFW_SRGB_CAPABLE, GL_TRUE);

   /*
   if (major >= 3)
      ::glfwWindowHint(GLFW_SAMPLES,   4);*/

   ::glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
   ::glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);

   if (
      (major > 3) ||
      (
         (major == 3) && 
         (minor >= 1)
      )
   )
   {
#if !defined(NDEBUG)
      ::glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
# if !defined(__APPLE__)
      ::glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT,  GL_TRUE);
# endif
#endif
   }

   if (
      (major > 3) ||
      (
         (major == 3) && 
         (minor >= 2)
      )
   )
   {
      //::glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
      ::glfwWindowHint(GLFW_OPENGL_PROFILE,        GLFW_OPENGL_CORE_PROFILE);
      //::glfwWindowHint(GLFW_OPENGL_PROFILE,        GLFW_OPENGL_COMPAT_PROFILE);
   }
#endif

#if defined(RENDERSTACK_GL_API_OPENGL_ES_2) || defined(RENDERSTACK_GL_API_OPENGL_ES_3)
   ::glfwWindowHint(GLFW_CLIENT_API,   GLFW_OPENGL_ES_API);
   ::glfwWindowHint(GLFW_RED_BITS,     0);
   ::glfwWindowHint(GLFW_GREEN_BITS,   0);
   ::glfwWindowHint(GLFW_BLUE_BITS,    0);
   ::glfwWindowHint(GLFW_DEPTH_BITS,   0);
   ::glfwWindowHint(GLFW_STENCIL_BITS, 0);
   ::glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
   ::glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);
#endif

   m_window = ::glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr);
   if (!m_window)
   {
      ::fprintf(stderr, "Failed to open GLFW window for GL %d, %d\n", major, minor);
      ::glfwTerminate(); // TODO Move elsewhere!
      return false;
   }

   m_running = true;
   m_capture = false;
   m_show = true;

   //int forward =::glfwGetWindowParam((GLFWwindow*)m_window, GLFW_OPENGL_FORWARD_COMPAT);

   ::glfwSetWindowUserPointer  ((GLFWwindow*)m_window, this);
   ::glfwSetWindowSizeCallback ((GLFWwindow*)m_window, s_resize);
   ::glfwSetKeyCallback        ((GLFWwindow*)m_window, s_key);
   ::glfwSetCursorPosCallback  ((GLFWwindow*)m_window, s_mouse_pos);
   ::glfwSetMouseButtonCallback((GLFWwindow*)m_window, s_mouse_button);
   ::glfwSetScrollCallback     ((GLFWwindow*)m_window, s_mouse_wheel);
   ::glfwSetWindowCloseCallback((GLFWwindow*)m_window, s_window_close);
#if RENDERSTACK_3DMOUSE_SUPPORT
   ::glfwSet3DMouseCallback    ((GLFWwindow*)m_window, s_3d_mouse);
#endif

   ::glfwSetInputMode((GLFWwindow*)m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
   ::glfwSetInputMode((GLFWwindow*)m_window, GLFW_STICKY_KEYS, GL_FALSE);
   ::glfwSetInputMode((GLFWwindow*)m_window, GLFW_STICKY_MOUSE_BUTTONS, GL_FALSE);
   ::glfwSwapInterval(0);

   ::glfwShowWindow((GLFWwindow*)m_window);
   ::glfwMakeContextCurrent((GLFWwindow*)m_window);
   get_extensions();

   ::glfwSwapInterval(0);

   return true;
}