Fix DISABLE_QML behavior

This commit is contained in:
Brad Davis 2018-05-25 12:02:36 -07:00 committed by Bradley Austin Davis
parent 243bd5ea69
commit d6bcdcde3f
7 changed files with 73 additions and 18 deletions

View file

@ -4574,12 +4574,15 @@ void Application::idle() {
_lastTimeUpdated.start(); _lastTimeUpdated.start();
// If the offscreen Ui has something active that is NOT the root, then assume it has keyboard focus. // If the offscreen Ui has something active that is NOT the root, then assume it has keyboard focus.
if (_keyboardDeviceHasFocus && offscreenUi && offscreenUi->getWindow()->activeFocusItem() != offscreenUi->getRootItem()) { if (offscreenUi && offscreenUi->getWindow()) {
auto activeFocusItem = offscreenUi->getWindow()->activeFocusItem();
if (_keyboardDeviceHasFocus && activeFocusItem != offscreenUi->getRootItem()) {
_keyboardMouseDevice->pluginFocusOutEvent(); _keyboardMouseDevice->pluginFocusOutEvent();
_keyboardDeviceHasFocus = false; _keyboardDeviceHasFocus = false;
} else if (offscreenUi && offscreenUi->getWindow()->activeFocusItem() == offscreenUi->getRootItem()) { } else if (activeFocusItem == offscreenUi->getRootItem()) {
_keyboardDeviceHasFocus = true; _keyboardDeviceHasFocus = true;
} }
}
checkChangeCursor(); checkChangeCursor();

View file

@ -99,7 +99,7 @@ QPointF OffscreenSurface::mapToVirtualScreen(const QPointF& originalPoint) {
// //
bool OffscreenSurface::filterEnabled(QObject* originalDestination, QEvent* event) const { bool OffscreenSurface::filterEnabled(QObject* originalDestination, QEvent* event) const {
if (!_sharedObject || _sharedObject->getWindow() == originalDestination) { if (!_sharedObject || !_sharedObject->getWindow() || _sharedObject->getWindow() == originalDestination) {
return false; return false;
} }
// Only intercept events while we're in an active state // Only intercept events while we're in an active state

View file

@ -8,6 +8,8 @@
#include "RenderEventHandler.h" #include "RenderEventHandler.h"
#ifndef DISABLE_QML
#include <gl/Config.h> #include <gl/Config.h>
#include <gl/QOpenGLContextWrapper.h> #include <gl/QOpenGLContextWrapper.h>
@ -165,3 +167,4 @@ void RenderEventHandler::onQuit() {
moveToThread(qApp->thread()); moveToThread(qApp->thread());
QThread::currentThread()->quit(); QThread::currentThread()->quit();
} }
#endif

View file

@ -7,6 +7,8 @@
// //
#pragma once #pragma once
#ifndef DISABLE_QML
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QThread> #include <QtCore/QThread>
#include <QtGui/qevent.h> #include <QtGui/qevent.h>
@ -54,3 +56,5 @@ private:
}; };
}}} // namespace hifi::qml::impl }}} // namespace hifi::qml::impl
#endif

View file

@ -55,6 +55,8 @@ QOpenGLContext* SharedObject::getSharedContext() {
} }
SharedObject::SharedObject() { SharedObject::SharedObject() {
#ifndef DISABLE_QML
// Create render control // Create render control
_renderControl = new RenderControl(); _renderControl = new RenderControl();
@ -68,6 +70,7 @@ SharedObject::SharedObject() {
_quickWindow->setColor(QColor(255, 255, 255, 0)); _quickWindow->setColor(QColor(255, 255, 255, 0));
_quickWindow->setClearBeforeRendering(true); _quickWindow->setClearBeforeRendering(true);
#endif
QObject::connect(qApp, &QCoreApplication::aboutToQuit, this, &SharedObject::onAboutToQuit); QObject::connect(qApp, &QCoreApplication::aboutToQuit, this, &SharedObject::onAboutToQuit);
} }
@ -78,7 +81,7 @@ SharedObject::~SharedObject() {
destroy(); destroy();
// _renderTimer is created with `this` as the parent, so need no explicit destruction // _renderTimer is created with `this` as the parent, so need no explicit destruction
#ifndef DISABLE_QML
// Destroy the event hand // Destroy the event hand
if (_renderObject) { if (_renderObject) {
delete _renderObject; delete _renderObject;
@ -89,18 +92,20 @@ SharedObject::~SharedObject() {
delete _renderControl; delete _renderControl;
_renderControl = nullptr; _renderControl = nullptr;
} }
#endif
if (_rootItem) { if (_rootItem) {
delete _rootItem; delete _rootItem;
_rootItem = nullptr; _rootItem = nullptr;
} }
#ifndef DISABLE_QML
if (_quickWindow) { if (_quickWindow) {
_quickWindow->destroy(); _quickWindow->destroy();
delete _quickWindow; delete _quickWindow;
_quickWindow = nullptr; _quickWindow = nullptr;
} }
#endif
if (_qmlContext) { if (_qmlContext) {
auto engine = _qmlContext->engine(); auto engine = _qmlContext->engine();
delete _qmlContext; delete _qmlContext;
@ -114,7 +119,9 @@ void SharedObject::create(OffscreenSurface* surface) {
qFatal("QML surface root item already set"); qFatal("QML surface root item already set");
} }
#ifndef DISABLE_QML
QObject::connect(_quickWindow, &QQuickWindow::focusObjectChanged, surface, &OffscreenSurface::onFocusObjectChanged); QObject::connect(_quickWindow, &QQuickWindow::focusObjectChanged, surface, &OffscreenSurface::onFocusObjectChanged);
#endif
// Create a QML engine. // Create a QML engine.
auto qmlEngine = acquireEngine(surface); auto qmlEngine = acquireEngine(surface);
@ -125,10 +132,12 @@ void SharedObject::create(OffscreenSurface* surface) {
surface->onRootContextCreated(_qmlContext); surface->onRootContextCreated(_qmlContext);
emit surface->rootContextCreated(_qmlContext); emit surface->rootContextCreated(_qmlContext);
#ifndef DISABLE_QML
if (!qmlEngine->incubationController()) { if (!qmlEngine->incubationController()) {
qmlEngine->setIncubationController(_quickWindow->incubationController()); qmlEngine->setIncubationController(_quickWindow->incubationController());
} }
_qmlContext->setContextProperty("offscreenWindow", QVariant::fromValue(_quickWindow)); _qmlContext->setContextProperty("offscreenWindow", QVariant::fromValue(_quickWindow));
#endif
} }
void SharedObject::setRootItem(QQuickItem* rootItem) { void SharedObject::setRootItem(QQuickItem* rootItem) {
@ -137,6 +146,7 @@ void SharedObject::setRootItem(QQuickItem* rootItem) {
} }
_rootItem = rootItem; _rootItem = rootItem;
#ifndef DISABLE_QML
_rootItem->setSize(_quickWindow->size()); _rootItem->setSize(_quickWindow->size());
// Create the render thread // Create the render thread
@ -150,6 +160,8 @@ void SharedObject::setRootItem(QQuickItem* rootItem) {
QObject::connect(_renderControl, &QQuickRenderControl::renderRequested, this, &SharedObject::requestRender); QObject::connect(_renderControl, &QQuickRenderControl::renderRequested, this, &SharedObject::requestRender);
QObject::connect(_renderControl, &QQuickRenderControl::sceneChanged, this, &SharedObject::requestRenderSync); QObject::connect(_renderControl, &QQuickRenderControl::sceneChanged, this, &SharedObject::requestRenderSync);
#endif
} }
void SharedObject::destroy() { void SharedObject::destroy() {
@ -163,6 +175,7 @@ void SharedObject::destroy() {
} }
_paused = true; _paused = true;
#ifndef DISABLE_QML
if (_renderTimer) { if (_renderTimer) {
_renderTimer->stop(); _renderTimer->stop();
QObject::disconnect(_renderTimer); QObject::disconnect(_renderTimer);
@ -171,9 +184,11 @@ void SharedObject::destroy() {
if (_renderControl) { if (_renderControl) {
QObject::disconnect(_renderControl); QObject::disconnect(_renderControl);
} }
#endif
QObject::disconnect(qApp); QObject::disconnect(qApp);
#ifndef DISABLE_QML
{ {
QMutexLocker lock(&_mutex); QMutexLocker lock(&_mutex);
_quit = true; _quit = true;
@ -190,6 +205,7 @@ void SharedObject::destroy() {
delete _renderThread; delete _renderThread;
_renderThread = nullptr; _renderThread = nullptr;
} }
#endif
} }
@ -240,6 +256,7 @@ void SharedObject::releaseEngine(QQmlEngine* engine) {
} }
bool SharedObject::event(QEvent* e) { bool SharedObject::event(QEvent* e) {
#ifndef DISABLE_QML
switch (static_cast<OffscreenEvent::Type>(e->type())) { switch (static_cast<OffscreenEvent::Type>(e->type())) {
case OffscreenEvent::Initialize: case OffscreenEvent::Initialize:
onInitialize(); onInitialize();
@ -252,6 +269,7 @@ bool SharedObject::event(QEvent* e) {
default: default:
break; break;
} }
#endif
return QObject::event(e); return QObject::event(e);
} }
@ -261,22 +279,28 @@ void SharedObject::initializeRenderControl(QOpenGLContext* context) {
qFatal("QML rendering context has no share context"); qFatal("QML rendering context has no share context");
} }
#ifndef DISABLE_QML
if (!nsightActive()) { if (!nsightActive()) {
_renderControl->initialize(context); _renderControl->initialize(context);
} }
#endif
} }
void SharedObject::releaseTextureAndFence() { void SharedObject::releaseTextureAndFence() {
#ifndef DISABLE_QML
QMutexLocker lock(&_mutex); QMutexLocker lock(&_mutex);
// If the most recent texture was unused, we can directly recycle it // If the most recent texture was unused, we can directly recycle it
if (_latestTextureAndFence.first) { if (_latestTextureAndFence.first) {
getTextureCache().releaseTexture(_latestTextureAndFence); getTextureCache().releaseTexture(_latestTextureAndFence);
_latestTextureAndFence = TextureAndFence{ 0, 0 }; _latestTextureAndFence = TextureAndFence{ 0, 0 };
} }
#endif
} }
void SharedObject::setRenderTarget(uint32_t fbo, const QSize& size) { void SharedObject::setRenderTarget(uint32_t fbo, const QSize& size) {
#ifndef DISABLE_QML
_quickWindow->setRenderTarget(fbo, size); _quickWindow->setRenderTarget(fbo, size);
#endif
} }
QSize SharedObject::getSize() const { QSize SharedObject::getSize() const {
@ -295,6 +319,7 @@ void SharedObject::setSize(const QSize& size) {
} }
qCDebug(qmlLogging) << "Offscreen UI resizing to " << size.width() << "x" << size.height(); qCDebug(qmlLogging) << "Offscreen UI resizing to " << size.width() << "x" << size.height();
#ifndef DISABLE_QML
_quickWindow->setGeometry(QRect(QPoint(), size)); _quickWindow->setGeometry(QRect(QPoint(), size));
_quickWindow->contentItem()->setSize(size); _quickWindow->contentItem()->setSize(size);
@ -304,9 +329,11 @@ void SharedObject::setSize(const QSize& size) {
} }
requestRenderSync(); requestRenderSync();
#endif
} }
bool SharedObject::preRender() { bool SharedObject::preRender() {
#ifndef DISABLE_QML
QMutexLocker lock(&_mutex); QMutexLocker lock(&_mutex);
if (_paused) { if (_paused) {
if (_syncRequested) { if (_syncRequested) {
@ -327,6 +354,7 @@ bool SharedObject::preRender() {
} }
_syncRequested = false; _syncRequested = false;
} }
#endif
return true; return true;
} }
@ -339,8 +367,10 @@ void SharedObject::shutdownRendering(OffscreenGLCanvas& canvas, const QSize& siz
getTextureCache().releaseTexture(_latestTextureAndFence); getTextureCache().releaseTexture(_latestTextureAndFence);
} }
} }
#ifndef DISABLE_QML
_renderControl->invalidate(); _renderControl->invalidate();
canvas.doneCurrent(); canvas.doneCurrent();
#endif
wake(); wake();
} }
@ -381,8 +411,10 @@ bool SharedObject::fetchTexture(TextureAndFence& textureAndFence) {
} }
void SharedObject::setProxyWindow(QWindow* window) { void SharedObject::setProxyWindow(QWindow* window) {
#ifndef DISABLE_QML
_proxyWindow = window; _proxyWindow = window;
_renderControl->setRenderWindow(window); _renderControl->setRenderWindow(window);
#endif
} }
void SharedObject::wait() { void SharedObject::wait() {
@ -394,6 +426,7 @@ void SharedObject::wake() {
} }
void SharedObject::onInitialize() { void SharedObject::onInitialize() {
#ifndef DISABLE_QML
// Associate root item with the window. // Associate root item with the window.
_rootItem->setParentItem(_quickWindow->contentItem()); _rootItem->setParentItem(_quickWindow->contentItem());
_renderControl->prepareThread(_renderThread); _renderControl->prepareThread(_renderThread);
@ -410,9 +443,11 @@ void SharedObject::onInitialize() {
_renderTimer->setTimerType(Qt::PreciseTimer); _renderTimer->setTimerType(Qt::PreciseTimer);
_renderTimer->setInterval(MIN_TIMER_MS); // 5ms, Qt::PreciseTimer required _renderTimer->setInterval(MIN_TIMER_MS); // 5ms, Qt::PreciseTimer required
_renderTimer->start(); _renderTimer->start();
#endif
} }
void SharedObject::onRender() { void SharedObject::onRender() {
#ifndef DISABLE_QML
PROFILE_RANGE(render_qml, __FUNCTION__); PROFILE_RANGE(render_qml, __FUNCTION__);
if (_quit) { if (_quit) {
return; return;
@ -430,6 +465,7 @@ void SharedObject::onRender() {
QCoreApplication::postEvent(_renderObject, new OffscreenEvent(OffscreenEvent::Render)); QCoreApplication::postEvent(_renderObject, new OffscreenEvent(OffscreenEvent::Render));
} }
_renderRequested = false; _renderRequested = false;
#endif
} }
void SharedObject::onTimer() { void SharedObject::onTimer() {
@ -455,7 +491,9 @@ void SharedObject::onTimer() {
} }
} }
#ifndef DISABLE_QML
QCoreApplication::postEvent(this, new OffscreenEvent(OffscreenEvent::Render)); QCoreApplication::postEvent(this, new OffscreenEvent(OffscreenEvent::Render));
#endif
} }
void SharedObject::onAboutToQuit() { void SharedObject::onAboutToQuit() {

View file

@ -93,17 +93,21 @@ private:
// Texture management // Texture management
TextureAndFence _latestTextureAndFence{ 0, 0 }; TextureAndFence _latestTextureAndFence{ 0, 0 };
RenderControl* _renderControl{ nullptr };
RenderEventHandler* _renderObject{ nullptr };
QQuickWindow* _quickWindow{ nullptr };
QWindow* _proxyWindow{ nullptr };
QQuickItem* _item{ nullptr }; QQuickItem* _item{ nullptr };
QQuickItem* _rootItem{ nullptr }; QQuickItem* _rootItem{ nullptr };
QQuickWindow* _quickWindow{ nullptr };
QQmlContext* _qmlContext{ nullptr }; QQmlContext* _qmlContext{ nullptr };
mutable QMutex _mutex;
QWaitCondition _cond;
#ifndef DISABLE_QML
QWindow* _proxyWindow{ nullptr };
RenderControl* _renderControl{ nullptr };
RenderEventHandler* _renderObject{ nullptr };
QTimer* _renderTimer{ nullptr }; QTimer* _renderTimer{ nullptr };
QThread* _renderThread{ nullptr }; QThread* _renderThread{ nullptr };
QWaitCondition _cond; #endif
mutable QMutex _mutex;
uint64_t _lastRenderTime{ 0 }; uint64_t _lastRenderTime{ 0 };
QSize _size{ 100, 100 }; QSize _size{ 100, 100 };

View file

@ -96,11 +96,14 @@ static OffscreenFlags* offscreenFlags { nullptr };
// so I think it's OK for the time being. // so I think it's OK for the time being.
bool OffscreenUi::shouldSwallowShortcut(QEvent* event) { bool OffscreenUi::shouldSwallowShortcut(QEvent* event) {
Q_ASSERT(event->type() == QEvent::ShortcutOverride); Q_ASSERT(event->type() == QEvent::ShortcutOverride);
auto window = getWindow();
if (window) {
QObject* focusObject = getWindow()->focusObject(); QObject* focusObject = getWindow()->focusObject();
if (focusObject != getWindow() && focusObject != getRootItem()) { if (focusObject != getWindow() && focusObject != getRootItem()) {
event->accept(); event->accept();
return true; return true;
} }
}
return false; return false;
} }