static DFBResult x11AllocateKey( CoreSurfacePool *pool, void *pool_data, void *pool_local, CoreSurfaceBuffer *buffer, const char *key, u64 handle, CoreSurfaceAllocation *allocation, void *alloc_data ) { CoreSurface *surface; x11AllocationData *alloc = alloc_data; x11PoolLocalData *local = pool_local; DFBX11 *x11 = local->x11; D_DEBUG_AT( X11_Surfaces, "%s( %s, 0x%08llx )\n", __FUNCTION__, key, (unsigned long long) handle ); D_DEBUG_AT( X11_Surfaces, " -> allocation: %s\n", ToString_CoreSurfaceAllocation( allocation ) ); D_MAGIC_ASSERT( pool, CoreSurfacePool ); D_MAGIC_ASSERT( buffer, CoreSurfaceBuffer ); surface = buffer->surface; D_MAGIC_ASSERT( surface, CoreSurface ); if (!strcmp( key, "Pixmap/X11" )) { D_DEBUG_AT( X11_Surfaces, " -> Pixmap/X11\n" ); alloc->type = X11_ALLOC_PIXMAP; } else if (!strcmp( key, "Window/X11" )) { D_DEBUG_AT( X11_Surfaces, " -> Window/X11\n" ); alloc->type = X11_ALLOC_WINDOW; } else { D_BUG( "unexpected key '%s'", key ); return DFB_BUG; } dfb_surface_calc_buffer_size( surface, 8, 8, &alloc->pitch, &allocation->size ); // alloc->depth = DefaultDepthOfScreen( x11->screenptr ); // alloc->visual = DefaultVisualOfScreen( x11->screenptr ); alloc->visual = x11->visuals[DFB_PIXELFORMAT_INDEX(buffer->format)]; alloc->depth = DFB_COLOR_BITS_PER_PIXEL( buffer->format ) + DFB_ALPHA_BITS_PER_PIXEL( buffer->format ); if (alloc->depth == DefaultDepthOfScreen( x11->screenptr )) alloc->visual = DefaultVisualOfScreen( x11->screenptr ); D_DEBUG_AT( X11_Surfaces, " -> visual %p (id %lu), depth %d\n", alloc->visual, alloc->visual->visualid, alloc->depth ); if (handle) { switch (alloc->type) { case X11_ALLOC_PIXMAP: XLockDisplay( x11->display ); alloc->xid = (unsigned long) handle; x11->Sync( x11 ); D_DEBUG_AT( X11_Surfaces, " -> pixmap 0x%08lx\n", (long) alloc->xid ); XUnlockDisplay( x11->display ); D_INFO( "X11/Windows: Import Pixmap 0x%08lx\n", alloc->xid ); break; case X11_ALLOC_WINDOW: { XLockDisplay( x11->display ); alloc->window = (unsigned long) handle; x11->Sync( x11 ); D_DEBUG_AT( X11_Surfaces, " -> window 0x%08lx\n", (long) alloc->window ); XCompositeRedirectWindow( x11->display, alloc->window, CompositeRedirectManual ); x11->Sync( x11 ); D_DEBUG_AT( X11_Surfaces, " -> redirected\n" ); alloc->xid = XCompositeNameWindowPixmap( x11->display, alloc->window ); // alloc->xid = alloc->window; x11->Sync( x11 ); D_DEBUG_AT( X11_Surfaces, " -> pixmap 0x%08lx\n", (long) alloc->xid ); XUnmapWindow( x11->display, alloc->window ); x11->Sync( x11 ); D_DEBUG_AT( X11_Surfaces, " -> unmapped\n" ); XUnlockDisplay( x11->display ); D_INFO( "X11/Windows: Import Window 0x%08lx with Pixmap handle 0x%08lx\n", alloc->window, alloc->xid ); break; } default: D_BUG( "unexpected allocation type %d\n", alloc->type ); return DFB_BUG; } } else { // alloc->type = X11_ALLOC_PIXMAP; switch (alloc->type) { case X11_ALLOC_PIXMAP: XLockDisplay( x11->display ); x11->Sync( x11 ); D_DEBUG_AT( X11_Surfaces, " -> creating pixmap...\n" ); alloc->xid = XCreatePixmap( x11->display, DefaultRootWindow(x11->display), allocation->config.size.w, allocation->config.size.h, alloc->depth ); x11->Sync( x11 ); XSync( x11->display, False ); D_DEBUG_AT( X11_Surfaces, " -> pixmap 0x%08lx\n", (long) alloc->xid ); XUnlockDisplay( x11->display ); D_INFO( "X11/Windows: New Pixmap 0x%08lx\n", alloc->xid ); alloc->created = true; break; case X11_ALLOC_WINDOW: { Window w = (Window) (long) buffer->surface->data; XSetWindowAttributes attr; attr.event_mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask | KeyPressMask | KeyReleaseMask | ExposureMask | StructureNotifyMask; attr.background_pixmap = 0; XLockDisplay( x11->display ); x11->Sync( x11 ); D_DEBUG_AT( X11_Surfaces, " -> creating window...\n" ); alloc->window = w?:XCreateWindow( x11->display, DefaultRootWindow(x11->display), 600, 200, allocation->config.size.w, allocation->config.size.h, 0, alloc->depth, InputOutput, alloc->visual, CWEventMask, &attr ); x11->Sync( x11 ); D_DEBUG_AT( X11_Surfaces, " -> window 0x%08lx\n", (long) alloc->window ); buffer->surface->data = (void*) (long) alloc->window; XMapRaised( x11->display, alloc->window ); x11->Sync( x11 ); D_DEBUG_AT( X11_Surfaces, " -> raised\n" ); XCompositeRedirectWindow( x11->display, alloc->window, CompositeRedirectManual ); x11->Sync( x11 ); D_DEBUG_AT( X11_Surfaces, " -> redirected\n" ); alloc->xid = XCompositeNameWindowPixmap( x11->display, alloc->window ); // alloc->xid = alloc->window; x11->Sync( x11 ); D_DEBUG_AT( X11_Surfaces, " -> pixmap 0x%08lx\n", (long) alloc->xid ); XUnmapWindow( x11->display, alloc->window ); x11->Sync( x11 ); D_DEBUG_AT( X11_Surfaces, " -> unmapped\n" ); XUnlockDisplay( x11->display ); D_INFO( "X11/Windows: New Window 0x%08lx with Pixmap handle 0x%08lx\n", alloc->window, alloc->xid ); alloc->created = !w; break; } default: D_BUG( "unexpected allocation type %d\n", alloc->type ); return DFB_BUG; } } alloc->gc = XCreateGC( x11->display, alloc->xid, 0, NULL ); allocation->offset = alloc->type; return DFB_OK; }
DFBResult GetConfigAttribs::eglGetConfigAttribs( EGL::Display &display, EGLNativePixmapType native, EGLint *attribs, EGLint max ) { D_DEBUG_AT( DFBEGL_GetConfigAttribs, "%s( display %p, native %p, attribs %p, max %d )\n", __FUNCTION__, &display, native, attribs, max ); if (!attribs) return DFB_INVARG; DFB_EGL_ATTRIB_LIST_DEBUG_AT( DFBEGL_GetConfigAttribs, attribs ); IDirectFBSurface *surface = (IDirectFBSurface *) native; for (EGLint *v=attribs; *v != EGL_NONE; v+=2) { if (max > 0 && v-attribs >= max) { D_DEBUG_AT( DFBEGL_GetConfigAttribs, " -> max (%d) reached (%ld)\n", max, v-attribs ); break; } EGLint attribute = v[0]; EGLint value = v[1]; DFBSurfacePixelFormat format; DFBDimension size; D_DEBUG_AT( DFBEGL_GetConfigAttribs, " -> [%ld] 0x%04x '%s' <- %d (0x%08x)\n", v-attribs, attribute, **EGLInt(attribute), value, value ); switch (attribute) { case EGL_BUFFER_SIZE: surface->GetPixelFormat( surface, &format ); value = DFB_COLOR_BITS_PER_PIXEL( format ); break; case EGL_ALPHA_SIZE: surface->GetPixelFormat( surface, &format ); value = DFB_ALPHA_BITS_PER_PIXEL( format ); break; case EGL_BLUE_SIZE: case EGL_GREEN_SIZE: case EGL_RED_SIZE: surface->GetPixelFormat( surface, &format ); value = DFB_COLOR_BITS_PER_PIXEL( format ) / 3;//FIXME break; //case EGL_DEPTH_SIZE: //case EGL_STENCIL_SIZE: //case EGL_RENDERABLE_TYPE: case EGL_SURFACE_TYPE: value = EGL_WINDOW_BIT; // FIXME break; case EGL_WIDTH: // keep? not a config attribute actually surface->GetSize( surface, &size.w, &size.h ); value = size.w; break; case EGL_HEIGHT: // keep? not a config attribute actually surface->GetSize( surface, &size.w, &size.h ); value = size.h; break; default: D_DEBUG_AT( DFBEGL_GetConfigAttribs, " -> UNRECOGNIZED!!!\n" ); continue; } D_DEBUG_AT( DFBEGL_GetConfigAttribs, " => %d (0x%08x)\n", value, value ); v[1] = value; } D_DEBUG_AT( DFBEGL_GetConfigAttribs, " --> DONE -------------\n" ); DFB_EGL_ATTRIB_LIST_DEBUG_AT( DFBEGL_GetConfigAttribs, attribs ); return DFB_OK; }