Commit ad398ee8 by Jamie Madill Committed by Commit Bot

Free OSWindow and EGLWindow through helpers.

This cleans up any potential problems with allocating and freeing resources in different shared objects or DLLs. Previously we were using a dynamically linked allocation function and then calling the standard delete function. Also adds a base class helper for EGLWindow. Will base the WGL Window class on this. Needed for running ANGLE tests against native drivers. Bug: angleproject:2995 Change-Id: Ic92b447649ebb32c547605c20086c07a601842f0 Reviewed-on: https://chromium-review.googlesource.com/c/1393443 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent 9fa54eab
......@@ -14,7 +14,7 @@
int main(int argc, char *argv[])
{
OSWindow *window = CreateOSWindow();
OSWindow *window = OSWindow::New();
int width = 400;
int height = 400;
int x = 0;
......
......@@ -58,7 +58,7 @@ void main()
{
window window;
window.osWindow = CreateOSWindow();
window.osWindow = OSWindow::New();
if (!window.osWindow->initialize("MultiWindow", 256, 256))
{
return false;
......
......@@ -49,7 +49,12 @@ SampleApplication::SampleApplication(std::string name,
EGLint glesMinorVersion,
size_t width,
size_t height)
: mName(std::move(name)), mWidth(width), mHeight(height), mRunning(false)
: mName(std::move(name)),
mWidth(width),
mHeight(height),
mRunning(false),
mEGLWindow(nullptr),
mOSWindow(nullptr)
{
EGLint requestedRenderer = EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE;
......@@ -61,10 +66,10 @@ SampleApplication::SampleApplication(std::string name,
// Load EGL library so we can initialize the display.
mEntryPointsLib.reset(angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME));
mEGLWindow.reset(new EGLWindow(glesMajorVersion, glesMinorVersion,
EGLPlatformParameters(requestedRenderer)));
mEGLWindow = EGLWindow::New(glesMajorVersion, glesMinorVersion,
EGLPlatformParameters(requestedRenderer));
mTimer.reset(CreateTimer());
mOSWindow.reset(CreateOSWindow());
mOSWindow = OSWindow::New();
mEGLWindow->setConfigRedBits(8);
mEGLWindow->setConfigGreenBits(8);
......@@ -77,7 +82,11 @@ SampleApplication::SampleApplication(std::string name,
mEGLWindow->setSwapInterval(0);
}
SampleApplication::~SampleApplication() {}
SampleApplication::~SampleApplication()
{
EGLWindow::Delete(&mEGLWindow);
OSWindow::Delete(&mOSWindow);
}
bool SampleApplication::initialize()
{
......@@ -97,7 +106,7 @@ void SampleApplication::swap()
OSWindow *SampleApplication::getWindow() const
{
return mOSWindow.get();
return mOSWindow;
}
EGLConfig SampleApplication::getConfig() const
......@@ -129,7 +138,7 @@ int SampleApplication::run()
mOSWindow->setVisible(true);
if (!mEGLWindow->initializeGL(mOSWindow.get(), mEntryPointsLib.get()))
if (!mEGLWindow->initializeGL(mOSWindow, mEntryPointsLib.get()))
{
return -1;
}
......
......@@ -61,8 +61,8 @@ class SampleApplication
bool mRunning;
std::unique_ptr<Timer> mTimer;
std::unique_ptr<EGLWindow> mEGLWindow;
std::unique_ptr<OSWindow> mOSWindow;
EGLWindow *mEGLWindow;
OSWindow *mOSWindow;
// Handle to the entry point binding library.
std::unique_ptr<angle::Library> mEntryPointsLib;
......
......@@ -272,7 +272,7 @@ eglu::NativeWindow *NativeWindowFactory::createWindow(eglu::NativeDisplay *nativ
NativeWindow::NativeWindow(ANGLENativeDisplay *nativeDisplay,
const eglu::WindowParams &params,
EventState *eventState)
: eglu::NativeWindow(kWindowCapabilities), mWindow(CreateOSWindow()), mEvents(eventState)
: eglu::NativeWindow(kWindowCapabilities), mWindow(OSWindow::New()), mEvents(eventState)
{
bool initialized = mWindow->initialize(
"dEQP ANGLE Tests",
......@@ -305,7 +305,7 @@ void NativeWindow::setVisibility(eglu::WindowParams::Visibility visibility)
NativeWindow::~NativeWindow()
{
delete mWindow;
OSWindow::Delete(&mWindow);
}
eglw::EGLNativeWindowType NativeWindow::getLegacyNative()
......
......@@ -116,7 +116,7 @@ class EGLContextCompatibilityTest : public EGLTest,
EGLConfig contextConfig,
bool compatible) const
{
OSWindow *osWindow = CreateOSWindow();
OSWindow *osWindow = OSWindow::New();
ASSERT_TRUE(osWindow != nullptr);
osWindow->initialize("EGLContextCompatibilityTest", 500, 500);
osWindow->setVisible(true);
......@@ -144,7 +144,7 @@ class EGLContextCompatibilityTest : public EGLTest,
eglDestroyContext(mDisplay, context);
ASSERT_EGL_SUCCESS();
SafeDelete(osWindow);
OSWindow::Delete(&osWindow);
}
void testPbufferCompatibility(EGLConfig pbufferConfig,
......
......@@ -76,7 +76,7 @@ class EGLDeviceCreationTest : public EGLTest
SafeRelease(mDevice);
SafeRelease(mDeviceContext);
SafeDelete(mOSWindow);
OSWindow::Delete(&mOSWindow);
if (mSurface != EGL_NO_SURFACE)
{
......@@ -138,7 +138,7 @@ class EGLDeviceCreationTest : public EGLTest
ASSERT_EGL_TRUE(eglChooseConfig(mDisplay, configAttributes, &mConfig, 1, &configCount));
// Create an OS Window
mOSWindow = CreateOSWindow();
mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLSurfaceTest", 64, 64);
// Create window surface
......
......@@ -47,7 +47,7 @@ class EGLDirectCompositionTest : public ANGLETest
}
// Create an OS Window
mOSWindow = std::unique_ptr<OSWindow>(CreateOSWindow());
mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLDirectCompositionTest", WINDOWWIDTH, WINDOWHEIGHT);
auto nativeWindow = mOSWindow->getNativeWindow();
......@@ -198,9 +198,11 @@ class EGLDirectCompositionTest : public ANGLETest
return;
}
ASSERT_EGL_TRUE(eglTerminate(mEglDisplay));
OSWindow::Delete(&mOSWindow);
}
std::unique_ptr<OSWindow> mOSWindow;
OSWindow *mOSWindow;
ComPtr<ICompositor> mCompositor;
ComPtr<IDispatcherQueueController> mDispatcherController;
ComPtr<ICompositionColorBrush> mColorBrush;
......
......@@ -31,7 +31,7 @@ class EGLPresentPathD3D11 : public EGLTest, public testing::WithParamInterface<P
{
EGLTest::SetUp();
mOSWindow = CreateOSWindow();
mOSWindow = OSWindow::New();
mWindowWidth = 64;
mOSWindow->initialize("EGLPresentPathD3D11", mWindowWidth, mWindowWidth);
}
......@@ -169,7 +169,7 @@ class EGLPresentPathD3D11 : public EGLTest, public testing::WithParamInterface<P
}
mOSWindow->destroy();
SafeDelete(mOSWindow);
OSWindow::Delete(&mOSWindow);
}
void drawQuadUsingGL()
......
......@@ -21,7 +21,7 @@ class EGLRobustnessTest : public EGLTest,
{
EGLTest::SetUp();
mOSWindow = CreateOSWindow();
mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLRobustnessTest", 500, 500);
mOSWindow->setVisible(true);
......@@ -80,7 +80,7 @@ class EGLRobustnessTest : public EGLTest,
eglTerminate(mDisplay);
EXPECT_EGL_SUCCESS();
SafeDelete(mOSWindow);
OSWindow::Delete(&mOSWindow);
}
void createContext(EGLint resetStrategy)
......
......@@ -42,7 +42,7 @@ class EGLSurfaceTest : public EGLTest
{
EGLTest::SetUp();
mOSWindow = CreateOSWindow();
mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLSurfaceTest", 64, 64);
}
......@@ -82,7 +82,7 @@ class EGLSurfaceTest : public EGLTest
}
mOSWindow->destroy();
SafeDelete(mOSWindow);
OSWindow::Delete(&mOSWindow);
ASSERT_TRUE(mWindowSurface == EGL_NO_SURFACE && mContext == EGL_NO_CONTEXT);
}
......
......@@ -64,7 +64,7 @@ class EGLSyncControlTest : public testing::Test
SafeRelease(mDevice);
SafeRelease(mDeviceContext);
SafeDelete(mOSWindow);
OSWindow::Delete(&mOSWindow);
if (mSurface != EGL_NO_SURFACE)
{
......@@ -110,7 +110,7 @@ class EGLSyncControlTest : public testing::Test
EGL_NONE};
// Create an OS Window
mOSWindow = CreateOSWindow();
mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLSyncControlTest", 64, 64);
mOSWindow->setVisible(true);
......
......@@ -95,7 +95,7 @@ TEST_P(EGLX11VisualHintTest, ValidVisualIDAndClear)
{
// We'll test the extension with one visual ID but we don't care which one. This means we
// can use OSWindow to create a window and just grab its visual.
OSWindow *osWindow = CreateOSWindow();
OSWindow *osWindow = OSWindow::New();
osWindow->initialize("EGLX11VisualHintTest", 500, 500);
osWindow->setVisible(true);
......@@ -151,7 +151,7 @@ TEST_P(EGLX11VisualHintTest, ValidVisualIDAndClear)
eglDestroyContext(display, context);
ASSERT_EGL_SUCCESS();
SafeDelete(osWindow);
OSWindow::Delete(&osWindow);
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglTerminate(display);
......@@ -165,7 +165,7 @@ TEST_P(EGLX11VisualHintTest, InvalidWindowVisualID)
// creation will succeed.
int visualId;
{
OSWindow *osWindow = CreateOSWindow();
OSWindow *osWindow = OSWindow::New();
osWindow->initialize("EGLX11VisualHintTest", 500, 500);
osWindow->setVisible(true);
......@@ -175,7 +175,7 @@ TEST_P(EGLX11VisualHintTest, InvalidWindowVisualID)
ASSERT_NE(0, XGetWindowAttributes(mDisplay, xWindow, &windowAttributes));
visualId = windowAttributes.visual->visualid;
SafeDelete(osWindow);
OSWindow::Delete(&osWindow);
}
auto attributes = getDisplayAttributes(visualId);
......@@ -205,7 +205,7 @@ TEST_P(EGLX11VisualHintTest, InvalidWindowVisualID)
ASSERT_EQ(EGL_NO_SURFACE, window);
ASSERT_EGL_ERROR(EGL_BAD_MATCH);
SafeDelete(osWindow);
OSWindow::Delete(&osWindow);
}
ANGLE_INSTANTIATE_TEST(EGLX11VisualHintTest, ES2_OPENGL());
......@@ -632,7 +632,7 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam<PlatformsWi
public:
void SetUp() override
{
mOSWindow = CreateOSWindow();
mOSWindow = OSWindow::New();
bool result = mOSWindow->initialize("ProgramBinariesAcrossRenderersTests", 100, 100);
if (result == false)
......@@ -646,12 +646,11 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam<PlatformsWi
EGLWindow *createAndInitEGLWindow(angle::PlatformParameters &param)
{
EGLWindow *eglWindow =
new EGLWindow(param.majorVersion, param.minorVersion, param.eglParameters);
EGLWindow::New(param.majorVersion, param.minorVersion, param.eglParameters);
bool result = eglWindow->initializeGL(mOSWindow, mEntryPointsLib.get());
if (result == false)
{
SafeDelete(eglWindow);
eglWindow = nullptr;
EGLWindow::Delete(&eglWindow);
}
angle::LoadGLES(eglGetProcAddress);
......@@ -663,8 +662,7 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam<PlatformsWi
{
ASSERT_NE(nullptr, *eglWindow);
(*eglWindow)->destroyGL();
SafeDelete(*eglWindow);
*eglWindow = nullptr;
EGLWindow::Delete(eglWindow);
}
GLuint createES2ProgramFromSource()
......@@ -706,7 +704,7 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam<PlatformsWi
void TearDown() override
{
mOSWindow->destroy();
SafeDelete(mOSWindow);
OSWindow::Delete(&mOSWindow);
}
OSWindow *mOSWindow = nullptr;
......
......@@ -311,7 +311,7 @@ std::string RenderTestParams::suffix() const
ANGLERenderTest::ANGLERenderTest(const std::string &name, const RenderTestParams &testParams)
: ANGLEPerfTest(name, testParams.suffix(), OneFrame() ? 1 : testParams.iterationsPerStep),
mTestParams(testParams),
mEGLWindow(createEGLWindow(testParams)),
mGLWindow(nullptr),
mOSWindow(nullptr)
{
// Force fast tests to make sure our slowest bots don't time out.
......@@ -322,12 +322,14 @@ ANGLERenderTest::ANGLERenderTest(const std::string &name, const RenderTestParams
// Try to ensure we don't trigger allocation during execution.
mTraceEventBuffer.reserve(kInitialTraceEventBufferSize);
mGLWindow = createEGLWindow(testParams);
}
ANGLERenderTest::~ANGLERenderTest()
{
SafeDelete(mOSWindow);
SafeDelete(mEGLWindow);
OSWindow::Delete(&mOSWindow);
GLWindowBase::Delete(&mGLWindow);
}
void ANGLERenderTest::addExtensionPrerequisite(const char *extensionName)
......@@ -342,15 +344,15 @@ void ANGLERenderTest::SetUp()
// Set a consistent CPU core affinity and high priority.
angle::StabilizeCPUForBenchmarking();
mOSWindow = CreateOSWindow();
mOSWindow = OSWindow::New();
if (!mEGLWindow)
if (!mGLWindow)
{
abortTest();
mSkipTest = true;
return;
}
mEGLWindow->setSwapInterval(0);
mGLWindow->setSwapInterval(0);
mPlatformMethods.overrideWorkaroundsD3D = OverrideWorkaroundsD3D;
mPlatformMethods.logError = EmptyPlatformMethod;
......@@ -361,7 +363,7 @@ void ANGLERenderTest::SetUp()
mPlatformMethods.updateTraceEventDuration = UpdateTraceEventDuration;
mPlatformMethods.monotonicallyIncreasingTime = MonotonicallyIncreasingTime;
mPlatformMethods.context = this;
mEGLWindow->setPlatformMethods(&mPlatformMethods);
mGLWindow->setPlatformMethods(&mPlatformMethods);
if (!mOSWindow->initialize(mName, mTestParams.windowWidth, mTestParams.windowHeight))
{
......@@ -374,9 +376,9 @@ void ANGLERenderTest::SetUp()
mEntryPointsLib.reset(angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME));
#endif // defined(ANGLE_USE_UTIL_LOADER)
if (!mEGLWindow->initializeGL(mOSWindow, mEntryPointsLib.get()))
if (!mGLWindow->initializeGL(mOSWindow, mEntryPointsLib.get()))
{
FAIL() << "Failed initializing EGLWindow";
FAIL() << "Failed initializing GL Window";
return;
}
......@@ -406,10 +408,22 @@ void ANGLERenderTest::SetUp()
void ANGLERenderTest::TearDown()
{
destroyBenchmark();
if (!mSkipTest)
{
destroyBenchmark();
}
mEGLWindow->destroyGL();
mOSWindow->destroy();
if (mGLWindow)
{
mGLWindow->destroyGL();
mGLWindow = nullptr;
}
if (mOSWindow)
{
mOSWindow->destroy();
mOSWindow = nullptr;
}
// Dump trace events to json file.
if (gEnableTrace)
......@@ -446,7 +460,7 @@ void ANGLERenderTest::step()
// to swap.
if (mTestParams.eglParameters.deviceType != EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE)
{
mEGLWindow->swap();
mGLWindow->swap();
}
mOSWindow->messageLoop();
}
......@@ -486,12 +500,12 @@ bool ANGLERenderTest::areExtensionPrerequisitesFulfilled() const
void ANGLERenderTest::setWebGLCompatibilityEnabled(bool webglCompatibility)
{
mEGLWindow->setWebGLCompatibilityEnabled(webglCompatibility);
mGLWindow->setWebGLCompatibilityEnabled(webglCompatibility);
}
void ANGLERenderTest::setRobustResourceInit(bool enabled)
{
mEGLWindow->setRobustResourceInit(enabled);
mGLWindow->setRobustResourceInit(enabled);
}
std::vector<TraceEvent> &ANGLERenderTest::getTraceEventBuffer()
......@@ -502,8 +516,8 @@ std::vector<TraceEvent> &ANGLERenderTest::getTraceEventBuffer()
// static
EGLWindow *ANGLERenderTest::createEGLWindow(const RenderTestParams &testParams)
{
return new EGLWindow(testParams.majorVersion, testParams.minorVersion,
testParams.eglParameters);
return EGLWindow::New(testParams.majorVersion, testParams.minorVersion,
testParams.eglParameters);
}
void ANGLEProcessPerfTestArgs(int *argc, char **argv)
......
......@@ -151,7 +151,7 @@ class ANGLERenderTest : public ANGLEPerfTest
static EGLWindow *createEGLWindow(const RenderTestParams &testParams);
EGLWindow *mEGLWindow;
GLWindowBase *mGLWindow;
OSWindow *mOSWindow;
std::vector<const char *> mExtensionPrerequisites;
angle::PlatformMethods mPlatformMethods;
......
......@@ -95,7 +95,7 @@ EGLInitializePerfTest::EGLInitializePerfTest()
}
displayAttributes.push_back(EGL_NONE);
mOSWindow = CreateOSWindow();
mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLInitialize Test", 64, 64);
auto eglGetPlatformDisplayEXT = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(
......@@ -125,7 +125,7 @@ void EGLInitializePerfTest::SetUp()
EGLInitializePerfTest::~EGLInitializePerfTest()
{
SafeDelete(mOSWindow);
OSWindow::Delete(&mOSWindow);
}
void EGLInitializePerfTest::step()
......
......@@ -59,7 +59,7 @@ EGLMakeCurrentPerfTest::EGLMakeCurrentPerfTest()
displayAttributes.push_back(platform.deviceType);
displayAttributes.push_back(EGL_NONE);
mOSWindow = CreateOSWindow();
mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLMakeCurrent Test", 64, 64);
mEGLLibrary.reset(angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME));
......
......@@ -293,7 +293,7 @@ ANGLETestBase::ANGLETestBase(const angle::PlatformParameters &params)
m3DTexturedQuadProgram(0),
mDeferContextInit(false)
{
mEGLWindow = new EGLWindow(params.majorVersion, params.minorVersion, params.eglParameters);
mEGLWindow = EGLWindow::New(params.majorVersion, params.minorVersion, params.eglParameters);
// Default debug layers to enabled in tests.
mEGLWindow->setDebugLayersEnabled(true);
......@@ -333,7 +333,7 @@ ANGLETestBase::~ANGLETestBase()
{
glDeleteProgram(m3DTexturedQuadProgram);
}
SafeDelete(mEGLWindow);
EGLWindow::Delete(&mEGLWindow);
}
void ANGLETestBase::ANGLETestSetUp()
......@@ -372,10 +372,6 @@ void ANGLETestBase::ANGLETestSetUp()
FAIL() << "GL Context init failed.";
}
#if defined(ANGLE_USE_UTIL_LOADER)
angle::LoadGLES(eglGetProcAddress);
#endif // defined(ANGLE_USE_UTIL_LOADER)
if (needSwap)
{
// Swap the buffers so that the default framebuffer picks up the resize
......@@ -395,27 +391,22 @@ void ANGLETestBase::ANGLETestSetUp()
void ANGLETestBase::ANGLETestTearDown()
{
mEGLWindow->setPlatformMethods(nullptr);
if (mEGLWindow)
{
mEGLWindow->setPlatformMethods(nullptr);
checkD3D11SDKLayersMessages();
}
mPlatformContext.currentTest = nullptr;
checkD3D11SDKLayersMessages();
const auto &info = testing::UnitTest::GetInstance()->current_test_info();
angle::WriteDebugMessage("Exiting %s.%s\n", info->test_case_name(), info->name());
swapBuffers();
if (eglGetError() != EGL_SUCCESS)
{
FAIL() << "egl error during swap.";
}
mOSWindow->messageLoop();
if (!destroyEGLContext())
{
FAIL() << "egl context destruction failed.";
}
getGLWindow()->destroyGL();
// Check for quit message
Event myEvent;
......@@ -430,9 +421,14 @@ void ANGLETestBase::ANGLETestTearDown()
void ANGLETestBase::swapBuffers()
{
if (mEGLWindow->isGLInitialized())
if (getGLWindow()->isGLInitialized())
{
mEGLWindow->swap();
getGLWindow()->swap();
if (mEGLWindow)
{
EXPECT_EGL_SUCCESS();
}
}
}
......@@ -904,34 +900,39 @@ void ANGLETestBase::setWindowHeight(int height)
mHeight = height;
}
GLWindowBase *ANGLETestBase::getGLWindow() const
{
return mEGLWindow;
}
void ANGLETestBase::setConfigRedBits(int bits)
{
mEGLWindow->setConfigRedBits(bits);
getGLWindow()->setConfigRedBits(bits);
}
void ANGLETestBase::setConfigGreenBits(int bits)
{
mEGLWindow->setConfigGreenBits(bits);
getGLWindow()->setConfigGreenBits(bits);
}
void ANGLETestBase::setConfigBlueBits(int bits)
{
mEGLWindow->setConfigBlueBits(bits);
getGLWindow()->setConfigBlueBits(bits);
}
void ANGLETestBase::setConfigAlphaBits(int bits)
{
mEGLWindow->setConfigAlphaBits(bits);
getGLWindow()->setConfigAlphaBits(bits);
}
void ANGLETestBase::setConfigDepthBits(int bits)
{
mEGLWindow->setConfigDepthBits(bits);
getGLWindow()->setConfigDepthBits(bits);
}
void ANGLETestBase::setConfigStencilBits(int bits)
{
mEGLWindow->setConfigStencilBits(bits);
getGLWindow()->setConfigStencilBits(bits);
}
void ANGLETestBase::setConfigComponentType(EGLenum componentType)
......@@ -1039,16 +1040,10 @@ bool ANGLETestBase::isMultisampleEnabled() const
return mEGLWindow->isMultisample();
}
bool ANGLETestBase::destroyEGLContext()
{
mEGLWindow->destroyGL();
return true;
}
// static
bool ANGLETestBase::InitTestWindow()
{
mOSWindow = CreateOSWindow();
mOSWindow = OSWindow::New();
if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
{
return false;
......@@ -1065,8 +1060,7 @@ bool ANGLETestBase::DestroyTestWindow()
if (mOSWindow)
{
mOSWindow->destroy();
delete mOSWindow;
mOSWindow = nullptr;
OSWindow::Delete(&mOSWindow);
}
return true;
......
......@@ -235,9 +235,10 @@ GLColor32F ReadColor32F(GLint x, GLint y);
#define EXPECT_PIXEL_COLOR32F_NEAR(x, y, angleColor, abs_error) \
EXPECT_PIXEL32F_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
class ANGLETestBase;
class EGLWindow;
class GLWindowBase;
class OSWindow;
class ANGLETestBase;
struct TestPlatformContext final : private angle::NonCopyable
{
......@@ -385,8 +386,6 @@ class ANGLETestBase
};
private:
bool destroyEGLContext();
void checkD3D11SDKLayersMessages();
void drawQuad(GLuint program,
......@@ -397,6 +396,8 @@ class ANGLETestBase
bool useInstancedDrawCalls,
GLuint numInstances);
GLWindowBase *getGLWindow() const;
EGLWindow *mEGLWindow;
int mWidth;
int mHeight;
......
......@@ -20,6 +20,25 @@
namespace angle
{
namespace
{
bool IsANGLEConfigSupported(const PlatformParameters &param, OSWindow *osWindow)
{
std::unique_ptr<angle::Library> eglLibrary;
#if defined(ANGLE_USE_UTIL_LOADER)
eglLibrary.reset(angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME));
#endif
EGLWindow *eglWindow =
EGLWindow::New(param.majorVersion, param.minorVersion, param.eglParameters);
bool result = eglWindow->initializeGL(osWindow, eglLibrary.get());
eglWindow->destroyGL();
EGLWindow::Delete(&eglWindow);
return result;
}
} // namespace
bool IsPlatformAvailable(const PlatformParameters &param)
{
switch (param.getRenderer())
......@@ -75,27 +94,16 @@ bool IsPlatformAvailable(const PlatformParameters &param)
}
else
{
OSWindow *osWindow = CreateOSWindow();
OSWindow *osWindow = OSWindow::New();
bool result = osWindow->initialize("CONFIG_TESTER", 1, 1);
if (result)
{
std::unique_ptr<angle::Library> eglLibrary;
#if defined(ANGLE_USE_UTIL_LOADER)
eglLibrary.reset(angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME));
#endif // defined(ANGLE_USE_UTIL_LOADER)
EGLWindow *eglWindow =
new EGLWindow(param.majorVersion, param.minorVersion, param.eglParameters);
result = eglWindow->initializeGL(osWindow, eglLibrary.get());
eglWindow->destroyGL();
SafeDelete(eglWindow);
result = IsANGLEConfigSupported(param, osWindow);
}
osWindow->destroy();
SafeDelete(osWindow);
OSWindow::Delete(&osWindow);
paramAvailabilityCache[param] = result;
......
......@@ -557,7 +557,7 @@ void destroy_window(struct sample_info &info)
void init_window_size(struct sample_info &info, int32_t default_width, int32_t default_height)
{
#ifdef __ANDROID__
info.mOSWindow = CreateOSWindow();
info.mOSWindow = OSWindow::New();
assert(info.mOSWindow != nullptr);
info.mOSWindow->initialize("VulkanTest", default_width, default_height);
#endif
......
......@@ -87,39 +87,45 @@ bool operator==(const EGLPlatformParameters &a, const EGLPlatformParameters &b)
(a.presentPath == b.presentPath);
}
// GLWindowBase implementation.
GLWindowBase::GLWindowBase(EGLint glesMajorVersion, EGLint glesMinorVersion)
: mClientMajorVersion(glesMajorVersion),
mClientMinorVersion(glesMinorVersion),
mRedBits(-1),
mGreenBits(-1),
mBlueBits(-1),
mAlphaBits(-1),
mDepthBits(-1),
mStencilBits(-1),
mSwapInterval(-1),
mPlatformMethods(nullptr)
{}
GLWindowBase::~GLWindowBase() = default;
// EGLWindow implementation.
EGLWindow::EGLWindow(EGLint glesMajorVersion,
EGLint glesMinorVersion,
const EGLPlatformParameters &platform)
: mDisplay(EGL_NO_DISPLAY),
: GLWindowBase(glesMajorVersion, glesMinorVersion),
mDisplay(EGL_NO_DISPLAY),
mSurface(EGL_NO_SURFACE),
mContext(EGL_NO_CONTEXT),
mClientMajorVersion(glesMajorVersion),
mClientMinorVersion(glesMinorVersion),
mEGLMajorVersion(0),
mEGLMinorVersion(0),
mPlatform(platform),
mRedBits(-1),
mGreenBits(-1),
mBlueBits(-1),
mAlphaBits(-1),
mDepthBits(-1),
mStencilBits(-1),
mComponentType(EGL_COLOR_COMPONENT_TYPE_FIXED_EXT),
mMultisample(false),
mDebug(false),
mNoError(false),
mWebGLCompatibility(false),
mExtensionsEnabled(),
mBindGeneratesResource(true),
mClientArraysEnabled(true),
mRobustAccess(false),
mRobustResourceInit(),
mSwapInterval(-1),
mSamples(-1),
mDebugLayersEnabled(),
mContextProgramCacheEnabled(),
mContextVirtualization(),
mPlatformMethods(nullptr)
mContextVirtualization()
{}
EGLWindow::~EGLWindow()
......@@ -152,18 +158,18 @@ EGLContext EGLWindow::getContext() const
return mContext;
}
bool EGLWindow::initializeGL(OSWindow *osWindow, angle::Library *eglLibrary)
bool EGLWindow::initializeGL(OSWindow *osWindow, angle::Library *glWindowingLibrary)
{
if (!initializeDisplayAndSurface(osWindow, eglLibrary))
if (!initializeDisplayAndSurface(osWindow, glWindowingLibrary))
return false;
return initializeContext();
}
bool EGLWindow::initializeDisplayAndSurface(OSWindow *osWindow, angle::Library *eglLibrary)
bool EGLWindow::initializeDisplayAndSurface(OSWindow *osWindow, angle::Library *glWindowingLibrary)
{
#if defined(ANGLE_USE_UTIL_LOADER)
PFNEGLGETPROCADDRESSPROC getProcAddress;
eglLibrary->getAs("eglGetProcAddress", &getProcAddress);
glWindowingLibrary->getAs("eglGetProcAddress", &getProcAddress);
if (!getProcAddress)
{
return false;
......@@ -307,6 +313,10 @@ bool EGLWindow::initializeDisplayAndSurface(OSWindow *osWindow, angle::Library *
return false;
}
#if defined(ANGLE_USE_UTIL_LOADER)
angle::LoadGLES(eglGetProcAddress);
#endif // defined(ANGLE_USE_UTIL_LOADER)
return true;
}
......@@ -324,7 +334,7 @@ EGLContext EGLWindow::createContext(EGLContext share) const
bool hasWebGLCompatibility =
strstr(displayExtensions, "EGL_ANGLE_create_context_webgl_compatibility") != nullptr;
if (mWebGLCompatibility && !hasWebGLCompatibility)
if (mWebGLCompatibility.valid() && !hasWebGLCompatibility)
{
return EGL_NO_CONTEXT;
}
......@@ -389,10 +399,10 @@ EGLContext EGLWindow::createContext(EGLContext share) const
contextAttributes.push_back(EGL_CONTEXT_OPENGL_NO_ERROR_KHR);
contextAttributes.push_back(mNoError ? EGL_TRUE : EGL_FALSE);
if (hasWebGLCompatibility)
if (mWebGLCompatibility.valid())
{
contextAttributes.push_back(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE);
contextAttributes.push_back(mWebGLCompatibility ? EGL_TRUE : EGL_FALSE);
contextAttributes.push_back(mWebGLCompatibility.value() ? EGL_TRUE : EGL_FALSE);
}
if (mExtensionsEnabled.valid())
......@@ -552,3 +562,25 @@ bool CheckExtensionExists(const char *allExtensions, const std::string &extName)
return paddedExtensions.find(std::string(" ") + extName + std::string(" ")) !=
std::string::npos;
}
// static
void GLWindowBase::Delete(GLWindowBase **window)
{
delete *window;
*window = nullptr;
}
// static
EGLWindow *EGLWindow::New(EGLint glesMajorVersion,
EGLint glesMinorVersion,
const EGLPlatformParameters &platform)
{
return new EGLWindow(glesMajorVersion, glesMinorVersion, platform);
}
// static
void EGLWindow::Delete(EGLWindow **window)
{
delete *window;
*window = nullptr;
}
......@@ -26,30 +26,78 @@ class Library;
struct PlatformMethods;
} // namespace angle
class ANGLE_UTIL_EXPORT EGLWindow : angle::NonCopyable
class ANGLE_UTIL_EXPORT GLWindowBase : angle::NonCopyable
{
public:
EGLWindow(EGLint glesMajorVersion,
EGLint glesMinorVersion,
const EGLPlatformParameters &platform);
~EGLWindow();
static void Delete(GLWindowBase **window);
// It should also be possible to set multisample and floating point framebuffers.
void setConfigRedBits(int bits) { mRedBits = bits; }
void setConfigGreenBits(int bits) { mGreenBits = bits; }
void setConfigBlueBits(int bits) { mBlueBits = bits; }
void setConfigAlphaBits(int bits) { mAlphaBits = bits; }
void setConfigDepthBits(int bits) { mDepthBits = bits; }
void setConfigStencilBits(int bits) { mStencilBits = bits; }
void setSwapInterval(int swapInterval) { mSwapInterval = swapInterval; }
int getConfigRedBits() const { return mRedBits; }
int getConfigGreenBits() const { return mGreenBits; }
int getConfigBlueBits() const { return mBlueBits; }
int getConfigAlphaBits() const { return mAlphaBits; }
int getConfigDepthBits() const { return mDepthBits; }
int getConfigStencilBits() const { return mStencilBits; }
int getSwapInterval() const { return mSwapInterval; }
void setPlatformMethods(angle::PlatformMethods *platformMethods)
{
mPlatformMethods = platformMethods;
}
void setWebGLCompatibilityEnabled(bool webglCompatibility)
{
mWebGLCompatibility = webglCompatibility;
}
void setRobustResourceInit(bool enabled) { mRobustResourceInit = enabled; }
EGLint getClientMajorVersion() const { return mClientMajorVersion; }
EGLint getClientMinorVersion() const { return mClientMinorVersion; }
virtual bool initializeGL(OSWindow *osWindow, angle::Library *glLibrary) = 0;
virtual bool isGLInitialized() const = 0;
virtual void swap() = 0;
virtual void destroyGL() = 0;
virtual void makeCurrent() = 0;
protected:
GLWindowBase(EGLint glesMajorVersion, EGLint glesMinorVersion);
virtual ~GLWindowBase();
EGLint mClientMajorVersion;
EGLint mClientMinorVersion;
int mRedBits;
int mGreenBits;
int mBlueBits;
int mAlphaBits;
int mDepthBits;
int mStencilBits;
int mSwapInterval;
angle::PlatformMethods *mPlatformMethods;
Optional<bool> mWebGLCompatibility;
Optional<bool> mRobustResourceInit;
};
class ANGLE_UTIL_EXPORT EGLWindow : public GLWindowBase
{
public:
static EGLWindow *New(EGLint glesMajorVersion,
EGLint glesMinorVersion,
const EGLPlatformParameters &platform);
static void Delete(EGLWindow **window);
void setConfigComponentType(EGLenum componentType) { mComponentType = componentType; }
void setMultisample(bool multisample) { mMultisample = multisample; }
void setSamples(EGLint samples) { mSamples = samples; }
void setDebugEnabled(bool debug) { mDebug = debug; }
void setNoErrorEnabled(bool noError) { mNoError = noError; }
void setWebGLCompatibilityEnabled(bool webglCompatibility)
{
mWebGLCompatibility = webglCompatibility;
}
void setExtensionsEnabled(bool extensionsEnabled) { mExtensionsEnabled = extensionsEnabled; }
void setBindGeneratesResource(bool bindGeneratesResource)
{
......@@ -58,42 +106,27 @@ class ANGLE_UTIL_EXPORT EGLWindow : angle::NonCopyable
void setDebugLayersEnabled(bool enabled) { mDebugLayersEnabled = enabled; }
void setClientArraysEnabled(bool enabled) { mClientArraysEnabled = enabled; }
void setRobustAccess(bool enabled) { mRobustAccess = enabled; }
void setRobustResourceInit(bool enabled) { mRobustResourceInit = enabled; }
void setSwapInterval(EGLint swapInterval) { mSwapInterval = swapInterval; }
void setPlatformMethods(angle::PlatformMethods *platformMethods)
{
mPlatformMethods = platformMethods;
}
void setContextProgramCacheEnabled(bool enabled) { mContextProgramCacheEnabled = enabled; }
void setContextVirtualization(bool enabled) { mContextVirtualization = enabled; }
static EGLBoolean FindEGLConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *config);
void swap();
void swap() override;
EGLint getClientMajorVersion() const { return mClientMajorVersion; }
EGLint getClientMinorVersion() const { return mClientMinorVersion; }
const EGLPlatformParameters &getPlatform() const { return mPlatform; }
EGLConfig getConfig() const;
EGLDisplay getDisplay() const;
EGLSurface getSurface() const;
EGLContext getContext() const;
int getConfigRedBits() const { return mRedBits; }
int getConfigGreenBits() const { return mGreenBits; }
int getConfigBlueBits() const { return mBlueBits; }
int getConfigAlphaBits() const { return mAlphaBits; }
int getConfigDepthBits() const { return mDepthBits; }
int getConfigStencilBits() const { return mStencilBits; }
bool isMultisample() const { return mMultisample; }
bool isDebugEnabled() const { return mDebug; }
EGLint getSwapInterval() const { return mSwapInterval; }
const angle::PlatformMethods *getPlatformMethods() const { return mPlatformMethods; }
// Internally initializes the Display, Surface and Context.
bool initializeGL(OSWindow *osWindow, angle::Library *eglLibrary);
bool initializeGL(OSWindow *osWindow, angle::Library *glWindowingLibrary) override;
// Only initializes the Display and Surface.
bool initializeDisplayAndSurface(OSWindow *osWindow, angle::Library *eglLibrary);
bool initializeDisplayAndSurface(OSWindow *osWindow, angle::Library *glWindowingLibrary);
// Create an EGL context with this window's configuration
EGLContext createContext(EGLContext share) const;
......@@ -101,46 +134,39 @@ class ANGLE_UTIL_EXPORT EGLWindow : angle::NonCopyable
// Only initializes the Context.
bool initializeContext();
void destroyGL();
bool isGLInitialized() const;
void makeCurrent();
void destroyGL() override;
bool isGLInitialized() const override;
void makeCurrent() override;
static bool ClientExtensionEnabled(const std::string &extName);
private:
EGLWindow(EGLint glesMajorVersion,
EGLint glesMinorVersion,
const EGLPlatformParameters &platform);
~EGLWindow() override;
EGLConfig mConfig;
EGLDisplay mDisplay;
EGLSurface mSurface;
EGLContext mContext;
EGLint mClientMajorVersion;
EGLint mClientMinorVersion;
EGLint mEGLMajorVersion;
EGLint mEGLMinorVersion;
EGLPlatformParameters mPlatform;
int mRedBits;
int mGreenBits;
int mBlueBits;
int mAlphaBits;
int mDepthBits;
int mStencilBits;
EGLenum mComponentType;
bool mMultisample;
bool mDebug;
bool mNoError;
bool mWebGLCompatibility;
Optional<bool> mExtensionsEnabled;
bool mBindGeneratesResource;
bool mClientArraysEnabled;
bool mRobustAccess;
Optional<bool> mRobustResourceInit;
EGLint mSwapInterval;
EGLint mSamples;
Optional<bool> mDebugLayersEnabled;
Optional<bool> mContextProgramCacheEnabled;
Optional<bool> mContextVirtualization;
angle::PlatformMethods *mPlatformMethods;
};
ANGLE_UTIL_EXPORT bool CheckExtensionExists(const char *allExtensions, const std::string &extName);
......
......@@ -3,9 +3,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// OSWindow:
// Operating system window integration base class.
#ifndef SAMPLE_UTIL_WINDOW_H
#define SAMPLE_UTIL_WINDOW_H
#ifndef UTIL_OSWINDOW_H_
#define UTIL_OSWINDOW_H_
#include <stdint.h>
#include <list>
......@@ -20,8 +22,8 @@
class ANGLE_UTIL_EXPORT OSWindow
{
public:
OSWindow();
virtual ~OSWindow();
static OSWindow *New();
static void Delete(OSWindow **osWindow);
virtual bool initialize(const std::string &name, size_t width, size_t height) = 0;
virtual void destroy() = 0;
......@@ -56,6 +58,10 @@ class ANGLE_UTIL_EXPORT OSWindow
bool didTestEventFire();
protected:
OSWindow();
virtual ~OSWindow();
friend ANGLE_UTIL_EXPORT void FreeOSWindow(OSWindow *window);
int mX;
int mY;
int mWidth;
......@@ -64,6 +70,4 @@ class ANGLE_UTIL_EXPORT OSWindow
std::list<Event> mEvents;
};
ANGLE_UTIL_EXPORT OSWindow *CreateOSWindow();
#endif // SAMPLE_UTIL_WINDOW_H
#endif // UTIL_OSWINDOW_H_
......@@ -86,16 +86,6 @@ void AndroidWindow::signalTestEvent()
UNIMPLEMENTED();
}
OSWindow *CreateOSWindow()
{
// There should be only one live instance of AndroidWindow at a time,
// as there is only one Activity Surface behind it.
// Creating a new AndroidWindow each time works for ANGLETest,
// as it destroys an old window before creating a new one.
// TODO: use GLSurfaceView to support multiple windows
return new AndroidWindow();
}
static void onAppCmd(struct android_app *app, int32_t cmd)
{
switch (cmd)
......@@ -144,3 +134,14 @@ void android_main(struct android_app *app)
}
}
}
// static
OSWindow *OSWindow::New()
{
// There should be only one live instance of AndroidWindow at a time,
// as there is only one Activity Surface behind it.
// Creating a new AndroidWindow each time works for ANGLETest,
// as it destroys an old window before creating a new one.
// TODO: use GLSurfaceView to support multiple windows
return new AndroidWindow();
}
......@@ -777,7 +777,8 @@ NSWindow *OSXWindow::getNSWindow() const
return mWindow;
}
OSWindow *CreateOSWindow()
// static
OSWindow *OSWindow::New()
{
return new OSXWindow;
}
......@@ -64,7 +64,8 @@ void OzoneWindow::setVisible(bool isVisible)
void OzoneWindow::signalTestEvent() {}
OSWindow *CreateOSWindow()
// static
OSWindow *OSWindow::New()
{
return new OzoneWindow();
}
......@@ -736,11 +736,6 @@ void Win32Window::setMousePosition(int x, int y)
SetCursorPos(topLeft.x + x, topLeft.y + y);
}
OSWindow *CreateOSWindow()
{
return new Win32Window();
}
bool Win32Window::setPosition(int x, int y)
{
if (mX == x && mY == y)
......@@ -830,3 +825,9 @@ void Win32Window::signalTestEvent()
{
PostMessage(mNativeWindow, WM_USER, 0, 0);
}
// static
OSWindow *OSWindow::New()
{
return new Win32Window();
}
......@@ -8,9 +8,9 @@
#include "windows/winrt/WinRTWindow.h"
#include <wrl.h>
#include <windows.applicationmodel.core.h>
#include <windows.ui.xaml.h>
#include <wrl.h>
#include "angle_windowsstore.h"
#include "common/debug.h"
......@@ -22,9 +22,7 @@ using namespace ABI::Windows::UI::Core;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
WinRTWindow::WinRTWindow() : mNativeWindow(nullptr)
{
}
WinRTWindow::WinRTWindow() : mNativeWindow(nullptr) {}
WinRTWindow::~WinRTWindow()
{
......@@ -50,8 +48,8 @@ bool WinRTWindow::initialize(const std::string &name, size_t width, size_t heigh
destroy();
// Get all the relevant activation factories
result = GetActivationFactory(
HStringReference(RuntimeClass_Windows_UI_Core_CoreWindow).Get(), &coreWindowStatic);
result = GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_Core_CoreWindow).Get(),
&coreWindowStatic);
if (FAILED(result))
{
return false;
......@@ -90,7 +88,7 @@ bool WinRTWindow::initialize(const std::string &name, size_t width, size_t heigh
// Get the PropertySet as a map, so we can Insert things into it later
ComPtr<IInspectable> tempNativeWindow = mNativeWindow;
result = tempNativeWindow.As(&nativeWindowAsMap);
result = tempNativeWindow.As(&nativeWindowAsMap);
if (FAILED(result))
{
return false;
......@@ -195,7 +193,7 @@ bool WinRTWindow::initialize(const std::string &name, size_t width, size_t heigh
Size renderSize;
renderSize.Width = static_cast<float>(width);
renderSize.Height = static_cast<float>(height);
result = propertyValueStatics->CreateSize(renderSize, sizeValue.GetAddressOf());
result = propertyValueStatics->CreateSize(renderSize, sizeValue.GetAddressOf());
if (FAILED(result))
{
return false;
......@@ -278,7 +276,7 @@ void WinRTWindow::signalTestEvent()
UNIMPLEMENTED();
}
OSWindow *CreateOSWindow()
OSWindow *OSWindow::New()
{
return new WinRTWindow();
}
\ No newline at end of file
......@@ -413,11 +413,6 @@ void X11Window::setMousePosition(int x, int y)
XWarpPointer(mDisplay, None, mWindow, 0, 0, 0, 0, x, y);
}
OSWindow *CreateOSWindow()
{
return new X11Window();
}
bool X11Window::setPosition(int x, int y)
{
XMoveWindow(mDisplay, mWindow, x, y);
......@@ -706,3 +701,9 @@ void X11Window::processEvent(const XEvent &xEvent)
break;
}
}
// static
OSWindow *OSWindow::New()
{
return new X11Window();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment