Fixing menu items in display plugins

This commit is contained in:
Brad Davis 2015-12-03 16:42:17 -08:00
parent 7262a10e62
commit 60aa93c38c
16 changed files with 120 additions and 97 deletions

View file

@ -4777,19 +4777,18 @@ void Application::updateDisplayMode() {
return; return;
} }
if (!_currentDisplayPluginActions.isEmpty()) {
if (!_pluginContainer->currentDisplayActions().isEmpty()) {
auto menu = Menu::getInstance(); auto menu = Menu::getInstance();
foreach(auto itemInfo, _currentDisplayPluginActions) { foreach(auto itemInfo, _pluginContainer->currentDisplayActions()) {
menu->removeMenuItem(itemInfo.first, itemInfo.second); menu->removeMenuItem(itemInfo.first, itemInfo.second);
} }
_currentDisplayPluginActions.clear(); _pluginContainer->currentDisplayActions().clear();
} }
if (newDisplayPlugin) { if (newDisplayPlugin) {
_offscreenContext->makeCurrent(); _offscreenContext->makeCurrent();
_activatingDisplayPlugin = true;
newDisplayPlugin->activate(); newDisplayPlugin->activate();
_activatingDisplayPlugin = false;
_offscreenContext->makeCurrent(); _offscreenContext->makeCurrent();
offscreenUi->resize(fromGlm(newDisplayPlugin->getRecommendedUiSize())); offscreenUi->resize(fromGlm(newDisplayPlugin->getRecommendedUiSize()));
_offscreenContext->makeCurrent(); _offscreenContext->makeCurrent();

View file

@ -427,8 +427,6 @@ private:
InputPluginList _activeInputPlugins; InputPluginList _activeInputPlugins;
bool _activatingDisplayPlugin { false }; bool _activatingDisplayPlugin { false };
QVector<QPair<QString, QString>> _currentDisplayPluginActions;
QVector<QPair<QString, QString>> _currentInputPluginActions;
QMap<uint32_t, gpu::FramebufferPointer> _lockedFramebufferMap; QMap<uint32_t, gpu::FramebufferPointer> _lockedFramebufferMap;
MainWindow* _window; MainWindow* _window;

View file

@ -36,37 +36,31 @@ void PluginContainerProxy::removeMenu(const QString& menuName) {
Menu::getInstance()->removeMenu(menuName); Menu::getInstance()->removeMenu(menuName);
} }
extern bool _activatingDisplayPlugin; QAction* PluginContainerProxy::addMenuItem(PluginType type, const QString& path, const QString& name, std::function<void(bool)> onClicked, bool checkable, bool checked, const QString& groupName) {
extern QVector<QPair<QString, QString>> _currentDisplayPluginActions; auto menu = Menu::getInstance();
extern QVector<QPair<QString, QString>> _currentInputPluginActions; MenuWrapper* parentItem = menu->getMenu(path);
std::map<QString, QActionGroup*> _exclusiveGroups; QAction* action = menu->addActionToQMenuAndActionHash(parentItem, name);
if (!groupName.isEmpty()) {
QAction* PluginContainerProxy::addMenuItem(const QString& path, const QString& name, std::function<void(bool)> onClicked, bool checkable, bool checked, const QString& groupName) { QActionGroup* group{ nullptr };
//auto menu = Menu::getInstance(); if (!_exclusiveGroups.count(groupName)) {
//MenuWrapper* parentItem = menu->getMenu(path); group = _exclusiveGroups[groupName] = new QActionGroup(menu);
//QAction* action = menu->addActionToQMenuAndActionHash(parentItem, name); group->setExclusive(true);
//if (!groupName.isEmpty()) { } else {
// QActionGroup* group{ nullptr }; group = _exclusiveGroups[groupName];
// if (!_exclusiveGroups.count(groupName)) { }
// group = _exclusiveGroups[groupName] = new QActionGroup(menu); group->addAction(action);
// group->setExclusive(true); }
// } else { connect(action, &QAction::triggered, [=] {
// group = _exclusiveGroups[groupName]; onClicked(action->isChecked());
// } });
// group->addAction(action); action->setCheckable(checkable);
//} action->setChecked(checked);
//connect(action, &QAction::triggered, [=] { if (type == PluginType::DISPLAY_PLUGIN) {
// onClicked(action->isChecked()); _currentDisplayPluginActions.push_back({ path, name });
//}); } else {
//action->setCheckable(checkable); _currentInputPluginActions.push_back({ path, name });
//action->setChecked(checked); }
//if (_activatingDisplayPlugin) { return action;
// _currentDisplayPluginActions.push_back({ path, name });
//} else {
// _currentInputPluginActions.push_back({ path, name });
//}
//return action;
return nullptr;
} }
void PluginContainerProxy::removeMenuItem(const QString& menuName, const QString& menuItem) { void PluginContainerProxy::removeMenuItem(const QString& menuName, const QString& menuItem) {
@ -188,5 +182,13 @@ void PluginContainerProxy::releaseSceneTexture(uint32_t texture) {
} }
void PluginContainerProxy::releaseOverlayTexture(uint32_t texture) { void PluginContainerProxy::releaseOverlayTexture(uint32_t texture) {
// FIXME implement present thread compositing
}
QVector<QPair<QString, QString>>& PluginContainerProxy::currentDisplayActions() {
return _currentDisplayPluginActions;
}
QVector<QPair<QString, QString>>& PluginContainerProxy::currentInputActions() {
return _currentInputPluginActions;
} }

View file

@ -2,19 +2,23 @@
#ifndef hifi_PluginContainerProxy_h #ifndef hifi_PluginContainerProxy_h
#define hifi_PluginContainerProxy_h #define hifi_PluginContainerProxy_h
#include <QObject> #include <QtCore/QObject>
#include <QRect> #include <QtCore/QRect>
#include <plugins/Forward.h> #include <plugins/Forward.h>
#include <plugins/PluginContainer.h> #include <plugins/PluginContainer.h>
class QActionGroup;
class PluginContainerProxy : public QObject, PluginContainer { class PluginContainerProxy : public QObject, PluginContainer {
Q_OBJECT Q_OBJECT
PluginContainerProxy(); PluginContainerProxy();
virtual ~PluginContainerProxy(); virtual ~PluginContainerProxy();
virtual QVector<QPair<QString, QString>>& currentDisplayActions() override;
virtual QVector<QPair<QString, QString>>& currentInputActions() override;
virtual void addMenu(const QString& menuName) override; virtual void addMenu(const QString& menuName) override;
virtual void removeMenu(const QString& menuName) override; virtual void removeMenu(const QString& menuName) override;
virtual QAction* addMenuItem(const QString& path, const QString& name, std::function<void(bool)> onClicked, bool checkable = false, bool checked = false, const QString& groupName = "") override; virtual QAction* addMenuItem(PluginType type, const QString& path, const QString& name, std::function<void(bool)> onClicked, bool checkable = false, bool checked = false, const QString& groupName = "") override;
virtual void removeMenuItem(const QString& menuName, const QString& menuItem) override; virtual void removeMenuItem(const QString& menuName, const QString& menuItem) override;
virtual bool isOptionChecked(const QString& name) override; virtual bool isOptionChecked(const QString& name) override;
virtual void setIsOptionChecked(const QString& path, bool checked) override; virtual void setIsOptionChecked(const QString& path, bool checked) override;
@ -32,8 +36,12 @@ class PluginContainerProxy : public QObject, PluginContainer {
virtual const DisplayPlugin* getActiveDisplayPlugin() const override; virtual const DisplayPlugin* getActiveDisplayPlugin() const override;
QRect _savedGeometry{ 10, 120, 800, 600 }; QRect _savedGeometry{ 10, 120, 800, 600 };
std::map<QString, QActionGroup*> _exclusiveGroups;
QVector<QPair<QString, QString>> _currentDisplayPluginActions;
QVector<QPair<QString, QString>> _currentInputPluginActions;
friend class Application; friend class Application;
}; };
#endif #endif

View file

@ -31,60 +31,59 @@ const QString& Basic2DWindowOpenGLDisplayPlugin::getName() const {
} }
void Basic2DWindowOpenGLDisplayPlugin::activate() { void Basic2DWindowOpenGLDisplayPlugin::activate() {
//_framerateActions.clear();
//_container->addMenuItem(MENU_PATH(), FULLSCREEN,
// [this](bool clicked) {
// if (clicked) {
// _container->setFullscreen(getFullscreenTarget());
// } else {
// _container->unsetFullscreen();
// }
// }, true, false);
//_container->addMenu(FRAMERATE);
//_framerateActions.push_back(
// _container->addMenuItem(FRAMERATE, FRAMERATE_UNLIMITED,
// [this](bool) { updateFramerate(); }, true, true, FRAMERATE));
//_framerateActions.push_back(
// _container->addMenuItem(FRAMERATE, FRAMERATE_60,
// [this](bool) { updateFramerate(); }, true, false, FRAMERATE));
//_framerateActions.push_back(
// _container->addMenuItem(FRAMERATE, FRAMERATE_50,
// [this](bool) { updateFramerate(); }, true, false, FRAMERATE));
//_framerateActions.push_back(
// _container->addMenuItem(FRAMERATE, FRAMERATE_40,
// [this](bool) { updateFramerate(); }, true, false, FRAMERATE));
//_framerateActions.push_back(
// _container->addMenuItem(FRAMERATE, FRAMERATE_30,
// [this](bool) { updateFramerate(); }, true, false, FRAMERATE));
WindowOpenGLDisplayPlugin::activate(); WindowOpenGLDisplayPlugin::activate();
//// Vsync detection happens in the parent class activate, so we need to check after that _framerateActions.clear();
//if (_vsyncSupported) { _container->addMenuItem(PluginType::DISPLAY_PLUGIN, MENU_PATH(), FULLSCREEN,
// _vsyncAction = _container->addMenuItem(MENU_PATH(), VSYNC_ON, [this](bool) {}, true, true); [this](bool clicked) {
//} else { if (clicked) {
// _vsyncAction = nullptr; _container->setFullscreen(getFullscreenTarget());
//} } else {
_container->unsetFullscreen();
}
}, true, false);
_container->addMenu(FRAMERATE);
_framerateActions.push_back(
_container->addMenuItem(PluginType::DISPLAY_PLUGIN, FRAMERATE, FRAMERATE_UNLIMITED,
[this](bool) { updateFramerate(); }, true, true, FRAMERATE));
_framerateActions.push_back(
_container->addMenuItem(PluginType::DISPLAY_PLUGIN, FRAMERATE, FRAMERATE_60,
[this](bool) { updateFramerate(); }, true, false, FRAMERATE));
_framerateActions.push_back(
_container->addMenuItem(PluginType::DISPLAY_PLUGIN, FRAMERATE, FRAMERATE_50,
[this](bool) { updateFramerate(); }, true, false, FRAMERATE));
_framerateActions.push_back(
_container->addMenuItem(PluginType::DISPLAY_PLUGIN, FRAMERATE, FRAMERATE_40,
[this](bool) { updateFramerate(); }, true, false, FRAMERATE));
_framerateActions.push_back(
_container->addMenuItem(PluginType::DISPLAY_PLUGIN, FRAMERATE, FRAMERATE_30,
[this](bool) { updateFramerate(); }, true, false, FRAMERATE));
// Vsync detection happens in the parent class activate, so we need to check after that
if (_vsyncSupported) {
_vsyncAction = _container->addMenuItem(PluginType::DISPLAY_PLUGIN, MENU_PATH(), VSYNC_ON, [this](bool) {}, true, true);
} else {
_vsyncAction = nullptr;
}
updateFramerate(); updateFramerate();
} }
void Basic2DWindowOpenGLDisplayPlugin::deactivate() {
WindowOpenGLDisplayPlugin::deactivate();
}
void Basic2DWindowOpenGLDisplayPlugin::submitSceneTexture(uint32_t frameIndex, uint32_t sceneTexture, const glm::uvec2& sceneSize) { void Basic2DWindowOpenGLDisplayPlugin::submitSceneTexture(uint32_t frameIndex, uint32_t sceneTexture, const glm::uvec2& sceneSize) {
if (_vsyncAction) { if (_vsyncAction) {
_wantVsync = _vsyncAction->isChecked(); _wantVsync = _vsyncAction->isChecked();
//bool vsyncEnabed = isVsyncEnabled();
//if (vsyncEnabed ^ wantVsync) {
// enableVsync(wantVsync);
//}
} }
WindowOpenGLDisplayPlugin::submitSceneTexture(frameIndex, sceneTexture, sceneSize); WindowOpenGLDisplayPlugin::submitSceneTexture(frameIndex, sceneTexture, sceneSize);
} }
void Basic2DWindowOpenGLDisplayPlugin::internalPresent() {
if (_wantVsync != isVsyncEnabled()) {
enableVsync(_wantVsync);
}
WindowOpenGLDisplayPlugin::internalPresent();
}
int Basic2DWindowOpenGLDisplayPlugin::getDesiredInterval() const { int Basic2DWindowOpenGLDisplayPlugin::getDesiredInterval() const {
static const int THROTTLED_PAINT_TIMER_DELAY_MS = MSECS_PER_SECOND / 15; static const int THROTTLED_PAINT_TIMER_DELAY_MS = MSECS_PER_SECOND / 15;
static const int ULIMIITED_PAINT_TIMER_DELAY_MS = 1; static const int ULIMIITED_PAINT_TIMER_DELAY_MS = 1;

View file

@ -19,10 +19,11 @@ public:
virtual const QString & getName() const override; virtual const QString & getName() const override;
virtual void activate() override; virtual void activate() override;
virtual void deactivate() override;
virtual void submitSceneTexture(uint32_t frameIndex, uint32_t sceneTexture, const glm::uvec2& sceneSize) override; virtual void submitSceneTexture(uint32_t frameIndex, uint32_t sceneTexture, const glm::uvec2& sceneSize) override;
virtual void internalPresent() override;
virtual bool isThrottled() const override; virtual bool isThrottled() const override;
protected: protected:

View file

@ -145,6 +145,8 @@ private:
QGLContext* _context { nullptr }; QGLContext* _context { nullptr };
}; };
bool OpenGLDisplayPlugin::_vsyncSupported = false;
OpenGLDisplayPlugin::OpenGLDisplayPlugin() { OpenGLDisplayPlugin::OpenGLDisplayPlugin() {
_sceneTextureEscrow.setRecycler([this](GLuint texture){ _sceneTextureEscrow.setRecycler([this](GLuint texture){
cleanupForSceneTexture(texture); cleanupForSceneTexture(texture);
@ -175,10 +177,18 @@ void OpenGLDisplayPlugin::activate() {
// Start the present thread if necessary // Start the present thread if necessary
auto presentThread = DependencyManager::get<PresentThread>(); auto presentThread = DependencyManager::get<PresentThread>();
if (!presentThread) { if (!presentThread) {
auto widget = _container->getPrimaryWidget();
// TODO: write the proper code for linux
#if defined(Q_OS_WIN)
widget->makeCurrent();
_vsyncSupported = wglewGetExtension("WGL_EXT_swap_control");
widget->doneCurrent();
#endif
DependencyManager::set<PresentThread>(); DependencyManager::set<PresentThread>();
presentThread = DependencyManager::get<PresentThread>(); presentThread = DependencyManager::get<PresentThread>();
presentThread->setObjectName("Presentation Thread"); presentThread->setObjectName("Presentation Thread");
auto widget = _container->getPrimaryWidget();
presentThread->setContext(widget->context()); presentThread->setContext(widget->context());
// Start execution // Start execution
presentThread->start(); presentThread->start();
@ -201,10 +211,6 @@ void OpenGLDisplayPlugin::customizeContext() {
auto presentThread = DependencyManager::get<PresentThread>(); auto presentThread = DependencyManager::get<PresentThread>();
Q_ASSERT(thread() == presentThread->thread()); Q_ASSERT(thread() == presentThread->thread());
// TODO: write the proper code for linux
#if defined(Q_OS_WIN)
_vsyncSupported = wglewGetExtension("WGL_EXT_swap_control");
#endif
enableVsync(); enableVsync();
using namespace oglplus; using namespace oglplus;

View file

@ -70,7 +70,6 @@ protected:
mutable QTimer _timer; mutable QTimer _timer;
ProgramPtr _program; ProgramPtr _program;
ShapeWrapperPtr _plane; ShapeWrapperPtr _plane;
bool _vsyncSupported { false };
Mutex _mutex; Mutex _mutex;
SimpleMovingAverage _usecsPerFrame { 10 }; SimpleMovingAverage _usecsPerFrame { 10 };
@ -81,6 +80,8 @@ protected:
GLTextureEscrow _overlayTextureEscrow; GLTextureEscrow _overlayTextureEscrow;
GLTextureEscrow _sceneTextureEscrow; GLTextureEscrow _sceneTextureEscrow;
static bool _vsyncSupported;
}; };

View file

@ -19,7 +19,6 @@ public:
virtual void customizeContext() override; virtual void customizeContext() override;
virtual glm::uvec2 getRecommendedRenderSize() const override; virtual glm::uvec2 getRecommendedRenderSize() const override;
void internalPresent() override; void internalPresent() override;
private: private:

View file

@ -74,7 +74,7 @@ void StereoDisplayPlugin::activate() {
if (screen == qApp->primaryScreen()) { if (screen == qApp->primaryScreen()) {
checked = true; checked = true;
} }
auto action = _container->addMenuItem(MENU_PATH(), name, auto action = _container->addMenuItem(PluginType::DISPLAY_PLUGIN, MENU_PATH(), name,
[this](bool clicked) { updateScreen(); }, true, checked, "Screens"); [this](bool clicked) { updateScreen(); }, true, checked, "Screens");
_screenActions[i] = action; _screenActions[i] = action;
} }

View file

@ -68,7 +68,7 @@ void SixenseManager::activate() {
#ifdef HAVE_SIXENSE #ifdef HAVE_SIXENSE
_container->addMenu(MENU_PATH); _container->addMenu(MENU_PATH);
_container->addMenuItem(MENU_PATH, TOGGLE_SMOOTH, _container->addMenuItem(PluginType::INPUT_PLUGIN, MENU_PATH, TOGGLE_SMOOTH,
[this] (bool clicked) { setSixenseFilter(clicked); }, [this] (bool clicked) { setSixenseFilter(clicked); },
true, true); true, true);

View file

@ -60,7 +60,7 @@ void ViveControllerManager::activate() {
InputPlugin::activate(); InputPlugin::activate();
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
_container->addMenu(MENU_PATH); _container->addMenu(MENU_PATH);
_container->addMenuItem(MENU_PATH, RENDER_CONTROLLERS, _container->addMenuItem(PluginType::INPUT_PLUGIN, MENU_PATH, RENDER_CONTROLLERS,
[this] (bool clicked) { this->setRenderControllers(clicked); }, [this] (bool clicked) { this->setRenderControllers(clicked); },
true, true); true, true);

View file

@ -10,6 +10,11 @@
#include <vector> #include <vector>
#include <memory> #include <memory>
enum class PluginType {
DISPLAY_PLUGIN,
INPUT_PLUGIN,
};
class DisplayPlugin; class DisplayPlugin;
class InputPlugin; class InputPlugin;
class Plugin; class Plugin;

View file

@ -10,6 +10,10 @@
#include <functional> #include <functional>
#include <stdint.h> #include <stdint.h>
#include <QString> #include <QString>
#include <QtCore/QVector>
#include <QtCore/QPair>
#include "Forward.h"
class QAction; class QAction;
class QGLWidget; class QGLWidget;
@ -24,9 +28,11 @@ public:
static PluginContainer& getInstance(); static PluginContainer& getInstance();
PluginContainer(); PluginContainer();
virtual ~PluginContainer(); virtual ~PluginContainer();
virtual QVector<QPair<QString, QString>>& currentDisplayActions() = 0;
virtual QVector<QPair<QString, QString>>& currentInputActions() = 0;
virtual void addMenu(const QString& menuName) = 0; virtual void addMenu(const QString& menuName) = 0;
virtual void removeMenu(const QString& menuName) = 0; virtual void removeMenu(const QString& menuName) = 0;
virtual QAction* addMenuItem(const QString& path, const QString& name, std::function<void(bool)> onClicked, bool checkable = false, bool checked = false, const QString& groupName = "") = 0; virtual QAction* addMenuItem(PluginType pluginType, const QString& path, const QString& name, std::function<void(bool)> onClicked, bool checkable = false, bool checked = false, const QString& groupName = "") = 0;
virtual void removeMenuItem(const QString& menuName, const QString& menuItem) = 0; virtual void removeMenuItem(const QString& menuName, const QString& menuItem) = 0;
virtual bool isOptionChecked(const QString& name) = 0; virtual bool isOptionChecked(const QString& name) = 0;
virtual void setIsOptionChecked(const QString& path, bool checked) = 0; virtual void setIsOptionChecked(const QString& path, bool checked) = 0;

View file

@ -68,6 +68,7 @@ void OculusBaseDisplayPlugin::deinit() {
} }
void OculusBaseDisplayPlugin::activate() { void OculusBaseDisplayPlugin::activate() {
WindowOpenGLDisplayPlugin::activate();
#if (OVR_MAJOR_VERSION >= 6) #if (OVR_MAJOR_VERSION >= 6)
if (!OVR_SUCCESS(ovr_Initialize(nullptr))) { if (!OVR_SUCCESS(ovr_Initialize(nullptr))) {
qFatal("Could not init OVR"); qFatal("Could not init OVR");
@ -134,8 +135,6 @@ void OculusBaseDisplayPlugin::activate() {
qFatal("Could not attach to sensor device"); qFatal("Could not attach to sensor device");
} }
#endif #endif
WindowOpenGLDisplayPlugin::activate();
} }
void OculusBaseDisplayPlugin::deactivate() { void OculusBaseDisplayPlugin::deactivate() {

View file

@ -144,7 +144,7 @@ static const QString MONO_PREVIEW = "Mono Preview";
static const QString FRAMERATE = DisplayPlugin::MENU_PATH() + ">Framerate"; static const QString FRAMERATE = DisplayPlugin::MENU_PATH() + ">Framerate";
void OculusDisplayPlugin::activate() { void OculusDisplayPlugin::activate() {
_container->addMenuItem(MENU_PATH(), MONO_PREVIEW, _container->addMenuItem(PluginType::DISPLAY_PLUGIN, MENU_PATH(), MONO_PREVIEW,
[this](bool clicked) { [this](bool clicked) {
_monoPreview = clicked; _monoPreview = clicked;
}, true, true); }, true, true);