diff options
Diffstat (limited to 'src/qt-compositor/compositor_api')
4 files changed, 103 insertions, 40 deletions
diff --git a/src/qt-compositor/compositor_api/waylandcompositor.cpp b/src/qt-compositor/compositor_api/waylandcompositor.cpp index ee3e949..a682237 100644 --- a/src/qt-compositor/compositor_api/waylandcompositor.cpp +++ b/src/qt-compositor/compositor_api/waylandcompositor.cpp @@ -44,14 +44,16 @@ #include "wayland_wrapper/wlsurface.h" #include "wayland_wrapper/wlselection.h" #include <QtCore/QCoreApplication> +#include <QDebug> #ifdef QT_COMPOSITOR_DECLARATIVE #include "waylandsurfaceitem.h" #endif -WaylandCompositor::WaylandCompositor(QWidget *topLevelWidget, const char *socketName) +WaylandCompositor::WaylandCompositor(QWindow *window, QOpenGLContext *context, const char *socketName) : m_compositor(0) - , m_toplevel_widget(topLevelWidget) + , m_glContext(context) + , m_toplevel_widget(window) , m_socket_name(socketName) { QStringList arguments = QCoreApplication::instance()->arguments(); @@ -108,7 +110,12 @@ WaylandSurface *WaylandCompositor::directRenderSurface() const return surf ? surf->handle() : 0; } -QWidget * WaylandCompositor::topLevelWidget() const +QOpenGLContext * WaylandCompositor::glContext() const +{ + return m_glContext; +} + +QWindow * WaylandCompositor::window() const { return m_toplevel_widget; } @@ -151,3 +158,27 @@ void WaylandCompositor::setOutputGeometry(const QRect &geometry) { m_compositor->setOutputGeometry(geometry); } + +bool WaylandCompositor::isDragging() const +{ + return m_compositor->isDragging(); +} + +void WaylandCompositor::sendDragMoveEvent(const QPoint &global, const QPoint &local, + WaylandSurface *surface) +{ + m_compositor->sendDragMoveEvent(global, local, surface ? surface->handle() : 0); +} + +void WaylandCompositor::sendDragEndEvent() +{ + m_compositor->sendDragEndEvent(); +} + +void WaylandCompositor::changeCursor(const QImage &image, int hotspotX, int hotspotY) +{ + Q_UNUSED(image); + Q_UNUSED(hotspotX); + Q_UNUSED(hotspotY); + qDebug() << "changeCursor" << image.size() << hotspotX << hotspotY; +} diff --git a/src/qt-compositor/compositor_api/waylandcompositor.h b/src/qt-compositor/compositor_api/waylandcompositor.h index 1075265..11660b8 100644 --- a/src/qt-compositor/compositor_api/waylandcompositor.h +++ b/src/qt-compositor/compositor_api/waylandcompositor.h @@ -44,11 +44,9 @@ #include <QObject> #include <QImage> #include <QRect> +#include <QOpenGLContext> -#ifdef QT_COMPOSITOR_WAYLAND_GL -#include <QtOpenGL/QGLContext> -#endif - +class QGLContext; class QWidget; class QMimeData; class WaylandSurface; @@ -61,7 +59,7 @@ namespace Wayland class WaylandCompositor { public: - WaylandCompositor(QWidget *topLevelWidget = 0, const char *socketName = 0); + WaylandCompositor(QWindow *window = 0, QOpenGLContext *context = 0, const char *socketName = 0); virtual ~WaylandCompositor(); void frameFinished(WaylandSurface *surface = 0); @@ -73,7 +71,8 @@ public: void setDirectRenderSurface(WaylandSurface *surface); WaylandSurface *directRenderSurface() const; - QWidget *topLevelWidget()const; + QOpenGLContext *glContext() const; + QWindow *window()const; virtual void surfaceCreated(WaylandSurface *surface) = 0; @@ -87,11 +86,18 @@ public: void setScreenOrientation(qint32 orientationInDegrees); void setOutputGeometry(const QRect &outputGeometry); + bool isDragging() const; + void sendDragMoveEvent(const QPoint &global, const QPoint &local, WaylandSurface *surface); + void sendDragEndEvent(); + + virtual void changeCursor(const QImage &image, int hotspotX, int hotspotY); + private: static void retainedSelectionChanged(QMimeData *mimeData, void *param); Wayland::Compositor *m_compositor; - QWidget *m_toplevel_widget; + QOpenGLContext *m_glContext; + QWindow *m_toplevel_widget; QByteArray m_socket_name; }; diff --git a/src/qt-compositor/compositor_api/waylandsurfaceitem.cpp b/src/qt-compositor/compositor_api/waylandsurfaceitem.cpp index e503a03..31889d7 100644 --- a/src/qt-compositor/compositor_api/waylandsurfaceitem.cpp +++ b/src/qt-compositor/compositor_api/waylandsurfaceitem.cpp @@ -49,29 +49,32 @@ #include <QtDeclarative/QSGSimpleRectNode> #include <QtDeclarative/QSGCanvas> -void WaylandSurfaceItem::surfaceDamaged(const QRect &) +class WaylandSurfaceTextureProvider : public QSGTextureProvider { - QSGTexture *oldTexture = m_texture; - - if (m_surface->type() == WaylandSurface::Texture) { - QSGEngine::TextureOption opt = useTextureAlpha() ? QSGEngine::TextureHasAlphaChannel : QSGEngine::TextureOption(0); +public: + WaylandSurfaceTextureProvider() : t(0) { } - m_texture = canvas()->sceneGraphEngine()->createTextureFromId(m_surface->texture(), - m_surface->geometry().size(), - opt); - } else { - m_texture = canvas()->sceneGraphEngine()->createTextureFromImage(m_surface->image()); + QSGTexture *texture() const { + if (t) + t->setFiltering(smooth ? QSGTexture::Linear : QSGTexture::Nearest); + return t; } - delete oldTexture; + QSGTexture *t; + bool smooth; +}; - emit textureChanged(); +void WaylandSurfaceItem::surfaceDamaged(const QRect &) +{ + m_damaged = true; + update(); } WaylandSurfaceItem::WaylandSurfaceItem(QSGItem *parent) : QSGItem(parent) , m_surface(0) , m_texture(0) + , m_provider(0) , m_paintEnabled(true) , m_touchEventsEnabled(false) { @@ -81,6 +84,7 @@ WaylandSurfaceItem::WaylandSurfaceItem(WaylandSurface *surface, QSGItem *parent) : QSGItem(parent) , m_surface(0) , m_texture(0) + , m_provider(0) , m_paintEnabled(true) , m_touchEventsEnabled(false) { @@ -102,14 +106,15 @@ void WaylandSurfaceItem::init(WaylandSurface *surface) setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); connect(surface, SIGNAL(mapped(const QSize &)), this, SLOT(surfaceMapped(const QSize &))); connect(surface, SIGNAL(destroyed(QObject *)), this, SLOT(surfaceDestroyed(QObject *))); - connect(this, SIGNAL(textureChanged()), this, SLOT(update())); connect(surface, SIGNAL(damaged(const QRect &)), this, SLOT(surfaceDamaged(const QRect &))); + m_damaged = false; + } WaylandSurfaceItem::~WaylandSurfaceItem() { - delete m_texture; + m_texture->deleteLater(); } void WaylandSurfaceItem::setSurface(WaylandSurface *surface) @@ -122,26 +127,26 @@ bool WaylandSurfaceItem::isYInverted() const return m_surface->isYInverted(); } -QSGTexture *WaylandSurfaceItem::texture() const +QSGTextureProvider *WaylandSurfaceItem::textureProvider() const { - if (m_texture) - m_texture->setFiltering(smooth() ? QSGTexture::Linear : QSGTexture::Nearest); - return m_texture; + if (!m_provider) + m_provider = new WaylandSurfaceTextureProvider(); + return m_provider; } -void WaylandSurfaceItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +void WaylandSurfaceItem::mousePressEvent(QMouseEvent *event) { if (m_surface) m_surface->sendMousePressEvent(toSurface(event->pos()), event->button()); } -void WaylandSurfaceItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +void WaylandSurfaceItem::mouseMoveEvent(QMouseEvent *event) { if (m_surface) m_surface->sendMouseMoveEvent(toSurface(event->pos())); } -void WaylandSurfaceItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void WaylandSurfaceItem::mouseReleaseEvent(QMouseEvent *event) { if (m_surface) m_surface->sendMouseReleaseEvent(toSurface(event->pos()), event->button()); @@ -216,6 +221,25 @@ QSGNode *WaylandSurfaceItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDa { QSGSimpleTextureNode *node = static_cast<QSGSimpleTextureNode *>(oldNode); + if (m_damaged) { + QSGTexture *oldTexture = m_texture; + if (m_surface->type() == WaylandSurface::Texture) { + QSGEngine::TextureOption opt = useTextureAlpha() ? QSGEngine::TextureHasAlphaChannel : QSGEngine::TextureOption(0); + m_texture = canvas()->sceneGraphEngine()->createTextureFromId(m_surface->texture(), + m_surface->geometry().size(), + opt); + } else { + m_texture = canvas()->sceneGraphEngine()->createTextureFromImage(m_surface->image()); + } + delete oldTexture; + m_damaged = false; + } + + if (m_provider) { + m_provider->t = m_texture; + m_provider->smooth = smooth(); + } + if (!m_texture || !m_paintEnabled) { delete oldNode; return 0; @@ -255,7 +279,7 @@ void WaylandSurfaceItem::setClientRenderingEnabled(bool enabled) m_surface->sendOnScreenVisibilityChange(enabled); } - emit clientRenderingEnabledChanged(); + emit clientRenderingEnabledChanged(); } } diff --git a/src/qt-compositor/compositor_api/waylandsurfaceitem.h b/src/qt-compositor/compositor_api/waylandsurfaceitem.h index bc296b5..95b1429 100644 --- a/src/qt-compositor/compositor_api/waylandsurfaceitem.h +++ b/src/qt-compositor/compositor_api/waylandsurfaceitem.h @@ -47,12 +47,13 @@ #include <private/qsgtextureprovider_p.h> class WaylandSurface; +class WaylandSurfaceTextureProvider; + Q_DECLARE_METATYPE(WaylandSurface*) -class WaylandSurfaceItem : public QSGItem, public QSGTextureProvider +class WaylandSurfaceItem : public QSGItem { Q_OBJECT - Q_INTERFACES(QSGTextureProvider) Q_PROPERTY(WaylandSurface* surface READ surface WRITE setSurface) Q_PROPERTY(bool paintEnabled READ paintEnabled WRITE setPaintEnabled) Q_PROPERTY(bool useTextureAlpha READ useTextureAlpha WRITE setUseTextureAlpha NOTIFY useTextureAlphaChanged) @@ -69,8 +70,8 @@ public: Q_INVOKABLE bool isYInverted() const; - QSGTexture *texture() const; - const char *textureChangedSignal() const { return SIGNAL(textureChanged()); } + bool isTextureProvider() const { return true; } + QSGTextureProvider *textureProvider() const; bool paintEnabled() const; bool useTextureAlpha() const { return m_useTextureAlpha; } @@ -82,9 +83,9 @@ public: void setTouchEventsEnabled(bool enabled); protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); void keyPressEvent(QKeyEvent *event); void keyReleaseEvent(QKeyEvent *event); @@ -101,7 +102,6 @@ private slots: void surfaceDamaged(const QRect &); signals: - void textureChanged(); void useTextureAlphaChanged(); void clientRenderingEnabledChanged(); void touchEventsEnabledChanged(); @@ -115,10 +115,12 @@ private: WaylandSurface *m_surface; QSGTexture *m_texture; + mutable WaylandSurfaceTextureProvider *m_provider; bool m_paintEnabled; bool m_useTextureAlpha; bool m_clientRenderingEnabled; bool m_touchEventsEnabled; + bool m_damaged; }; #endif |