Remove the geometry from the wayland surface
authorJørgen Lind <jorgen.lind@nokia.com>
Wed, 4 Jan 2012 09:26:20 +0000 (10:26 +0100)
committerJørgen Lind <jorgen.lind@nokia.com>
Wed, 4 Jan 2012 10:51:06 +0000 (11:51 +0100)
and add pos and size properties instead. The pos is a PointF while the
size is a integer based Size since pos can be transformed, while the
size reffers to the pixel size.

Change-Id: I5d84aa6661405cb0df356b787246d0d73ad0c503
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
examples/qwidget-compositor/main.cpp
examples/qwindow-compositor/qwindowcompositor.cpp
src/compositor/compositor_api/waylandsurface.cpp
src/compositor/compositor_api/waylandsurface.h
src/compositor/compositor_api/waylandsurfaceitem.cpp
src/compositor/compositor_api/waylandsurfaceitem.h
src/compositor/wayland_wrapper/wlsubsurface.cpp
src/compositor/wayland_wrapper/wlsurface.cpp
src/compositor/wayland_wrapper/wlsurface.h

index a95eda6..b123b84 100644 (file)
@@ -96,10 +96,10 @@ private slots:
         WaylandSurface *surface = qobject_cast<WaylandSurface *>(sender());
         QPoint pos;
         if (!m_surfaces.contains(surface)) {
-            uint px = 1 + (qrand() % (width() - surface->geometry().size().width() - 2));
-            uint py = 1 + (qrand() % (height() - surface->geometry().size().height() - 2));
+            uint px = 1 + (qrand() % (width() - surface->size().width() - 2));
+            uint py = 1 + (qrand() % (height() - surface->size().height() - 2));
             pos = QPoint(px, py);
-            surface->setGeometry(QRect(pos, surface->geometry().size()));
+            surface->setPos(pos);
             m_surfaces.append(surface);
         }
 
@@ -163,17 +163,16 @@ protected:
         QLinkedListIterator<WaylandSurface *> i(surface->subSurfaces());
         while (i.hasNext()) {
             WaylandSurface *subSurface = i.next();
-            QPoint p = subSurface->mapTo(window,QPoint(0,0));
-            QRect geo = subSurface->geometry();
-            geo.moveTo(p);
-            if (geo.isValid()) {
+            QPointF p = subSurface->mapTo(window,QPoint(0,0));
+            QSize size = subSurface->size();
+            if (size.isValid()) {
                 GLuint texture = 0;
                 if (subSurface->type() == WaylandSurface::Texture) {
                     texture = subSurface->texture(QOpenGLContext::currentContext());
                 } else if (surface->type() == WaylandSurface::Shm ) {
                     texture = m_textureCache->bindTexture(context()->contextHandle(), surface->image());
                 }
-                m_textureBlitter->drawTexture(texture,geo,window->geometry().size(),0,window->isYInverted(),subSurface->isYInverted());
+                m_textureBlitter->drawTexture(texture,QRect(p.toPoint(),size),window->size(),0,window->isYInverted(),subSurface->isYInverted());
             }
             paintChildren(subSurface,window);
         }
@@ -227,7 +226,9 @@ protected:
         for (int i = 0; i < m_surfaces.size(); ++i) {
 #ifdef QT_COMPOSITOR_WAYLAND_GL
             GLuint texture = composeSurface(m_surfaces.at(i));
-            m_textureBlitter->drawTexture(texture,m_surfaces.at(i)->geometry(),size(),0,false,m_surfaces.at(i)->isYInverted());
+            WaylandSurface *surface = m_surfaces.at(i);
+            QRect geo(surface->pos().toPoint(),surface->size());
+            m_textureBlitter->drawTexture(texture,geo,size(),0,false,m_surfaces.at(i)->isYInverted());
 #else
             QImage img = composeSurface(m_surfaces.at(i));
             p.drawImage(m_surfaces.at(i)->geometry().topLeft(),img);
@@ -256,7 +257,7 @@ protected:
 
     void raise(WaylandSurface *surface) {
         setInputFocus(surface);
-        surfaceDamaged(surface, QRect(QPoint(), surface->geometry().size()));
+        surfaceDamaged(surface, QRect(QPoint(), surface->size()));
         m_surfaces.removeOne(surface);
         m_surfaces.append(surface);
     }
@@ -265,14 +266,14 @@ protected:
         m_cursorPos = e->pos();
         if (!m_cursor.isNull())
             update();
-        QPoint local;
+        QPointF local;
         if (WaylandSurface *surface = surfaceAt(e->pos(), &local)) {
             raise(surface);
             if (e->modifiers() & Qt::ControlModifier) {
                 m_moveSurface = surface;
                 m_moveOffset = local;
             } else {
-                surface->sendMousePressEvent(local, e->button());
+                surface->sendMousePressEvent(local.toPoint(), e->button());
             }
         }
     }
@@ -283,7 +284,7 @@ protected:
             update();
         if (isDragging()) {
             QPoint global = e->pos(); // "global" here means the window of the compositor
-            QPoint local;
+            QPointF local;
             WaylandSurface *surface = surfaceAt(e->pos(), &local);
             if (surface) {
                 if (!m_dragSourceSurface)
@@ -292,19 +293,17 @@ protected:
                     m_lastDragSourcePos = local;
                 raise(surface);
             }
-            sendDragMoveEvent(global, local, surface);
+            sendDragMoveEvent(global, local.toPoint(), surface);
             return;
         }
         if (m_moveSurface) {
-            QRect geometry = m_moveSurface->geometry();
-            geometry.moveTo(e->pos() - m_moveOffset);
-            m_moveSurface->setGeometry(geometry);
+            m_moveSurface->setPos(e->posF() - m_moveOffset);
             update();
             return;
         }
-        QPoint local;
+        QPointF local;
         if (WaylandSurface *surface = surfaceAt(e->pos(), &local))
-            surface->sendMouseMoveEvent(local);
+            surface->sendMouseMoveEvent(local.toPoint());
     }
 
     void mouseReleaseEvent(QMouseEvent *e) {
@@ -312,7 +311,7 @@ protected:
             sendDragEndEvent();
             if (m_dragSourceSurface) {
                 // Must send a release event to the source too, no matter where the cursor is now.
-                m_dragSourceSurface->sendMouseReleaseEvent(m_lastDragSourcePos, e->button());
+                m_dragSourceSurface->sendMouseReleaseEvent(m_lastDragSourcePos.toPoint(), e->button());
                 m_dragSourceSurface = 0;
             }
         }
@@ -320,9 +319,9 @@ protected:
             m_moveSurface = 0;
             return;
         }
-        QPoint local;
+        QPointF local;
         if (WaylandSurface *surface = surfaceAt(e->pos(), &local))
-            surface->sendMouseReleaseEvent(local, e->button());
+            surface->sendMouseReleaseEvent(local.toPoint(), e->button());
     }
 
     void keyPressEvent(QKeyEvent *event)
@@ -339,12 +338,14 @@ protected:
         m_surfaces.last()->sendKeyReleaseEvent(event->nativeScanCode());
     }
 
-    WaylandSurface *surfaceAt(const QPoint &point, QPoint *local = 0) {
+    WaylandSurface *surfaceAt(const QPointF &point, QPointF *local = 0) {
         for (int i = m_surfaces.size() - 1; i >= 0; --i) {
-            if (m_surfaces.at(i)->geometry().contains(point)) {
+            WaylandSurface *surface = m_surfaces.at(i);
+            QRect geo(surface->pos().toPoint(),surface->size());
+            if (geo.contains(point.toPoint())) {
                 if (local)
-                    *local = point - m_surfaces.at(i)->geometry().topLeft();
-                return m_surfaces.at(i);
+                    *local = point - surface->pos();
+                return surface;
             }
         }
         return 0;
@@ -369,9 +370,9 @@ private:
 #endif
 
     WaylandSurface *m_moveSurface;
-    QPoint m_moveOffset;
+    QPointF m_moveOffset;
     WaylandSurface *m_dragSourceSurface;
-    QPoint m_lastDragSourcePos;
+    QPointF m_lastDragSourcePos;
 
     QImage m_cursor;
     QPoint m_cursorPos;
index b6ad9ca..e97bfb6 100644 (file)
@@ -45,12 +45,12 @@ void QWindowCompositor::surfaceMapped()
     WaylandSurface *surface = qobject_cast<WaylandSurface *>(sender());
     QPoint pos;
     if (!m_surfaces.contains(surface)) {
-        uint px = 1 + (qrand() % (m_window->width() - surface->geometry().size().width() - 2));
-        uint py = 1 + (qrand() % (m_window->height() - surface->geometry().size().height() - 2));
+        uint px = 1 + (qrand() % (m_window->width() - surface->size().width() - 2));
+        uint py = 1 + (qrand() % (m_window->height() - surface->size().height() - 2));
         pos = QPoint(px, py);
-        surface->setGeometry(QRect(pos, surface->geometry().size()));
+        surface->setPos(pos);
     } else {
-        surface->setGeometry(QRect(window()->geometry().topLeft(),surface->geometry().size()));
+        surface->setPos(window()->geometry().topLeft());
         m_surfaces.removeOne(surface);
     }
     m_surfaces.append(surface);
@@ -81,16 +81,18 @@ void QWindowCompositor::surfaceCreated(WaylandSurface *surface)
 
 QPointF QWindowCompositor::toSurface(WaylandSurface *surface, const QPointF &pos) const
 {
-    return pos - surface->geometry().topLeft();
+    return pos - surface->pos();
 }
 
 WaylandSurface *QWindowCompositor::surfaceAt(const QPoint &point, QPoint *local)
 {
     for (int i = m_surfaces.size() - 1; i >= 0; --i) {
-        if (m_surfaces.at(i)->geometry().contains(point)) {
+        WaylandSurface *surface = m_surfaces.at(i);
+        QRect geo(surface->pos().toPoint(),surface->size());
+        if (geo.contains(point)) {
             if (local)
-                *local = toSurface(m_surfaces.at(i), point).toPoint();
-            return m_surfaces.at(i);
+                *local = toSurface(surface, point).toPoint();
+            return surface;
         }
     }
     return 0;
@@ -124,18 +126,16 @@ void QWindowCompositor::paintChildren(WaylandSurface *surface, WaylandSurface *w
     QLinkedListIterator<WaylandSurface *> i(surface->subSurfaces());
     while (i.hasNext()) {
         WaylandSurface *subSurface = i.next();
-        QPoint p = subSurface->mapTo(window,QPoint(0,0));
-        QRect geo = subSurface->geometry();
-        geo.moveTo(p);
-        if (geo.isValid()) {
+        QPointF p = subSurface->mapTo(window,QPointF(0,0));
+        if (subSurface->size().isValid()) {
             GLuint texture = 0;
             if (subSurface->type() == WaylandSurface::Texture) {
                 texture = subSurface->texture(QOpenGLContext::currentContext());
             } else if (surface->type() == WaylandSurface::Shm ) {
                 texture = m_textureCache->bindTexture(QOpenGLContext::currentContext(),surface->image());
             }
-            qDebug() << "window geo is" << window->geometry().size();
-            m_textureBlitter->drawTexture(texture,geo,window->geometry().size(),0,window->isYInverted(),subSurface->isYInverted());
+            QRect geo(p.toPoint(),subSurface->size());
+            m_textureBlitter->drawTexture(texture,geo,window->size(),0,window->isYInverted(),subSurface->isYInverted());
         }
         paintChildren(subSurface,window);
     }
@@ -160,7 +160,8 @@ void QWindowCompositor::render()
 
     foreach (WaylandSurface *surface, m_surfaces) {
         GLuint texture = composeSurface(surface);
-        m_textureBlitter->drawTexture(texture,surface->geometry(),m_window->size(),0,false,surface->isYInverted());
+        QRect geo(surface->pos().toPoint(),surface->size());
+        m_textureBlitter->drawTexture(texture,geo,m_window->size(),0,false,surface->isYInverted());
     }
 
     m_textureBlitter->release();
@@ -213,9 +214,7 @@ bool QWindowCompositor::eventFilter(QObject *obj, QEvent *event)
     case QEvent::MouseMove: {
         QMouseEvent *me = static_cast<QMouseEvent *>(event);
         if (m_draggingWindow) {
-            QRect geo = m_draggingWindow->geometry();
-            geo.moveTopLeft(me->pos() - m_drag_diff);
-            m_draggingWindow->setGeometry(geo);
+            m_draggingWindow->setPos(me->posF() - m_drag_diff);
             m_renderScheduler.start(0);
         } else {
             QPoint local;
index 60d2684..b7391e9 100644 (file)
@@ -76,16 +76,28 @@ bool WaylandSurface::visible() const
     return d->surface->visible();
 }
 
-QRect WaylandSurface::geometry() const
+QPointF WaylandSurface::pos() const
 {
     Q_D(const WaylandSurface);
-    return d->surface->geometry();
+    return d->surface->pos();
 }
 
-void WaylandSurface::setGeometry(const QRect &geometry)
+void WaylandSurface::setPos(const QPointF &pos)
 {
     Q_D(WaylandSurface);
-    d->surface->setGeometry(geometry);
+    d->surface->setPos(pos);
+}
+
+QSize WaylandSurface::size() const
+{
+    Q_D(const WaylandSurface);
+    d->surface->size();
+}
+
+void WaylandSurface::setSize(const QSize &size)
+{
+    Q_D(WaylandSurface);
+    d->surface->setSize(size);
 }
 
 QImage WaylandSurface::image() const
@@ -151,14 +163,14 @@ void WaylandSurface::setWindowProperty(const QString &name, const QVariant &valu
     d->surface->setWindowProperty(name, value);
 }
 
-QPoint WaylandSurface::mapToParent(const QPoint &pos) const
+QPointF WaylandSurface::mapToParent(const QPointF &pos) const
 {
-    return pos + geometry().topLeft();
+    return pos + this->pos();
 }
 
-QPoint WaylandSurface::mapTo(WaylandSurface *parent, const QPoint &pos) const
+QPointF WaylandSurface::mapTo(WaylandSurface *parent, const QPointF &pos) const
 {
-    QPoint p = pos;
+    QPointF p = pos;
     if (parent) {
         const WaylandSurface * surface = this;
         while (surface != parent) {
index 89befea..9457183 100644 (file)
@@ -68,7 +68,8 @@ class Q_COMPOSITOR_EXPORT WaylandSurface : public QObject
 {
     Q_OBJECT
     Q_DECLARE_PRIVATE(WaylandSurface)
-    Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
+    Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY sizeChanged)
+    Q_PROPERTY(QPointF pos READ pos WRITE setPos NOTIFY posChanged)
 public:
     enum Type {
         Invalid,
@@ -87,8 +88,10 @@ public:
 
     bool visible() const;
 
-    void setGeometry(const QRect &geometry);
-    QRect geometry() const;
+    QPointF pos() const;
+    void setPos(const QPointF &pos);
+    QSize size() const;
+    void setSize(const QSize &size);
 
     QImage image() const;
 #ifdef QT_COMPOSITOR_WAYLAND_GL
@@ -125,15 +128,16 @@ public:
     QVariantMap windowProperties() const;
     void setWindowProperty(const QString &name, const QVariant &value);
 
-    QPoint mapToParent(const QPoint &) const;
-    QPoint mapTo(WaylandSurface *, const QPoint &) const;
+    QPointF mapToParent(const QPointF &) const;
+    QPointF mapTo(WaylandSurface *, const QPointF &) const;
 
 signals:
     void mapped();
     void unmapped();
     void damaged(const QRect &rect);
     void parentChanged(WaylandSurface *newParent, WaylandSurface *oldParent);
-    void geometryChanged();
+    void sizeChanged();
+    void posChanged();
     void windowPropertyChanged(const QString &name, const QVariant &value);
 
     friend class Wayland::Surface;
index eca3f62..6083594 100644 (file)
@@ -98,8 +98,8 @@ void WaylandSurfaceItem::init(WaylandSurface *surface)
     m_surface = surface;
     m_surface->setSurfaceItem(this);
 
-    setWidth(surface->geometry().width());
-    setHeight(surface->geometry().height());
+    setWidth(surface->size().width());
+    setHeight(surface->size().height());
 
     setSmooth(true);
     setFlag(ItemHasContents);
@@ -110,7 +110,8 @@ void WaylandSurfaceItem::init(WaylandSurface *surface)
     connect(surface, SIGNAL(damaged(const QRect &)), this, SLOT(surfaceDamaged(const QRect &)));
     connect(surface, SIGNAL(parentChanged(WaylandSurface*,WaylandSurface*)),
             this, SLOT(parentChanged(WaylandSurface*,WaylandSurface*)));
-    connect(surface, SIGNAL(geometryChanged()), this, SLOT(updateGeometry()));
+    connect(surface, SIGNAL(sizeChanged()), this, SLOT(updateSize()));
+    connect(surface, SIGNAL(posChanged()), this, SLOT(updatePosition()));
 
     m_damaged = false;
 
@@ -239,10 +240,14 @@ void WaylandSurfaceItem::parentChanged(WaylandSurface *newParent, WaylandSurface
     }
 }
 
-void WaylandSurfaceItem::updateGeometry()
+void WaylandSurfaceItem::updateSize()
 {
-    setPos(m_surface->geometry().topLeft());
-    setSize(m_surface->geometry().size());
+    setSize(m_surface->size());
+}
+
+void WaylandSurfaceItem::updatePosition()
+{
+    setPos(m_surface->pos());
 }
 
 bool WaylandSurfaceItem::paintEnabled() const
@@ -270,7 +275,7 @@ QSGNode *WaylandSurfaceItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDa
 
             QQuickCanvas::CreateTextureOptions opt = useTextureAlpha() ? QQuickCanvas::TextureHasAlphaChannel : QQuickCanvas::CreateTextureOptions(0);
             m_texture = canvas()->createTextureFromId(m_surface->texture(context),
-                                                                          m_surface->geometry().size(),
+                                                                          m_surface->size(),
                                                                           opt);
         } else {
             m_texture = canvas()->createTextureFromImage(m_surface->image());
index 6e8161c..f6f9ecd 100644 (file)
@@ -104,7 +104,8 @@ private slots:
     void surfaceDestroyed(QObject *object);
     void surfaceDamaged(const QRect &);
     void parentChanged(WaylandSurface *newParent, WaylandSurface *oldParent);
-    void updateGeometry();
+    void updateSize();
+    void updatePosition();
 
 signals:
     void textureChanged();
index e8b8ab6..4289222 100644 (file)
@@ -91,12 +91,10 @@ SubSurface::~SubSurface()
 
 void SubSurface::setSubSurface(SubSurface *subSurface, int x, int y)
 {
-//    Q_ASSERT(!m_sub_surfaces.contains(subSurface->m_surface->handle()));
+    Q_ASSERT(!m_sub_surfaces.contains(subSurface->m_surface->handle()));
     m_sub_surfaces.append(subSurface->m_surface->handle());
     subSurface->setParent(this);
-    QRect rect = m_surface->geometry();
-    rect.moveTo(x,y);
-    subSurface->m_surface->setGeometry(rect);
+    subSurface->m_surface->setPos(QPointF(x,y));
 }
 
 void SubSurface::removeSubSurface(SubSurface *subSurfaces)
index 30b0bd0..6a8547e 100644 (file)
@@ -243,7 +243,8 @@ public:
 
     SurfaceBuffer bufferPool[buffer_pool_size];
 
-    QRect geometry;
+    QPointF position;
+    QSize size;
 private:
     Surface *q_ptr;
 };
@@ -377,21 +378,34 @@ QImage Surface::image() const
     return QImage();
 }
 
-QRect Surface::geometry() const
+QPointF Surface::pos() const
 {
     Q_D(const Surface);
-    return d->geometry;
+    return d->position;
 }
 
-void Surface::setGeometry(const QRect &rect)
+void Surface::setPos(const QPointF &pos)
 {
     Q_D(Surface);
-    bool emitChange = false;
-    if (rect != d->geometry)
-        emitChange = true;
-    d->geometry = rect;
+    bool emitChange = pos != d->position;
+    d->position = pos;
     if (emitChange)
-        d->qtSurface->geometryChanged();
+        d->qtSurface->posChanged();
+}
+
+QSize Surface::size() const
+{
+    Q_D(const Surface);
+    return d->size;
+}
+
+void Surface::setSize(const QSize &size)
+{
+    Q_D(Surface);
+    bool emitChange = size != d->size;
+    d->size = size;
+    if (emitChange)
+        d->qtSurface->sizeChanged();
 }
 
 #ifdef QT_COMPOSITOR_WAYLAND_GL
@@ -440,9 +454,7 @@ void Surface::attach(struct wl_buffer *buffer)
     bool emitMap = !d->surfaceBuffer && buffer && (!d->subSurface || !d->subSurface->parent());
     bool emitUnmap = d->surfaceBuffer && !buffer;
 
-    if (d->surfaceBuffer && d->surfaceBuffer != d->directRenderBuffer) {
-        if (d->textureBuffer == d->surfaceBuffer)
-            d->textureBuffer = 0;
+    if (d->surfaceBuffer && !d->surfaceBuffer->textureCreated() && d->surfaceBuffer != d->directRenderBuffer) {
         d->surfaceBuffer->destructBufferState();
         d->surfaceBuffer = 0;
     }
@@ -453,10 +465,7 @@ void Surface::attach(struct wl_buffer *buffer)
         width = d->surfaceBuffer->width();
         height = d->surfaceBuffer->height();
     }
-    QRect geo = geometry();
-    geo.setWidth(width);
-    geo.setHeight(height);
-    setGeometry(geo);
+    setSize(QSize(width,height));
 
     if (emitMap) {
         d->qtSurface->mapped();
index 905ee53..88bd15c 100644 (file)
@@ -84,8 +84,11 @@ public:
 
     QImage image() const;
 
-    QRect geometry() const;
-    void setGeometry(const QRect &rect);
+    QPointF pos() const;
+    void setPos(const QPointF  &pos);
+
+    QSize size() const;
+    void setSize(const QSize &size);
 
 #ifdef QT_COMPOSITOR_WAYLAND_GL
     GLuint textureId(QOpenGLContext *context) const;