summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorGiulio Camuffo <giulio.camuffo@jollamobile.com>2014-03-31 17:18:43 +0300
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-29 11:17:45 +0200
commitbb37532f36862eb29e033508d1c6c5dbc8c2be13 (patch)
treefa9d2e8300bf07f07e2c49b35e1bb936fbe8bc90 /examples
parent96ab8abe0b0faea7f63f0477025fe0649e410362 (diff)
Split QWaylandSurface in a model and view fashion
QtQuick compositors already use a view class (QWaylandSurfaceItem), so add a new QWaylandSurfaceView, which is subclassed by QWaylandSurfaceItem, and move the view related methods of QWaylandSurface there. A QWaylandSurface can have many views. Change-Id: I7e92fe1f7e9d252f5f40a3097feabb5f3318b03a Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/qml-compositor/WindowContainer.qml22
-rw-r--r--examples/qml-compositor/main.cpp7
-rw-r--r--examples/qml-compositor/main.qml4
-rw-r--r--examples/qwindow-compositor/qwindowcompositor.cpp120
-rw-r--r--examples/qwindow-compositor/qwindowcompositor.h14
-rw-r--r--examples/server-buffer/compositor/main.cpp6
-rw-r--r--examples/server-buffer/compositor/qml/main.qml14
7 files changed, 84 insertions, 103 deletions
diff --git a/examples/qml-compositor/WindowContainer.qml b/examples/qml-compositor/WindowContainer.qml
index 77dd1d4dc..8d25327cc 100644
--- a/examples/qml-compositor/WindowContainer.qml
+++ b/examples/qml-compositor/WindowContainer.qml
@@ -57,16 +57,6 @@ Item {
console.log("visibility changed: " + visible);
}
- WaylandSurfaceItem {
- id: surfaceItem
- anchors.fill: parent
- touchEventsEnabled: true
-
- onSurfaceDestroyed: {
- destroyAnimation.start();
- }
- }
-
opacity: 0
property real targetX
@@ -75,7 +65,7 @@ Item {
property real targetHeight
property real targetScale
- property variant child: surfaceItem
+ property variant child: null
property variant chrome: null
property bool animationsEnabled: false
property bool isFullscreen: state === "fullscreen"
@@ -116,7 +106,7 @@ Item {
ContrastEffect {
id: effect
source: child
- anchors.fill: child
+ anchors.fill: parent
blend: { if (child && chrome && (chrome.selected || child.focus)) 0.0; else 0.6 }
opacity: 1.0
z: 1
@@ -188,9 +178,15 @@ Item {
}
Connections {
- target: container.child.surface
+ target: container.child ? container.child.surface : null
onUnmapped: unmapAnimation.start()
}
+ Connections {
+ target: container.child
+ onSurfaceDestroyed: {
+ destroyAnimation.start();
+ }
+ }
Image {
source: "closebutton.png"
diff --git a/examples/qml-compositor/main.cpp b/examples/qml-compositor/main.cpp
index dbabc9d04..91bc6677f 100644
--- a/examples/qml-compositor/main.cpp
+++ b/examples/qml-compositor/main.cpp
@@ -41,6 +41,8 @@
#include "qwaylandquickcompositor.h"
#include "qwaylandquicksurface.h"
+#include <QtCompositor/qwaylandsurfaceitem.h>
+
#include <QGuiApplication>
#include <QTimer>
#include <QPainter>
@@ -74,6 +76,11 @@ public:
return m_fullscreenSurface;
}
+ Q_INVOKABLE QWaylandSurfaceItem *item(QWaylandSurface *surf)
+ {
+ return static_cast<QWaylandSurfaceItem *>(surf->views().first());
+ }
+
signals:
void windowAdded(QVariant window);
void windowDestroyed(QVariant window);
diff --git a/examples/qml-compositor/main.qml b/examples/qml-compositor/main.qml
index 120c92bdb..9fafccb86 100644
--- a/examples/qml-compositor/main.qml
+++ b/examples/qml-compositor/main.qml
@@ -87,7 +87,9 @@ Item {
var windowContainer = windowContainerComponent.createObject(root);
console.log(windowContainerComponent.errorString());
- windowContainer.child.surface = window;
+ windowContainer.child = compositor.item(window);
+ windowContainer.child.parent = windowContainer;
+ windowContainer.child.touchEventsEnabled = true;
windowContainer.targetWidth = window.size.width;
windowContainer.targetHeight = window.size.height;
diff --git a/examples/qwindow-compositor/qwindowcompositor.cpp b/examples/qwindow-compositor/qwindowcompositor.cpp
index b485064f1..925e3214f 100644
--- a/examples/qwindow-compositor/qwindowcompositor.cpp
+++ b/examples/qwindow-compositor/qwindowcompositor.cpp
@@ -53,6 +53,7 @@
#include <QtCompositor/qwaylandinput.h>
#include <QtCompositor/qwaylandbufferref.h>
+#include <QtCompositor/qwaylandsurfaceview.h>
static GLuint textureFromImage(const QImage &image)
{
@@ -187,7 +188,8 @@ void QWindowCompositor::surfaceMapped()
py = 1 + (qrand() % (m_window->height() - surface->size().height() - 2));
}
pos = QPoint(px, py);
- surface->setPos(pos);
+ QWaylandSurfaceView *view = surface->views().first();
+ view->setPos(pos);
} else {
m_surfaces.removeOne(surface);
}
@@ -232,7 +234,6 @@ void QWindowCompositor::surfaceCreated(QWaylandSurface *surface)
connect(surface, SIGNAL(unmapped()), this, SLOT(surfaceUnmapped()));
connect(surface, SIGNAL(redraw()), this, SLOT(surfaceCommitted()));
connect(surface, SIGNAL(extendedSurfaceReady()), this, SLOT(sendExpose()));
- connect(surface, SIGNAL(posChanged()), this, SLOT(surfacePosChanged()));
m_renderScheduler.start(0);
surface->setBufferAttacher(new BufferAttacher);
@@ -262,9 +263,9 @@ void QWindowCompositor::updateCursor(bool hasBuffer)
}
}
-QPointF QWindowCompositor::toSurface(QWaylandSurface *surface, const QPointF &pos) const
+QPointF QWindowCompositor::toView(QWaylandSurfaceView *view, const QPointF &pos) const
{
- return pos - surface->pos();
+ return pos - view->pos();
}
void QWindowCompositor::setCursorSurface(QWaylandSurface *surface, int hotspotX, int hotspotY)
@@ -279,62 +280,22 @@ void QWindowCompositor::setCursorSurface(QWaylandSurface *surface, int hotspotX,
m_cursorSurface->setBufferAttacher(new BufferAttacher);
}
-QWaylandSurface *QWindowCompositor::surfaceAt(const QPointF &point, QPointF *local)
+QWaylandSurfaceView *QWindowCompositor::viewAt(const QPointF &point, QPointF *local)
{
for (int i = m_surfaces.size() - 1; i >= 0; --i) {
QWaylandSurface *surface = m_surfaces.at(i);
- QRectF geo(surface->pos(), surface->size());
- if (geo.contains(point)) {
- if (local)
- *local = toSurface(surface, point);
- return surface;
+ foreach (QWaylandSurfaceView *view, surface->views()) {
+ QRectF geo(view->pos(), surface->size());
+ if (geo.contains(point)) {
+ if (local)
+ *local = toView(view, point);
+ return view;
+ }
}
}
return 0;
}
-GLuint QWindowCompositor::composeSurface(QWaylandSurface *surface)
-{
- QSize windowSize = surface->size();
-
- QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
- functions->glBindFramebuffer(GL_FRAMEBUFFER, m_surface_fbo);
-
- GLuint texture = static_cast<BufferAttacher *>(surface->bufferAttacher())->texture;
-
- functions->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D, texture, 0);
- paintChildren(surface, surface,windowSize);
- functions->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D,0, 0);
-
- functions->glBindFramebuffer(GL_FRAMEBUFFER, 0);
-
-
- return texture;
-}
-
-void QWindowCompositor::paintChildren(QWaylandSurface *surface, QWaylandSurface *window, const QSize &windowSize) {
-
- if (surface->subSurfaces().size() == 0)
- return;
-
- QLinkedListIterator<QWaylandSurface *> i(surface->subSurfaces());
- while (i.hasNext()) {
- QWaylandSurface *subSurface = i.next();
- QPointF p = subSurface->mapTo(window,QPointF(0,0));
- QSize subSize = subSurface->size();
- if (subSize.isValid()) {
- GLuint texture = static_cast<BufferAttacher *>(subSurface->bufferAttacher())->texture;
- QRect geo(p.toPoint(),subSize);
- if (texture > 0)
- m_textureBlitter->drawTexture(texture,geo,windowSize,0,window->isYInverted(),subSurface->isYInverted());
- }
- paintChildren(subSurface,window,windowSize);
- }
-}
-
-
void QWindowCompositor::render()
{
m_window->makeCurrent();
@@ -355,9 +316,14 @@ void QWindowCompositor::render()
foreach (QWaylandSurface *surface, m_surfaces) {
if (!surface->visible())
continue;
- GLuint texture = composeSurface(surface);
- QRect geo(surface->pos().toPoint(),surface->size());
- m_textureBlitter->drawTexture(texture,geo,m_window->size(),0,false,surface->isYInverted());
+ GLuint texture = static_cast<BufferAttacher *>(surface->bufferAttacher())->texture;
+ foreach (QWaylandSurfaceView *view, surface->views()) {
+ QRect geo(view->pos().toPoint(),surface->size());
+ m_textureBlitter->drawTexture(texture,geo,m_window->size(),0,false,surface->isYInverted());
+ foreach (QWaylandSurface *child, surface->subSurfaces()) {
+ drawSubSurface(view->pos().toPoint(), child);
+ }
+ }
}
m_textureBlitter->release();
@@ -367,6 +333,18 @@ void QWindowCompositor::render()
m_window->swapBuffers();
}
+void QWindowCompositor::drawSubSurface(const QPoint &offset, QWaylandSurface *surface)
+{
+ GLuint texture = static_cast<BufferAttacher *>(surface->bufferAttacher())->texture;
+ QWaylandSurfaceView *view = surface->views().first();
+ QPoint pos = view->pos().toPoint() + offset;
+ QRect geo(pos, surface->size());
+ m_textureBlitter->drawTexture(texture, geo, m_window->size(), 0, false, surface->isYInverted());
+ foreach (QWaylandSurface *child, surface->subSurfaces()) {
+ drawSubSurface(pos, child);
+ }
+}
+
bool QWindowCompositor::eventFilter(QObject *obj, QEvent *event)
{
if (obj != m_window)
@@ -394,15 +372,15 @@ bool QWindowCompositor::eventFilter(QObject *obj, QEvent *event)
case QEvent::MouseButtonPress: {
QPointF local;
QMouseEvent *me = static_cast<QMouseEvent *>(event);
- QWaylandSurface *targetSurface = surfaceAt(me->localPos(), &local);
- if (m_dragKeyIsPressed && targetSurface) {
- m_draggingWindow = targetSurface;
+ QWaylandSurfaceView *target = viewAt(me->localPos(), &local);
+ if (m_dragKeyIsPressed && target) {
+ m_draggingWindow = target;
m_drag_diff = local;
} else {
- if (targetSurface && input->keyboardFocus() != targetSurface) {
- input->setKeyboardFocus(targetSurface);
- m_surfaces.removeOne(targetSurface);
- m_surfaces.append(targetSurface);
+ if (target && input->keyboardFocus() != target->surface()) {
+ input->setKeyboardFocus(target->surface());
+ m_surfaces.removeOne(target->surface());
+ m_surfaces.append(target->surface());
m_renderScheduler.start(0);
}
input->sendMousePressEvent(me->button(), local, me->localPos());
@@ -410,15 +388,15 @@ bool QWindowCompositor::eventFilter(QObject *obj, QEvent *event)
return true;
}
case QEvent::MouseButtonRelease: {
- QWaylandSurface *targetSurface = input->mouseFocus();
+ QWaylandSurfaceView *target = input->mouseFocus();
if (m_draggingWindow) {
m_draggingWindow = 0;
m_drag_diff = QPointF();
} else {
QMouseEvent *me = static_cast<QMouseEvent *>(event);
QPointF localPos;
- if (targetSurface)
- localPos = toSurface(targetSurface, me->localPos());
+ if (target)
+ localPos = toView(target, me->localPos());
input->sendMouseReleaseEvent(me->button(), localPos, me->localPos());
}
return true;
@@ -430,8 +408,8 @@ bool QWindowCompositor::eventFilter(QObject *obj, QEvent *event)
m_renderScheduler.start(0);
} else {
QPointF local;
- QWaylandSurface *targetSurface = surfaceAt(me->localPos(), &local);
- input->sendMouseMoveEvent(targetSurface, local, me->localPos());
+ QWaylandSurfaceView *target = viewAt(me->localPos(), &local);
+ input->sendMouseMoveEvent(target, local, me->localPos());
}
break;
}
@@ -466,16 +444,16 @@ bool QWindowCompositor::eventFilter(QObject *obj, QEvent *event)
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
- QWaylandSurface *targetSurface = 0;
+ QWaylandSurfaceView *target = 0;
QTouchEvent *te = static_cast<QTouchEvent *>(event);
QList<QTouchEvent::TouchPoint> points = te->touchPoints();
QPoint pointPos;
if (!points.isEmpty()) {
pointPos = points.at(0).pos().toPoint();
- targetSurface = surfaceAt(pointPos);
+ target = viewAt(pointPos);
}
- if (targetSurface && targetSurface != input->mouseFocus())
- input->setMouseFocus(targetSurface, pointPos, pointPos);
+ if (target && target != input->mouseFocus())
+ input->setMouseFocus(target, pointPos, pointPos);
if (input->mouseFocus())
input->sendFullTouchEvent(te);
break;
diff --git a/examples/qwindow-compositor/qwindowcompositor.h b/examples/qwindow-compositor/qwindowcompositor.h
index c84bb9145..a366b8951 100644
--- a/examples/qwindow-compositor/qwindowcompositor.h
+++ b/examples/qwindow-compositor/qwindowcompositor.h
@@ -50,6 +50,8 @@
#include <QObject>
#include <QTimer>
+class QWaylandSurfaceView;
+
class QWindowCompositor : public QObject, public QWaylandCompositor
{
Q_OBJECT
@@ -69,14 +71,10 @@ protected:
void surfaceCommitted(QWaylandSurface *surface);
void surfaceCreated(QWaylandSurface *surface);
- QWaylandSurface* surfaceAt(const QPointF &point, QPointF *local = 0);
-
- GLuint composeSurface(QWaylandSurface *surface);
- void paintChildren(QWaylandSurface *surface, QWaylandSurface *window, const QSize &windowSize);
-
+ QWaylandSurfaceView* viewAt(const QPointF &point, QPointF *local = 0);
bool eventFilter(QObject *obj, QEvent *event);
- QPointF toSurface(QWaylandSurface *surface, const QPointF &pos) const;
+ QPointF toView(QWaylandSurfaceView *view, const QPointF &pos) const;
void setCursorSurface(QWaylandSurface *surface, int hotspotX, int hotspotY);
@@ -88,6 +86,8 @@ private slots:
void updateCursor(bool hasBuffer);
private:
+ void drawSubSurface(const QPoint &offset, QWaylandSurface *surface);
+
QOpenGLWindow *m_window;
QImage m_backgroundImage;
GLuint m_backgroundTexture;
@@ -97,7 +97,7 @@ private:
QTimer m_renderScheduler;
//Dragging windows around
- QWaylandSurface *m_draggingWindow;
+ QWaylandSurfaceView *m_draggingWindow;
bool m_dragKeyIsPressed;
QPointF m_drag_diff;
diff --git a/examples/server-buffer/compositor/main.cpp b/examples/server-buffer/compositor/main.cpp
index a30ea0895..77c3a1a08 100644
--- a/examples/server-buffer/compositor/main.cpp
+++ b/examples/server-buffer/compositor/main.cpp
@@ -40,6 +40,7 @@
#include "qwaylandquickcompositor.h"
#include "qwaylandsurface.h"
+#include "qwaylandsurfaceitem.h"
#include <QGuiApplication>
#include <QTimer>
@@ -88,6 +89,11 @@ public:
connect(this, SIGNAL(serverBuffersCreated()), this, SLOT(createServerBufferItems()));
}
+ Q_INVOKABLE QWaylandSurfaceItem *item(QWaylandSurface *surf)
+ {
+ return static_cast<QWaylandSurfaceItem *>(surf->views().first());
+ }
+
signals:
void windowAdded(QVariant window);
void windowDestroyed(QVariant window);
diff --git a/examples/server-buffer/compositor/qml/main.qml b/examples/server-buffer/compositor/qml/main.qml
index 1beddbf1d..c9d62be55 100644
--- a/examples/server-buffer/compositor/qml/main.qml
+++ b/examples/server-buffer/compositor/qml/main.qml
@@ -59,18 +59,10 @@ Item {
anchors.fill: parent
}
- Component {
- id: windowItem
- WaylandSurfaceItem {
- onSurfaceDestroyed: {
- destroy();
- }
- }
- }
-
function windowAdded(window) {
- var item = windowItem.createObject(root);
- item.surface = window;
+ var item = compositor.item(window);
+ item.parent = root;
+ item.surfaceDestroyed.connect(item.destroy);
}
function windowResized(window) {