Apply clang-format across the whole tree
Run clang-format (the repo's .clang-format: LLVM base, 120 cols, tabs, Allman functions) over every source file so the tree is formatter-clean. Whitespace only -- no behavior change; full x64 + x86 suites pass. Also set SortIncludes: false in .clang-format. Windows include order is load-bearing (windows.h must precede tlhelp32.h / mmreg.h / xinput.h / dinput.h; winsock2.h must precede windows.h), and the default alphabetical sort reorders tlhelp32.h ahead of windows.h -- a build break. Leaving order alone keeps the manual, correct grouping.
This commit is contained in:
@@ -28,13 +28,11 @@
|
||||
|
||||
using namespace coop;
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
int g_failures = 0;
|
||||
void check(bool ok, const char* what)
|
||||
{
|
||||
if (!ok)
|
||||
{
|
||||
if (!ok) {
|
||||
std::printf(" FAIL: %s\n", what);
|
||||
++g_failures;
|
||||
}
|
||||
@@ -42,8 +40,7 @@ void check(bool ok, const char* what)
|
||||
template <typename T>
|
||||
void release(T*& p)
|
||||
{
|
||||
if (p)
|
||||
{
|
||||
if (p) {
|
||||
p->Release();
|
||||
p = nullptr;
|
||||
}
|
||||
@@ -64,8 +61,7 @@ int main()
|
||||
{
|
||||
// --- Host side: SharedBlock so the hook's IpcClient connects. ---
|
||||
SharedMemory shm;
|
||||
if (!shm.create(shared_memory_name(GetCurrentProcessId()), sizeof(SharedBlock)))
|
||||
{
|
||||
if (!shm.create(shared_memory_name(GetCurrentProcessId()), sizeof(SharedBlock))) {
|
||||
std::printf("FAIL: create shared memory\n");
|
||||
return 1;
|
||||
}
|
||||
@@ -77,8 +73,7 @@ int main()
|
||||
hook::IpcClient ipc;
|
||||
check(ipc.connect(10, 5), "IPC client connect");
|
||||
|
||||
if (!hook::install_opengl_hooks(ipc))
|
||||
{
|
||||
if (!hook::install_opengl_hooks(ipc)) {
|
||||
std::printf("SKIP: could not install the OpenGL swap hooks\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -92,8 +87,8 @@ int main()
|
||||
RegisterClassExW(&wc);
|
||||
// WS_POPUP so the client area is exactly kW x kH (an overlapped window can't
|
||||
// shrink below its minimum caption size, which would skew the captured dims).
|
||||
HWND hwnd = CreateWindowExW(0, wc.lpszClassName, L"", WS_POPUP, 0, 0, kW, kH, nullptr, nullptr,
|
||||
wc.hInstance, nullptr);
|
||||
HWND hwnd =
|
||||
CreateWindowExW(0, wc.lpszClassName, L"", WS_POPUP, 0, 0, kW, kH, nullptr, nullptr, wc.hInstance, nullptr);
|
||||
ShowWindow(hwnd, SW_SHOWNOACTIVATE); // a mapped window makes the backbuffer reliable
|
||||
HDC hdc = GetDC(hwnd);
|
||||
|
||||
@@ -105,17 +100,15 @@ int main()
|
||||
pfd.cColorBits = 32;
|
||||
const int pf = ChoosePixelFormat(hdc, &pfd);
|
||||
HGLRC glrc = nullptr;
|
||||
if (pf == 0 || !SetPixelFormat(hdc, pf, &pfd) || (glrc = wglCreateContext(hdc)) == nullptr ||
|
||||
!wglMakeCurrent(hdc, glrc))
|
||||
{
|
||||
if (pf == 0 || !SetPixelFormat(hdc, pf, &pfd) || (glrc = wglCreateContext(hdc)) == nullptr
|
||||
|| !wglMakeCurrent(hdc, glrc)) {
|
||||
std::printf("SKIP: could not create an OpenGL context on this machine\n");
|
||||
hook::remove_opengl_hooks();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Clear the backbuffer to a known color, then SwapBuffers (fires the detour).
|
||||
for (int frame = 0; frame < 3; ++frame)
|
||||
{
|
||||
for (int frame = 0; frame < 3; ++frame) {
|
||||
glViewport(0, 0, kW, kH);
|
||||
glClearColor(0.20f, 0.40f, 0.60f, 1.0f); // -> ~{51,102,153,255}
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
@@ -134,23 +127,19 @@ int main()
|
||||
check(block->video.width == kW && block->video.height == kH, "shared dimensions published");
|
||||
|
||||
// --- Consumer: open the shared texture by name, copy to staging, verify color.
|
||||
if (hook::opengl_frames_shared() > 0)
|
||||
{
|
||||
if (hook::opengl_frames_shared() > 0) {
|
||||
ID3D11Device* devB = nullptr;
|
||||
ID3D11DeviceContext* ctxB = nullptr;
|
||||
if (SUCCEEDED(D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, nullptr, 0,
|
||||
D3D11_SDK_VERSION, &devB, nullptr, &ctxB)))
|
||||
{
|
||||
if (SUCCEEDED(D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, nullptr, 0, D3D11_SDK_VERSION,
|
||||
&devB, nullptr, &ctxB))) {
|
||||
ID3D11Device1* dev1 = nullptr;
|
||||
devB->QueryInterface(IID_PPV_ARGS(&dev1));
|
||||
const std::wstring name = video_share_name(GetCurrentProcessId());
|
||||
ID3D11Texture2D* sharedB = nullptr;
|
||||
IDXGIKeyedMutex* km = nullptr;
|
||||
if (dev1 != nullptr &&
|
||||
SUCCEEDED(dev1->OpenSharedResourceByName(name.c_str(),
|
||||
DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE,
|
||||
IID_PPV_ARGS(&sharedB))))
|
||||
{
|
||||
if (dev1 != nullptr
|
||||
&& SUCCEEDED(dev1->OpenSharedResourceByName(
|
||||
name.c_str(), DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, IID_PPV_ARGS(&sharedB)))) {
|
||||
sharedB->QueryInterface(IID_PPV_ARGS(&km));
|
||||
D3D11_TEXTURE2D_DESC sd{};
|
||||
sharedB->GetDesc(&sd);
|
||||
@@ -160,32 +149,24 @@ int main()
|
||||
sd.MiscFlags = 0;
|
||||
ID3D11Texture2D* staging = nullptr;
|
||||
devB->CreateTexture2D(&sd, nullptr, &staging);
|
||||
if (km != nullptr && staging != nullptr && km->AcquireSync(kVideoMutexKey, 1000) == S_OK)
|
||||
{
|
||||
if (km != nullptr && staging != nullptr && km->AcquireSync(kVideoMutexKey, 1000) == S_OK) {
|
||||
ctxB->CopyResource(staging, sharedB);
|
||||
km->ReleaseSync(kVideoMutexKey);
|
||||
D3D11_MAPPED_SUBRESOURCE m{};
|
||||
if (SUCCEEDED(ctxB->Map(staging, 0, D3D11_MAP_READ, 0, &m)))
|
||||
{
|
||||
if (SUCCEEDED(ctxB->Map(staging, 0, D3D11_MAP_READ, 0, &m))) {
|
||||
const auto* px = static_cast<const std::uint8_t*>(m.pData);
|
||||
std::printf("readback pixel0 = {%u,%u,%u,%u}\n", px[0], px[1], px[2], px[3]);
|
||||
check(near_byte(px[0], 51) && near_byte(px[1], 102) && near_byte(px[2], 153),
|
||||
"shared texture carries the rendered color");
|
||||
ctxB->Unmap(staging, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
check(false, "map staging texture");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
check(false, "acquire keyed mutex + copy shared texture");
|
||||
}
|
||||
release(staging);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
check(false, "open shared texture by name");
|
||||
}
|
||||
release(km);
|
||||
|
||||
Reference in New Issue
Block a user