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:
@@ -23,13 +23,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;
|
||||
}
|
||||
@@ -37,8 +35,7 @@ void check(bool ok, const char* what)
|
||||
template <typename T>
|
||||
void release(T*& p)
|
||||
{
|
||||
if (p)
|
||||
{
|
||||
if (p) {
|
||||
p->Release();
|
||||
p = nullptr;
|
||||
}
|
||||
@@ -55,8 +52,7 @@ constexpr UINT kH = 720;
|
||||
int main()
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -68,15 +64,13 @@ int main()
|
||||
hook::IpcClient ipc;
|
||||
check(ipc.connect(10, 5), "IPC client connect");
|
||||
|
||||
if (!hook::install_d3d9_hooks(ipc))
|
||||
{
|
||||
if (!hook::install_d3d9_hooks(ipc)) {
|
||||
std::printf("SKIP: could not install the D3D9 Present hook (no d3d9.dll / device?)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
IDirect3D9* d3d = Direct3DCreate9(D3D_SDK_VERSION);
|
||||
if (d3d == nullptr)
|
||||
{
|
||||
if (d3d == nullptr) {
|
||||
std::printf("SKIP: Direct3DCreate9 failed\n");
|
||||
hook::remove_d3d9_hooks();
|
||||
return 0;
|
||||
@@ -101,8 +95,7 @@ int main()
|
||||
IDirect3DDevice9* dev = nullptr;
|
||||
HRESULT hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
|
||||
D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED, &pp, &dev);
|
||||
if (FAILED(hr) || dev == nullptr)
|
||||
{
|
||||
if (FAILED(hr) || dev == nullptr) {
|
||||
std::printf("SKIP: CreateDevice failed (hr=0x%08lX)\n", static_cast<unsigned long>(hr));
|
||||
release(d3d);
|
||||
hook::remove_d3d9_hooks();
|
||||
@@ -111,8 +104,7 @@ int main()
|
||||
|
||||
// Clear to a known color (R=51,G=102,B=153) and Present -> fires the detour.
|
||||
const D3DCOLOR color = D3DCOLOR_XRGB(51, 102, 153);
|
||||
for (int frame = 0; frame < 3; ++frame)
|
||||
{
|
||||
for (int frame = 0; frame < 3; ++frame) {
|
||||
dev->Clear(0, nullptr, D3DCLEAR_TARGET, color, 1.0f, 0);
|
||||
dev->Present(nullptr, nullptr, nullptr, nullptr);
|
||||
}
|
||||
@@ -132,18 +124,15 @@ int main()
|
||||
ID3D11Device* devB = nullptr;
|
||||
ID3D11DeviceContext* ctxB = nullptr;
|
||||
if (SUCCEEDED(D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, nullptr, 0, D3D11_SDK_VERSION,
|
||||
&devB, nullptr, &ctxB)))
|
||||
{
|
||||
&devB, nullptr, &ctxB))) {
|
||||
ID3D11Device1* dev1 = nullptr;
|
||||
devB->QueryInterface(IID_PPV_ARGS(&dev1));
|
||||
ID3D11Texture2D* sharedB = nullptr;
|
||||
IDXGIKeyedMutex* km = nullptr;
|
||||
const std::wstring name = video_share_name(GetCurrentProcessId());
|
||||
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);
|
||||
@@ -153,32 +142,24 @@ int main()
|
||||
sd.MiscFlags = 0;
|
||||
ID3D11Texture2D* staging = nullptr;
|
||||
check(SUCCEEDED(devB->CreateTexture2D(&sd, nullptr, &staging)), "create staging texture");
|
||||
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 mapped{};
|
||||
if (SUCCEEDED(ctxB->Map(staging, 0, D3D11_MAP_READ, 0, &mapped)))
|
||||
{
|
||||
if (SUCCEEDED(ctxB->Map(staging, 0, D3D11_MAP_READ, 0, &mapped))) {
|
||||
const auto* px = static_cast<const std::uint8_t*>(mapped.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 (BGRA->RGBA swizzle)");
|
||||
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