static char * drm_get_device_name(int fd) { char *device_name = NULL; #ifdef HAVE_LIBUDEV struct udev *udev; struct udev_device *device; struct stat buf; const char *tmp; udev = udev_new(); if (fstat(fd, &buf) < 0) { _eglLog(_EGL_WARNING, "failed to stat fd %d", fd); goto out; } device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev); if (device == NULL) { _eglLog(_EGL_WARNING, "could not create udev device for fd %d", fd); goto out; } tmp = udev_device_get_devnode(device); if (!tmp) goto out; device_name = strdup(tmp); out: udev_device_unref(device); udev_unref(udev); #endif return device_name; }
/** * Initialize DRI2 and pipe screen. */ static boolean dri2_display_init_screen(struct native_display *ndpy) { struct dri2_display *dri2dpy = dri2_display(ndpy); int fd; if (!x11_screen_support(dri2dpy->xscr, X11_SCREEN_EXTENSION_DRI2) || !x11_screen_support(dri2dpy->xscr, X11_SCREEN_EXTENSION_GLX)) { _eglLog(_EGL_WARNING, "GLX/DRI2 is not supported"); return FALSE; } dri2dpy->dri_driver = x11_screen_probe_dri2(dri2dpy->xscr, &dri2dpy->dri_major, &dri2dpy->dri_minor); fd = x11_screen_enable_dri2(dri2dpy->xscr, dri2_display_invalidate_buffers, &dri2dpy->base); if (fd < 0) return FALSE; dri2dpy->base.screen = dri2dpy->event_handler->new_drm_screen(&dri2dpy->base, dri2dpy->dri_driver, fd); if (!dri2dpy->base.screen) { _eglLog(_EGL_DEBUG, "failed to create DRM screen"); return FALSE; } return TRUE; }
static struct st_api * egl_st_load_gl(void) { const char module[] = "st_GL"; const char symbol[] = "st_api_create_OpenGL"; struct st_api *stapi; stapi = load_gl(module, symbol); /* try again with libglapi.so loaded */ if (!stapi) { struct util_dl_library *glapi = util_dl_open("libglapi" UTIL_DL_EXT); if (glapi) { _eglLog(_EGL_DEBUG, "retry with libglapi" UTIL_DL_EXT " loaded"); stapi = load_gl(module, symbol); util_dl_close(glapi); } } if (!stapi) _eglLog(_EGL_WARNING, "unable to load %s" UTIL_DL_EXT, module); return stapi; }
/** * Open the named driver and find its bootstrap function: _eglMain(). */ static _EGLMain_t _eglOpenLibrary(const char *driverPath, lib_handle *handle) { lib_handle lib; _EGLMain_t mainFunc = NULL; const char *error = "unknown error"; assert(driverPath); _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath); lib = load_library(driverPath); if (!lib) { _eglLog(_EGL_WARNING, "Could not open driver %s (%s)", driverPath, error); return NULL; } mainFunc = (_EGLMain_t) get_proc_address(lib, "_eglMain"); if (!mainFunc) { _eglLog(_EGL_WARNING, "_eglMain not found in %s (%s)", driverPath, error); return NULL; } *handle = lib; return mainFunc; }
static EGLBoolean haiku_add_configs_for_visuals(_EGLDisplay *dpy) { printf("Adding configs\n"); struct haiku_egl_config* conf; conf = CALLOC_STRUCT(haiku_egl_config); _eglInitConfig(&conf->base, dpy, 1); _eglLog(_EGL_DEBUG,"Config inited\n"); _eglSetConfigKey(&conf->base, EGL_RED_SIZE, 8); _eglSetConfigKey(&conf->base, EGL_BLUE_SIZE, 8); _eglSetConfigKey(&conf->base, EGL_GREEN_SIZE, 8); _eglSetConfigKey(&conf->base, EGL_LUMINANCE_SIZE, 0); _eglSetConfigKey(&conf->base, EGL_ALPHA_SIZE, 8); _eglSetConfigKey(&conf->base, EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER); EGLint r = (_eglGetConfigKey(&conf->base, EGL_RED_SIZE) + _eglGetConfigKey(&conf->base, EGL_GREEN_SIZE) + _eglGetConfigKey(&conf->base, EGL_BLUE_SIZE) + _eglGetConfigKey(&conf->base, EGL_ALPHA_SIZE)); _eglSetConfigKey(&conf->base, EGL_BUFFER_SIZE, r); _eglSetConfigKey(&conf->base, EGL_CONFIG_CAVEAT, EGL_NONE); _eglSetConfigKey(&conf->base, EGL_CONFIG_ID, 1); _eglSetConfigKey(&conf->base, EGL_BIND_TO_TEXTURE_RGB, EGL_FALSE); _eglSetConfigKey(&conf->base, EGL_BIND_TO_TEXTURE_RGBA, EGL_FALSE); _eglSetConfigKey(&conf->base, EGL_STENCIL_SIZE, 0); _eglSetConfigKey(&conf->base, EGL_TRANSPARENT_TYPE, EGL_NONE); _eglSetConfigKey(&conf->base, EGL_NATIVE_RENDERABLE, EGL_TRUE); // Let's say yes _eglSetConfigKey(&conf->base, EGL_NATIVE_VISUAL_ID, 0); // No visual _eglSetConfigKey(&conf->base, EGL_NATIVE_VISUAL_TYPE, EGL_NONE); // No visual _eglSetConfigKey(&conf->base, EGL_RENDERABLE_TYPE, 0x8); _eglSetConfigKey(&conf->base, EGL_SAMPLE_BUFFERS, 0); // TODO: How to get the right value ? _eglSetConfigKey(&conf->base, EGL_SAMPLES, _eglGetConfigKey(&conf->base, EGL_SAMPLE_BUFFERS) == 0 ? 0 : 0); _eglSetConfigKey(&conf->base, EGL_DEPTH_SIZE, 24); // TODO: How to get the right value ? _eglSetConfigKey(&conf->base, EGL_LEVEL, 0); _eglSetConfigKey(&conf->base, EGL_MAX_PBUFFER_WIDTH, 0); // TODO: How to get the right value ? _eglSetConfigKey(&conf->base, EGL_MAX_PBUFFER_HEIGHT, 0); // TODO: How to get the right value ? _eglSetConfigKey(&conf->base, EGL_MAX_PBUFFER_PIXELS, 0); // TODO: How to get the right value ? _eglSetConfigKey(&conf->base, EGL_SURFACE_TYPE, EGL_WINDOW_BIT /*| EGL_PIXMAP_BIT | EGL_PBUFFER_BIT*/); printf("Config configuated\n"); if (!_eglValidateConfig(&conf->base, EGL_FALSE)) { _eglLog(_EGL_DEBUG, "Haiku failed to validate config"); return EGL_FALSE; } printf("Validated config\n"); _eglLinkConfig(&conf->base); if (!_eglGetArraySize(dpy->Configs)) { _eglLog(_EGL_WARNING, "Haiku: failed to create any config"); return EGL_FALSE; } printf("Config successful!\n"); return EGL_TRUE; }
EGLBoolean init_haiku(_EGLDriver *drv, _EGLDisplay *dpy) { _eglLog(_EGL_DEBUG,"\nInitializing Haiku EGL\n"); //_EGLDisplay* egl_dpy; printf("Initializing Haiku EGL\n"); _eglSetLogProc(haiku_log); loader_set_logger(_eglLog); /*egl_dpy = (_EGLDisplay*) calloc(1, sizeof(_EGLDisplay)); if (!egl_dpy) return _eglError(EGL_BAD_ALLOC, "eglInitialize"); dpy->DriverData=(void*) egl_dpy; if (!dpy->PlatformDisplay) { // OPEN DEVICE //dri2_dpy->bwindow = (void*)haiku_create_window(); //dri2_dpy->own_device = true; } else { //dri2_dpy->bwindow = (BWindow*)dpy->PlatformDisplay; }*/ //dri2_dpy->driver_name = strdup("swrast"); //if (!dri2_load_driver_swrast(dpy)) // goto cleanup_conn; /*dri2_dpy->swrast_loader_extension.base.name = __DRI_SWRAST_LOADER; dri2_dpy->swrast_loader_extension.base.version = __DRI_SWRAST_LOADER_VERSION; dri2_dpy->swrast_loader_extension.getDrawableInfo = swrastGetDrawableInfo; dri2_dpy->swrast_loader_extension.putImage = swrastPutImage; dri2_dpy->swrast_loader_extension.getImage = swrastGetImage; dri2_dpy->extensions[0] = &dri2_dpy->swrast_loader_extension.base; dri2_dpy->extensions[1] = NULL; dri2_dpy->extensions[2] = NULL;*/ /*if (dri2_dpy->bwindow) { if (!dri2_haiku_add_configs_for_visuals(dri2_dpy, dpy)) goto cleanup_configs; }*/ _eglLog(_EGL_DEBUG,"Add configs"); haiku_add_configs_for_visuals(dpy); dpy->VersionMajor=1; dpy->VersionMinor=4; //dpy->Extensions.KHR_create_context = true; //dri2_dpy->vtbl = &dri2_haiku_display_vtbl; _eglLog(_EGL_DEBUG, "Initialization finished"); return EGL_TRUE; }
/** * Enable DRI2 and returns the file descriptor of the DRM device. The file * descriptor will be closed automatically when the screen is destoryed. */ int x11_screen_enable_dri2(struct x11_screen *xscr, x11_drawable_invalidate_buffers invalidate_buffers, void *user_data) { if (xscr->dri_fd < 0) { int fd; drm_magic_t magic; /* get the driver name and the device name first */ if (!x11_screen_probe_dri2(xscr, NULL, NULL)) return -1; fd = open(xscr->dri_device, O_RDWR); if (fd < 0) { _eglLog(_EGL_WARNING, "failed to open %s", xscr->dri_device); return -1; } memset(&magic, 0, sizeof(magic)); if (drmGetMagic(fd, &magic)) { _eglLog(_EGL_WARNING, "failed to get magic"); close(fd); return -1; } if (!DRI2Authenticate(xscr->dpy, RootWindow(xscr->dpy, xscr->number), magic)) { _eglLog(_EGL_WARNING, "failed to authenticate magic"); close(fd); return -1; } if (!x11_screen_init_glx(xscr)) { _eglLog(_EGL_WARNING, "failed to initialize GLX"); close(fd); return -1; } if (xscr->glx_dpy->xscr) { _eglLog(_EGL_WARNING, "display is already managed by another x11 screen"); close(fd); return -1; } xscr->glx_dpy->xscr = xscr; xscr->dri_invalidate_buffers = invalidate_buffers; xscr->dri_user_data = user_data; xscr->dri_fd = fd; } return xscr->dri_fd; }
_EGLContext* haiku_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, _EGLContext *share_list, const EGLint *attrib_list) { _eglLog(_EGL_DEBUG,"Creating context"); struct haiku_egl_context* context; context=(struct haiku_egl_context*)calloc(1,sizeof (*context)); if(!_eglInitContext(&context->ctx, disp, conf, attrib_list)) printf("ERROR creating context"); _eglLog(_EGL_DEBUG, "Context created"); return &context->ctx; }
/** * Open the named driver and find its bootstrap function: _eglMain(). */ static _EGLMain_t _eglOpenLibrary(const char *driverPath, lib_handle *handle) { lib_handle lib; _EGLMain_t mainFunc = NULL; const char *error = "unknown error"; assert(driverPath); _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath); lib = open_library(driverPath); #if defined(_EGL_PLATFORM_WINDOWS) /* XXX untested */ if (lib) mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain"); #elif defined(_EGL_PLATFORM_X) if (lib) { mainFunc = (_EGLMain_t) dlsym(lib, "_eglMain"); if (!mainFunc) error = dlerror(); } else { error = dlerror(); } #else /* _EGL_PLATFORM_NO_OS */ /* must be the default driver name */ if (strcmp(driverPath, DefaultDriverName) == 0) mainFunc = (_EGLMain_t) _eglMain; else error = "not builtin driver"; #endif if (!lib) { _eglLog(_EGL_WARNING, "Could not open driver %s (%s)", driverPath, error); if (!getenv("EGL_DRIVER")) _eglLog(_EGL_WARNING, "The driver can be overridden by setting EGL_DRIVER"); return NULL; } if (!mainFunc) { _eglLog(_EGL_WARNING, "_eglMain not found in %s (%s)", driverPath, error); if (lib) close_library(lib); return NULL; } *handle = lib; return mainFunc; }
/** * Open the named driver and find its bootstrap function: _eglMain(). */ static _EGLMain_t _eglOpenLibrary(const char *driverPath, lib_handle *handle) { lib_handle lib; _EGLMain_t mainFunc = NULL; const char *error = "unknown error"; assert(driverPath); _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath); lib = open_library(driverPath); #if defined(_EGL_OS_WINDOWS) /* XXX untested */ if (lib) mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain"); #elif defined(_EGL_OS_UNIX) if (lib) { union { _EGLMain_t func; void *ptr; } tmp = { NULL }; /* direct cast gives a warning when compiled with -pedantic */ tmp.ptr = dlsym(lib, "_eglMain"); mainFunc = tmp.func; if (!mainFunc) error = dlerror(); } else { error = dlerror(); } #endif if (!lib) { _eglLog(_EGL_WARNING, "Could not open driver %s (%s)", driverPath, error); if (!getenv("EGL_DRIVER")) _eglLog(_EGL_WARNING, "The driver can be overridden by setting EGL_DRIVER"); return NULL; } if (!mainFunc) { _eglLog(_EGL_WARNING, "_eglMain not found in %s (%s)", driverPath, error); if (lib) close_library(lib); return NULL; } *handle = lib; return mainFunc; }
char * dri2_get_driver_for_fd(int fd) { struct udev *udev; struct udev_device *device, *parent; const char *pci_id; char *driver = NULL; int vendor_id, chip_id, i, j; udev = udev_new(); device = dri2_udev_device_new_from_fd(udev, fd); if (device == NULL) return NULL; parent = udev_device_get_parent(device); if (parent == NULL) { _eglLog(_EGL_WARNING, "DRI2: could not get parent device"); goto out; } pci_id = udev_device_get_property_value(parent, "PCI_ID"); if (pci_id == NULL || sscanf(pci_id, "%x:%x", &vendor_id, &chip_id) != 2) { _eglLog(_EGL_WARNING, "EGL-DRI2: malformed or no PCI ID"); goto out; } for (i = 0; driver_map[i].driver; i++) { if (vendor_id != driver_map[i].vendor_id) continue; if (driver_map[i].num_chips_ids == -1) { driver = strdup(driver_map[i].driver); _eglLog(_EGL_DEBUG, "pci id for %d: %04x:%04x, driver %s", fd, vendor_id, chip_id, driver); goto out; } for (j = 0; j < driver_map[i].num_chips_ids; j++) if (driver_map[i].chip_ids[j] == chip_id) { driver = strdup(driver_map[i].driver); _eglLog(_EGL_DEBUG, "pci id for %d: %04x:%04x, driver %s", fd, vendor_id, chip_id, driver); goto out; } } out: udev_device_unref(device); udev_unref(udev); return driver; }
static struct pipe_resource * egl_g3d_reference_drm_buffer(_EGLDisplay *dpy, EGLint name, _EGLImage *img, const EGLint *attribs) { struct egl_g3d_display *gdpy = egl_g3d_display(dpy); _EGLImageAttribs attrs; EGLint format; struct native_buffer nbuf; if (!dpy->Extensions.MESA_drm_image) return NULL; if (_eglParseImageAttribList(&attrs, dpy, attribs) != EGL_SUCCESS) return NULL; if (attrs.Width <= 0 || attrs.Height <= 0 || attrs.DRMBufferStrideMESA <= 0) { _eglLog(_EGL_DEBUG, "bad width, height, or stride (%dx%dx%d)", attrs.Width, attrs.Height, attrs.DRMBufferStrideMESA); return NULL; } switch (attrs.DRMBufferFormatMESA) { case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: format = PIPE_FORMAT_B8G8R8A8_UNORM; break; default: _eglLog(_EGL_DEBUG, "bad image format value 0x%04x", attrs.DRMBufferFormatMESA); return NULL; break; } memset(&nbuf, 0, sizeof(nbuf)); nbuf.type = NATIVE_BUFFER_DRM; nbuf.u.drm.templ.target = PIPE_TEXTURE_2D; nbuf.u.drm.templ.format = format; nbuf.u.drm.templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; nbuf.u.drm.templ.width0 = attrs.Width; nbuf.u.drm.templ.height0 = attrs.Height; nbuf.u.drm.templ.depth0 = 1; nbuf.u.drm.templ.array_size = 1; nbuf.u.drm.name = name; nbuf.u.drm.stride = attrs.DRMBufferStrideMESA * util_format_get_blocksize(format); return gdpy->native->buffer->import_buffer(gdpy->native, &nbuf); }
static void drm_get_device_id(struct drm_device *device) { char path[512]; FILE *file; char *ret; /* TODO get the real minor */ int minor = 0; device->deviceID = 0; snprintf(path, sizeof(path), "/sys/class/drm/card%d/device/device", minor); file = fopen(path, "r"); if (!file) { _eglLog(_EGL_WARNING, "Could not retrive device ID\n"); return; } ret = fgets(path, sizeof( path ), file); fclose(file); if (!ret) return; sscanf(path, "%x", &device->deviceID); }
/** * Finish display management. */ void _eglFiniDisplay(void) { _EGLDisplay *dpyList, *dpy; /* atexit function is called with global mutex locked */ dpyList = _eglGlobal.DisplayList; while (dpyList) { EGLint i; /* pop list head */ dpy = dpyList; dpyList = dpyList->Next; for (i = 0; i < _EGL_NUM_RESOURCES; i++) { if (dpy->ResourceLists[i]) { _eglLog(_EGL_DEBUG, "Display %p is destroyed with resources", dpy); break; } } free(dpy); } _eglGlobal.DisplayList = NULL; }
static EGLBoolean droid_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *dpy) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); const struct { int format; unsigned int rgba_masks[4]; } visuals[] = { { HAL_PIXEL_FORMAT_RGBA_8888, { 0xff, 0xff00, 0xff0000, 0xff000000 } }, { HAL_PIXEL_FORMAT_RGBX_8888, { 0xff, 0xff00, 0xff0000, 0x0 } }, { HAL_PIXEL_FORMAT_RGB_888, { 0xff, 0xff00, 0xff0000, 0x0 } }, { HAL_PIXEL_FORMAT_RGB_565, { 0xf800, 0x7e0, 0x1f, 0x0 } }, { HAL_PIXEL_FORMAT_BGRA_8888, { 0xff0000, 0xff00, 0xff, 0xff000000 } }, { 0, 0, { 0, 0, 0, 0 } } }; int count, i, j; count = 0; for (i = 0; visuals[i].format; i++) { int format_count = 0; for (j = 0; dri2_dpy->driver_configs[j]; j++) { const EGLint surface_type = EGL_WINDOW_BIT | EGL_PBUFFER_BIT; struct dri2_egl_config *dri2_conf; unsigned int double_buffered = 0; dri2_dpy->core->getConfigAttrib(dri2_dpy->driver_configs[j], __DRI_ATTRIB_DOUBLE_BUFFER, &double_buffered); /* support only double buffered configs */ if (!double_buffered) continue; dri2_conf = dri2_add_config(dpy, dri2_dpy->driver_configs[j], count + 1, surface_type, NULL, visuals[i].rgba_masks); if (dri2_conf) { dri2_conf->base.NativeVisualID = visuals[i].format; dri2_conf->base.NativeVisualType = visuals[i].format; count++; format_count++; } } if (!format_count) { _eglLog(_EGL_DEBUG, "No DRI config supports native format 0x%x", visuals[i].format); } } /* post-process configs */ for (i = 0; i < dpy->Configs->Size; i++) { struct dri2_egl_config *dri2_conf = dri2_egl_config(dpy->Configs->Elements[i]); /* there is no front buffer so no OpenGL */ dri2_conf->base.RenderableType &= ~EGL_OPENGL_BIT; dri2_conf->base.Conformant &= ~EGL_OPENGL_BIT; } return (count != 0); }
EGLBoolean _eglPointerIsDereferencable(void *p) { #ifdef HAVE_MINCORE uintptr_t addr = (uintptr_t) p; unsigned char valid = 0; const long page_size = getpagesize(); if (p == NULL) return EGL_FALSE; /* align addr to page_size */ addr &= ~(page_size - 1); if (mincore((void *) addr, page_size, &valid) < 0) { _eglLog(_EGL_DEBUG, "mincore failed: %m"); return EGL_FALSE; } /* mincore() returns 0 on success, and -1 on failure. The last parameter * is a vector of bytes with one entry for each page queried. mincore * returns page residency information in the first bit of each byte in the * vector. * * Residency doesn't actually matter when determining whether a pointer is * dereferenceable, so the output vector can be ignored. What matters is * whether mincore succeeds. See: * * http://man7.org/linux/man-pages/man2/mincore.2.html */ return EGL_TRUE; #else return p != NULL; #endif }
static int dri2_x11_do_authenticate(struct dri2_egl_display *dri2_dpy, uint32_t id) { xcb_dri2_authenticate_reply_t *authenticate; xcb_dri2_authenticate_cookie_t authenticate_cookie; xcb_screen_iterator_t s; xcb_screen_t *screen; int ret = 0; s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); screen = get_xcb_screen(s, dri2_dpy->screen); if (!screen) { _eglLog(_EGL_WARNING, "DRI2: failed to get xcb screen"); return -1; } authenticate_cookie = xcb_dri2_authenticate_unchecked(dri2_dpy->conn, screen->root, id); authenticate = xcb_dri2_authenticate_reply(dri2_dpy->conn, authenticate_cookie, NULL); if (authenticate == NULL || !authenticate->authenticated) ret = -1; free(authenticate); return ret; }
/** * Load a driver and save it. */ const char * _eglPreloadDriver(_EGLDisplay *dpy) { char *path, *args; _EGLDriver *drv; EGLint i; path = _eglChooseDriver(dpy, &args); if (!path) return NULL; for (i = 0; i < _eglGlobal.NumDrivers; i++) { drv = _eglGlobal.Drivers[i]; if (strcmp(drv->Path, path) == 0) { _eglLog(_EGL_DEBUG, "Driver %s is already preloaded", drv->Name); free(path); if (args) free(args); return drv->Name; } } drv = _eglLoadDriver(path, args); if (!drv) return NULL; _eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv; return drv->Name; }
/** * Parse the list of sync attributes and return the proper error code. */ static EGLint _eglParseSyncAttribList(_EGLSync *sync, const EGLint *attrib_list) { EGLint i, err = EGL_SUCCESS; if (!attrib_list) return EGL_SUCCESS; for (i = 0; attrib_list[i] != EGL_NONE; i++) { EGLint attr = attrib_list[i++]; EGLint val = attrib_list[i]; switch (attr) { default: (void) val; err = EGL_BAD_ATTRIBUTE; break; } if (err != EGL_SUCCESS) { _eglLog(_EGL_DEBUG, "bad sync attribute 0x%04x", attr); break; } } return err; }
/** * Return the native platform. It is the platform of the EGL native types. */ _EGLPlatformType _eglGetNativePlatform(void *nativeDisplay) { static _EGLPlatformType native_platform = _EGL_INVALID_PLATFORM; char *detection_method = NULL; if (native_platform == _EGL_INVALID_PLATFORM) { native_platform = _eglGetNativePlatformFromEnv(); detection_method = "environment overwrite"; if (native_platform == _EGL_INVALID_PLATFORM) { native_platform = _eglNativePlatformDetectNativeDisplay(nativeDisplay); detection_method = "autodetected"; if (native_platform == _EGL_INVALID_PLATFORM) { native_platform = _EGL_NATIVE_PLATFORM; detection_method = "build-time configuration"; } } } if (detection_method != NULL) _eglLog(_EGL_DEBUG, "Native platform type: %s (%s)", egl_platforms[native_platform].name, detection_method); return native_platform; }
/** * Match a display to a driver. The display is initialized unless test_only is * true. The matching is done by finding the first driver that can initialize * the display. */ _EGLDriver * _eglMatchDriver(_EGLDisplay *dpy, EGLBoolean test_only) { _EGLDriver *best_drv; assert(!dpy->Initialized); _eglLockMutex(&_eglModuleMutex); /* set options */ dpy->Options.TestOnly = test_only; dpy->Options.UseFallback = EGL_FALSE; best_drv = _eglMatchAndInitialize(dpy); if (!best_drv) { dpy->Options.UseFallback = EGL_TRUE; best_drv = _eglMatchAndInitialize(dpy); } _eglUnlockMutex(&_eglModuleMutex); if (best_drv) { _eglLog(_EGL_DEBUG, "the best driver is %s%s", best_drv->Name, (test_only) ? " (test only) " : ""); if (!test_only) { dpy->Driver = best_drv; dpy->Initialized = EGL_TRUE; } } return best_drv; }
/** * Add a module to the module array. */ static _EGLModule * _eglAddModule(const char *path) { _EGLModule *mod; EGLint i; if (!_eglModules) { _eglModules = _eglCreateArray("Module", 8); if (!_eglModules) return NULL; } /* find duplicates */ for (i = 0; i < _eglModules->Size; i++) { mod = _eglModules->Elements[i]; if (strcmp(mod->Path, path) == 0) return mod; } /* allocate a new one */ mod = calloc(1, sizeof(*mod)); if (mod) { mod->Path = _eglstrdup(path); if (!mod->Path) { free(mod); mod = NULL; } } if (mod) { _eglAppendArray(_eglModules, (void *) mod); _eglLog(_EGL_DEBUG, "added %s to module array", mod->Path); } return mod; }
/** * Initialize the given _EGLContext object to defaults and/or the values * in the attrib_list. */ EGLBoolean _eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list) { const EGLenum api = eglQueryAPI(); EGLint err; if (api == EGL_NONE) { _eglError(EGL_BAD_MATCH, "eglCreateContext(no client API)"); return EGL_FALSE; } _eglInitResource(&ctx->Resource, sizeof(*ctx), dpy); ctx->ClientAPI = api; ctx->Config = conf; ctx->WindowRenderBuffer = EGL_NONE; ctx->ClientVersion = 1; /* the default, per EGL spec */ err = _eglParseContextAttribList(ctx, attrib_list); if (err == EGL_SUCCESS && ctx->Config) { EGLint api_bit; api_bit = _eglGetContextAPIBit(ctx); if (!(ctx->Config->RenderableType & api_bit)) { _eglLog(_EGL_DEBUG, "context api is 0x%x while config supports 0x%x", api_bit, ctx->Config->RenderableType); err = EGL_BAD_CONFIG; } } if (err != EGL_SUCCESS) return _eglError(err, "eglCreateContext"); return EGL_TRUE; }
static void swrastGetDrawableInfo(__DRIdrawable * draw, int *x, int *y, int *w, int *h, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; struct dri2_egl_display *dri2_dpy = dri2_egl_display(dri2_surf->base.Resource.Display); xcb_get_geometry_cookie_t cookie; xcb_get_geometry_reply_t *reply; xcb_generic_error_t *error; *w = *h = 0; cookie = xcb_get_geometry (dri2_dpy->conn, dri2_surf->drawable); reply = xcb_get_geometry_reply (dri2_dpy->conn, cookie, &error); if (reply == NULL) return; if (error != NULL) { _eglLog(_EGL_WARNING, "error in xcb_get_geometry"); free(error); } else { *w = reply->width; *h = reply->height; } free(reply); }
/** * Initialize the logging facility. */ static void _eglInitLogger(void) { const char *log_env; EGLint i, level = -1; if (logging.initialized) return; log_env = getenv("EGL_LOG_LEVEL"); if (log_env) { for (i = 0; level_strings[i]; i++) { if (_eglstrcasecmp(log_env, level_strings[i]) == 0) { level = i; break; } } } else { level = FALLBACK_LOG_LEVEL; } logging.logger = _eglDefaultLogger; logging.level = (level >= 0) ? level : FALLBACK_LOG_LEVEL; logging.initialized = EGL_TRUE; /* it is fine to call _eglLog now */ if (log_env && level < 0) { _eglLog(_EGL_WARNING, "Unrecognized EGL_LOG_LEVEL environment variable value. " "Expected one of \"fatal\", \"warning\", \"info\", \"debug\". " "Got \"%s\". Falling back to \"%s\".", log_env, level_strings[FALLBACK_LOG_LEVEL]); } }
boolean drm_display_init_modeset(struct native_display *ndpy) { struct drm_display *drmdpy = drm_display(ndpy); /* resources are fixed, unlike crtc, connector, or encoder */ drmdpy->resources = drmModeGetResources(drmdpy->fd); if (!drmdpy->resources) { _eglLog(_EGL_DEBUG, "Failed to get KMS resources. Disable modeset."); return FALSE; } drmdpy->saved_crtcs = CALLOC(drmdpy->resources->count_crtcs, sizeof(*drmdpy->saved_crtcs)); if (!drmdpy->saved_crtcs) { drm_display_fini_modeset(&drmdpy->base); return FALSE; } drmdpy->shown_surfaces = CALLOC(drmdpy->resources->count_crtcs, sizeof(*drmdpy->shown_surfaces)); if (!drmdpy->shown_surfaces) { drm_display_fini_modeset(&drmdpy->base); return FALSE; } drmdpy->base.modeset = &drm_display_modeset; return TRUE; }
static void swrastGetImage(__DRIdrawable * read, int x, int y, int w, int h, char *data, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; struct dri2_egl_display *dri2_dpy = dri2_egl_display(dri2_surf->base.Resource.Display); xcb_get_image_cookie_t cookie; xcb_get_image_reply_t *reply; xcb_generic_error_t *error; cookie = xcb_get_image (dri2_dpy->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, dri2_surf->drawable, x, y, w, h, ~0); reply = xcb_get_image_reply (dri2_dpy->conn, cookie, &error); if (reply == NULL) return; if (error != NULL) { _eglLog(_EGL_WARNING, "error in xcb_get_image"); free(error); } else { uint32_t bytes = xcb_get_image_data_length(reply); uint8_t *idata = xcb_get_image_data(reply); memcpy(data, idata, bytes); } free(reply); }
/** * Match a display to a driver. The matching is done by finding the first * driver that can initialize the display. */ _EGLDriver * _eglMatchDriver(_EGLDisplay *dpy) { _EGLDriver *best_drv; assert(!dpy->Initialized); /* set options */ dpy->Options.UseFallback = env_var_as_boolean("LIBGL_ALWAYS_SOFTWARE", false); best_drv = _eglMatchAndInitialize(dpy); if (!best_drv) { dpy->Options.UseFallback = EGL_TRUE; best_drv = _eglMatchAndInitialize(dpy); } if (best_drv) { _eglLog(_EGL_DEBUG, "the best driver is %s", best_drv->Name); dpy->Driver = best_drv; dpy->Initialized = EGL_TRUE; } return best_drv; }
static const char * droid_get_driver_name(int fd) { int vendor_id = -1, chip_id = -1; int idx, i; char *name; if (!droid_get_pci_id(fd, &vendor_id, &chip_id)) return NULL; for (idx = 0; driver_map[idx].driver; idx++) { if (vendor_id != driver_map[idx].vendor_id) continue; if (driver_map[idx].num_chips_ids == -1) break; for (i = 0; i < driver_map[idx].num_chips_ids; i++) { if (driver_map[idx].chip_ids[i] == chip_id) break; } if (i < driver_map[idx].num_chips_ids) break; } _eglLog(_EGL_INFO, "pci id for fd %d: %04x:%04x, driver %s", fd, vendor_id, chip_id, driver_map[idx].driver); return driver_map[idx].driver; }
/** * Load a module and create the driver object. */ static EGLBoolean _eglLoadModule(_EGLModule *mod) { _EGLMain_t mainFunc; lib_handle lib; _EGLDriver *drv; if (mod->Driver) return EGL_TRUE; if (mod->BuiltIn) { lib = (lib_handle) NULL; mainFunc = mod->BuiltIn; } else { mainFunc = _eglOpenLibrary(mod->Path, &lib); if (!mainFunc) return EGL_FALSE; } drv = mainFunc(NULL); if (!drv) { return EGL_FALSE; } if (!drv->Name) { _eglLog(_EGL_WARNING, "Driver loaded from %s has no name", mod->Path); drv->Name = "UNNAMED"; } mod->Handle = (void *) lib; mod->Driver = drv; return EGL_TRUE; }