Skip to content

Commit

Permalink
Backup, shuld work now.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtugend committed Aug 6, 2021
1 parent 3b638d6 commit e97f376
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 58 deletions.
59 changes: 27 additions & 32 deletions afx-cefhud-interop/assets/examples/default/drawing.html
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,6 @@ <h2>Last game events:</h2>

let {frameCount: clientFrameCount, pass: clientPass} = await Utils.toPromise(self.interop, "pumpBegin");

let frameGap = frameCount - Utils.coalesce(self.lastFrameCount, frameCount - 1);

self.lastFrameCount = frameCount;

if(frameGap != 1) {
await Utils.toPromise(self.interop, "pumpSkip");
}

let cmp = frameCount - clientFrameCount;
if(0 == cmp) cmp = pass - clientPass;

Expand Down Expand Up @@ -782,43 +774,46 @@ <h2>Last game events:</h2>
// 1) CEF can spit out intermediate frames (e.g. when GIFs are animating).
// 2) CEF spits out the previous frame, not the current frame.

let animationFrame = false;
let rendered = false;
window.requestAnimationFrame(function(timestamp){
animationFrame = true;
});
let animationFrame = 0;
let resultShareHandle;
function onAnimationFrame(timestamp) {
++animationFrame;
if(animationFrame < 2)
window.requestAnimationFrame(onAnimationFrame);
}
window.requestAnimationFrame(onAnimationFrame);

while(!rendered) {
try {
try {
while(animationFrame < 2) {
await Utils.toPromise(self.interop, "cefBeginFrame", width, height, {
"onAfterClear": function(resolve,reject,shareHandle) {
if(0 == animationFrame) {
resolve(false);
return;
}
onAfterClear(shareHandle,width,height).then(()=>{
resolve(true);
}).catch((e)=>{
reject(e);
});
}
, "onAfterRender": function(resolve,reject,shareHandle) {
if(animationFrame) {
rendered = true;
onAfterRender(shareHandle,x,y,width,height).then(()=>{
resolve(true);
}).catch((e)=>{
reject(e);
});
} else
resolve(false);
resultShareHandle = shareHandle;
resolve(false);
}
});
} catch(e) {
console.log(e);
if(e && e.soft) {
Utils.logError(e);
await Utils.toPromise(self.interop, "pumpFinish");
return;
}
throw e;
}

await onAfterRender(resultShareHandle,x,y,width,height);

} catch(e) {
console.log(e);
if(e && e.soft) {
Utils.logError(e);
await Utils.toPromise(self.interop, "pumpFinish");
return;
}
throw e;
}

await Utils.toPromise(self.interop, "pumpFinish");
Expand Down
20 changes: 9 additions & 11 deletions afx-cefhud-interop/assets/examples/default/engine.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,18 +376,16 @@
doConnect()
.then(()=>{
function pumper() {
if(self.connected) {
Utils.toPromise(self.interop, "pump", self.pumpEvents).then(()=>{
queueMicrotask(pumper);
}).catch((e) => {
Utils.logError(e);
Utils.toPromise(self.interop, "pump", self.pumpEvents).then(()=>{
queueMicrotask(pumper);
}).catch((e) => {
Utils.logError(e);

if(!(e && e.soft))
return Utils.toPromise(self, "disconnect");
if(!(e && e.soft))
return Utils.toPromise(self, "disconnect");

queueMicrotask(pumper);
});
}
queueMicrotask(pumper);
});
}

pumper();
Expand All @@ -396,7 +394,7 @@
}

AfxEngineInterop.prototype.disconnect = async function() {

this.interop.cancel();
this.messagePromises = {};
this.pumpPromise = Promise.resolve();
Expand Down
4 changes: 2 additions & 2 deletions afx-cefhud-interop/assets/examples/default/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ <h1>Default example</h1>

await this.reconnect();
},
"drawingConnected": async function(engineInteropId) {
"drawingConnected": async function(drawingInteropId) {
this.elDrawingStatus.innerText = "connected";
},
"drawingDisconnected": async function(engineInteropId) {
"drawingDisconnected": async function(drawingInteropId) {
this.elDrawingStatus.innerText = "DISCONNECTED";
}
};
Expand Down
6 changes: 3 additions & 3 deletions afx-cefhud-interop/cefsimple_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ const char* g_szPixelShaderCode =
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12,
D3D11_INPUT_PER_VERTEX_DATA, 0}};

/* BUGGED DON'T USE.
bool AfxWaitForGPU(ID3D11DeviceContext* pCtx) {
if(!g_pDevice) return false;

Expand All @@ -172,7 +171,6 @@ bool AfxWaitForGPU(ID3D11DeviceContext* pCtx) {

return bOk;
}
*/

class CGpuPipeClient : public advancedfx::interop::CPipeClient
{
Expand Down Expand Up @@ -254,7 +252,7 @@ _In_ ID3D11Resource* pSrcResource) {
it->second.FirstClear = true;
++it->second.FlushCount;

// AfxWaitForGPU(This);
AfxWaitForGPU(This);

try {
g_GpuPipeClient.WriteInt32(
Expand Down Expand Up @@ -320,6 +318,8 @@ My_ClearRenderTargetView(ID3D11DeviceContext* This,
if (pInputLayout && pVertexBuffer && pVertexShader && pPixelShader) {
bool paintFromTempGameTexture = false;

AfxWaitForGPU(This);

try {
std::unique_lock<std::mutex> lock(g_GpuPipeClientMutex);

Expand Down
7 changes: 6 additions & 1 deletion afx-cefhud-interop/simple_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void SimpleApp::OnBeforeCommandLineProcessing(
command_line->AppendSwitch("disable-hang-monitor");

command_line->AppendSwitch("disable-frame-rate-limit");
command_line->AppendSwitchWithValue("deadline-to-synchronize-surfaces", "0");
//command_line->AppendSwitchWithValue("deadline-to-synchronize-surfaces", "0");

//command_line->AppendSwitch("disable-threaded-animation");
//command_line->AppendSwitch("disable-threaded-scrolling");
Expand All @@ -280,4 +280,9 @@ void SimpleApp::OnBeforeCommandLineProcessing(
//command_line->AppendSwitch("enable-main-frame-before-activation");

command_line->AppendSwitch("disable-backgrounding-occluded-windows");
command_line->AppendSwitch("disable-renderer-backgrounding");

command_line->AppendSwitch("disable-new-content-rendering-timeout");

command_line->AppendSwitch("headless");
}
3 changes: 0 additions & 3 deletions afx-cefhud-interop/simple_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,11 @@ 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
18 changes: 12 additions & 6 deletions afx-cefhud-interop/simple_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class SimpleHandler : public CefClient,
OnRenderDone(browserId, shared_handle);
}

virtual bool GetScreenInfo(CefRefPtr<CefBrowser> browser,
CefScreenInfo& screen_info) OVERRIDE {
m_NextBrowserId = browser->GetIdentifier();
return false;
}

virtual void GetViewRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) OVERRIDE;

Expand Down Expand Up @@ -638,17 +644,17 @@ class SimpleHandler : public CefClient,
} break;
case advancedfx::interop::HostGpuMessage::OnAfterClear: {
HANDLE sharedHandle = ReadHandle();
INT32 browserId = ReadInt32();
bool bResult =
m_Host->m_Host->OnAfterClear(browserId, sharedHandle);
ReadInt32();
bool bResult = m_Host->m_Host->OnAfterClear(
m_Host->m_Host->m_NextBrowserId, sharedHandle);
WriteBoolean(bResult);
Flush();
} break;
case advancedfx::interop::HostGpuMessage::OnAfterRender: {
HANDLE sharedHandle = ReadHandle();
INT32 browserId = ReadInt32();
bool bResult =
m_Host->m_Host->OnAfterRender(browserId, sharedHandle);
ReadInt32();
bool bResult = m_Host->m_Host->OnAfterRender(
m_Host->m_Host->m_NextBrowserId, sharedHandle);
WriteBoolean(bResult);
Flush();
} break;
Expand Down

0 comments on commit e97f376

Please sign in to comment.