diff options
10 files changed, 46 insertions, 35 deletions
diff --git a/src/compositor/global/waylandobject.h b/src/compositor/global/waylandobject.h index 32721df2..4cbe6da7 100644 --- a/src/compositor/global/waylandobject.h +++ b/src/compositor/global/waylandobject.h @@ -51,35 +51,45 @@ template <typename T> class Object { public: + typedef T Base; + Object() { memset(&m_waylandObject, 0, sizeof(T)); } const T *base() const { return &m_waylandObject; } T *base() { return &m_waylandObject; } + template <typename Implementation> + void addClientResource(wl_client *client, + wl_resource *resource, + int id, const struct wl_interface *interface, + Implementation implementation, + void (*destroy)(struct wl_resource *resource)) + { + resource->object.id = id; + resource->object.interface = interface; + resource->object.implementation = (void (**)(void))implementation; + resource->data = &m_waylandObject; + resource->destroy = destroy; + + wl_client_add_resource(client, resource); + } + private: T m_waylandObject; }; -template <typename To, typename From> -To wayland_cast(From *from) +template <typename T> +T *resolve(wl_resource *from) { - Object<From> *object = reinterpret_cast<Object<From> *>(from); - return static_cast<To>(object); + Object<typename T::Base> *object = reinterpret_cast<Object<typename T::Base> *>(from->data); + return static_cast<T *>(object); } -template <typename Implementation> -void addClientResource(struct wl_client *client, - struct wl_resource *resource, - int id, const struct wl_interface *interface, - Implementation implementation, - void (*destroy)(struct wl_resource *resource)) +template <typename T> +T *wayland_cast(typename T::Base *from) { - resource->object.id = id; - resource->object.interface = interface; - resource->object.implementation = (void (**)(void))implementation; - resource->destroy = destroy; - - wl_client_add_resource(client, resource); + Object<typename T::Base> *object = reinterpret_cast<Object<typename T::Base> *>(from); + return static_cast<T *>(object); } } diff --git a/src/compositor/hardware_integration/xcomposite_egl/xcompositeeglintegration.cpp b/src/compositor/hardware_integration/xcomposite_egl/xcompositeeglintegration.cpp index 6047a624..88f5a1ce 100644 --- a/src/compositor/hardware_integration/xcomposite_egl/xcompositeeglintegration.cpp +++ b/src/compositor/hardware_integration/xcomposite_egl/xcompositeeglintegration.cpp @@ -102,7 +102,7 @@ void XCompositeEglIntegration::initializeHardware(Wayland::Display *waylandDispl GLuint XCompositeEglIntegration::createTextureFromBuffer(wl_buffer *buffer, QOpenGLContext *) { - XCompositeBuffer *compositorBuffer = Wayland::wayland_cast<XCompositeBuffer *>(buffer); + XCompositeBuffer *compositorBuffer = Wayland::wayland_cast<XCompositeBuffer>(buffer); Pixmap pixmap = XCompositeNameWindowPixmap(mDisplay, compositorBuffer->window()); QVector<EGLint> eglConfigSpec = eglbuildSpec(); @@ -145,6 +145,6 @@ GLuint XCompositeEglIntegration::createTextureFromBuffer(wl_buffer *buffer, QOpe bool XCompositeEglIntegration::isYInverted(wl_buffer *buffer) const { - XCompositeBuffer *compositorBuffer = Wayland::wayland_cast<XCompositeBuffer *>(buffer); + XCompositeBuffer *compositorBuffer = Wayland::wayland_cast<XCompositeBuffer>(buffer); return compositorBuffer->isYInverted(); } diff --git a/src/compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.cpp b/src/compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.cpp index a6aaba71..b8a86083 100644 --- a/src/compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.cpp +++ b/src/compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.cpp @@ -122,7 +122,7 @@ void XCompositeGLXIntegration::initializeHardware(Wayland::Display *waylandDispl GLuint XCompositeGLXIntegration::createTextureFromBuffer(wl_buffer *buffer, QOpenGLContext *) { - XCompositeBuffer *compositorBuffer = Wayland::wayland_cast<XCompositeBuffer *>(buffer); + XCompositeBuffer *compositorBuffer = Wayland::wayland_cast<XCompositeBuffer>(buffer); Pixmap pixmap = XCompositeNameWindowPixmap(mDisplay, compositorBuffer->window()); QVector<int> glxConfigSpec = qglx_buildSpec(); @@ -155,6 +155,6 @@ GLuint XCompositeGLXIntegration::createTextureFromBuffer(wl_buffer *buffer, QOpe bool XCompositeGLXIntegration::isYInverted(wl_buffer *buffer) const { - XCompositeBuffer *compositorBuffer = Wayland::wayland_cast<XCompositeBuffer *>(buffer); + XCompositeBuffer *compositorBuffer = Wayland::wayland_cast<XCompositeBuffer>(buffer); return compositorBuffer->isYInverted(); } diff --git a/src/compositor/hardware_integration/xcomposite_share/xcompositehandler.cpp b/src/compositor/hardware_integration/xcomposite_share/xcompositehandler.cpp index 6c886a49..46380fbf 100644 --- a/src/compositor/hardware_integration/xcomposite_share/xcompositehandler.cpp +++ b/src/compositor/hardware_integration/xcomposite_share/xcompositehandler.cpp @@ -67,10 +67,10 @@ XCompositeHandler::XCompositeHandler(Wayland::Compositor *compositor, Display *d void XCompositeHandler::createBuffer(struct wl_client *client, uint32_t id, Window window, const QSize &size) { XCompositeBuffer *buffer = new XCompositeBuffer(mCompositor, window, size); - Wayland::addClientResource(client,&buffer->base()->resource, - id,&wl_buffer_interface, - &XCompositeBuffer::buffer_interface, - XCompositeBuffer::delete_resource); + buffer->addClientResource(client, &buffer->base()->resource, + id,&wl_buffer_interface, + &XCompositeBuffer::buffer_interface, + XCompositeBuffer::delete_resource); } void XCompositeHandler::xcomposite_bind_func(struct wl_client *client, void *data, uint32_t version, uint32_t id) diff --git a/src/compositor/wayland_wrapper/wldatadevicemanager.cpp b/src/compositor/wayland_wrapper/wldatadevicemanager.cpp index b8c41719..04214ef8 100644 --- a/src/compositor/wayland_wrapper/wldatadevicemanager.cpp +++ b/src/compositor/wayland_wrapper/wldatadevicemanager.cpp @@ -204,7 +204,7 @@ void DataDeviceManager::get_data_device(struct wl_client *client, struct wl_resource *input_device_resource) { DataDeviceManager *data_device_manager = static_cast<DataDeviceManager *>(data_device_manager_resource->data); - InputDevice *input_device = reinterpret_cast<InputDevice *>(input_device_resource->data); + InputDevice *input_device = resolve<InputDevice>(input_device_resource); input_device->clientRequestedDataDevice(data_device_manager,client,id); } diff --git a/src/compositor/wayland_wrapper/wlextendedsurface.cpp b/src/compositor/wayland_wrapper/wlextendedsurface.cpp index fe4e487a..94899048 100644 --- a/src/compositor/wayland_wrapper/wlextendedsurface.cpp +++ b/src/compositor/wayland_wrapper/wlextendedsurface.cpp @@ -71,7 +71,7 @@ void SurfaceExtensionGlobal::get_extended_surface(struct wl_client *client, struct wl_resource *surface_resource) { Q_UNUSED(surface_extension_resource); - Surface *surface = reinterpret_cast<Surface *>(surface_resource); + Surface *surface = resolve<Surface>(surface_resource); new ExtendedSurface(client,id,surface); } diff --git a/src/compositor/wayland_wrapper/wlinputdevice.cpp b/src/compositor/wayland_wrapper/wlinputdevice.cpp index edf55d7f..72b735a2 100644 --- a/src/compositor/wayland_wrapper/wlinputdevice.cpp +++ b/src/compositor/wayland_wrapper/wlinputdevice.cpp @@ -207,7 +207,7 @@ void InputDevice::sendFullTouchEvent(QTouchEvent *event) Surface *InputDevice::keyboardFocus() const { - return wayland_cast<Surface *>(base()->keyboard_focus); + return wayland_cast<Surface>(base()->keyboard_focus); } void InputDevice::setKeyboardFocus(Surface *surface) @@ -218,7 +218,7 @@ void InputDevice::setKeyboardFocus(Surface *surface) Surface *InputDevice::mouseFocus() const { - return wayland_cast<Surface *>(base()->pointer_focus); + return wayland_cast<Surface>(base()->pointer_focus); } void InputDevice::setMouseFocus(Surface *surface, const QPoint &globalPos, const QPoint &localPos) @@ -320,7 +320,7 @@ void InputDevice::input_device_attach(struct wl_client *client, struct wl_input_device *device_base = reinterpret_cast<struct wl_input_device *>(device_resource->data); struct wl_buffer *buffer = reinterpret_cast<struct wl_buffer *>(buffer_resource); - InputDevice *inputDevice = wayland_cast<InputDevice *>(device_base); + InputDevice *inputDevice = wayland_cast<InputDevice>(device_base); if (wl_buffer_is_shm(buffer)) { ShmBuffer *shmBuffer = static_cast<ShmBuffer *>(buffer->user_data); if (shmBuffer) { diff --git a/src/compositor/wayland_wrapper/wlshellsurface.cpp b/src/compositor/wayland_wrapper/wlshellsurface.cpp index 36598993..39c60a2e 100644 --- a/src/compositor/wayland_wrapper/wlshellsurface.cpp +++ b/src/compositor/wayland_wrapper/wlshellsurface.cpp @@ -66,7 +66,7 @@ void Shell::get_shell_surface(struct wl_client *client, struct wl_resource *surface_super) { Q_UNUSED(shell_resource); - Surface *surface = reinterpret_cast<Surface *>(surface_super); + Surface *surface = resolve<Surface>(surface_super); new ShellSurface(client,id,surface); } diff --git a/src/compositor/wayland_wrapper/wlsubsurface.cpp b/src/compositor/wayland_wrapper/wlsubsurface.cpp index ed3c0a9b..56404589 100644 --- a/src/compositor/wayland_wrapper/wlsubsurface.cpp +++ b/src/compositor/wayland_wrapper/wlsubsurface.cpp @@ -62,7 +62,7 @@ void SubSurfaceExtensionGlobal::bind_func(wl_client *client, void *data, uint32_ void SubSurfaceExtensionGlobal::get_sub_surface_aware_surface(wl_client *client, wl_resource *sub_surface_extension_resource, uint32_t id, wl_resource *surface_resource) { Q_UNUSED(sub_surface_extension_resource); - Surface *surface = reinterpret_cast<Surface *>(surface_resource); + Surface *surface = resolve<Surface>(surface_resource); new SubSurface(client,id,surface); } diff --git a/src/compositor/wayland_wrapper/wlsurface.cpp b/src/compositor/wayland_wrapper/wlsurface.cpp index 92ee0e7c..f4fee87e 100644 --- a/src/compositor/wayland_wrapper/wlsurface.cpp +++ b/src/compositor/wayland_wrapper/wlsurface.cpp @@ -69,7 +69,7 @@ namespace Wayland { void destroy_surface(struct wl_resource *resource) { - Surface *surface = wayland_cast<Surface *>((wl_surface *)resource); + Surface *surface = resolve<Surface>(resource); surface->compositor()->surfaceDestroyed(surface); delete surface; } @@ -417,20 +417,21 @@ void Surface::surface_attach(struct wl_client *client, struct wl_resource *surfa Q_UNUSED(client); Q_UNUSED(x); Q_UNUSED(y); - reinterpret_cast<Surface *>(surface)->attach(reinterpret_cast<struct wl_buffer *>(buffer)); + resolve<Surface>(surface)->attach(reinterpret_cast<wl_buffer *>(buffer->data)); } void Surface::surface_damage(struct wl_client *client, struct wl_resource *surface, int32_t x, int32_t y, int32_t width, int32_t height) { Q_UNUSED(client); - reinterpret_cast<Surface *>(surface)->damage(QRect(x, y, width, height)); + resolve<Surface>(surface)->damage(QRect(x, y, width, height)); } + void Surface::surface_frame(struct wl_client *client, struct wl_resource *resource, uint32_t callback) { - Surface *surface = reinterpret_cast<Surface *>(resource); + Surface *surface = resolve<Surface>(resource); struct wl_resource *frame_callback = wl_client_add_object(client,&wl_callback_interface,0,callback,surface); wl_list_insert(&surface->m_frame_callback_list,&frame_callback->link); } |