Merge lp:~dandrader/qtmir/coordinateTranslator into lp:qtmir
- coordinateTranslator
- Merge into trunk
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 |
Related bugs: |
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:
Description of the change
* Are there any related MPs required for this MP to build/function as expected? Please list.
https:/
* 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
Gerry Boland (gerboland) wrote : | # |
Unity8 CI Bot (unity8-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:472
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
- 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
Daniel d'Andrada (dandrader) wrote : | # |
On 13/04/2016 12:01, Gerry Boland wrote:
> qtmircoordinate
> we don't need "qtmir" in the filename.
removed the file prefix
Unity8 CI Bot (unity8-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:473
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Unity8 CI Bot (unity8-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:474
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Gerry Boland (gerboland) wrote : | # |
I dislike that it is MirSurface & MirSurfaceItem's responsibility to subscribe themselves to this CoordinateTrans
I also dislike that CoordinateTrans
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 CoordinateTrans
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 (CoordinateTran
+ CoordinateTrans
+ }
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 BlockingQueuedC
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 CoordinateTrans
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.
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.
Daniel d'Andrada (dandrader) wrote : | # |
On 14/04/2016 07:34, Gerry Boland wrote:
> + if (CoordinateTran
> + CoordinateTrans
> + }
> 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.
CoordinateTrans
It's created by MirServer here:
"""
override_
{
return std::make_
});
"""
CoordinateTrans
instance, if any.
How do you conciliate the Singleton pattern you expect with the way
things get created in MirServer?
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 BlockingQueuedC
You mean CoordinateTrans
Qt::BlockingQue
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 DisplayConfigur
ationPolicy 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 ProxySurfaceLis
tModel: :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:
:onSessionState Changed 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 FindQt5Platform
Support 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_
brokenFBOReadBa ck on various chipsets Gives for impressive improvements in QSGDefaultDista
nceFieldGlyphCa che::storeGlyph s
impressive = 788ms -> 6msCopied 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
-
MirSurfaceListM
odel: 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
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
Unity8 CI Bot (unity8-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:521
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
- 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.WindowSta ck 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 BlockingQueuedC
onnection, 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:
:CoordinateTran slator
Unmerged revisions
- 540. By Daniel d'Andrada
-
Implement mir::scene:
:CoordinateTran slator
Preview Diff
1 | === modified file 'src/modules/Unity/Application/mirsurface.cpp' | |||
2 | --- src/modules/Unity/Application/mirsurface.cpp 2016-05-25 13:54:52 +0000 | |||
3 | +++ src/modules/Unity/Application/mirsurface.cpp 2016-06-23 20:33:14 +0000 | |||
4 | @@ -23,6 +23,7 @@ | |||
5 | 23 | #include <debughelpers.h> | 23 | #include <debughelpers.h> |
6 | 24 | 24 | ||
7 | 25 | // mirserver | 25 | // mirserver |
8 | 26 | #include <coordinatetranslator.h> | ||
9 | 26 | #include <surfaceobserver.h> | 27 | #include <surfaceobserver.h> |
10 | 27 | #include "screen.h" | 28 | #include "screen.h" |
11 | 28 | 29 | ||
12 | @@ -244,6 +245,10 @@ | |||
13 | 244 | QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); | 245 | QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); |
14 | 245 | 246 | ||
15 | 246 | setCloseTimer(new Timer); | 247 | setCloseTimer(new Timer); |
16 | 248 | |||
17 | 249 | if (CoordinateTranslator::instance()) { | ||
18 | 250 | CoordinateTranslator::instance()->registerMirSurface(this, surface.get()); | ||
19 | 251 | } | ||
20 | 247 | } | 252 | } |
21 | 248 | 253 | ||
22 | 249 | MirSurface::~MirSurface() | 254 | MirSurface::~MirSurface() |
23 | @@ -252,6 +257,10 @@ | |||
24 | 252 | 257 | ||
25 | 253 | Q_ASSERT(m_views.isEmpty()); | 258 | Q_ASSERT(m_views.isEmpty()); |
26 | 254 | 259 | ||
27 | 260 | if (CoordinateTranslator::instance()) { | ||
28 | 261 | CoordinateTranslator::instance()->unregisterMirSurface(m_surface.get()); | ||
29 | 262 | } | ||
30 | 263 | |||
31 | 255 | QMutexLocker locker(&m_mutex); | 264 | QMutexLocker locker(&m_mutex); |
32 | 256 | m_surface->remove_observer(m_surfaceObserver); | 265 | m_surface->remove_observer(m_surfaceObserver); |
33 | 257 | 266 | ||
34 | 258 | 267 | ||
35 | === modified file 'src/modules/Unity/Application/mirsurfaceitem.cpp' | |||
36 | --- src/modules/Unity/Application/mirsurfaceitem.cpp 2016-05-24 20:13:10 +0000 | |||
37 | +++ src/modules/Unity/Application/mirsurfaceitem.cpp 2016-06-23 20:33:14 +0000 | |||
38 | @@ -27,6 +27,9 @@ | |||
39 | 27 | // common | 27 | // common |
40 | 28 | #include <debughelpers.h> | 28 | #include <debughelpers.h> |
41 | 29 | 29 | ||
42 | 30 | // mirserver | ||
43 | 31 | #include <coordinatetranslator.h> | ||
44 | 32 | |||
45 | 30 | // Qt | 33 | // Qt |
46 | 31 | #include <QDebug> | 34 | #include <QDebug> |
47 | 32 | #include <QGuiApplication> | 35 | #include <QGuiApplication> |
48 | @@ -641,6 +644,9 @@ | |||
49 | 641 | 644 | ||
50 | 642 | if (m_surface) { | 645 | if (m_surface) { |
51 | 643 | disconnect(m_surface, nullptr, this, nullptr); | 646 | disconnect(m_surface, nullptr, this, nullptr); |
52 | 647 | if (CoordinateTranslator::instance()) { | ||
53 | 648 | CoordinateTranslator::instance()->unregisterMirSurfaceItem(this, m_surface); | ||
54 | 649 | } | ||
55 | 644 | m_surface->unregisterView((qintptr)this); | 650 | m_surface->unregisterView((qintptr)this); |
56 | 645 | unsetCursor(); | 651 | unsetCursor(); |
57 | 646 | } | 652 | } |
58 | @@ -649,6 +655,7 @@ | |||
59 | 649 | 655 | ||
60 | 650 | if (m_surface) { | 656 | if (m_surface) { |
61 | 651 | m_surface->registerView((qintptr)this); | 657 | m_surface->registerView((qintptr)this); |
62 | 658 | updateCoordinateTranslatorRegistration(); | ||
63 | 652 | 659 | ||
64 | 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, |
65 | 654 | // schedules call to updatePaintNode() from the rendering thread | 661 | // schedules call to updatePaintNode() from the rendering thread |
66 | @@ -735,6 +742,21 @@ | |||
67 | 735 | } | 742 | } |
68 | 736 | } | 743 | } |
69 | 737 | 744 | ||
70 | 745 | void MirSurfaceItem::updateCoordinateTranslatorRegistration() | ||
71 | 746 | { | ||
72 | 747 | auto coordinateTranslator = CoordinateTranslator::instance(); | ||
73 | 748 | |||
74 | 749 | if (!surface() || !coordinateTranslator) { | ||
75 | 750 | return; | ||
76 | 751 | } | ||
77 | 752 | |||
78 | 753 | if (surfaceWidth() != -1 && surfaceHeight() != -1) { | ||
79 | 754 | coordinateTranslator->registerMirSurfaceItem(this, surface()); | ||
80 | 755 | } else { | ||
81 | 756 | coordinateTranslator->unregisterMirSurfaceItem(this, surface()); | ||
82 | 757 | } | ||
83 | 758 | } | ||
84 | 759 | |||
85 | 738 | int MirSurfaceItem::surfaceWidth() const | 760 | int MirSurfaceItem::surfaceWidth() const |
86 | 739 | { | 761 | { |
87 | 740 | return m_surfaceWidth; | 762 | return m_surfaceWidth; |
88 | @@ -746,6 +768,7 @@ | |||
89 | 746 | m_surfaceWidth = value; | 768 | m_surfaceWidth = value; |
90 | 747 | scheduleMirSurfaceSizeUpdate(); | 769 | scheduleMirSurfaceSizeUpdate(); |
91 | 748 | Q_EMIT surfaceWidthChanged(value); | 770 | Q_EMIT surfaceWidthChanged(value); |
92 | 771 | updateCoordinateTranslatorRegistration(); | ||
93 | 749 | } | 772 | } |
94 | 750 | } | 773 | } |
95 | 751 | 774 | ||
96 | @@ -765,6 +788,7 @@ | |||
97 | 765 | m_surfaceHeight = value; | 788 | m_surfaceHeight = value; |
98 | 766 | scheduleMirSurfaceSizeUpdate(); | 789 | scheduleMirSurfaceSizeUpdate(); |
99 | 767 | Q_EMIT surfaceHeightChanged(value); | 790 | Q_EMIT surfaceHeightChanged(value); |
100 | 791 | updateCoordinateTranslatorRegistration(); | ||
101 | 768 | } | 792 | } |
102 | 769 | } | 793 | } |
103 | 770 | 794 | ||
104 | @@ -781,6 +805,24 @@ | |||
105 | 781 | } | 805 | } |
106 | 782 | } | 806 | } |
107 | 783 | 807 | ||
108 | 808 | bool MirSurfaceItem::event(QEvent *ev) | ||
109 | 809 | { | ||
110 | 810 | if (ev->type() == PointMappingEvent::pointMappingEventType()) { | ||
111 | 811 | processPointMappingEvent(static_cast<PointMappingEvent*>(ev)); | ||
112 | 812 | return true; | ||
113 | 813 | } else { | ||
114 | 814 | return QQuickItem::event(ev); | ||
115 | 815 | } | ||
116 | 816 | } | ||
117 | 817 | |||
118 | 818 | void MirSurfaceItem::processPointMappingEvent(PointMappingEvent *event) | ||
119 | 819 | { | ||
120 | 820 | PointMappingQuery &query = event->query(); | ||
121 | 821 | |||
122 | 822 | query.screenPoint = mapToScene(query.localPoint); | ||
123 | 823 | query.semaphore.release(); | ||
124 | 824 | } | ||
125 | 825 | |||
126 | 784 | } // namespace qtmir | 826 | } // namespace qtmir |
127 | 785 | 827 | ||
128 | 786 | #include "mirsurfaceitem.moc" | 828 | #include "mirsurfaceitem.moc" |
129 | 787 | 829 | ||
130 | === modified file 'src/modules/Unity/Application/mirsurfaceitem.h' | |||
131 | --- src/modules/Unity/Application/mirsurfaceitem.h 2016-05-24 20:13:10 +0000 | |||
132 | +++ src/modules/Unity/Application/mirsurfaceitem.h 2016-06-23 20:33:14 +0000 | |||
133 | @@ -34,6 +34,7 @@ | |||
134 | 34 | class MirSurfaceManager; | 34 | class MirSurfaceManager; |
135 | 35 | class QSGMirSurfaceNode; | 35 | class QSGMirSurfaceNode; |
136 | 36 | class MirTextureProvider; | 36 | class MirTextureProvider; |
137 | 37 | class PointMappingEvent; | ||
138 | 37 | 38 | ||
139 | 38 | class MirSurfaceItem : public unity::shell::application::MirSurfaceItemInterface | 39 | class MirSurfaceItem : public unity::shell::application::MirSurfaceItemInterface |
140 | 39 | { | 40 | { |
141 | @@ -79,6 +80,10 @@ | |||
142 | 79 | QSGTextureProvider *textureProvider() const override; | 80 | QSGTextureProvider *textureProvider() const override; |
143 | 80 | 81 | ||
144 | 81 | //////// | 82 | //////// |
145 | 83 | // QObject | ||
146 | 84 | bool event(QEvent *e) override; | ||
147 | 85 | |||
148 | 86 | //////// | ||
149 | 82 | // own API | 87 | // own API |
150 | 83 | 88 | ||
151 | 84 | // to allow easy touch event injection from tests | 89 | // to allow easy touch event injection from tests |
152 | @@ -88,7 +93,6 @@ | |||
153 | 88 | const QList<QTouchEvent::TouchPoint> &touchPoints, | 93 | const QList<QTouchEvent::TouchPoint> &touchPoints, |
154 | 89 | Qt::TouchPointStates touchPointStates); | 94 | Qt::TouchPointStates touchPointStates); |
155 | 90 | 95 | ||
156 | 91 | |||
157 | 92 | public Q_SLOTS: | 96 | public Q_SLOTS: |
158 | 93 | // Called by QQuickWindow from the rendering thread | 97 | // Called by QQuickWindow from the rendering thread |
159 | 94 | void invalidateSceneGraph(); | 98 | void invalidateSceneGraph(); |
160 | @@ -139,6 +143,9 @@ | |||
161 | 139 | const QList<QTouchEvent::TouchPoint> &touchPoints, | 143 | const QList<QTouchEvent::TouchPoint> &touchPoints, |
162 | 140 | Qt::TouchPointStates touchPointStates); | 144 | Qt::TouchPointStates touchPointStates); |
163 | 141 | 145 | ||
164 | 146 | void processPointMappingEvent(PointMappingEvent *event); | ||
165 | 147 | void updateCoordinateTranslatorRegistration(); | ||
166 | 148 | |||
167 | 142 | MirSurfaceInterface* m_surface; | 149 | MirSurfaceInterface* m_surface; |
168 | 143 | QQuickWindow* m_window; | 150 | QQuickWindow* m_window; |
169 | 144 | 151 | ||
170 | 145 | 152 | ||
171 | === modified file 'src/platforms/mirserver/CMakeLists.txt' | |||
172 | --- src/platforms/mirserver/CMakeLists.txt 2016-06-14 08:33:55 +0000 | |||
173 | +++ src/platforms/mirserver/CMakeLists.txt 2016-06-23 20:33:14 +0000 | |||
174 | @@ -80,6 +80,7 @@ | |||
175 | 80 | clipboard.cpp | 80 | clipboard.cpp |
176 | 81 | creationhints.cpp | 81 | creationhints.cpp |
177 | 82 | tracepoints.c | 82 | tracepoints.c |
178 | 83 | coordinatetranslator.cpp | ||
179 | 83 | # We need to run moc on these headers | 84 | # We need to run moc on these headers |
180 | 84 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h | 85 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h |
181 | 85 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirMousePointerInterface.h | 86 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirMousePointerInterface.h |
182 | 86 | 87 | ||
183 | === added file 'src/platforms/mirserver/coordinatetranslator.cpp' | |||
184 | --- src/platforms/mirserver/coordinatetranslator.cpp 1970-01-01 00:00:00 +0000 | |||
185 | +++ src/platforms/mirserver/coordinatetranslator.cpp 2016-06-23 20:33:14 +0000 | |||
186 | @@ -0,0 +1,145 @@ | |||
187 | 1 | /* | ||
188 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
189 | 3 | * | ||
190 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
191 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
192 | 6 | * the Free Software Foundation. | ||
193 | 7 | * | ||
194 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
195 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
196 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
197 | 11 | * Lesser General Public License for more details. | ||
198 | 12 | * | ||
199 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
200 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
201 | 15 | */ | ||
202 | 16 | |||
203 | 17 | #include "coordinatetranslator.h" | ||
204 | 18 | |||
205 | 19 | #include <QCoreApplication> | ||
206 | 20 | #include <QDebug> | ||
207 | 21 | |||
208 | 22 | using namespace qtmir; | ||
209 | 23 | |||
210 | 24 | ////////////////// | ||
211 | 25 | // PointMappingQuery | ||
212 | 26 | |||
213 | 27 | PointMappingQuery::PointMappingQuery(int32_t localPointX, int32_t localPointY) | ||
214 | 28 | : localPoint(localPointX, localPointY) | ||
215 | 29 | { | ||
216 | 30 | } | ||
217 | 31 | |||
218 | 32 | ////////////////// | ||
219 | 33 | // PointMappingEvent | ||
220 | 34 | |||
221 | 35 | int PointMappingEvent::m_pointMappingEventType = 0; | ||
222 | 36 | |||
223 | 37 | QEvent::Type PointMappingEvent::pointMappingEventType() | ||
224 | 38 | { | ||
225 | 39 | if (!m_pointMappingEventType) { | ||
226 | 40 | m_pointMappingEventType = QEvent::registerEventType(); | ||
227 | 41 | } | ||
228 | 42 | return static_cast<QEvent::Type>(m_pointMappingEventType); | ||
229 | 43 | } | ||
230 | 44 | |||
231 | 45 | PointMappingEvent::PointMappingEvent(QSharedPointer<PointMappingQuery> query) | ||
232 | 46 | : QEvent(pointMappingEventType()) | ||
233 | 47 | { | ||
234 | 48 | m_query = query; | ||
235 | 49 | } | ||
236 | 50 | |||
237 | 51 | PointMappingQuery &PointMappingEvent::query() | ||
238 | 52 | { | ||
239 | 53 | return *m_query.data(); | ||
240 | 54 | } | ||
241 | 55 | |||
242 | 56 | ////////////////// | ||
243 | 57 | // CoordinateTranslator | ||
244 | 58 | |||
245 | 59 | CoordinateTranslator *CoordinateTranslator::m_instance = nullptr; | ||
246 | 60 | |||
247 | 61 | CoordinateTranslator::CoordinateTranslator() | ||
248 | 62 | { | ||
249 | 63 | Q_ASSERT(m_instance == nullptr); | ||
250 | 64 | m_instance = this; | ||
251 | 65 | } | ||
252 | 66 | |||
253 | 67 | CoordinateTranslator::~CoordinateTranslator() | ||
254 | 68 | { | ||
255 | 69 | Q_ASSERT(m_instance); | ||
256 | 70 | m_instance = nullptr; | ||
257 | 71 | } | ||
258 | 72 | |||
259 | 73 | CoordinateTranslator *CoordinateTranslator::instance() | ||
260 | 74 | { | ||
261 | 75 | return m_instance; | ||
262 | 76 | } | ||
263 | 77 | |||
264 | 78 | void CoordinateTranslator::registerMirSurfaceItem(QObject *item, unity::shell::application::MirSurfaceInterface* unitySurface) | ||
265 | 79 | { | ||
266 | 80 | QMutexLocker mutexLocker(&m_mutex); | ||
267 | 81 | m_unitySurfaceToItemHash[unitySurface] = item; | ||
268 | 82 | } | ||
269 | 83 | |||
270 | 84 | void CoordinateTranslator::unregisterMirSurfaceItem(QObject *item, unity::shell::application::MirSurfaceInterface* unitySurface) | ||
271 | 85 | { | ||
272 | 86 | QMutexLocker mutexLocker(&m_mutex); | ||
273 | 87 | if (m_unitySurfaceToItemHash.find(unitySurface) != m_unitySurfaceToItemHash.end() | ||
274 | 88 | && m_unitySurfaceToItemHash[unitySurface] == item) { | ||
275 | 89 | m_unitySurfaceToItemHash.remove(unitySurface); | ||
276 | 90 | } | ||
277 | 91 | } | ||
278 | 92 | |||
279 | 93 | void CoordinateTranslator::registerMirSurface(unity::shell::application::MirSurfaceInterface *unitySurface, | ||
280 | 94 | mir::frontend::Surface *mirSurface) | ||
281 | 95 | { | ||
282 | 96 | QMutexLocker mutexLocker(&m_mutex); | ||
283 | 97 | m_mirToUnitySurfaceHash[mirSurface] = unitySurface; | ||
284 | 98 | } | ||
285 | 99 | |||
286 | 100 | void CoordinateTranslator::unregisterMirSurface(mir::frontend::Surface *mirSurface) | ||
287 | 101 | { | ||
288 | 102 | QMutexLocker mutexLocker(&m_mutex); | ||
289 | 103 | m_mirToUnitySurfaceHash.remove(mirSurface); | ||
290 | 104 | } | ||
291 | 105 | |||
292 | 106 | mir::geometry::Point CoordinateTranslator::surface_to_screen(std::shared_ptr<mir::frontend::Surface> surface, | ||
293 | 107 | int32_t localX, int32_t localY) | ||
294 | 108 | { | ||
295 | 109 | QObject *item = nullptr; | ||
296 | 110 | mir::geometry::Point screenPoint; | ||
297 | 111 | |||
298 | 112 | { | ||
299 | 113 | QMutexLocker mutexLocker(&m_mutex); | ||
300 | 114 | |||
301 | 115 | unity::shell::application::MirSurfaceInterface *unitySurface = nullptr; | ||
302 | 116 | { | ||
303 | 117 | auto it = m_mirToUnitySurfaceHash.find(surface.get()); | ||
304 | 118 | if (it != m_mirToUnitySurfaceHash.end()) { | ||
305 | 119 | unitySurface = it.value(); | ||
306 | 120 | } | ||
307 | 121 | } | ||
308 | 122 | |||
309 | 123 | |||
310 | 124 | if (unitySurface) { | ||
311 | 125 | auto it = m_unitySurfaceToItemHash.find(unitySurface); | ||
312 | 126 | if (it != m_unitySurfaceToItemHash.end()) { | ||
313 | 127 | item = it.value(); | ||
314 | 128 | } | ||
315 | 129 | } | ||
316 | 130 | } | ||
317 | 131 | |||
318 | 132 | if (item) { | ||
319 | 133 | QSharedPointer<PointMappingQuery> query(new PointMappingQuery(localX, localY)); | ||
320 | 134 | PointMappingEvent *event = new PointMappingEvent(query); | ||
321 | 135 | QCoreApplication::postEvent(item, event); | ||
322 | 136 | query->semaphore.acquire(); | ||
323 | 137 | |||
324 | 138 | screenPoint.x = mir::geometry::X{query->screenPoint.x()}; | ||
325 | 139 | screenPoint.y = mir::geometry::Y{query->screenPoint.y()}; | ||
326 | 140 | } else { | ||
327 | 141 | qWarning() << "qtmir::CoordinateTranslator::mapToScreen - no MirSurfaceItem found for the given surface"; | ||
328 | 142 | } | ||
329 | 143 | |||
330 | 144 | return screenPoint; | ||
331 | 145 | } | ||
332 | 0 | 146 | ||
333 | === added file 'src/platforms/mirserver/coordinatetranslator.h' | |||
334 | --- src/platforms/mirserver/coordinatetranslator.h 1970-01-01 00:00:00 +0000 | |||
335 | +++ src/platforms/mirserver/coordinatetranslator.h 2016-06-23 20:33:14 +0000 | |||
336 | @@ -0,0 +1,84 @@ | |||
337 | 1 | /* | ||
338 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
339 | 3 | * | ||
340 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
341 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
342 | 6 | * the Free Software Foundation. | ||
343 | 7 | * | ||
344 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
345 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
346 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
347 | 11 | * Lesser General Public License for more details. | ||
348 | 12 | * | ||
349 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
350 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
351 | 15 | */ | ||
352 | 16 | |||
353 | 17 | #include <QEvent> | ||
354 | 18 | #include <QMutex> | ||
355 | 19 | #include <QMutexLocker> | ||
356 | 20 | #include <QPointF> | ||
357 | 21 | #include <QSemaphore> | ||
358 | 22 | #include <QSharedPointer> | ||
359 | 23 | |||
360 | 24 | #include <mir/scene/coordinate_translator.h> | ||
361 | 25 | |||
362 | 26 | namespace unity { | ||
363 | 27 | namespace shell { | ||
364 | 28 | namespace application { | ||
365 | 29 | class MirSurfaceInterface; | ||
366 | 30 | } | ||
367 | 31 | } | ||
368 | 32 | } | ||
369 | 33 | |||
370 | 34 | namespace qtmir { | ||
371 | 35 | |||
372 | 36 | class PointMappingQuery { | ||
373 | 37 | public: | ||
374 | 38 | PointMappingQuery(int32_t localPointX, int32_t localPointY); | ||
375 | 39 | QSemaphore semaphore; | ||
376 | 40 | QPointF localPoint; | ||
377 | 41 | QPointF screenPoint; | ||
378 | 42 | }; | ||
379 | 43 | |||
380 | 44 | class PointMappingEvent : public QEvent { | ||
381 | 45 | public: | ||
382 | 46 | static Type pointMappingEventType(); | ||
383 | 47 | PointMappingEvent(QSharedPointer<PointMappingQuery> query); | ||
384 | 48 | PointMappingQuery &query(); | ||
385 | 49 | private: | ||
386 | 50 | static int m_pointMappingEventType; | ||
387 | 51 | QSharedPointer<PointMappingQuery> m_query; | ||
388 | 52 | }; | ||
389 | 53 | |||
390 | 54 | /* | ||
391 | 55 | A mir::scene::CoordinateTranslator implementation for qtmir | ||
392 | 56 | |||
393 | 57 | Acts as a bridge between mir::scene::CoordinateTranslator::surface_to_screen() and | ||
394 | 58 | QQuickItem::mapToScene(). | ||
395 | 59 | */ | ||
396 | 60 | class CoordinateTranslator : public mir::scene::CoordinateTranslator | ||
397 | 61 | { | ||
398 | 62 | public: | ||
399 | 63 | CoordinateTranslator(); | ||
400 | 64 | virtual ~CoordinateTranslator(); | ||
401 | 65 | static CoordinateTranslator *instance(); | ||
402 | 66 | |||
403 | 67 | // Called from Qt's GUI thread | ||
404 | 68 | void registerMirSurfaceItem(QObject *item, unity::shell::application::MirSurfaceInterface *surface); | ||
405 | 69 | void unregisterMirSurfaceItem(QObject *item, unity::shell::application::MirSurfaceInterface *surface); | ||
406 | 70 | void registerMirSurface(unity::shell::application::MirSurfaceInterface *unitySurface, mir::frontend::Surface *mirSurface); | ||
407 | 71 | void unregisterMirSurface(mir::frontend::Surface *mirSurface); | ||
408 | 72 | |||
409 | 73 | // Called from some Mir thread | ||
410 | 74 | mir::geometry::Point surface_to_screen(std::shared_ptr<mir::frontend::Surface> surface, | ||
411 | 75 | int32_t x, int32_t y) override; | ||
412 | 76 | |||
413 | 77 | private: | ||
414 | 78 | QMutex m_mutex; | ||
415 | 79 | QHash<unity::shell::application::MirSurfaceInterface*, QObject*> m_unitySurfaceToItemHash; | ||
416 | 80 | QHash<mir::frontend::Surface*, unity::shell::application::MirSurfaceInterface*> m_mirToUnitySurfaceHash; | ||
417 | 81 | static CoordinateTranslator *m_instance; | ||
418 | 82 | }; | ||
419 | 83 | |||
420 | 84 | } // namespace qtmir | ||
421 | 0 | 85 | ||
422 | === modified file 'src/platforms/mirserver/mirserver.cpp' | |||
423 | --- src/platforms/mirserver/mirserver.cpp 2016-05-19 13:45:08 +0000 | |||
424 | +++ src/platforms/mirserver/mirserver.cpp 2016-06-23 20:33:14 +0000 | |||
425 | @@ -20,6 +20,7 @@ | |||
426 | 20 | 20 | ||
427 | 21 | // local | 21 | // local |
428 | 22 | #include "argvHelper.h" | 22 | #include "argvHelper.h" |
429 | 23 | #include "coordinatetranslator.h" | ||
430 | 23 | #include "mircursorimages.h" | 24 | #include "mircursorimages.h" |
431 | 24 | #include "mirdisplayconfigurationpolicy.h" | 25 | #include "mirdisplayconfigurationpolicy.h" |
432 | 25 | #include "mirglconfig.h" | 26 | #include "mirglconfig.h" |
433 | @@ -104,6 +105,11 @@ | |||
434 | 104 | return std::make_shared<MirGLConfig>(); | 105 | return std::make_shared<MirGLConfig>(); |
435 | 105 | }); | 106 | }); |
436 | 106 | 107 | ||
437 | 108 | override_the_coordinate_translator([] | ||
438 | 109 | { | ||
439 | 110 | return std::make_shared<qtmir::CoordinateTranslator>(); | ||
440 | 111 | }); | ||
441 | 112 | |||
442 | 107 | override_the_server_status_listener([] | 113 | override_the_server_status_listener([] |
443 | 108 | { | 114 | { |
444 | 109 | return std::make_shared<MirServerStatusListener>(); | 115 | return std::make_shared<MirServerStatusListener>(); |
445 | 110 | 116 | ||
446 | === modified file 'tests/mirserver/CMakeLists.txt' | |||
447 | --- tests/mirserver/CMakeLists.txt 2016-04-13 14:25:42 +0000 | |||
448 | +++ tests/mirserver/CMakeLists.txt 2016-06-23 20:33:14 +0000 | |||
449 | @@ -1,6 +1,7 @@ | |||
450 | 1 | add_subdirectory(ArgvHelper) | 1 | add_subdirectory(ArgvHelper) |
451 | 2 | add_subdirectory(Clipboard) | ||
452 | 3 | add_subdirectory(CoordinateTranslator) | ||
453 | 2 | add_subdirectory(QtEventFeeder) | 4 | add_subdirectory(QtEventFeeder) |
454 | 3 | add_subdirectory(Clipboard) | ||
455 | 4 | add_subdirectory(Screen) | 5 | add_subdirectory(Screen) |
456 | 5 | add_subdirectory(ScreensModel) | 6 | add_subdirectory(ScreensModel) |
457 | 6 | add_subdirectory(WindowManager) | 7 | add_subdirectory(WindowManager) |
458 | 7 | 8 | ||
459 | === added directory 'tests/mirserver/CoordinateTranslator' | |||
460 | === added file 'tests/mirserver/CoordinateTranslator/CMakeLists.txt' | |||
461 | --- tests/mirserver/CoordinateTranslator/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
462 | +++ tests/mirserver/CoordinateTranslator/CMakeLists.txt 2016-06-23 20:33:14 +0000 | |||
463 | @@ -0,0 +1,44 @@ | |||
464 | 1 | set( | ||
465 | 2 | COORDINATE_TRANSLATOR_TEST_SOURCES | ||
466 | 3 | coordinatetranslator_test.cpp | ||
467 | 4 | FakeMirSurfaceItem.cpp | ||
468 | 5 | ${CMAKE_SOURCE_DIR}/src/common/debughelpers.cpp | ||
469 | 6 | ${CMAKE_SOURCE_DIR}/src/modules/Unity/Application/mirsurfacelistmodel.cpp | ||
470 | 7 | # We need to run moc on these headers | ||
471 | 8 | ${CMAKE_SOURCE_DIR}/src/modules/Unity/Application/mirsurfaceinterface.h | ||
472 | 9 | ${CMAKE_SOURCE_DIR}/src/modules/Unity/Application/session_interface.h | ||
473 | 10 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h | ||
474 | 11 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h | ||
475 | 12 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h | ||
476 | 13 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirFocusControllerInterface.h | ||
477 | 14 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h | ||
478 | 15 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceItemInterface.h | ||
479 | 16 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h | ||
480 | 17 | # Feed the automoc monster | ||
481 | 18 | ) | ||
482 | 19 | |||
483 | 20 | include_directories( | ||
484 | 21 | ${CMAKE_SOURCE_DIR}/src/platforms/mirserver | ||
485 | 22 | ${CMAKE_SOURCE_DIR}/src/modules | ||
486 | 23 | ${CMAKE_SOURCE_DIR}/src/common | ||
487 | 24 | ${CMAKE_SOURCE_DIR}/tests/framework | ||
488 | 25 | ${MIRSERVER_INCLUDE_DIRS} | ||
489 | 26 | ) | ||
490 | 27 | |||
491 | 28 | add_executable(QtMirCoordinateTranslatorTest ${COORDINATE_TRANSLATOR_TEST_SOURCES}) | ||
492 | 29 | |||
493 | 30 | add_dependencies(QtMirCoordinateTranslatorTest qtmir-test-framework-static) | ||
494 | 31 | |||
495 | 32 | target_link_libraries( | ||
496 | 33 | QtMirCoordinateTranslatorTest | ||
497 | 34 | |||
498 | 35 | qpa-mirserver | ||
499 | 36 | |||
500 | 37 | -L${CMAKE_BINARY_DIR}/tests/framework | ||
501 | 38 | qtmir-test-framework-static | ||
502 | 39 | |||
503 | 40 | ${GTEST_BOTH_LIBRARIES} | ||
504 | 41 | ${GMOCK_LIBRARIES} | ||
505 | 42 | ) | ||
506 | 43 | |||
507 | 44 | add_test(QtMirCoordinateTranslator QtMirCoordinateTranslatorTest) | ||
508 | 0 | 45 | ||
509 | === added file 'tests/mirserver/CoordinateTranslator/FakeMirSurfaceItem.cpp' | |||
510 | --- tests/mirserver/CoordinateTranslator/FakeMirSurfaceItem.cpp 1970-01-01 00:00:00 +0000 | |||
511 | +++ tests/mirserver/CoordinateTranslator/FakeMirSurfaceItem.cpp 2016-06-23 20:33:14 +0000 | |||
512 | @@ -0,0 +1,40 @@ | |||
513 | 1 | /* | ||
514 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
515 | 3 | * | ||
516 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
517 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
518 | 6 | * the Free Software Foundation. | ||
519 | 7 | * | ||
520 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
521 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
522 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
523 | 11 | * Lesser General Public License for more details. | ||
524 | 12 | * | ||
525 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
526 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
527 | 15 | */ | ||
528 | 16 | |||
529 | 17 | #include "FakeMirSurfaceItem.h" | ||
530 | 18 | |||
531 | 19 | // mirserver | ||
532 | 20 | #include <coordinatetranslator.h> | ||
533 | 21 | |||
534 | 22 | using namespace qtmir; | ||
535 | 23 | |||
536 | 24 | bool FakeMirSurfaceItem::event(QEvent *ev) | ||
537 | 25 | { | ||
538 | 26 | if (ev->type() == PointMappingEvent::pointMappingEventType()) { | ||
539 | 27 | processPointMappingEvent(static_cast<PointMappingEvent*>(ev)); | ||
540 | 28 | return true; | ||
541 | 29 | } else { | ||
542 | 30 | return QObject::event(ev); | ||
543 | 31 | } | ||
544 | 32 | } | ||
545 | 33 | |||
546 | 34 | void FakeMirSurfaceItem::processPointMappingEvent(PointMappingEvent* event) | ||
547 | 35 | { | ||
548 | 36 | PointMappingQuery &query = event->query(); | ||
549 | 37 | |||
550 | 38 | query.screenPoint = query.localPoint * 2; | ||
551 | 39 | query.semaphore.release(); | ||
552 | 40 | } | ||
553 | 0 | 41 | ||
554 | === added file 'tests/mirserver/CoordinateTranslator/FakeMirSurfaceItem.h' | |||
555 | --- tests/mirserver/CoordinateTranslator/FakeMirSurfaceItem.h 1970-01-01 00:00:00 +0000 | |||
556 | +++ tests/mirserver/CoordinateTranslator/FakeMirSurfaceItem.h 2016-06-23 20:33:14 +0000 | |||
557 | @@ -0,0 +1,37 @@ | |||
558 | 1 | /* | ||
559 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
560 | 3 | * | ||
561 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
562 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
563 | 6 | * the Free Software Foundation. | ||
564 | 7 | * | ||
565 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
566 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
567 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
568 | 11 | * Lesser General Public License for more details. | ||
569 | 12 | * | ||
570 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
571 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
572 | 15 | */ | ||
573 | 16 | |||
574 | 17 | #ifndef FAKEMIRSURFACEITEM_H | ||
575 | 18 | #define FAKEMIRSURFACEITEM_H | ||
576 | 19 | |||
577 | 20 | #include <QObject> | ||
578 | 21 | |||
579 | 22 | namespace qtmir { | ||
580 | 23 | |||
581 | 24 | class PointMappingEvent; | ||
582 | 25 | |||
583 | 26 | class FakeMirSurfaceItem : public QObject | ||
584 | 27 | { | ||
585 | 28 | Q_OBJECT | ||
586 | 29 | public: | ||
587 | 30 | bool event(QEvent *e) override; | ||
588 | 31 | private: | ||
589 | 32 | void processPointMappingEvent(PointMappingEvent* event); | ||
590 | 33 | }; | ||
591 | 34 | |||
592 | 35 | } // namespace qtmir | ||
593 | 36 | |||
594 | 37 | #endif // FAKEMIRSURFACEITEM_H | ||
595 | 0 | 38 | ||
596 | === added file 'tests/mirserver/CoordinateTranslator/coordinatetranslator_test.cpp' | |||
597 | --- tests/mirserver/CoordinateTranslator/coordinatetranslator_test.cpp 1970-01-01 00:00:00 +0000 | |||
598 | +++ tests/mirserver/CoordinateTranslator/coordinatetranslator_test.cpp 2016-06-23 20:33:14 +0000 | |||
599 | @@ -0,0 +1,105 @@ | |||
600 | 1 | /* | ||
601 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
602 | 3 | * | ||
603 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
604 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
605 | 6 | * the Free Software Foundation. | ||
606 | 7 | * | ||
607 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
608 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
609 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
610 | 11 | * Lesser General Public License for more details. | ||
611 | 12 | * | ||
612 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
613 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
614 | 15 | */ | ||
615 | 16 | |||
616 | 17 | #include <gtest/gtest.h> | ||
617 | 18 | |||
618 | 19 | // mirserver | ||
619 | 20 | #include <coordinatetranslator.h> | ||
620 | 21 | |||
621 | 22 | // tests/framework | ||
622 | 23 | #include <fake_mirsurface.h> | ||
623 | 24 | #include <mock_surface.h> | ||
624 | 25 | |||
625 | 26 | // local | ||
626 | 27 | #include "FakeMirSurfaceItem.h" | ||
627 | 28 | |||
628 | 29 | // Qt | ||
629 | 30 | #include <QCoreApplication> | ||
630 | 31 | #include <QMutex> | ||
631 | 32 | #include <QThread> | ||
632 | 33 | #include <QWaitCondition> | ||
633 | 34 | |||
634 | 35 | using namespace qtmir; | ||
635 | 36 | |||
636 | 37 | class FakeQtGuiThread : public QThread | ||
637 | 38 | { | ||
638 | 39 | Q_OBJECT | ||
639 | 40 | |||
640 | 41 | public: | ||
641 | 42 | std::shared_ptr<mir::scene::MockSurface> mirSurface; | ||
642 | 43 | |||
643 | 44 | QMutex mutex; | ||
644 | 45 | QWaitCondition waitCondition; | ||
645 | 46 | |||
646 | 47 | protected: | ||
647 | 48 | void run() override | ||
648 | 49 | { | ||
649 | 50 | int argc = 0; | ||
650 | 51 | char* argv[0]; | ||
651 | 52 | QCoreApplication qtApp(argc, argv); | ||
652 | 53 | |||
653 | 54 | qtmir::FakeMirSurfaceItem surfaceItem; | ||
654 | 55 | qtmir::FakeMirSurface unitySurface; | ||
655 | 56 | |||
656 | 57 | CoordinateTranslator::instance()->registerMirSurface(&unitySurface, mirSurface.get()); | ||
657 | 58 | CoordinateTranslator::instance()->registerMirSurfaceItem(&surfaceItem, &unitySurface); | ||
658 | 59 | |||
659 | 60 | // sync-point | ||
660 | 61 | mutex.lock(); | ||
661 | 62 | mutex.unlock(); | ||
662 | 63 | waitCondition.wakeAll(); | ||
663 | 64 | |||
664 | 65 | qtApp.exec(); | ||
665 | 66 | } | ||
666 | 67 | }; | ||
667 | 68 | |||
668 | 69 | class QtMirCoordinateTranslatorTest : public ::testing::Test | ||
669 | 70 | { | ||
670 | 71 | public: | ||
671 | 72 | QtMirCoordinateTranslatorTest() | ||
672 | 73 | { | ||
673 | 74 | } | ||
674 | 75 | |||
675 | 76 | CoordinateTranslator coordinateTranslator; | ||
676 | 77 | }; | ||
677 | 78 | |||
678 | 79 | TEST_F(QtMirCoordinateTranslatorTest, surface_to_screen) | ||
679 | 80 | { | ||
680 | 81 | |||
681 | 82 | auto mirSurface = std::make_shared<mir::scene::MockSurface>(); | ||
682 | 83 | |||
683 | 84 | FakeQtGuiThread fakeQtGuiThread; | ||
684 | 85 | fakeQtGuiThread.mirSurface = mirSurface; | ||
685 | 86 | |||
686 | 87 | fakeQtGuiThread.mutex.lock(); | ||
687 | 88 | fakeQtGuiThread.start(); | ||
688 | 89 | |||
689 | 90 | // sync-point | ||
690 | 91 | fakeQtGuiThread.waitCondition.wait(&fakeQtGuiThread.mutex); | ||
691 | 92 | fakeQtGuiThread.mutex.unlock(); | ||
692 | 93 | |||
693 | 94 | // The tests's own thread acts as the Mir thread that calls surface_to_screen() | ||
694 | 95 | mir::geometry::Point screenPoint = coordinateTranslator.surface_to_screen(mirSurface, 10, 30); | ||
695 | 96 | |||
696 | 97 | // FakeMirSurfaceItem will just multiply each coordinate by 2 | ||
697 | 98 | EXPECT_EQ(screenPoint.x.as_int(), 10*2); | ||
698 | 99 | EXPECT_EQ(screenPoint.y.as_int(), 30*2); | ||
699 | 100 | |||
700 | 101 | QCoreApplication::instance()->quit(); | ||
701 | 102 | fakeQtGuiThread.wait(); | ||
702 | 103 | } | ||
703 | 104 | |||
704 | 105 | #include "coordinatetranslator_test.moc" |
qtmircoordinate translator. cpp
we don't need "qtmir" in the filename.