Skip to content

Commit 8679e22

Browse files
committed
Merge remote-tracking branch 'upstream/master' into next
2 parents 493d9fb + 579775d commit 8679e22

File tree

561 files changed

+27834
-16577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

561 files changed

+27834
-16577
lines changed

Client/cefweb/CWebView.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ CWebView::~CWebView()
4141
g_pCore->GetWebCore()->SetFocusedWebView(nullptr);
4242
}
4343

44+
// Make sure we don't dead lock the CEF render thread
45+
ResumeCefThread();
46+
4447
// Ensure that CefRefPtr::~CefRefPtr doesn't try to release it twice (it has already been released in CWebView::OnBeforeClose)
45-
m_pWebView = nullptr;
48+
m_pWebView = nullptr;
4649

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

83+
// Make sure we don't dead lock the CEF render thread
84+
ResumeCefThread();
85+
8086
if (m_pWebView)
8187
m_pWebView->GetHost()->CloseBrowser(true);
8288
}
@@ -200,7 +206,7 @@ void CWebView::UpdateTexture()
200206

201207
auto pSurface = m_pWebBrowserRenderItem->m_pD3DRenderTargetSurface;
202208
if (m_bBeingDestroyed || !pSurface)
203-
return;
209+
m_RenderData.changed = m_RenderData.popupShown = false;
204210

205211
// Discard current buffer if size doesn't match
206212
// This happens when resizing the browser as OnPaint is called asynchronously
@@ -281,6 +287,9 @@ void CWebView::UpdateTexture()
281287
pSurface->UnlockRect();
282288
}
283289
}
290+
291+
m_RenderData.cefThreadState = ECefThreadState::Running;
292+
m_RenderData.cefThreadCv.notify_all();
284293
}
285294

286295
void CWebView::ExecuteJavascript(const SString& strJavascriptCode)
@@ -447,6 +456,8 @@ void CWebView::Resize(const CVector2D& size)
447456
// Send resize event to CEF
448457
if (m_pWebView)
449458
m_pWebView->GetHost()->WasResized();
459+
460+
ResumeCefThread();
450461
}
451462

452463
CVector2D CWebView::GetSize()
@@ -709,6 +720,10 @@ void CWebView::OnPaint(CefRefPtr<CefBrowser> browser, CefRenderHandler::PaintEle
709720
m_RenderData.height = height;
710721
m_RenderData.dirtyRects = dirtyRects;
711722
m_RenderData.changed = true;
723+
724+
// Wait for the main thread to handle drawing the texture
725+
m_RenderData.cefThreadState = ECefThreadState::Wait;
726+
m_RenderData.cefThreadCv.wait(lock, [&](){ return m_RenderData.cefThreadState == ECefThreadState::Running; });
712727
}
713728

714729
////////////////////////////////////////////////////////////////////
@@ -1067,3 +1082,14 @@ void CWebView::OnBeforeContextMenu(CefRefPtr<CefBrowser> browser, CefRefPtr<CefF
10671082
// Show no context menu
10681083
model->Clear();
10691084
}
1085+
1086+
void CWebView::ResumeCefThread()
1087+
{
1088+
{
1089+
// It's recommended to unlock a mutex before the cv notifying to avoid a possible pessimization
1090+
std::unique_lock<std::mutex> lock(m_RenderData.dataMutex);
1091+
m_RenderData.cefThreadState = ECefThreadState::Running;
1092+
}
1093+
1094+
m_RenderData.cefThreadCv.notify_all();
1095+
}

Client/cefweb/CWebView.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030

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

33+
enum class ECefThreadState
34+
{
35+
Running = 0, // CEF thread is currently running
36+
Wait // CEF thread is waiting for the main thread
37+
};
38+
3339
class CWebView : public CWebViewInterface,
3440
private CefClient,
3541
private CefRenderHandler,
@@ -173,6 +179,8 @@ class CWebView : public CWebViewInterface,
173179
CefRefPtr<CefMenuModel> model) override;
174180

175181
private:
182+
void ResumeCefThread();
183+
176184
CefRefPtr<CefBrowser> m_pWebView;
177185
CWebBrowserItem* m_pWebBrowserRenderItem;
178186

@@ -192,6 +200,8 @@ class CWebView : public CWebViewInterface,
192200
{
193201
bool changed = false;
194202
std::mutex dataMutex;
203+
ECefThreadState cefThreadState = ECefThreadState::Running;
204+
std::condition_variable cefThreadCv;
195205

196206
const void* buffer;
197207
int width, height;
0 Bytes
Binary file not shown.

Client/loader/MainFunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ void CheckDataFiles()
837837
const char* szFilename;
838838
} integrityCheckList[] = {{"8E58FCC0672A66C827C6F90FA4B58538", "bass.dll"}, {"285A668CB793F5A5CA134DE9682A6064", "bass_aac.dll"},
839839
{"07C11F7D8058F350ADF6FC9AB81B38AC", "bass_ac3.dll"}, {"D8CCB4B8235F31A3C73485FDE18B0187", "bass_fx.dll"},
840-
{"ACA5F6C422F4FCA0E87AC9835C047E43", "bassflac.dll"}, {"154F9323D8C7F7C7755D9276E4084D6E", "bassmidi.dll"},
840+
{"65F79B61AD377DE06D88FE40B1D70538", "bassflac.dll"}, {"9AAF837944A9763CD914AC7D31ABC8C7", "bassmidi.dll"},
841841
{"D31DA7583083C1370F3C6B9C15F363CC", "bassmix.dll"}, {"26C74F5E9DF6C59DED3B09335E5D82AD", "bassopus.dll"},
842842
{"1A78628A8AB4B8DB0E336610A3ACF153", "basswebm.dll"}, {"893113C6C49DC1E1EF288310E68DB306", "basswma.dll"},
843843
{"6E2C5DCF4EE973E69ECA39288D20C436", "tags.dll"}, {"309D860FC8137E5FE9E7056C33B4B8BE", "vea.dll"},

Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ void CClientVectorGraphicDisplay::Render()
4242
if (HasUpdated())
4343
{
4444
m_pVectorGraphic->OnUpdate();
45-
}
46-
45+
}
4746
}
4847

4948
void CClientVectorGraphicDisplay::UpdateTexture()
@@ -52,46 +51,41 @@ void CClientVectorGraphicDisplay::UpdateTexture()
5251
return;
5352

5453
Document* svgDocument = m_pVectorGraphic->GetSVGDocument();
55-
56-
if (svgDocument == nullptr)
54+
if (!svgDocument)
5755
return;
5856

5957
CVectorGraphicItem* pVectorGraphicItem = m_pVectorGraphic->GetRenderItem();
60-
6158
if (!pVectorGraphicItem)
6259
return;
6360

6461
IDirect3DSurface9* surface = m_pVectorGraphic->GetRenderItem()->m_pD3DRenderTargetSurface;
65-
6662
if (!surface)
6763
return;
6864

69-
IDirect3DDevice9* device = pVectorGraphicItem->m_pDevice;
70-
71-
uint width = pVectorGraphicItem->m_uiSizeX;
72-
uint height = pVectorGraphicItem->m_uiSizeY;
73-
74-
Bitmap bitmap = svgDocument->renderToBitmap(width, height);
65+
Bitmap bitmap = svgDocument->renderToBitmap(pVectorGraphicItem->m_uiSizeX, pVectorGraphicItem->m_uiSizeY);
66+
if (!bitmap.valid())
67+
return;
7568

7669
// Lock surface
7770
D3DLOCKED_RECT LockedRect;
78-
surface->LockRect(&LockedRect, nullptr, 0);
71+
if (SUCCEEDED(surface->LockRect(&LockedRect, nullptr, D3DLOCK_DISCARD)))
72+
{
73+
auto surfaceData = static_cast<byte*>(LockedRect.pBits);
74+
auto sourceData = static_cast<const byte*>(bitmap.data());
7975

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

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

87-
// advance row pointers
88-
sourceData += bitmap.stride();
89-
surfaceData += LockedRect.Pitch;
85+
// Unlock surface
86+
surface->UnlockRect();
9087
}
9188

92-
// Unlock surface
93-
surface->UnlockRect();
94-
9589
m_bHasUpdated = false;
9690
}
9791

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

10397
CVectorGraphicItem* pVectorGraphicItem = m_pVectorGraphic->GetRenderItem();
104-
10598
if (!pVectorGraphicItem)
10699
return;
107100

108101
IDirect3DSurface9* surface = pVectorGraphicItem->m_pD3DRenderTargetSurface;
109-
110102
if (!surface)
111103
return;
112104

113-
IDirect3DDevice9* device = pVectorGraphicItem->m_pDevice;
114-
115105
// Lock surface
116106
D3DLOCKED_RECT LockedRect;
117-
surface->LockRect(&LockedRect, nullptr, 0);
118-
119-
device->ColorFill(surface, nullptr, D3DCOLOR_ARGB(0, 0, 0, 0));
107+
if (SUCCEEDED(surface->LockRect(&LockedRect, nullptr, D3DLOCK_DISCARD)))
108+
{
109+
std::memset(LockedRect.pBits, 0x0, LockedRect.Pitch * pVectorGraphicItem->m_uiSurfaceSizeY);
120110

121-
// Unlock surface
122-
surface->UnlockRect();
111+
// Unlock surface
112+
surface->UnlockRect();
113+
}
123114

124115
m_bIsCleared = true;
125116
}

0 commit comments

Comments
 (0)