Merge lp:~dandrader/qtmir/coordinateTranslator into lp:qtmir

Proposed by Daniel d'Andrada
Status: Superseded
Proposed branch: lp:~dandrader/qtmir/coordinateTranslator
Merge into: lp:qtmir
Prerequisite: lp:~dandrader/qtmir/surfaceListModel
Diff against target: 704 lines (+523/-2)
12 files modified
src/modules/Unity/Application/mirsurface.cpp (+9/-0)
src/modules/Unity/Application/mirsurfaceitem.cpp (+42/-0)
src/modules/Unity/Application/mirsurfaceitem.h (+8/-1)
src/platforms/mirserver/CMakeLists.txt (+1/-0)
src/platforms/mirserver/coordinatetranslator.cpp (+145/-0)
src/platforms/mirserver/coordinatetranslator.h (+84/-0)
src/platforms/mirserver/mirserver.cpp (+6/-0)
tests/mirserver/CMakeLists.txt (+2/-1)
tests/mirserver/CoordinateTranslator/CMakeLists.txt (+44/-0)
tests/mirserver/CoordinateTranslator/FakeMirSurfaceItem.cpp (+40/-0)
tests/mirserver/CoordinateTranslator/FakeMirSurfaceItem.h (+37/-0)
tests/mirserver/CoordinateTranslator/coordinatetranslator_test.cpp (+105/-0)
To merge this branch: bzr merge lp:~dandrader/qtmir/coordinateTranslator
Reviewer Review Type Date Requested Status
Unity8 CI Bot (community) continuous-integration Approve
Gerry Boland (community) Needs Fixing
Review via email: mp+291768@code.launchpad.net

This proposal has been superseded by a proposal from 2016-06-23.

Commit message

Implement mir::scene::CoordinateTranslator

Description of the change

* Are there any related MPs required for this MP to build/function as expected? Please list.
https://code.launchpad.net/~gerboland/qtubuntu/enable-debug-mode/+merge/276293

* Did you perform an exploratory manual test run of your code change and any related functionality?
Yes. I used lp:~dandrader/+junk/getScreenPointMir for that.

* If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
Not applicable

To post a comment you must log in.
Revision history for this message
Gerry Boland (gerboland) wrote :

qtmircoordinatetranslator.cpp
we don't need "qtmir" in the filename.

Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
471. By Daniel d'Andrada

Logging of Qt's OpenGL debug messages now must be enabled via CMake option
Approved by: Gerry Boland

472. By Daniel d'Andrada

Application: improve debug logging

Minimize boilerplate in logging code, as well as standardise its format.
Approved by: Gerry Boland

473. By Daniel d'Andrada

Remove application screenshot provider

It's no longer needed now that QML provides a "item-snapshot" feature.

Besides, it has no purpose in a surface-based window management.
Approved by: Lukáš Tinkl, Gerry Boland

474. By Daniel d'Andrada

MirSurface: replace keymapLayout and keymapVariant with keymap

That's easier for unity8 to use, leads to declarative code.
Approved by: Lukáš Tinkl

475. By Daniel d'Andrada

Surface-based window management

- Session is no longer exported to QML. It's now an internal qtmir concept.
Approved by: Gerry Boland

476. By Michał Sawicz

Inline -gles packaging.
Approved by: Gerry Boland

477. By CI Train Bot Account

Releasing 0.4.8+16.04.20160413-0ubuntu1

Revision history for this message
Daniel d'Andrada (dandrader) wrote :

On 13/04/2016 12:01, Gerry Boland wrote:
> qtmircoordinatetranslator.cpp
> we don't need "qtmir" in the filename.

removed the file prefix

Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

I dislike that it is MirSurface & MirSurfaceItem's responsibility to subscribe themselves to this CoordinateTranslator. I would much prefer using the publish-subscribe model that Qt's signal/slots offer us, where MirSurface{,Item} would signal their creation, and CoordinateTranslator would operate on that.

I also dislike that CoordinateTranslator duplicates the list of MirSurfaces that SurfaceManager already has.

Why did you rule out this possibility: having the MirSurfaceItem position update the position of the corresponding mir::Surface in Mir's model? If Mir's model was roughly correct, we wouldn't need to replace the default CoordinateTranslator implementation. That option strikes me as simpler, with less code in qtmir, and less cross-thread synchronisation to deal with.

Also, I want to avoid us just replacing parts of Mir whenever we feel like it. I'd like you to try using Mir's CoordinateTransform implementation, and if it is unworkable, we should communicate why that is to the Mir team.

+ if (CoordinateTranslator::instance()) {
+ CoordinateTranslator::instance()->registerMirSurface(this, surface.get());
+ }
Why would there not be an instance returned? Having to check this every time is a pain. Singleton pattern requires instance() returns a valid object.

All the custom event stuff you've done is equivalent to a BlockingQueuedConnection afaics. Am curious why you avoided it.

review: Needs Fixing
Revision history for this message
Daniel d'Andrada (dandrader) wrote :

On 14/04/2016 07:34, Gerry Boland wrote:
> Why did you rule out this possibility: having the MirSurfaceItem position update the position of the corresponding mir::Surface in Mir's model? If Mir's model was roughly correct, we wouldn't need to replace the default CoordinateTranslator implementation. That option strikes me as simpler, with less code in qtmir, and less cross-thread synchronisation to deal with.

A QQuickItem has no knowledge of whether its transformation
(translation, rotation and scaling) relative to the root item has
changed. Nor it should as that would be pretty bad performance-wise
(imagine moving a parent would generate a deluge of signals to all the
children in its subtree). Trying to go that way would be a mistake in my
opinion.

Revision history for this message
Daniel d'Andrada (dandrader) wrote :

On 14/04/2016 07:34, Gerry Boland wrote:
> Also, I want to avoid us just replacing parts of Mir whenever we feel like it. I'd like you to try using Mir's CoordinateTransform implementation, and if it is unworkable, we should communicate why that is to the Mir team.

Mir's default CoordinateTransform is oblivious to our QML scene and
that's why it must be replaced in qtmir. And, as explained before,
having a QQuickItem aware of changes to its scene position (so it could
update its mir model counterpart) is not feasible.

The only way to have it working the way you want (QML keeping some mir
scene model in sync with it) is to have untiy8 QML code *explicitly*
calling scene sync functions at key moments. This is error prone and
clutters QML code and could easily impact performance negatively.

Revision history for this message
Daniel d'Andrada (dandrader) wrote :

On 14/04/2016 07:34, Gerry Boland wrote:
> + if (CoordinateTranslator::instance()) {
> + CoordinateTranslator::instance()->registerMirSurface(this, surface.get());
> + }
> Why would there not be an instance returned? Having to check this every time is a pain. Singleton pattern requires instance() returns a valid object.

CoordinateTranslator has no control over the creation of its instance.

It's created by MirServer here:

"""
     override_the_coordinate_translator([]
         {
             return std::make_shared<qtmir::CoordinateTranslator>();
         });
"""

CoordinateTranslator::instance() simply returns its single existing
instance, if any.

How do you conciliate the Singleton pattern you expect with the way
things get created in MirServer?

Revision history for this message
Daniel d'Andrada (dandrader) wrote :

On 14/04/2016 07:34, Gerry Boland wrote:
> All the custom event stuff you've done is equivalent to a BlockingQueuedConnection afaics. Am curious why you avoided it.

You mean CoordinateTranslator calling QMetaObject::invokeMethod([...],
Qt::BlockingQueuedConnection , [...]) on a MirSurfaceItem? Yeah, I think
it boils down to the same indeed. So here I am reinventing the wheel.

478. By Alberto Aguirre

Mir 0.22 compatibility
Approved by: Cemil Azizoglu, Kevin DuBois, Brandon Schaefer

479. By CI Train Bot Account

Releasing 0.4.8+16.04.20160426-0ubuntu1

480. By Michael Terry

Use latest UbuntuAppLaunch API which supports libertine apps.
Approved by: Nick Dedekind

481. By Lukáš Tinkl

Regression fix: restore window title handling Fixes: #1563522
Approved by: Nick Dedekind

482. By CI Train Bot Account

Releasing 0.4.8+16.04.20160428-0ubuntu1

483. By Gerry Boland

Enhance ScreenController & the DisplayConfigurationPolicy to implement dynamic grid units.

- Rename ScreenController to ScreenModel, as it just reflects current screen state, does not offer means to configure it
- ScreenController can update state of existing Screens, based on Mir DisplayConfiguration changes.
- Expand Screen to include scale & form factor properties, with getter/notifier in NativeInterface. This enables the dynamic grid units in the shell
- Add a Unity.Screens qml module to give QML better information about connected screens, and allow basic reconfiguring.
- Implement a basic display configuration policy to set suitable scale and form factor on an external display (needed for dynamic grid units) Fixes: #1573532
Approved by: Unity8 CI Bot, Daniel d'Andrada

484. By CI Train Bot Account

Releasing 0.4.8+16.04.20160429.1-0ubuntu1

485. By Daniel d'Andrada

Session: Add a blank surface to the public list if it already has child prompt surfaces

A prompt session may come in too early, before its parent session got a chance
to draw its surface's first frame.

Normally that wouldn't be a problem and we could withhold that parent surface until
it's finally drawn to. But unfortunately the application process might be blocked,
unable to draw anything, until its child prompt session gets dismissed.

Because of that we have no option but to expose this blank surface to shell so that
it can display it along with the prompt surface on top of it, so that the user can
interact with it right away and finally unblock the application. Fixes: #1578665
Approved by: Unity8 CI Bot

486. By CI Train Bot Account

Releasing 0.4.8+16.04.20160511-0ubuntu1

487. By Daniel d'Andrada

Fix ProxySurfaceListModel::countChanged signal
Approved by: Unity8 CI Bot

488. By Daniel d'Andrada

Move prompt surfaces from MirSurface to Application and emit firstChanged signal

489. By CI Train Bot Account

Releasing 0.4.8+16.04.20160518.1-0ubuntu1

490. By Gerry Boland

UAL can throw on creating Application if invalid appId, catch instead of aborting Fixes: #1578258
Approved by: Unity8 CI Bot, Michael Terry

491. By Daniel d'Andrada

Application: Don't respawn if closed while still starting up

+ refactoring of Application::onSessionStateChanged to explicitly cover every single internal state on session stopping. Fixes: #1575577
Approved by: Gerry Boland, Unity8 CI Bot, Michael Terry

492. By Alan Griffiths

Reduce coupling to MirServer - it has been misused as a context object.
Approved by: Alan Griffiths, Unity8 CI Bot, Daniel d'Andrada

493. By Michał Sawicz

Centralize logging categories

The header part is already centralized. Make the cpp the same.

Moves all logging category symbols to the mirserver lib.

Enables mirserver to use logging categories that were previously declared in the Unity.Application module.
Approved by: Unity8 CI Bot, Michael Terry

494. By Daniel d'Andrada

Also interpret the cursor names used by Mir client API Fixes: #1447839
Approved by: Unity8 CI Bot, Michał Sawicz

495. By Timo Jyrinki

Use FindQt5PlatformSupport to find platform support, other methods not available on Qt 5.6 anymore. Fixes: #1554404
Approved by: Gerry Boland

496. By CI Train Bot Account

Releasing 0.4.8+16.10.20160520.1-0ubuntu1

497. By Daniel d'Andrada

Bump unity-api versions
Approved by: Lukáš Tinkl

498. By Alan Griffiths

Drop the (unused) prototype Window Management code
Approved by: Gerry Boland, Unity8 CI Bot

499. By Daniel d'Andrada

Fix mir::scene::Surface focus attribute updates
Approved by: Unity8 CI Bot

500. By Albert Astals Cid

Enable workaround_brokenFBOReadBack on various chipsets

Gives for impressive improvements in QSGDefaultDistanceFieldGlyphCache::storeGlyphs
impressive = 788ms -> 6ms

Copied from qtubuntu
 Fixes: #1581123
Approved by: Gerry Boland, Unity8 CI Bot

501. By Alan Griffiths

Remove workaround for lp:1502200
Approved by: Unity8 CI Bot, Daniel d'Andrada

502. By CI Train Bot Account

Releasing 0.4.8+16.10.20160525.2-0ubuntu1

503. By Kevin DuBois

rebuild for mir 0.23

504. By CI Train Bot Account

Releasing 0.4.8+16.10.20160602-0ubuntu1

505. By Michael Zanetti

Adding ApplicationInfo::surfaceCount property

506. By Albert Astals Cid

Add support for compiler sanitizers via ECM

507. By Albert Astals Cid

Compile with -fsanitize=undefined

508. By Albert Astals Cid

Fix leak in ScreensModelTest (LP: #1585502)

509. By Albert Astals Cid

Fix leak in SessionManager test (LP: #1585498)

510. By Albert Astals Cid

Remove unused m_sessions member

511. By Albert Astals Cid

Add missing breaks

512. By Albert Astals Cid

Initialize m_lastX and m_lastY

513. By Albert Astals Cid

Initialize m_sessionId

514. By Albert Astals Cid

Give the locker a name

515. By Albert Astals Cid

Fix memory leak in QtEventFeederTest (LP: #1585503)

516. By Albert Astals Cid

Fix leaks in application_manager_test (LP: #1585501)

517. By Daniel d'Andrada

Improve Session debug logging

518. By Daniel d'Andrada

MirSurfaceListModel: prepending a surface always causes firstChanged() emission

519. By Gerry Boland

Release temporary GL context ASAP, fixes QtMir on X11. Add some hotpath branching hints (LP: #1588921)

520. By CI Train Bot Account

Releasing 0.4.8+16.10.20160614-0ubuntu1

Revision history for this message
Gerry Boland (gerboland) wrote :

Please merge trunk. I'll revisit this review, as this is needed, and I can't propose a better approach currently

review: Needs Fixing
Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:521
https://unity8-jenkins.ubuntu.com/job/lp-qtmir-ci/294/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/2139
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/2167
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2076
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2076
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2076
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=vivid+overlay/2067
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=vivid+overlay/2067/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2067
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2067/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=yakkety/2067
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=yakkety/2067/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=vivid+overlay/2067
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=vivid+overlay/2067/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2067
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2067/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=yakkety/2067
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=yakkety/2067/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=vivid+overlay/2067
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=vivid+overlay/2067/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/2067
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/2067/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=yakkety/2067
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=yakkety/2067/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-qtmir-ci/294/rebuild

review: Approve (continuous-integration)
521. By Daniel d'Andrada

com.canonical.Unity.FocusInfo D-Bus service for providing focus information

522. By CI Train Bot Account

Releasing 0.4.8+16.10.20160704.1-0ubuntu1

523. By Michał Sawicz

Don't use root dbus path (LP: #1599145)

524. By CI Train Bot Account

Releasing 0.4.8+16.10.20160705.2-0ubuntu1

525. By Łukasz Zemczak

Build the qtmir-android package for arm64 as well.

526. By CI Train Bot Account

Releasing 0.4.8+16.10.20160712-0ubuntu1

527. By Daniel d'Andrada

Implement MirSurface::inputBounds and make use of mir's input region

This allows us to finally drop the UbuntuKeyboardInfo hack.

Approved by: Gerry Boland

528. By CI Train Bot Account

Releasing 0.4.8+16.10.20160714-0ubuntu1

529. By Timo Jyrinki

Rebuild against Qt 5.6.

530. By Nick Dedekind

Re-added occlusion detection (LP: #1475678)

Approved by: Daniel d'Andrada

531. By CI Train Bot Account

* Add support for compiler sanitizers via ECM
* Compile with -fsanitize=undefined
* Fix leak in ScreensModelTest (LP: #1585502)
* Fix leak in SessionManager test (LP: #1585498)
* Remove unused m_sessions member
* Add missing breaks
* Initialize m_lastX and m_lastY
* Initialize m_sessionId
* Give the locker a name
* Fix memory leak in QtEventFeederTest (LP: #1585503)
* Fix leaks in application_manager_test (LP: #1585501)
* Improve Session debug logging
* MirSurfaceListModel: prepending a surface always causes
  firstChanged() emission
* Adding ApplicationInfo::surfaceCount property

532. By Daniel d'Andrada

Ensure different cursor names for consecutive custom cursor changes
(LP: #1604701) (LP: #1605078) (LP: #1604701, #1605078)

Approved by: Albert Astals Cid, Unity8 CI Bot

533. By Gerry Boland

Dump core if Mir fails to start in time - dump will help us see where Mir blocked (LP: #1537389)

Approved by: Daniel van Vugt, Unity8 CI Bot

534. By Marco Trevisan (Treviño)

ScreenWindow: handle window activated when exposing it

This will ensure that there's a focused window for the rendered application
(thus we can deliver keyboard events to it) (LP: #1590060)

Approved by: Gerry Boland, Unity8 CI Bot

535. By Albert Astals Cid

Fix memory leak in application_test

Approved by: Daniel d'Andrada, Unity8 CI Bot

536. By Gerry Boland

Tests: AppManTest: use stack instead of heap when possible, better cleanup of resources

Approved by: Andreas Pokorny, Daniel d'Andrada

537. By Daniel d'Andrada

Remove com.canonical.Unity.WindowStack D-Bus service

Nobody knows of anyone using it and the code is outdated
(pre surface-based WM era), so it doesn't even work correctly.

Therefore this is effectively dead code.

Approved by: Gerry Boland

538. By Gerry Boland

AppMan: queue the onProcessStarting slot, as processStarting blocks ubuntu-app-launch from executing the process.

The ProcessStarting signal is fired by a sync dbus call from upstart via ubuntu-app-launch. It is a sync call as AppMan needs to be informed of a new process, before that process can connect through Mir and be authenticated with authoriseSession (it was async before, but we had to make it sync to fix a bug where fast starting processes would connect to Mir before upstart's signal was received).

Instead of reacting immediately in the onProcessStarted - creating the Application & emitting signals to shell (which causes animations) -all blocking upstart launching the app, it is better to push an event onto the event queue and let upstart launch the app.

Note that authoriseSession is a slot connected to with a BlockingQueuedConnection, which also creates an event and pushes it to the event queue. As this will definitely happen after the processStarted signal, we are guaranteed that the slots will be called in the correct order.

This change improves app startup times on Krillin by around 100ms.

Approved by: Daniel d'Andrada

539. By CI Train Bot Account

Releasing 0.4.8+16.10.20160730-0ubuntu1

540. By Daniel d'Andrada

Implement mir::scene::CoordinateTranslator

Unmerged revisions

540. By Daniel d'Andrada

Implement mir::scene::CoordinateTranslator

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/modules/Unity/Application/mirsurface.cpp'
--- src/modules/Unity/Application/mirsurface.cpp 2016-05-25 13:54:52 +0000
+++ src/modules/Unity/Application/mirsurface.cpp 2016-06-23 20:33:14 +0000
@@ -23,6 +23,7 @@
23#include <debughelpers.h>23#include <debughelpers.h>
2424
25// mirserver25// mirserver
26#include <coordinatetranslator.h>
26#include <surfaceobserver.h>27#include <surfaceobserver.h>
27#include "screen.h"28#include "screen.h"
2829
@@ -244,6 +245,10 @@
244 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);245 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
245246
246 setCloseTimer(new Timer);247 setCloseTimer(new Timer);
248
249 if (CoordinateTranslator::instance()) {
250 CoordinateTranslator::instance()->registerMirSurface(this, surface.get());
251 }
247}252}
248253
249MirSurface::~MirSurface()254MirSurface::~MirSurface()
@@ -252,6 +257,10 @@
252257
253 Q_ASSERT(m_views.isEmpty());258 Q_ASSERT(m_views.isEmpty());
254259
260 if (CoordinateTranslator::instance()) {
261 CoordinateTranslator::instance()->unregisterMirSurface(m_surface.get());
262 }
263
255 QMutexLocker locker(&m_mutex);264 QMutexLocker locker(&m_mutex);
256 m_surface->remove_observer(m_surfaceObserver);265 m_surface->remove_observer(m_surfaceObserver);
257266
258267
=== modified file 'src/modules/Unity/Application/mirsurfaceitem.cpp'
--- src/modules/Unity/Application/mirsurfaceitem.cpp 2016-05-24 20:13:10 +0000
+++ src/modules/Unity/Application/mirsurfaceitem.cpp 2016-06-23 20:33:14 +0000
@@ -27,6 +27,9 @@
27// common27// common
28#include <debughelpers.h>28#include <debughelpers.h>
2929
30// mirserver
31#include <coordinatetranslator.h>
32
30// Qt33// Qt
31#include <QDebug>34#include <QDebug>
32#include <QGuiApplication>35#include <QGuiApplication>
@@ -641,6 +644,9 @@
641644
642 if (m_surface) {645 if (m_surface) {
643 disconnect(m_surface, nullptr, this, nullptr);646 disconnect(m_surface, nullptr, this, nullptr);
647 if (CoordinateTranslator::instance()) {
648 CoordinateTranslator::instance()->unregisterMirSurfaceItem(this, m_surface);
649 }
644 m_surface->unregisterView((qintptr)this);650 m_surface->unregisterView((qintptr)this);
645 unsetCursor();651 unsetCursor();
646 }652 }
@@ -649,6 +655,7 @@
649655
650 if (m_surface) {656 if (m_surface) {
651 m_surface->registerView((qintptr)this);657 m_surface->registerView((qintptr)this);
658 updateCoordinateTranslatorRegistration();
652659
653 // When a new mir frame gets posted we notify the QML engine that this item needs redrawing,660 // When a new mir frame gets posted we notify the QML engine that this item needs redrawing,
654 // schedules call to updatePaintNode() from the rendering thread661 // schedules call to updatePaintNode() from the rendering thread
@@ -735,6 +742,21 @@
735 }742 }
736}743}
737744
745void MirSurfaceItem::updateCoordinateTranslatorRegistration()
746{
747 auto coordinateTranslator = CoordinateTranslator::instance();
748
749 if (!surface() || !coordinateTranslator) {
750 return;
751 }
752
753 if (surfaceWidth() != -1 && surfaceHeight() != -1) {
754 coordinateTranslator->registerMirSurfaceItem(this, surface());
755 } else {
756 coordinateTranslator->unregisterMirSurfaceItem(this, surface());
757 }
758}
759
738int MirSurfaceItem::surfaceWidth() const760int MirSurfaceItem::surfaceWidth() const
739{761{
740 return m_surfaceWidth;762 return m_surfaceWidth;
@@ -746,6 +768,7 @@
746 m_surfaceWidth = value;768 m_surfaceWidth = value;
747 scheduleMirSurfaceSizeUpdate();769 scheduleMirSurfaceSizeUpdate();
748 Q_EMIT surfaceWidthChanged(value);770 Q_EMIT surfaceWidthChanged(value);
771 updateCoordinateTranslatorRegistration();
749 }772 }
750}773}
751774
@@ -765,6 +788,7 @@
765 m_surfaceHeight = value;788 m_surfaceHeight = value;
766 scheduleMirSurfaceSizeUpdate();789 scheduleMirSurfaceSizeUpdate();
767 Q_EMIT surfaceHeightChanged(value);790 Q_EMIT surfaceHeightChanged(value);
791 updateCoordinateTranslatorRegistration();
768 }792 }
769}793}
770794
@@ -781,6 +805,24 @@
781 }805 }
782}806}
783807
808bool MirSurfaceItem::event(QEvent *ev)
809{
810 if (ev->type() == PointMappingEvent::pointMappingEventType()) {
811 processPointMappingEvent(static_cast<PointMappingEvent*>(ev));
812 return true;
813 } else {
814 return QQuickItem::event(ev);
815 }
816}
817
818void MirSurfaceItem::processPointMappingEvent(PointMappingEvent *event)
819{
820 PointMappingQuery &query = event->query();
821
822 query.screenPoint = mapToScene(query.localPoint);
823 query.semaphore.release();
824}
825
784} // namespace qtmir826} // namespace qtmir
785827
786#include "mirsurfaceitem.moc"828#include "mirsurfaceitem.moc"
787829
=== modified file 'src/modules/Unity/Application/mirsurfaceitem.h'
--- src/modules/Unity/Application/mirsurfaceitem.h 2016-05-24 20:13:10 +0000
+++ src/modules/Unity/Application/mirsurfaceitem.h 2016-06-23 20:33:14 +0000
@@ -34,6 +34,7 @@
34class MirSurfaceManager;34class MirSurfaceManager;
35class QSGMirSurfaceNode;35class QSGMirSurfaceNode;
36class MirTextureProvider;36class MirTextureProvider;
37class PointMappingEvent;
3738
38class MirSurfaceItem : public unity::shell::application::MirSurfaceItemInterface39class MirSurfaceItem : public unity::shell::application::MirSurfaceItemInterface
39{40{
@@ -79,6 +80,10 @@
79 QSGTextureProvider *textureProvider() const override;80 QSGTextureProvider *textureProvider() const override;
8081
81 ////////82 ////////
83 // QObject
84 bool event(QEvent *e) override;
85
86 ////////
82 // own API87 // own API
8388
84 // to allow easy touch event injection from tests89 // to allow easy touch event injection from tests
@@ -88,7 +93,6 @@
88 const QList<QTouchEvent::TouchPoint> &touchPoints,93 const QList<QTouchEvent::TouchPoint> &touchPoints,
89 Qt::TouchPointStates touchPointStates);94 Qt::TouchPointStates touchPointStates);
9095
91
92public Q_SLOTS:96public Q_SLOTS:
93 // Called by QQuickWindow from the rendering thread97 // Called by QQuickWindow from the rendering thread
94 void invalidateSceneGraph();98 void invalidateSceneGraph();
@@ -139,6 +143,9 @@
139 const QList<QTouchEvent::TouchPoint> &touchPoints,143 const QList<QTouchEvent::TouchPoint> &touchPoints,
140 Qt::TouchPointStates touchPointStates);144 Qt::TouchPointStates touchPointStates);
141145
146 void processPointMappingEvent(PointMappingEvent *event);
147 void updateCoordinateTranslatorRegistration();
148
142 MirSurfaceInterface* m_surface;149 MirSurfaceInterface* m_surface;
143 QQuickWindow* m_window;150 QQuickWindow* m_window;
144151
145152
=== modified file 'src/platforms/mirserver/CMakeLists.txt'
--- src/platforms/mirserver/CMakeLists.txt 2016-06-14 08:33:55 +0000
+++ src/platforms/mirserver/CMakeLists.txt 2016-06-23 20:33:14 +0000
@@ -80,6 +80,7 @@
80 clipboard.cpp80 clipboard.cpp
81 creationhints.cpp81 creationhints.cpp
82 tracepoints.c82 tracepoints.c
83 coordinatetranslator.cpp
83# We need to run moc on these headers84# We need to run moc on these headers
84 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h85 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
85 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirMousePointerInterface.h86 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirMousePointerInterface.h
8687
=== added file 'src/platforms/mirserver/coordinatetranslator.cpp'
--- src/platforms/mirserver/coordinatetranslator.cpp 1970-01-01 00:00:00 +0000
+++ src/platforms/mirserver/coordinatetranslator.cpp 2016-06-23 20:33:14 +0000
@@ -0,0 +1,145 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "coordinatetranslator.h"
18
19#include <QCoreApplication>
20#include <QDebug>
21
22using namespace qtmir;
23
24//////////////////
25// PointMappingQuery
26
27PointMappingQuery::PointMappingQuery(int32_t localPointX, int32_t localPointY)
28 : localPoint(localPointX, localPointY)
29{
30}
31
32//////////////////
33// PointMappingEvent
34
35int PointMappingEvent::m_pointMappingEventType = 0;
36
37QEvent::Type PointMappingEvent::pointMappingEventType()
38{
39 if (!m_pointMappingEventType) {
40 m_pointMappingEventType = QEvent::registerEventType();
41 }
42 return static_cast<QEvent::Type>(m_pointMappingEventType);
43}
44
45PointMappingEvent::PointMappingEvent(QSharedPointer<PointMappingQuery> query)
46 : QEvent(pointMappingEventType())
47{
48 m_query = query;
49}
50
51PointMappingQuery &PointMappingEvent::query()
52{
53 return *m_query.data();
54}
55
56//////////////////
57// CoordinateTranslator
58
59CoordinateTranslator *CoordinateTranslator::m_instance = nullptr;
60
61CoordinateTranslator::CoordinateTranslator()
62{
63 Q_ASSERT(m_instance == nullptr);
64 m_instance = this;
65}
66
67CoordinateTranslator::~CoordinateTranslator()
68{
69 Q_ASSERT(m_instance);
70 m_instance = nullptr;
71}
72
73CoordinateTranslator *CoordinateTranslator::instance()
74{
75 return m_instance;
76}
77
78void CoordinateTranslator::registerMirSurfaceItem(QObject *item, unity::shell::application::MirSurfaceInterface* unitySurface)
79{
80 QMutexLocker mutexLocker(&m_mutex);
81 m_unitySurfaceToItemHash[unitySurface] = item;
82}
83
84void CoordinateTranslator::unregisterMirSurfaceItem(QObject *item, unity::shell::application::MirSurfaceInterface* unitySurface)
85{
86 QMutexLocker mutexLocker(&m_mutex);
87 if (m_unitySurfaceToItemHash.find(unitySurface) != m_unitySurfaceToItemHash.end()
88 && m_unitySurfaceToItemHash[unitySurface] == item) {
89 m_unitySurfaceToItemHash.remove(unitySurface);
90 }
91}
92
93void CoordinateTranslator::registerMirSurface(unity::shell::application::MirSurfaceInterface *unitySurface,
94 mir::frontend::Surface *mirSurface)
95{
96 QMutexLocker mutexLocker(&m_mutex);
97 m_mirToUnitySurfaceHash[mirSurface] = unitySurface;
98}
99
100void CoordinateTranslator::unregisterMirSurface(mir::frontend::Surface *mirSurface)
101{
102 QMutexLocker mutexLocker(&m_mutex);
103 m_mirToUnitySurfaceHash.remove(mirSurface);
104}
105
106mir::geometry::Point CoordinateTranslator::surface_to_screen(std::shared_ptr<mir::frontend::Surface> surface,
107 int32_t localX, int32_t localY)
108{
109 QObject *item = nullptr;
110 mir::geometry::Point screenPoint;
111
112 {
113 QMutexLocker mutexLocker(&m_mutex);
114
115 unity::shell::application::MirSurfaceInterface *unitySurface = nullptr;
116 {
117 auto it = m_mirToUnitySurfaceHash.find(surface.get());
118 if (it != m_mirToUnitySurfaceHash.end()) {
119 unitySurface = it.value();
120 }
121 }
122
123
124 if (unitySurface) {
125 auto it = m_unitySurfaceToItemHash.find(unitySurface);
126 if (it != m_unitySurfaceToItemHash.end()) {
127 item = it.value();
128 }
129 }
130 }
131
132 if (item) {
133 QSharedPointer<PointMappingQuery> query(new PointMappingQuery(localX, localY));
134 PointMappingEvent *event = new PointMappingEvent(query);
135 QCoreApplication::postEvent(item, event);
136 query->semaphore.acquire();
137
138 screenPoint.x = mir::geometry::X{query->screenPoint.x()};
139 screenPoint.y = mir::geometry::Y{query->screenPoint.y()};
140 } else {
141 qWarning() << "qtmir::CoordinateTranslator::mapToScreen - no MirSurfaceItem found for the given surface";
142 }
143
144 return screenPoint;
145}
0146
=== added file 'src/platforms/mirserver/coordinatetranslator.h'
--- src/platforms/mirserver/coordinatetranslator.h 1970-01-01 00:00:00 +0000
+++ src/platforms/mirserver/coordinatetranslator.h 2016-06-23 20:33:14 +0000
@@ -0,0 +1,84 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <QEvent>
18#include <QMutex>
19#include <QMutexLocker>
20#include <QPointF>
21#include <QSemaphore>
22#include <QSharedPointer>
23
24#include <mir/scene/coordinate_translator.h>
25
26namespace unity {
27 namespace shell {
28 namespace application {
29 class MirSurfaceInterface;
30 }
31 }
32}
33
34namespace qtmir {
35
36class PointMappingQuery {
37public:
38 PointMappingQuery(int32_t localPointX, int32_t localPointY);
39 QSemaphore semaphore;
40 QPointF localPoint;
41 QPointF screenPoint;
42};
43
44class PointMappingEvent : public QEvent {
45public:
46 static Type pointMappingEventType();
47 PointMappingEvent(QSharedPointer<PointMappingQuery> query);
48 PointMappingQuery &query();
49private:
50 static int m_pointMappingEventType;
51 QSharedPointer<PointMappingQuery> m_query;
52};
53
54/*
55 A mir::scene::CoordinateTranslator implementation for qtmir
56
57 Acts as a bridge between mir::scene::CoordinateTranslator::surface_to_screen() and
58 QQuickItem::mapToScene().
59 */
60class CoordinateTranslator : public mir::scene::CoordinateTranslator
61{
62public:
63 CoordinateTranslator();
64 virtual ~CoordinateTranslator();
65 static CoordinateTranslator *instance();
66
67 // Called from Qt's GUI thread
68 void registerMirSurfaceItem(QObject *item, unity::shell::application::MirSurfaceInterface *surface);
69 void unregisterMirSurfaceItem(QObject *item, unity::shell::application::MirSurfaceInterface *surface);
70 void registerMirSurface(unity::shell::application::MirSurfaceInterface *unitySurface, mir::frontend::Surface *mirSurface);
71 void unregisterMirSurface(mir::frontend::Surface *mirSurface);
72
73 // Called from some Mir thread
74 mir::geometry::Point surface_to_screen(std::shared_ptr<mir::frontend::Surface> surface,
75 int32_t x, int32_t y) override;
76
77private:
78 QMutex m_mutex;
79 QHash<unity::shell::application::MirSurfaceInterface*, QObject*> m_unitySurfaceToItemHash;
80 QHash<mir::frontend::Surface*, unity::shell::application::MirSurfaceInterface*> m_mirToUnitySurfaceHash;
81 static CoordinateTranslator *m_instance;
82};
83
84} // namespace qtmir
085
=== modified file 'src/platforms/mirserver/mirserver.cpp'
--- src/platforms/mirserver/mirserver.cpp 2016-05-19 13:45:08 +0000
+++ src/platforms/mirserver/mirserver.cpp 2016-06-23 20:33:14 +0000
@@ -20,6 +20,7 @@
2020
21// local21// local
22#include "argvHelper.h"22#include "argvHelper.h"
23#include "coordinatetranslator.h"
23#include "mircursorimages.h"24#include "mircursorimages.h"
24#include "mirdisplayconfigurationpolicy.h"25#include "mirdisplayconfigurationpolicy.h"
25#include "mirglconfig.h"26#include "mirglconfig.h"
@@ -104,6 +105,11 @@
104 return std::make_shared<MirGLConfig>();105 return std::make_shared<MirGLConfig>();
105 });106 });
106107
108 override_the_coordinate_translator([]
109 {
110 return std::make_shared<qtmir::CoordinateTranslator>();
111 });
112
107 override_the_server_status_listener([]113 override_the_server_status_listener([]
108 {114 {
109 return std::make_shared<MirServerStatusListener>();115 return std::make_shared<MirServerStatusListener>();
110116
=== modified file 'tests/mirserver/CMakeLists.txt'
--- tests/mirserver/CMakeLists.txt 2016-04-13 14:25:42 +0000
+++ tests/mirserver/CMakeLists.txt 2016-06-23 20:33:14 +0000
@@ -1,6 +1,7 @@
1add_subdirectory(ArgvHelper)1add_subdirectory(ArgvHelper)
2add_subdirectory(Clipboard)
3add_subdirectory(CoordinateTranslator)
2add_subdirectory(QtEventFeeder)4add_subdirectory(QtEventFeeder)
3add_subdirectory(Clipboard)
4add_subdirectory(Screen)5add_subdirectory(Screen)
5add_subdirectory(ScreensModel)6add_subdirectory(ScreensModel)
6add_subdirectory(WindowManager)7add_subdirectory(WindowManager)
78
=== added directory 'tests/mirserver/CoordinateTranslator'
=== added file 'tests/mirserver/CoordinateTranslator/CMakeLists.txt'
--- tests/mirserver/CoordinateTranslator/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/mirserver/CoordinateTranslator/CMakeLists.txt 2016-06-23 20:33:14 +0000
@@ -0,0 +1,44 @@
1set(
2 COORDINATE_TRANSLATOR_TEST_SOURCES
3 coordinatetranslator_test.cpp
4 FakeMirSurfaceItem.cpp
5 ${CMAKE_SOURCE_DIR}/src/common/debughelpers.cpp
6 ${CMAKE_SOURCE_DIR}/src/modules/Unity/Application/mirsurfacelistmodel.cpp
7# We need to run moc on these headers
8 ${CMAKE_SOURCE_DIR}/src/modules/Unity/Application/mirsurfaceinterface.h
9 ${CMAKE_SOURCE_DIR}/src/modules/Unity/Application/session_interface.h
10 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
11 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
12 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
13 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirFocusControllerInterface.h
14 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
15 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceItemInterface.h
16 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h
17# Feed the automoc monster
18)
19
20include_directories(
21 ${CMAKE_SOURCE_DIR}/src/platforms/mirserver
22 ${CMAKE_SOURCE_DIR}/src/modules
23 ${CMAKE_SOURCE_DIR}/src/common
24 ${CMAKE_SOURCE_DIR}/tests/framework
25 ${MIRSERVER_INCLUDE_DIRS}
26)
27
28add_executable(QtMirCoordinateTranslatorTest ${COORDINATE_TRANSLATOR_TEST_SOURCES})
29
30add_dependencies(QtMirCoordinateTranslatorTest qtmir-test-framework-static)
31
32target_link_libraries(
33 QtMirCoordinateTranslatorTest
34
35 qpa-mirserver
36
37 -L${CMAKE_BINARY_DIR}/tests/framework
38 qtmir-test-framework-static
39
40 ${GTEST_BOTH_LIBRARIES}
41 ${GMOCK_LIBRARIES}
42)
43
44add_test(QtMirCoordinateTranslator QtMirCoordinateTranslatorTest)
045
=== added file 'tests/mirserver/CoordinateTranslator/FakeMirSurfaceItem.cpp'
--- tests/mirserver/CoordinateTranslator/FakeMirSurfaceItem.cpp 1970-01-01 00:00:00 +0000
+++ tests/mirserver/CoordinateTranslator/FakeMirSurfaceItem.cpp 2016-06-23 20:33:14 +0000
@@ -0,0 +1,40 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "FakeMirSurfaceItem.h"
18
19// mirserver
20#include <coordinatetranslator.h>
21
22using namespace qtmir;
23
24bool FakeMirSurfaceItem::event(QEvent *ev)
25{
26 if (ev->type() == PointMappingEvent::pointMappingEventType()) {
27 processPointMappingEvent(static_cast<PointMappingEvent*>(ev));
28 return true;
29 } else {
30 return QObject::event(ev);
31 }
32}
33
34void FakeMirSurfaceItem::processPointMappingEvent(PointMappingEvent* event)
35{
36 PointMappingQuery &query = event->query();
37
38 query.screenPoint = query.localPoint * 2;
39 query.semaphore.release();
40}
041
=== added file 'tests/mirserver/CoordinateTranslator/FakeMirSurfaceItem.h'
--- tests/mirserver/CoordinateTranslator/FakeMirSurfaceItem.h 1970-01-01 00:00:00 +0000
+++ tests/mirserver/CoordinateTranslator/FakeMirSurfaceItem.h 2016-06-23 20:33:14 +0000
@@ -0,0 +1,37 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef FAKEMIRSURFACEITEM_H
18#define FAKEMIRSURFACEITEM_H
19
20#include <QObject>
21
22namespace qtmir {
23
24class PointMappingEvent;
25
26class FakeMirSurfaceItem : public QObject
27{
28 Q_OBJECT
29public:
30 bool event(QEvent *e) override;
31private:
32 void processPointMappingEvent(PointMappingEvent* event);
33};
34
35} // namespace qtmir
36
37#endif // FAKEMIRSURFACEITEM_H
038
=== added file 'tests/mirserver/CoordinateTranslator/coordinatetranslator_test.cpp'
--- tests/mirserver/CoordinateTranslator/coordinatetranslator_test.cpp 1970-01-01 00:00:00 +0000
+++ tests/mirserver/CoordinateTranslator/coordinatetranslator_test.cpp 2016-06-23 20:33:14 +0000
@@ -0,0 +1,105 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <gtest/gtest.h>
18
19// mirserver
20#include <coordinatetranslator.h>
21
22// tests/framework
23#include <fake_mirsurface.h>
24#include <mock_surface.h>
25
26// local
27#include "FakeMirSurfaceItem.h"
28
29// Qt
30#include <QCoreApplication>
31#include <QMutex>
32#include <QThread>
33#include <QWaitCondition>
34
35using namespace qtmir;
36
37class FakeQtGuiThread : public QThread
38{
39 Q_OBJECT
40
41public:
42 std::shared_ptr<mir::scene::MockSurface> mirSurface;
43
44 QMutex mutex;
45 QWaitCondition waitCondition;
46
47protected:
48 void run() override
49 {
50 int argc = 0;
51 char* argv[0];
52 QCoreApplication qtApp(argc, argv);
53
54 qtmir::FakeMirSurfaceItem surfaceItem;
55 qtmir::FakeMirSurface unitySurface;
56
57 CoordinateTranslator::instance()->registerMirSurface(&unitySurface, mirSurface.get());
58 CoordinateTranslator::instance()->registerMirSurfaceItem(&surfaceItem, &unitySurface);
59
60 // sync-point
61 mutex.lock();
62 mutex.unlock();
63 waitCondition.wakeAll();
64
65 qtApp.exec();
66 }
67};
68
69class QtMirCoordinateTranslatorTest : public ::testing::Test
70{
71public:
72 QtMirCoordinateTranslatorTest()
73 {
74 }
75
76 CoordinateTranslator coordinateTranslator;
77};
78
79TEST_F(QtMirCoordinateTranslatorTest, surface_to_screen)
80{
81
82 auto mirSurface = std::make_shared<mir::scene::MockSurface>();
83
84 FakeQtGuiThread fakeQtGuiThread;
85 fakeQtGuiThread.mirSurface = mirSurface;
86
87 fakeQtGuiThread.mutex.lock();
88 fakeQtGuiThread.start();
89
90 // sync-point
91 fakeQtGuiThread.waitCondition.wait(&fakeQtGuiThread.mutex);
92 fakeQtGuiThread.mutex.unlock();
93
94 // The tests's own thread acts as the Mir thread that calls surface_to_screen()
95 mir::geometry::Point screenPoint = coordinateTranslator.surface_to_screen(mirSurface, 10, 30);
96
97 // FakeMirSurfaceItem will just multiply each coordinate by 2
98 EXPECT_EQ(screenPoint.x.as_int(), 10*2);
99 EXPECT_EQ(screenPoint.y.as_int(), 30*2);
100
101 QCoreApplication::instance()->quit();
102 fakeQtGuiThread.wait();
103}
104
105#include "coordinatetranslator_test.moc"

Subscribers

People subscribed via source and target branches