void Draw(int _iPane, HDC hDC, const CRect& scrRect, BOOL bRecalc)
{
const std::vector<Info>& drawinfos = App::General::Infos();
std::vector<std::future<void>> futures;
for (const auto& info : drawinfos)
{
futures.emplace_back(std::async(std::launch::async, [=]()
{
if (auto dcPtr = ThreadSafeWinGdi::CreateCompatibleDC(hDC))
{
HDC threadHdc = dcPtr.get();
CDC* threadCDC = ThreadSafeWinGdi::FromHandle(threadHdc);
auto view = static_cast<View*>(App::GetView());
CRect rect = view->GetViewRect();
HBITMAP newBitmap = ThreadSafeWinGdi::CreateCompatibleBitmap(hDC, rect.Width(), rect.Height());
auto oldBitmap = (HBITMAP)(threadCDC->SelectObject(newBitmap));
auto brush = ThreadSafeWinGdi::CreateSolidBrush(view->GetBkColor(_Env().GetEllipsoid()));
ThreadSafeWinGdi::FillRect(threadHdc, rect, brush.get());
CManager manager;
manager.SetEventWnd(coconutView);
manager.SetDC(_iPane, threadHdc);
manager.SetViewRect(_iPane, scrRect);
manager.SetMapRect(_iPane, App::GetERManager().GetDrawMapRect(_iPane), FALSE);
// ::Polygon, ::Polyline...(thread safe ok)
DrawInfo(manager, _iPane, info);
ThreadSafeWinGdi::BitBlt(hDC, 0, 0, rect.Width(), rect.Height(), threadHdc, 0, 0, SRCCOPY);
ThreadSafeWinGdi::DeleteObject(newBitmap);
}
}));
}
for (auto& future : futures)
{
future.wait();
}
I would like to process drawing through multithreading.
After creating and drawing a dc
for each thread, I want to draw it by Bitblt
to mainDc
.
However, it seems that only the bitblt
target appears at the end.
ex) ThreadSafeWinGdi code
BOOL ThreadSafeWinGdi::DeleteObject(HGDIOBJ ho)
{
static std::mutex deleteObject;
std::unique_lock<std::mutex> lock(deleteObject);
return ::DeleteObject(ho);
}