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 @@ ...@@ -14,7 +14,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
OSWindow *window = CreateOSWindow(); OSWindow *window = OSWindow::New();
int width = 400; int width = 400;
int height = 400; int height = 400;
int x = 0; int x = 0;
......
...@@ -58,7 +58,7 @@ void main() ...@@ -58,7 +58,7 @@ void main()
{ {
window window; window window;
window.osWindow = CreateOSWindow(); window.osWindow = OSWindow::New();
if (!window.osWindow->initialize("MultiWindow", 256, 256)) if (!window.osWindow->initialize("MultiWindow", 256, 256))
{ {
return false; return false;
......
...@@ -49,7 +49,12 @@ SampleApplication::SampleApplication(std::string name, ...@@ -49,7 +49,12 @@ SampleApplication::SampleApplication(std::string name,
EGLint glesMinorVersion, EGLint glesMinorVersion,
size_t width, size_t width,
size_t height) 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; EGLint requestedRenderer = EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE;
...@@ -61,10 +66,10 @@ SampleApplication::SampleApplication(std::string name, ...@@ -61,10 +66,10 @@ SampleApplication::SampleApplication(std::string name,
// Load EGL library so we can initialize the display. // Load EGL library so we can initialize the display.
mEntryPointsLib.reset(angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME)); mEntryPointsLib.reset(angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME));
mEGLWindow.reset(new EGLWindow(glesMajorVersion, glesMinorVersion, mEGLWindow = EGLWindow::New(glesMajorVersion, glesMinorVersion,
EGLPlatformParameters(requestedRenderer))); EGLPlatformParameters(requestedRenderer));
mTimer.reset(CreateTimer()); mTimer.reset(CreateTimer());
mOSWindow.reset(CreateOSWindow()); mOSWindow = OSWindow::New();
mEGLWindow->setConfigRedBits(8); mEGLWindow->setConfigRedBits(8);
mEGLWindow->setConfigGreenBits(8); mEGLWindow->setConfigGreenBits(8);
...@@ -77,7 +82,11 @@ SampleApplication::SampleApplication(std::string name, ...@@ -77,7 +82,11 @@ SampleApplication::SampleApplication(std::string name,
mEGLWindow->setSwapInterval(0); mEGLWindow->setSwapInterval(0);
} }
SampleApplication::~SampleApplication() {} SampleApplication::~SampleApplication()
{
EGLWindow::Delete(&mEGLWindow);
OSWindow::Delete(&mOSWindow);
}
bool SampleApplication::initialize() bool SampleApplication::initialize()
{ {
...@@ -97,7 +106,7 @@ void SampleApplication::swap() ...@@ -97,7 +106,7 @@ void SampleApplication::swap()
OSWindow *SampleApplication::getWindow() const OSWindow *SampleApplication::getWindow() const
{ {
return mOSWindow.get(); return mOSWindow;
} }
EGLConfig SampleApplication::getConfig() const EGLConfig SampleApplication::getConfig() const
...@@ -129,7 +138,7 @@ int SampleApplication::run() ...@@ -129,7 +138,7 @@ int SampleApplication::run()
mOSWindow->setVisible(true); mOSWindow->setVisible(true);
if (!mEGLWindow->initializeGL(mOSWindow.get(), mEntryPointsLib.get())) if (!mEGLWindow->initializeGL(mOSWindow, mEntryPointsLib.get()))
{ {
return -1; return -1;
} }
......
...@@ -61,8 +61,8 @@ class SampleApplication ...@@ -61,8 +61,8 @@ class SampleApplication
bool mRunning; bool mRunning;
std::unique_ptr<Timer> mTimer; std::unique_ptr<Timer> mTimer;
std::unique_ptr<EGLWindow> mEGLWindow; EGLWindow *mEGLWindow;
std::unique_ptr<OSWindow> mOSWindow; OSWindow *mOSWindow;
// Handle to the entry point binding library. // Handle to the entry point binding library.
std::unique_ptr<angle::Library> mEntryPointsLib; std::unique_ptr<angle::Library> mEntryPointsLib;
......
...@@ -272,7 +272,7 @@ eglu::NativeWindow *NativeWindowFactory::createWindow(eglu::NativeDisplay *nativ ...@@ -272,7 +272,7 @@ eglu::NativeWindow *NativeWindowFactory::createWindow(eglu::NativeDisplay *nativ
NativeWindow::NativeWindow(ANGLENativeDisplay *nativeDisplay, NativeWindow::NativeWindow(ANGLENativeDisplay *nativeDisplay,
const eglu::WindowParams &params, const eglu::WindowParams &params,
EventState *eventState) EventState *eventState)
: eglu::NativeWindow(kWindowCapabilities), mWindow(CreateOSWindow()), mEvents(eventState) : eglu::NativeWindow(kWindowCapabilities), mWindow(OSWindow::New()), mEvents(eventState)
{ {
bool initialized = mWindow->initialize( bool initialized = mWindow->initialize(
"dEQP ANGLE Tests", "dEQP ANGLE Tests",
...@@ -305,7 +305,7 @@ void NativeWindow::setVisibility(eglu::WindowParams::Visibility visibility) ...@@ -305,7 +305,7 @@ void NativeWindow::setVisibility(eglu::WindowParams::Visibility visibility)
NativeWindow::~NativeWindow() NativeWindow::~NativeWindow()
{ {
delete mWindow; OSWindow::Delete(&mWindow);
} }
eglw::EGLNativeWindowType NativeWindow::getLegacyNative() eglw::EGLNativeWindowType NativeWindow::getLegacyNative()
......
...@@ -116,7 +116,7 @@ class EGLContextCompatibilityTest : public EGLTest, ...@@ -116,7 +116,7 @@ class EGLContextCompatibilityTest : public EGLTest,
EGLConfig contextConfig, EGLConfig contextConfig,
bool compatible) const bool compatible) const
{ {
OSWindow *osWindow = CreateOSWindow(); OSWindow *osWindow = OSWindow::New();
ASSERT_TRUE(osWindow != nullptr); ASSERT_TRUE(osWindow != nullptr);
osWindow->initialize("EGLContextCompatibilityTest", 500, 500); osWindow->initialize("EGLContextCompatibilityTest", 500, 500);
osWindow->setVisible(true); osWindow->setVisible(true);
...@@ -144,7 +144,7 @@ class EGLContextCompatibilityTest : public EGLTest, ...@@ -144,7 +144,7 @@ class EGLContextCompatibilityTest : public EGLTest,
eglDestroyContext(mDisplay, context); eglDestroyContext(mDisplay, context);
ASSERT_EGL_SUCCESS(); ASSERT_EGL_SUCCESS();
SafeDelete(osWindow); OSWindow::Delete(&osWindow);
} }
void testPbufferCompatibility(EGLConfig pbufferConfig, void testPbufferCompatibility(EGLConfig pbufferConfig,
......
...@@ -76,7 +76,7 @@ class EGLDeviceCreationTest : public EGLTest ...@@ -76,7 +76,7 @@ class EGLDeviceCreationTest : public EGLTest
SafeRelease(mDevice); SafeRelease(mDevice);
SafeRelease(mDeviceContext); SafeRelease(mDeviceContext);
SafeDelete(mOSWindow); OSWindow::Delete(&mOSWindow);
if (mSurface != EGL_NO_SURFACE) if (mSurface != EGL_NO_SURFACE)
{ {
...@@ -138,7 +138,7 @@ class EGLDeviceCreationTest : public EGLTest ...@@ -138,7 +138,7 @@ class EGLDeviceCreationTest : public EGLTest
ASSERT_EGL_TRUE(eglChooseConfig(mDisplay, configAttributes, &mConfig, 1, &configCount)); ASSERT_EGL_TRUE(eglChooseConfig(mDisplay, configAttributes, &mConfig, 1, &configCount));
// Create an OS Window // Create an OS Window
mOSWindow = CreateOSWindow(); mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLSurfaceTest", 64, 64); mOSWindow->initialize("EGLSurfaceTest", 64, 64);
// Create window surface // Create window surface
......
...@@ -47,7 +47,7 @@ class EGLDirectCompositionTest : public ANGLETest ...@@ -47,7 +47,7 @@ class EGLDirectCompositionTest : public ANGLETest
} }
// Create an OS Window // Create an OS Window
mOSWindow = std::unique_ptr<OSWindow>(CreateOSWindow()); mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLDirectCompositionTest", WINDOWWIDTH, WINDOWHEIGHT); mOSWindow->initialize("EGLDirectCompositionTest", WINDOWWIDTH, WINDOWHEIGHT);
auto nativeWindow = mOSWindow->getNativeWindow(); auto nativeWindow = mOSWindow->getNativeWindow();
...@@ -198,9 +198,11 @@ class EGLDirectCompositionTest : public ANGLETest ...@@ -198,9 +198,11 @@ class EGLDirectCompositionTest : public ANGLETest
return; return;
} }
ASSERT_EGL_TRUE(eglTerminate(mEglDisplay)); ASSERT_EGL_TRUE(eglTerminate(mEglDisplay));
OSWindow::Delete(&mOSWindow);
} }
std::unique_ptr<OSWindow> mOSWindow; OSWindow *mOSWindow;
ComPtr<ICompositor> mCompositor; ComPtr<ICompositor> mCompositor;
ComPtr<IDispatcherQueueController> mDispatcherController; ComPtr<IDispatcherQueueController> mDispatcherController;
ComPtr<ICompositionColorBrush> mColorBrush; ComPtr<ICompositionColorBrush> mColorBrush;
......
...@@ -31,7 +31,7 @@ class EGLPresentPathD3D11 : public EGLTest, public testing::WithParamInterface<P ...@@ -31,7 +31,7 @@ class EGLPresentPathD3D11 : public EGLTest, public testing::WithParamInterface<P
{ {
EGLTest::SetUp(); EGLTest::SetUp();
mOSWindow = CreateOSWindow(); mOSWindow = OSWindow::New();
mWindowWidth = 64; mWindowWidth = 64;
mOSWindow->initialize("EGLPresentPathD3D11", mWindowWidth, mWindowWidth); mOSWindow->initialize("EGLPresentPathD3D11", mWindowWidth, mWindowWidth);
} }
...@@ -169,7 +169,7 @@ class EGLPresentPathD3D11 : public EGLTest, public testing::WithParamInterface<P ...@@ -169,7 +169,7 @@ class EGLPresentPathD3D11 : public EGLTest, public testing::WithParamInterface<P
} }
mOSWindow->destroy(); mOSWindow->destroy();
SafeDelete(mOSWindow); OSWindow::Delete(&mOSWindow);
} }
void drawQuadUsingGL() void drawQuadUsingGL()
......
...@@ -21,7 +21,7 @@ class EGLRobustnessTest : public EGLTest, ...@@ -21,7 +21,7 @@ class EGLRobustnessTest : public EGLTest,
{ {
EGLTest::SetUp(); EGLTest::SetUp();
mOSWindow = CreateOSWindow(); mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLRobustnessTest", 500, 500); mOSWindow->initialize("EGLRobustnessTest", 500, 500);
mOSWindow->setVisible(true); mOSWindow->setVisible(true);
...@@ -80,7 +80,7 @@ class EGLRobustnessTest : public EGLTest, ...@@ -80,7 +80,7 @@ class EGLRobustnessTest : public EGLTest,
eglTerminate(mDisplay); eglTerminate(mDisplay);
EXPECT_EGL_SUCCESS(); EXPECT_EGL_SUCCESS();
SafeDelete(mOSWindow); OSWindow::Delete(&mOSWindow);
} }
void createContext(EGLint resetStrategy) void createContext(EGLint resetStrategy)
......
...@@ -42,7 +42,7 @@ class EGLSurfaceTest : public EGLTest ...@@ -42,7 +42,7 @@ class EGLSurfaceTest : public EGLTest
{ {
EGLTest::SetUp(); EGLTest::SetUp();
mOSWindow = CreateOSWindow(); mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLSurfaceTest", 64, 64); mOSWindow->initialize("EGLSurfaceTest", 64, 64);
} }
...@@ -82,7 +82,7 @@ class EGLSurfaceTest : public EGLTest ...@@ -82,7 +82,7 @@ class EGLSurfaceTest : public EGLTest
} }
mOSWindow->destroy(); mOSWindow->destroy();
SafeDelete(mOSWindow); OSWindow::Delete(&mOSWindow);
ASSERT_TRUE(mWindowSurface == EGL_NO_SURFACE && mContext == EGL_NO_CONTEXT); ASSERT_TRUE(mWindowSurface == EGL_NO_SURFACE && mContext == EGL_NO_CONTEXT);
} }
......
...@@ -64,7 +64,7 @@ class EGLSyncControlTest : public testing::Test ...@@ -64,7 +64,7 @@ class EGLSyncControlTest : public testing::Test
SafeRelease(mDevice); SafeRelease(mDevice);
SafeRelease(mDeviceContext); SafeRelease(mDeviceContext);
SafeDelete(mOSWindow); OSWindow::Delete(&mOSWindow);
if (mSurface != EGL_NO_SURFACE) if (mSurface != EGL_NO_SURFACE)
{ {
...@@ -110,7 +110,7 @@ class EGLSyncControlTest : public testing::Test ...@@ -110,7 +110,7 @@ class EGLSyncControlTest : public testing::Test
EGL_NONE}; EGL_NONE};
// Create an OS Window // Create an OS Window
mOSWindow = CreateOSWindow(); mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLSyncControlTest", 64, 64); mOSWindow->initialize("EGLSyncControlTest", 64, 64);
mOSWindow->setVisible(true); mOSWindow->setVisible(true);
......
...@@ -95,7 +95,7 @@ TEST_P(EGLX11VisualHintTest, ValidVisualIDAndClear) ...@@ -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 // 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. // 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->initialize("EGLX11VisualHintTest", 500, 500);
osWindow->setVisible(true); osWindow->setVisible(true);
...@@ -151,7 +151,7 @@ TEST_P(EGLX11VisualHintTest, ValidVisualIDAndClear) ...@@ -151,7 +151,7 @@ TEST_P(EGLX11VisualHintTest, ValidVisualIDAndClear)
eglDestroyContext(display, context); eglDestroyContext(display, context);
ASSERT_EGL_SUCCESS(); ASSERT_EGL_SUCCESS();
SafeDelete(osWindow); OSWindow::Delete(&osWindow);
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglTerminate(display); eglTerminate(display);
...@@ -165,7 +165,7 @@ TEST_P(EGLX11VisualHintTest, InvalidWindowVisualID) ...@@ -165,7 +165,7 @@ TEST_P(EGLX11VisualHintTest, InvalidWindowVisualID)
// creation will succeed. // creation will succeed.
int visualId; int visualId;
{ {
OSWindow *osWindow = CreateOSWindow(); OSWindow *osWindow = OSWindow::New();
osWindow->initialize("EGLX11VisualHintTest", 500, 500); osWindow->initialize("EGLX11VisualHintTest", 500, 500);
osWindow->setVisible(true); osWindow->setVisible(true);
...@@ -175,7 +175,7 @@ TEST_P(EGLX11VisualHintTest, InvalidWindowVisualID) ...@@ -175,7 +175,7 @@ TEST_P(EGLX11VisualHintTest, InvalidWindowVisualID)
ASSERT_NE(0, XGetWindowAttributes(mDisplay, xWindow, &windowAttributes)); ASSERT_NE(0, XGetWindowAttributes(mDisplay, xWindow, &windowAttributes));
visualId = windowAttributes.visual->visualid; visualId = windowAttributes.visual->visualid;
SafeDelete(osWindow); OSWindow::Delete(&osWindow);
} }
auto attributes = getDisplayAttributes(visualId); auto attributes = getDisplayAttributes(visualId);
...@@ -205,7 +205,7 @@ TEST_P(EGLX11VisualHintTest, InvalidWindowVisualID) ...@@ -205,7 +205,7 @@ TEST_P(EGLX11VisualHintTest, InvalidWindowVisualID)
ASSERT_EQ(EGL_NO_SURFACE, window); ASSERT_EQ(EGL_NO_SURFACE, window);
ASSERT_EGL_ERROR(EGL_BAD_MATCH); ASSERT_EGL_ERROR(EGL_BAD_MATCH);
SafeDelete(osWindow); OSWindow::Delete(&osWindow);
} }
ANGLE_INSTANTIATE_TEST(EGLX11VisualHintTest, ES2_OPENGL()); ANGLE_INSTANTIATE_TEST(EGLX11VisualHintTest, ES2_OPENGL());
...@@ -632,7 +632,7 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam<PlatformsWi ...@@ -632,7 +632,7 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam<PlatformsWi
public: public:
void SetUp() override void SetUp() override
{ {
mOSWindow = CreateOSWindow(); mOSWindow = OSWindow::New();
bool result = mOSWindow->initialize("ProgramBinariesAcrossRenderersTests", 100, 100); bool result = mOSWindow->initialize("ProgramBinariesAcrossRenderersTests", 100, 100);
if (result == false) if (result == false)
...@@ -646,12 +646,11 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam<PlatformsWi ...@@ -646,12 +646,11 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam<PlatformsWi
EGLWindow *createAndInitEGLWindow(angle::PlatformParameters &param) EGLWindow *createAndInitEGLWindow(angle::PlatformParameters &param)
{ {
EGLWindow *eglWindow = 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()); bool result = eglWindow->initializeGL(mOSWindow, mEntryPointsLib.get());
if (result == false) if (result == false)
{ {
SafeDelete(eglWindow); EGLWindow::Delete(&eglWindow);
eglWindow = nullptr;
} }
angle::LoadGLES(eglGetProcAddress); angle::LoadGLES(eglGetProcAddress);
...@@ -663,8 +662,7 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam<PlatformsWi ...@@ -663,8 +662,7 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam<PlatformsWi
{ {
ASSERT_NE(nullptr, *eglWindow); ASSERT_NE(nullptr, *eglWindow);
(*eglWindow)->destroyGL(); (*eglWindow)->destroyGL();
SafeDelete(*eglWindow); EGLWindow::Delete(eglWindow);
*eglWindow = nullptr;
} }
GLuint createES2ProgramFromSource() GLuint createES2ProgramFromSource()
...@@ -706,7 +704,7 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam<PlatformsWi ...@@ -706,7 +704,7 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam<PlatformsWi
void TearDown() override void TearDown() override
{ {
mOSWindow->destroy(); mOSWindow->destroy();
SafeDelete(mOSWindow); OSWindow::Delete(&mOSWindow);
} }
OSWindow *mOSWindow = nullptr; OSWindow *mOSWindow = nullptr;
......
...@@ -311,7 +311,7 @@ std::string RenderTestParams::suffix() const ...@@ -311,7 +311,7 @@ std::string RenderTestParams::suffix() const
ANGLERenderTest::ANGLERenderTest(const std::string &name, const RenderTestParams &testParams) ANGLERenderTest::ANGLERenderTest(const std::string &name, const RenderTestParams &testParams)
: ANGLEPerfTest(name, testParams.suffix(), OneFrame() ? 1 : testParams.iterationsPerStep), : ANGLEPerfTest(name, testParams.suffix(), OneFrame() ? 1 : testParams.iterationsPerStep),
mTestParams(testParams), mTestParams(testParams),
mEGLWindow(createEGLWindow(testParams)), mGLWindow(nullptr),
mOSWindow(nullptr) mOSWindow(nullptr)
{ {
// Force fast tests to make sure our slowest bots don't time out. // 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 ...@@ -322,12 +322,14 @@ ANGLERenderTest::ANGLERenderTest(const std::string &name, const RenderTestParams
// Try to ensure we don't trigger allocation during execution. // Try to ensure we don't trigger allocation during execution.
mTraceEventBuffer.reserve(kInitialTraceEventBufferSize); mTraceEventBuffer.reserve(kInitialTraceEventBufferSize);
mGLWindow = createEGLWindow(testParams);
} }
ANGLERenderTest::~ANGLERenderTest() ANGLERenderTest::~ANGLERenderTest()
{ {
SafeDelete(mOSWindow); OSWindow::Delete(&mOSWindow);
SafeDelete(mEGLWindow); GLWindowBase::Delete(&mGLWindow);
} }
void ANGLERenderTest::addExtensionPrerequisite(const char *extensionName) void ANGLERenderTest::addExtensionPrerequisite(const char *extensionName)
...@@ -342,15 +344,15 @@ void ANGLERenderTest::SetUp() ...@@ -342,15 +344,15 @@ void ANGLERenderTest::SetUp()
// Set a consistent CPU core affinity and high priority. // Set a consistent CPU core affinity and high priority.
angle::StabilizeCPUForBenchmarking(); angle::StabilizeCPUForBenchmarking();
mOSWindow = CreateOSWindow(); mOSWindow = OSWindow::New();
if (!mEGLWindow) if (!mGLWindow)
{ {
abortTest(); mSkipTest = true;
return; return;
} }
mEGLWindow->setSwapInterval(0); mGLWindow->setSwapInterval(0);
mPlatformMethods.overrideWorkaroundsD3D = OverrideWorkaroundsD3D; mPlatformMethods.overrideWorkaroundsD3D = OverrideWorkaroundsD3D;
mPlatformMethods.logError = EmptyPlatformMethod; mPlatformMethods.logError = EmptyPlatformMethod;
...@@ -361,7 +363,7 @@ void ANGLERenderTest::SetUp() ...@@ -361,7 +363,7 @@ void ANGLERenderTest::SetUp()
mPlatformMethods.updateTraceEventDuration = UpdateTraceEventDuration; mPlatformMethods.updateTraceEventDuration = UpdateTraceEventDuration;
mPlatformMethods.monotonicallyIncreasingTime = MonotonicallyIncreasingTime; mPlatformMethods.monotonicallyIncreasingTime = MonotonicallyIncreasingTime;
mPlatformMethods.context = this; mPlatformMethods.context = this;
mEGLWindow->setPlatformMethods(&mPlatformMethods); mGLWindow->setPlatformMethods(&mPlatformMethods);
if (!mOSWindow->initialize(mName, mTestParams.windowWidth, mTestParams.windowHeight)) if (!mOSWindow->initialize(mName, mTestParams.windowWidth, mTestParams.windowHeight))
{ {
...@@ -374,9 +376,9 @@ void ANGLERenderTest::SetUp() ...@@ -374,9 +376,9 @@ void ANGLERenderTest::SetUp()
mEntryPointsLib.reset(angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME)); mEntryPointsLib.reset(angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME));
#endif // defined(ANGLE_USE_UTIL_LOADER) #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; return;
} }
...@@ -406,10 +408,22 @@ void ANGLERenderTest::SetUp() ...@@ -406,10 +408,22 @@ void ANGLERenderTest::SetUp()
void ANGLERenderTest::TearDown() void ANGLERenderTest::TearDown()
{ {
destroyBenchmark(); if (!mSkipTest)
{
destroyBenchmark();
}
mEGLWindow->destroyGL(); if (mGLWindow)
mOSWindow->destroy(); {
mGLWindow->destroyGL();
mGLWindow = nullptr;
}
if (mOSWindow)
{
mOSWindow->destroy();
mOSWindow = nullptr;
}
// Dump trace events to json file. // Dump trace events to json file.
if (gEnableTrace) if (gEnableTrace)
...@@ -446,7 +460,7 @@ void ANGLERenderTest::step() ...@@ -446,7 +460,7 @@ void ANGLERenderTest::step()
// to swap. // to swap.
if (mTestParams.eglParameters.deviceType != EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE) if (mTestParams.eglParameters.deviceType != EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE)
{ {
mEGLWindow->swap(); mGLWindow->swap();
} }
mOSWindow->messageLoop(); mOSWindow->messageLoop();
} }
...@@ -486,12 +500,12 @@ bool ANGLERenderTest::areExtensionPrerequisitesFulfilled() const ...@@ -486,12 +500,12 @@ bool ANGLERenderTest::areExtensionPrerequisitesFulfilled() const
void ANGLERenderTest::setWebGLCompatibilityEnabled(bool webglCompatibility) void ANGLERenderTest::setWebGLCompatibilityEnabled(bool webglCompatibility)
{ {
mEGLWindow->setWebGLCompatibilityEnabled(webglCompatibility); mGLWindow->setWebGLCompatibilityEnabled(webglCompatibility);
} }
void ANGLERenderTest::setRobustResourceInit(bool enabled) void ANGLERenderTest::setRobustResourceInit(bool enabled)
{ {
mEGLWindow->setRobustResourceInit(enabled); mGLWindow->setRobustResourceInit(enabled);
} }
std::vector<TraceEvent> &ANGLERenderTest::getTraceEventBuffer() std::vector<TraceEvent> &ANGLERenderTest::getTraceEventBuffer()
...@@ -502,8 +516,8 @@ std::vector<TraceEvent> &ANGLERenderTest::getTraceEventBuffer() ...@@ -502,8 +516,8 @@ std::vector<TraceEvent> &ANGLERenderTest::getTraceEventBuffer()
// static // static
EGLWindow *ANGLERenderTest::createEGLWindow(const RenderTestParams &testParams) EGLWindow *ANGLERenderTest::createEGLWindow(const RenderTestParams &testParams)
{ {
return new EGLWindow(testParams.majorVersion, testParams.minorVersion, return EGLWindow::New(testParams.majorVersion, testParams.minorVersion,
testParams.eglParameters); testParams.eglParameters);
} }
void ANGLEProcessPerfTestArgs(int *argc, char **argv) void ANGLEProcessPerfTestArgs(int *argc, char **argv)
......
...@@ -151,7 +151,7 @@ class ANGLERenderTest : public ANGLEPerfTest ...@@ -151,7 +151,7 @@ class ANGLERenderTest : public ANGLEPerfTest
static EGLWindow *createEGLWindow(const RenderTestParams &testParams); static EGLWindow *createEGLWindow(const RenderTestParams &testParams);
EGLWindow *mEGLWindow; GLWindowBase *mGLWindow;
OSWindow *mOSWindow; OSWindow *mOSWindow;
std::vector<const char *> mExtensionPrerequisites; std::vector<const char *> mExtensionPrerequisites;
angle::PlatformMethods mPlatformMethods; angle::PlatformMethods mPlatformMethods;
......
...@@ -95,7 +95,7 @@ EGLInitializePerfTest::EGLInitializePerfTest() ...@@ -95,7 +95,7 @@ EGLInitializePerfTest::EGLInitializePerfTest()
} }
displayAttributes.push_back(EGL_NONE); displayAttributes.push_back(EGL_NONE);
mOSWindow = CreateOSWindow(); mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLInitialize Test", 64, 64); mOSWindow->initialize("EGLInitialize Test", 64, 64);
auto eglGetPlatformDisplayEXT = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>( auto eglGetPlatformDisplayEXT = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(
...@@ -125,7 +125,7 @@ void EGLInitializePerfTest::SetUp() ...@@ -125,7 +125,7 @@ void EGLInitializePerfTest::SetUp()
EGLInitializePerfTest::~EGLInitializePerfTest() EGLInitializePerfTest::~EGLInitializePerfTest()
{ {
SafeDelete(mOSWindow); OSWindow::Delete(&mOSWindow);
} }
void EGLInitializePerfTest::step() void EGLInitializePerfTest::step()
......
...@@ -59,7 +59,7 @@ EGLMakeCurrentPerfTest::EGLMakeCurrentPerfTest() ...@@ -59,7 +59,7 @@ EGLMakeCurrentPerfTest::EGLMakeCurrentPerfTest()
displayAttributes.push_back(platform.deviceType); displayAttributes.push_back(platform.deviceType);
displayAttributes.push_back(EGL_NONE); displayAttributes.push_back(EGL_NONE);
mOSWindow = CreateOSWindow(); mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLMakeCurrent Test", 64, 64); mOSWindow->initialize("EGLMakeCurrent Test", 64, 64);
mEGLLibrary.reset(angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME)); mEGLLibrary.reset(angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME));
......
...@@ -293,7 +293,7 @@ ANGLETestBase::ANGLETestBase(const angle::PlatformParameters &params) ...@@ -293,7 +293,7 @@ ANGLETestBase::ANGLETestBase(const angle::PlatformParameters &params)
m3DTexturedQuadProgram(0), m3DTexturedQuadProgram(0),
mDeferContextInit(false) 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. // Default debug layers to enabled in tests.
mEGLWindow->setDebugLayersEnabled(true); mEGLWindow->setDebugLayersEnabled(true);
...@@ -333,7 +333,7 @@ ANGLETestBase::~ANGLETestBase() ...@@ -333,7 +333,7 @@ ANGLETestBase::~ANGLETestBase()
{ {
glDeleteProgram(m3DTexturedQuadProgram); glDeleteProgram(m3DTexturedQuadProgram);
} }
SafeDelete(mEGLWindow); EGLWindow::Delete(&mEGLWindow);
} }
void ANGLETestBase::ANGLETestSetUp() void ANGLETestBase::ANGLETestSetUp()
...@@ -372,10 +372,6 @@ void ANGLETestBase::ANGLETestSetUp() ...@@ -372,10 +372,6 @@ void ANGLETestBase::ANGLETestSetUp()
FAIL() << "GL Context init failed."; FAIL() << "GL Context init failed.";
} }
#if defined(ANGLE_USE_UTIL_LOADER)
angle::LoadGLES(eglGetProcAddress);
#endif // defined(ANGLE_USE_UTIL_LOADER)
if (needSwap) if (needSwap)
{ {
// Swap the buffers so that the default framebuffer picks up the resize // Swap the buffers so that the default framebuffer picks up the resize
...@@ -395,27 +391,22 @@ void ANGLETestBase::ANGLETestSetUp() ...@@ -395,27 +391,22 @@ void ANGLETestBase::ANGLETestSetUp()
void ANGLETestBase::ANGLETestTearDown() void ANGLETestBase::ANGLETestTearDown()
{ {
mEGLWindow->setPlatformMethods(nullptr); if (mEGLWindow)
{
mEGLWindow->setPlatformMethods(nullptr);
checkD3D11SDKLayersMessages();
}
mPlatformContext.currentTest = nullptr; mPlatformContext.currentTest = nullptr;
checkD3D11SDKLayersMessages();
const auto &info = testing::UnitTest::GetInstance()->current_test_info(); const auto &info = testing::UnitTest::GetInstance()->current_test_info();
angle::WriteDebugMessage("Exiting %s.%s\n", info->test_case_name(), info->name()); angle::WriteDebugMessage("Exiting %s.%s\n", info->test_case_name(), info->name());
swapBuffers(); swapBuffers();
if (eglGetError() != EGL_SUCCESS)
{
FAIL() << "egl error during swap.";
}
mOSWindow->messageLoop(); mOSWindow->messageLoop();
if (!destroyEGLContext()) getGLWindow()->destroyGL();
{
FAIL() << "egl context destruction failed.";
}
// Check for quit message // Check for quit message
Event myEvent; Event myEvent;
...@@ -430,9 +421,14 @@ void ANGLETestBase::ANGLETestTearDown() ...@@ -430,9 +421,14 @@ void ANGLETestBase::ANGLETestTearDown()
void ANGLETestBase::swapBuffers() 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) ...@@ -904,34 +900,39 @@ void ANGLETestBase::setWindowHeight(int height)
mHeight = height; mHeight = height;
} }
GLWindowBase *ANGLETestBase::getGLWindow() const
{
return mEGLWindow;
}
void ANGLETestBase::setConfigRedBits(int bits) void ANGLETestBase::setConfigRedBits(int bits)
{ {
mEGLWindow->setConfigRedBits(bits); getGLWindow()->setConfigRedBits(bits);
} }
void ANGLETestBase::setConfigGreenBits(int bits) void ANGLETestBase::setConfigGreenBits(int bits)
{ {
mEGLWindow->setConfigGreenBits(bits); getGLWindow()->setConfigGreenBits(bits);
} }
void ANGLETestBase::setConfigBlueBits(int bits) void ANGLETestBase::setConfigBlueBits(int bits)
{ {
mEGLWindow->setConfigBlueBits(bits); getGLWindow()->setConfigBlueBits(bits);
} }
void ANGLETestBase::setConfigAlphaBits(int bits) void ANGLETestBase::setConfigAlphaBits(int bits)
{ {
mEGLWindow->setConfigAlphaBits(bits); getGLWindow()->setConfigAlphaBits(bits);
} }
void ANGLETestBase::setConfigDepthBits(int bits) void ANGLETestBase::setConfigDepthBits(int bits)
{ {
mEGLWindow->setConfigDepthBits(bits); getGLWindow()->setConfigDepthBits(bits);
} }
void ANGLETestBase::setConfigStencilBits(int bits) void ANGLETestBase::setConfigStencilBits(int bits)
{ {
mEGLWindow->setConfigStencilBits(bits); getGLWindow()->setConfigStencilBits(bits);
} }
void ANGLETestBase::setConfigComponentType(EGLenum componentType) void ANGLETestBase::setConfigComponentType(EGLenum componentType)
...@@ -1039,16 +1040,10 @@ bool ANGLETestBase::isMultisampleEnabled() const ...@@ -1039,16 +1040,10 @@ bool ANGLETestBase::isMultisampleEnabled() const
return mEGLWindow->isMultisample(); return mEGLWindow->isMultisample();
} }
bool ANGLETestBase::destroyEGLContext()
{
mEGLWindow->destroyGL();
return true;
}
// static // static
bool ANGLETestBase::InitTestWindow() bool ANGLETestBase::InitTestWindow()
{ {
mOSWindow = CreateOSWindow(); mOSWindow = OSWindow::New();
if (!mOSWindow->initialize("ANGLE_TEST", 128, 128)) if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
{ {
return false; return false;
...@@ -1065,8 +1060,7 @@ bool ANGLETestBase::DestroyTestWindow() ...@@ -1065,8 +1060,7 @@ bool ANGLETestBase::DestroyTestWindow()
if (mOSWindow) if (mOSWindow)
{ {
mOSWindow->destroy(); mOSWindow->destroy();
delete mOSWindow; OSWindow::Delete(&mOSWindow);
mOSWindow = nullptr;
} }
return true; return true;
......
...@@ -235,9 +235,10 @@ GLColor32F ReadColor32F(GLint x, GLint y); ...@@ -235,9 +235,10 @@ GLColor32F ReadColor32F(GLint x, GLint y);
#define EXPECT_PIXEL_COLOR32F_NEAR(x, y, angleColor, abs_error) \ #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) EXPECT_PIXEL32F_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
class ANGLETestBase;
class EGLWindow; class EGLWindow;
class GLWindowBase;
class OSWindow; class OSWindow;
class ANGLETestBase;
struct TestPlatformContext final : private angle::NonCopyable struct TestPlatformContext final : private angle::NonCopyable
{ {
...@@ -385,8 +386,6 @@ class ANGLETestBase ...@@ -385,8 +386,6 @@ class ANGLETestBase
}; };
private: private:
bool destroyEGLContext();
void checkD3D11SDKLayersMessages(); void checkD3D11SDKLayersMessages();
void drawQuad(GLuint program, void drawQuad(GLuint program,
...@@ -397,6 +396,8 @@ class ANGLETestBase ...@@ -397,6 +396,8 @@ class ANGLETestBase
bool useInstancedDrawCalls, bool useInstancedDrawCalls,
GLuint numInstances); GLuint numInstances);
GLWindowBase *getGLWindow() const;
EGLWindow *mEGLWindow; EGLWindow *mEGLWindow;
int mWidth; int mWidth;
int mHeight; int mHeight;
......
...@@ -20,6 +20,25 @@ ...@@ -20,6 +20,25 @@
namespace angle 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) bool IsPlatformAvailable(const PlatformParameters &param)
{ {
switch (param.getRenderer()) switch (param.getRenderer())
...@@ -75,27 +94,16 @@ bool IsPlatformAvailable(const PlatformParameters &param) ...@@ -75,27 +94,16 @@ bool IsPlatformAvailable(const PlatformParameters &param)
} }
else else
{ {
OSWindow *osWindow = CreateOSWindow(); OSWindow *osWindow = OSWindow::New();
bool result = osWindow->initialize("CONFIG_TESTER", 1, 1); bool result = osWindow->initialize("CONFIG_TESTER", 1, 1);
if (result) if (result)
{ {
std::unique_ptr<angle::Library> eglLibrary; result = IsANGLEConfigSupported(param, osWindow);
#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);
} }
osWindow->destroy(); osWindow->destroy();
SafeDelete(osWindow); OSWindow::Delete(&osWindow);
paramAvailabilityCache[param] = result; paramAvailabilityCache[param] = result;
......
...@@ -557,7 +557,7 @@ void destroy_window(struct sample_info &info) ...@@ -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) void init_window_size(struct sample_info &info, int32_t default_width, int32_t default_height)
{ {
#ifdef __ANDROID__ #ifdef __ANDROID__
info.mOSWindow = CreateOSWindow(); info.mOSWindow = OSWindow::New();
assert(info.mOSWindow != nullptr); assert(info.mOSWindow != nullptr);
info.mOSWindow->initialize("VulkanTest", default_width, default_height); info.mOSWindow->initialize("VulkanTest", default_width, default_height);
#endif #endif
......
...@@ -87,39 +87,45 @@ bool operator==(const EGLPlatformParameters &a, const EGLPlatformParameters &b) ...@@ -87,39 +87,45 @@ bool operator==(const EGLPlatformParameters &a, const EGLPlatformParameters &b)
(a.presentPath == b.presentPath); (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, EGLWindow::EGLWindow(EGLint glesMajorVersion,
EGLint glesMinorVersion, EGLint glesMinorVersion,
const EGLPlatformParameters &platform) const EGLPlatformParameters &platform)
: mDisplay(EGL_NO_DISPLAY), : GLWindowBase(glesMajorVersion, glesMinorVersion),
mDisplay(EGL_NO_DISPLAY),
mSurface(EGL_NO_SURFACE), mSurface(EGL_NO_SURFACE),
mContext(EGL_NO_CONTEXT), mContext(EGL_NO_CONTEXT),
mClientMajorVersion(glesMajorVersion),
mClientMinorVersion(glesMinorVersion),
mEGLMajorVersion(0), mEGLMajorVersion(0),
mEGLMinorVersion(0), mEGLMinorVersion(0),
mPlatform(platform), mPlatform(platform),
mRedBits(-1),
mGreenBits(-1),
mBlueBits(-1),
mAlphaBits(-1),
mDepthBits(-1),
mStencilBits(-1),
mComponentType(EGL_COLOR_COMPONENT_TYPE_FIXED_EXT), mComponentType(EGL_COLOR_COMPONENT_TYPE_FIXED_EXT),
mMultisample(false), mMultisample(false),
mDebug(false), mDebug(false),
mNoError(false), mNoError(false),
mWebGLCompatibility(false),
mExtensionsEnabled(), mExtensionsEnabled(),
mBindGeneratesResource(true), mBindGeneratesResource(true),
mClientArraysEnabled(true), mClientArraysEnabled(true),
mRobustAccess(false), mRobustAccess(false),
mRobustResourceInit(),
mSwapInterval(-1),
mSamples(-1), mSamples(-1),
mDebugLayersEnabled(), mDebugLayersEnabled(),
mContextProgramCacheEnabled(), mContextProgramCacheEnabled(),
mContextVirtualization(), mContextVirtualization()
mPlatformMethods(nullptr)
{} {}
EGLWindow::~EGLWindow() EGLWindow::~EGLWindow()
...@@ -152,18 +158,18 @@ EGLContext EGLWindow::getContext() const ...@@ -152,18 +158,18 @@ EGLContext EGLWindow::getContext() const
return mContext; 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 false;
return initializeContext(); return initializeContext();
} }
bool EGLWindow::initializeDisplayAndSurface(OSWindow *osWindow, angle::Library *eglLibrary) bool EGLWindow::initializeDisplayAndSurface(OSWindow *osWindow, angle::Library *glWindowingLibrary)
{ {
#if defined(ANGLE_USE_UTIL_LOADER) #if defined(ANGLE_USE_UTIL_LOADER)
PFNEGLGETPROCADDRESSPROC getProcAddress; PFNEGLGETPROCADDRESSPROC getProcAddress;
eglLibrary->getAs("eglGetProcAddress", &getProcAddress); glWindowingLibrary->getAs("eglGetProcAddress", &getProcAddress);
if (!getProcAddress) if (!getProcAddress)
{ {
return false; return false;
...@@ -307,6 +313,10 @@ bool EGLWindow::initializeDisplayAndSurface(OSWindow *osWindow, angle::Library * ...@@ -307,6 +313,10 @@ bool EGLWindow::initializeDisplayAndSurface(OSWindow *osWindow, angle::Library *
return false; return false;
} }
#if defined(ANGLE_USE_UTIL_LOADER)
angle::LoadGLES(eglGetProcAddress);
#endif // defined(ANGLE_USE_UTIL_LOADER)
return true; return true;
} }
...@@ -324,7 +334,7 @@ EGLContext EGLWindow::createContext(EGLContext share) const ...@@ -324,7 +334,7 @@ EGLContext EGLWindow::createContext(EGLContext share) const
bool hasWebGLCompatibility = bool hasWebGLCompatibility =
strstr(displayExtensions, "EGL_ANGLE_create_context_webgl_compatibility") != nullptr; strstr(displayExtensions, "EGL_ANGLE_create_context_webgl_compatibility") != nullptr;
if (mWebGLCompatibility && !hasWebGLCompatibility) if (mWebGLCompatibility.valid() && !hasWebGLCompatibility)
{ {
return EGL_NO_CONTEXT; return EGL_NO_CONTEXT;
} }
...@@ -389,10 +399,10 @@ EGLContext EGLWindow::createContext(EGLContext share) const ...@@ -389,10 +399,10 @@ EGLContext EGLWindow::createContext(EGLContext share) const
contextAttributes.push_back(EGL_CONTEXT_OPENGL_NO_ERROR_KHR); contextAttributes.push_back(EGL_CONTEXT_OPENGL_NO_ERROR_KHR);
contextAttributes.push_back(mNoError ? EGL_TRUE : EGL_FALSE); contextAttributes.push_back(mNoError ? EGL_TRUE : EGL_FALSE);
if (hasWebGLCompatibility) if (mWebGLCompatibility.valid())
{ {
contextAttributes.push_back(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE); 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()) if (mExtensionsEnabled.valid())
...@@ -552,3 +562,25 @@ bool CheckExtensionExists(const char *allExtensions, const std::string &extName) ...@@ -552,3 +562,25 @@ bool CheckExtensionExists(const char *allExtensions, const std::string &extName)
return paddedExtensions.find(std::string(" ") + extName + std::string(" ")) != return paddedExtensions.find(std::string(" ") + extName + std::string(" ")) !=
std::string::npos; 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; ...@@ -26,30 +26,78 @@ class Library;
struct PlatformMethods; struct PlatformMethods;
} // namespace angle } // namespace angle
class ANGLE_UTIL_EXPORT EGLWindow : angle::NonCopyable class ANGLE_UTIL_EXPORT GLWindowBase : angle::NonCopyable
{ {
public: public:
EGLWindow(EGLint glesMajorVersion, static void Delete(GLWindowBase **window);
EGLint glesMinorVersion,
const EGLPlatformParameters &platform);
~EGLWindow();
// It should also be possible to set multisample and floating point framebuffers.
void setConfigRedBits(int bits) { mRedBits = bits; } void setConfigRedBits(int bits) { mRedBits = bits; }
void setConfigGreenBits(int bits) { mGreenBits = bits; } void setConfigGreenBits(int bits) { mGreenBits = bits; }
void setConfigBlueBits(int bits) { mBlueBits = bits; } void setConfigBlueBits(int bits) { mBlueBits = bits; }
void setConfigAlphaBits(int bits) { mAlphaBits = bits; } void setConfigAlphaBits(int bits) { mAlphaBits = bits; }
void setConfigDepthBits(int bits) { mDepthBits = bits; } void setConfigDepthBits(int bits) { mDepthBits = bits; }
void setConfigStencilBits(int bits) { mStencilBits = 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 setConfigComponentType(EGLenum componentType) { mComponentType = componentType; }
void setMultisample(bool multisample) { mMultisample = multisample; } void setMultisample(bool multisample) { mMultisample = multisample; }
void setSamples(EGLint samples) { mSamples = samples; } void setSamples(EGLint samples) { mSamples = samples; }
void setDebugEnabled(bool debug) { mDebug = debug; } void setDebugEnabled(bool debug) { mDebug = debug; }
void setNoErrorEnabled(bool noError) { mNoError = noError; } void setNoErrorEnabled(bool noError) { mNoError = noError; }
void setWebGLCompatibilityEnabled(bool webglCompatibility)
{
mWebGLCompatibility = webglCompatibility;
}
void setExtensionsEnabled(bool extensionsEnabled) { mExtensionsEnabled = extensionsEnabled; } void setExtensionsEnabled(bool extensionsEnabled) { mExtensionsEnabled = extensionsEnabled; }
void setBindGeneratesResource(bool bindGeneratesResource) void setBindGeneratesResource(bool bindGeneratesResource)
{ {
...@@ -58,42 +106,27 @@ class ANGLE_UTIL_EXPORT EGLWindow : angle::NonCopyable ...@@ -58,42 +106,27 @@ class ANGLE_UTIL_EXPORT EGLWindow : angle::NonCopyable
void setDebugLayersEnabled(bool enabled) { mDebugLayersEnabled = enabled; } void setDebugLayersEnabled(bool enabled) { mDebugLayersEnabled = enabled; }
void setClientArraysEnabled(bool enabled) { mClientArraysEnabled = enabled; } void setClientArraysEnabled(bool enabled) { mClientArraysEnabled = enabled; }
void setRobustAccess(bool enabled) { mRobustAccess = 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 setContextProgramCacheEnabled(bool enabled) { mContextProgramCacheEnabled = enabled; }
void setContextVirtualization(bool enabled) { mContextVirtualization = enabled; } void setContextVirtualization(bool enabled) { mContextVirtualization = enabled; }
static EGLBoolean FindEGLConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *config); 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; } const EGLPlatformParameters &getPlatform() const { return mPlatform; }
EGLConfig getConfig() const; EGLConfig getConfig() const;
EGLDisplay getDisplay() const; EGLDisplay getDisplay() const;
EGLSurface getSurface() const; EGLSurface getSurface() const;
EGLContext getContext() 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 isMultisample() const { return mMultisample; }
bool isDebugEnabled() const { return mDebug; } bool isDebugEnabled() const { return mDebug; }
EGLint getSwapInterval() const { return mSwapInterval; }
const angle::PlatformMethods *getPlatformMethods() const { return mPlatformMethods; } const angle::PlatformMethods *getPlatformMethods() const { return mPlatformMethods; }
// Internally initializes the Display, Surface and Context. // 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. // 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 // Create an EGL context with this window's configuration
EGLContext createContext(EGLContext share) const; EGLContext createContext(EGLContext share) const;
...@@ -101,46 +134,39 @@ class ANGLE_UTIL_EXPORT EGLWindow : angle::NonCopyable ...@@ -101,46 +134,39 @@ class ANGLE_UTIL_EXPORT EGLWindow : angle::NonCopyable
// Only initializes the Context. // Only initializes the Context.
bool initializeContext(); bool initializeContext();
void destroyGL(); void destroyGL() override;
bool isGLInitialized() const; bool isGLInitialized() const override;
void makeCurrent() override;
void makeCurrent();
static bool ClientExtensionEnabled(const std::string &extName); static bool ClientExtensionEnabled(const std::string &extName);
private: private:
EGLWindow(EGLint glesMajorVersion,
EGLint glesMinorVersion,
const EGLPlatformParameters &platform);
~EGLWindow() override;
EGLConfig mConfig; EGLConfig mConfig;
EGLDisplay mDisplay; EGLDisplay mDisplay;
EGLSurface mSurface; EGLSurface mSurface;
EGLContext mContext; EGLContext mContext;
EGLint mClientMajorVersion;
EGLint mClientMinorVersion;
EGLint mEGLMajorVersion; EGLint mEGLMajorVersion;
EGLint mEGLMinorVersion; EGLint mEGLMinorVersion;
EGLPlatformParameters mPlatform; EGLPlatformParameters mPlatform;
int mRedBits;
int mGreenBits;
int mBlueBits;
int mAlphaBits;
int mDepthBits;
int mStencilBits;
EGLenum mComponentType; EGLenum mComponentType;
bool mMultisample; bool mMultisample;
bool mDebug; bool mDebug;
bool mNoError; bool mNoError;
bool mWebGLCompatibility;
Optional<bool> mExtensionsEnabled; Optional<bool> mExtensionsEnabled;
bool mBindGeneratesResource; bool mBindGeneratesResource;
bool mClientArraysEnabled; bool mClientArraysEnabled;
bool mRobustAccess; bool mRobustAccess;
Optional<bool> mRobustResourceInit;
EGLint mSwapInterval;
EGLint mSamples; EGLint mSamples;
Optional<bool> mDebugLayersEnabled; Optional<bool> mDebugLayersEnabled;
Optional<bool> mContextProgramCacheEnabled; Optional<bool> mContextProgramCacheEnabled;
Optional<bool> mContextVirtualization; Optional<bool> mContextVirtualization;
angle::PlatformMethods *mPlatformMethods;
}; };
ANGLE_UTIL_EXPORT bool CheckExtensionExists(const char *allExtensions, const std::string &extName); ANGLE_UTIL_EXPORT bool CheckExtensionExists(const char *allExtensions, const std::string &extName);
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "common/debug.h" #include "common/debug.h"
#ifndef DEBUG_EVENTS #ifndef DEBUG_EVENTS
#define DEBUG_EVENTS 0 # define DEBUG_EVENTS 0
#endif #endif
#if DEBUG_EVENTS #if DEBUG_EVENTS
...@@ -20,21 +20,21 @@ static const char *MouseButtonName(MouseButton button) ...@@ -20,21 +20,21 @@ static const char *MouseButtonName(MouseButton button)
{ {
switch (button) switch (button)
{ {
case MOUSEBUTTON_UNKNOWN: case MOUSEBUTTON_UNKNOWN:
return "Unknown"; return "Unknown";
case MOUSEBUTTON_LEFT: case MOUSEBUTTON_LEFT:
return "Left"; return "Left";
case MOUSEBUTTON_RIGHT: case MOUSEBUTTON_RIGHT:
return "Right"; return "Right";
case MOUSEBUTTON_MIDDLE: case MOUSEBUTTON_MIDDLE:
return "Middle"; return "Middle";
case MOUSEBUTTON_BUTTON4: case MOUSEBUTTON_BUTTON4:
return "Button4"; return "Button4";
case MOUSEBUTTON_BUTTON5: case MOUSEBUTTON_BUTTON5:
return "Button5"; return "Button5";
default: default:
UNREACHABLE(); UNREACHABLE();
return nullptr; return nullptr;
} }
} }
...@@ -42,109 +42,212 @@ static const char *KeyName(Key key) ...@@ -42,109 +42,212 @@ static const char *KeyName(Key key)
{ {
switch (key) switch (key)
{ {
case KEY_UNKNOWN: return "Unknown"; case KEY_UNKNOWN:
case KEY_A: return "A"; return "Unknown";
case KEY_B: return "B"; case KEY_A:
case KEY_C: return "C"; return "A";
case KEY_D: return "D"; case KEY_B:
case KEY_E: return "E"; return "B";
case KEY_F: return "F"; case KEY_C:
case KEY_G: return "G"; return "C";
case KEY_H: return "H"; case KEY_D:
case KEY_I: return "I"; return "D";
case KEY_J: return "J"; case KEY_E:
case KEY_K: return "K"; return "E";
case KEY_L: return "L"; case KEY_F:
case KEY_M: return "M"; return "F";
case KEY_N: return "N"; case KEY_G:
case KEY_O: return "O"; return "G";
case KEY_P: return "P"; case KEY_H:
case KEY_Q: return "Q"; return "H";
case KEY_R: return "R"; case KEY_I:
case KEY_S: return "S"; return "I";
case KEY_T: return "T"; case KEY_J:
case KEY_U: return "U"; return "J";
case KEY_V: return "V"; case KEY_K:
case KEY_W: return "W"; return "K";
case KEY_X: return "X"; case KEY_L:
case KEY_Y: return "Y"; return "L";
case KEY_Z: return "Z"; case KEY_M:
case KEY_NUM0: return "Num0"; return "M";
case KEY_NUM1: return "Num1"; case KEY_N:
case KEY_NUM2: return "Num2"; return "N";
case KEY_NUM3: return "Num3"; case KEY_O:
case KEY_NUM4: return "Num4"; return "O";
case KEY_NUM5: return "Num5"; case KEY_P:
case KEY_NUM6: return "Num6"; return "P";
case KEY_NUM7: return "Num7"; case KEY_Q:
case KEY_NUM8: return "Num8"; return "Q";
case KEY_NUM9: return "Num9"; case KEY_R:
case KEY_ESCAPE: return "Escape"; return "R";
case KEY_LCONTROL: return "Left Control"; case KEY_S:
case KEY_LSHIFT: return "Left Shift"; return "S";
case KEY_LALT: return "Left Alt"; case KEY_T:
case KEY_LSYSTEM: return "Left System"; return "T";
case KEY_RCONTROL: return "Right Control"; case KEY_U:
case KEY_RSHIFT: return "Right Shift"; return "U";
case KEY_RALT: return "Right Alt"; case KEY_V:
case KEY_RSYSTEM: return "Right System"; return "V";
case KEY_MENU: return "Menu"; case KEY_W:
case KEY_LBRACKET: return "Left Bracket"; return "W";
case KEY_RBRACKET: return "Right Bracket"; case KEY_X:
case KEY_SEMICOLON: return "Semicolon"; return "X";
case KEY_COMMA: return "Comma"; case KEY_Y:
case KEY_PERIOD: return "Period"; return "Y";
case KEY_QUOTE: return "Quote"; case KEY_Z:
case KEY_SLASH: return "Slash"; return "Z";
case KEY_BACKSLASH: return "Backslash"; case KEY_NUM0:
case KEY_TILDE: return "Tilde"; return "Num0";
case KEY_EQUAL: return "Equal"; case KEY_NUM1:
case KEY_DASH: return "Dash"; return "Num1";
case KEY_SPACE: return "Space"; case KEY_NUM2:
case KEY_RETURN: return "Return"; return "Num2";
case KEY_BACK: return "Back"; case KEY_NUM3:
case KEY_TAB: return "Tab"; return "Num3";
case KEY_PAGEUP: return "Page Up"; case KEY_NUM4:
case KEY_PAGEDOWN: return "Page Down"; return "Num4";
case KEY_END: return "End"; case KEY_NUM5:
case KEY_HOME: return "Home"; return "Num5";
case KEY_INSERT: return "Insert"; case KEY_NUM6:
case KEY_DELETE: return "Delete"; return "Num6";
case KEY_ADD: return "Add"; case KEY_NUM7:
case KEY_SUBTRACT: return "Substract"; return "Num7";
case KEY_MULTIPLY: return "Multiply"; case KEY_NUM8:
case KEY_DIVIDE: return "Divide"; return "Num8";
case KEY_LEFT: return "Left"; case KEY_NUM9:
case KEY_RIGHT: return "Right"; return "Num9";
case KEY_UP: return "Up"; case KEY_ESCAPE:
case KEY_DOWN: return "Down"; return "Escape";
case KEY_NUMPAD0: return "Numpad 0"; case KEY_LCONTROL:
case KEY_NUMPAD1: return "Numpad 1"; return "Left Control";
case KEY_NUMPAD2: return "Numpad 2"; case KEY_LSHIFT:
case KEY_NUMPAD3: return "Numpad 3"; return "Left Shift";
case KEY_NUMPAD4: return "Numpad 4"; case KEY_LALT:
case KEY_NUMPAD5: return "Numpad 5"; return "Left Alt";
case KEY_NUMPAD6: return "Numpad 6"; case KEY_LSYSTEM:
case KEY_NUMPAD7: return "Numpad 7"; return "Left System";
case KEY_NUMPAD8: return "Numpad 8"; case KEY_RCONTROL:
case KEY_NUMPAD9: return "Numpad 9"; return "Right Control";
case KEY_F1: return "F1"; case KEY_RSHIFT:
case KEY_F2: return "F2"; return "Right Shift";
case KEY_F3: return "F3"; case KEY_RALT:
case KEY_F4: return "F4"; return "Right Alt";
case KEY_F5: return "F5"; case KEY_RSYSTEM:
case KEY_F6: return "F6"; return "Right System";
case KEY_F7: return "F7"; case KEY_MENU:
case KEY_F8: return "F8"; return "Menu";
case KEY_F9: return "F9"; case KEY_LBRACKET:
case KEY_F10: return "F10"; return "Left Bracket";
case KEY_F11: return "F11"; case KEY_RBRACKET:
case KEY_F12: return "F12"; return "Right Bracket";
case KEY_F13: return "F13"; case KEY_SEMICOLON:
case KEY_F14: return "F14"; return "Semicolon";
case KEY_F15: return "F15"; case KEY_COMMA:
case KEY_PAUSE: return "Pause"; return "Comma";
default: return "Unknown Key"; case KEY_PERIOD:
return "Period";
case KEY_QUOTE:
return "Quote";
case KEY_SLASH:
return "Slash";
case KEY_BACKSLASH:
return "Backslash";
case KEY_TILDE:
return "Tilde";
case KEY_EQUAL:
return "Equal";
case KEY_DASH:
return "Dash";
case KEY_SPACE:
return "Space";
case KEY_RETURN:
return "Return";
case KEY_BACK:
return "Back";
case KEY_TAB:
return "Tab";
case KEY_PAGEUP:
return "Page Up";
case KEY_PAGEDOWN:
return "Page Down";
case KEY_END:
return "End";
case KEY_HOME:
return "Home";
case KEY_INSERT:
return "Insert";
case KEY_DELETE:
return "Delete";
case KEY_ADD:
return "Add";
case KEY_SUBTRACT:
return "Substract";
case KEY_MULTIPLY:
return "Multiply";
case KEY_DIVIDE:
return "Divide";
case KEY_LEFT:
return "Left";
case KEY_RIGHT:
return "Right";
case KEY_UP:
return "Up";
case KEY_DOWN:
return "Down";
case KEY_NUMPAD0:
return "Numpad 0";
case KEY_NUMPAD1:
return "Numpad 1";
case KEY_NUMPAD2:
return "Numpad 2";
case KEY_NUMPAD3:
return "Numpad 3";
case KEY_NUMPAD4:
return "Numpad 4";
case KEY_NUMPAD5:
return "Numpad 5";
case KEY_NUMPAD6:
return "Numpad 6";
case KEY_NUMPAD7:
return "Numpad 7";
case KEY_NUMPAD8:
return "Numpad 8";
case KEY_NUMPAD9:
return "Numpad 9";
case KEY_F1:
return "F1";
case KEY_F2:
return "F2";
case KEY_F3:
return "F3";
case KEY_F4:
return "F4";
case KEY_F5:
return "F5";
case KEY_F6:
return "F6";
case KEY_F7:
return "F7";
case KEY_F8:
return "F8";
case KEY_F9:
return "F9";
case KEY_F10:
return "F10";
case KEY_F11:
return "F11";
case KEY_F12:
return "F12";
case KEY_F13:
return "F13";
case KEY_F14:
return "F14";
case KEY_F15:
return "F15";
case KEY_PAUSE:
return "Pause";
default:
return "Unknown Key";
} }
} }
...@@ -178,78 +281,75 @@ static std::string KeyState(const Event::KeyEvent &event) ...@@ -178,78 +281,75 @@ static std::string KeyState(const Event::KeyEvent &event)
return ""; return "";
} }
static void PrintEvent(const Event& event) static void PrintEvent(const Event &event)
{ {
switch (event.Type) switch (event.Type)
{ {
case Event::EVENT_CLOSED: case Event::EVENT_CLOSED:
std::cout << "Event: Window Closed" << std::endl; std::cout << "Event: Window Closed" << std::endl;
break; break;
case Event::EVENT_MOVED: case Event::EVENT_MOVED:
std::cout << "Event: Window Moved (" << event.Move.X std::cout << "Event: Window Moved (" << event.Move.X << ", " << event.Move.Y << ")"
<< ", " << event.Move.Y << ")" << std::endl; << std::endl;
break; break;
case Event::EVENT_RESIZED: case Event::EVENT_RESIZED:
std::cout << "Event: Window Resized (" << event.Size.Width std::cout << "Event: Window Resized (" << event.Size.Width << ", " << event.Size.Height
<< ", " << event.Size.Height << ")" << std::endl; << ")" << std::endl;
break; break;
case Event::EVENT_LOST_FOCUS: case Event::EVENT_LOST_FOCUS:
std::cout << "Event: Window Lost Focus" << std::endl; std::cout << "Event: Window Lost Focus" << std::endl;
break; break;
case Event::EVENT_GAINED_FOCUS: case Event::EVENT_GAINED_FOCUS:
std::cout << "Event: Window Gained Focus" << std::endl; std::cout << "Event: Window Gained Focus" << std::endl;
break; break;
case Event::EVENT_TEXT_ENTERED: case Event::EVENT_TEXT_ENTERED:
// TODO(cwallez) show the character // TODO(cwallez) show the character
std::cout << "Event: Text Entered" << std::endl; std::cout << "Event: Text Entered" << std::endl;
break; break;
case Event::EVENT_KEY_PRESSED: case Event::EVENT_KEY_PRESSED:
std::cout << "Event: Key Pressed (" << KeyName(event.Key.Code) << KeyState(event.Key) << ")" << std::endl; std::cout << "Event: Key Pressed (" << KeyName(event.Key.Code) << KeyState(event.Key)
break; << ")" << std::endl;
case Event::EVENT_KEY_RELEASED: break;
std::cout << "Event: Key Released (" << KeyName(event.Key.Code) << KeyState(event.Key) << ")" << std::endl; case Event::EVENT_KEY_RELEASED:
break; std::cout << "Event: Key Released (" << KeyName(event.Key.Code) << KeyState(event.Key)
case Event::EVENT_MOUSE_WHEEL_MOVED: << ")" << std::endl;
std::cout << "Event: Mouse Wheel (" << event.MouseWheel.Delta << ")" << std::endl; break;
break; case Event::EVENT_MOUSE_WHEEL_MOVED:
case Event::EVENT_MOUSE_BUTTON_PRESSED: std::cout << "Event: Mouse Wheel (" << event.MouseWheel.Delta << ")" << std::endl;
std::cout << "Event: Mouse Button Pressed " << MouseButtonName(event.MouseButton.Button) << break;
" at (" << event.MouseButton.X << ", " << event.MouseButton.Y << ")" << std::endl; case Event::EVENT_MOUSE_BUTTON_PRESSED:
break; std::cout << "Event: Mouse Button Pressed " << MouseButtonName(event.MouseButton.Button)
case Event::EVENT_MOUSE_BUTTON_RELEASED: << " at (" << event.MouseButton.X << ", " << event.MouseButton.Y << ")"
std::cout << "Event: Mouse Button Released " << MouseButtonName(event.MouseButton.Button) << << std::endl;
" at (" << event.MouseButton.X << ", " << event.MouseButton.Y << ")" << std::endl; break;
break; case Event::EVENT_MOUSE_BUTTON_RELEASED:
case Event::EVENT_MOUSE_MOVED: std::cout << "Event: Mouse Button Released "
std::cout << "Event: Mouse Moved (" << event.MouseMove.X << MouseButtonName(event.MouseButton.Button) << " at (" << event.MouseButton.X
<< ", " << event.MouseMove.Y << ")" << std::endl; << ", " << event.MouseButton.Y << ")" << std::endl;
break; break;
case Event::EVENT_MOUSE_ENTERED: case Event::EVENT_MOUSE_MOVED:
std::cout << "Event: Mouse Entered Window" << std::endl; std::cout << "Event: Mouse Moved (" << event.MouseMove.X << ", " << event.MouseMove.Y
break; << ")" << std::endl;
case Event::EVENT_MOUSE_LEFT: break;
std::cout << "Event: Mouse Left Window" << std::endl; case Event::EVENT_MOUSE_ENTERED:
break; std::cout << "Event: Mouse Entered Window" << std::endl;
case Event::EVENT_TEST: break;
std::cout << "Event: Test" << std::endl; case Event::EVENT_MOUSE_LEFT:
break; std::cout << "Event: Mouse Left Window" << std::endl;
default: break;
UNREACHABLE(); case Event::EVENT_TEST:
break; std::cout << "Event: Test" << std::endl;
break;
default:
UNREACHABLE();
break;
} }
} }
#endif #endif
OSWindow::OSWindow() OSWindow::OSWindow() : mX(0), mY(0), mWidth(0), mHeight(0) {}
: mX(0),
mY(0),
mWidth(0),
mHeight(0)
{
}
OSWindow::~OSWindow() OSWindow::~OSWindow() {}
{}
int OSWindow::getX() const int OSWindow::getX() const
{ {
...@@ -294,16 +394,16 @@ void OSWindow::pushEvent(Event event) ...@@ -294,16 +394,16 @@ void OSWindow::pushEvent(Event event)
{ {
switch (event.Type) switch (event.Type)
{ {
case Event::EVENT_MOVED: case Event::EVENT_MOVED:
mX = event.Move.X; mX = event.Move.X;
mY = event.Move.Y; mY = event.Move.Y;
break; break;
case Event::EVENT_RESIZED: case Event::EVENT_RESIZED:
mWidth = event.Size.Width; mWidth = event.Size.Width;
mHeight = event.Size.Height; mHeight = event.Size.Height;
break; break;
default: default:
break; break;
} }
mEvents.push_back(event); mEvents.push_back(event);
...@@ -326,3 +426,10 @@ bool OSWindow::didTestEventFire() ...@@ -326,3 +426,10 @@ bool OSWindow::didTestEventFire()
return false; return false;
} }
// static
void OSWindow::Delete(OSWindow **window)
{
delete *window;
*window = nullptr;
}
...@@ -3,9 +3,11 @@ ...@@ -3,9 +3,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// OSWindow:
// Operating system window integration base class.
#ifndef SAMPLE_UTIL_WINDOW_H #ifndef UTIL_OSWINDOW_H_
#define SAMPLE_UTIL_WINDOW_H #define UTIL_OSWINDOW_H_
#include <stdint.h> #include <stdint.h>
#include <list> #include <list>
...@@ -20,8 +22,8 @@ ...@@ -20,8 +22,8 @@
class ANGLE_UTIL_EXPORT OSWindow class ANGLE_UTIL_EXPORT OSWindow
{ {
public: public:
OSWindow(); static OSWindow *New();
virtual ~OSWindow(); static void Delete(OSWindow **osWindow);
virtual bool initialize(const std::string &name, size_t width, size_t height) = 0; virtual bool initialize(const std::string &name, size_t width, size_t height) = 0;
virtual void destroy() = 0; virtual void destroy() = 0;
...@@ -56,6 +58,10 @@ class ANGLE_UTIL_EXPORT OSWindow ...@@ -56,6 +58,10 @@ class ANGLE_UTIL_EXPORT OSWindow
bool didTestEventFire(); bool didTestEventFire();
protected: protected:
OSWindow();
virtual ~OSWindow();
friend ANGLE_UTIL_EXPORT void FreeOSWindow(OSWindow *window);
int mX; int mX;
int mY; int mY;
int mWidth; int mWidth;
...@@ -64,6 +70,4 @@ class ANGLE_UTIL_EXPORT OSWindow ...@@ -64,6 +70,4 @@ class ANGLE_UTIL_EXPORT OSWindow
std::list<Event> mEvents; std::list<Event> mEvents;
}; };
ANGLE_UTIL_EXPORT OSWindow *CreateOSWindow(); #endif // UTIL_OSWINDOW_H_
#endif // SAMPLE_UTIL_WINDOW_H
...@@ -86,16 +86,6 @@ void AndroidWindow::signalTestEvent() ...@@ -86,16 +86,6 @@ void AndroidWindow::signalTestEvent()
UNIMPLEMENTED(); 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) static void onAppCmd(struct android_app *app, int32_t cmd)
{ {
switch (cmd) switch (cmd)
...@@ -144,3 +134,14 @@ void android_main(struct android_app *app) ...@@ -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 ...@@ -777,7 +777,8 @@ NSWindow *OSXWindow::getNSWindow() const
return mWindow; return mWindow;
} }
OSWindow *CreateOSWindow() // static
OSWindow *OSWindow::New()
{ {
return new OSXWindow; return new OSXWindow;
} }
...@@ -64,7 +64,8 @@ void OzoneWindow::setVisible(bool isVisible) ...@@ -64,7 +64,8 @@ void OzoneWindow::setVisible(bool isVisible)
void OzoneWindow::signalTestEvent() {} void OzoneWindow::signalTestEvent() {}
OSWindow *CreateOSWindow() // static
OSWindow *OSWindow::New()
{ {
return new OzoneWindow(); return new OzoneWindow();
} }
...@@ -736,11 +736,6 @@ void Win32Window::setMousePosition(int x, int y) ...@@ -736,11 +736,6 @@ void Win32Window::setMousePosition(int x, int y)
SetCursorPos(topLeft.x + x, topLeft.y + y); SetCursorPos(topLeft.x + x, topLeft.y + y);
} }
OSWindow *CreateOSWindow()
{
return new Win32Window();
}
bool Win32Window::setPosition(int x, int y) bool Win32Window::setPosition(int x, int y)
{ {
if (mX == x && mY == y) if (mX == x && mY == y)
...@@ -830,3 +825,9 @@ void Win32Window::signalTestEvent() ...@@ -830,3 +825,9 @@ void Win32Window::signalTestEvent()
{ {
PostMessage(mNativeWindow, WM_USER, 0, 0); PostMessage(mNativeWindow, WM_USER, 0, 0);
} }
// static
OSWindow *OSWindow::New()
{
return new Win32Window();
}
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
#include "windows/winrt/WinRTWindow.h" #include "windows/winrt/WinRTWindow.h"
#include <wrl.h>
#include <windows.applicationmodel.core.h> #include <windows.applicationmodel.core.h>
#include <windows.ui.xaml.h> #include <windows.ui.xaml.h>
#include <wrl.h>
#include "angle_windowsstore.h" #include "angle_windowsstore.h"
#include "common/debug.h" #include "common/debug.h"
...@@ -22,9 +22,7 @@ using namespace ABI::Windows::UI::Core; ...@@ -22,9 +22,7 @@ using namespace ABI::Windows::UI::Core;
using namespace Microsoft::WRL; using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers; using namespace Microsoft::WRL::Wrappers;
WinRTWindow::WinRTWindow() : mNativeWindow(nullptr) WinRTWindow::WinRTWindow() : mNativeWindow(nullptr) {}
{
}
WinRTWindow::~WinRTWindow() WinRTWindow::~WinRTWindow()
{ {
...@@ -50,8 +48,8 @@ bool WinRTWindow::initialize(const std::string &name, size_t width, size_t heigh ...@@ -50,8 +48,8 @@ bool WinRTWindow::initialize(const std::string &name, size_t width, size_t heigh
destroy(); destroy();
// Get all the relevant activation factories // Get all the relevant activation factories
result = GetActivationFactory( result = GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_Core_CoreWindow).Get(),
HStringReference(RuntimeClass_Windows_UI_Core_CoreWindow).Get(), &coreWindowStatic); &coreWindowStatic);
if (FAILED(result)) if (FAILED(result))
{ {
return false; return false;
...@@ -90,7 +88,7 @@ bool WinRTWindow::initialize(const std::string &name, size_t width, size_t heigh ...@@ -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 // Get the PropertySet as a map, so we can Insert things into it later
ComPtr<IInspectable> tempNativeWindow = mNativeWindow; ComPtr<IInspectable> tempNativeWindow = mNativeWindow;
result = tempNativeWindow.As(&nativeWindowAsMap); result = tempNativeWindow.As(&nativeWindowAsMap);
if (FAILED(result)) if (FAILED(result))
{ {
return false; return false;
...@@ -195,7 +193,7 @@ bool WinRTWindow::initialize(const std::string &name, size_t width, size_t heigh ...@@ -195,7 +193,7 @@ bool WinRTWindow::initialize(const std::string &name, size_t width, size_t heigh
Size renderSize; Size renderSize;
renderSize.Width = static_cast<float>(width); renderSize.Width = static_cast<float>(width);
renderSize.Height = static_cast<float>(height); renderSize.Height = static_cast<float>(height);
result = propertyValueStatics->CreateSize(renderSize, sizeValue.GetAddressOf()); result = propertyValueStatics->CreateSize(renderSize, sizeValue.GetAddressOf());
if (FAILED(result)) if (FAILED(result))
{ {
return false; return false;
...@@ -278,7 +276,7 @@ void WinRTWindow::signalTestEvent() ...@@ -278,7 +276,7 @@ void WinRTWindow::signalTestEvent()
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
OSWindow *CreateOSWindow() OSWindow *OSWindow::New()
{ {
return new WinRTWindow(); return new WinRTWindow();
} }
\ No newline at end of file
...@@ -413,11 +413,6 @@ void X11Window::setMousePosition(int x, int y) ...@@ -413,11 +413,6 @@ void X11Window::setMousePosition(int x, int y)
XWarpPointer(mDisplay, None, mWindow, 0, 0, 0, 0, x, y); XWarpPointer(mDisplay, None, mWindow, 0, 0, 0, 0, x, y);
} }
OSWindow *CreateOSWindow()
{
return new X11Window();
}
bool X11Window::setPosition(int x, int y) bool X11Window::setPosition(int x, int y)
{ {
XMoveWindow(mDisplay, mWindow, x, y); XMoveWindow(mDisplay, mWindow, x, y);
...@@ -706,3 +701,9 @@ void X11Window::processEvent(const XEvent &xEvent) ...@@ -706,3 +701,9 @@ void X11Window::processEvent(const XEvent &xEvent)
break; 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