Allow running Samples against native GL.

Useful for perf testing/comparison.

Bug: angleproject:4729
Change-Id: Ic46424570dcef0a30d506962f546910ba7440595
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2241620
Reviewed-by: Jonah Ryan-Davis <jonahr@google.com>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
This commit is contained in:
Jamie Madill 2020-06-11 13:32:10 -04:00 коммит произвёл Commit Bot
Родитель 31bbe1ba08
Коммит 11e26fa006
6 изменённых файлов: 73 добавлений и 32 удалений

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

@ -6,6 +6,7 @@
#include "SampleApplication.h"
#include "common/debug.h"
#include "util/EGLWindow.h"
#include "util/gles_loader_autogen.h"
#include "util/random_utils.h"
@ -15,9 +16,14 @@
#include <iostream>
#include <utility>
#if defined(ANGLE_PLATFORM_WINDOWS)
# include "util/windows/WGLWindow.h"
#endif // defined(ANGLE_PLATFORM_WINDOWS)
namespace
{
const char *kUseAngleArg = "--use-angle=";
const char *kUseGlArg = "--use-gl=native";
using DisplayTypeInfo = std::pair<const char *, EGLint>;
@ -71,29 +77,56 @@ SampleApplication::SampleApplication(std::string name,
mWidth(width),
mHeight(height),
mRunning(false),
mGLWindow(nullptr),
mEGLWindow(nullptr),
mOSWindow(nullptr)
mOSWindow(nullptr),
mDriverType(angle::GLESDriverType::AngleEGL)
{
mPlatformParams.renderer = EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE;
bool useNativeGL = false;
if (argc > 1 && strncmp(argv[1], kUseAngleArg, strlen(kUseAngleArg)) == 0)
for (int argIndex = 1; argIndex < argc; argIndex++)
{
const char *arg = argv[1] + strlen(kUseAngleArg);
mPlatformParams.renderer = GetDisplayTypeFromArg(arg);
mPlatformParams.deviceType = GetDeviceTypeFromArg(arg);
if (strncmp(argv[argIndex], kUseAngleArg, strlen(kUseAngleArg)) == 0)
{
const char *arg = argv[argIndex] + strlen(kUseAngleArg);
mPlatformParams.renderer = GetDisplayTypeFromArg(arg);
mPlatformParams.deviceType = GetDeviceTypeFromArg(arg);
}
if (strncmp(argv[argIndex], kUseGlArg, strlen(kUseGlArg)) == 0)
{
useNativeGL = true;
}
}
// Load EGL library so we can initialize the display.
mEntryPointsLib.reset(
angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME, angle::SearchType::ApplicationDir));
mOSWindow = OSWindow::New();
mEGLWindow = EGLWindow::New(glesMajorVersion, glesMinorVersion);
mOSWindow = OSWindow::New();
// Load EGL library so we can initialize the display.
if (useNativeGL)
{
#if defined(ANGLE_PLATFORM_WINDOWS)
mGLWindow = WGLWindow::New(glesMajorVersion, glesMinorVersion);
mEntryPointsLib.reset(angle::OpenSharedLibrary("opengl32", angle::SearchType::SystemDir));
mDriverType = angle::GLESDriverType::SystemWGL;
#else
mGLWindow = EGLWindow::New(glesMajorVersion, glesMinorVersion);
mEntryPointsLib.reset(
angle::OpenSharedLibraryWithExtension(angle::GetNativeEGLLibraryNameWithExtension()));
mDriverType = angle::GLESDriverType::SystemEGL;
#endif // defined(ANGLE_PLATFORM_WINDOWS)
}
else
{
mGLWindow = mEGLWindow = EGLWindow::New(glesMajorVersion, glesMinorVersion);
mEntryPointsLib.reset(
angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME, angle::SearchType::ApplicationDir));
}
}
SampleApplication::~SampleApplication()
{
EGLWindow::Delete(&mEGLWindow);
GLWindowBase::Delete(&mGLWindow);
OSWindow::Delete(&mOSWindow);
}
@ -110,7 +143,7 @@ void SampleApplication::draw() {}
void SampleApplication::swap()
{
mEGLWindow->swap();
mGLWindow->swap();
}
OSWindow *SampleApplication::getWindow() const
@ -120,21 +153,25 @@ OSWindow *SampleApplication::getWindow() const
EGLConfig SampleApplication::getConfig() const
{
ASSERT(mEGLWindow);
return mEGLWindow->getConfig();
}
EGLDisplay SampleApplication::getDisplay() const
{
ASSERT(mEGLWindow);
return mEGLWindow->getDisplay();
}
EGLSurface SampleApplication::getSurface() const
{
ASSERT(mEGLWindow);
return mEGLWindow->getSurface();
}
EGLContext SampleApplication::getContext() const
{
ASSERT(mEGLWindow);
return mEGLWindow->getContext();
}
@ -155,20 +192,18 @@ int SampleApplication::run()
configParams.depthBits = 24;
configParams.stencilBits = 8;
if (!mEGLWindow->initializeGL(mOSWindow, mEntryPointsLib.get(), angle::GLESDriverType::AngleEGL,
mPlatformParams, configParams))
if (!mGLWindow->initializeGL(mOSWindow, mEntryPointsLib.get(), mDriverType, mPlatformParams,
configParams))
{
return -1;
}
// Disable vsync
if (!mEGLWindow->setSwapInterval(0))
if (!mGLWindow->setSwapInterval(0))
{
return -1;
}
angle::LoadGLES(eglGetProcAddress);
mRunning = true;
int result = 0;
@ -223,7 +258,7 @@ int SampleApplication::run()
}
destroy();
mEGLWindow->destroyGL();
mGLWindow->destroyGL();
mOSWindow->destroy();
return result;

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

@ -19,6 +19,7 @@
#include "util/egl_loader_autogen.h"
class EGLWindow;
class GLWindowBase;
namespace angle
{
@ -66,8 +67,10 @@ class SampleApplication
bool mRunning;
Timer mTimer;
GLWindowBase *mGLWindow;
EGLWindow *mEGLWindow;
OSWindow *mOSWindow;
angle::GLESDriverType mDriverType;
EGLPlatformParameters mPlatformParams;

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

@ -784,18 +784,4 @@ PlatformParameters ES3_EGL()
{
return PlatformParameters(3, 0, GLESDriverType::SystemEGL);
}
const char *GetNativeEGLLibraryNameWithExtension()
{
#if defined(ANGLE_PLATFORM_ANDROID)
return "libEGL.so";
#elif defined(ANGLE_PLATFORM_LINUX)
return "libEGL.so.1";
#elif defined(ANGLE_PLATFORM_WINDOWS)
return "libEGL.dll";
#else
return "unknown_libegl";
#endif
}
} // namespace angle

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

@ -433,4 +433,15 @@ int NumberOfProcessors()
return static_cast<int>(res);
}
const char *GetNativeEGLLibraryNameWithExtension()
{
#if defined(ANGLE_PLATFORM_ANDROID)
return "libEGL.so";
#elif defined(ANGLE_PLATFORM_LINUX)
return "libEGL.so.1";
#else
return "unknown_libegl";
#endif
}
} // namespace angle

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

@ -120,6 +120,7 @@ Process *LaunchProcess(const std::vector<const char *> &args,
int NumberOfProcessors();
const char *GetNativeEGLLibraryNameWithExtension();
} // namespace angle
#endif // UTIL_TEST_UTILS_H_

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

@ -444,4 +444,9 @@ bool DeleteFile(const char *path)
return !!::DeleteFileA(path) ? true : ReturnSuccessOnNotFound();
}
const char *GetNativeEGLLibraryNameWithExtension()
{
return "libEGL.dll";
}
} // namespace angle