glamor-ddx: Reuse glamor_dix module to handle egl platform.
We already have a glamor egl module at glamor directory which could initialize and create egl context and also can attach a gbm buffer to a specified pixmap or to the screen pixmap. This commit remove all the duplicated code here and use the glamor_dix module directly. As we don't want to handle egl stuffs in this layer, we have to change the way to handle hardware cursor. Previous method is to call egl functions to create a egl image and then bind the image to a texutre then call gl functions to load texture image to the cursor bo. Now we can bind the cursor bo to a cursor pixmap and then use putimage to load new image to the cursor bo. Then we can completely avoid to call egl or gl functions directly in this ddx driver. Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
This commit is contained in:
parent
1590da0011
commit
09c63d3201
|
@ -9,14 +9,13 @@ glamor_la_CFLAGS = \
|
||||||
-I$(top_srcdir)/hw/xfree86/ddc \
|
-I$(top_srcdir)/hw/xfree86/ddc \
|
||||||
-I$(top_srcdir)/hw/xfree86/ramdac \
|
-I$(top_srcdir)/hw/xfree86/ramdac \
|
||||||
-I$(top_srcdir)/hw/xfree86/i2c \
|
-I$(top_srcdir)/hw/xfree86/i2c \
|
||||||
-I$(top_srcdir)/glamor
|
-I$(top_srcdir)/glamor
|
||||||
|
|
||||||
if GLAMOR_GLES2
|
if GLAMOR_GLES2
|
||||||
glamor_la_CFLAGS+=-DGLAMOR_GLES2
|
glamor_la_CFLAGS+=-DGLAMOR_GLES2
|
||||||
endif
|
endif
|
||||||
|
|
||||||
glamor_la_LDFLAGS = -module -avoid-version \
|
glamor_la_LDFLAGS = -module -avoid-version \
|
||||||
$(top_builddir)/glamor/libglamor.la \
|
|
||||||
$(EGL_LIBS)
|
$(EGL_LIBS)
|
||||||
|
|
||||||
glamor_ladir = $(moduledir)/drivers
|
glamor_ladir = $(moduledir)/drivers
|
||||||
|
|
|
@ -41,9 +41,9 @@
|
||||||
#include "../../../mi/micmap.h"
|
#include "../../../mi/micmap.h"
|
||||||
#include <xf86Crtc.h>
|
#include <xf86Crtc.h>
|
||||||
#include <xf86.h>
|
#include <xf86.h>
|
||||||
#define GC XORG_GC
|
//#define GC XORG_GC
|
||||||
#include <glamor.h>
|
#include <glamor.h>
|
||||||
#undef GC
|
//#undef GC
|
||||||
|
|
||||||
#include "glamor_ddx.h"
|
#include "glamor_ddx.h"
|
||||||
|
|
||||||
|
@ -59,50 +59,50 @@ glamor_ddx_identify(int flags)
|
||||||
xf86Msg(X_INFO, "Standalone %s: OpenGL accelerated X.org driver\n", glamor_ddx_name);
|
xf86Msg(X_INFO, "Standalone %s: OpenGL accelerated X.org driver\n", glamor_ddx_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool
|
static Bool
|
||||||
glamor_resize(ScrnInfoPtr scrn, int width, int height)
|
glamor_ddx_init_front_buffer(ScrnInfoPtr scrn, int width, int height)
|
||||||
{
|
{
|
||||||
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
||||||
ScreenPtr screen = screenInfo.screens[scrn->scrnIndex];
|
|
||||||
EGLImageKHR image;
|
|
||||||
GLuint texture;
|
|
||||||
|
|
||||||
if (glamor->root != EGL_NO_IMAGE_KHR &&
|
glamor->root_bo = gbm_bo_create(glamor->gbm, width, height,
|
||||||
scrn->virtualX == width && scrn->virtualY == height)
|
|
||||||
return TRUE;
|
|
||||||
else if (scrn->virtualX != width || scrn->virtualY != height) {
|
|
||||||
|
|
||||||
if (glamor->root != EGL_NO_IMAGE_KHR) {
|
|
||||||
eglDestroyImageKHR(glamor->display, glamor->root);
|
|
||||||
gbm_bo_destroy(glamor->root_bo);
|
|
||||||
glamor->root = EGL_NO_IMAGE_KHR;
|
|
||||||
}
|
|
||||||
glamor->root_bo = gbm_bo_create(glamor->gbm, width, height,
|
|
||||||
GBM_BO_FORMAT_ARGB8888,
|
GBM_BO_FORMAT_ARGB8888,
|
||||||
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
|
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
|
||||||
}
|
|
||||||
|
|
||||||
if (glamor->root_bo == NULL)
|
if (glamor->root_bo == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
image = glamor->egl_create_image_khr(glamor->display, NULL, EGL_NATIVE_PIXMAP_KHR, glamor->root_bo, NULL);
|
scrn->virtualX = width;
|
||||||
|
scrn->virtualY = height;
|
||||||
|
/* XXX shall we update displayWidth here ? */
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (image == EGL_NO_IMAGE_KHR) {
|
static Bool
|
||||||
gbm_bo_destroy(glamor->root_bo);
|
glamor_create_screen_image(ScrnInfoPtr scrn)
|
||||||
return FALSE;
|
{
|
||||||
}
|
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
||||||
|
ScreenPtr screen = screenInfo.screens[scrn->scrnIndex];
|
||||||
|
unsigned int handle, stride;
|
||||||
|
handle = gbm_bo_get_handle(glamor->root_bo).u32;
|
||||||
|
stride = gbm_bo_get_pitch(glamor->root_bo);
|
||||||
|
return glamor_create_egl_screen_image(screen, handle, stride);
|
||||||
|
}
|
||||||
|
|
||||||
glGenTextures(1, &texture);
|
Bool
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glamor_front_buffer_resize(ScrnInfoPtr scrn, int width, int height)
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
{
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
||||||
(glamor->egl_image_target_texture2d_oes)(GL_TEXTURE_2D, image);
|
ScreenPtr screen = screenInfo.screens[scrn->scrnIndex];
|
||||||
|
|
||||||
glamor_set_screen_pixmap_texture(screen, width, height, texture);
|
if (glamor->root_bo != NULL) {
|
||||||
glamor->root = image;
|
glamor_close_egl_screen(screen);
|
||||||
scrn->virtualX = width;
|
gbm_bo_destroy(glamor->root_bo);
|
||||||
scrn->virtualY = height;
|
glamor->root_bo = NULL;
|
||||||
return TRUE;
|
}
|
||||||
|
|
||||||
|
if (!glamor_ddx_init_front_buffer(scrn, width, height))
|
||||||
|
return FALSE;
|
||||||
|
return glamor_create_screen_image(scrn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -113,32 +113,56 @@ glamor_frontbuffer_handle(ScrnInfoPtr scrn, uint32_t *handle, uint32_t *pitch)
|
||||||
*pitch = gbm_bo_get_pitch(glamor->root_bo);
|
*pitch = gbm_bo_get_pitch(glamor->root_bo);
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLImageKHR glamor_create_cursor_argb(ScrnInfoPtr scrn, int width, int height)
|
Bool
|
||||||
|
glamor_create_cursor(ScrnInfoPtr scrn, struct glamor_gbm_cursor *cursor, int width, int height)
|
||||||
{
|
{
|
||||||
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
||||||
glamor->cursor_bo = gbm_bo_create(glamor->gbm, width, height,
|
ScreenPtr screen = screenInfo.screens[scrn->scrnIndex];
|
||||||
|
unsigned int handle, stride;
|
||||||
|
|
||||||
|
|
||||||
|
if (cursor->cursor_pixmap)
|
||||||
|
glamor_destroy_cursor(scrn, cursor);
|
||||||
|
|
||||||
|
cursor->cursor_pixmap = screen->CreatePixmap(screen, 0, 0, 32, 0);
|
||||||
|
if (cursor->cursor_pixmap == NULL)
|
||||||
|
return FALSE;
|
||||||
|
screen->ModifyPixmapHeader(cursor->cursor_pixmap, width, height, 0, 0, 0, 0);
|
||||||
|
cursor->cursor_bo = gbm_bo_create(glamor->gbm, width, height,
|
||||||
GBM_BO_FORMAT_ARGB8888,
|
GBM_BO_FORMAT_ARGB8888,
|
||||||
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING | GBM_BO_USE_CURSOR_64X64);
|
GBM_BO_USE_SCANOUT
|
||||||
|
| GBM_BO_USE_RENDERING
|
||||||
|
| GBM_BO_USE_CURSOR_64X64);
|
||||||
|
|
||||||
if (glamor->cursor_bo == NULL)
|
if (cursor->cursor_bo == NULL)
|
||||||
return EGL_NO_IMAGE_KHR;
|
goto fail;
|
||||||
|
glamor_cursor_handle(cursor, &handle, &stride);
|
||||||
|
if (!glamor_create_egl_pixmap_image(cursor->cursor_pixmap, handle, stride))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
return glamor->egl_create_image_khr(glamor->display, NULL, EGL_NATIVE_PIXMAP_KHR, glamor->cursor_bo, NULL);
|
return TRUE;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
glamor_destroy_cursor(scrn, cursor);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void glamor_destroy_cursor(ScrnInfoPtr scrn, EGLImageKHR cursor)
|
void glamor_destroy_cursor(ScrnInfoPtr scrn, struct glamor_gbm_cursor *cursor)
|
||||||
{
|
{
|
||||||
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
ScreenPtr screen = screenInfo.screens[scrn->scrnIndex];
|
||||||
eglDestroyImageKHR(glamor->display, cursor);
|
if (cursor->cursor_pixmap)
|
||||||
gbm_bo_destroy(glamor->cursor_bo);
|
screen->DestroyPixmap(cursor->cursor_pixmap);
|
||||||
|
if (cursor->cursor_bo)
|
||||||
|
gbm_bo_destroy(cursor->cursor_bo);
|
||||||
|
cursor->cursor_bo = NULL;
|
||||||
|
cursor->cursor_pixmap = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
glamor_cursor_handle(ScrnInfoPtr scrn, EGLImageKHR cursor, uint32_t *handle, uint32_t *pitch)
|
glamor_cursor_handle(struct glamor_gbm_cursor *cursor, uint32_t *handle, uint32_t *pitch)
|
||||||
{
|
{
|
||||||
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
*handle = gbm_bo_get_handle(cursor->cursor_bo).u32;
|
||||||
*handle = gbm_bo_get_handle(glamor->cursor_bo).u32;
|
*pitch = gbm_bo_get_pitch(cursor->cursor_bo);
|
||||||
*pitch = gbm_bo_get_pitch(glamor->cursor_bo);
|
|
||||||
ErrorF("cursor stride: %d\n", *pitch);
|
ErrorF("cursor stride: %d\n", *pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +213,9 @@ glamor_ddx_pre_init(ScrnInfoPtr scrn, int flags)
|
||||||
if (!xf86LoadSubModule(scrn, "fb"))
|
if (!xf86LoadSubModule(scrn, "fb"))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
if (!xf86LoadSubModule(scrn, "glamor_dix"))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
@ -232,16 +259,16 @@ glamor_ddx_create_screen_resources(ScreenPtr screen)
|
||||||
{
|
{
|
||||||
ScrnInfoPtr scrn = xf86Screens[screen->myNum];
|
ScrnInfoPtr scrn = xf86Screens[screen->myNum];
|
||||||
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
||||||
int width = scrn->virtualX;
|
|
||||||
int height = scrn->virtualY;
|
|
||||||
|
|
||||||
screen->CreateScreenResources = glamor->CreateScreenResources;
|
screen->CreateScreenResources = glamor->CreateScreenResources;
|
||||||
if (!(*screen->CreateScreenResources) (screen))
|
if (!(*screen->CreateScreenResources) (screen))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!glamor_glyphs_init(screen))
|
if (!glamor_glyphs_init(screen))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
glamor_resize(scrn, width, height);
|
if (glamor->root_bo == NULL)
|
||||||
|
return FALSE;
|
||||||
|
if (!glamor_create_screen_image(scrn))
|
||||||
|
return FALSE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,79 +285,22 @@ glamor_ddx_close_screen(int scrnIndex, ScreenPtr screen)
|
||||||
glamor_ddx_leave_vt(scrnIndex, 0);
|
glamor_ddx_leave_vt(scrnIndex, 0);
|
||||||
|
|
||||||
glamor_fini(screen);
|
glamor_fini(screen);
|
||||||
|
glamor_close_egl_screen(screen);
|
||||||
eglDestroyImageKHR(glamor->display, glamor->root);
|
|
||||||
gbm_bo_destroy(glamor->root_bo);
|
gbm_bo_destroy(glamor->root_bo);
|
||||||
|
|
||||||
eglMakeCurrent(glamor->display,
|
|
||||||
EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
||||||
eglTerminate(glamor->display);
|
|
||||||
|
|
||||||
drmmode_closefb(scrn);
|
drmmode_closefb(scrn);
|
||||||
|
|
||||||
glamor->fd = -1;
|
glamor->fd = -1;
|
||||||
|
|
||||||
glamor->root = EGL_NO_IMAGE_KHR;
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static Bool
|
|
||||||
glamor_egl_has_extension(struct glamor_ddx_screen_private *glamor, char *extension)
|
|
||||||
{
|
|
||||||
const char *egl_extensions;
|
|
||||||
char *pext;
|
|
||||||
int ext_len;
|
|
||||||
ext_len = strlen(extension);
|
|
||||||
|
|
||||||
egl_extensions = (const char*)eglQueryString(glamor->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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Bool
|
|
||||||
glamor_ddx_init_front_buffer(ScrnInfoPtr scrn)
|
|
||||||
{
|
|
||||||
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
|
||||||
int width = scrn->virtualX;
|
|
||||||
int height = scrn->virtualY;
|
|
||||||
|
|
||||||
glamor->root_bo = gbm_bo_create(glamor->gbm, width, height,
|
|
||||||
GBM_BO_FORMAT_ARGB8888,
|
|
||||||
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
|
|
||||||
|
|
||||||
if (glamor->root_bo == NULL)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
/* XXX shall we update displayWidth here ? */
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Bool
|
static Bool
|
||||||
glamor_ddx_screen_init(int scrnIndex, ScreenPtr screen, int argc, char **argv)
|
glamor_ddx_screen_init(int scrnIndex, ScreenPtr screen, int argc, char **argv)
|
||||||
{
|
{
|
||||||
ScrnInfoPtr scrn = xf86Screens[screen->myNum];
|
ScrnInfoPtr scrn = xf86Screens[screen->myNum];
|
||||||
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
||||||
const char *version;
|
|
||||||
VisualPtr visual;
|
VisualPtr visual;
|
||||||
EGLint config_attribs[] = {
|
|
||||||
#ifdef GLAMOR_GLES2
|
|
||||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
||||||
#endif
|
|
||||||
EGL_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* If serverGeneration != 1 then fd was closed during the last
|
/* If serverGeneration != 1 then fd was closed during the last
|
||||||
time closing screen, actually in eglTerminate(). */
|
time closing screen, actually in eglTerminate(). */
|
||||||
|
|
||||||
|
@ -354,62 +324,7 @@ glamor_ddx_screen_init(int scrnIndex, ScreenPtr screen, int argc, char **argv)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
glamor->display = eglGetDisplay(glamor->gbm);
|
glamor_egl_init(scrn, glamor->fd);
|
||||||
#ifndef GLAMOR_GLES2
|
|
||||||
eglBindAPI(EGL_OPENGL_API);
|
|
||||||
#else
|
|
||||||
eglBindAPI(EGL_OPENGL_ES_API);
|
|
||||||
#endif
|
|
||||||
if (!eglInitialize(glamor->display, &glamor->major, &glamor->minor)) {
|
|
||||||
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
|
||||||
"eglInitialize() failed\n");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
version = eglQueryString(glamor->display, EGL_VERSION);
|
|
||||||
xf86Msg(X_INFO, "%s: EGL version %s:\n", glamor_ddx_name, version);
|
|
||||||
|
|
||||||
#define GLAMOR_CHECK_EGL_EXTENSION(EXT) \
|
|
||||||
if (!glamor_egl_has_extension(glamor, "EGL_" #EXT)) { \
|
|
||||||
ErrorF("EGL_" #EXT "required.\n"); \
|
|
||||||
return FALSE; \
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
#else
|
|
||||||
GLAMOR_CHECK_EGL_EXTENSION(KHR_surfaceless_opengl);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
glamor->egl_create_drm_image_mesa = (PFNEGLCREATEDRMIMAGEMESA)eglGetProcAddress("eglCreateDRMImageMESA");
|
|
||||||
glamor->egl_create_image_khr = (PFNEGLCREATEIMAGEKHRPROC)
|
|
||||||
eglGetProcAddress("eglCreateImageKHR");
|
|
||||||
glamor->egl_export_drm_image_mesa = (PFNEGLEXPORTDRMIMAGEMESA)eglGetProcAddress("eglExportDRMImageMESA");
|
|
||||||
glamor->egl_image_target_texture2d_oes = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
|
|
||||||
|
|
||||||
if (!glamor->egl_create_drm_image_mesa || !glamor->egl_export_drm_image_mesa ||
|
|
||||||
!glamor->egl_image_target_texture2d_oes) {
|
|
||||||
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
|
||||||
"eglGetProcAddress() failed\n");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
glamor->context = eglCreateContext(glamor->display,
|
|
||||||
NULL, EGL_NO_CONTEXT, config_attribs);
|
|
||||||
if (glamor->context == EGL_NO_CONTEXT) {
|
|
||||||
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
|
||||||
"Failed to create EGL context\n");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!eglMakeCurrent(glamor->display,
|
|
||||||
EGL_NO_SURFACE, EGL_NO_SURFACE, glamor->context)) {
|
|
||||||
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
|
||||||
"Failed to make EGL context current\n");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
miClearVisualTypes();
|
miClearVisualTypes();
|
||||||
if (!miSetVisualTypes(scrn->depth,
|
if (!miSetVisualTypes(scrn->depth,
|
||||||
|
@ -419,7 +334,7 @@ glamor_ddx_screen_init(int scrnIndex, ScreenPtr screen, int argc, char **argv)
|
||||||
if (!miSetPixmapDepths())
|
if (!miSetPixmapDepths())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!glamor_ddx_init_front_buffer(scrn))
|
if (!glamor_ddx_init_front_buffer(scrn, scrn->virtualX, scrn->virtualY))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!fbScreenInit(screen, NULL,
|
if (!fbScreenInit(screen, NULL,
|
||||||
|
@ -613,18 +528,6 @@ glamor_ddx_setup(pointer module, pointer opts, int *errmaj, int *errmin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool
|
|
||||||
glamor_gl_dispatch_init(ScreenPtr screen, struct glamor_gl_dispatch *dispatch, int gl_version)
|
|
||||||
{
|
|
||||||
ScrnInfoPtr scrn = xf86Screens[screen->myNum];
|
|
||||||
struct glamor_ddx_screen_private *glamor_egl = glamor_ddx_get_screen_private(scrn);
|
|
||||||
if (!glamor_gl_dispatch_init_impl(dispatch, gl_version, eglGetProcAddress))
|
|
||||||
return FALSE;
|
|
||||||
glamor_egl->dispatch = dispatch;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static XF86ModuleVersionInfo glamor_ddx_version_info = {
|
static XF86ModuleVersionInfo glamor_ddx_version_info = {
|
||||||
glamor_ddx_name,
|
glamor_ddx_name,
|
||||||
MODULEVENDORSTRING,
|
MODULEVENDORSTRING,
|
||||||
|
|
|
@ -50,23 +50,6 @@
|
||||||
#include <xorgVersion.h>
|
#include <xorgVersion.h>
|
||||||
#include <libkms/libkms.h>
|
#include <libkms/libkms.h>
|
||||||
|
|
||||||
#define GL_GLEXT_PROTOTYPES
|
|
||||||
#define EGL_EGLEXT_PROTOTYPES
|
|
||||||
#define EGL_DISPLAY_NO_X_MESA
|
|
||||||
|
|
||||||
#if GLAMOR_GLES2
|
|
||||||
#include <GLES2/gl2.h>
|
|
||||||
#include <GLES2/gl2ext.h>
|
|
||||||
#ifndef GL_BGRA
|
|
||||||
#define GL_BGRA GL_BGRA_EXT
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#include <GL/gl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
#include <EGL/eglext.h>
|
|
||||||
|
|
||||||
#include "glamor_ddx.h"
|
#include "glamor_ddx.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -85,8 +68,7 @@ typedef struct {
|
||||||
drmmode_ptr drmmode;
|
drmmode_ptr drmmode;
|
||||||
drmModeCrtcPtr mode_crtc;
|
drmModeCrtcPtr mode_crtc;
|
||||||
uint32_t rotate_fb_id;
|
uint32_t rotate_fb_id;
|
||||||
EGLImageKHR cursor;
|
struct glamor_gbm_cursor *cursor;
|
||||||
unsigned int cursor_tex;
|
|
||||||
} drmmode_crtc_private_rec, *drmmode_crtc_private_ptr;
|
} drmmode_crtc_private_rec, *drmmode_crtc_private_ptr;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -341,7 +323,7 @@ drmmode_update_fb (ScrnInfoPtr scrn, int width, int height)
|
||||||
if (drmmode->fb_id != 0 &&
|
if (drmmode->fb_id != 0 &&
|
||||||
scrn->virtualX == width && scrn->virtualY == height)
|
scrn->virtualX == width && scrn->virtualY == height)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
if (!glamor_resize(scrn, width, height))
|
if (!glamor_front_buffer_resize(scrn, width, height))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (drmmode->fb_id != 0)
|
if (drmmode->fb_id != 0)
|
||||||
drmModeRmFB(drmmode->fd, drmmode->fb_id);
|
drmModeRmFB(drmmode->fd, drmmode->fb_id);
|
||||||
|
@ -490,37 +472,33 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
|
||||||
{
|
{
|
||||||
drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
|
drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
|
||||||
ScrnInfoPtr scrn = crtc->scrn;
|
ScrnInfoPtr scrn = crtc->scrn;
|
||||||
|
ScreenPtr screen = screenInfo.screens[scrn->scrnIndex];
|
||||||
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
struct glamor_ddx_screen_private *glamor = glamor_ddx_get_screen_private(scrn);
|
||||||
|
GCPtr gc;
|
||||||
|
|
||||||
if (drmmode_crtc->cursor == NULL)
|
if (drmmode_crtc->cursor == NULL)
|
||||||
{
|
{
|
||||||
drmmode_crtc->cursor = glamor_create_cursor_argb(scrn, 64, 64);
|
drmmode_crtc->cursor = calloc(1, sizeof(*drmmode_crtc->cursor));
|
||||||
if (drmmode_crtc->cursor == EGL_NO_IMAGE_KHR)
|
if (drmmode_crtc->cursor == NULL) {
|
||||||
|
ErrorF("Failed to allocate cursor.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!glamor_create_cursor(scrn, drmmode_crtc->cursor, 64, 64)) {
|
||||||
|
free(drmmode_crtc->cursor);
|
||||||
|
drmmode_crtc->cursor = NULL;
|
||||||
|
ErrorF("Failed to create glamor cursor.\n");
|
||||||
return;
|
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);
|
|
||||||
(glamor->egl_image_target_texture2d_oes)(GL_TEXTURE_2D, drmmode_crtc->cursor);
|
|
||||||
}
|
}
|
||||||
glBindTexture(GL_TEXTURE_2D, drmmode_crtc->cursor_tex);
|
|
||||||
#ifdef GLAMOR_GLES2
|
|
||||||
/* XXX Actually, the image is BGRA not RGBA, so the r and b
|
|
||||||
* should be swapped. But as normally, they are the same value
|
|
||||||
* ignore this currently, don't want to let CPU to do the swizzle.
|
|
||||||
* considering to put this function to the glamor rendering directory.
|
|
||||||
* Thus we can reuse the shader to do this.*/
|
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0,
|
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, image);
|
|
||||||
#else
|
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 64);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0,
|
|
||||||
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
gc = GetScratchGC (drmmode_crtc->cursor->cursor_pixmap->drawable.depth, screen);
|
||||||
|
if (!gc)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ValidateGC (&drmmode_crtc->cursor->cursor_pixmap->drawable, gc);
|
||||||
|
(*gc->ops->PutImage)(&drmmode_crtc->cursor->cursor_pixmap->drawable, gc,
|
||||||
|
32, 0, 0, 64, 64, 0, ZPixmap, (char*)image);
|
||||||
|
FreeScratchGC (gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -537,13 +515,12 @@ drmmode_hide_cursor (xf86CrtcPtr crtc)
|
||||||
static void
|
static void
|
||||||
drmmode_show_cursor (xf86CrtcPtr crtc)
|
drmmode_show_cursor (xf86CrtcPtr crtc)
|
||||||
{
|
{
|
||||||
ScrnInfoPtr scrn = crtc->scrn;
|
|
||||||
drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
|
drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
|
||||||
drmmode_ptr drmmode = drmmode_crtc->drmmode;
|
drmmode_ptr drmmode = drmmode_crtc->drmmode;
|
||||||
uint32_t handle, stride;
|
uint32_t handle, stride;
|
||||||
|
|
||||||
ErrorF("show cursor\n");
|
ErrorF("show cursor\n");
|
||||||
glamor_cursor_handle(scrn, drmmode_crtc->cursor, &handle, &stride);
|
glamor_cursor_handle(drmmode_crtc->cursor, &handle, &stride);
|
||||||
|
|
||||||
drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
|
drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
|
||||||
handle, 64, 64);
|
handle, 64, 64);
|
||||||
|
@ -654,8 +631,9 @@ drmmode_crtc_destroy(xf86CrtcPtr crtc)
|
||||||
ScrnInfoPtr scrn = crtc->scrn;
|
ScrnInfoPtr scrn = crtc->scrn;
|
||||||
if (drmmode_crtc->cursor) {
|
if (drmmode_crtc->cursor) {
|
||||||
drmmode_hide_cursor(crtc);
|
drmmode_hide_cursor(crtc);
|
||||||
glDeleteTextures(1, &drmmode_crtc->cursor_tex);
|
|
||||||
glamor_destroy_cursor(scrn, drmmode_crtc->cursor);
|
glamor_destroy_cursor(scrn, drmmode_crtc->cursor);
|
||||||
|
free(drmmode_crtc->cursor);
|
||||||
|
drmmode_crtc->cursor = NULL;
|
||||||
}
|
}
|
||||||
free(drmmode_crtc->cursor);
|
free(drmmode_crtc->cursor);
|
||||||
crtc->driver_private = NULL;
|
crtc->driver_private = NULL;
|
||||||
|
|
|
@ -1,43 +1,23 @@
|
||||||
#ifndef GLAMOR_DDX_H
|
#ifndef GLAMOR_DDX_H
|
||||||
#define GLAMOR_DDX_H
|
#define GLAMOR_DDX_H
|
||||||
|
|
||||||
#define GL_GLEXT_PROTOTYPES
|
|
||||||
#define EGL_EGLEXT_PROTOTYPES
|
|
||||||
#define EGL_DISPLAY_NO_X_MESA
|
|
||||||
|
|
||||||
#if GLAMOR_GLES2
|
|
||||||
#include <GLES2/gl2.h>
|
|
||||||
#include <GLES2/gl2ext.h>
|
|
||||||
#else
|
|
||||||
#include <GL/gl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MESA_EGL_NO_X11_HEADERS
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
#include <EGL/eglext.h>
|
|
||||||
|
|
||||||
#include <gbm.h>
|
#include <gbm.h>
|
||||||
#include "glamor_gl_dispatch.h"
|
#define GLAMOR_FOR_XORG 1
|
||||||
|
#include <glamor.h>
|
||||||
struct glamor_ddx_screen_private {
|
struct glamor_ddx_screen_private {
|
||||||
EGLDisplay display;
|
|
||||||
EGLContext context;
|
|
||||||
EGLImageKHR root;
|
|
||||||
struct gbm_bo *root_bo;
|
struct gbm_bo *root_bo;
|
||||||
struct gbm_bo *cursor_bo;
|
struct gbm_bo *cursor_bo;
|
||||||
|
struct gbm_device *gbm;
|
||||||
EGLint major, minor;
|
|
||||||
|
|
||||||
CreateScreenResourcesProcPtr CreateScreenResources;
|
CreateScreenResourcesProcPtr CreateScreenResources;
|
||||||
CloseScreenProcPtr CloseScreen;
|
CloseScreenProcPtr CloseScreen;
|
||||||
int fd;
|
int fd;
|
||||||
int cpp;
|
int cpp;
|
||||||
struct gbm_device *gbm;
|
};
|
||||||
|
|
||||||
PFNEGLCREATEDRMIMAGEMESA egl_create_drm_image_mesa;
|
struct glamor_gbm_cursor {
|
||||||
PFNEGLEXPORTDRMIMAGEMESA egl_export_drm_image_mesa;
|
struct gbm_bo *cursor_bo;
|
||||||
PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr;
|
PixmapPtr cursor_pixmap;
|
||||||
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC egl_image_target_texture2d_oes;
|
|
||||||
struct glamor_gl_dispatch *dispatch;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline static struct glamor_ddx_screen_private *
|
inline static struct glamor_ddx_screen_private *
|
||||||
|
@ -46,15 +26,15 @@ glamor_ddx_get_screen_private(ScrnInfoPtr scrn)
|
||||||
return (struct glamor_ddx_screen_private *) (scrn->driverPrivate);
|
return (struct glamor_ddx_screen_private *) (scrn->driverPrivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool glamor_resize(ScrnInfoPtr scrn, int width, int height);
|
Bool glamor_front_buffer_resize(ScrnInfoPtr scrn, int width, int height);
|
||||||
void glamor_frontbuffer_handle(ScrnInfoPtr scrn,
|
void glamor_frontbuffer_handle(ScrnInfoPtr scrn,
|
||||||
uint32_t *handle, uint32_t *pitch);
|
uint32_t *handle, uint32_t *pitch);
|
||||||
Bool glamor_load_cursor(ScrnInfoPtr scrn,
|
Bool glamor_load_cursor(ScrnInfoPtr scrn,
|
||||||
CARD32 *image, int width, int height);
|
int width, int height);
|
||||||
|
|
||||||
void glamor_cursor_handle(ScrnInfoPtr scrn, EGLImageKHR image, uint32_t *handle, uint32_t *pitch);
|
void glamor_cursor_handle(struct glamor_gbm_cursor *cursor, uint32_t *handle, uint32_t *pitch);
|
||||||
EGLImageKHR glamor_create_cursor_argb(ScrnInfoPtr scrn, int width, int height);
|
Bool glamor_create_cursor(ScrnInfoPtr scrn, struct glamor_gbm_cursor *cursor, int width, int height);
|
||||||
void glamor_destroy_cursor(ScrnInfoPtr scrn, EGLImageKHR cursor);
|
void glamor_destroy_cursor(ScrnInfoPtr scrn, struct glamor_gbm_cursor *cursor) ;
|
||||||
|
|
||||||
Bool drmmode_pre_init(ScrnInfoPtr scrn, int fd, int cpp);
|
Bool drmmode_pre_init(ScrnInfoPtr scrn, int fd, int cpp);
|
||||||
void drmmode_closefb(ScrnInfoPtr scrn);
|
void drmmode_closefb(ScrnInfoPtr scrn);
|
||||||
|
|
Loading…
Reference in New Issue