summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/winrt/qwinrtwindow.cpp
diff options
context:
space:
mode:
authorAndrew Knight <andrew.knight@intopalo.com>2015-08-12 12:43:54 +0300
committerAndrew Knight <andrew.knight@intopalo.com>2015-08-13 16:12:37 +0000
commit807ec8ea48281d5dbe365895fd9679da5b6753a5 (patch)
treeb65ffb79da8e2941385b345dda7cc49f5638a0b0 /src/plugins/platforms/winrt/qwinrtwindow.cpp
parentebc2b963aa9e8ce2e983ef08c9b503ccc1702fdb (diff)
winrt: Refactor platform plugin for XAML support
By using XAML as the platform compositor, many benefits are possible: - Better input context handling for tablets - Better multiple window support (including non-fullscreen windows) - Support for transparent windows and window opacity - Integration with native platform controls - Simpler orientation handling on Windows Phone with built-in transitions This patch applies only the minimal parts to make XAML mode work just as the raw D3D mode. It does this by: - Moving all OpenGL parts into QWinRTEGLContext. This will allow us to have non-OpenGL windows later (e.g. Direct2D raster surfaces). - Moving more window-specific parts into QWinRTWindow. Each window creates a SwapChainPanel which can then be used for ANGLE (or Direct2D) content. - Moving non screen-specific parts into QWinRTIntegration. - Having QWinRTScreen create the base XAML element Canvas. - Running certain calls on the UI thread where necessary. The following code parts were removed: - The UIAutomationCore code in QWinRTInputContext, as this is incompatible with XAML automation. - The D3D Trim and device blacklist, as these have been fixed in ANGLE. - Core dispatcher processing in QEventDispatcherWinRT. Now there is only one native event dispatcher; it is always running and never needs to be pumped. Future commits should address: - Maintaining the window stack list and visibility using the XAML Canvas. - Allowing for windows (e.g. popups) to be sized and positioned instead of fullscreen. - Using the XAML automation API to improve the platform input context. [ChangeLog][QPA][winrt] Windows Store apps are now composited inside a XAML container, allowing for tighter integration with the native UI layer. Change-Id: I285c6dea657c5dab2fda2b1bd8e8e5dd15882c72 Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
Diffstat (limited to 'src/plugins/platforms/winrt/qwinrtwindow.cpp')
-rw-r--r--src/plugins/platforms/winrt/qwinrtwindow.cpp160
1 files changed, 133 insertions, 27 deletions
diff --git a/src/plugins/platforms/winrt/qwinrtwindow.cpp b/src/plugins/platforms/winrt/qwinrtwindow.cpp
index adc5dfb776..634d62ef24 100644
--- a/src/plugins/platforms/winrt/qwinrtwindow.cpp
+++ b/src/plugins/platforms/winrt/qwinrtwindow.cpp
@@ -36,47 +36,138 @@
#include "qwinrtwindow.h"
#include "qwinrtscreen.h"
+#include <private/qeventdispatcher_winrt_p.h>
-#include <qpa/qwindowsysteminterface.h>
+#include <EGL/egl.h>
+#define EGL_EGLEXT_PROTOTYPES
+#include <EGL/eglext.h>
+
+#include <qfunctions_winrt.h>
#include <qpa/qplatformscreen.h>
+#include <qpa/qwindowsysteminterface.h>
#include <QtGui/QGuiApplication>
-#include <QtGui/QWindow>
#include <QtGui/QOpenGLContext>
+#include <QtGui/QWindow>
+#include <QtPlatformSupport/private/qeglconvenience_p.h>
-#include <qfunctions_winrt.h>
-#include <windows.ui.viewmanagement.h>
+#include <functional>
#include <wrl.h>
+#include <windows.foundation.h>
+#include <windows.foundation.collections.h>
+#include <windows.ui.xaml.h>
+#include <windows.ui.xaml.controls.h>
+#include <windows.ui.viewmanagement.h>
using namespace ABI::Windows::UI::ViewManagement;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
+using namespace ABI::Windows::Foundation;
+using namespace ABI::Windows::Foundation::Collections;
+using namespace ABI::Windows::UI;
QT_BEGIN_NAMESPACE
+class QWinRTWindowPrivate
+{
+public:
+ QWinRTScreen *screen;
+
+ QSurfaceFormat surfaceFormat;
+ QString windowTitle;
+
+ ComPtr<Xaml::Controls::ISwapChainPanel> swapChainPanel;
+};
+
QWinRTWindow::QWinRTWindow(QWindow *window)
: QPlatformWindow(window)
- , m_screen(static_cast<QWinRTScreen*>(screen()))
+ , d_ptr(new QWinRTWindowPrivate)
{
+ Q_D(QWinRTWindow);
+
+ d->screen = static_cast<QWinRTScreen *>(screen());
setWindowFlags(window->flags());
setWindowState(window->windowState());
setWindowTitle(window->title());
handleContentOrientationChange(window->contentOrientation());
+
+ d->surfaceFormat.setAlphaBufferSize(0);
+ d->surfaceFormat.setRedBufferSize(8);
+ d->surfaceFormat.setGreenBufferSize(8);
+ d->surfaceFormat.setBlueBufferSize(8);
+ d->surfaceFormat.setDepthBufferSize(24);
+ d->surfaceFormat.setStencilBufferSize(8);
+ d->surfaceFormat.setRenderableType(QSurfaceFormat::OpenGLES);
+ d->surfaceFormat.setSamples(1);
+ d->surfaceFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
+
+ HRESULT hr;
+ hr = QEventDispatcherWinRT::runOnXamlThread([this, d]() {
+ // Create a new swapchain and place it inside the canvas
+ HRESULT hr;
+ hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_UI_Xaml_Controls_SwapChainPanel).Get(),
+ &d->swapChainPanel);
+ Q_ASSERT_SUCCEEDED(hr);
+ ComPtr<Xaml::IUIElement> uiElement;
+ hr = d->swapChainPanel.As(&uiElement);
+ Q_ASSERT_SUCCEEDED(hr);
+
+ ComPtr<Xaml::IDependencyObject> canvas = d->screen->canvas();
+ ComPtr<Xaml::Controls::IPanel> panel;
+ hr = canvas.As(&panel);
+ Q_ASSERT_SUCCEEDED(hr);
+ ComPtr<IVector<Xaml::UIElement *>> children;
+ hr = panel->get_Children(&children);
+ Q_ASSERT_SUCCEEDED(hr);
+ hr = children->Append(uiElement.Get());
+ Q_ASSERT_SUCCEEDED(hr);
+ return S_OK;
+ });
+ Q_ASSERT_SUCCEEDED(hr);
+
setGeometry(window->geometry());
}
QWinRTWindow::~QWinRTWindow()
{
- m_screen->removeWindow(window());
+ Q_D(QWinRTWindow);
+
+ HRESULT hr;
+ hr = QEventDispatcherWinRT::runOnXamlThread([d]() {
+ HRESULT hr;
+ ComPtr<Xaml::IDependencyObject> canvas = d->screen->canvas();
+ ComPtr<Xaml::Controls::IPanel> panel;
+ hr = canvas.As(&panel);
+ Q_ASSERT_SUCCEEDED(hr);
+ ComPtr<IVector<Xaml::UIElement *>> children;
+ hr = panel->get_Children(&children);
+ Q_ASSERT_SUCCEEDED(hr);
+
+ ComPtr<Xaml::IUIElement> uiElement;
+ hr = d->swapChainPanel.As(&uiElement);
+ Q_ASSERT_SUCCEEDED(hr);
+ quint32 index;
+ boolean found;
+ hr = children->IndexOf(uiElement.Get(), &index, &found);
+ Q_ASSERT_SUCCEEDED(hr);
+ if (found) {
+ hr = children->RemoveAt(index);
+ Q_ASSERT_SUCCEEDED(hr);
+ }
+ return S_OK;
+ });
+ RETURN_VOID_IF_FAILED("Failed to completely destroy window resources, likely because the application is shutting down");
}
QSurfaceFormat QWinRTWindow::format() const
{
- return m_screen->surfaceFormat();
+ Q_D(const QWinRTWindow);
+ return d->surfaceFormat;
}
bool QWinRTWindow::isActive() const
{
- return m_screen->topWindow() == window();
+ Q_D(const QWinRTWindow);
+ return d->screen->topWindow() == window();
}
bool QWinRTWindow::isExposed() const
@@ -87,55 +178,70 @@ bool QWinRTWindow::isExposed() const
void QWinRTWindow::setGeometry(const QRect &rect)
{
+ Q_D(QWinRTWindow);
+
if (window()->isTopLevel()) {
- QPlatformWindow::setGeometry(m_screen->geometry());
+ QPlatformWindow::setGeometry(d->screen->geometry());
QWindowSystemInterface::handleGeometryChange(window(), geometry());
} else {
QPlatformWindow::setGeometry(rect);
QWindowSystemInterface::handleGeometryChange(window(), rect);
}
+
+ HRESULT hr;
+ hr = QEventDispatcherWinRT::runOnXamlThread([this, d]() {
+ HRESULT hr;
+ ComPtr<Xaml::IFrameworkElement> frameworkElement;
+ hr = d->swapChainPanel.As(&frameworkElement);
+ Q_ASSERT_SUCCEEDED(hr);
+ const QSizeF size = QSizeF(geometry().size()) / d->screen->scaleFactor();
+ hr = frameworkElement->put_Width(size.width());
+ Q_ASSERT_SUCCEEDED(hr);
+ hr = frameworkElement->put_Height(size.height());
+ Q_ASSERT_SUCCEEDED(hr);
+ return S_OK;
+ });
+ Q_ASSERT_SUCCEEDED(hr);
}
void QWinRTWindow::setVisible(bool visible)
{
+ Q_D(QWinRTWindow);
if (!window()->isTopLevel())
return;
if (visible)
- m_screen->addWindow(window());
+ d->screen->addWindow(window());
else
- m_screen->removeWindow(window());
+ d->screen->removeWindow(window());
}
void QWinRTWindow::setWindowTitle(const QString &title)
{
- ComPtr<IApplicationViewStatics2> statics;
- HRESULT hr;
-
- hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_ViewManagement_ApplicationView).Get(),
- IID_PPV_ARGS(&statics));
- RETURN_VOID_IF_FAILED("Could not get ApplicationViewStatics");
-
- ComPtr<IApplicationView> view;
- hr = statics->GetForCurrentView(&view);
- RETURN_VOID_IF_FAILED("Could not access currentView");
-
- HStringReference str(reinterpret_cast<LPCWSTR>(title.utf16()), title.length());
- hr = view->put_Title(str.Get());
- RETURN_VOID_IF_FAILED("Unable to set window title");
+ Q_D(QWinRTWindow);
+ d->windowTitle = title;
+ d->screen->updateWindowTitle();
}
void QWinRTWindow::raise()
{
+ Q_D(QWinRTWindow);
if (!window()->isTopLevel())
return;
- m_screen->raise(window());
+ d->screen->raise(window());
}
void QWinRTWindow::lower()
{
+ Q_D(QWinRTWindow);
if (!window()->isTopLevel())
return;
- m_screen->lower(window());
+ d->screen->lower(window());
+}
+
+WId QWinRTWindow::winId() const
+{
+ Q_D(const QWinRTWindow);
+ return WId(d->swapChainPanel.Get());
}
qreal QWinRTWindow::devicePixelRatio() const