From 4fc97effda095a84131b89059d0a347a78511bfd Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Mon, 22 Apr 2019 16:22:18 -0700 Subject: [PATCH] combine snapshotOperator lists per sam's suggestions --- interface/src/Application.cpp | 22 ++++++------------- interface/src/Application.h | 7 ++---- interface/src/graphics/GraphicsEngine.cpp | 3 --- interface/src/ui/Snapshot.cpp | 4 ++-- interface/src/ui/SnapshotAnimated.cpp | 2 +- .../display-plugins/OpenGLDisplayPlugin.cpp | 15 +++++-------- libraries/gpu/src/gpu/Frame.h | 3 +-- 7 files changed, 18 insertions(+), 38 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 27c6ef2f64..f46d0d3ddd 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -8441,23 +8441,15 @@ void Application::loadAvatarBrowser() const { void Application::addSnapshotOperator(const SnapshotOperator& snapshotOperator) { std::lock_guard lock(_snapshotMutex); _snapshotOperators.push(snapshotOperator); + _hasPrimarySnapshot |= std::get<2>(snapshotOperator); } bool Application::takeSnapshotOperators(std::queue& snapshotOperators) { std::lock_guard lock(_snapshotMutex); + bool hasPrimarySnapshot = _hasPrimarySnapshot; + _hasPrimarySnapshot = false; _snapshotOperators.swap(snapshotOperators); - return !snapshotOperators.empty(); -} - -void Application::addSecondarySnapshotOperator(const SecondarySnapshotOperator& snapshotOperator) { - std::lock_guard lock(_snapshotMutex); - _secondarySnapshotOperators.push(snapshotOperator); -} - -bool Application::takeSecondarySnapshotOperators(std::queue& snapshotOperators) { - std::lock_guard lock(_snapshotMutex); - _secondarySnapshotOperators.swap(snapshotOperators); - return !snapshotOperators.empty(); + return hasPrimarySnapshot; } void Application::takeSnapshot(bool notify, bool includeAnimated, float aspectRatio, const QString& filename) { @@ -8476,15 +8468,15 @@ void Application::takeSnapshot(bool notify, bool includeAnimated, float aspectRa SnapshotAnimated::saveSnapshotAnimated(path, aspectRatio, DependencyManager::get()); }); } - }, aspectRatio }); + }, aspectRatio, true }); } void Application::takeSecondaryCameraSnapshot(const bool& notify, const QString& filename) { - addSecondarySnapshotOperator([notify, filename](const QImage& snapshot) { + addSnapshotOperator({ [notify, filename](const QImage& snapshot) { QString snapshotPath = DependencyManager::get()->saveSnapshot(snapshot, filename, TestScriptingInterface::getInstance()->getTestResultsLocation()); emit DependencyManager::get()->stillSnapshotTaken(snapshotPath, notify); - }); + }, 0, false }); } void Application::takeSecondaryCamera360Snapshot(const glm::vec3& cameraPosition, const bool& cubemapOutputFormat, const bool& notify, const QString& filename) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 967790d034..12523f3108 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -345,12 +345,9 @@ public: void toggleAwayMode(); #endif - using SnapshotOperator = std::pair, float>; - using SecondarySnapshotOperator = std::function; + using SnapshotOperator = std::tuple, float, bool>; void addSnapshotOperator(const SnapshotOperator& snapshotOperator); bool takeSnapshotOperators(std::queue& snapshotOperators); - void addSecondarySnapshotOperator(const SecondarySnapshotOperator& snapshotOperator); - bool takeSecondarySnapshotOperators(std::queue& snapshotOperators); signals: void svoImportRequested(const QString& url); @@ -798,7 +795,7 @@ private: SharedSoundPointer _sampleSound; std::mutex _snapshotMutex; std::queue _snapshotOperators; - std::queue _secondarySnapshotOperators; + bool _hasPrimarySnapshot { false }; DisplayPluginPointer _autoSwitchDisplayModeSupportedHMDPlugin; QString _autoSwitchDisplayModeSupportedHMDPluginName; diff --git a/interface/src/graphics/GraphicsEngine.cpp b/interface/src/graphics/GraphicsEngine.cpp index 09471a9570..267822baf2 100644 --- a/interface/src/graphics/GraphicsEngine.cpp +++ b/interface/src/graphics/GraphicsEngine.cpp @@ -245,7 +245,6 @@ void GraphicsEngine::render_performFrame() { } std::queue snapshotOperators; - std::queue secondarySnapshotOperators; if (!_programsCompiled.load()) { gpu::doInBatch("splashFrame", _gpuContext, [&](gpu::Batch& batch) { batch.setFramebuffer(finalFramebuffer); @@ -274,7 +273,6 @@ void GraphicsEngine::render_performFrame() { renderArgs._hudOperator = displayPlugin->getHUDOperator(); renderArgs._hudTexture = qApp->getApplicationOverlay().getOverlayTexture(); renderArgs._takingSnapshot = qApp->takeSnapshotOperators(snapshotOperators); - qApp->takeSecondarySnapshotOperators(secondarySnapshotOperators); renderArgs._blitFramebuffer = finalFramebuffer; render_runRenderFrame(&renderArgs); } @@ -290,7 +288,6 @@ void GraphicsEngine::render_performFrame() { } }; frame->snapshotOperators = snapshotOperators; - frame->secondarySnapshotOperators = secondarySnapshotOperators; // deliver final scene rendering commands to the display plugin { PROFILE_RANGE(render, "/pluginOutput"); diff --git a/interface/src/ui/Snapshot.cpp b/interface/src/ui/Snapshot.cpp index 94523fa6dd..93d9188cc8 100644 --- a/interface/src/ui/Snapshot.cpp +++ b/interface/src/ui/Snapshot.cpp @@ -168,7 +168,7 @@ void Snapshot::takeNextSnapshot() { if (_taking360Snapshot) { if (!_waitingOnSnapshot) { _waitingOnSnapshot = true; - qApp->addSecondarySnapshotOperator([this](const QImage& snapshot) { + qApp->addSnapshotOperator({ [this](const QImage& snapshot) { // Order is: // 0. Down // 1. Front @@ -202,7 +202,7 @@ void Snapshot::takeNextSnapshot() { _waitingOnSnapshot = false; _snapshotIndex++; - }); + }, 0, false }); } } else { _snapshotTimer.stop(); diff --git a/interface/src/ui/SnapshotAnimated.cpp b/interface/src/ui/SnapshotAnimated.cpp index 03ec86e342..f8f6a30635 100644 --- a/interface/src/ui/SnapshotAnimated.cpp +++ b/interface/src/ui/SnapshotAnimated.cpp @@ -86,7 +86,7 @@ void SnapshotAnimated::captureFrames() { SnapshotAnimated::snapshotAnimatedTimerRunning = false; } } - }, SnapshotAnimated::aspectRatio }); + }, SnapshotAnimated::aspectRatio, true }); } else { // Notify the user that we're processing the snapshot // This also pops up the "Share" dialog. The unprocessed GIF will be visualized as a loading icon until processingGifCompleted() is called. diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index e80102ec85..4c3de004bd 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -725,20 +725,15 @@ void OpenGLDisplayPlugin::present() { PROFILE_RANGE_EX(render, "snapshotOperators", 0xffff00ff, frameId) while (!_currentFrame->snapshotOperators.empty()) { auto& snapshotOperator = _currentFrame->snapshotOperators.front(); - snapshotOperator.first(getScreenshot(snapshotOperator.second)); + if (std::get<2>(snapshotOperator)) { + std::get<0>(snapshotOperator)(getScreenshot(std::get<1>(snapshotOperator))); + } else { + std::get<0>(snapshotOperator)(getSecondaryCameraScreenshot()); + } _currentFrame->snapshotOperators.pop(); } } - { // If we have any secondary camera snapshots this frame, handle them - PROFILE_RANGE_EX(render, "secondarySnapshotOperators", 0x00ff00ff, frameId) - while (!_currentFrame->secondarySnapshotOperators.empty()) { - auto& snapshotOperator = _currentFrame->secondarySnapshotOperators.front(); - snapshotOperator(getSecondaryCameraScreenshot()); - _currentFrame->secondarySnapshotOperators.pop(); - } - } - // Take the composite framebuffer and send it to the output device { PROFILE_RANGE_EX(render, "internalPresent", 0xff00ffff, frameId) diff --git a/libraries/gpu/src/gpu/Frame.h b/libraries/gpu/src/gpu/Frame.h index 541b9393d3..9aa99e50f7 100644 --- a/libraries/gpu/src/gpu/Frame.h +++ b/libraries/gpu/src/gpu/Frame.h @@ -42,8 +42,7 @@ namespace gpu { /// How to process the framebuffer when the frame dies. MUST BE THREAD SAFE FramebufferRecycler framebufferRecycler; - std::queue, float>> snapshotOperators; - std::queue> secondarySnapshotOperators; + std::queue, float, bool>> snapshotOperators; protected: friend class Deserializer;