Commit b861aad8 authored by Zhigang Gong's avatar Zhigang Gong Committed by Eric Anholt

Initial version.

Signed-off-by: default avatarZhigang Gong <zhigang.gong@linux.intel.com>
parent 2dbbe256
noinst_LTLIBRARIES = libglamor.la
inst_LTLIBRARIES = libglamor.la
# Override these since glamor doesn't need them and the needed files aren't
# built (in hw/xfree86/os-support/solaris) until after glamor is built
SOLARIS_ASM_CFLAGS=""
if XORG
sdk_HEADERS = glamor.h
endif
if GLAMOR_GLES2
libglamor_la_LIBADD = $(GLESV2_LIBS)
else
libglamor_la_LIBADD = $(GL_LIBS)
endif
if XORG
sdk_HEADERS = glamor.h
endif
instdir = $(moduledir)
INCLUDES = \
$(XORG_INCS)
AM_CFLAGS = $(XORG_CFLAGS) $(DIX_CFLAGS) $(LIBDRM_CFLAGS)
libglamor_la_LDFLAGS = -avoid-version
libglamor_la_SOURCES = \
glamor.c \
glamor_copyarea.c \
......@@ -45,3 +40,17 @@ libglamor_la_SOURCES = \
glamor_window.c\
glamor_gl_dispatch.c\
glamor.h
sdk_HEADERS = glamor.h
if EGL
LIBGLAMOR_EGL = libglamor_egl.la
module_LTLIBRARIES = $(LIBGLAMOR_EGL)
libglamor_egl_la_DEPENDENCIES = libglamor.la
libglamor_egl_la_LDFLAGS = -avoid-version -module $(EGL_LIBS) -lglamor
#libglamor_egl_la_LIBADD = $(top_builddir)/src/libglamor.la
libglamor_egl_la_SOURCES = glamor_eglmodule.c $(top_srcdir)/src/glamor_egl.c
libglamor_egl_la_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/src $(LIBDRM_CFLAGS) $(EGL_CFLAGS)
endif
This diff is collapsed.
......@@ -39,25 +39,43 @@
#include "fb.h"
#include "fbpict.h"
#endif /* GLAMOR_H */
#endif /* GLAMOR_H */
#define GLAMOR_INVERTED_Y_AXIS 1
#define GLAMOR_HOSTX 2
#define GLAMOR_VALID_FLAGS (GLAMOR_INVERTED_Y_AXIS | GLAMOR_HOSTX)
#define GLAMOR_INVERTED_Y_AXIS 1
#define GLAMOR_USE_SCREEN 2
#define GLAMOR_USE_PICTURE_SCREEN 4
#define GLAMOR_VALID_FLAGS (GLAMOR_INVERTED_Y_AXIS \
| GLAMOR_USE_SCREEN \
| GLAMOR_USE_PICTURE_SCREEN)
#define GLAMOR_EGL_EXTERNAL_BUFFER 3
extern _X_EXPORT Bool glamor_init(ScreenPtr screen, unsigned int flags);
extern _X_EXPORT void glamor_fini(ScreenPtr screen);
extern _X_EXPORT void glamor_set_screen_pixmap_texture(ScreenPtr screen, int w, int h, unsigned int tex);
extern _X_EXPORT Bool glamor_glyphs_init (ScreenPtr pScreen);
void glamor_set_pixmap_texture(PixmapPtr pixmap, int w, int h, unsigned int tex);
extern _X_EXPORT void glamor_set_screen_pixmap_texture(ScreenPtr screen,
int w, int h,
unsigned int tex);
extern _X_EXPORT Bool glamor_glyphs_init(ScreenPtr pScreen);
void glamor_set_pixmap_texture(PixmapPtr pixmap, int w, int h,
unsigned int tex);
extern _X_EXPORT void glamor_destroy_textured_pixmap(PixmapPtr pixmap);
extern _X_EXPORT void glamor_block_handler(ScreenPtr screen);
#ifdef GLAMOR_FOR_XORG
extern _X_EXPORT Bool glamor_egl_init(ScrnInfoPtr scrn, int fd);
extern _X_EXPORT Bool glamor_create_egl_screen_image(ScreenPtr screen, int handle, int stride);
extern _X_EXPORT Bool glamor_create_egl_pixmap_image(PixmapPtr pixmap, int handle, int stride);
extern _X_EXPORT Bool glamor_close_egl_screen(ScreenPtr screen);
extern _X_EXPORT void glamor_free_egl_screen(int scrnIndex, int flags);
extern _X_EXPORT Bool glamor_egl_create_textured_screen(ScreenPtr screen,
int handle,
int stride);
extern _X_EXPORT Bool glamor_egl_create_textured_pixmap(PixmapPtr pixmap,
int handle,
int stride);
extern _X_EXPORT Bool glamor_egl_close_screen(ScreenPtr screen);
extern _X_EXPORT void glamor_egl_free_screen(int scrnIndex, int flags);
extern _X_EXPORT Bool glamor_egl_init_textured_pixmap(ScreenPtr screen);
extern _X_EXPORT void glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap);
#endif
This diff is collapsed.
......@@ -32,29 +32,31 @@
* Screen CopyWindow implementation.
*/
void glamor_copy_window(WindowPtr win, DDXPointRec old_origin,
RegionPtr src_region)
void
glamor_copy_window(WindowPtr win, DDXPointRec old_origin,
RegionPtr src_region)
{
RegionRec dst_region;
int dx, dy;
PixmapPtr pixmap = win->drawable.pScreen->GetWindowPixmap(win);
RegionRec dst_region;
int dx, dy;
PixmapPtr pixmap = win->drawable.pScreen->GetWindowPixmap(win);
dx = old_origin.x - win->drawable.x;
dy = old_origin.y - win->drawable.y;
REGION_TRANSLATE(win->drawable.pScreen, src_region, -dx, -dy);
dx = old_origin.x - win->drawable.x;
dy = old_origin.y - win->drawable.y;
REGION_TRANSLATE(win->drawable.pScreen, src_region, -dx, -dy);
REGION_INIT(win->drawable.pScreen, &dst_region, NullBox, 0);
REGION_INIT(win->drawable.pScreen, &dst_region, NullBox, 0);
REGION_INTERSECT(win->drawable.pScreen, &dst_region, &win->borderClip,
src_region);
REGION_INTERSECT(win->drawable.pScreen, &dst_region,
&win->borderClip, src_region);
#ifdef COMPOSITE
if (pixmap->screen_x || pixmap->screen_y)
REGION_TRANSLATE(win->drawable.pScreen, &dst_region,
-pixmap->screen_x, -pixmap->screen_y);
if (pixmap->screen_x || pixmap->screen_y)
REGION_TRANSLATE(win->drawable.pScreen, &dst_region,
-pixmap->screen_x, -pixmap->screen_y);
#endif
miCopyRegion(&pixmap->drawable, &pixmap->drawable,
NULL, &dst_region, dx, dy, glamor_copy_n_to_n, 0, NULL);
miCopyRegion(&pixmap->drawable, &pixmap->drawable,
NULL, &dst_region, dx, dy, glamor_copy_n_to_n, 0,
NULL);
REGION_UNINIT(win->drawable.pScreen, &dst_region);
REGION_UNINIT(win->drawable.pScreen, &dst_region);
}
This diff is collapsed.
......@@ -11,7 +11,8 @@
#define GLAMOR_DEBUG_TEXTURE_DYNAMIC_UPLOAD 3
extern void
AbortServer(void) _X_NORETURN;
AbortServer(void)
_X_NORETURN;
#define GLAMOR_PANIC(_format_, ...) \
do { \
......@@ -19,9 +20,9 @@ AbortServer(void) _X_NORETURN;
" at %32s line %d: " _format_ "\n", \
__FUNCTION__, __LINE__, \
##__VA_ARGS__ ); \
AbortServer(); \
exit(1); \
} while(0)
......
......@@ -64,10 +64,15 @@
static const char glamor_name[] = "glamor";
static DevPrivateKeyRec glamor_egl_pixmap_private_key_index;
DevPrivateKey glamor_egl_pixmap_private_key =
&glamor_egl_pixmap_private_key_index;
static void
glamor_identify(int flags)
{
xf86Msg(X_INFO, "%s: OpenGL accelerated X.org driver based.\n", glamor_name);
xf86Msg(X_INFO, "%s: OpenGL accelerated X.org driver based.\n",
glamor_name);
}
struct glamor_egl_screen_private {
......@@ -75,51 +80,56 @@ struct glamor_egl_screen_private {
EGLContext context;
EGLImageKHR root;
EGLint major, minor;
CreateScreenResourcesProcPtr CreateScreenResources;
CloseScreenProcPtr CloseScreen;
int fd;
int front_buffer_handle;
int front_buffer_handle;
int cpp;
struct gbm_device *gbm;
struct gbm_device *gbm;
PFNEGLCREATEDRMIMAGEMESA egl_create_drm_image_mesa;
PFNEGLEXPORTDRMIMAGEMESA egl_export_drm_image_mesa;
PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr;
PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr;
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC egl_image_target_texture2d_oes;
struct glamor_gl_dispatch *dispatch;
struct glamor_gl_dispatch *dispatch;
};
int xf86GlamorEGLPrivateIndex = -1;
static struct glamor_egl_screen_private* glamor_get_egl_screen_private(ScrnInfoPtr scrn)
static struct glamor_egl_screen_private
*
glamor_egl_get_screen_private(ScrnInfoPtr scrn)
{
return (struct glamor_egl_screen_private *) scrn->privates[xf86GlamorEGLPrivateIndex].ptr;
return (struct glamor_egl_screen_private *)
scrn->privates[xf86GlamorEGLPrivateIndex].ptr;
}
static EGLImageKHR
_glamor_create_egl_image(struct glamor_egl_screen_private *glamor_egl, int width, int height, int stride, int name)
_glamor_egl_create_image(struct glamor_egl_screen_private *glamor_egl,
int width, int height, int stride, int name)
{
EGLImageKHR image;
EGLint attribs[] = {
EGL_WIDTH, 0,
EGL_HEIGHT, 0,
EGL_DRM_BUFFER_STRIDE_MESA, 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_WIDTH, 0,
EGL_HEIGHT, 0,
EGL_DRM_BUFFER_STRIDE_MESA, 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_NONE
};
attribs[1] = width;
attribs[3] = height;
attribs[5] = stride / 4;
image = glamor_egl->egl_create_image_khr (glamor_egl->display,
glamor_egl->context,
EGL_DRM_BUFFER_MESA,
(void*)name,
attribs);
attribs[5] = stride / 4;
image = glamor_egl->egl_create_image_khr(glamor_egl->display,
glamor_egl->context,
EGL_DRM_BUFFER_MESA,
(void *) name, attribs);
if (image == EGL_NO_IMAGE_KHR)
return EGL_NO_IMAGE_KHR;
......@@ -130,162 +140,198 @@ _glamor_create_egl_image(struct glamor_egl_screen_private *glamor_egl, int width
static int
glamor_get_flink_name(int fd, int handle, int *name)
{
struct drm_gem_flink flink;
flink.handle = handle;
if (ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink) < 0)
return FALSE;
*name = flink.name;
return TRUE;
struct drm_gem_flink flink;
flink.handle = handle;
if (ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink) < 0)
return FALSE;
*name = flink.name;
return TRUE;
}
static Bool
glamor_create_texture_from_image(struct glamor_egl_screen_private *glamor_egl, EGLImageKHR image, GLuint *texture)
glamor_create_texture_from_image(struct glamor_egl_screen_private
*glamor_egl,
EGLImageKHR image, GLuint * texture)
{
glamor_egl->dispatch->glGenTextures(1, texture);
glamor_egl->dispatch->glBindTexture(GL_TEXTURE_2D, *texture);
glamor_egl->dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glamor_egl->dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
(glamor_egl->egl_image_target_texture2d_oes)(GL_TEXTURE_2D, image);
return TRUE;
glamor_egl->dispatch->glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glamor_egl->dispatch->glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
(glamor_egl->egl_image_target_texture2d_oes) (GL_TEXTURE_2D,
image);
return TRUE;
}
Bool
glamor_create_egl_screen_image(ScreenPtr screen, int handle, int stride)
glamor_egl_create_textured_screen(ScreenPtr screen, int handle, int stride)
{
ScrnInfoPtr scrn = xf86Screens[screen->myNum];
struct glamor_egl_screen_private *glamor_egl = glamor_get_egl_screen_private(scrn);
struct glamor_egl_screen_private *glamor_egl =
glamor_egl_get_screen_private(scrn);
EGLImageKHR image;
GLuint texture;
if (!glamor_get_flink_name(glamor_egl->fd, handle, &glamor_egl->front_buffer_handle)) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"Couldn't flink front buffer handle\n");
return FALSE;
}
if (!glamor_get_flink_name
(glamor_egl->fd, handle, &glamor_egl->front_buffer_handle)) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"Couldn't flink front buffer handle\n");
return FALSE;
}
if (glamor_egl->root) {
eglDestroyImageKHR(glamor_egl->display, glamor_egl->root);
glamor_egl->root = EGL_NO_IMAGE_KHR;
}
image = _glamor_create_egl_image( glamor_egl,
scrn->virtualX,
scrn->virtualY,
stride,
glamor_egl->front_buffer_handle);
if (image == EGL_NO_IMAGE_KHR)
return FALSE;
glamor_create_texture_from_image(glamor_egl, image, &texture);
glamor_set_screen_pixmap_texture(screen, scrn->virtualX, scrn->virtualY, texture);
if (glamor_egl->root) {
eglDestroyImageKHR(glamor_egl->display, glamor_egl->root);
glamor_egl->root = EGL_NO_IMAGE_KHR;
}
image = _glamor_egl_create_image(glamor_egl,
scrn->virtualX,
scrn->virtualY,
stride,
glamor_egl->front_buffer_handle);
if (image == EGL_NO_IMAGE_KHR)
return FALSE;
glamor_create_texture_from_image(glamor_egl, image, &texture);
glamor_set_screen_pixmap_texture(screen, scrn->virtualX,
scrn->virtualY, texture);
glamor_egl->root = image;
return TRUE;
return TRUE;
}
/*
* This function will be called from the dri buffer allocation.
* It is somehow very familiar with the create screen image.
* It is somehow very familiar with the create textured screen.
* XXX the egl image here is not stored at any data structure.
* Does this cause a leak problem?
*/
Bool
glamor_create_egl_pixmap_image(PixmapPtr pixmap, int handle, int stride)
glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride)
{
ScreenPtr screen = pixmap->drawable.pScreen;
ScrnInfoPtr scrn = xf86Screens[screen->myNum];
struct glamor_egl_screen_private *glamor_egl = glamor_get_egl_screen_private(scrn);
struct glamor_egl_screen_private *glamor_egl =
glamor_egl_get_screen_private(scrn);
EGLImageKHR image;
GLuint texture;
int name;
if (!glamor_get_flink_name(glamor_egl->fd, handle, &name)) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"Couldn't flink pixmap handle\n");
return FALSE;
}
int name;
if (!glamor_get_flink_name(glamor_egl->fd, handle, &name)) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"Couldn't flink pixmap handle\n");
return FALSE;
}
image = _glamor_create_egl_image( glamor_egl,
pixmap->drawable.width,
pixmap->drawable.height,
stride,
name);
if (image == EGL_NO_IMAGE_KHR)
return FALSE;
glamor_create_texture_from_image(glamor_egl, image, &texture);
glamor_set_pixmap_texture(pixmap, pixmap->drawable.width, pixmap->drawable.height, texture);
return TRUE;
image = _glamor_egl_create_image(glamor_egl,
pixmap->drawable.width,
pixmap->drawable.height, stride,
name);
if (image == EGL_NO_IMAGE_KHR) {
ErrorF("Failed to create khr image for bo handle %d.\n", handle);
return FALSE;
}
glamor_create_texture_from_image(glamor_egl, image, &texture);
glamor_set_pixmap_texture(pixmap, pixmap->drawable.width,
pixmap->drawable.height, texture);
dixSetPrivate(&pixmap->devPrivates, glamor_egl_pixmap_private_key,
image);
return TRUE;
}
void
glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap)
{
EGLImageKHR image;
ScrnInfoPtr scrn = xf86Screens[pixmap->drawable.pScreen->myNum];
struct glamor_egl_screen_private *glamor_egl =
glamor_egl_get_screen_private(scrn);
if (pixmap->refcnt == 1) {
image = dixLookupPrivate(&pixmap->devPrivates,
glamor_egl_pixmap_private_key);
if (image != EGL_NO_IMAGE_KHR)
eglDestroyImageKHR(glamor_egl->display, image);
}
glamor_destroy_textured_pixmap(pixmap);
}
Bool
glamor_close_egl_screen(ScreenPtr screen)
glamor_egl_close_screen(ScreenPtr screen)
{
ScrnInfoPtr scrn = xf86Screens[screen->myNum];
struct glamor_egl_screen_private *glamor_egl = glamor_get_egl_screen_private(scrn);
struct glamor_egl_screen_private *glamor_egl =
glamor_egl_get_screen_private(scrn);
glamor_fini(screen);
eglDestroyImageKHR(glamor_egl->display, glamor_egl->root);
eglDestroyImageKHR(glamor_egl->display, glamor_egl->root);
glamor_egl->root = EGL_NO_IMAGE_KHR;
return TRUE;
}
static Bool
glamor_egl_has_extension(struct glamor_egl_screen_private *glamor_egl, char *extension)
glamor_egl_has_extension(struct glamor_egl_screen_private *glamor_egl,
char *extension)
{
const char *egl_extensions;
char *pext;
int ext_len;
ext_len = strlen(extension);
egl_extensions = (const char*)eglQueryString(glamor_egl->display, EGL_EXTENSIONS);
pext = (char*)egl_extensions;
if (pext == NULL || extension == NULL)
return FALSE;
while((pext = strstr(pext, extension)) != NULL) {
if (pext[ext_len] == ' ' || pext[ext_len] == '\0')
return TRUE;
pext += ext_len;
}
return FALSE;
const char *egl_extensions;
char *pext;
int ext_len;
ext_len = strlen(extension);
egl_extensions =
(const char *) eglQueryString(glamor_egl->display,
EGL_EXTENSIONS);
pext = (char *) egl_extensions;
if (pext == NULL || extension == NULL)
return FALSE;
while ((pext = strstr(pext, extension)) != NULL) {
if (pext[ext_len] == ' ' || pext[ext_len] == '\0')
return TRUE;
pext += ext_len;
}
return FALSE;
}
Bool glamor_egl_init(ScrnInfoPtr scrn, int fd)
Bool
glamor_egl_init(ScrnInfoPtr scrn, int fd)
{
struct glamor_egl_screen_private *glamor_egl;
const char *version;
EGLint config_attribs[] = {
EGLint config_attribs[] = {
#ifdef GLAMOR_GLES2
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_CONTEXT_CLIENT_VERSION, 2,
#endif
EGL_NONE
};
EGL_NONE
};
glamor_identify(0);
glamor_egl = calloc(sizeof(*glamor_egl), 1);
if (xf86GlamorEGLPrivateIndex == -1)
xf86GlamorEGLPrivateIndex = xf86AllocateScrnInfoPrivateIndex();
glamor_identify(0);
glamor_egl = calloc(sizeof(*glamor_egl), 1);
if (xf86GlamorEGLPrivateIndex == -1)
xf86GlamorEGLPrivateIndex =
xf86AllocateScrnInfoPrivateIndex();
scrn->privates[xf86GlamorEGLPrivateIndex].ptr = glamor_egl;
scrn->privates[xf86GlamorEGLPrivateIndex].ptr = glamor_egl;
glamor_egl->fd = fd;
glamor_egl->fd = fd;
glamor_egl->display = eglGetDRMDisplayMESA(glamor_egl->fd);
glamor_egl->display = eglGetDRMDisplayMESA(glamor_egl->fd);
if (glamor_egl->display == EGL_NO_DISPLAY) {
glamor_egl->gbm = gbm_create_device(glamor_egl->fd);
if (glamor_egl->gbm == NULL) {
ErrorF("couldn't get display device\n");
return FALSE;
}
}
if (glamor_egl->display == EGL_NO_DISPLAY) {
glamor_egl->gbm = gbm_create_device(glamor_egl->fd);
if (glamor_egl->gbm == NULL) {
ErrorF("couldn't get display device\n");
return FALSE;
}
}
glamor_egl->display = eglGetDisplay(glamor_egl->gbm);
#ifndef GLAMOR_GLES2
......@@ -293,7 +339,9 @@ Bool glamor_egl_init(ScrnInfoPtr scrn, int fd)
#else
eglBindAPI(EGL_OPENGL_ES_API);
#endif
if (!eglInitialize(glamor_egl->display, &glamor_egl->major, &glamor_egl->minor)) {
if (!eglInitialize
(glamor_egl->display, &glamor_egl->major, &glamor_egl->minor))
{
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"eglInitialize() failed\n");
return FALSE;
......@@ -306,34 +354,36 @@ Bool glamor_egl_init(ScrnInfoPtr scrn, int fd)
if (!glamor_egl_has_extension(glamor_egl, "EGL_" #EXT)) { \
ErrorF("EGL_" #EXT "required.\n"); \
return FALSE; \
}
}
GLAMOR_CHECK_EGL_EXTENSION(MESA_drm_image);
GLAMOR_CHECK_EGL_EXTENSION(KHR_gl_renderbuffer_image);
GLAMOR_CHECK_EGL_EXTENSION(MESA_drm_image);
GLAMOR_CHECK_EGL_EXTENSION(KHR_gl_renderbuffer_image);
#ifdef GLAMOR_GLES2
GLAMOR_CHECK_EGL_EXTENSION(KHR_surfaceless_gles2);
GLAMOR_CHECK_EGL_EXTENSION(KHR_surfaceless_gles2);
#else
GLAMOR_CHECK_EGL_EXTENSION(KHR_surfaceless_opengl);
GLAMOR_CHECK_EGL_EXTENSION(KHR_surfaceless_opengl);
#endif
glamor_egl->egl_export_drm_image_mesa = (PFNEGLEXPORTDRMIMAGEMESA)
eglGetProcAddress("eglExportDRMImageMESA");
glamor_egl->egl_create_image_khr = (PFNEGLCREATEIMAGEKHRPROC)
eglGetProcAddress("eglCreateImageKHR");
eglGetProcAddress("eglExportDRMImageMESA");
glamor_egl->egl_create_image_khr = (PFNEGLCREATEIMAGEKHRPROC)
eglGetProcAddress("eglCreateImageKHR");
glamor_egl->egl_image_target_texture2d_oes = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)