diff --git a/src/newgal/dri/drivideo.c b/src/newgal/dri/drivideo.c index 62413c23..0496c6eb 100644 --- a/src/newgal/dri/drivideo.c +++ b/src/newgal/dri/drivideo.c @@ -295,7 +295,7 @@ static int open_drm_device(GAL_VideoDevice *device) device->hidden->dev_fd = device_fd; device->hidden->driver = device->hidden->driver_ops->create_driver(device_fd); if (device->hidden->driver == NULL) { - _WRN_PRINTF("NEWGAL>DRM: failed to create DRM driver"); + _WRN_PRINTF("NEWGAL>DRM: failed to create DRM driver\n"); device->hidden->driver_ops = NULL; } @@ -325,7 +325,7 @@ static GAL_VideoDevice *DRI_CreateDevice(int devindex) if (GetMgEtcValue ("dri", "device", device->hidden->dev_name, LEN_DEVICE_NAME) < 0) { strcpy(device->hidden->dev_name, "/dev/dri/card0"); - _WRN_PRINTF("NEWGAL>DRM: No dri.device defined, use the default '/dev/dri/card0'"); + _WRN_PRINTF("NEWGAL>DRM: No dri.device defined, use the default '/dev/dri/card0'\n"); } device->hidden->dev_fd = -1; @@ -1703,6 +1703,11 @@ GAL_Surface* __dri_create_surface_from_name (GHANDLE video, return NULL; } + if (vdata->driver_ops->create_buffer_from_name == NULL) { + _ERR_PRINTF ("NEWGAL>DRM: not implemented method: create_buffer_from_name!\n"); + return NULL; + } + depth = translate_drm_format(drm_format, RGBAmasks); if (depth == 0) { _ERR_PRINTF("NEWGAL>DRM: not supported drm format: %u\n", @@ -1713,6 +1718,7 @@ GAL_Surface* __dri_create_surface_from_name (GHANDLE video, surface_buffer = vdata->driver_ops->create_buffer_from_name(vdata->driver, name, drm_format, width, height, pitch); if (surface_buffer == NULL) { + _ERR_PRINTF ("NEWGAL>DRM: create_buffer_from_name failed!\n"); return NULL; } /* not a foreign surface */ @@ -1792,6 +1798,106 @@ GAL_Surface* __dri_create_surface_from_handle (GHANDLE video, return NULL; } + if (vdata->driver_ops->create_buffer_from_handle == NULL) { + _ERR_PRINTF ("NEWGAL>DRM: not implemented method: create_buffer_from_handle!\n"); + return NULL; + } + + depth = translate_drm_format (drm_format, RGBAmasks); + if (depth == 0) { + _ERR_PRINTF ("NEWGAL>DRM: not supported drm format: %u\n", + drm_format); + return NULL; + } + + surface_buffer = vdata->driver_ops->create_buffer_from_handle (vdata->driver, + handle, size, drm_format, width, height, pitch); + if (surface_buffer == NULL) { + _ERR_PRINTF ("NEWGAL>DRM: create_buffer_from_handle failed!\n"); + return NULL; + } + /* this is a foreign surface */ + surface_buffer->foreign = 1; + + if (vdata->driver_ops->map_buffer (vdata->driver, surface_buffer) == NULL) { + _ERR_PRINTF ("NEWGAL>DRM: cannot map hardware buffer: %m\n"); + goto error; + } + + /* Allocate the surface */ + surface = (GAL_Surface *)malloc (sizeof(*surface)); + if (surface == NULL) { + goto error; + } + + /* Allocate the format */ + surface->format = GAL_AllocFormat (depth, RGBAmasks[0], RGBAmasks[1], + RGBAmasks[2], RGBAmasks[3]); + if (surface->format == NULL) { + goto error; + return(NULL); + } + + /* Allocate an empty mapping */ + surface->map = GAL_AllocBlitMap (); + if (surface->map == NULL) { + goto error; + } + + surface->format_version = 0; + surface->video = this; + surface->flags = GAL_HWSURFACE; + surface->dpi = GDCAP_DPI_DEFAULT; + surface->w = width; + surface->h = height; + surface->pitch = pitch; + surface->offset = 0; + surface->pixels = surface_buffer->pixels; + surface->hwdata = (struct private_hwdata *)surface_buffer; + + /* The surface is ready to go */ + surface->refcount = 1; + + GAL_SetClipRect(surface, NULL); + +#ifdef _MGUSE_SYNC_UPDATE + /* Initialize update region */ + InitClipRgn (&surface->update_region, &__mg_free_update_region_list); +#endif + + return(surface); + +error: + if (surface) + GAL_FreeSurface(surface); + + if (surface_buffer) + vdata->driver_ops->destroy_buffer(vdata->driver, surface_buffer); + + return NULL; +} + +/* called by driCreateDCFromPrimeFd */ +GAL_Surface* __dri_create_surface_from_prime_fd (GHANDLE video, + int prime_fd, unsigned long size, uint32_t drm_format, + unsigned int width, unsigned int height, uint32_t pitch) +{ + GAL_VideoDevice *this = (GAL_VideoDevice *)video; + DriVideoData* vdata = this->hidden; + DriSurfaceBuffer* surface_buffer; + GAL_Surface* surface = NULL; + Uint32 RGBAmasks[4]; + int depth; + + if (this && this->VideoInit != DRI_VideoInit) { + return NULL; + } + + if (vdata->driver_ops->create_buffer_from_prime_fd == NULL) { + _ERR_PRINTF ("NEWGAL>DRM: not implemented method: create_buffer_from_prime_fd.\n"); + return NULL; + } + depth = translate_drm_format(drm_format, RGBAmasks); if (depth == 0) { _ERR_PRINTF("NEWGAL>DRM: not supported drm format: %u\n", @@ -1799,15 +1905,16 @@ GAL_Surface* __dri_create_surface_from_handle (GHANDLE video, return NULL; } - surface_buffer = vdata->driver_ops->create_buffer_from_handle(vdata->driver, - handle, size, drm_format, width, height, pitch); + surface_buffer = vdata->driver_ops->create_buffer_from_prime_fd (vdata->driver, + prime_fd, size, drm_format, width, height, pitch); if (surface_buffer == NULL) { + _ERR_PRINTF ("NEWGAL>DRM: create_buffer_from_prime_fd failed!\n"); return NULL; } - /* this is a foreign surface */ + /* not a foreign surface */ surface_buffer->foreign = 1; - if (vdata->driver_ops->map_buffer(vdata->driver, surface_buffer) == NULL) { + if (vdata->driver_ops->map_buffer (vdata->driver, surface_buffer) == NULL) { _ERR_PRINTF ("NEWGAL>DRM: cannot map hardware buffer: %m\n"); goto error; } diff --git a/src/newgdi/gdi.c b/src/newgdi/gdi.c index dccaaaf0..44fe2108 100644 --- a/src/newgdi/gdi.c +++ b/src/newgdi/gdi.c @@ -233,7 +233,7 @@ void mg_TerminateScreenDC (void) #define INIT_SPECIFICAL_FONTS(etc_section) \ { \ if (!font_InitSpecificalFonts (etc_section)) { \ - _WRN_PRINTF ("Can not initialize fonts defined in section %s!", etc_section); \ + _WRN_PRINTF ("Can not initialize fonts defined in section %s!\n", etc_section); \ goto error; \ } \ } @@ -242,7 +242,7 @@ void mg_TerminateScreenDC (void) BOOL mg_InitGDI (void) { if (!InitTextBitmapBuffer ()) { - _WRN_PRINTF ("Can not initialize text bitmap buffer!"); + _WRN_PRINTF ("Can not initialize text bitmap buffer!\n"); goto error; } @@ -264,7 +264,7 @@ BOOL mg_InitGDI (void) #if (defined (_MGFONT_TTF) || defined (_MGFONT_FT2)) && defined(_MGRM_THREADS) if (!font_InitFreetypeLibrary ()) { - _WRN_PRINTF ("Can not initialize freetype fonts!"); + _WRN_PRINTF ("Can not initialize freetype fonts!\n"); goto error; } INIT_SPECIFICAL_FONTS (FONT_ETC_SECTION_NAME_TTF); @@ -273,13 +273,13 @@ BOOL mg_InitGDI (void) /* TODO: add other font support here */ #if defined (_MGFONT_SEF) && !defined(_LITE_VERSION) if(!initialize_scripteasy()) { - _WRN_PRINTF ("Can not initialize ScriptEasy fonts!"); + _WRN_PRINTF ("Can not initialize ScriptEasy fonts!\n"); goto error; } #endif if (!font_InitIncoreFonts ()) { - _WRN_PRINTF ("Can not initialize incore fonts!"); + _WRN_PRINTF ("Can not initialize incore fonts!\n"); goto error; } @@ -288,7 +288,7 @@ BOOL mg_InitGDI (void) #endif if (!mg_InitSysFont ()) { - _WRN_PRINTF ("Can not create system fonts!"); + _WRN_PRINTF ("Can not create system fonts!\n"); goto error; } @@ -2660,7 +2660,7 @@ HDC GetSecondarySubDC (HDC secondary_dc, HWND hwnd_child, BOOL client) UNLOCK(&dcslot); if (i >= DCSLOTNUMBER) { - _WRN_PRINTF ("NEWGDI>GetSecondarySubDC: no DC slot."); + _WRN_PRINTF ("No DC slot.\n"); return HDC_SCREEN; } @@ -3405,7 +3405,7 @@ HDC GUIAPI InitSlaveScreenEx (const char* name, const char* mode, int dpi) } else { free (pmem_dc); - _WRN_PRINTF ("Can not init the slave screen: %s (%s)", + _WRN_PRINTF ("Can not init the slave screen: %s (%s)\n", name, mode); return HDC_INVALID; } @@ -3857,4 +3857,57 @@ MG_EXPORT HDC driCreateDCFromHandle (GHANDLE video, return (HDC)pmem_dc; } +/* implemented in DRI engine. */ +GAL_Surface* __dri_create_surface_from_prime_fd (GHANDLE video, + int prime_fd, unsigned long size, uint32_t drm_format, + unsigned int width, unsigned int height, uint32_t pitch); + +MG_EXPORT HDC driCreateDCFromPrimeFd (GHANDLE video, + int prime_fd, unsigned long size, uint32_t drm_format, + unsigned int width, unsigned int height, uint32_t pitch) +{ + PDC pmem_dc = NULL; + GAL_Surface* surface; + + if (!(pmem_dc = malloc (sizeof(DC)))) + return HDC_INVALID; + + LOCK (&__mg_gdilock); + surface =__dri_create_surface_from_prime_fd (video, prime_fd, size, + drm_format, width, height, pitch); + UNLOCK (&__mg_gdilock); + + if (!surface) { + free (pmem_dc); + return HDC_INVALID; + } + + if (surface->format->Amask) { + surface->flags |= GAL_SRCPIXELALPHA; + } + + pmem_dc->DataType = TYPE_HDC; + pmem_dc->DCType = TYPE_MEMDC; + pmem_dc->inuse = TRUE; + pmem_dc->surface = surface; + + dc_InitDC (pmem_dc, HWND_DESKTOP, FALSE); + + InitClipRgn (&pmem_dc->lcrgn, &__mg_FreeClipRectList); + MAKE_REGION_INFINITE(&pmem_dc->lcrgn); + InitClipRgn (&pmem_dc->ecrgn, &__mg_FreeClipRectList); + pmem_dc->pGCRInfo = NULL; + pmem_dc->oldage = 0; + + pmem_dc->DevRC.left = 0; + pmem_dc->DevRC.top = 0; + pmem_dc->DevRC.right = width; + pmem_dc->DevRC.bottom = height; + + SetClipRgn (&pmem_dc->ecrgn, &pmem_dc->DevRC); + IntersectClipRect(&pmem_dc->lcrgn, &pmem_dc->DevRC); + + return (HDC)pmem_dc; +} + #endif