diff options
author | Liang Qi <liang.qi@qt.io> | 2017-01-25 12:12:45 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-01-25 12:19:40 +0100 |
commit | 44e3a9d321190f2958e1a1bdfa7f840e56355279 (patch) | |
tree | 4d167e9d0cfcb59eb6e2dd5ed4f55981627e9339 /examples | |
parent | e26696524ceb58f4fe0cb7202d873240b6a9478d (diff) | |
parent | f72d63866d3f5820865fcd309b649dc9932518ee (diff) |
Merge remote-tracking branch 'origin/5.8' into dev
Conflicts:
.qmake.conf
examples/wayland/custom-extension/client-common/main.cpp
src/client/qwaylandwlshellintegration_p.h
src/client/qwaylandxdgshellintegration_p.h
src/compositor/compositor_api/qwaylandquickoutput.h
src/plugins/shellintegration/ivi-shell/qwaylandivisurface_p.h
Change-Id: Ic78c610ddf102b0a185294f625bbfcb9238b0f3c
Diffstat (limited to 'examples')
11 files changed, 134 insertions, 43 deletions
diff --git a/examples/wayland/custom-extension/client-common/customextension.h b/examples/wayland/custom-extension/client-common/customextension.h index 3b64fc646..9f7fac782 100644 --- a/examples/wayland/custom-extension/client-common/customextension.h +++ b/examples/wayland/custom-extension/client-common/customextension.h @@ -69,11 +69,11 @@ private slots: void handleExtensionActive(); private: - void example_extension_close(wl_surface *surface) Q_DECL_OVERRIDE; - void example_extension_set_font_size(wl_surface *surface, uint32_t pixel_size) Q_DECL_OVERRIDE; - void example_extension_set_window_decoration(uint32_t state) Q_DECL_OVERRIDE; + void example_extension_close(wl_surface *surface) override; + void example_extension_set_font_size(wl_surface *surface, uint32_t pixel_size) override; + void example_extension_set_window_decoration(uint32_t state) override; - bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE; + bool eventFilter(QObject *object, QEvent *event) override; QWindow *windowForSurface(struct ::wl_surface *); void sendWindowRegistration(QWindow *); diff --git a/examples/wayland/custom-extension/compositor/customextension.h b/examples/wayland/custom-extension/compositor/customextension.h index b1b00408b..7f09ad0eb 100644 --- a/examples/wayland/custom-extension/compositor/customextension.h +++ b/examples/wayland/custom-extension/compositor/customextension.h @@ -54,7 +54,7 @@ class CustomExtension : public QWaylandCompositorExtensionTemplate<CustomExtens Q_OBJECT public: CustomExtension(QWaylandCompositor *compositor = 0); - void initialize() Q_DECL_OVERRIDE; + void initialize() override; signals: void surfaceAdded(QWaylandSurface *surface); @@ -67,9 +67,9 @@ public slots: void close(QWaylandSurface *surface); protected: - void example_extension_bounce(Resource *resource, wl_resource *surface, uint32_t duration) Q_DECL_OVERRIDE; - void example_extension_spin(Resource *resource, wl_resource *surface, uint32_t duration) Q_DECL_OVERRIDE; - void example_extension_register_surface(Resource *resource, wl_resource *surface) Q_DECL_OVERRIDE; + void example_extension_bounce(Resource *resource, wl_resource *surface, uint32_t duration) override; + void example_extension_spin(Resource *resource, wl_resource *surface, uint32_t duration) override; + void example_extension_register_surface(Resource *resource, wl_resource *surface) override; }; Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(CustomExtension) diff --git a/examples/wayland/custom-extension/cpp-client/main.cpp b/examples/wayland/custom-extension/cpp-client/main.cpp index af8de53b5..3dbada171 100644 --- a/examples/wayland/custom-extension/cpp-client/main.cpp +++ b/examples/wayland/custom-extension/cpp-client/main.cpp @@ -100,7 +100,7 @@ public slots: } protected: - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE + void paintEvent(QPaintEvent *) override { QPainter p(this); p.setFont(m_font); @@ -113,7 +113,7 @@ protected: p.drawText(rect3, Qt::TextWordWrap, "Create new window."); } - void mousePressEvent(QMouseEvent *ev) Q_DECL_OVERRIDE + void mousePressEvent(QMouseEvent *ev) override { if (rect1.contains(ev->pos())) doSpin(); diff --git a/examples/wayland/minimal-cpp/compositor.h b/examples/wayland/minimal-cpp/compositor.h index e44a8eb52..3ac0311e3 100644 --- a/examples/wayland/minimal-cpp/compositor.h +++ b/examples/wayland/minimal-cpp/compositor.h @@ -68,7 +68,7 @@ class Compositor : public QWaylandCompositor public: Compositor(Window *window); ~Compositor(); - void create() Q_DECL_OVERRIDE; + void create() override; QList<View*> views() const { return m_views; } diff --git a/examples/wayland/minimal-cpp/window.h b/examples/wayland/minimal-cpp/window.h index 4df1bc833..16b14c8e9 100644 --- a/examples/wayland/minimal-cpp/window.h +++ b/examples/wayland/minimal-cpp/window.h @@ -55,8 +55,8 @@ public: void setCompositor(Compositor *comp); protected: - void initializeGL() Q_DECL_OVERRIDE; - void paintGL() Q_DECL_OVERRIDE; + void initializeGL() override; + void paintGL() override; private: QOpenGLTextureBlitter m_textureBlitter; diff --git a/examples/wayland/qwindow-compositor/compositor.cpp b/examples/wayland/qwindow-compositor/compositor.cpp index 4878c373e..8d0db5258 100644 --- a/examples/wayland/qwindow-compositor/compositor.cpp +++ b/examples/wayland/qwindow-compositor/compositor.cpp @@ -56,13 +56,15 @@ #define GL_TEXTURE_EXTERNAL_OES 0x8D65 #endif -View::View() - : m_textureTarget(GL_TEXTURE_2D) +View::View(Compositor *compositor) + : m_compositor(compositor) + , m_textureTarget(GL_TEXTURE_2D) , m_texture(0) , m_wlShellSurface(nullptr) , m_xdgSurface(nullptr) , m_xdgPopup(nullptr) , m_parentView(nullptr) + , m_animationFactor(1.0) {} QOpenGLTexture *View::getTexture() @@ -70,16 +72,33 @@ QOpenGLTexture *View::getTexture() if (advance()) { QWaylandBufferRef buf = currentBuffer(); m_texture = buf.toOpenGLTexture(); + if (surface()) { + m_size = surface()->size(); + m_origin = buf.origin() == QWaylandSurface::OriginTopLeft + ? QOpenGLTextureBlitter::OriginTopLeft + : QOpenGLTextureBlitter::OriginBottomLeft; + } } return m_texture; } +QOpenGLTextureBlitter::Origin View::textureOrigin() const +{ + return m_origin; +} + +QSize View::size() const +{ + return surface() ? surface()->size() : m_size; +} + bool View::isCursor() const { - return surface()->isCursorSurface(); + return surface() && surface()->isCursorSurface(); } + void View::onXdgSetMaximized() { m_xdgSurface->sendMaximized(output()->geometry().size()); @@ -117,6 +136,44 @@ void View::onOffsetForNextFrame(const QPoint &offset) setPosition(position() + offset); } + +void View::timerEvent(QTimerEvent *event) +{ + if (event->timerId() != m_animationTimer.timerId()) + return; + + m_compositor->triggerRender(); + + if (m_animationCountUp) { + m_animationFactor += .08; + if (m_animationFactor > 1.0) { + m_animationFactor = 1.0; + m_animationTimer.stop(); + emit animationDone(); + } + } else { + m_animationFactor -= .08; + if (m_animationFactor < 0.01) { + m_animationFactor = 0.01; + m_animationTimer.stop(); + emit animationDone(); + } + } +} + +void View::startAnimation(bool countUp) +{ + m_animationCountUp = countUp; + m_animationFactor = countUp ? .1 : 1.0; + m_animationTimer.start(20, this); +} + +void View::cancelAnimation() +{ + m_animationFactor = 1.0; + m_animationTimer.stop(); +} + void View::onXdgUnsetFullscreen() { onXdgUnsetMaximized(); @@ -159,8 +216,7 @@ void Compositor::onSurfaceCreated(QWaylandSurface *surface) connect(surface, &QWaylandSurface::redraw, this, &Compositor::triggerRender); connect(surface, &QWaylandSurface::subsurfacePositionChanged, this, &Compositor::onSubsurfacePositionChanged); - - View *view = new View; + View *view = new View(this); view->setSurface(surface); view->setOutput(outputFor(m_window)); m_views << view; @@ -189,10 +245,20 @@ void Compositor::surfaceDestroyed() void Compositor::viewSurfaceDestroyed() { View *view = qobject_cast<View*>(sender()); + view->setBufferLocked(true); + view->startAnimation(false); + connect(view, &View::animationDone, this, &Compositor::viewAnimationDone); +} + + +void Compositor::viewAnimationDone() +{ + View *view = qobject_cast<View*>(sender()); m_views.removeAll(view); delete view; } + View * Compositor::findView(const QWaylandSurface *s) const { Q_FOREACH (View* view, m_views) { @@ -212,6 +278,7 @@ void Compositor::onWlShellSurfaceCreated(QWaylandWlShellSurface *wlShellSurface) View *view = findView(wlShellSurface->surface()); Q_ASSERT(view); view->m_wlShellSurface = wlShellSurface; + view->startAnimation(true); } void Compositor::onXdgSurfaceCreated(QWaylandXdgSurfaceV5 *xdgSurface) @@ -227,6 +294,7 @@ void Compositor::onXdgSurfaceCreated(QWaylandXdgSurfaceV5 *xdgSurface) connect(xdgSurface, &QWaylandXdgSurfaceV5::setFullscreen, view, &View::onXdgSetFullscreen); connect(xdgSurface, &QWaylandXdgSurfaceV5::unsetMaximized, view, &View::onXdgUnsetMaximized); connect(xdgSurface, &QWaylandXdgSurfaceV5::unsetFullscreen, view, &View::onXdgUnsetFullscreen); + view->startAnimation(true); } void Compositor::onXdgPopupRequested(QWaylandSurface *surface, QWaylandSurface *parent, @@ -291,6 +359,7 @@ void Compositor::onSetPopup(QWaylandSeat *seat, QWaylandSurface *parent, const Q View *parentView = findView(parent); if (parentView) view->setPosition(parentView->position() + relativeToParent); + view->cancelAnimation(); } } diff --git a/examples/wayland/qwindow-compositor/compositor.h b/examples/wayland/qwindow-compositor/compositor.h index bf52c8c7e..ddc85c480 100644 --- a/examples/wayland/qwindow-compositor/compositor.h +++ b/examples/wayland/qwindow-compositor/compositor.h @@ -47,6 +47,7 @@ #include <QtWaylandCompositor/QWaylandWlShellSurface> #include <QtWaylandCompositor/QWaylandXdgSurfaceV5> #include <QTimer> +#include <QOpenGLTextureBlitter> QT_BEGIN_NAMESPACE @@ -54,33 +55,51 @@ class QWaylandWlShell; class QWaylandWlShellSurface; class QWaylandXdgShellV5; class QOpenGLTexture; +class Compositor; class View : public QWaylandView { Q_OBJECT public: - View(); + View(Compositor *compositor); QOpenGLTexture *getTexture(); + QOpenGLTextureBlitter::Origin textureOrigin() const; QPointF position() const { return m_position; } void setPosition(const QPointF &pos) { m_position = pos; } + QSize size() const; bool isCursor() const; bool hasShell() const { return m_wlShellSurface; } void setParentView(View *parent) { m_parentView = parent; } View *parentView() const { return m_parentView; } QPointF parentPosition() const { return m_parentView ? (m_parentView->position() + m_parentView->parentPosition()) : QPointF(); } - QSize windowSize() { return m_xdgSurface ? m_xdgSurface->windowGeometry().size() : surface()->size(); } + QSize windowSize() { return m_xdgSurface ? m_xdgSurface->windowGeometry().size() : surface() ? surface()->size() : m_size; } QPoint offset() const { return m_offset; } + qreal animationFactor() const {return m_animationFactor; } + void setAnimationFactor(qreal f) {m_animationFactor = f; } + +signals: + void animationDone(); + +protected: + void timerEvent(QTimerEvent *event); + private: friend class Compositor; + Compositor *m_compositor; GLenum m_textureTarget; QOpenGLTexture *m_texture; + QOpenGLTextureBlitter::Origin m_origin; QPointF m_position; + QSize m_size; QWaylandWlShellSurface *m_wlShellSurface; QWaylandXdgSurfaceV5 *m_xdgSurface; QWaylandXdgPopupV5 *m_xdgPopup; View *m_parentView; QPoint m_offset; + qreal m_animationFactor; + QBasicTimer m_animationTimer; + bool m_animationCountUp; public slots: void onXdgSetMaximized(); @@ -88,6 +107,9 @@ public slots: void onXdgSetFullscreen(QWaylandOutput *output); void onXdgUnsetFullscreen(); void onOffsetForNextFrame(const QPoint &offset); + + void startAnimation(bool countUp); + void cancelAnimation(); }; class Compositor : public QWaylandCompositor @@ -96,7 +118,7 @@ class Compositor : public QWaylandCompositor public: Compositor(QWindow *window); ~Compositor(); - void create() Q_DECL_OVERRIDE; + void create() override; void startRender(); void endRender(); @@ -119,6 +141,9 @@ signals: void dragStarted(View *dragIcon); void frameOffset(const QPoint &offset); +public slots: + void triggerRender(); + private slots: void surfaceHasContentChanged(); void surfaceDestroyed(); @@ -129,7 +154,6 @@ private slots: void startDrag(); - void triggerRender(); void onSurfaceCreated(QWaylandSurface *surface); void onWlShellSurfaceCreated(QWaylandWlShellSurface *wlShellSurface); @@ -143,6 +167,7 @@ private slots: void onSubsurfacePositionChanged(const QPoint &position); void updateCursor(); + void viewAnimationDone(); private: View *findView(const QWaylandSurface *s) const; QWindow *m_window; diff --git a/examples/wayland/qwindow-compositor/window.cpp b/examples/wayland/qwindow-compositor/window.cpp index 59ef1d56a..fcb5fd474 100644 --- a/examples/wayland/qwindow-compositor/window.cpp +++ b/examples/wayland/qwindow-compositor/window.cpp @@ -129,18 +129,17 @@ void Window::paintGL() m_textureBlitter.bind(currentTarget); } QWaylandSurface *surface = view->surface(); - if (surface && surface->hasContent()) { - QSize s = surface->size(); + if ((surface && surface->hasContent()) || view->isBufferLocked()) { + QSize s = view->size(); if (!s.isEmpty()) { if (m_mouseView == view && m_grabState == ResizeGrab && m_resizeAnchored) view->setPosition(getAnchoredPosition(m_resizeAnchorPosition, m_resizeEdge, s)); QPointF pos = view->position() + view->parentPosition(); QRectF surfaceGeometry(pos, s); - QOpenGLTextureBlitter::Origin surfaceOrigin = - view->currentBuffer().origin() == QWaylandSurface::OriginTopLeft - ? QOpenGLTextureBlitter::OriginTopLeft - : QOpenGLTextureBlitter::OriginBottomLeft; - QMatrix4x4 targetTransform = QOpenGLTextureBlitter::targetTransform(surfaceGeometry, QRect(QPoint(), size())); + auto surfaceOrigin = view->textureOrigin(); + auto sf = view->animationFactor(); + QRectF targetRect(surfaceGeometry.topLeft() * sf, surfaceGeometry.size() * sf); + QMatrix4x4 targetTransform = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(), size())); m_textureBlitter.blit(texture->textureId(), targetTransform, surfaceOrigin); } } @@ -157,10 +156,8 @@ View *Window::viewAt(const QPointF &point) Q_FOREACH (View *view, m_compositor->views()) { if (view == m_dragIconView) continue; - QPointF topLeft = view->position(); - QWaylandSurface *surface = view->surface(); - QRectF geo(topLeft, surface->size()); - if (geo.contains(point)) + QRectF geom(view->position(), view->size()); + if (geom.contains(point)) ret = view; } return ret; diff --git a/examples/wayland/qwindow-compositor/window.h b/examples/wayland/qwindow-compositor/window.h index 53c85a6ef..4d8980f0c 100644 --- a/examples/wayland/qwindow-compositor/window.h +++ b/examples/wayland/qwindow-compositor/window.h @@ -59,15 +59,15 @@ public: void setCompositor(Compositor *comp); protected: - void initializeGL() Q_DECL_OVERRIDE; - void paintGL() Q_DECL_OVERRIDE; + void initializeGL() override; + void paintGL() override; - void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *e) override; + void mouseReleaseEvent(QMouseEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; - void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE; - void keyReleaseEvent(QKeyEvent *e) Q_DECL_OVERRIDE; + void keyPressEvent(QKeyEvent *e) override; + void keyReleaseEvent(QKeyEvent *e) override; private slots: void startMove(); diff --git a/examples/wayland/server-buffer/client/main.cpp b/examples/wayland/server-buffer/client/main.cpp index 1a2c447a7..bab4a942a 100644 --- a/examples/wayland/server-buffer/client/main.cpp +++ b/examples/wayland/server-buffer/client/main.cpp @@ -144,7 +144,7 @@ public slots: } protected: - void registry_global(uint32_t name, const QString &interface, uint32_t version) Q_DECL_OVERRIDE + void registry_global(uint32_t name, const QString &interface, uint32_t version) override { Q_UNUSED(version); if (interface == QStringLiteral("qt_share_buffer")) { @@ -152,7 +152,7 @@ protected: } } - void share_buffer_cross_buffer(struct ::qt_server_buffer *buffer) Q_DECL_OVERRIDE + void share_buffer_cross_buffer(struct ::qt_server_buffer *buffer) override { QtWaylandClient::QWaylandServerBuffer *serverBuffer = m_server_buffer_integration->serverBuffer(buffer); if (m_server_buffer_list.isEmpty()) { diff --git a/examples/wayland/server-buffer/compositor/main.cpp b/examples/wayland/server-buffer/compositor/main.cpp index 8c43ce5c5..9ac91244e 100644 --- a/examples/wayland/server-buffer/compositor/main.cpp +++ b/examples/wayland/server-buffer/compositor/main.cpp @@ -215,7 +215,7 @@ protected: connect(surface, &QWaylandSurface::hasContentChanged, this, &QmlCompositor::surfaceMapped); } - void share_buffer_bind_resource(Resource *resource) Q_DECL_OVERRIDE + void share_buffer_bind_resource(Resource *resource) override { if (m_server_buffer_32_bit) { struct ::wl_client *client = resource->handle->client; |