Phase 4
This commit is contained in:
@@ -23,10 +23,8 @@
|
||||
#include <vector>
|
||||
|
||||
OpenGLComposite::OpenGLComposite(HWND hWnd, HDC hDC, HGLRC hRC) :
|
||||
hGLWnd(hWnd), hGLDC(hDC), hGLRC(hRC),
|
||||
mScreenshotRequested(false)
|
||||
hGLWnd(hWnd), hGLDC(hDC), hGLRC(hRC)
|
||||
{
|
||||
InitializeCriticalSection(&pMutex);
|
||||
mRuntimeStore = std::make_unique<RuntimeStore>();
|
||||
mRuntimeEventDispatcher = std::make_unique<RuntimeEventDispatcher>();
|
||||
mRuntimeSnapshotProvider = std::make_unique<RuntimeSnapshotProvider>(mRuntimeStore->GetRenderSnapshotBuilder(), *mRuntimeEventDispatcher);
|
||||
@@ -34,11 +32,10 @@ OpenGLComposite::OpenGLComposite(HWND hWnd, HDC hDC, HGLRC hRC) :
|
||||
mRenderEngine = std::make_unique<RenderEngine>(
|
||||
*mRuntimeSnapshotProvider,
|
||||
mRuntimeStore->GetHealthTelemetry(),
|
||||
pMutex,
|
||||
hGLDC,
|
||||
hGLRC,
|
||||
[this]() { renderEffect(); },
|
||||
[this]() { ProcessScreenshotRequest(); },
|
||||
[]() {},
|
||||
[this]() { paintGL(false); });
|
||||
mVideoBackend = std::make_unique<VideoBackend>(*mRenderEngine, mRuntimeStore->GetHealthTelemetry(), *mRuntimeEventDispatcher);
|
||||
mShaderBuildQueue = std::make_unique<ShaderBuildQueue>(*mRuntimeSnapshotProvider, *mRuntimeEventDispatcher);
|
||||
@@ -61,8 +58,6 @@ OpenGLComposite::~OpenGLComposite()
|
||||
mShaderBuildQueue->Stop();
|
||||
if (mVideoBackend)
|
||||
mVideoBackend->ReleaseResources();
|
||||
|
||||
DeleteCriticalSection(&pMutex);
|
||||
}
|
||||
|
||||
bool OpenGLComposite::InitDeckLink()
|
||||
@@ -294,8 +289,50 @@ bool OpenGLComposite::ReloadShader(bool preserveFeedbackState)
|
||||
|
||||
bool OpenGLComposite::RequestScreenshot(std::string& error)
|
||||
{
|
||||
(void)error;
|
||||
mScreenshotRequested.store(true);
|
||||
if (!mRenderEngine || !mVideoBackend)
|
||||
{
|
||||
error = "The render engine is not ready.";
|
||||
return false;
|
||||
}
|
||||
|
||||
const unsigned width = mVideoBackend->OutputFrameWidth();
|
||||
const unsigned height = mVideoBackend->OutputFrameHeight();
|
||||
if (width == 0 || height == 0)
|
||||
{
|
||||
error = "The output frame size is not available.";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::filesystem::path outputPath;
|
||||
try
|
||||
{
|
||||
outputPath = BuildScreenshotPath();
|
||||
std::filesystem::create_directories(outputPath.parent_path());
|
||||
}
|
||||
catch (const std::exception& exception)
|
||||
{
|
||||
error = exception.what();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mRenderEngine->RequestScreenshotCapture(
|
||||
width,
|
||||
height,
|
||||
[outputPath](unsigned captureWidth, unsigned captureHeight, std::vector<unsigned char> topDownPixels) {
|
||||
try
|
||||
{
|
||||
WritePngFileAsync(outputPath, captureWidth, captureHeight, std::move(topDownPixels));
|
||||
}
|
||||
catch (const std::exception& exception)
|
||||
{
|
||||
OutputDebugStringA((std::string("Screenshot request failed: ") + exception.what() + "\n").c_str());
|
||||
}
|
||||
}))
|
||||
{
|
||||
error = "Screenshot capture request failed.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -342,32 +379,6 @@ void OpenGLComposite::RenderFrame(const RenderFrameInput& frameInput)
|
||||
mRenderEngine->RenderPreparedFrame(frameState);
|
||||
}
|
||||
|
||||
void OpenGLComposite::ProcessScreenshotRequest()
|
||||
{
|
||||
if (!mScreenshotRequested.exchange(false))
|
||||
return;
|
||||
|
||||
const unsigned width = mVideoBackend ? mVideoBackend->OutputFrameWidth() : 0;
|
||||
const unsigned height = mVideoBackend ? mVideoBackend->OutputFrameHeight() : 0;
|
||||
if (width == 0 || height == 0)
|
||||
return;
|
||||
|
||||
std::vector<unsigned char> topDownPixels;
|
||||
if (!mRenderEngine->CaptureOutputFrameRgbaTopDown(width, height, topDownPixels))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
const std::filesystem::path outputPath = BuildScreenshotPath();
|
||||
std::filesystem::create_directories(outputPath.parent_path());
|
||||
WritePngFileAsync(outputPath, width, height, std::move(topDownPixels));
|
||||
}
|
||||
catch (const std::exception& exception)
|
||||
{
|
||||
OutputDebugStringA((std::string("Screenshot request failed: ") + exception.what() + "\n").c_str());
|
||||
}
|
||||
}
|
||||
|
||||
std::filesystem::path OpenGLComposite::BuildScreenshotPath() const
|
||||
{
|
||||
const std::filesystem::path root = mRuntimeStore && !mRuntimeStore->GetRuntimeDataRoot().empty()
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "RenderFrameState.h"
|
||||
|
||||
#include <functional>
|
||||
#include <atomic>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -73,7 +72,6 @@ private:
|
||||
HWND hGLWnd;
|
||||
HDC hGLDC;
|
||||
HGLRC hGLRC;
|
||||
CRITICAL_SECTION pMutex;
|
||||
|
||||
std::unique_ptr<RuntimeStore> mRuntimeStore;
|
||||
std::unique_ptr<RuntimeCoordinator> mRuntimeCoordinator;
|
||||
@@ -84,13 +82,11 @@ private:
|
||||
std::unique_ptr<RuntimeServices> mRuntimeServices;
|
||||
std::unique_ptr<RuntimeUpdateController> mRuntimeUpdateController;
|
||||
std::unique_ptr<VideoBackend> mVideoBackend;
|
||||
std::atomic<bool> mScreenshotRequested;
|
||||
|
||||
bool InitOpenGLState();
|
||||
void renderEffect();
|
||||
RenderFrameInput BuildRenderFrameInput() const;
|
||||
void RenderFrame(const RenderFrameInput& frameInput);
|
||||
void ProcessScreenshotRequest();
|
||||
std::filesystem::path BuildScreenshotPath() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
enum class RenderCommandResetScope
|
||||
{
|
||||
@@ -31,6 +32,7 @@ struct RenderInputUploadRequest
|
||||
{
|
||||
VideoIOFrame inputFrame;
|
||||
VideoIOState videoState;
|
||||
std::vector<unsigned char> ownedBytes;
|
||||
};
|
||||
|
||||
struct RenderOutputFrameRequest
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
#include <gl/gl.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
RenderEngine::RenderEngine(
|
||||
RuntimeSnapshotProvider& runtimeSnapshotProvider,
|
||||
HealthTelemetry& healthTelemetry,
|
||||
CRITICAL_SECTION& mutex,
|
||||
HDC hdc,
|
||||
HGLRC hglrc,
|
||||
RenderEffectCallback renderEffect,
|
||||
@@ -17,7 +17,6 @@ RenderEngine::RenderEngine(
|
||||
mRenderPass(mRenderer),
|
||||
mRenderPipeline(mRenderer, runtimeSnapshotProvider, healthTelemetry, std::move(renderEffect), std::move(screenshotReady), std::move(previewPaint)),
|
||||
mShaderPrograms(mRenderer, runtimeSnapshotProvider),
|
||||
mMutex(mutex),
|
||||
mHdc(hdc),
|
||||
mHglrc(hglrc),
|
||||
mFrameStateResolver(runtimeSnapshotProvider)
|
||||
@@ -136,6 +135,24 @@ void RenderEngine::ReportRenderThreadRequestFailure(const char* operationName, c
|
||||
OutputDebugStringA(message.str().c_str());
|
||||
}
|
||||
|
||||
bool RenderEngine::IsRenderThreadAccessExpected() const
|
||||
{
|
||||
return !mRenderThreadRunning || GetCurrentThreadId() == mRenderThreadId;
|
||||
}
|
||||
|
||||
void RenderEngine::ReportWrongThreadRenderAccess(const char* operationName) const
|
||||
{
|
||||
if (IsRenderThreadAccessExpected())
|
||||
return;
|
||||
|
||||
std::ostringstream message;
|
||||
message << "Wrong-thread render access detected";
|
||||
if (operationName && operationName[0] != '\0')
|
||||
message << " [" << operationName << "]";
|
||||
message << ".\n";
|
||||
OutputDebugStringA(message.str().c_str());
|
||||
}
|
||||
|
||||
bool RenderEngine::CompileDecodeShader(int errorMessageSize, char* errorMessage)
|
||||
{
|
||||
return InvokeOnRenderThread([this, errorMessageSize, errorMessage]() {
|
||||
@@ -241,11 +258,13 @@ void RenderEngine::ApplyRuntimeCoordinatorRenderReset(RuntimeCoordinatorRenderRe
|
||||
|
||||
void RenderEngine::ResetTemporalHistoryStateOnRenderThread()
|
||||
{
|
||||
ReportWrongThreadRenderAccess("reset-temporal-history");
|
||||
mShaderPrograms.ResetTemporalHistoryState();
|
||||
}
|
||||
|
||||
void RenderEngine::ResetShaderFeedbackStateOnRenderThread()
|
||||
{
|
||||
ReportWrongThreadRenderAccess("reset-shader-feedback");
|
||||
mShaderPrograms.ResetShaderFeedbackState();
|
||||
}
|
||||
|
||||
@@ -276,6 +295,124 @@ void RenderEngine::ProcessRenderResetCommandsOnRenderThread()
|
||||
ApplyRenderResetOnRenderThread(resetScope);
|
||||
}
|
||||
|
||||
void RenderEngine::EnqueuePreviewPresentWake()
|
||||
{
|
||||
if (!mRenderThreadRunning || GetCurrentThreadId() == mRenderThreadId)
|
||||
return;
|
||||
|
||||
bool shouldNotify = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mRenderThreadMutex);
|
||||
if (!mRenderThreadStopping && !mPreviewPresentWakePending)
|
||||
{
|
||||
mPreviewPresentWakePending = true;
|
||||
mRenderThreadTasks.push([this]() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mRenderThreadMutex);
|
||||
mPreviewPresentWakePending = false;
|
||||
}
|
||||
ProcessPreviewPresentCommandsOnRenderThread();
|
||||
});
|
||||
shouldNotify = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldNotify)
|
||||
mRenderThreadCondition.notify_one();
|
||||
}
|
||||
|
||||
void RenderEngine::ProcessPreviewPresentCommandsOnRenderThread()
|
||||
{
|
||||
RenderPreviewPresentRequest request;
|
||||
if (mRenderCommandQueue.TryTakePreviewPresent(request))
|
||||
PresentPreviewOnRenderThread(request.outputFrameWidth, request.outputFrameHeight);
|
||||
}
|
||||
|
||||
void RenderEngine::EnqueueInputUploadWake()
|
||||
{
|
||||
if (!mRenderThreadRunning || GetCurrentThreadId() == mRenderThreadId)
|
||||
return;
|
||||
|
||||
bool shouldNotify = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mRenderThreadMutex);
|
||||
if (!mRenderThreadStopping && !mInputUploadWakePending)
|
||||
{
|
||||
mInputUploadWakePending = true;
|
||||
mRenderThreadTasks.push([this]() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mRenderThreadMutex);
|
||||
mInputUploadWakePending = false;
|
||||
}
|
||||
ProcessInputUploadCommandsOnRenderThread();
|
||||
});
|
||||
shouldNotify = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldNotify)
|
||||
mRenderThreadCondition.notify_one();
|
||||
}
|
||||
|
||||
void RenderEngine::ProcessInputUploadCommandsOnRenderThread()
|
||||
{
|
||||
RenderInputUploadRequest request;
|
||||
while (mRenderCommandQueue.TryTakeInputUpload(request))
|
||||
{
|
||||
if (request.ownedBytes.empty())
|
||||
continue;
|
||||
|
||||
request.inputFrame.bytes = request.ownedBytes.data();
|
||||
UploadInputFrameOnRenderThread(request.inputFrame, request.videoState);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderEngine::EnqueueScreenshotCaptureWake()
|
||||
{
|
||||
if (!mRenderThreadRunning || GetCurrentThreadId() == mRenderThreadId)
|
||||
return;
|
||||
|
||||
bool shouldNotify = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mRenderThreadMutex);
|
||||
if (!mRenderThreadStopping && !mScreenshotCaptureWakePending)
|
||||
{
|
||||
mScreenshotCaptureWakePending = true;
|
||||
mRenderThreadTasks.push([this]() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mRenderThreadMutex);
|
||||
mScreenshotCaptureWakePending = false;
|
||||
}
|
||||
ProcessScreenshotCaptureCommandsOnRenderThread();
|
||||
});
|
||||
shouldNotify = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldNotify)
|
||||
mRenderThreadCondition.notify_one();
|
||||
}
|
||||
|
||||
void RenderEngine::ProcessScreenshotCaptureCommandsOnRenderThread()
|
||||
{
|
||||
RenderScreenshotCaptureRequest request;
|
||||
ScreenshotCaptureCallback completion;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mRenderThreadMutex);
|
||||
completion = mScreenshotCaptureCompletion;
|
||||
}
|
||||
|
||||
while (mRenderCommandQueue.TryTakeScreenshotCapture(request))
|
||||
{
|
||||
if (!completion)
|
||||
continue;
|
||||
|
||||
std::vector<unsigned char> topDownPixels;
|
||||
if (CaptureOutputFrameRgbaTopDownOnRenderThread(request.width, request.height, topDownPixels))
|
||||
completion(request.width, request.height, std::move(topDownPixels));
|
||||
}
|
||||
}
|
||||
|
||||
void RenderEngine::ClearOscOverlayState()
|
||||
{
|
||||
mRuntimeLiveState.Clear();
|
||||
@@ -323,32 +460,62 @@ bool RenderEngine::TryPresentPreview(bool force, unsigned previewFps, unsigned o
|
||||
|
||||
if (mRenderThreadRunning)
|
||||
{
|
||||
return TryInvokeOnRenderThread("preview-present", [this, outputFrameWidth, outputFrameHeight]() {
|
||||
mRenderCommandQueue.RequestPreviewPresent({ outputFrameWidth, outputFrameHeight });
|
||||
RenderPreviewPresentRequest request;
|
||||
return mRenderCommandQueue.TryTakePreviewPresent(request) &&
|
||||
PresentPreviewOnRenderThread(request.outputFrameWidth, request.outputFrameHeight);
|
||||
});
|
||||
mRenderCommandQueue.RequestPreviewPresent({ outputFrameWidth, outputFrameHeight });
|
||||
if (GetCurrentThreadId() == mRenderThreadId)
|
||||
ProcessPreviewPresentCommandsOnRenderThread();
|
||||
else
|
||||
EnqueuePreviewPresentWake();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!TryEnterCriticalSection(&mMutex))
|
||||
return false;
|
||||
|
||||
mRenderCommandQueue.RequestPreviewPresent({ outputFrameWidth, outputFrameHeight });
|
||||
RenderPreviewPresentRequest request;
|
||||
const bool presented = mRenderCommandQueue.TryTakePreviewPresent(request) &&
|
||||
PresentPreviewOnRenderThread(request.outputFrameWidth, request.outputFrameHeight);
|
||||
LeaveCriticalSection(&mMutex);
|
||||
return presented;
|
||||
ReportRenderThreadRequestFailure("preview-present", "render thread is not running");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RenderEngine::PresentPreviewOnRenderThread(unsigned outputFrameWidth, unsigned outputFrameHeight)
|
||||
{
|
||||
ReportWrongThreadRenderAccess("preview-present");
|
||||
mRenderer.PresentToWindow(mHdc, outputFrameWidth, outputFrameHeight);
|
||||
mLastPreviewPresentTime = std::chrono::steady_clock::now();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderEngine::RequestScreenshotCapture(unsigned width, unsigned height, ScreenshotCaptureCallback completion)
|
||||
{
|
||||
if (width == 0 || height == 0 || !completion)
|
||||
return false;
|
||||
if (!mRenderThreadRunning)
|
||||
return false;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mRenderThreadMutex);
|
||||
mScreenshotCaptureCompletion = std::move(completion);
|
||||
}
|
||||
mRenderCommandQueue.RequestScreenshotCapture({ width, height });
|
||||
EnqueueScreenshotCaptureWake();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderEngine::QueueInputFrame(const VideoIOFrame& inputFrame, const VideoIOState& videoState)
|
||||
{
|
||||
if (inputFrame.hasNoInputSource || inputFrame.bytes == nullptr)
|
||||
return true;
|
||||
if (inputFrame.rowBytes <= 0 || inputFrame.height == 0)
|
||||
return false;
|
||||
|
||||
const std::size_t byteCount = static_cast<std::size_t>(inputFrame.rowBytes) * inputFrame.height;
|
||||
RenderInputUploadRequest request;
|
||||
request.inputFrame = inputFrame;
|
||||
request.videoState = videoState;
|
||||
request.ownedBytes.resize(byteCount);
|
||||
std::memcpy(request.ownedBytes.data(), inputFrame.bytes, byteCount);
|
||||
request.inputFrame.bytes = nullptr;
|
||||
|
||||
mRenderCommandQueue.RequestInputUpload(request);
|
||||
EnqueueInputUploadWake();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderEngine::TryUploadInputFrame(const VideoIOFrame& inputFrame, const VideoIOState& videoState)
|
||||
{
|
||||
if (inputFrame.hasNoInputSource || inputFrame.bytes == nullptr)
|
||||
@@ -364,21 +531,13 @@ bool RenderEngine::TryUploadInputFrame(const VideoIOFrame& inputFrame, const Vid
|
||||
});
|
||||
}
|
||||
|
||||
if (!TryEnterCriticalSection(&mMutex))
|
||||
return false;
|
||||
|
||||
wglMakeCurrent(mHdc, mHglrc);
|
||||
mRenderCommandQueue.RequestInputUpload({ inputFrame, videoState });
|
||||
RenderInputUploadRequest request;
|
||||
const bool uploaded = mRenderCommandQueue.TryTakeInputUpload(request) &&
|
||||
UploadInputFrameOnRenderThread(request.inputFrame, request.videoState);
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
LeaveCriticalSection(&mMutex);
|
||||
return uploaded;
|
||||
ReportRenderThreadRequestFailure("input-upload", "render thread is not running");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RenderEngine::UploadInputFrameOnRenderThread(const VideoIOFrame& inputFrame, const VideoIOState& videoState)
|
||||
{
|
||||
ReportWrongThreadRenderAccess("input-upload");
|
||||
const long textureSize = inputFrame.rowBytes * static_cast<long>(inputFrame.height);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
@@ -395,7 +554,7 @@ bool RenderEngine::UploadInputFrameOnRenderThread(const VideoIOFrame& inputFrame
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderEngine::RenderOutputFrame(const RenderPipelineFrameContext& context, VideoIOOutputFrame& outputFrame)
|
||||
bool RenderEngine::RequestOutputFrame(const RenderPipelineFrameContext& context, VideoIOOutputFrame& outputFrame)
|
||||
{
|
||||
if (mRenderThreadRunning)
|
||||
{
|
||||
@@ -407,20 +566,20 @@ bool RenderEngine::RenderOutputFrame(const RenderPipelineFrameContext& context,
|
||||
});
|
||||
}
|
||||
|
||||
EnterCriticalSection(&mMutex);
|
||||
wglMakeCurrent(mHdc, mHglrc);
|
||||
mRenderCommandQueue.RequestOutputFrame({ context.videoState, context.completion });
|
||||
RenderOutputFrameRequest request;
|
||||
const bool rendered = mRenderCommandQueue.TryTakeOutputFrame(request) &&
|
||||
RenderOutputFrameOnRenderThread({ request.videoState, request.completion }, outputFrame);
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
LeaveCriticalSection(&mMutex);
|
||||
return rendered;
|
||||
ReportRenderThreadRequestFailure("output-render", "render thread is not running");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RenderEngine::RenderOutputFrame(const RenderPipelineFrameContext& context, VideoIOOutputFrame& outputFrame)
|
||||
{
|
||||
return RequestOutputFrame(context, outputFrame);
|
||||
}
|
||||
|
||||
bool RenderEngine::RenderOutputFrameOnRenderThread(const RenderPipelineFrameContext& context, VideoIOOutputFrame& outputFrame)
|
||||
{
|
||||
ReportWrongThreadRenderAccess("output-render");
|
||||
ProcessRenderResetCommandsOnRenderThread();
|
||||
ProcessInputUploadCommandsOnRenderThread();
|
||||
return mRenderPipeline.RenderFrame(context, outputFrame);
|
||||
}
|
||||
|
||||
@@ -466,6 +625,7 @@ void RenderEngine::RenderLayerStack(
|
||||
VideoIOPixelFormat inputPixelFormat,
|
||||
unsigned historyCap)
|
||||
{
|
||||
ReportWrongThreadRenderAccess("render-layer-stack");
|
||||
mRenderPass.Render(
|
||||
hasInputSource,
|
||||
layerStates,
|
||||
@@ -484,6 +644,7 @@ void RenderEngine::RenderLayerStack(
|
||||
|
||||
bool RenderEngine::ReadOutputFrameRgbaOnRenderThread(unsigned width, unsigned height, std::vector<unsigned char>& bottomUpPixels)
|
||||
{
|
||||
ReportWrongThreadRenderAccess("read-output-frame-rgba");
|
||||
if (width == 0 || height == 0)
|
||||
return false;
|
||||
|
||||
@@ -510,15 +671,8 @@ bool RenderEngine::CaptureOutputFrameRgbaTopDown(unsigned width, unsigned height
|
||||
});
|
||||
}
|
||||
|
||||
EnterCriticalSection(&mMutex);
|
||||
wglMakeCurrent(mHdc, mHglrc);
|
||||
mRenderCommandQueue.RequestScreenshotCapture({ width, height });
|
||||
RenderScreenshotCaptureRequest request;
|
||||
const bool captured = mRenderCommandQueue.TryTakeScreenshotCapture(request) &&
|
||||
CaptureOutputFrameRgbaTopDownOnRenderThread(request.width, request.height, topDownPixels);
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
LeaveCriticalSection(&mMutex);
|
||||
return captured;
|
||||
ReportRenderThreadRequestFailure("screenshot-capture", "render thread is not running");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RenderEngine::CaptureOutputFrameRgbaTopDownOnRenderThread(unsigned width, unsigned height, std::vector<unsigned char>& topDownPixels)
|
||||
|
||||
@@ -33,6 +33,7 @@ class RenderEngine
|
||||
public:
|
||||
using RenderEffectCallback = std::function<void()>;
|
||||
using ScreenshotCallback = std::function<void()>;
|
||||
using ScreenshotCaptureCallback = std::function<void(unsigned, unsigned, std::vector<unsigned char>)>;
|
||||
using PreviewPaintCallback = std::function<void()>;
|
||||
|
||||
struct OscOverlayUpdate
|
||||
@@ -61,7 +62,6 @@ public:
|
||||
RenderEngine(
|
||||
RuntimeSnapshotProvider& runtimeSnapshotProvider,
|
||||
HealthTelemetry& healthTelemetry,
|
||||
CRITICAL_SECTION& mutex,
|
||||
HDC hdc,
|
||||
HGLRC hglrc,
|
||||
RenderEffectCallback renderEffect,
|
||||
@@ -100,7 +100,10 @@ public:
|
||||
const std::vector<OscOverlayCommitCompletion>& completedCommits);
|
||||
void ResizeView(int width, int height);
|
||||
bool TryPresentPreview(bool force, unsigned previewFps, unsigned outputFrameWidth, unsigned outputFrameHeight);
|
||||
bool RequestScreenshotCapture(unsigned width, unsigned height, ScreenshotCaptureCallback completion);
|
||||
bool QueueInputFrame(const VideoIOFrame& inputFrame, const VideoIOState& videoState);
|
||||
bool TryUploadInputFrame(const VideoIOFrame& inputFrame, const VideoIOState& videoState);
|
||||
bool RequestOutputFrame(const RenderPipelineFrameContext& context, VideoIOOutputFrame& outputFrame);
|
||||
bool RenderOutputFrame(const RenderPipelineFrameContext& context, VideoIOOutputFrame& outputFrame);
|
||||
bool ResolveRenderFrameState(
|
||||
const RenderFrameInput& input,
|
||||
@@ -178,6 +181,8 @@ private:
|
||||
|
||||
void RenderThreadMain(std::promise<bool> ready);
|
||||
void ReportRenderThreadRequestFailure(const char* operationName, const char* reason);
|
||||
bool IsRenderThreadAccessExpected() const;
|
||||
void ReportWrongThreadRenderAccess(const char* operationName) const;
|
||||
bool CommitPreparedLayerPrograms(const PreparedShaderBuild& preparedBuild, unsigned inputFrameWidth, unsigned inputFrameHeight, int errorMessageSize, char* errorMessage);
|
||||
void RenderLayerStack(
|
||||
bool hasInputSource,
|
||||
@@ -191,6 +196,12 @@ private:
|
||||
void ResetShaderFeedbackStateOnRenderThread();
|
||||
void ApplyRenderResetOnRenderThread(RenderCommandResetScope resetScope);
|
||||
void ProcessRenderResetCommandsOnRenderThread();
|
||||
void EnqueuePreviewPresentWake();
|
||||
void ProcessPreviewPresentCommandsOnRenderThread();
|
||||
void EnqueueInputUploadWake();
|
||||
void ProcessInputUploadCommandsOnRenderThread();
|
||||
void EnqueueScreenshotCaptureWake();
|
||||
void ProcessScreenshotCaptureCommandsOnRenderThread();
|
||||
bool PresentPreviewOnRenderThread(unsigned outputFrameWidth, unsigned outputFrameHeight);
|
||||
bool UploadInputFrameOnRenderThread(const VideoIOFrame& inputFrame, const VideoIOState& videoState);
|
||||
bool RenderOutputFrameOnRenderThread(const RenderPipelineFrameContext& context, VideoIOOutputFrame& outputFrame);
|
||||
@@ -201,7 +212,6 @@ private:
|
||||
OpenGLRenderPass mRenderPass;
|
||||
OpenGLRenderPipeline mRenderPipeline;
|
||||
OpenGLShaderPrograms mShaderPrograms;
|
||||
CRITICAL_SECTION& mMutex;
|
||||
HDC mHdc;
|
||||
HGLRC mHglrc;
|
||||
|
||||
@@ -216,5 +226,9 @@ private:
|
||||
std::queue<std::function<void()>> mRenderThreadTasks;
|
||||
std::atomic<bool> mRenderThreadRunning = false;
|
||||
bool mRenderThreadStopping = false;
|
||||
bool mPreviewPresentWakePending = false;
|
||||
bool mInputUploadWakePending = false;
|
||||
bool mScreenshotCaptureWakePending = false;
|
||||
ScreenshotCaptureCallback mScreenshotCaptureCompletion;
|
||||
bool mResourcesDestroyed = false;
|
||||
};
|
||||
|
||||
@@ -12,14 +12,14 @@ void OpenGLVideoIOBridge::UploadInputFrame(const VideoIOFrame& inputFrame, const
|
||||
if (inputFrame.hasNoInputSource || inputFrame.bytes == nullptr)
|
||||
return; // don't transfer texture when there's no input
|
||||
|
||||
mRenderEngine.TryUploadInputFrame(inputFrame, state);
|
||||
mRenderEngine.QueueInputFrame(inputFrame, state);
|
||||
}
|
||||
|
||||
void OpenGLVideoIOBridge::RenderScheduledFrame(const VideoIOState& state, const VideoIOCompletion& completion, VideoIOOutputFrame& outputFrame)
|
||||
bool OpenGLVideoIOBridge::RenderScheduledFrame(const VideoIOState& state, const VideoIOCompletion& completion, VideoIOOutputFrame& outputFrame)
|
||||
{
|
||||
RenderPipelineFrameContext frameContext;
|
||||
frameContext.videoState = state;
|
||||
frameContext.completion = completion;
|
||||
|
||||
mRenderEngine.RenderOutputFrame(frameContext, outputFrame);
|
||||
return mRenderEngine.RequestOutputFrame(frameContext, outputFrame);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public:
|
||||
explicit OpenGLVideoIOBridge(RenderEngine& renderEngine);
|
||||
|
||||
void UploadInputFrame(const VideoIOFrame& inputFrame, const VideoIOState& state);
|
||||
void RenderScheduledFrame(const VideoIOState& state, const VideoIOCompletion& completion, VideoIOOutputFrame& outputFrame);
|
||||
bool RenderScheduledFrame(const VideoIOState& state, const VideoIOCompletion& completion, VideoIOOutputFrame& outputFrame);
|
||||
|
||||
private:
|
||||
RenderEngine& mRenderEngine;
|
||||
|
||||
@@ -232,11 +232,17 @@ void VideoBackend::HandleOutputFrameCompletion(const VideoIOCompletion& completi
|
||||
return;
|
||||
|
||||
const VideoIOState& state = mVideoIODevice->State();
|
||||
bool rendered = true;
|
||||
if (mBridge)
|
||||
mBridge->RenderScheduledFrame(state, completion, outputFrame);
|
||||
rendered = mBridge->RenderScheduledFrame(state, completion, outputFrame);
|
||||
|
||||
EndOutputFrame(outputFrame);
|
||||
AccountForCompletionResult(completion.result);
|
||||
if (!rendered)
|
||||
{
|
||||
PublishBackendStateChanged("output-render-failed", "Output frame render request failed; skipping schedule for this frame.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Schedule the next frame after render work is complete so device-side
|
||||
// bookkeeping stays with the backend seam and the bridge stays render-only.
|
||||
|
||||
Reference in New Issue
Block a user