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>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-10-30 16:30:23 +01:00
|
|
|
#include "dix-config.h"
|
2012-01-05 07:26:01 +01:00
|
|
|
|
2011-12-12 00:09:03 +01:00
|
|
|
#define GLAMOR_FOR_XORG
|
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 EGL_DISPLAY_NO_X_MESA
|
|
|
|
|
2012-01-20 05:10:06 +01:00
|
|
|
#ifdef GLAMOR_HAS_GBM
|
2011-09-20 09:14:49 +02:00
|
|
|
#include <gbm.h>
|
2013-12-05 08:49:15 +01:00
|
|
|
#include <drm_fourcc.h>
|
2012-01-20 05:10:06 +01:00
|
|
|
#endif
|
2011-09-20 09:14:49 +02:00
|
|
|
|
2011-08-24 10:54:32 +02:00
|
|
|
#define MESA_EGL_NO_X11_HEADERS
|
2013-12-18 21:18:20 +01:00
|
|
|
#include <epoxy/gl.h>
|
|
|
|
#include <epoxy/egl.h>
|
2011-08-24 10:54:32 +02:00
|
|
|
|
2011-12-12 00:09:03 +01:00
|
|
|
#include "glamor.h"
|
2013-12-19 00:27:52 +01:00
|
|
|
#include "glamor_priv.h"
|
2013-12-31 09:07:42 +01:00
|
|
|
#include "dri3.h"
|
2011-12-12 00:09:03 +01:00
|
|
|
|
2011-08-24 10:54:32 +02:00
|
|
|
static const char glamor_name[] = "glamor";
|
|
|
|
|
|
|
|
static void
|
|
|
|
glamor_identify(int flags)
|
|
|
|
{
|
2013-12-18 20:59:07 +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 {
|
2013-12-18 20:59:07 +01:00
|
|
|
EGLDisplay display;
|
|
|
|
EGLContext context;
|
|
|
|
EGLint major, minor;
|
2013-12-31 09:07:42 +01:00
|
|
|
char *device_path;
|
2013-12-18 20:59:07 +01:00
|
|
|
|
|
|
|
CreateScreenResourcesProcPtr CreateScreenResources;
|
|
|
|
CloseScreenProcPtr CloseScreen;
|
|
|
|
int fd;
|
|
|
|
int cpp;
|
2012-01-20 05:10:06 +01:00
|
|
|
#ifdef GLAMOR_HAS_GBM
|
2013-12-18 20:59:07 +01:00
|
|
|
struct gbm_device *gbm;
|
2012-01-20 05:10:06 +01:00
|
|
|
#endif
|
2013-12-18 20:59:07 +01:00
|
|
|
int has_gem;
|
|
|
|
int gl_context_depth;
|
|
|
|
int dri3_capable;
|
|
|
|
|
|
|
|
CloseScreenProcPtr saved_close_screen;
|
|
|
|
xf86FreeScreenProc *saved_free_screen;
|
2011-08-24 10:54:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
int xf86GlamorEGLPrivateIndex = -1;
|
|
|
|
|
2013-12-19 00:27:52 +01:00
|
|
|
|
GLX: Enable glx support.
If we are using MESA as our GL library, then both xserver's
GLX and glamor are link to the same library. As xserver's
GLX has its own _glapi_get/set_context/dispatch etc, and it
is a simplified version derived from mesa thus is not
sufficient for mesa/egl's dri loader which is used by glamor.
Then if glx module is loaded before glamoregl module, the
initialization of mesa/egl/opengl will not be correct, and
will fail at a very early stage, most likely fail to map
the element buffer.
Two methodis to fix this problem, first is to modify the xserver's
glx's glapi.c to fit mesa's requirement. The second is to put
a glamor.conf as below, to the system's xorg.conf path.
Section "Module"
Load "glamoregl"
EndSection
Then glamor will be loaded firstly, and the mesa's libglapi.so
will be used. As current xserver's dispatch table is the same
as mesa's, then the glx's dri loader can work without problem.
We took the second method as it don't need any change to xorg.:)
Although this is not a graceful implementation as it depends
on the xserver's dispatch table and the mesa's dispatch table
is the same and the context set and get is using the same method.
Anyway it works.
As by default, xserver will enable GLX_USE_TLS. But mesa will not
enable it, you may need to enable that when build mesa.
Three pre-requirements to make this glamor version work:
0. Make sure xserver has commit 66e603, if not please pull the latest
master branch.
1. Rebuild mesa by enable GLX_USE_TLS.
2. Put the glamor.conf to your system's xorg.conf path and make sure
it loaded prior to glx module.
Preliminary testing shows indirect glxgears works fine.
If user want to use GLES2 for glamor by using MESA, GLX will not
work correctly.
If you are not using normal MESA, for example PVR's private GLES
implementation, then it should be ok to use GLES2 glamor and the
GLX should work as expected. In this commit, I use gbm to check
whether we are using MESA or non-mesa. Maybe not the best way.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2012-02-10 09:04:07 +01:00
|
|
|
static struct glamor_egl_screen_private *
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_egl_get_screen_private(ScrnInfoPtr scrn)
|
2011-08-24 10:54:32 +02:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
return (struct glamor_egl_screen_private *)
|
|
|
|
scrn->privates[xf86GlamorEGLPrivateIndex].ptr;
|
2011-08-24 10:54:32 +02:00
|
|
|
}
|
2013-12-18 20:59:07 +01:00
|
|
|
|
2013-12-19 00:27:52 +01:00
|
|
|
static void
|
2014-03-15 01:31:18 +01:00
|
|
|
glamor_egl_make_current(struct glamor_context *glamor_ctx)
|
GLX: Enable glx support.
If we are using MESA as our GL library, then both xserver's
GLX and glamor are link to the same library. As xserver's
GLX has its own _glapi_get/set_context/dispatch etc, and it
is a simplified version derived from mesa thus is not
sufficient for mesa/egl's dri loader which is used by glamor.
Then if glx module is loaded before glamoregl module, the
initialization of mesa/egl/opengl will not be correct, and
will fail at a very early stage, most likely fail to map
the element buffer.
Two methodis to fix this problem, first is to modify the xserver's
glx's glapi.c to fit mesa's requirement. The second is to put
a glamor.conf as below, to the system's xorg.conf path.
Section "Module"
Load "glamoregl"
EndSection
Then glamor will be loaded firstly, and the mesa's libglapi.so
will be used. As current xserver's dispatch table is the same
as mesa's, then the glx's dri loader can work without problem.
We took the second method as it don't need any change to xorg.:)
Although this is not a graceful implementation as it depends
on the xserver's dispatch table and the mesa's dispatch table
is the same and the context set and get is using the same method.
Anyway it works.
As by default, xserver will enable GLX_USE_TLS. But mesa will not
enable it, you may need to enable that when build mesa.
Three pre-requirements to make this glamor version work:
0. Make sure xserver has commit 66e603, if not please pull the latest
master branch.
1. Rebuild mesa by enable GLX_USE_TLS.
2. Put the glamor.conf to your system's xorg.conf path and make sure
it loaded prior to glx module.
Preliminary testing shows indirect glxgears works fine.
If user want to use GLES2 for glamor by using MESA, GLX will not
work correctly.
If you are not using normal MESA, for example PVR's private GLES
implementation, then it should be ok to use GLES2 glamor and the
GLX should work as expected. In this commit, I use gbm to check
whether we are using MESA or non-mesa. Maybe not the best way.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2012-02-10 09:04:07 +01:00
|
|
|
{
|
2014-04-04 08:03:31 +02:00
|
|
|
/* There's only a single global dispatch table in Mesa. EGL, GLX,
|
|
|
|
* and AIGLX's direct dispatch table manipulation don't talk to
|
|
|
|
* each other. We need to set the context to NULL first to avoid
|
|
|
|
* EGL's no-op context change fast path when switching back to
|
|
|
|
* EGL.
|
|
|
|
*/
|
2014-03-15 01:20:12 +01:00
|
|
|
eglMakeCurrent(glamor_ctx->display, EGL_NO_SURFACE,
|
|
|
|
EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
2014-04-04 08:03:31 +02:00
|
|
|
|
2014-03-15 01:20:12 +01:00
|
|
|
if (!eglMakeCurrent(glamor_ctx->display,
|
|
|
|
EGL_NO_SURFACE, EGL_NO_SURFACE,
|
|
|
|
glamor_ctx->ctx)) {
|
|
|
|
FatalError("Failed to make EGL context current\n");
|
2013-12-18 20:59:07 +01:00
|
|
|
}
|
GLX: Enable glx support.
If we are using MESA as our GL library, then both xserver's
GLX and glamor are link to the same library. As xserver's
GLX has its own _glapi_get/set_context/dispatch etc, and it
is a simplified version derived from mesa thus is not
sufficient for mesa/egl's dri loader which is used by glamor.
Then if glx module is loaded before glamoregl module, the
initialization of mesa/egl/opengl will not be correct, and
will fail at a very early stage, most likely fail to map
the element buffer.
Two methodis to fix this problem, first is to modify the xserver's
glx's glapi.c to fit mesa's requirement. The second is to put
a glamor.conf as below, to the system's xorg.conf path.
Section "Module"
Load "glamoregl"
EndSection
Then glamor will be loaded firstly, and the mesa's libglapi.so
will be used. As current xserver's dispatch table is the same
as mesa's, then the glx's dri loader can work without problem.
We took the second method as it don't need any change to xorg.:)
Although this is not a graceful implementation as it depends
on the xserver's dispatch table and the mesa's dispatch table
is the same and the context set and get is using the same method.
Anyway it works.
As by default, xserver will enable GLX_USE_TLS. But mesa will not
enable it, you may need to enable that when build mesa.
Three pre-requirements to make this glamor version work:
0. Make sure xserver has commit 66e603, if not please pull the latest
master branch.
1. Rebuild mesa by enable GLX_USE_TLS.
2. Put the glamor.conf to your system's xorg.conf path and make sure
it loaded prior to glx module.
Preliminary testing shows indirect glxgears works fine.
If user want to use GLES2 for glamor by using MESA, GLX will not
work correctly.
If you are not using normal MESA, for example PVR's private GLES
implementation, then it should be ok to use GLES2 glamor and the
GLX should work as expected. In this commit, I use gbm to check
whether we are using MESA or non-mesa. Maybe not the best way.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2012-02-10 09:04:07 +01: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,
|
2013-12-18 20:59:07 +01:00
|
|
|
int width, int height, int stride, int name, int depth)
|
2011-08-24 10:54:32 +02:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
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_NONE
|
|
|
|
};
|
|
|
|
attribs[1] = width;
|
|
|
|
attribs[3] = height;
|
|
|
|
attribs[5] = stride;
|
|
|
|
if (depth != 32 && depth != 24)
|
|
|
|
return EGL_NO_IMAGE_KHR;
|
2013-12-18 21:18:20 +01:00
|
|
|
image = eglCreateImageKHR(glamor_egl->display,
|
|
|
|
glamor_egl->context,
|
|
|
|
EGL_DRM_BUFFER_MESA,
|
|
|
|
(void *) (uintptr_t) name,
|
|
|
|
attribs);
|
2013-12-18 20:59:07 +01:00
|
|
|
if (image == EGL_NO_IMAGE_KHR)
|
|
|
|
return EGL_NO_IMAGE_KHR;
|
|
|
|
|
|
|
|
return image;
|
2011-09-08 09:16:01 +02:00
|
|
|
}
|
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)
|
|
|
|
{
|
2013-12-18 20:59:07 +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
|
2014-04-17 01:16:21 +02:00
|
|
|
glamor_create_texture_from_image(ScreenPtr screen,
|
2013-12-18 20:59:07 +01:00
|
|
|
EGLImageKHR image, GLuint * texture)
|
2011-09-08 09:16:01 +02:00
|
|
|
{
|
2014-04-17 01:16:21 +02:00
|
|
|
struct glamor_screen_private *glamor_priv =
|
|
|
|
glamor_get_screen_private(screen);
|
|
|
|
|
2014-03-15 01:31:18 +01:00
|
|
|
glamor_make_current(glamor_priv);
|
2014-04-17 01:16:21 +02:00
|
|
|
|
2013-12-18 21:18:20 +01:00
|
|
|
glGenTextures(1, texture);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, *texture);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
|
|
|
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2014-04-17 01:16:21 +02:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
return TRUE;
|
2011-08-24 10:54:32 +02:00
|
|
|
}
|
|
|
|
|
2014-12-09 21:28:38 +01:00
|
|
|
void *
|
|
|
|
glamor_egl_get_gbm_device(ScreenPtr screen)
|
|
|
|
{
|
|
|
|
#ifdef GLAMOR_HAS_GBM
|
|
|
|
struct glamor_egl_screen_private *glamor_egl =
|
|
|
|
glamor_egl_get_screen_private(xf86ScreenToScrn(screen));
|
|
|
|
return glamor_egl->gbm;
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-12-05 08:49:15 +01:00
|
|
|
unsigned int
|
2015-06-10 06:46:22 +02:00
|
|
|
glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h, Bool linear)
|
2013-12-05 08:49:15 +01:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
|
|
|
struct glamor_egl_screen_private *glamor_egl;
|
|
|
|
EGLImageKHR image;
|
|
|
|
GLuint texture;
|
|
|
|
|
2013-12-27 23:21:05 +01:00
|
|
|
#ifdef GLAMOR_HAS_GBM
|
2013-12-18 20:59:07 +01:00
|
|
|
struct gbm_bo *bo;
|
|
|
|
EGLNativePixmapType native_pixmap;
|
|
|
|
|
|
|
|
glamor_egl = glamor_egl_get_screen_private(scrn);
|
|
|
|
bo = gbm_bo_create(glamor_egl->gbm, w, h, GBM_FORMAT_ARGB8888,
|
2015-06-10 06:46:22 +02:00
|
|
|
#ifdef GLAMOR_HAS_GBM_LINEAR
|
|
|
|
(linear ? GBM_BO_USE_LINEAR : 0) |
|
|
|
|
#endif
|
2013-12-18 20:59:07 +01:00
|
|
|
GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
|
|
|
|
if (!bo)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* If the following assignment raises an error or a warning
|
|
|
|
* then that means EGLNativePixmapType is not struct gbm_bo *
|
|
|
|
* on your platform: This code won't work and you should not
|
|
|
|
* compile with dri3 support enabled */
|
|
|
|
native_pixmap = bo;
|
|
|
|
|
2013-12-18 21:18:20 +01:00
|
|
|
image = eglCreateImageKHR(glamor_egl->display,
|
|
|
|
EGL_NO_CONTEXT,
|
|
|
|
EGL_NATIVE_PIXMAP_KHR,
|
|
|
|
native_pixmap, NULL);
|
2013-12-18 20:59:07 +01:00
|
|
|
gbm_bo_destroy(bo);
|
|
|
|
if (image == EGL_NO_IMAGE_KHR)
|
|
|
|
return 0;
|
2014-04-17 01:16:21 +02:00
|
|
|
glamor_create_texture_from_image(screen, image, &texture);
|
2013-12-18 21:18:20 +01:00
|
|
|
eglDestroyImageKHR(glamor_egl->display, image);
|
2013-12-18 20:59:07 +01:00
|
|
|
|
|
|
|
return texture;
|
2013-12-05 08:49:15 +01:00
|
|
|
#else
|
2013-12-18 20:59:07 +01:00
|
|
|
return 0; /* this path should never happen */
|
2013-12-05 08:49:15 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
|
|
|
PixmapPtr screen_pixmap;
|
|
|
|
|
|
|
|
screen_pixmap = screen->GetScreenPixmap(screen);
|
|
|
|
|
|
|
|
if (!glamor_egl_create_textured_pixmap(screen_pixmap, handle, stride)) {
|
|
|
|
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
|
|
|
"Failed to create textured screen.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-12-05 19:58:28 +01:00
|
|
|
glamor_set_screen_pixmap(screen_pixmap, NULL);
|
2013-12-18 20:59:07 +01:00
|
|
|
return TRUE;
|
2012-02-17 09:56:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
glamor_egl_create_textured_screen_ext(ScreenPtr screen,
|
2013-12-18 20:59:07 +01:00
|
|
|
int handle,
|
|
|
|
int stride, PixmapPtr *back_pixmap)
|
2012-02-17 09:56:05 +01:00
|
|
|
{
|
2014-12-05 19:58:28 +01:00
|
|
|
return glamor_egl_create_textured_screen(screen, handle, stride);
|
2011-09-08 09:16:01 +02:00
|
|
|
}
|
|
|
|
|
2012-05-15 04:42:41 +02:00
|
|
|
static Bool
|
2012-01-20 09:23:17 +01:00
|
|
|
glamor_egl_check_has_gem(int fd)
|
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
struct drm_gem_flink flink;
|
2012-01-20 09:23:17 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
flink.handle = 0;
|
|
|
|
|
|
|
|
ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
|
|
|
|
if (errno == ENOENT || errno == EINVAL)
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
2012-01-20 09:23:17 +01:00
|
|
|
}
|
|
|
|
|
2014-12-08 21:59:31 +01:00
|
|
|
static void
|
|
|
|
glamor_egl_set_pixmap_image(PixmapPtr pixmap, EGLImageKHR image)
|
|
|
|
{
|
|
|
|
struct glamor_pixmap_private *pixmap_priv =
|
|
|
|
glamor_get_pixmap_private(pixmap);
|
|
|
|
EGLImageKHR old;
|
|
|
|
|
2014-10-30 07:08:57 +01:00
|
|
|
old = pixmap_priv->image;
|
2014-12-08 21:59:31 +01:00
|
|
|
if (old) {
|
|
|
|
ScreenPtr screen = pixmap->drawable.pScreen;
|
|
|
|
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
|
|
|
struct glamor_egl_screen_private *glamor_egl = glamor_egl_get_screen_private(scrn);
|
|
|
|
|
|
|
|
eglDestroyImageKHR(glamor_egl->display, old);
|
|
|
|
}
|
2014-10-30 07:08:57 +01:00
|
|
|
pixmap_priv->image = image;
|
2014-12-08 21:59:31 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
ScreenPtr screen = pixmap->drawable.pScreen;
|
|
|
|
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
2013-12-19 00:27:52 +01:00
|
|
|
struct glamor_screen_private *glamor_priv =
|
|
|
|
glamor_get_screen_private(screen);
|
2013-12-18 20:59:07 +01:00
|
|
|
struct glamor_egl_screen_private *glamor_egl;
|
|
|
|
EGLImageKHR image;
|
|
|
|
GLuint texture;
|
|
|
|
int name;
|
|
|
|
Bool ret = FALSE;
|
|
|
|
|
|
|
|
glamor_egl = glamor_egl_get_screen_private(scrn);
|
|
|
|
|
2014-03-15 01:31:18 +01:00
|
|
|
glamor_make_current(glamor_priv);
|
2013-12-18 20:59:07 +01:00
|
|
|
if (glamor_egl->has_gem) {
|
|
|
|
if (!glamor_get_flink_name(glamor_egl->fd, handle, &name)) {
|
|
|
|
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
|
|
|
"Couldn't flink pixmap handle\n");
|
|
|
|
glamor_set_pixmap_type(pixmap, GLAMOR_DRM_ONLY);
|
|
|
|
assert(0);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
name = handle;
|
|
|
|
|
|
|
|
image = _glamor_egl_create_image(glamor_egl,
|
|
|
|
pixmap->drawable.width,
|
|
|
|
pixmap->drawable.height,
|
|
|
|
((stride * 8 +
|
|
|
|
7) / pixmap->drawable.bitsPerPixel),
|
|
|
|
name, pixmap->drawable.depth);
|
|
|
|
if (image == EGL_NO_IMAGE_KHR) {
|
|
|
|
glamor_set_pixmap_type(pixmap, GLAMOR_DRM_ONLY);
|
|
|
|
goto done;
|
|
|
|
}
|
2014-04-17 01:16:21 +02:00
|
|
|
glamor_create_texture_from_image(screen, image, &texture);
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
|
|
|
|
glamor_set_pixmap_texture(pixmap, texture);
|
2014-12-08 21:59:31 +01:00
|
|
|
glamor_egl_set_pixmap_image(pixmap, image);
|
2013-12-18 20:59:07 +01:00
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
return ret;
|
2011-11-02 06:44:50 +01:00
|
|
|
}
|
|
|
|
|
2013-11-18 22:52:22 +01:00
|
|
|
Bool
|
|
|
|
glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap, void *bo)
|
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
ScreenPtr screen = pixmap->drawable.pScreen;
|
|
|
|
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
2013-12-19 00:27:52 +01:00
|
|
|
struct glamor_screen_private *glamor_priv =
|
|
|
|
glamor_get_screen_private(screen);
|
2013-12-18 20:59:07 +01:00
|
|
|
struct glamor_egl_screen_private *glamor_egl;
|
|
|
|
EGLImageKHR image;
|
|
|
|
GLuint texture;
|
|
|
|
Bool ret = FALSE;
|
|
|
|
|
|
|
|
glamor_egl = glamor_egl_get_screen_private(scrn);
|
|
|
|
|
2014-03-15 01:31:18 +01:00
|
|
|
glamor_make_current(glamor_priv);
|
2013-12-18 20:59:07 +01:00
|
|
|
|
2013-12-18 21:18:20 +01:00
|
|
|
image = eglCreateImageKHR(glamor_egl->display,
|
|
|
|
glamor_egl->context,
|
|
|
|
EGL_NATIVE_PIXMAP_KHR, bo, NULL);
|
2013-12-18 20:59:07 +01:00
|
|
|
if (image == EGL_NO_IMAGE_KHR) {
|
|
|
|
glamor_set_pixmap_type(pixmap, GLAMOR_DRM_ONLY);
|
|
|
|
goto done;
|
|
|
|
}
|
2014-04-17 01:16:21 +02:00
|
|
|
glamor_create_texture_from_image(screen, image, &texture);
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
|
|
|
|
glamor_set_pixmap_texture(pixmap, texture);
|
2014-12-08 21:59:31 +01:00
|
|
|
glamor_egl_set_pixmap_image(pixmap, image);
|
2013-12-18 20:59:07 +01:00
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
return ret;
|
2013-11-18 22:52:22 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 23:21:05 +01:00
|
|
|
#ifdef GLAMOR_HAS_GBM
|
2013-12-18 20:59:07 +01:00
|
|
|
int glamor_get_fd_from_bo(int gbm_fd, struct gbm_bo *bo, int *fd);
|
|
|
|
void glamor_get_name_from_bo(int gbm_fd, struct gbm_bo *bo, int *name);
|
2013-12-05 08:49:15 +01:00
|
|
|
int
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_get_fd_from_bo(int gbm_fd, struct gbm_bo *bo, int *fd)
|
2013-12-05 08:49:15 +01:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
union gbm_bo_handle handle;
|
|
|
|
struct drm_prime_handle args;
|
|
|
|
|
|
|
|
handle = gbm_bo_get_handle(bo);
|
|
|
|
args.handle = handle.u32;
|
|
|
|
args.flags = DRM_CLOEXEC;
|
|
|
|
if (ioctl(gbm_fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args))
|
|
|
|
return FALSE;
|
|
|
|
*fd = args.fd;
|
|
|
|
return TRUE;
|
2013-12-05 08:49:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_get_name_from_bo(int gbm_fd, struct gbm_bo *bo, int *name)
|
2013-12-05 08:49:15 +01:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
union gbm_bo_handle handle;
|
2013-12-05 08:49:15 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
handle = gbm_bo_get_handle(bo);
|
|
|
|
if (!glamor_get_flink_name(gbm_fd, handle.u32, name))
|
|
|
|
*name = -1;
|
2013-12-05 08:49:15 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-12-27 23:21:05 +01:00
|
|
|
#ifdef GLAMOR_HAS_GBM
|
2015-01-14 02:00:28 +01:00
|
|
|
static void *
|
|
|
|
_get_gbm_bo_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, unsigned int tex)
|
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
2013-12-28 03:45:44 +01:00
|
|
|
struct glamor_pixmap_private *pixmap_priv =
|
|
|
|
glamor_get_pixmap_private(pixmap);
|
2013-12-19 00:27:52 +01:00
|
|
|
struct glamor_screen_private *glamor_priv =
|
|
|
|
glamor_get_screen_private(screen);
|
2013-12-18 20:59:07 +01:00
|
|
|
struct glamor_egl_screen_private *glamor_egl;
|
|
|
|
EGLImageKHR image;
|
|
|
|
struct gbm_bo *bo;
|
|
|
|
|
|
|
|
EGLint attribs[] = {
|
|
|
|
EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
|
|
|
|
EGL_GL_TEXTURE_LEVEL_KHR, 0,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
glamor_egl = glamor_egl_get_screen_private(scrn);
|
|
|
|
|
2014-03-15 01:31:18 +01:00
|
|
|
glamor_make_current(glamor_priv);
|
2013-12-18 20:59:07 +01:00
|
|
|
|
2014-10-30 07:08:57 +01:00
|
|
|
image = pixmap_priv->image;
|
2013-12-28 03:45:44 +01:00
|
|
|
if (!image) {
|
2013-12-18 21:18:20 +01:00
|
|
|
image = eglCreateImageKHR(glamor_egl->display,
|
|
|
|
glamor_egl->context,
|
|
|
|
EGL_GL_TEXTURE_2D_KHR,
|
|
|
|
(EGLClientBuffer) (uintptr_t)
|
|
|
|
tex, attribs);
|
2013-12-18 20:59:07 +01:00
|
|
|
if (image == EGL_NO_IMAGE_KHR)
|
2015-01-14 02:00:28 +01:00
|
|
|
return NULL;
|
2013-12-18 20:59:07 +01:00
|
|
|
|
|
|
|
glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
|
2014-12-08 21:59:31 +01:00
|
|
|
glamor_egl_set_pixmap_image(pixmap, image);
|
2013-12-18 20:59:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_EGL_IMAGE, image, 0);
|
2015-01-14 02:00:28 +01:00
|
|
|
if (!bo)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pixmap->devKind = gbm_bo_get_stride(bo);
|
|
|
|
|
|
|
|
return bo;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void *
|
|
|
|
glamor_gbm_bo_from_pixmap(ScreenPtr screen, PixmapPtr pixmap)
|
|
|
|
{
|
|
|
|
#ifdef GLAMOR_HAS_GBM
|
|
|
|
glamor_screen_private *glamor_priv =
|
|
|
|
glamor_get_screen_private(pixmap->drawable.pScreen);
|
|
|
|
glamor_pixmap_private *pixmap_priv =
|
|
|
|
glamor_get_pixmap_private(pixmap);
|
|
|
|
|
|
|
|
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
|
|
|
if (pixmap_priv == NULL || !glamor_priv->dri3_enabled)
|
|
|
|
return NULL;
|
|
|
|
switch (pixmap_priv->type) {
|
|
|
|
case GLAMOR_TEXTURE_DRM:
|
|
|
|
case GLAMOR_TEXTURE_ONLY:
|
|
|
|
if (!glamor_pixmap_ensure_fbo(pixmap, GL_RGBA, 0))
|
|
|
|
return NULL;
|
|
|
|
return _get_gbm_bo_from_pixmap(screen, pixmap,
|
|
|
|
pixmap_priv->fbo->tex);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
|
|
|
|
PixmapPtr pixmap,
|
|
|
|
unsigned int tex,
|
|
|
|
Bool want_name, CARD16 *stride, CARD32 *size)
|
|
|
|
{
|
|
|
|
#ifdef GLAMOR_HAS_GBM
|
|
|
|
struct glamor_egl_screen_private *glamor_egl;
|
|
|
|
struct gbm_bo *bo;
|
|
|
|
int fd = -1;
|
|
|
|
|
|
|
|
glamor_egl = glamor_egl_get_screen_private(xf86ScreenToScrn(screen));
|
|
|
|
|
|
|
|
bo = _get_gbm_bo_from_pixmap(screen, pixmap, tex);
|
2013-12-18 20:59:07 +01:00
|
|
|
if (!bo)
|
|
|
|
goto failure;
|
|
|
|
|
|
|
|
pixmap->devKind = gbm_bo_get_stride(bo);
|
|
|
|
|
|
|
|
if (want_name) {
|
|
|
|
if (glamor_egl->has_gem)
|
|
|
|
glamor_get_name_from_bo(glamor_egl->fd, bo, &fd);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (glamor_get_fd_from_bo(glamor_egl->fd, bo, &fd)) {
|
|
|
|
}
|
|
|
|
}
|
2013-12-31 03:41:57 +01:00
|
|
|
*stride = pixmap->devKind;
|
|
|
|
*size = pixmap->devKind * gbm_bo_get_height(bo);
|
2013-12-18 20:59:07 +01:00
|
|
|
|
|
|
|
gbm_bo_destroy(bo);
|
|
|
|
failure:
|
|
|
|
return fd;
|
2013-12-05 08:49:15 +01:00
|
|
|
#else
|
2013-12-18 20:59:07 +01:00
|
|
|
return -1;
|
2013-12-05 08:49:15 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-06-10 05:38:39 +02:00
|
|
|
_X_EXPORT Bool
|
|
|
|
glamor_back_pixmap_from_fd(PixmapPtr pixmap,
|
|
|
|
int fd,
|
|
|
|
CARD16 width,
|
|
|
|
CARD16 height,
|
|
|
|
CARD16 stride, CARD8 depth, CARD8 bpp)
|
2013-12-05 08:49:15 +01:00
|
|
|
{
|
2013-12-27 23:21:05 +01:00
|
|
|
#ifdef GLAMOR_HAS_GBM
|
2015-06-10 05:38:39 +02:00
|
|
|
ScreenPtr screen = pixmap->drawable.pScreen;
|
2013-12-18 20:59:07 +01:00
|
|
|
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
|
|
|
struct glamor_egl_screen_private *glamor_egl;
|
|
|
|
struct gbm_bo *bo;
|
|
|
|
EGLImageKHR image;
|
|
|
|
Bool ret = FALSE;
|
|
|
|
|
|
|
|
EGLint attribs[] = {
|
|
|
|
EGL_WIDTH, 0,
|
|
|
|
EGL_HEIGHT, 0,
|
|
|
|
EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
|
|
|
|
EGL_DMA_BUF_PLANE0_FD_EXT, 0,
|
|
|
|
EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
|
|
|
|
EGL_DMA_BUF_PLANE0_PITCH_EXT, 0,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
glamor_egl = glamor_egl_get_screen_private(scrn);
|
|
|
|
|
|
|
|
if (!glamor_egl->dri3_capable)
|
2015-06-10 05:38:39 +02:00
|
|
|
return FALSE;
|
2013-12-18 20:59:07 +01:00
|
|
|
|
|
|
|
if (bpp != 32 || !(depth == 24 || depth == 32) || width == 0 || height == 0)
|
2015-06-10 05:38:39 +02:00
|
|
|
return FALSE;
|
2013-12-18 20:59:07 +01:00
|
|
|
|
|
|
|
attribs[1] = width;
|
|
|
|
attribs[3] = height;
|
|
|
|
attribs[7] = fd;
|
|
|
|
attribs[11] = stride;
|
2013-12-18 21:18:20 +01:00
|
|
|
image = eglCreateImageKHR(glamor_egl->display,
|
|
|
|
EGL_NO_CONTEXT,
|
|
|
|
EGL_LINUX_DMA_BUF_EXT,
|
|
|
|
NULL, attribs);
|
2013-12-18 20:59:07 +01:00
|
|
|
|
|
|
|
if (image == EGL_NO_IMAGE_KHR)
|
2015-06-10 05:38:39 +02:00
|
|
|
return FALSE;
|
2013-12-18 20:59:07 +01:00
|
|
|
|
|
|
|
/* EGL_EXT_image_dma_buf_import can impose restrictions on the
|
|
|
|
* usage of the image. Use gbm_bo to bypass the limitations. */
|
|
|
|
bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_EGL_IMAGE, image, 0);
|
2013-12-18 21:18:20 +01:00
|
|
|
eglDestroyImageKHR(glamor_egl->display, image);
|
2013-12-18 20:59:07 +01:00
|
|
|
|
|
|
|
if (!bo)
|
2015-06-10 05:38:39 +02:00
|
|
|
return FALSE;
|
2013-12-18 20:59:07 +01:00
|
|
|
|
|
|
|
screen->ModifyPixmapHeader(pixmap, width, height, 0, 0, stride, NULL);
|
|
|
|
|
|
|
|
ret = glamor_egl_create_textured_pixmap_from_gbm_bo(pixmap, bo);
|
|
|
|
gbm_bo_destroy(bo);
|
|
|
|
|
|
|
|
if (ret)
|
2015-06-10 05:38:39 +02:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
_X_EXPORT PixmapPtr
|
|
|
|
glamor_pixmap_from_fd(ScreenPtr screen,
|
|
|
|
int fd,
|
|
|
|
CARD16 width,
|
|
|
|
CARD16 height,
|
|
|
|
CARD16 stride, CARD8 depth, CARD8 bpp)
|
|
|
|
{
|
|
|
|
#ifdef GLAMOR_HAS_GBM
|
|
|
|
PixmapPtr pixmap;
|
|
|
|
Bool ret;
|
|
|
|
|
|
|
|
pixmap = screen->CreatePixmap(screen, 0, 0, depth, 0);
|
|
|
|
ret = glamor_back_pixmap_from_fd(pixmap, fd, width, height,
|
|
|
|
stride, depth, bpp);
|
|
|
|
if (ret == FALSE) {
|
2013-12-18 20:59:07 +01:00
|
|
|
screen->DestroyPixmap(pixmap);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-06-10 05:38:39 +02:00
|
|
|
return pixmap;
|
2013-12-05 08:49:15 +01:00
|
|
|
#else
|
2013-12-18 20:59:07 +01:00
|
|
|
return NULL;
|
2013-12-05 08:49:15 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-12-05 19:58:28 +01:00
|
|
|
void
|
|
|
|
glamor_egl_destroy_pixmap_image(PixmapPtr pixmap)
|
2011-11-02 06:44:50 +01:00
|
|
|
{
|
2013-12-28 03:45:44 +01:00
|
|
|
struct glamor_pixmap_private *pixmap_priv =
|
|
|
|
glamor_get_pixmap_private(pixmap);
|
2013-12-18 20:59:07 +01:00
|
|
|
|
2014-10-30 07:08:57 +01:00
|
|
|
if (pixmap_priv && pixmap_priv->image) {
|
2014-12-05 19:58:28 +01:00
|
|
|
ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
|
|
|
|
struct glamor_egl_screen_private *glamor_egl =
|
|
|
|
glamor_egl_get_screen_private(scrn);
|
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
/* 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);
|
2014-10-30 07:08:57 +01:00
|
|
|
eglDestroyImageKHR(glamor_egl->display, pixmap_priv->image);
|
|
|
|
pixmap_priv->image = NULL;
|
2013-12-18 20:59:07 +01:00
|
|
|
}
|
2012-01-31 11:16:58 +01:00
|
|
|
}
|
|
|
|
|
2012-02-17 09:56:05 +01:00
|
|
|
_X_EXPORT void
|
|
|
|
glamor_egl_exchange_buffers(PixmapPtr front, PixmapPtr back)
|
|
|
|
{
|
2013-12-28 03:45:44 +01:00
|
|
|
EGLImageKHR temp;
|
|
|
|
struct glamor_pixmap_private *front_priv =
|
|
|
|
glamor_get_pixmap_private(front);
|
|
|
|
struct glamor_pixmap_private *back_priv =
|
|
|
|
glamor_get_pixmap_private(back);
|
2013-12-18 20:59:07 +01:00
|
|
|
|
|
|
|
glamor_pixmap_exchange_fbos(front, back);
|
2013-12-28 03:45:44 +01:00
|
|
|
|
2014-10-30 07:08:57 +01:00
|
|
|
temp = back_priv->image;
|
|
|
|
back_priv->image = front_priv->image;
|
|
|
|
front_priv->image = temp;
|
2013-12-28 03:45:44 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_set_pixmap_type(front, GLAMOR_TEXTURE_DRM);
|
|
|
|
glamor_set_pixmap_type(back, GLAMOR_TEXTURE_DRM);
|
2012-02-17 09:56:05 +01:00
|
|
|
}
|
|
|
|
|
2014-12-10 08:21:44 +01:00
|
|
|
void
|
|
|
|
glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap)
|
|
|
|
{
|
|
|
|
glamor_destroy_textured_pixmap(pixmap);
|
|
|
|
}
|
|
|
|
|
2012-01-31 11:16:58 +01:00
|
|
|
static Bool
|
2013-12-18 01:32:17 +01:00
|
|
|
glamor_egl_close_screen(ScreenPtr screen)
|
2011-08-24 10:54:32 +02:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
ScrnInfoPtr scrn;
|
|
|
|
struct glamor_egl_screen_private *glamor_egl;
|
2013-12-28 03:45:44 +01:00
|
|
|
struct glamor_pixmap_private *pixmap_priv;
|
2013-12-18 20:59:07 +01:00
|
|
|
PixmapPtr screen_pixmap;
|
|
|
|
|
|
|
|
scrn = xf86ScreenToScrn(screen);
|
|
|
|
glamor_egl = glamor_egl_get_screen_private(scrn);
|
|
|
|
screen_pixmap = screen->GetScreenPixmap(screen);
|
2013-12-28 03:45:44 +01:00
|
|
|
pixmap_priv = glamor_get_pixmap_private(screen_pixmap);
|
2013-12-18 20:59:07 +01:00
|
|
|
|
2014-10-30 07:08:57 +01:00
|
|
|
eglDestroyImageKHR(glamor_egl->display, pixmap_priv->image);
|
|
|
|
pixmap_priv->image = NULL;
|
2013-12-28 03:45:44 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
screen->CloseScreen = glamor_egl->saved_close_screen;
|
|
|
|
|
2013-12-18 01:32:17 +01:00
|
|
|
return screen->CloseScreen(screen);
|
2011-08-24 10:54:32 +02:00
|
|
|
}
|
|
|
|
|
2015-04-15 13:29:58 +02:00
|
|
|
#ifdef DRI3
|
2013-12-31 09:07:42 +01:00
|
|
|
static int
|
2014-04-05 01:28:43 +02:00
|
|
|
glamor_dri3_open_client(ClientPtr client,
|
|
|
|
ScreenPtr screen,
|
|
|
|
RRProviderPtr provider,
|
|
|
|
int *fdp)
|
2013-12-31 09:07:42 +01:00
|
|
|
{
|
|
|
|
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
|
|
|
struct glamor_egl_screen_private *glamor_egl =
|
|
|
|
glamor_egl_get_screen_private(scrn);
|
|
|
|
int fd;
|
|
|
|
drm_magic_t magic;
|
|
|
|
|
|
|
|
fd = open(glamor_egl->device_path, O_RDWR|O_CLOEXEC);
|
|
|
|
if (fd < 0)
|
|
|
|
return BadAlloc;
|
|
|
|
|
|
|
|
/* Before FD passing in the X protocol with DRI3 (and increased
|
|
|
|
* security of rendering with per-process address spaces on the
|
|
|
|
* GPU), the kernel had to come up with a way to have the server
|
|
|
|
* decide which clients got to access the GPU, which was done by
|
|
|
|
* each client getting a unique (magic) number from the kernel,
|
|
|
|
* passing it to the server, and the server then telling the
|
|
|
|
* kernel which clients were authenticated for using the device.
|
|
|
|
*
|
|
|
|
* Now that we have FD passing, the server can just set up the
|
|
|
|
* authentication on its own and hand the prepared FD off to the
|
|
|
|
* client.
|
|
|
|
*/
|
|
|
|
if (drmGetMagic(fd, &magic) < 0) {
|
|
|
|
if (errno == EACCES) {
|
|
|
|
/* Assume that we're on a render node, and the fd is
|
|
|
|
* already as authenticated as it should be.
|
|
|
|
*/
|
|
|
|
*fdp = fd;
|
|
|
|
return Success;
|
|
|
|
} else {
|
|
|
|
close(fd);
|
|
|
|
return BadMatch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drmAuthMagic(glamor_egl->fd, magic) < 0) {
|
|
|
|
close(fd);
|
|
|
|
return BadMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
*fdp = fd;
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
static dri3_screen_info_rec glamor_dri3_info = {
|
2014-04-05 01:28:43 +02:00
|
|
|
.version = 1,
|
|
|
|
.open_client = glamor_dri3_open_client,
|
2013-12-31 09:07:42 +01:00
|
|
|
.pixmap_from_fd = glamor_pixmap_from_fd,
|
|
|
|
.fd_from_pixmap = glamor_fd_from_pixmap,
|
|
|
|
};
|
2015-04-15 13:29:58 +02:00
|
|
|
#endif /* DRI3 */
|
2013-12-31 09:07:42 +01:00
|
|
|
|
2012-01-31 11:16:58 +01:00
|
|
|
void
|
2013-12-19 00:27:52 +01:00
|
|
|
glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
|
2012-01-31 11:16:58 +01:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
|
|
|
struct glamor_egl_screen_private *glamor_egl =
|
|
|
|
glamor_egl_get_screen_private(scrn);
|
2012-01-31 11:16:58 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_egl->saved_close_screen = screen->CloseScreen;
|
|
|
|
screen->CloseScreen = glamor_egl_close_screen;
|
2013-12-19 00:27:52 +01:00
|
|
|
|
|
|
|
glamor_ctx->ctx = glamor_egl->context;
|
|
|
|
glamor_ctx->display = glamor_egl->display;
|
|
|
|
|
2014-03-15 01:31:18 +01:00
|
|
|
glamor_ctx->make_current = glamor_egl_make_current;
|
2013-12-31 09:07:42 +01:00
|
|
|
|
2015-04-15 13:29:58 +02:00
|
|
|
#ifdef DRI3
|
2013-12-31 09:07:42 +01:00
|
|
|
if (glamor_egl->dri3_capable) {
|
2015-04-15 13:29:58 +02:00
|
|
|
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
|
2013-12-31 09:07:42 +01:00
|
|
|
/* Tell the core that we have the interfaces for import/export
|
|
|
|
* of pixmaps.
|
|
|
|
*/
|
|
|
|
glamor_enable_dri3(screen);
|
|
|
|
|
|
|
|
/* If the driver wants to do its own auth dance (e.g. Xwayland
|
|
|
|
* on pre-3.15 kernels that don't have render nodes and thus
|
|
|
|
* has the wayland compositor as a master), then it needs us
|
|
|
|
* to stay out of the way and let it init DRI3 on its own.
|
|
|
|
*/
|
|
|
|
if (!(glamor_priv->flags & GLAMOR_NO_DRI3)) {
|
|
|
|
/* To do DRI3 device FD generation, we need to open a new fd
|
|
|
|
* to the same device we were handed in originally.
|
|
|
|
*/
|
|
|
|
glamor_egl->device_path = drmGetDeviceNameFromFd(glamor_egl->fd);
|
|
|
|
|
|
|
|
if (!dri3_screen_init(screen, &glamor_dri3_info)) {
|
|
|
|
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
|
|
|
"Failed to initialize DRI3.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-15 13:29:58 +02:00
|
|
|
#endif
|
2012-01-31 11:16:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-12-18 01:32:17 +01:00
|
|
|
glamor_egl_free_screen(ScrnInfoPtr scrn)
|
2012-01-31 11:16:58 +01:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
struct glamor_egl_screen_private *glamor_egl;
|
|
|
|
|
|
|
|
glamor_egl = glamor_egl_get_screen_private(scrn);
|
|
|
|
if (glamor_egl != NULL) {
|
2012-01-31 11:16:58 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
eglMakeCurrent(glamor_egl->display,
|
|
|
|
EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
2012-01-31 11:16:58 +01:00
|
|
|
#ifdef GLAMOR_HAS_GBM
|
2013-12-18 20:59:07 +01:00
|
|
|
if (glamor_egl->gbm)
|
|
|
|
gbm_device_destroy(glamor_egl->gbm);
|
2012-01-31 11:16:58 +01:00
|
|
|
#endif
|
2013-12-31 09:07:42 +01:00
|
|
|
free(glamor_egl->device_path);
|
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
scrn->FreeScreen = glamor_egl->saved_free_screen;
|
|
|
|
free(glamor_egl);
|
2013-12-18 01:32:17 +01:00
|
|
|
scrn->FreeScreen(scrn);
|
2013-12-18 20:59:07 +01:00
|
|
|
}
|
2012-01-31 11:16:58 +01: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
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
struct glamor_egl_screen_private *glamor_egl;
|
|
|
|
const char *version;
|
|
|
|
|
|
|
|
EGLint config_attribs[] = {
|
2011-08-24 10:54:32 +02:00
|
|
|
#ifdef GLAMOR_GLES2
|
2013-12-18 20:59:07 +01:00
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
2011-08-24 10:54:32 +02:00
|
|
|
#endif
|
2013-12-18 20:59:07 +01:00
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
glamor_identify(0);
|
|
|
|
glamor_egl = calloc(sizeof(*glamor_egl), 1);
|
|
|
|
if (glamor_egl == NULL)
|
|
|
|
return FALSE;
|
|
|
|
if (xf86GlamorEGLPrivateIndex == -1)
|
|
|
|
xf86GlamorEGLPrivateIndex = xf86AllocateScrnInfoPrivateIndex();
|
|
|
|
|
|
|
|
scrn->privates[xf86GlamorEGLPrivateIndex].ptr = glamor_egl;
|
|
|
|
glamor_egl->fd = fd;
|
2012-01-20 05:10:06 +01:00
|
|
|
#ifdef GLAMOR_HAS_GBM
|
2013-12-18 20:59:07 +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;
|
|
|
|
}
|
|
|
|
glamor_egl->display = eglGetDisplay(glamor_egl->gbm);
|
2012-01-20 05:10:06 +01:00
|
|
|
#else
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_egl->display = eglGetDisplay((EGLNativeDisplayType) (intptr_t) fd);
|
2012-01-20 05:10:06 +01:00
|
|
|
#endif
|
2011-12-16 08:02:54 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_egl->has_gem = glamor_egl_check_has_gem(fd);
|
2012-01-20 09:23:17 +01:00
|
|
|
|
2011-08-24 10:54:32 +02:00
|
|
|
#ifndef GLAMOR_GLES2
|
2013-12-18 20:59:07 +01:00
|
|
|
eglBindAPI(EGL_OPENGL_API);
|
2011-08-24 10:54:32 +02:00
|
|
|
#else
|
2013-12-18 20:59:07 +01:00
|
|
|
eglBindAPI(EGL_OPENGL_ES_API);
|
2011-08-24 10:54:32 +02:00
|
|
|
#endif
|
2013-12-18 20:59:07 +01:00
|
|
|
if (!eglInitialize
|
|
|
|
(glamor_egl->display, &glamor_egl->major, &glamor_egl->minor)) {
|
|
|
|
xf86DrvMsg(scrn->scrnIndex, X_ERROR, "eglInitialize() failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-08-24 10:54:32 +02:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
version = eglQueryString(glamor_egl->display, EGL_VERSION);
|
|
|
|
xf86Msg(X_INFO, "%s: EGL version %s:\n", glamor_name, version);
|
2011-08-24 10:54:32 +02:00
|
|
|
|
|
|
|
#define GLAMOR_CHECK_EGL_EXTENSION(EXT) \
|
2013-12-28 03:27:56 +01:00
|
|
|
if (!epoxy_has_egl_extension(glamor_egl->display, "EGL_" #EXT)) { \
|
2012-08-07 18:13:32 +02:00
|
|
|
ErrorF("EGL_" #EXT " required.\n"); \
|
2011-12-13 15:48:34 +01:00
|
|
|
return FALSE; \
|
|
|
|
}
|
2011-08-24 10:54:32 +02:00
|
|
|
|
2012-08-07 18:16:58 +02:00
|
|
|
#define GLAMOR_CHECK_EGL_EXTENSIONS(EXT1, EXT2) \
|
2013-12-28 03:27:56 +01:00
|
|
|
if (!epoxy_has_egl_extension(glamor_egl->display, "EGL_" #EXT1) && \
|
|
|
|
!epoxy_has_egl_extension(glamor_egl->display, "EGL_" #EXT2)) { \
|
2012-08-07 18:16:58 +02:00
|
|
|
ErrorF("EGL_" #EXT1 " or EGL_" #EXT2 " required.\n"); \
|
|
|
|
return FALSE; \
|
|
|
|
}
|
|
|
|
|
2013-12-18 20:59:07 +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
|
2013-12-18 20:59:07 +01:00
|
|
|
GLAMOR_CHECK_EGL_EXTENSIONS(KHR_surfaceless_context, KHR_surfaceless_gles2);
|
2011-08-24 10:54:32 +02:00
|
|
|
#else
|
2013-12-18 20:59:07 +01:00
|
|
|
GLAMOR_CHECK_EGL_EXTENSIONS(KHR_surfaceless_context,
|
|
|
|
KHR_surfaceless_opengl);
|
2011-08-24 10:54:32 +02:00
|
|
|
#endif
|
|
|
|
|
2013-12-27 23:21:05 +01:00
|
|
|
#ifdef GLAMOR_HAS_GBM
|
2013-12-28 03:27:56 +01:00
|
|
|
if (epoxy_has_egl_extension(glamor_egl->display,
|
|
|
|
"EGL_KHR_gl_texture_2D_image") &&
|
|
|
|
epoxy_has_egl_extension(glamor_egl->display,
|
|
|
|
"EGL_EXT_image_dma_buf_import"))
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_egl->dri3_capable = TRUE;
|
2013-12-05 08:49:15 +01:00
|
|
|
#endif
|
2013-12-18 20:59:07 +01:00
|
|
|
|
|
|
|
glamor_egl->context = eglCreateContext(glamor_egl->display,
|
|
|
|
NULL, EGL_NO_CONTEXT,
|
|
|
|
config_attribs);
|
|
|
|
if (glamor_egl->context == EGL_NO_CONTEXT) {
|
|
|
|
xf86DrvMsg(scrn->scrnIndex, X_ERROR, "Failed to create EGL context\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!eglMakeCurrent(glamor_egl->display,
|
|
|
|
EGL_NO_SURFACE, EGL_NO_SURFACE, glamor_egl->context)) {
|
|
|
|
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
|
|
|
"Failed to make EGL context current\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
glamor_egl->saved_free_screen = scrn->FreeScreen;
|
|
|
|
scrn->FreeScreen = glamor_egl_free_screen;
|
2012-02-10 13:54:44 +01:00
|
|
|
#ifdef GLAMOR_GLES2
|
2013-12-18 20:59:07 +01:00
|
|
|
xf86DrvMsg(scrn->scrnIndex, X_INFO, "Using GLES2.\n");
|
|
|
|
xf86DrvMsg(scrn->scrnIndex, X_WARNING,
|
|
|
|
"Glamor is using GLES2 but GLX needs GL. "
|
|
|
|
"Indirect GLX may not work correctly.\n");
|
2012-02-10 13:54:44 +01:00
|
|
|
#endif
|
2013-12-18 20:59:07 +01:00
|
|
|
return TRUE;
|
2011-11-02 06:44:50 +01:00
|
|
|
}
|
2011-09-08 09:16:01 +02:00
|
|
|
|
2013-12-31 03:33:09 +01:00
|
|
|
/** Stub to retain compatibility with pre-server-1.16 ABI. */
|
2011-11-02 06:44:50 +01:00
|
|
|
Bool
|
|
|
|
glamor_egl_init_textured_pixmap(ScreenPtr screen)
|
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
return TRUE;
|
2011-08-24 10:54:32 +02:00
|
|
|
}
|