resolve comments

This commit is contained in:
Tian Liao 2024-04-09 11:39:41 +08:00
commit 4286051b42
3 changed files with 17 additions and 30 deletions

View file

@ -55,7 +55,7 @@ namespace
// Translate the pointer position to the [-1, 1] bounds. // Translate the pointer position to the [-1, 1] bounds.
__inline std::pair<double, double> PointerPositionToGraphPosition(double posX, double posY, double width, double height) __inline std::pair<double, double> PointerPositionToGraphPosition(double posX, double posY, double width, double height)
{ {
return std::make_pair((2 * posX / width - 1), (1 - 2 * posY / height)); return { (2 * posX / width - 1), (1 - 2 * posY / height) };
} }
} }
@ -381,7 +381,7 @@ namespace GraphControl
if (initResult.has_value()) if (initResult.has_value())
{ {
auto graphedEquations = *initResult; auto& graphedEquations = *initResult;
for (size_t i = 0; i < validEqs.size(); ++i) for (size_t i = 0; i < validEqs.size(); ++i)
{ {
@ -573,8 +573,8 @@ namespace GraphControl
} }
eq->GraphedEquation->GetGraphEquationOptions()->SetLineStyle(static_cast<::Graphing::Renderer::LineStyle>(eq->EquationStyle)); eq->GraphedEquation->GetGraphEquationOptions()->SetLineStyle(static_cast<::Graphing::Renderer::LineStyle>(eq->EquationStyle));
eq->GraphedEquation->GetGraphEquationOptions()->SetLineWidth(LineWidth); eq->GraphedEquation->GetGraphEquationOptions()->SetLineWidth(static_cast<float>(LineWidth));
eq->GraphedEquation->GetGraphEquationOptions()->SetSelectedEquationLineWidth(LineWidth + ((LineWidth <= 2) ? 1 : 2)); eq->GraphedEquation->GetGraphEquationOptions()->SetSelectedEquationLineWidth(static_cast<float>(LineWidth + ((LineWidth <= 2) ? 1 : 2)));
} }
} }
options.SetGraphColors(graphColors); options.SetGraphColors(graphColors);
@ -1070,7 +1070,7 @@ void Grapher::OnLineWidthPropertyChanged(double oldValue, double newValue)
UpdateGraphOptions(m_graph->GetOptions(), GetGraphableEquations()); UpdateGraphOptions(m_graph->GetOptions(), GetGraphableEquations());
if (m_renderMain) if (m_renderMain)
{ {
m_renderMain->SetPointRadius(LineWidth + 1); m_renderMain->SetPointRadius(static_cast<float>(LineWidth + 1));
m_renderMain->RunRenderPass(); m_renderMain->RunRenderPass();
TraceLogger::GetInstance()->LogLineWidthChanged(); TraceLogger::GetInstance()->LogLineWidthChanged();

View file

@ -46,7 +46,6 @@ namespace GraphControl::DX
RenderMain::~RenderMain() RenderMain::~RenderMain()
{ {
m_renderPassCts.cancel();
UnregisterEventHandlers(); UnregisterEventHandlers();
} }
@ -206,44 +205,32 @@ namespace GraphControl::DX
concurrency::task<bool> RenderMain::RunRenderPassAsync(bool allowCancel) concurrency::task<bool> RenderMain::RunRenderPassAsync(bool allowCancel)
{ {
if (allowCancel)
{
m_renderPassCts.cancel();
}
m_renderPassCts = concurrency::cancellation_token_source{};
bool result = false; bool result = false;
auto currentVer = ++m_renderPassVer;
Platform::WeakReference that{ this };
co_await m_coreWindow->Dispatcher->RunAsync( co_await m_coreWindow->Dispatcher->RunAsync(
CoreDispatcherPriority::High, CoreDispatcherPriority::High,
ref new DispatchedHandler( ref new DispatchedHandler(
[this, &result, cancel = m_renderPassCts.get_token()] [&]
{ {
if (cancel.is_canceled()) auto self = that.Resolve<RenderMain>();
if (self == nullptr || (allowCancel && m_renderPassVer != currentVer))
{
return; return;
result = RunRenderPassInternal(); }
result = self->RunRenderPassInternal();
})); }));
co_return result; co_return result;
} }
bool RenderMain::RunRenderPassInternal() bool RenderMain::RunRenderPassInternal()
{ {
// We are accessing Direct3D resources directly without Direct2D's knowledge, so we if (Render())
// must manually acquire and apply the Direct2D factory lock.
winrt::com_ptr<ID2D1Multithread> d2dmultithread;
m_deviceResources.GetD2DFactory()->QueryInterface(IID_PPV_ARGS(d2dmultithread.put()));
d2dmultithread->Enter();
bool succesful = Render();
if (succesful)
{ {
m_deviceResources.Present(); m_deviceResources.Present();
return true;
} }
return false;
// It is absolutely critical that the factory lock be released upon
// exiting this function, or else any consequent Direct2D calls will be blocked.
d2dmultithread->Leave();
return succesful;
} }
// Renders the current frame according to the current application state. // Renders the current frame according to the current application state.

View file

@ -184,7 +184,7 @@ namespace GraphControl::DX
// Are we currently showing the tracing value // Are we currently showing the tracing value
bool m_Tracing; bool m_Tracing;
concurrency::cancellation_token_source m_renderPassCts; unsigned m_renderPassVer = 0;
HRESULT m_HResult; HRESULT m_HResult;
}; };