Skip to content

Commit

Permalink
Backup, GIF still broken
Browse files Browse the repository at this point in the history
  • Loading branch information
dtugend committed Jul 5, 2021
1 parent 4d49b91 commit e38d4b3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 55 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# afx-cefhud-interop

## Known problems:

Animated GIFs can cause freezes.

## FAQ

### Can I use this for browsing the internet?
Expand Down Expand Up @@ -45,7 +49,7 @@ cmake -G "Visual Studio 16" -A x64 "-DUSE_SANDBOX=Off" ..
Then, open the newly created c:\some\directory\afx-cefhud-interop\build\cef.sln in Visual Studio 2019 and select **Release** and **x64** in the confugration, right click afx-cefhud-interop in Solution tree and select Build.

For instructions how to use the binary see the comments at the top of the example.html here:
https://github.com/advancedfx/afx-cefhud-interop/blob/main/afx-cefhud-interop/examples/default/index.html#L4
https://github.com/advancedfx/afx-cefhud-interop/blob/main/afx-cefhud-interop/assets/examples/default/index.html#L4

----

Expand Down
18 changes: 13 additions & 5 deletions afx-cefhud-interop/assets/examples/default/drawing.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@
.indicator.white {
background: #fff;
}
.hidden {
display: none;
}
</style>

<body>
<body id="body">
<div id="indicator" class="indicator"></div>
<div id="indicator2" class="indicator"></div>
<div class="main">
<!-- This makes it freeze for sure: <img src="https://media1.tenor.com/images/74a87da6760e119fdfbb1ee9d2914871/tenor.gif?itemid=5437251" width="320" height="auto" /> -->
<!-- This makes it freeze for sure: <img id="gif" src="https://media1.tenor.com/images/74a87da6760e119fdfbb1ee9d2914871/tenor.gif?itemid=5437251" width="320" height="auto" class="" /> -->
<h1 style="color: #00ff00">Hello World from afx-cefhud-interop</h1>
<p>Client time: <span id="clientTime"></span></p>
<h2>Last game events:</h2>
Expand Down Expand Up @@ -61,8 +64,9 @@ <h2>Last game events:</h2>
this.cefTextures = {};
this.elIndicator = document.getElementById('indicator');
this.elIndicator2 = document.getElementById('indicator2');
this.divGameEvents = document.getElementById('gameEvents');
this.elGameEvents = document.getElementById('gameEvents');
this.elClientTime = document.getElementById('clientTime');
this.elGif = document.getElementById('gif');

this.engineInteropId = null;

Expand Down Expand Up @@ -129,6 +133,8 @@ <h2>Last game events:</h2>
"connect": async function(senderId) {
this.engineInteropId = senderId;
await this.connect(senderId);

var self = this;
},
"disconnect": async function(senderId) {
await Utils.toPromise(this, "disconnect");
Expand All @@ -148,11 +154,11 @@ <h2>Last game events:</h2>
this.elClientTime.innerText = renderInfo.curTime;
},
"onGameEvent": async function(e){
while(this.divGameEvents.childNodes.length > 10) this.divGameEvents.lastElementChild.remove();
while(this.elGameEvents.childNodes.length > 10) this.elGameEvents.lastElementChild.remove();

var docP = document.createElement('p');
docP.appendChild(document.createTextNode(JSON.stringify(e)));
this.divGameEvents.insertBefore(docP, this.divGameEvents.firstElementChild);
this.elGameEvents.insertBefore(docP, this.elGameEvents.firstElementChild);
},
"onHudEnd": async function(frameCount, pass){
this.elIndicator.classList.toggle("white",(frameCount % 2) == 0);
Expand Down Expand Up @@ -321,6 +327,8 @@ <h2>Last game events:</h2>
}
});

//await requestAnimationFramePromise;

await Utils.toPromise(self.interop, "pumpEnd");
}
catch(e) {
Expand Down
6 changes: 3 additions & 3 deletions afx-cefhud-interop/assets/examples/default/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
## Usage:
Launch CS:GO from HLAE with -afxInteropLight.
The game must run with at least 2 queues (which is the case for mat_queueu_mode 2, and on almost all CPUs also for mat_queue_mode -1 (recommended))!g
The game must run with at least 2 queues (which is the case for mat_queueu_mode 2, and on almost all CPUs also for mat_queue_mode -1 (recommended))!
Execute (will log warings / errors to debug.log in current directoy):
afx-cefhud-interop.exe "--url=afx://file/C:/source/afx-cefhud-interop/afx-cefhud-interop/assets/examples/default/index.html" "--disable-frame-rate-limit" "--enable-experimental-web-platform-features" "--enable-logging" "--v=1"
afx-cefhud-interop.exe "--url=afx://file/C:/source/afx-cefhud-interop/afx-cefhud-interop/assets/examples/default/index.html" "--enable-experimental-web-platform-features" "--enable-logging" "--v=1"
For live execute:
afx-cefhud-interop.exe "--url=afx://file/C:/source/afx-cefhud-interop/afx-cefhud-interop/assets/examples/default/index.html" "--deterministic-mode" "--deadline-to-synchronize-surfaces=0" "--disable-frame-rate-limit" "--enable-experimental-web-platform-features" "--disable-gpu-watchdog" "--disable-hang-monitor" "--enable-logging" "--log-severity=error"
afx-cefhud-interop.exe "--url=afx://file/C:/source/afx-cefhud-interop/afx-cefhud-interop/assets/examples/default/index.html" "--enable-experimental-web-platform-features" "--enable-logging" "--log-severity=error"
Optional arguments:
--afx-no-window
Expand Down
29 changes: 8 additions & 21 deletions afx-cefhud-interop/cefsimple_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,6 @@ const char* g_szPixelShaderCode =
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12,
D3D11_INPUT_PER_VERTEX_DATA, 0}};


ID3D11DeviceContext* g_ActiveContext = nullptr;
HANDLE g_ActiveShareHandle = INVALID_HANDLE_VALUE;
int g_ActiveBrowser = 0;

/* BUGGED DON'T USE.
bool AfxWaitForGPU(ID3D11DeviceContext* pCtx) {
if(!g_pDevice) return false;
Expand Down Expand Up @@ -238,7 +233,6 @@ void STDMETHODCALLTYPE My_OMSetRenderTargets(
void STDMETHODCALLTYPE My_Flush(ID3D11DeviceContext* This) {
g_Org_Flush(This);

if (This == g_ActiveContext && g_ActiveShareHandle != INVALID_HANDLE_VALUE) {
ID3D11RenderTargetView* oldRenderTarget[1] = {nullptr};
pContext->OMGetRenderTargets(1, &oldRenderTarget[0], NULL);

Expand All @@ -249,7 +243,7 @@ void STDMETHODCALLTYPE My_Flush(ID3D11DeviceContext* This) {

if (resource) {
auto it = g_Textures.find((ID3D11Texture2D*)resource);
if (it != g_Textures.end() && it->second.FlushCount < 1) {
if (it != g_Textures.end()) {
it->second.FirstClear = true;
++it->second.FlushCount;

Expand All @@ -258,24 +252,21 @@ void STDMETHODCALLTYPE My_Flush(ID3D11DeviceContext* This) {
try {
g_GpuPipeClient.WriteInt32(
(INT32)advancedfx::interop::HostGpuMessage::OnAfterRender);
g_GpuPipeClient.WriteHandle(g_ActiveShareHandle);
g_GpuPipeClient.WriteInt32(g_ActiveBrowser);
g_GpuPipeClient.WriteHandle(it->second.ShareHandle);
g_GpuPipeClient.WriteInt32(it->second.ActiveBrowser);
g_GpuPipeClient.Flush();

g_GpuPipeClient.ReadBoolean();
} catch (const std::exception& e) {
DLOG(ERROR) << "Error in " << __FILE__ << ":" << __LINE__ << ": "
<< e.what();
}
g_ActiveContext = nullptr;
g_ActiveShareHandle = INVALID_HANDLE_VALUE;
}

resource->Release();
}
oldRenderTarget[0]->Release();
}
}
}

void STDMETHODCALLTYPE
Expand All @@ -293,7 +284,7 @@ My_ClearRenderTargetView(ID3D11DeviceContext* This,

if (resource) {
auto it = g_Textures.find((ID3D11Texture2D*)resource);
if (it != g_Textures.end() && it->second.FirstClear) {
if (it != g_Textures.end()) {

/*
FLOAT color[4] = {((g_ClearCount << 0) % 256) / 255.0f,
Expand All @@ -305,10 +296,6 @@ My_ClearRenderTargetView(ID3D11DeviceContext* This,
it->second.FlushCount = 0;

if (pInputLayout && pVertexBuffer && pVertexShader && pPixelShader) {
g_ActiveContext = This;
g_ActiveShareHandle = it->second.ShareHandle;
g_ActiveBrowser = it->second.ActiveBrowser;

bool paintFromTempGameTexture = false;

try {
Expand Down Expand Up @@ -624,7 +611,7 @@ HRESULT STDMETHODCALLTYPE My_CreateTexture2D(
if (SUCCEEDED(result) && *ppTexture2D) {
InstallTextureHooks(*ppTexture2D);

/* int activeBrowser = 0;
int activeBrowser = 0;
try {
std::unique_lock<std::mutex> lock(g_GpuPipeClientMutex);

Expand All @@ -637,9 +624,9 @@ HRESULT STDMETHODCALLTYPE My_CreateTexture2D(
<< e.what();
DebugBreak();
activeBrowser = 0;
}*/
}

if (true) {
if (activeBrowser) {
// ID3D11Texture2D* tempTexture = nullptr;

// if (SUCCEEDED(True_CreateTexture2D(This, &Desc, nullptr,
Expand All @@ -655,7 +642,7 @@ HRESULT STDMETHODCALLTYPE My_CreateTexture2D(
g_Textures.emplace(
std::piecewise_construct, std::make_tuple(pLastGoodTexture2d),
std::make_tuple(shareHandle, tempTextureShareHandle, view,
Desc.Width, Desc.Height, 0));
Desc.Width, Desc.Height, activeBrowser));

view->Release();
}
Expand Down
6 changes: 6 additions & 0 deletions afx-cefhud-interop/simple_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,10 @@ void SimpleApp::OnBeforeCommandLineProcessing(
"no-user-gesture-required");

//

command_line->AppendSwitch("disable-gpu-watchdog");
command_line->AppendSwitch("disable-hang-monitor");
command_line->AppendSwitch("disable-frame-rate-limit");
command_line->AppendSwitchWithValue("deadline-to-synchronize-surfaces",
"0");
}
5 changes: 3 additions & 2 deletions afx-cefhud-interop/simple_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ void SimpleHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {

std::unique_lock<std::mutex> lock(m_BrowserMutex);

m_NextBrowserId = browser->GetIdentifier() + 1;

if (NULL == browser->GetHost()->GetWindowHandle() &&
60 == browser->GetHost()->GetWindowlessFrameRate()) {
}
Expand Down Expand Up @@ -188,11 +186,14 @@ void SimpleHandler::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) {
auto it = m_Browsers.find(browser->GetIdentifier());
if (it != m_Browsers.end()) {
if (CHostPipeServerConnectionThread* connection = it->second.Connection) {
m_NextBrowserId = browser->GetIdentifier();

rect.Set(0, 0, connection->GetWidth(), connection->GetHeight());
return;
}
}

m_NextBrowserId = 0;
rect.Set(0, 0, 640, 480);
}

Expand Down
35 changes: 12 additions & 23 deletions afx-cefhud-interop/simple_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,12 @@ class SimpleHandler : public CefClient,

int GetHeight() { return m_Owner->Height; }

void OnRenderDone() {
}
void OnRenderDone() { }

/**
* @throws exception
*/
bool OnAfterClear(void* share_handle) {

std::unique_lock<std::mutex> lock2(m_DrawingMutex);
m_DrawingDone = false;

Expand All @@ -326,7 +324,6 @@ class SimpleHandler : public CefClient,
* @throws exception
*/
bool OnAfterRender(void* share_handle) {

std::unique_lock<std::mutex> lock2(m_DrawingMutex);
m_DrawingDone = false;

Expand Down Expand Up @@ -457,7 +454,6 @@ class SimpleHandler : public CefClient,

m_Owner->Browser->GetHost()->WasResized();
}

m_Owner->Browser->GetHost()->SendExternalBeginFrame();
} break;
case advancedfx::interop::HostMessage::CreateDrawing: {
Expand Down Expand Up @@ -555,8 +551,6 @@ class SimpleHandler : public CefClient,
bool m_DrawingDone = false;
bool m_DrawingResult = false;

bool m_FirstRender = true;

std::mutex m_RenderMutex;
std::condition_variable m_RenderCv;
bool m_RenderDone = false;
Expand All @@ -582,18 +576,15 @@ class SimpleHandler : public CefClient,
HANDLE handle) override {
//MessageBoxA(NULL, "B", "NEW", MB_OK);

int browserId = m_Host->m_NextBrowserId;

return new CGpuPipeServerConnectionThread(handle, this, browserId);
return new CGpuPipeServerConnectionThread(handle, this);
}

class CGpuPipeServerConnectionThread
: public advancedfx::interop::CPipeServerConnectionThread {
public:
CGpuPipeServerConnectionThread(HANDLE handle, CGpuPipeServer* host, int browserId)
CGpuPipeServerConnectionThread(HANDLE handle, CGpuPipeServer* host)
: advancedfx::interop::CPipeServerConnectionThread(handle),
m_Host(host),
m_BrowserId(browserId) {}
m_Host(host) {}

void DeleteExternal(std::unique_lock<std::mutex>& lock) {
m_ExternalAbort = true;
Expand All @@ -618,7 +609,7 @@ class SimpleHandler : public CefClient,
std::unique_lock<std::mutex> lock(m_Host->m_ConnectionsMutex);

auto emplaced = m_Host->m_Connections.emplace(
std::piecewise_construct, std::forward_as_tuple(m_BrowserId),
std::piecewise_construct, std::forward_as_tuple(processId),
std::forward_as_tuple(this));
}

Expand All @@ -632,23 +623,23 @@ class SimpleHandler : public CefClient,
m_Host->m_Host->ReleaseShareHandle(shareHandle);
} break;
case advancedfx::interop::HostGpuMessage::OnAfterClear: {

HANDLE sharedHandle = ReadHandle();
ReadInt32();
INT32 browserId = ReadInt32();
bool bResult =
m_Host->m_Host->OnAfterClear(m_BrowserId, sharedHandle);
m_Host->m_Host->OnAfterClear(browserId, sharedHandle);
WriteBoolean(bResult);
Flush();
} break;
case advancedfx::interop::HostGpuMessage::OnAfterRender: {
HANDLE sharedHandle = ReadHandle();
ReadInt32();
bool bResult = m_Host->m_Host->OnAfterRender(m_BrowserId, sharedHandle);
INT32 browserId = ReadInt32();
bool bResult =
m_Host->m_Host->OnAfterRender(browserId, sharedHandle);
WriteBoolean(bResult);
Flush();
} break;
case advancedfx::interop::HostGpuMessage::GetActiveBrowser: {
WriteInt32(0);
WriteInt32(m_Host->m_Host->m_NextBrowserId);
Flush();
} break;
default:
Expand Down Expand Up @@ -680,8 +671,6 @@ class SimpleHandler : public CefClient,
bool m_Quit = false;
bool m_ExternalAbort = false;
CGpuPipeServer* m_Host;

int m_BrowserId;
};

SimpleHandler* m_Host;
Expand Down Expand Up @@ -722,7 +711,7 @@ class SimpleHandler : public CefClient,
std::mutex m_BrowserMutex;
std::map<int, BrowserMapElem> m_Browsers;
std::map<HANDLE, int> m_HandleToBrowserId;
int m_NextBrowserId = 1;
int m_NextBrowserId = 0;

bool m_Creating = true;

Expand Down

0 comments on commit e38d4b3

Please sign in to comment.