Commit e3295d41 authored by Zhigang Gong's avatar Zhigang Gong

glamor-ddx: Move the cursor EGL image to crtc strcture.

Cursor is a per crtc resource. And this commit also fix the cursor
initialization regard to the latest mesa EGL code. Now hardware
cursor works fine.
parent 43280372
......@@ -66,9 +66,8 @@ glamor_identify(int flags)
struct glamor_screen_private {
EGLDisplay display;
EGLContext context;
EGLImageKHR root, cursor;
EGLImageKHR root;
EGLint major, minor;
GLuint cursor_tex;
CreateScreenResourcesProcPtr CreateScreenResources;
CloseScreenProcPtr CloseScreen;
......@@ -149,14 +148,15 @@ EGLImageKHR glamor_create_cursor_argb(ScrnInfoPtr scrn, int width, int height)
}
void
glamor_cursor_handle(ScrnInfoPtr scrn, uint32_t *handle, uint32_t *pitch)
glamor_cursor_handle(ScrnInfoPtr scrn, EGLImageKHR cursor, uint32_t *handle, uint32_t *pitch)
{
struct glamor_screen_private *glamor = glamor_get_screen_private(scrn);
EGLint name;
eglExportDRMImageMESA (glamor->display, glamor->cursor, &name, (EGLint*) handle, (EGLint*) pitch);
eglExportDRMImageMESA (glamor->display, cursor, &name, (EGLint*) handle, (EGLint*) pitch);
ErrorF("cursor stride: %d\n", *pitch);
}
char * dri_device_name = "/dev/dri/card0";
static Bool
glamor_pre_init(ScrnInfoPtr scrn, int flags)
{
......@@ -166,7 +166,12 @@ glamor_pre_init(ScrnInfoPtr scrn, int flags)
glamor = xnfcalloc(sizeof *glamor, 1);
scrn->driverPrivate = glamor;
glamor->fd = open("/dev/dri/card1", O_RDWR);
glamor->fd = open(dri_device_name, O_RDWR);
if (glamor->fd == -1 ) {
ErrorF("Failed to open %s: %s\n", dri_device_name, strerror(errno));
goto fail;
}
glamor->cpp = 4;
scrn->monitor = scrn->confScreen->monitor;
......@@ -174,22 +179,21 @@ glamor_pre_init(ScrnInfoPtr scrn, int flags)
scrn->rgbBits = 8;
if (!xf86SetDepthBpp(scrn, 0, 0, 0, Support32bppFb))
return FALSE;
goto fail;
xf86PrintDepthBpp(scrn);
if (!xf86SetWeight(scrn, defaultWeight, defaultWeight))
return FALSE;
goto fail;
if (!xf86SetDefaultVisual(scrn, -1))
return FALSE;
goto fail;
glamor->cpp = scrn->bitsPerPixel / 8;
if (drmmode_pre_init(scrn, glamor->fd, glamor->cpp) == FALSE) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"Kernel modesetting setup failed\n");
xfree(glamor);
return FALSE;
goto fail;
}
scrn->currentMode = scrn->modes;
......@@ -197,9 +201,13 @@ glamor_pre_init(ScrnInfoPtr scrn, int flags)
/* Load the required sub modules */
if (!xf86LoadSubModule(scrn, "fb"))
return FALSE;
goto fail;
return TRUE;
fail:
scrn->driverPrivate = NULL;
xfree(glamor);
}
static void
......@@ -396,10 +404,12 @@ glamor_free_screen(int scrnIndex, int flags)
{
ScrnInfoPtr scrn = xf86Screens[scrnIndex];
struct glamor_screen_private *glamor = glamor_get_screen_private(scrn);
close(glamor->fd);
xfree(scrn->driverPrivate);
scrn->driverPrivate = NULL;
if (glamor != NULL)
{
close(glamor->fd);
xfree(glamor);
scrn->driverPrivate = NULL;
}
}
static ModeStatus
......@@ -422,8 +432,6 @@ glamor_probe(struct _DriverRec *drv, int flags)
ScrnInfoPtr scrn = NULL;
GDevPtr *sections;
int entity, n;
LogMessageVerb(X_INFO, 0 , "%s : %d \n", __FUNCTION__, __LINE__);
n = xf86MatchDevice(glamor_name, &sections);
if (n <= 0)
......
......@@ -48,6 +48,14 @@
#include <xf86Crtc.h>
#include <xf86DDC.h>
#include <xorgVersion.h>
#include <libkms/libkms.h>
#define GL_GLEXT_PROTOTYPES
#define EGL_EGLEXT_PROTOTYPES
#define EGL_DISPLAY_NO_X_MESA
#include <GL/gl.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include "glamor_ddx.h"
......@@ -67,6 +75,7 @@ typedef struct {
drmmode_ptr drmmode;
drmModeCrtcPtr mode_crtc;
uint32_t rotate_fb_id;
EGLImageKHR cursor;
unsigned int cursor_tex;
} drmmode_crtc_private_rec, *drmmode_crtc_private_ptr;
......@@ -328,7 +337,7 @@ drmmode_update_fb (ScrnInfoPtr scrn, int width, int height)
drmModeRmFB(drmmode->fd, drmmode->fb_id);
glamor_frontbuffer_handle(scrn, &handle, &pitch);
ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth,
scrn->bitsPerPixel, pitch,
scrn->bitsPerPixel, pitch /** drmmode->cpp*/,
handle, &drmmode->fb_id);
if (ret)
/* FIXME: Undo glamor_resize() */
......@@ -459,9 +468,31 @@ drmmode_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
static void
drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
{
drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
drmmode_ptr drmmode = drmmode_crtc->drmmode;
ScrnInfoPtr scrn = crtc->scrn;
//glamor_load_cursor(scrn, image, 64, 64);
if (drmmode_crtc->cursor == NULL)
{
drmmode_crtc->cursor = glamor_create_cursor_argb(scrn, 64, 64);
if (drmmode_crtc->cursor == EGL_NO_IMAGE_KHR)
return;
glGenTextures(1, &drmmode_crtc->cursor_tex);
glBindTexture(GL_TEXTURE_2D, drmmode_crtc->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, drmmode_crtc->cursor);
}
glPixelStorei(GL_UNPACK_ROW_LENGTH, 64);
glBindTexture(GL_TEXTURE_2D, drmmode_crtc->cursor_tex);
// memset(image, 0xff, 64*64*4);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0,
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image);
}
......@@ -484,7 +515,7 @@ drmmode_show_cursor (xf86CrtcPtr crtc)
uint32_t handle, stride;
ErrorF("show cursor\n");
glamor_cursor_handle(scrn, &handle, &stride);
glamor_cursor_handle(scrn, drmmode_crtc->cursor, &handle, &stride);
drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
handle, 64, 64);
......@@ -596,6 +627,7 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
.show_cursor = drmmode_show_cursor,
.hide_cursor = drmmode_hide_cursor,
.load_cursor_argb = drmmode_load_cursor_argb,
.load_cursor_image = NULL,
#if 0
.shadow_create = drmmode_crtc_shadow_create,
.shadow_allocate = drmmode_crtc_shadow_allocate,
......@@ -1311,9 +1343,10 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
if (!crtc->enabled)
continue;
#if 0
drmmode_set_mode_major(crtc, &crtc->mode,
crtc->rotation, crtc->x, crtc->y);
#endif
}
return TRUE;
......
......@@ -6,8 +6,8 @@ void glamor_frontbuffer_handle(ScrnInfoPtr scrn,
uint32_t *handle, uint32_t *pitch);
Bool glamor_load_cursor(ScrnInfoPtr scrn,
CARD32 *image, int width, int height);
void glamor_cursor_handle(ScrnInfoPtr scrn,
uint32_t *handle, uint32_t *pitch);
void glamor_cursor_handle(ScrnInfoPtr scrn, EGLImageKHR image, uint32_t *handle, uint32_t *pitch);
Bool drmmode_pre_init(ScrnInfoPtr scrn, int fd, int cpp);
void drmmode_closefb(ScrnInfoPtr scrn);
......
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