From d9769c193765ac303ad4d4760e57ff368df1f663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Mon, 24 Sep 2012 15:01:09 -0400 Subject: [PATCH 1/2] xwayland: Add xwayland support --- src/intel_device.c | 18 ++++++---- src/intel_driver.h | 6 +++- src/intel_module.c | 8 +++++ src/uxa/intel.h | 2 ++ src/uxa/intel_dri.c | 38 +++++++++++++++++++-- src/uxa/intel_driver.c | 89 ++++++++++++++++++++++++++++++++++++++++++++------ 6 files changed, 140 insertions(+), 21 deletions(-) diff --git a/src/intel_device.c b/src/intel_device.c index d9ff8bc..370b03c 100644 --- a/src/intel_device.c +++ b/src/intel_device.c @@ -181,14 +181,18 @@ int intel_open_device(int entity_num, if (dev) return dev->fd; - local_path = path ? strdup(path) : NULL; + if (!xorgWayland) { + local_path = path ? strdup(path) : NULL; - fd = __intel_open_device(pci, &local_path); - if (fd == -1) - goto err_path; + fd = __intel_open_device(pci, &local_path); + if (fd == -1) + goto err_path; - if (!__intel_check_device(fd)) - goto err_close; + if (!__intel_check_device(fd)) + goto err_close; + } else { + fd = -1; + } dev = malloc(sizeof(*dev)); if (dev == NULL) @@ -207,7 +211,7 @@ int intel_open_device(int entity_num, xf86GetEntityPrivate(entity_num, intel_device_key)->ptr = dev; - return fd; + return xorgWayland ? 0 : fd; err_close: close(fd); diff --git a/src/intel_driver.h b/src/intel_driver.h index 4768536..103d31e 100644 --- a/src/intel_driver.h +++ b/src/intel_driver.h @@ -129,6 +129,10 @@ void intel_put_device(ScrnInfoPtr scrn); void __intel_uxa_release_device(ScrnInfoPtr scrn); -#define hosted() (0) +#include +#ifdef XORG_WAYLAND +#include +#define hosted() (xorgWayland) +#endif #endif /* INTEL_DRIVER_H */ diff --git a/src/intel_module.c b/src/intel_module.c index b91152e..ec6d8b8 100644 --- a/src/intel_module.c +++ b/src/intel_module.c @@ -30,6 +30,7 @@ #include #include +#include #include #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,6,99,0,0) @@ -387,6 +388,10 @@ static Bool intel_driver_func(ScrnInfoPtr pScrn, (*flag) = HW_SKIP_CONSOLE; #endif +#ifdef HW_WAYLAND + if (xorgWayland) + (*flag) = HW_WAYLAND; +#endif return TRUE; default: /* Unknown or deprecated function */ @@ -415,6 +420,9 @@ static enum accel_method { UXA, SNA } get_accel_method(void) enum accel_method accel_method = DEFAULT_ACCEL_METHOD; XF86ConfDevicePtr dev; + if (xorgWayland) + return UXA; + if (hosted()) return SNA; diff --git a/src/uxa/intel.h b/src/uxa/intel.h index 9b696cd..0b3b95c 100644 --- a/src/uxa/intel.h +++ b/src/uxa/intel.h @@ -350,6 +350,8 @@ typedef struct intel_screen_private { InputHandlerProc uevent_handler; #endif Bool has_prime_vmap_flush; + + struct xwl_screen *xwl_screen; } intel_screen_private; #define INTEL_INFO(intel) ((intel)->info) diff --git a/src/uxa/intel_dri.c b/src/uxa/intel_dri.c index 0370034..74dabe6 100644 --- a/src/uxa/intel_dri.c +++ b/src/uxa/intel_dri.c @@ -50,6 +50,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #include "xf86.h" #include "xf86_OSproc.h" +#include "xf86Priv.h" #include "xf86Pci.h" #include "xf86drm.h" @@ -58,6 +59,10 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #include "shadow.h" #include "fb.h" +#ifdef XORG_WAYLAND +#include +#endif + #include "intel.h" #include "i830_reg.h" @@ -1520,6 +1525,22 @@ out_complete: return TRUE; } +#if DRI2INFOREC_VERSION >= 10 +static int intel_auth_magic3(ClientPtr client, ScreenPtr screen, uint32_t magic) + +{ + ScrnInfoPtr scrn = xf86Screens[screen->myNum]; + intel_screen_private *intel = intel_get_screen_private(scrn); + + /* Not wayland, go stragight to drm */ + if (!xorgWayland) + return drmAuthMagic(intel->drmSubFD, magic); + + /* Forward the request to our host */ + return xwl_drm_authenticate(client, intel->xwl_screen, magic); +} +#endif + static int dri2_server_generation; #endif @@ -1617,14 +1638,25 @@ Bool I830DRI2ScreenInit(ScreenPtr screen) info.CopyRegion = I830DRI2CopyRegion; #if DRI2INFOREC_VERSION >= 4 info.version = 4; - info.ScheduleSwap = I830DRI2ScheduleSwap; - info.GetMSC = I830DRI2GetMSC; - info.ScheduleWaitMSC = I830DRI2ScheduleWaitMSC; + if (!xorgWayland) { + info.ScheduleSwap = I830DRI2ScheduleSwap; + info.GetMSC = I830DRI2GetMSC; + info.ScheduleWaitMSC = I830DRI2ScheduleWaitMSC; + } else { + info.ScheduleSwap = NULL; + info.GetMSC = NULL; + info.ScheduleWaitMSC = NULL; + } info.numDrivers = 1; info.driverNames = driverNames; driverNames[0] = info.driverName; #endif +#if DRI2INFOREC_VERSION >= 10 + info.version = 10; + info.AuthMagic3 = intel_auth_magic3; +#endif + return DRI2ScreenInit(screen, &info); } diff --git a/src/uxa/intel_driver.c b/src/uxa/intel_driver.c index 675408d..e74ba60 100644 --- a/src/uxa/intel_driver.c +++ b/src/uxa/intel_driver.c @@ -70,12 +70,17 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #include "intel_xvmc.h" #endif +#ifdef XORG_WAYLAND +#include +#endif + #include "legacy/legacy.h" #include "uxa.h" #include #include "i915_drm.h" #include +#include #include "intel_glamor.h" #include "intel_options.h" @@ -167,10 +172,16 @@ static Bool i830CreateScreenResources(ScreenPtr screen) if (!(*screen->CreateScreenResources) (screen)) return FALSE; +#ifdef XORG_WAYLAND + if (intel->xwl_screen) + xwl_screen_init(intel->xwl_screen, screen); +#endif + if (!intel_uxa_create_screen_resources(screen)) return FALSE; - intel_copy_fb(scrn); + if (!intel->xwl_screen) + intel_copy_fb(scrn); return TRUE; } @@ -463,6 +474,27 @@ static void intel_setup_capabilities(ScrnInfoPtr scrn) #endif } +#ifdef XORG_WAYLAND +static int intel_create_window_buffer(struct xwl_window *xwl_window, + PixmapPtr pixmap) +{ + uint32_t name; + dri_bo *bo; + + bo = intel_get_pixmap_bo(pixmap); + if (bo == NULL || dri_bo_flink(bo, &name) != 0) + return BadDrawable; + + return xwl_create_window_buffer_drm(xwl_window, pixmap, name); +} + +static struct xwl_driver xwl_driver = { + .version = 1, + .use_drm = 1, + .create_window_buffer = intel_create_window_buffer +}; +#endif + /** * This is called before ScreenInit to do any require probing of screen * configuration. @@ -517,12 +549,6 @@ static Bool I830PreInit(ScrnInfoPtr scrn, int flags) intel->PciInfo = xf86GetPciInfoForEntity(intel->pEnt->index); - if (!intel_open_drm_master(scrn)) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "Failed to become DRM master.\n"); - return FALSE; - } - scrn->monitor = scrn->confScreen->monitor; scrn->progClock = TRUE; scrn->rgbBits = 8; @@ -561,6 +587,31 @@ static Bool I830PreInit(ScrnInfoPtr scrn, int flags) intel_check_chipset_option(scrn); intel_check_dri_option(scrn); +#ifdef XORG_WAYLAND + if (xorgWayland) { + intel->xwl_screen = xwl_screen_create(); + if (!intel->xwl_screen) { + xf86DrvMsg(scrn->scrnIndex, X_ERROR, + "Failed to initialize xwayland.\n"); + return FALSE; + } + + if (!xwl_screen_pre_init(scrn, intel->xwl_screen, + 0, &xwl_driver)) { + xf86DrvMsg(scrn->scrnIndex, X_ERROR, + "Failed to pre-init xwayland screen\n"); + xwl_screen_destroy(intel->xwl_screen); + } + + intel->drmSubFD = xwl_screen_get_drm_fd(intel->xwl_screen); + } +#endif + + if (!intel->xwl_screen && !intel_open_drm_master(scrn)) + xf86DrvMsg(scrn->scrnIndex, X_ERROR, + "Failed to become DRM master.\n"); + + if (!intel_init_bufmgr(intel)) { PreInitCleanup(scrn); return FALSE; @@ -599,6 +650,9 @@ static Bool I830PreInit(ScrnInfoPtr scrn, int flags) intel->swapbuffers_wait = xf86ReturnOptValBool(intel->Options, OPTION_SWAPBUFFERS_WAIT, TRUE); + if (!intel->xwl_screen) + intel->swapbuffers_wait = TRUE; + xf86DrvMsg(scrn->scrnIndex, X_CONFIG, "Wait on SwapBuffers? %s\n", intel->swapbuffers_wait ? "enabled" : "disabled"); @@ -620,7 +674,8 @@ static Bool I830PreInit(ScrnInfoPtr scrn, int flags) I830XvInit(scrn); - if (!intel_mode_pre_init(scrn, intel->drmSubFD, intel->cpp)) { + if (!intel->xwl_screen && + !intel_mode_pre_init(scrn, intel->drmSubFD, intel->cpp)) { PreInitCleanup(scrn); return FALSE; } @@ -757,6 +812,11 @@ I830BlockHandler(BLOCKHANDLER_ARGS_DECL) #ifdef INTEL_PIXMAP_SHARING intel_dirty_update(screen); #endif + +#ifdef XORG_WAYLAND + if (intel->xwl_screen) + xwl_screen_post_damage(intel->xwl_screen); +#endif } static Bool @@ -792,9 +852,16 @@ intel_flush_callback(CallbackListPtr *list, pointer user_data, pointer call_data) { ScrnInfoPtr scrn = user_data; + intel_screen_private *intel = intel_get_screen_private(scrn); + if (scrn->vtSema) { intel_batch_submit(scrn); intel_glamor_flush(intel_get_screen_private(scrn)); + +#ifdef XORG_WAYLAND + if (intel->xwl_screen) + xwl_screen_post_damage(intel->xwl_screen); +#endif } } @@ -1067,7 +1134,8 @@ I830ScreenInit(SCREEN_INIT_ARGS_DECL) if (serverGeneration == 1) xf86ShowUnusedOptions(scrn->scrnIndex, scrn->options); - intel_mode_init(intel); + if (!intel->xwl_screen) + intel_mode_init(intel); intel->suspended = FALSE; @@ -1182,7 +1250,8 @@ static Bool I830CloseScreen(CLOSE_SCREEN_ARGS_DECL) } if (intel->front_buffer) { - intel_mode_remove_fb(intel); + if (!intel->xwl_screen) + intel_mode_remove_fb(intel); drm_intel_bo_unreference(intel->front_buffer); intel->front_buffer = NULL; } -- 1.8.3.1