mirror of
https://github.com/VincentWei/MiniGUI.git
synced 2026-02-07 02:52:42 +08:00
GetSurfaceHandle -> GetVideoHandle; tune driGetDeviceFD and driGetSurfaceInfo; add driCreateDCFromName and driCreateDCFromHandle
This commit is contained in:
@@ -1407,6 +1407,8 @@ static GAL_Surface *DRI_SetVideoMode_Accl(_THIS, GAL_Surface *current,
|
||||
_ERR_PRINTF ("NEWGAL>DRM: cannot create scanout frame buffer: %m\n");
|
||||
goto error;
|
||||
}
|
||||
/* not a foreign surface */
|
||||
scanout_buff->foreign = 0;
|
||||
|
||||
if (NULL == vdata->driver_ops->map_buffer(vdata->driver, scanout_buff)) {
|
||||
_ERR_PRINTF ("NEWGAL>DRM: cannot map scanout frame buffer: %m\n");
|
||||
@@ -1506,6 +1508,8 @@ static int DRI_AllocHWSurface_Accl(_THIS, GAL_Surface *surface)
|
||||
if (surface_buffer == NULL) {
|
||||
return -1;
|
||||
}
|
||||
/* not a foreign surface */
|
||||
surface_buffer->foreign = 0;
|
||||
|
||||
if (vdata->driver_ops->map_buffer(vdata->driver, surface_buffer) == NULL) {
|
||||
_ERR_PRINTF ("NEWGAL>DRM: cannot map hardware buffer: %m\n");
|
||||
@@ -1648,9 +1652,9 @@ static int DRI_SetHWAlpha_Accl(_THIS, GAL_Surface *surface, Uint8 value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
MG_EXPORT int driGetDeviceFD (GHANDLE surface)
|
||||
MG_EXPORT int driGetDeviceFD (GHANDLE video)
|
||||
{
|
||||
GAL_VideoDevice *this = (GAL_VideoDevice *)((GAL_Surface*)surface)->video;
|
||||
GAL_VideoDevice *this = (GAL_VideoDevice *)video;
|
||||
if (this && this->VideoInit == DRI_VideoInit) {
|
||||
DriVideoData* vdata = this->hidden;
|
||||
return vdata->dev_fd;
|
||||
@@ -1659,9 +1663,9 @@ MG_EXPORT int driGetDeviceFD (GHANDLE surface)
|
||||
return -1;
|
||||
}
|
||||
|
||||
MG_EXPORT BOOL driGetSurfaceInfo (GHANDLE surface_handle, DriSurfaceInfo* info)
|
||||
/* called by driGetSurfaceInfo */
|
||||
BOOL __dri_get_surface_info (GAL_Surface *surface, DriSurfaceInfo* info)
|
||||
{
|
||||
GAL_Surface *surface = (GAL_Surface*)surface_handle;
|
||||
GAL_VideoDevice *this = (GAL_VideoDevice *)surface->video;
|
||||
|
||||
if (this && this->VideoInit == DRI_VideoInit &&
|
||||
@@ -1683,5 +1687,183 @@ MG_EXPORT BOOL driGetSurfaceInfo (GHANDLE surface_handle, DriSurfaceInfo* info)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* called by driCreateDCFromName */
|
||||
GAL_Surface* __dri_create_surface_from_name (GHANDLE video,
|
||||
uint32_t name, 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;
|
||||
}
|
||||
|
||||
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_name(vdata->driver,
|
||||
name, drm_format, width, height, pitch);
|
||||
if (surface_buffer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
/* not a foreign surface */
|
||||
surface_buffer->foreign = 0;
|
||||
|
||||
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 driCreateDCFromHandle */
|
||||
GAL_Surface* __dri_create_surface_from_handle (GHANDLE video,
|
||||
uint32_t handle, 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;
|
||||
}
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
#endif /* _MGGAL_DRI */
|
||||
|
||||
|
||||
133
src/newgdi/gdi.c
133
src/newgdi/gdi.c
@@ -3709,12 +3709,6 @@ MG_EXPORT int GUIAPI SetUserCompositionOps (HDC hdc, CB_COMP_SETPIXEL comp_setpi
|
||||
return old_rop;
|
||||
}
|
||||
|
||||
MG_EXPORT GHANDLE GetSurfaceHandle (HDC hdc)
|
||||
{
|
||||
PDC pdc = dc_HDC2PDC (hdc);
|
||||
return (GHANDLE)pdc->surface;
|
||||
}
|
||||
|
||||
MG_EXPORT BOOL GUIAPI SyncUpdateDC (HDC hdc)
|
||||
{
|
||||
#ifdef _MGUSE_SYNC_UPDATE
|
||||
@@ -3737,3 +3731,130 @@ MG_EXPORT BOOL GUIAPI IsMemDC (HDC hdc)
|
||||
return dc_IsMemDC (pdc);
|
||||
}
|
||||
|
||||
MG_EXPORT GHANDLE GetVideoHandle (HDC hdc)
|
||||
{
|
||||
PDC pdc = dc_HDC2PDC (hdc);
|
||||
return (GHANDLE)pdc->surface->video;
|
||||
}
|
||||
|
||||
#ifdef _MGGAL_DRI
|
||||
|
||||
/* implemented in DRI engine. */
|
||||
BOOL __dri_get_surface_info (GAL_Surface *surface, DriSurfaceInfo* info);
|
||||
|
||||
MG_EXPORT BOOL driGetSurfaceInfo (GHANDLE video, HDC hdc, DriSurfaceInfo* info)
|
||||
{
|
||||
PDC pdc = dc_HDC2PDC (hdc);
|
||||
if (pdc->surface->video != (GHANDLE)video)
|
||||
return FALSE;
|
||||
|
||||
return __dri_get_surface_info(pdc->surface, info);
|
||||
}
|
||||
|
||||
/* implemented in DRI engine. */
|
||||
GAL_Surface* __dri_create_surface_from_name (GHANDLE video,
|
||||
uint32_t name, uint32_t drm_format,
|
||||
unsigned int width, unsigned int height, uint32_t pitch);
|
||||
|
||||
MG_EXPORT HDC driCreateDCFromName (GHANDLE video,
|
||||
uint32_t name, 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_name (video, name,
|
||||
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;
|
||||
}
|
||||
|
||||
/* implemented in DRI engine. */
|
||||
GAL_Surface* __dri_create_surface_from_handle (GHANDLE video,
|
||||
uint32_t handle, unsigned long size, uint32_t drm_format,
|
||||
unsigned int width, unsigned int height, uint32_t pitch);
|
||||
|
||||
MG_EXPORT HDC driCreateDCFromHandle (GHANDLE video,
|
||||
uint32_t handle, 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_handle (video, handle, 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
|
||||
|
||||
Reference in New Issue
Block a user