Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikjuvonen committed Dec 23, 2022
2 parents 493d9fb + 579775d commit 8679e22
Show file tree
Hide file tree
Showing 561 changed files with 27,834 additions and 16,577 deletions.
30 changes: 28 additions & 2 deletions Client/cefweb/CWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ CWebView::~CWebView()
g_pCore->GetWebCore()->SetFocusedWebView(nullptr);
}

// Make sure we don't dead lock the CEF render thread
ResumeCefThread();

// Ensure that CefRefPtr::~CefRefPtr doesn't try to release it twice (it has already been released in CWebView::OnBeforeClose)
m_pWebView = nullptr;
m_pWebView = nullptr;

OutputDebugLine("CWebView::~CWebView");
}
Expand Down Expand Up @@ -77,6 +80,9 @@ void CWebView::CloseBrowser()
// CefBrowserHost::CloseBrowser calls the destructor after the browser has been destroyed
m_bBeingDestroyed = true;

// Make sure we don't dead lock the CEF render thread
ResumeCefThread();

if (m_pWebView)
m_pWebView->GetHost()->CloseBrowser(true);
}
Expand Down Expand Up @@ -200,7 +206,7 @@ void CWebView::UpdateTexture()

auto pSurface = m_pWebBrowserRenderItem->m_pD3DRenderTargetSurface;
if (m_bBeingDestroyed || !pSurface)
return;
m_RenderData.changed = m_RenderData.popupShown = false;

// Discard current buffer if size doesn't match
// This happens when resizing the browser as OnPaint is called asynchronously
Expand Down Expand Up @@ -281,6 +287,9 @@ void CWebView::UpdateTexture()
pSurface->UnlockRect();
}
}

m_RenderData.cefThreadState = ECefThreadState::Running;
m_RenderData.cefThreadCv.notify_all();
}

void CWebView::ExecuteJavascript(const SString& strJavascriptCode)
Expand Down Expand Up @@ -447,6 +456,8 @@ void CWebView::Resize(const CVector2D& size)
// Send resize event to CEF
if (m_pWebView)
m_pWebView->GetHost()->WasResized();

ResumeCefThread();
}

CVector2D CWebView::GetSize()
Expand Down Expand Up @@ -709,6 +720,10 @@ void CWebView::OnPaint(CefRefPtr<CefBrowser> browser, CefRenderHandler::PaintEle
m_RenderData.height = height;
m_RenderData.dirtyRects = dirtyRects;
m_RenderData.changed = true;

// Wait for the main thread to handle drawing the texture
m_RenderData.cefThreadState = ECefThreadState::Wait;
m_RenderData.cefThreadCv.wait(lock, [&](){ return m_RenderData.cefThreadState == ECefThreadState::Running; });
}

////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1067,3 +1082,14 @@ void CWebView::OnBeforeContextMenu(CefRefPtr<CefBrowser> browser, CefRefPtr<CefF
// Show no context menu
model->Clear();
}

void CWebView::ResumeCefThread()
{
{
// It's recommended to unlock a mutex before the cv notifying to avoid a possible pessimization
std::unique_lock<std::mutex> lock(m_RenderData.dataMutex);
m_RenderData.cefThreadState = ECefThreadState::Running;
}

m_RenderData.cefThreadCv.notify_all();
}
10 changes: 10 additions & 0 deletions Client/cefweb/CWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@

#define MTA_CEF_USERAGENT "Multi Theft Auto: San Andreas Client " MTA_DM_BUILDTAG_LONG

enum class ECefThreadState
{
Running = 0, // CEF thread is currently running
Wait // CEF thread is waiting for the main thread
};

class CWebView : public CWebViewInterface,
private CefClient,
private CefRenderHandler,
Expand Down Expand Up @@ -173,6 +179,8 @@ class CWebView : public CWebViewInterface,
CefRefPtr<CefMenuModel> model) override;

private:
void ResumeCefThread();

CefRefPtr<CefBrowser> m_pWebView;
CWebBrowserItem* m_pWebBrowserRenderItem;

Expand All @@ -192,6 +200,8 @@ class CWebView : public CWebViewInterface,
{
bool changed = false;
std::mutex dataMutex;
ECefThreadState cefThreadState = ECefThreadState::Running;
std::condition_variable cefThreadCv;

const void* buffer;
int width, height;
Expand Down
Binary file modified Client/launch/NEU/Multi Theft Auto.gdf.xml
Binary file not shown.
2 changes: 1 addition & 1 deletion Client/loader/MainFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ void CheckDataFiles()
const char* szFilename;
} integrityCheckList[] = {{"8E58FCC0672A66C827C6F90FA4B58538", "bass.dll"}, {"285A668CB793F5A5CA134DE9682A6064", "bass_aac.dll"},
{"07C11F7D8058F350ADF6FC9AB81B38AC", "bass_ac3.dll"}, {"D8CCB4B8235F31A3C73485FDE18B0187", "bass_fx.dll"},
{"ACA5F6C422F4FCA0E87AC9835C047E43", "bassflac.dll"}, {"154F9323D8C7F7C7755D9276E4084D6E", "bassmidi.dll"},
{"65F79B61AD377DE06D88FE40B1D70538", "bassflac.dll"}, {"9AAF837944A9763CD914AC7D31ABC8C7", "bassmidi.dll"},
{"D31DA7583083C1370F3C6B9C15F363CC", "bassmix.dll"}, {"26C74F5E9DF6C59DED3B09335E5D82AD", "bassopus.dll"},
{"1A78628A8AB4B8DB0E336610A3ACF153", "basswebm.dll"}, {"893113C6C49DC1E1EF288310E68DB306", "basswma.dll"},
{"6E2C5DCF4EE973E69ECA39288D20C436", "tags.dll"}, {"309D860FC8137E5FE9E7056C33B4B8BE", "vea.dll"},
Expand Down
57 changes: 24 additions & 33 deletions Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ void CClientVectorGraphicDisplay::Render()
if (HasUpdated())
{
m_pVectorGraphic->OnUpdate();
}

}
}

void CClientVectorGraphicDisplay::UpdateTexture()
Expand All @@ -52,46 +51,41 @@ void CClientVectorGraphicDisplay::UpdateTexture()
return;

Document* svgDocument = m_pVectorGraphic->GetSVGDocument();

if (svgDocument == nullptr)
if (!svgDocument)
return;

CVectorGraphicItem* pVectorGraphicItem = m_pVectorGraphic->GetRenderItem();

if (!pVectorGraphicItem)
return;

IDirect3DSurface9* surface = m_pVectorGraphic->GetRenderItem()->m_pD3DRenderTargetSurface;

if (!surface)
return;

IDirect3DDevice9* device = pVectorGraphicItem->m_pDevice;

uint width = pVectorGraphicItem->m_uiSizeX;
uint height = pVectorGraphicItem->m_uiSizeY;

Bitmap bitmap = svgDocument->renderToBitmap(width, height);
Bitmap bitmap = svgDocument->renderToBitmap(pVectorGraphicItem->m_uiSizeX, pVectorGraphicItem->m_uiSizeY);
if (!bitmap.valid())
return;

// Lock surface
D3DLOCKED_RECT LockedRect;
surface->LockRect(&LockedRect, nullptr, 0);
if (SUCCEEDED(surface->LockRect(&LockedRect, nullptr, D3DLOCK_DISCARD)))
{
auto surfaceData = static_cast<byte*>(LockedRect.pBits);
auto sourceData = static_cast<const byte*>(bitmap.data());

auto surfaceData = static_cast<byte*>(LockedRect.pBits);
auto sourceData = static_cast<const byte*>(bitmap.data());
for (uint32_t y = 0; y < bitmap.height(); ++y)
{
memcpy(surfaceData, sourceData, bitmap.width() * 4); // 4 bytes per pixel

for (uint32_t y = 0; y < bitmap.height(); ++y)
{
memcpy(surfaceData, sourceData, bitmap.width() * 4); // 4 bytes per pixel
// advance row pointers
sourceData += bitmap.stride();
surfaceData += LockedRect.Pitch;
}

// advance row pointers
sourceData += bitmap.stride();
surfaceData += LockedRect.Pitch;
// Unlock surface
surface->UnlockRect();
}

// Unlock surface
surface->UnlockRect();

m_bHasUpdated = false;
}

Expand All @@ -101,25 +95,22 @@ void CClientVectorGraphicDisplay::ClearTexture()
return;

CVectorGraphicItem* pVectorGraphicItem = m_pVectorGraphic->GetRenderItem();

if (!pVectorGraphicItem)
return;

IDirect3DSurface9* surface = pVectorGraphicItem->m_pD3DRenderTargetSurface;

if (!surface)
return;

IDirect3DDevice9* device = pVectorGraphicItem->m_pDevice;

// Lock surface
D3DLOCKED_RECT LockedRect;
surface->LockRect(&LockedRect, nullptr, 0);

device->ColorFill(surface, nullptr, D3DCOLOR_ARGB(0, 0, 0, 0));
if (SUCCEEDED(surface->LockRect(&LockedRect, nullptr, D3DLOCK_DISCARD)))
{
std::memset(LockedRect.pBits, 0x0, LockedRect.Pitch * pVectorGraphicItem->m_uiSurfaceSizeY);

// Unlock surface
surface->UnlockRect();
// Unlock surface
surface->UnlockRect();
}

m_bIsCleared = true;
}
Expand Down

0 comments on commit 8679e22

Please sign in to comment.