Commit 18a52e23 authored by Zhigang Gong's avatar Zhigang Gong

glamor-ddx: Migrate the code to latest mesa library.

Use eglCreateDRMImageMESA to create surfaceless image. And then
export the drm buffer back which can be used to create the frame
buffer.
parent eb3487a4
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
* *
*/ */
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
...@@ -85,11 +88,11 @@ glamor_resize(ScrnInfoPtr scrn, int width, int height) ...@@ -85,11 +88,11 @@ glamor_resize(ScrnInfoPtr scrn, int width, int height)
EGLImageKHR image; EGLImageKHR image;
GLuint texture; GLuint texture;
EGLint attribs[] = { EGLint attribs[] = {
EGL_IMAGE_WIDTH_INTEL, 0, EGL_WIDTH, 0,
EGL_IMAGE_HEIGHT_INTEL, 0, EGL_HEIGHT, 0,
EGL_IMAGE_FORMAT_INTEL, EGL_FORMAT_RGBA_8888_KHR, EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
EGL_IMAGE_USE_INTEL, EGL_IMAGE_USE_SHARE_INTEL | EGL_DRM_BUFFER_USE_MESA, EGL_DRM_BUFFER_USE_SHARE_MESA |
EGL_IMAGE_USE_SCANOUT_INTEL, EGL_DRM_BUFFER_USE_SCANOUT_MESA,
EGL_NONE EGL_NONE
}; };
...@@ -99,9 +102,8 @@ glamor_resize(ScrnInfoPtr scrn, int width, int height) ...@@ -99,9 +102,8 @@ glamor_resize(ScrnInfoPtr scrn, int width, int height)
attribs[1] = width; attribs[1] = width;
attribs[3] = height; attribs[3] = height;
image = eglCreateImageKHR(glamor->display, glamor->context, EGLint name, handle, stride, i;
EGL_SYSTEM_IMAGE_INTEL, image = eglCreateDRMImageMESA(glamor->display, attribs);
NULL, attribs);
if (image == EGL_NO_IMAGE_KHR) if (image == EGL_NO_IMAGE_KHR)
return FALSE; return FALSE;
...@@ -109,14 +111,13 @@ glamor_resize(ScrnInfoPtr scrn, int width, int height) ...@@ -109,14 +111,13 @@ glamor_resize(ScrnInfoPtr scrn, int width, int height)
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image); glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
glamor_set_pixmap_texture(screen->GetScreenPixmap(screen), glamor_set_pixmap_texture(screen->GetScreenPixmap(screen),
width, height, texture); width, height, texture);
glamor->root = image; glamor->root = image;
scrn->virtualX = width; scrn->virtualX = width;
scrn->virtualY = height; scrn->virtualY = height;
return TRUE; return TRUE;
} }
...@@ -125,49 +126,24 @@ glamor_frontbuffer_handle(ScrnInfoPtr scrn, uint32_t *handle, uint32_t *pitch) ...@@ -125,49 +126,24 @@ glamor_frontbuffer_handle(ScrnInfoPtr scrn, uint32_t *handle, uint32_t *pitch)
{ {
struct glamor_screen_private *glamor = glamor_get_screen_private(scrn); struct glamor_screen_private *glamor = glamor_get_screen_private(scrn);
EGLint name; EGLint name;
eglExportDRMImageMESA (glamor->display, glamor->root, &name, (EGLint*) handle, (EGLint*) pitch);
eglShareImageINTEL (glamor->display, glamor->context, glamor->root, 0,
&name, (EGLint *) handle, (EGLint *) pitch);
} }
Bool EGLImageKHR glamor_create_cursor_argb(ScrnInfoPtr scrn, int width, int height)
glamor_load_cursor(ScrnInfoPtr scrn, CARD32 *image, int width, int height)
{ {
struct glamor_screen_private *glamor = glamor_get_screen_private(scrn); struct glamor_screen_private *glamor = glamor_get_screen_private(scrn);
EGLint attribs[] = {
EGL_WIDTH, 0,
EGL_HEIGHT, 0,
EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
EGL_DRM_BUFFER_USE_MESA, EGL_DRM_BUFFER_USE_SHARE_MESA |
EGL_DRM_BUFFER_USE_SCANOUT_MESA | EGL_DRM_BUFFER_USE_CURSOR_MESA,
EGL_NONE
};
if (glamor->cursor == NULL) { attribs[1] = width;
EGLint attribs[] = { attribs[3] = height;
EGL_IMAGE_WIDTH_INTEL, 0, return eglCreateDRMImageMESA(glamor->display, attribs);
EGL_IMAGE_HEIGHT_INTEL, 0,
EGL_IMAGE_FORMAT_INTEL, EGL_FORMAT_RGBA_8888_KHR,
EGL_IMAGE_USE_INTEL, EGL_IMAGE_USE_SHARE_INTEL |
EGL_IMAGE_USE_SCANOUT_INTEL,
EGL_NONE
};
attribs[1] = width;
attribs[3] = height;
glamor->cursor =
eglCreateImageKHR(glamor->display, glamor->context,
EGL_SYSTEM_IMAGE_INTEL,
NULL, attribs);
if (image == EGL_NO_IMAGE_KHR)
return FALSE;
glGenTextures(1, &glamor->cursor_tex);
glBindTexture(GL_TEXTURE_2D, glamor->cursor_tex);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, glamor->cursor);
}
glBindTexture(GL_TEXTURE_2D, glamor->cursor_tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0,
GL_RGBA, GL_UNSIGNED_BYTE, image);
return TRUE;
} }
void void
...@@ -175,9 +151,7 @@ glamor_cursor_handle(ScrnInfoPtr scrn, uint32_t *handle, uint32_t *pitch) ...@@ -175,9 +151,7 @@ glamor_cursor_handle(ScrnInfoPtr scrn, uint32_t *handle, uint32_t *pitch)
{ {
struct glamor_screen_private *glamor = glamor_get_screen_private(scrn); struct glamor_screen_private *glamor = glamor_get_screen_private(scrn);
EGLint name; EGLint name;
eglExportDRMImageMESA (glamor->display, glamor->cursor, &name, (EGLint*) handle, (EGLint*) pitch);
eglShareImageINTEL (glamor->display, glamor->context, glamor->cursor,
0, &name, (EGLint *) handle, (EGLint *) pitch);
ErrorF("cursor stride: %d\n", *pitch); ErrorF("cursor stride: %d\n", *pitch);
} }
...@@ -190,8 +164,7 @@ glamor_pre_init(ScrnInfoPtr scrn, int flags) ...@@ -190,8 +164,7 @@ glamor_pre_init(ScrnInfoPtr scrn, int flags)
glamor = xnfcalloc(sizeof *glamor, 1); glamor = xnfcalloc(sizeof *glamor, 1);
scrn->driverPrivate = glamor; scrn->driverPrivate = glamor;
glamor->fd = open("/dev/dri/card1", O_RDWR);
glamor->fd = open("/dev/dri/card0", O_RDWR);
glamor->cpp = 4; glamor->cpp = 4;
scrn->monitor = scrn->confScreen->monitor; scrn->monitor = scrn->confScreen->monitor;
...@@ -243,7 +216,10 @@ glamor_enter_vt(int scrnIndex, int flags) ...@@ -243,7 +216,10 @@ glamor_enter_vt(int scrnIndex, int flags)
"drmSetMaster failed: %s\n", strerror(errno)); "drmSetMaster failed: %s\n", strerror(errno));
return FALSE; return FALSE;
} }
#if 0
if (!xf86SetDesiredModes(scrn))
return FALSE;
#endif
return TRUE; return TRUE;
} }
...@@ -266,6 +242,7 @@ glamor_create_screen_resources(ScreenPtr screen) ...@@ -266,6 +242,7 @@ glamor_create_screen_resources(ScreenPtr screen)
if (!(*screen->CreateScreenResources) (screen)) if (!(*screen->CreateScreenResources) (screen))
return FALSE; return FALSE;
if (!xf86SetDesiredModes(scrn)) if (!xf86SetDesiredModes(scrn))
return FALSE; return FALSE;
...@@ -300,15 +277,12 @@ glamor_screen_init(int scrnIndex, ScreenPtr screen, int argc, char **argv) ...@@ -300,15 +277,12 @@ glamor_screen_init(int scrnIndex, ScreenPtr screen, int argc, char **argv)
{ {
ScrnInfoPtr scrn = xf86Screens[screen->myNum]; ScrnInfoPtr scrn = xf86Screens[screen->myNum];
struct glamor_screen_private *glamor = glamor_get_screen_private(scrn); struct glamor_screen_private *glamor = glamor_get_screen_private(scrn);
EGLDisplayTypeDRMMESA display;
const char *version; const char *version;
VisualPtr visual;
display.type = EGL_DISPLAY_TYPE_DRM_MESA; glamor->display = eglGetDRMDisplayMESA(glamor->fd);
display.device = NULL; eglBindAPI(EGL_OPENGL_API);
display.fd = glamor->fd; LogMessageVerb(X_INFO, 0, "%s glCreateProgramObjectARB=%p", __FUNCTION__, *(&glCreateProgramObjectARB));
glamor->display = eglGetDisplay((EGLNativeDisplayType) &display);
if (!eglInitialize(glamor->display, &glamor->major, &glamor->minor)) { if (!eglInitialize(glamor->display, &glamor->major, &glamor->minor)) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR, xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"eglInitialize() failed\n"); "eglInitialize() failed\n");
...@@ -325,6 +299,7 @@ glamor_screen_init(int scrnIndex, ScreenPtr screen, int argc, char **argv) ...@@ -325,6 +299,7 @@ glamor_screen_init(int scrnIndex, ScreenPtr screen, int argc, char **argv)
"Failed to create EGL context\n"); "Failed to create EGL context\n");
return FALSE; return FALSE;
} }
if (!eglMakeCurrent(glamor->display, if (!eglMakeCurrent(glamor->display,
EGL_NO_SURFACE, EGL_NO_SURFACE, glamor->context)) { EGL_NO_SURFACE, EGL_NO_SURFACE, glamor->context)) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR, xf86DrvMsg(scrn->scrnIndex, X_ERROR,
...@@ -346,16 +321,29 @@ glamor_screen_init(int scrnIndex, ScreenPtr screen, int argc, char **argv) ...@@ -346,16 +321,29 @@ glamor_screen_init(int scrnIndex, ScreenPtr screen, int argc, char **argv)
1, scrn->bitsPerPixel)) 1, scrn->bitsPerPixel))
return FALSE; return FALSE;
fbPictureInit(screen, NULL, 0); if (scrn->bitsPerPixel > 8) {
/* Fixup RGB ordering */
visual = screen->visuals + screen->numVisuals;
while(--visual >= screen->visuals) {
if ((visual->class | DynamicClass) == DirectColor) {
visual->offsetRed = scrn->offset.red;
visual->offsetGreen = scrn->offset.green;
visual->offsetBlue = scrn->offset.blue;
visual->redMask = scrn->mask.red;
visual->blueMask = scrn->mask.blue;
}
}
}
fbPictureInit(screen, NULL, 0);
xf86SetBlackWhitePixels(screen); xf86SetBlackWhitePixels(screen);
if (!glamor_init(screen)) { if (!glamor_init(screen, GLAMOR_INVERTED_Y_AXIS)) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR, xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"Failed to initialize glamor\n"); "Failed to initialize glamor\n");
return FALSE; return FALSE;
} }
miInitializeBackingStore(screen); miInitializeBackingStore(screen);
xf86SetBackingStore(screen); xf86SetBackingStore(screen);
xf86SetSilkenMouse(screen); xf86SetSilkenMouse(screen);
...@@ -369,7 +357,7 @@ glamor_screen_init(int scrnIndex, ScreenPtr screen, int argc, char **argv) ...@@ -369,7 +357,7 @@ glamor_screen_init(int scrnIndex, ScreenPtr screen, int argc, char **argv)
HARDWARE_CURSOR_INVERT_MASK | HARDWARE_CURSOR_INVERT_MASK |
HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK | HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK |
HARDWARE_CURSOR_AND_SOURCE_WITH_MASK | HARDWARE_CURSOR_AND_SOURCE_WITH_MASK |
HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 | HARDWARE_CURSOR_SOURCE_MASK_NOT_INTERLEAVED |
HARDWARE_CURSOR_UPDATE_UNHIDDEN | HARDWARE_CURSOR_UPDATE_UNHIDDEN |
HARDWARE_CURSOR_ARGB))) { HARDWARE_CURSOR_ARGB))) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR, xf86DrvMsg(scrn->scrnIndex, X_ERROR,
...@@ -389,6 +377,15 @@ glamor_screen_init(int scrnIndex, ScreenPtr screen, int argc, char **argv) ...@@ -389,6 +377,15 @@ glamor_screen_init(int scrnIndex, ScreenPtr screen, int argc, char **argv)
glamor->CloseScreen = screen->CloseScreen; glamor->CloseScreen = screen->CloseScreen;
screen->CloseScreen = glamor_close_screen; screen->CloseScreen = glamor_close_screen;
/* Fixme should we init crtc screen here? */
if (!xf86CrtcScreenInit(screen))
return FALSE;
if (!miCreateDefColormap(screen))
return FALSE;
/* Fixme should we add handle colormap here? */
xf86DPMSInit(screen, xf86DPMSSet, 0);
return TRUE; return TRUE;
} }
...@@ -423,6 +420,8 @@ glamor_probe(struct _DriverRec *drv, int flags) ...@@ -423,6 +420,8 @@ glamor_probe(struct _DriverRec *drv, int flags)
ScrnInfoPtr scrn = NULL; ScrnInfoPtr scrn = NULL;
GDevPtr *sections; GDevPtr *sections;
int entity, n; int entity, n;
LogMessageVerb(X_INFO, 0 , "%s : %d \n", __FUNCTION__, __LINE__);
n = xf86MatchDevice(glamor_name, &sections); n = xf86MatchDevice(glamor_name, &sections);
if (n <= 0) if (n <= 0)
......
...@@ -328,7 +328,7 @@ drmmode_update_fb (ScrnInfoPtr scrn, int width, int height) ...@@ -328,7 +328,7 @@ drmmode_update_fb (ScrnInfoPtr scrn, int width, int height)
drmModeRmFB(drmmode->fd, drmmode->fb_id); drmModeRmFB(drmmode->fd, drmmode->fb_id);
glamor_frontbuffer_handle(scrn, &handle, &pitch); glamor_frontbuffer_handle(scrn, &handle, &pitch);
ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth, ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth,
scrn->bitsPerPixel, pitch * drmmode->cpp, scrn->bitsPerPixel, pitch,
handle, &drmmode->fb_id); handle, &drmmode->fb_id);
if (ret) if (ret)
/* FIXME: Undo glamor_resize() */ /* FIXME: Undo glamor_resize() */
...@@ -461,7 +461,7 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image) ...@@ -461,7 +461,7 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
{ {
ScrnInfoPtr scrn = crtc->scrn; ScrnInfoPtr scrn = crtc->scrn;
glamor_load_cursor(scrn, image, 64, 64); //glamor_load_cursor(scrn, image, 64, 64);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment