2011-08-24 10:54:32 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Intel Corporation.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including
|
|
|
|
* the next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Zhigang Gong <zhigang.gong@linux.intel.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-01-05 07:26:01 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-24 10:54:32 +02:00
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
2011-12-12 00:09:03 +01:00
|
|
|
#define GLAMOR_FOR_XORG
|
|
|
|
#include "xorg-server.h"
|
2011-08-24 10:54:32 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <xf86.h>
|
|
|
|
#include <xf86drm.h>
|
|
|
|
#define GL_GLEXT_PROTOTYPES
|
|
|
|
#define EGL_EGLEXT_PROTOTYPES
|
|
|
|
#define EGL_DISPLAY_NO_X_MESA
|
|
|
|
|
2011-09-20 09:14:49 +02:00
|
|
|
#include <gbm.h>
|
|
|
|
|
2011-08-24 10:54:32 +02:00
|
|
|
#if GLAMOR_GLES2
|
|
|
|
#include <GLES2/gl2.h>
|
2011-08-24 11:17:48 +02:00
|
|
|
#include <GLES2/gl2ext.h>
|
2011-08-24 10:54:32 +02:00
|
|
|
#else
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MESA_EGL_NO_X11_HEADERS
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <EGL/eglext.h>
|
|
|
|
|
|
|
|
#define GLAMOR_VERSION_MAJOR 0
|
|
|
|
#define GLAMOR_VERSION_MINOR 1
|
|
|
|
#define GLAMOR_VERSION_PATCH 0
|
|
|
|
|
2011-12-12 00:09:03 +01:00
|
|
|
#include "glamor.h"
|
|
|
|
#include "glamor_gl_dispatch.h"
|
|
|
|
|
2011-08-24 10:54:32 +02:00
|
|
|
static const char glamor_name[] = "glamor";
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
static DevPrivateKeyRec glamor_egl_pixmap_private_key_index;
|
2011-12-13 15:48:34 +01:00
|
|
|
DevPrivateKey glamor_egl_pixmap_private_key = &glamor_egl_pixmap_private_key_index;
|
2011-11-02 06:44:50 +01:00
|
|
|
|
2011-08-24 10:54:32 +02:00
|
|
|
static void
|
|
|
|
glamor_identify(int flags)
|
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
xf86Msg(X_INFO, "%s: OpenGL accelerated X.org driver based.\n",
|
|
|
|
glamor_name);
|
2011-08-24 10:54:32 +02:00
|
|
|
}
|
|
|
|
|
2011-09-08 09:16:01 +02:00
|
|
|
struct glamor_egl_screen_private {
|
2011-08-24 10:54:32 +02:00
|
|
|
EGLDisplay display;
|
|
|
|
EGLContext context;
|
|
|
|
EGLImageKHR root;
|
|
|
|
EGLint major, minor;
|
2011-11-02 06:44:50 +01:00
|
|
|
|
2011-08-24 10:54:32 +02:00
|
|
|
CreateScreenResourcesProcPtr CreateScreenResources;
|
|
|
|
CloseScreenProcPtr CloseScreen;
|
|
|
|
int fd;
|
2011-11-02 06:44:50 +01:00
|
|
|
int front_buffer_handle;
|
2011-08-24 10:54:32 +02:00
|
|
|
int cpp;
|
2011-11-02 06:44:50 +01:00
|
|
|
struct gbm_device *gbm;
|
2011-08-24 10:54:32 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr;
|
2011-08-24 11:17:48 +02:00
|
|
|
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC egl_image_target_texture2d_oes;
|
2011-11-02 06:44:50 +01:00
|
|
|
struct glamor_gl_dispatch *dispatch;
|
2011-08-24 10:54:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
int xf86GlamorEGLPrivateIndex = -1;
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
static struct glamor_egl_screen_private
|
|
|
|
*
|
|
|
|
glamor_egl_get_screen_private(ScrnInfoPtr scrn)
|
2011-08-24 10:54:32 +02:00
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
return (struct glamor_egl_screen_private *)
|
|
|
|
scrn->privates[xf86GlamorEGLPrivateIndex].ptr;
|
2011-08-24 10:54:32 +02:00
|
|
|
}
|
|
|
|
|
2011-09-08 09:16:01 +02:00
|
|
|
static EGLImageKHR
|
2011-11-02 06:44:50 +01:00
|
|
|
_glamor_egl_create_image(struct glamor_egl_screen_private *glamor_egl,
|
2011-12-09 09:01:45 +01:00
|
|
|
int width, int height, int stride, int name, int depth)
|
2011-08-24 10:54:32 +02:00
|
|
|
{
|
|
|
|
EGLImageKHR image;
|
|
|
|
EGLint attribs[] = {
|
2011-11-02 06:44:50 +01:00
|
|
|
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,
|
2011-08-24 10:54:32 +02:00
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
attribs[1] = width;
|
|
|
|
attribs[3] = height;
|
2011-12-09 09:01:45 +01:00
|
|
|
attribs[5] = stride;
|
2011-12-12 00:09:03 +01:00
|
|
|
if (depth != 32 && depth != 24)
|
2011-12-09 09:01:45 +01:00
|
|
|
return EGL_NO_IMAGE_KHR;
|
2011-11-02 06:44:50 +01:00
|
|
|
image = glamor_egl->egl_create_image_khr(glamor_egl->display,
|
|
|
|
glamor_egl->context,
|
|
|
|
EGL_DRM_BUFFER_MESA,
|
2011-11-22 11:28:10 +01:00
|
|
|
(void *) (uintptr_t)name, attribs);
|
2011-08-24 10:54:32 +02:00
|
|
|
if (image == EGL_NO_IMAGE_KHR)
|
2011-09-08 09:16:01 +02:00
|
|
|
return EGL_NO_IMAGE_KHR;
|
2011-08-24 10:54:32 +02:00
|
|
|
|
2011-08-24 11:17:48 +02:00
|
|
|
|
2011-09-08 09:16:01 +02:00
|
|
|
return image;
|
|
|
|
}
|
2011-08-24 10:54:32 +02:00
|
|
|
|
2011-09-08 09:16:01 +02:00
|
|
|
static int
|
|
|
|
glamor_get_flink_name(int fd, int handle, int *name)
|
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
struct drm_gem_flink flink;
|
|
|
|
flink.handle = handle;
|
|
|
|
if (ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink) < 0)
|
|
|
|
return FALSE;
|
|
|
|
*name = flink.name;
|
|
|
|
return TRUE;
|
2011-09-08 09:16:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static Bool
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_create_texture_from_image(struct glamor_egl_screen_private
|
|
|
|
*glamor_egl,
|
|
|
|
EGLImageKHR image, GLuint * texture)
|
2011-09-08 09:16:01 +02:00
|
|
|
{
|
|
|
|
glamor_egl->dispatch->glGenTextures(1, texture);
|
|
|
|
glamor_egl->dispatch->glBindTexture(GL_TEXTURE_2D, *texture);
|
2011-11-02 06:44:50 +01:00
|
|
|
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);
|
2011-12-09 09:01:45 +01:00
|
|
|
glamor_egl->dispatch->glBindTexture(GL_TEXTURE_2D, 0);
|
2011-11-02 06:44:50 +01:00
|
|
|
return TRUE;
|
2011-08-24 10:54:32 +02:00
|
|
|
}
|
|
|
|
|
2011-09-08 09:16:01 +02:00
|
|
|
|
2011-08-24 10:54:32 +02:00
|
|
|
Bool
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_egl_create_textured_screen(ScreenPtr screen, int handle, int stride)
|
2011-08-24 10:54:32 +02:00
|
|
|
{
|
|
|
|
ScrnInfoPtr scrn = xf86Screens[screen->myNum];
|
2011-11-02 06:44:50 +01:00
|
|
|
struct glamor_egl_screen_private *glamor_egl =
|
|
|
|
glamor_egl_get_screen_private(scrn);
|
2011-09-08 09:16:01 +02:00
|
|
|
EGLImageKHR image;
|
|
|
|
GLuint texture;
|
2011-08-24 10:54:32 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
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;
|
|
|
|
}
|
2011-09-08 09:16:01 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
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,
|
2011-12-09 09:01:45 +01:00
|
|
|
stride / 4,
|
|
|
|
glamor_egl->front_buffer_handle, 32);
|
2011-11-02 06:44:50 +01:00
|
|
|
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);
|
2011-09-08 09:16:01 +02:00
|
|
|
glamor_egl->root = image;
|
2011-11-02 06:44:50 +01:00
|
|
|
return TRUE;
|
2011-09-08 09:16:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride)
|
2011-09-08 09:16:01 +02:00
|
|
|
{
|
|
|
|
ScreenPtr screen = pixmap->drawable.pScreen;
|
|
|
|
ScrnInfoPtr scrn = xf86Screens[screen->myNum];
|
2011-11-02 06:44:50 +01:00
|
|
|
struct glamor_egl_screen_private *glamor_egl =
|
|
|
|
glamor_egl_get_screen_private(scrn);
|
2011-09-08 09:16:01 +02:00
|
|
|
EGLImageKHR image;
|
|
|
|
GLuint texture;
|
2011-11-02 06:44:50 +01:00
|
|
|
int name;
|
2011-12-09 09:01:45 +01:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
if (!glamor_get_flink_name(glamor_egl->fd, handle, &name)) {
|
|
|
|
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
|
|
|
"Couldn't flink pixmap handle\n");
|
2011-12-13 15:48:34 +01:00
|
|
|
glamor_set_pixmap_type(pixmap, GLAMOR_DRM_ONLY);
|
|
|
|
exit(1);
|
2011-11-02 06:44:50 +01:00
|
|
|
}
|
|
|
|
image = _glamor_egl_create_image(glamor_egl,
|
|
|
|
pixmap->drawable.width,
|
2011-12-09 09:01:45 +01:00
|
|
|
pixmap->drawable.height,
|
|
|
|
((stride * 8 + 7) / pixmap->drawable.bitsPerPixel),
|
|
|
|
name,
|
|
|
|
pixmap->drawable.depth);
|
2011-12-16 08:02:54 +01:00
|
|
|
if (image == EGL_NO_IMAGE_KHR)
|
|
|
|
return FALSE;
|
2011-11-02 06:44:50 +01:00
|
|
|
|
2011-12-16 08:02:54 +01:00
|
|
|
glamor_create_texture_from_image(glamor_egl, image, &texture);
|
|
|
|
glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_set_pixmap_texture(pixmap, pixmap->drawable.width,
|
|
|
|
pixmap->drawable.height, texture);
|
|
|
|
dixSetPrivate(&pixmap->devPrivates, glamor_egl_pixmap_private_key,
|
|
|
|
image);
|
2011-12-13 15:48:34 +01:00
|
|
|
|
2011-12-16 08:02:54 +01:00
|
|
|
return TRUE;
|
2011-11-02 06:44:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2011-12-23 09:21:44 +01:00
|
|
|
if (image != EGL_NO_IMAGE_KHR && image != NULL) {
|
|
|
|
/* Before destroy an image which was attached to
|
|
|
|
* a texture. we must call glFlush to make sure the
|
|
|
|
* operation on that texture has been done.*/
|
|
|
|
glamor_block_handler(pixmap->drawable.pScreen);
|
2011-11-02 06:44:50 +01:00
|
|
|
eglDestroyImageKHR(glamor_egl->display, image);
|
2011-12-23 09:21:44 +01:00
|
|
|
}
|
2011-11-02 06:44:50 +01:00
|
|
|
}
|
|
|
|
glamor_destroy_textured_pixmap(pixmap);
|
2011-08-24 10:54:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_egl_close_screen(ScreenPtr screen)
|
2011-08-24 10:54:32 +02:00
|
|
|
{
|
|
|
|
ScrnInfoPtr scrn = xf86Screens[screen->myNum];
|
2011-11-02 06:44:50 +01:00
|
|
|
struct glamor_egl_screen_private *glamor_egl =
|
|
|
|
glamor_egl_get_screen_private(scrn);
|
2011-08-24 10:54:32 +02:00
|
|
|
glamor_fini(screen);
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
eglDestroyImageKHR(glamor_egl->display, glamor_egl->root);
|
2011-08-24 10:54:32 +02:00
|
|
|
|
2011-09-08 09:16:01 +02:00
|
|
|
glamor_egl->root = EGL_NO_IMAGE_KHR;
|
2011-08-24 10:54:32 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Bool
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_egl_has_extension(struct glamor_egl_screen_private *glamor_egl,
|
|
|
|
char *extension)
|
2011-08-24 10:54:32 +02:00
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
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;
|
2011-08-24 10:54:32 +02:00
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
Bool
|
|
|
|
glamor_egl_init(ScrnInfoPtr scrn, int fd)
|
2011-08-24 10:54:32 +02:00
|
|
|
{
|
2011-09-08 09:16:01 +02:00
|
|
|
struct glamor_egl_screen_private *glamor_egl;
|
2011-08-24 10:54:32 +02:00
|
|
|
const char *version;
|
2011-11-02 06:44:50 +01:00
|
|
|
EGLint config_attribs[] = {
|
2011-08-24 10:54:32 +02:00
|
|
|
#ifdef GLAMOR_GLES2
|
2011-11-02 06:44:50 +01:00
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
2011-08-24 10:54:32 +02:00
|
|
|
#endif
|
2011-11-02 06:44:50 +01:00
|
|
|
EGL_NONE
|
|
|
|
};
|
2011-08-24 10:54:32 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_identify(0);
|
|
|
|
glamor_egl = calloc(sizeof(*glamor_egl), 1);
|
|
|
|
if (xf86GlamorEGLPrivateIndex == -1)
|
|
|
|
xf86GlamorEGLPrivateIndex =
|
|
|
|
xf86AllocateScrnInfoPrivateIndex();
|
2011-08-24 10:54:32 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
scrn->privates[xf86GlamorEGLPrivateIndex].ptr = glamor_egl;
|
|
|
|
glamor_egl->fd = fd;
|
2011-12-16 08:02:54 +01:00
|
|
|
glamor_egl->gbm = gbm_create_device(glamor_egl->fd);
|
|
|
|
if (glamor_egl->gbm == NULL) {
|
|
|
|
ErrorF("couldn't get display device\n");
|
|
|
|
return FALSE;
|
2011-11-02 06:44:50 +01:00
|
|
|
}
|
2011-09-20 09:14:49 +02:00
|
|
|
glamor_egl->display = eglGetDisplay(glamor_egl->gbm);
|
2011-12-16 08:02:54 +01:00
|
|
|
|
2011-08-24 10:54:32 +02:00
|
|
|
#ifndef GLAMOR_GLES2
|
|
|
|
eglBindAPI(EGL_OPENGL_API);
|
|
|
|
#else
|
|
|
|
eglBindAPI(EGL_OPENGL_ES_API);
|
|
|
|
#endif
|
2011-11-02 06:44:50 +01:00
|
|
|
if (!eglInitialize
|
|
|
|
(glamor_egl->display, &glamor_egl->major, &glamor_egl->minor))
|
|
|
|
{
|
2011-08-24 10:54:32 +02:00
|
|
|
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
|
|
|
"eglInitialize() failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-09-08 09:16:01 +02:00
|
|
|
version = eglQueryString(glamor_egl->display, EGL_VERSION);
|
2011-08-24 10:54:32 +02:00
|
|
|
xf86Msg(X_INFO, "%s: EGL version %s:\n", glamor_name, version);
|
|
|
|
|
|
|
|
#define GLAMOR_CHECK_EGL_EXTENSION(EXT) \
|
2011-12-13 15:48:34 +01:00
|
|
|
if (!glamor_egl_has_extension(glamor_egl, "EGL_" #EXT)) { \
|
|
|
|
ErrorF("EGL_" #EXT "required.\n"); \
|
|
|
|
return FALSE; \
|
|
|
|
}
|
2011-08-24 10:54:32 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
GLAMOR_CHECK_EGL_EXTENSION(MESA_drm_image);
|
|
|
|
GLAMOR_CHECK_EGL_EXTENSION(KHR_gl_renderbuffer_image);
|
2011-08-24 10:54:32 +02:00
|
|
|
#ifdef GLAMOR_GLES2
|
2011-11-02 06:44:50 +01:00
|
|
|
GLAMOR_CHECK_EGL_EXTENSION(KHR_surfaceless_gles2);
|
2011-08-24 10:54:32 +02:00
|
|
|
#else
|
2011-11-02 06:44:50 +01:00
|
|
|
GLAMOR_CHECK_EGL_EXTENSION(KHR_surfaceless_opengl);
|
2011-08-24 10:54:32 +02:00
|
|
|
#endif
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_egl->egl_create_image_khr = (PFNEGLCREATEIMAGEKHRPROC)
|
|
|
|
eglGetProcAddress("eglCreateImageKHR");
|
2011-08-24 10:54:32 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_egl->egl_image_target_texture2d_oes =
|
|
|
|
(PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)
|
|
|
|
eglGetProcAddress("glEGLImageTargetTexture2DOES");
|
2011-08-24 11:17:48 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
if (!glamor_egl->egl_create_image_khr
|
|
|
|
|| !glamor_egl->egl_image_target_texture2d_oes) {
|
2011-08-24 10:54:32 +02:00
|
|
|
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
|
|
|
"eglGetProcAddress() failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-09-08 09:16:01 +02:00
|
|
|
glamor_egl->context = eglCreateContext(glamor_egl->display,
|
2011-11-02 06:44:50 +01:00
|
|
|
NULL, EGL_NO_CONTEXT,
|
|
|
|
config_attribs);
|
2011-09-08 09:16:01 +02:00
|
|
|
if (glamor_egl->context == EGL_NO_CONTEXT) {
|
2011-08-24 10:54:32 +02:00
|
|
|
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
|
|
|
"Failed to create EGL context\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-09-08 09:16:01 +02:00
|
|
|
if (!eglMakeCurrent(glamor_egl->display,
|
2011-11-02 06:44:50 +01:00
|
|
|
EGL_NO_SURFACE, EGL_NO_SURFACE,
|
|
|
|
glamor_egl->context)) {
|
2011-08-24 10:54:32 +02:00
|
|
|
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
|
|
|
"Failed to make EGL context current\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2011-09-08 09:16:01 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
Bool
|
|
|
|
glamor_egl_init_textured_pixmap(ScreenPtr screen)
|
|
|
|
{
|
|
|
|
if (!dixRegisterPrivateKey
|
|
|
|
(glamor_egl_pixmap_private_key, PRIVATE_PIXMAP, 0)) {
|
|
|
|
LogMessage(X_WARNING,
|
|
|
|
"glamor%d: Failed to allocate egl pixmap private\n",
|
|
|
|
screen->myNum);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2011-08-24 10:54:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_egl_free_screen(int scrnIndex, int flags)
|
2011-08-24 10:54:32 +02:00
|
|
|
{
|
|
|
|
ScrnInfoPtr scrn = xf86Screens[scrnIndex];
|
2011-11-02 06:44:50 +01:00
|
|
|
struct glamor_egl_screen_private *glamor_egl =
|
|
|
|
glamor_egl_get_screen_private(scrn);
|
|
|
|
|
|
|
|
if (glamor_egl != NULL) {
|
|
|
|
if (!(flags & GLAMOR_EGL_EXTERNAL_BUFFER)) {
|
|
|
|
eglMakeCurrent(glamor_egl->display,
|
|
|
|
EGL_NO_SURFACE, EGL_NO_SURFACE,
|
|
|
|
EGL_NO_CONTEXT);
|
|
|
|
|
|
|
|
eglTerminate(glamor_egl->display);
|
|
|
|
}
|
|
|
|
free(glamor_egl);
|
2011-08-24 10:54:32 +02:00
|
|
|
}
|
|
|
|
}
|
2011-09-08 08:05:46 +02:00
|
|
|
|
|
|
|
Bool
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_gl_dispatch_init(ScreenPtr screen,
|
|
|
|
struct glamor_gl_dispatch *dispatch,
|
|
|
|
int gl_version)
|
2011-09-08 08:05:46 +02:00
|
|
|
{
|
|
|
|
ScrnInfoPtr scrn = xf86Screens[screen->myNum];
|
2011-11-02 06:44:50 +01:00
|
|
|
struct glamor_egl_screen_private *glamor_egl =
|
|
|
|
glamor_egl_get_screen_private(scrn);
|
|
|
|
if (!glamor_gl_dispatch_init_impl
|
|
|
|
(dispatch, gl_version, (get_proc_address_t)eglGetProcAddress))
|
|
|
|
return FALSE;
|
|
|
|
glamor_egl->dispatch = dispatch;
|
|
|
|
return TRUE;
|
2011-09-08 08:05:46 +02:00
|
|
|
}
|