Exemplo n.º 1
0
/**
 * Fill-in the dispatch stub for the named function.
 *
 * This function is intended to be called by a hardware driver.  When called,
 * a dispatch stub may be created created for the function.  A pointer to this
 * dispatch function will be returned by glXGetProcAddress.
 *
 * \param function_names       Array of pointers to function names that should
 *                             share a common dispatch offset.
 * \param parameter_signature  String representing the types of the parameters
 *                             passed to the named function.  Parameter types
 *                             are converted to characters using the following
 *                             rules:
 *                               - 'i' for \c GLint, \c GLuint, and \c GLenum
 *                               - 'p' for any pointer type
 *                               - 'f' for \c GLfloat and \c GLclampf
 *                               - 'd' for \c GLdouble and \c GLclampd
 *
 * \returns
 * The offset in the dispatch table of the named function.  A pointer to the
 * driver's implementation of the named function should be stored at
 * \c dispatch_table[\c offset].  Return -1 if error/problem.
 *
 * \sa glXGetProcAddress
 *
 * \warning
 * This function can only handle up to 8 names at a time.  As far as I know,
 * the maximum number of names ever associated with an existing GL function is
 * 4 (\c glPointParameterfSGIS, \c glPointParameterfEXT,
 * \c glPointParameterfARB, and \c glPointParameterf), so this should not be
 * too painful of a limitation.
 *
 * \todo
 * Check parameter_signature.
 */
int
_glapi_add_dispatch( const char * const * function_names,
		     const char * parameter_signature )
{
   const struct mapi_stub *function_stubs[8];
   const struct mapi_stub *alias = NULL;
   unsigned i;

   (void) memset(function_stubs, 0, sizeof(function_stubs));

   /* find the missing stubs, and decide the alias */
   for (i = 0; function_names[i] != NULL && i < 8; i++) {
      const char * funcName = function_names[i];
      const struct mapi_stub *stub;
      int slot;

      if (!funcName || funcName[0] != 'g' || funcName[1] != 'l')
         return -1;
      funcName += 2;

      stub = stub_find_public(funcName);
      if (!stub)
         stub = stub_find_dynamic(funcName, 0);

      slot = (stub) ? stub_get_slot(stub) : -1;
      if (slot >= 0) {
         if (alias && stub_get_slot(alias) != slot)
            return -1;
         /* use the first existing stub as the alias */
         if (!alias)
            alias = stub;

         function_stubs[i] = stub;
      }
   }

   /* generate missing stubs */
   for (i = 0; function_names[i] != NULL && i < 8; i++) {
      const char * funcName = function_names[i] + 2;
      struct mapi_stub *stub;

      if (function_stubs[i])
         continue;

      stub = stub_find_dynamic(funcName, 1);
      if (!stub)
         return -1;

      stub_fix_dynamic(stub, alias);
      if (!alias)
         alias = stub;
   }

   return (alias) ? stub_get_slot(alias) : -1;
}
Exemplo n.º 2
0
static GLboolean stubGetPatchOffset(const char *name, void **writePtr, const void **execPtr)
{
    const struct mapi_stub *stub;
    void *addr = NULL;

    stub = stub_find_public(name);

#if !defined(STATIC_DISPATCH_ONLY)
    if (!stub) {
        stub = stub_find_dynamic(name, 0);
    }
#endif // !defined(STATIC_DISPATCH_ONLY)

    if (stub) {
        addr = stub_get_addr(stub);
    }
    if (writePtr != NULL) {
        *writePtr = addr;
    }
    if (execPtr != NULL) {
        *execPtr = addr;
    }

    return (addr != NULL ? GL_TRUE : GL_FALSE);
}
Exemplo n.º 3
0
static GLboolean stubGetPatchOffset(const char *name, void **writePtr, const void **execPtr)
{
    const struct mapi_stub *stub;
    void *writeAddr = NULL;
    const void *execAddr = NULL;

    stub = stub_find_public(name);

#if !defined(STATIC_DISPATCH_ONLY)
    if (!stub) {
        stub = stub_find_dynamic(name, 0);
    }
#endif // !defined(STATIC_DISPATCH_ONLY)

    if (stub) {
        mapi_func addr = stub_get_addr(stub);
        if (addr != NULL) {
            entry_get_patch_addresses(addr, &writeAddr, &execAddr);
        }
    }

    if (writePtr != NULL) {
        *writePtr = writeAddr;
    }
    if (execPtr != NULL) {
        *execPtr = execAddr;
    }

    return ((writeAddr != NULL && execAddr != NULL) ? GL_TRUE : GL_FALSE);
}
Exemplo n.º 4
0
/**
 * Return the address of an entry.  Optionally generate the entry if it does
 * not exist.
 */
mapi_proc
mapi_get_proc_address(const char *name)
{
   const struct mapi_stub *stub;

   stub = stub_find_public(name);
   if (!stub)
      stub = stub_find_dynamic(name, 0);

   return (stub) ? (mapi_proc) stub_get_addr(stub) : NULL;
}
Exemplo n.º 5
0
static const struct mapi_stub *
_glapi_get_stub(const char *name, int generate)
{
   const struct mapi_stub *stub;

    if (!name)
        return NULL;

   stub = stub_find_public(name);
   if (!stub)
      stub = stub_find_dynamic(name, generate);

   return stub;
}
Exemplo n.º 6
0
static const struct mapi_stub *
get_stub(const char *name, const struct mapi_stub *alias)
{
   const struct mapi_stub *stub;

   stub = stub_find_public(name);
   if (!stub) {
      struct mapi_stub *dyn = stub_find_dynamic(name, 1);
      if (dyn) {
         stub_fix_dynamic(dyn, alias);
         stub = dyn;
      }
   }

   return stub;
}
Exemplo n.º 7
0
static const struct mapi_stub *
_glapi_get_stub(const char *name, int generate)
{
   const struct mapi_stub *stub;

#ifdef USE_MGL_NAMESPACE
   if (name)
      name++;
#endif

   if (!name || name[0] != 'g' || name[1] != 'l')
      return NULL;
   name += 2;

   stub = stub_find_public(name);
   if (!stub)
      stub = stub_find_dynamic(name, generate);

   return stub;
}