Allow rendering the graph on a background thread (#1014)
* Render on background thread * More work * variable fix * Add comments
This commit is contained in:
@@ -12,11 +12,13 @@ using namespace GraphControl::DX;
|
||||
using namespace Platform;
|
||||
using namespace Platform::Collections;
|
||||
using namespace std;
|
||||
using namespace Concurrency;
|
||||
using namespace Windows::Devices::Input;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Windows::Foundation::Collections;
|
||||
using namespace Windows::Storage::Streams;
|
||||
using namespace Windows::System;
|
||||
using namespace Windows::System::Threading;
|
||||
using namespace Windows::UI;
|
||||
using namespace Windows::UI::Core;
|
||||
using namespace Windows::UI::Input;
|
||||
@@ -228,9 +230,9 @@ namespace GraphControl
|
||||
TryPlotGraph(keepCurrentView, false);
|
||||
}
|
||||
|
||||
void Grapher::TryPlotGraph(bool keepCurrentView, bool shouldRetry)
|
||||
task<void> Grapher::TryPlotGraph(bool keepCurrentView, bool shouldRetry)
|
||||
{
|
||||
if (TryUpdateGraph(keepCurrentView))
|
||||
if (co_await TryUpdateGraph(keepCurrentView))
|
||||
{
|
||||
SetEquationsAsValid();
|
||||
}
|
||||
@@ -241,12 +243,12 @@ namespace GraphControl
|
||||
// If we failed to plot the graph, try again after the bad equations are flagged.
|
||||
if (shouldRetry)
|
||||
{
|
||||
TryUpdateGraph(keepCurrentView);
|
||||
co_await TryUpdateGraph(keepCurrentView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Grapher::TryUpdateGraph(bool keepCurrentView)
|
||||
task<bool> Grapher::TryUpdateGraph(bool keepCurrentView)
|
||||
{
|
||||
optional<vector<shared_ptr<IEquation>>> initResult = nullopt;
|
||||
bool successful = false;
|
||||
@@ -282,7 +284,7 @@ namespace GraphControl
|
||||
// If the equation request failed, then fail graphing.
|
||||
if (equationRequest == nullptr)
|
||||
{
|
||||
return false;
|
||||
co_return false;
|
||||
}
|
||||
|
||||
request += equationRequest;
|
||||
@@ -303,7 +305,8 @@ namespace GraphControl
|
||||
m_renderMain->Graph = m_graph;
|
||||
|
||||
// It is possible that the render fails, in that case fall through to explicit empty initialization
|
||||
if (m_renderMain->RunRenderPass())
|
||||
co_await m_renderMain->RunRenderPassAsync(false);
|
||||
if (m_renderMain->IsRenderPassSuccesful())
|
||||
{
|
||||
UpdateVariables();
|
||||
successful = true;
|
||||
@@ -329,7 +332,7 @@ namespace GraphControl
|
||||
SetGraphArgs();
|
||||
|
||||
m_renderMain->Graph = m_graph;
|
||||
m_renderMain->RunRenderPass();
|
||||
co_await m_renderMain->RunRenderPassAsync();
|
||||
|
||||
UpdateVariables();
|
||||
|
||||
@@ -341,7 +344,7 @@ namespace GraphControl
|
||||
}
|
||||
|
||||
// Return true if we were able to graph and render all graphable equations
|
||||
return successful;
|
||||
co_return successful;
|
||||
}
|
||||
|
||||
void Grapher::SetEquationsAsValid()
|
||||
@@ -365,8 +368,10 @@ namespace GraphControl
|
||||
|
||||
void Grapher::SetGraphArgs()
|
||||
{
|
||||
if (m_graph)
|
||||
if (m_graph != nullptr && m_renderMain != nullptr)
|
||||
{
|
||||
critical_section::scoped_lock lock(m_renderMain->GetCriticalSection());
|
||||
|
||||
for (auto variable : Variables)
|
||||
{
|
||||
m_graph->SetArgValue(variable->Key->Data(), variable->Value);
|
||||
@@ -436,14 +441,19 @@ namespace GraphControl
|
||||
|
||||
Variables->Insert(variableName, newValue);
|
||||
|
||||
if (m_graph)
|
||||
if (m_graph != nullptr && m_renderMain != nullptr)
|
||||
{
|
||||
m_graph->SetArgValue(variableName->Data(), newValue);
|
||||
|
||||
if (m_renderMain)
|
||||
{
|
||||
m_renderMain->RunRenderPass();
|
||||
}
|
||||
auto workItemHandler = ref new WorkItemHandler([this, variableName, newValue](IAsyncAction ^ action) {
|
||||
m_renderMain->GetCriticalSection().lock();
|
||||
m_graph->SetArgValue(variableName->Data(), newValue);
|
||||
m_renderMain->GetCriticalSection().unlock();
|
||||
|
||||
m_renderMain->RunRenderPassAsync();
|
||||
});
|
||||
|
||||
ThreadPool::RunAsync(workItemHandler, WorkItemPriority::High, WorkItemOptions::None);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -272,8 +272,8 @@ public
|
||||
void OnEquationChanged(Equation ^ equation);
|
||||
void OnEquationStyleChanged(Equation ^ equation);
|
||||
void OnEquationLineEnabledChanged(Equation ^ equation);
|
||||
bool TryUpdateGraph(bool keepCurrentView);
|
||||
void TryPlotGraph(bool keepCurrentView, bool shouldRetry);
|
||||
concurrency::task<bool> TryUpdateGraph(bool keepCurrentView);
|
||||
concurrency::task<void> TryPlotGraph(bool keepCurrentView, bool shouldRetry);
|
||||
void UpdateGraphOptions(Graphing::IGraphingOptions& options, const std::vector<Equation ^>& validEqs);
|
||||
std::vector<Equation ^> GetGraphableEquations();
|
||||
void SetGraphArgs();
|
||||
|
Reference in New Issue
Block a user