Bug 1828192 [Linux] Implement GfxInfo::FireTestProcess() and use it to run VA-API testing r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D175866
This commit is contained in:
stransky 2023-04-20 08:54:17 +00:00
Родитель 5c134bc785
Коммит 2f37fa4403
4 изменённых файлов: 35 добавлений и 14 удалений

Просмотреть файл

@ -256,6 +256,7 @@
#ifdef USE_GLX_TEST #ifdef USE_GLX_TEST
# include "mozilla/GUniquePtr.h" # include "mozilla/GUniquePtr.h"
# include "mozilla/GfxInfo.h"
#endif #endif
extern uint32_t gRestartMode; extern uint32_t gRestartMode;
@ -3704,6 +3705,8 @@ void fire_glxtest_process() {
close(pfd[1]); close(pfd[1]);
}); });
// Use G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_DO_NOT_REAP_CHILD flags
// to g_spawn_async_with_pipes() run posix_spawn() directly.
GUniquePtr<GError> err; GUniquePtr<GError> err;
g_spawn_async_with_pipes( g_spawn_async_with_pipes(
nullptr, argv, nullptr, nullptr, argv, nullptr,

Просмотреть файл

@ -533,8 +533,8 @@ void GfxInfo::GetData() {
AddCrashReportAnnotations(); AddCrashReportAnnotations();
} }
#ifdef MOZ_WAYLAND int GfxInfo::FireTestProcess(const nsAString& aBinaryFile, int* aOutPipe,
static int fire_vaapi_process(const char* aRenderDevicePath, int* aOutPipe) { const char** aStringArgs) {
nsCOMPtr<nsIFile> appFile; nsCOMPtr<nsIFile> appFile;
nsresult rv = XRE_GetBinaryPath(getter_AddRefs(appFile)); nsresult rv = XRE_GetBinaryPath(getter_AddRefs(appFile));
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
@ -547,30 +547,44 @@ static int fire_vaapi_process(const char* aRenderDevicePath, int* aOutPipe) {
gfxCriticalNote << "Couldn't get application directory.\n"; gfxCriticalNote << "Couldn't get application directory.\n";
return false; return false;
} }
exePath->Append(VAAPI_PROBE_BINARY); exePath->Append(aBinaryFile);
char* argv[] = {strdup(exePath->NativePath().get()), strdup("-d"), #define MAX_ARGS 8
strdup(aRenderDevicePath), nullptr}; char* argv[MAX_ARGS + 2];
auto freeArgv = mozilla::MakeScopeExit([&] {
for (auto& arg : argv) { argv[0] = strdup(exePath->NativePath().get());
free(arg); for (int i = 0; i < MAX_ARGS; i++) {
if (aStringArgs[i]) {
argv[i + 1] = strdup(aStringArgs[i]);
} else {
argv[i + 1] = nullptr;
break;
}
} }
});
// Use G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_DO_NOT_REAP_CHILD flags
// to g_spawn_async_with_pipes() run posix_spawn() directly.
int pid; int pid;
GUniquePtr<GError> err; GUniquePtr<GError> err;
g_spawn_async_with_pipes( g_spawn_async_with_pipes(
nullptr, argv, nullptr, nullptr, argv, nullptr,
GSpawnFlags(G_SPAWN_CLOEXEC_PIPES | G_SPAWN_DO_NOT_REAP_CHILD), nullptr, GSpawnFlags(G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_DO_NOT_REAP_CHILD),
nullptr, &pid, nullptr, aOutPipe, nullptr, getter_Transfers(err)); nullptr, nullptr, &pid, nullptr, aOutPipe, nullptr,
getter_Transfers(err));
if (err) { if (err) {
gfxCriticalNote << "Failed to probe VA-API hardware! " << err->message gfxCriticalNote << "FireTestProcess failed: " << err->message << "\n";
<< "\n";
pid = 0; pid = 0;
} }
for (auto& arg : argv) {
if (!arg) {
break;
}
free(arg);
}
return pid; return pid;
} }
#ifdef MOZ_WAYLAND
void GfxInfo::GetDataVAAPI() { void GfxInfo::GetDataVAAPI() {
if (mIsVAAPISupported.isSome()) { if (mIsVAAPISupported.isSome()) {
return; return;
@ -582,7 +596,8 @@ void GfxInfo::GetDataVAAPI() {
int vaapiPipe = -1; int vaapiPipe = -1;
int vaapiPID = 0; int vaapiPID = 0;
vaapiPID = fire_vaapi_process(mDrmRenderDevice.get(), &vaapiPipe); const char* args[] = {"-d", mDrmRenderDevice.get(), nullptr};
vaapiPID = FireTestProcess(VAAPI_PROBE_BINARY, &vaapiPipe, args);
if (!vaapiPID) { if (!vaapiPID) {
return; return;
} }

Просмотреть файл

@ -78,6 +78,8 @@ class GfxInfo final : public GfxInfoBase {
virtual bool DoesDriverVendorMatch(const nsAString& aBlocklistVendor, virtual bool DoesDriverVendorMatch(const nsAString& aBlocklistVendor,
const nsAString& aDriverVendor) override; const nsAString& aDriverVendor) override;
static int FireTestProcess(const nsAString& aBinaryFile, int* aOutPipe,
const char** aStringArgs);
private: private:
bool mInitialized = false; bool mInitialized = false;

Просмотреть файл

@ -33,6 +33,7 @@ EXPORTS += [
] ]
EXPORTS.mozilla += [ EXPORTS.mozilla += [
"GfxInfo.h",
"GfxInfoUtils.h", "GfxInfoUtils.h",
"GRefPtr.h", "GRefPtr.h",
"GUniquePtr.h", "GUniquePtr.h",