Commit 586666ce by Jamie Madill

Make the sample app own the OS Window object.

This allows us to use OS Windows and EGL contexts differently for different implementations - eg, tests and samples. BUG=angle:730 Change-Id: I65e69fd829c3dbf2f1b406d90045bc296798ebb6 Reviewed-on: https://chromium-review.googlesource.com/213290Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 1cfaaf8a
...@@ -10,10 +10,11 @@ ...@@ -10,10 +10,11 @@
SampleApplication::SampleApplication(const std::string& name, size_t width, size_t height, SampleApplication::SampleApplication(const std::string& name, size_t width, size_t height,
EGLint glesMajorVersion, EGLint requestedRenderer) EGLint glesMajorVersion, EGLint requestedRenderer)
: mName(name), : mName(name),
mRunning(false), mRunning(false)
mTimer(CreateTimer())
{ {
mEGLWindow.reset(new EGLWindow(width, height, glesMajorVersion, requestedRenderer)); mEGLWindow.reset(new EGLWindow(width, height, glesMajorVersion, requestedRenderer));
mTimer.reset(CreateTimer());
mOSWindow.reset(CreateOSWindow());
} }
SampleApplication::~SampleApplication() SampleApplication::~SampleApplication()
...@@ -44,7 +45,7 @@ void SampleApplication::swap() ...@@ -44,7 +45,7 @@ void SampleApplication::swap()
OSWindow *SampleApplication::getWindow() const OSWindow *SampleApplication::getWindow() const
{ {
return mEGLWindow->getWindow(); return mOSWindow.get();
} }
EGLConfig SampleApplication::getConfig() const EGLConfig SampleApplication::getConfig() const
...@@ -69,12 +70,12 @@ EGLContext SampleApplication::getContext() const ...@@ -69,12 +70,12 @@ EGLContext SampleApplication::getContext() const
int SampleApplication::run() int SampleApplication::run()
{ {
if (!getWindow()->initialize(mName, mEGLWindow->getWidth(), mEGLWindow->getHeight())) if (!mOSWindow->initialize(mName, mEGLWindow->getWidth(), mEGLWindow->getHeight()))
{ {
return -1; return -1;
} }
if (!mEGLWindow->initializeGL()) if (!mEGLWindow->initializeGL(mOSWindow.get()))
{ {
return -1; return -1;
} }
...@@ -117,14 +118,14 @@ int SampleApplication::run() ...@@ -117,14 +118,14 @@ int SampleApplication::run()
draw(); draw();
swap(); swap();
getWindow()->messageLoop(); mOSWindow->messageLoop();
prevTime = elapsedTime; prevTime = elapsedTime;
} }
destroy(); destroy();
mEGLWindow->destroyGL(); mEGLWindow->destroyGL();
getWindow()->destroy(); mOSWindow->destroy();
return result; return result;
} }
...@@ -136,5 +137,5 @@ void SampleApplication::exit() ...@@ -136,5 +137,5 @@ void SampleApplication::exit()
bool SampleApplication::popEvent(Event *event) bool SampleApplication::popEvent(Event *event)
{ {
return getWindow()->popEvent(event); return mOSWindow->popEvent(event);
} }
...@@ -52,6 +52,7 @@ class SampleApplication ...@@ -52,6 +52,7 @@ class SampleApplication
std::unique_ptr<Timer> mTimer; std::unique_ptr<Timer> mTimer;
std::unique_ptr<EGLWindow> mEGLWindow; std::unique_ptr<EGLWindow> mEGLWindow;
std::unique_ptr<OSWindow> mOSWindow;
}; };
#endif // SAMPLE_UTIL_SAMPLE_APPLICATION_H #endif // SAMPLE_UTIL_SAMPLE_APPLICATION_H
...@@ -24,8 +24,7 @@ EGLWindow::EGLWindow(size_t width, size_t height, ...@@ -24,8 +24,7 @@ EGLWindow::EGLWindow(size_t width, size_t height,
mClientVersion(glesMajorVersion), mClientVersion(glesMajorVersion),
mRequestedRenderer(requestedRenderer), mRequestedRenderer(requestedRenderer),
mWidth(width), mWidth(width),
mHeight(height), mHeight(height)
mOSWindow(CreateOSWindow())
{ {
} }
...@@ -39,11 +38,6 @@ void EGLWindow::swap() ...@@ -39,11 +38,6 @@ void EGLWindow::swap()
eglSwapBuffers(mDisplay, mSurface); eglSwapBuffers(mDisplay, mSurface);
} }
OSWindow *EGLWindow::getWindow() const
{
return mOSWindow.get();
}
EGLConfig EGLWindow::getConfig() const EGLConfig EGLWindow::getConfig() const
{ {
return mConfig; return mConfig;
...@@ -64,7 +58,7 @@ EGLContext EGLWindow::getContext() const ...@@ -64,7 +58,7 @@ EGLContext EGLWindow::getContext() const
return mContext; return mContext;
} }
bool EGLWindow::initializeGL() bool EGLWindow::initializeGL(const OSWindow *osWindow)
{ {
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(eglGetProcAddress("eglGetPlatformDisplayEXT")); PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(eglGetProcAddress("eglGetPlatformDisplayEXT"));
if (!eglGetPlatformDisplayEXT) if (!eglGetPlatformDisplayEXT)
...@@ -78,7 +72,7 @@ bool EGLWindow::initializeGL() ...@@ -78,7 +72,7 @@ bool EGLWindow::initializeGL()
EGL_NONE, EGL_NONE,
}; };
mDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, mOSWindow->getNativeDisplay(), displayAttributes); mDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, osWindow->getNativeDisplay(), displayAttributes);
if (mDisplay == EGL_NO_DISPLAY) if (mDisplay == EGL_NO_DISPLAY)
{ {
destroyGL(); destroyGL();
...@@ -124,7 +118,7 @@ bool EGLWindow::initializeGL() ...@@ -124,7 +118,7 @@ bool EGLWindow::initializeGL()
EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE,
}; };
mSurface = eglCreateWindowSurface(mDisplay, mConfig, mOSWindow->getNativeWindow(), surfaceAttributes); mSurface = eglCreateWindowSurface(mDisplay, mConfig, osWindow->getNativeWindow(), surfaceAttributes);
if (mSurface == EGL_NO_SURFACE) if (mSurface == EGL_NO_SURFACE)
{ {
eglGetError(); // Clear error and try again eglGetError(); // Clear error and try again
......
...@@ -40,7 +40,6 @@ class EGLWindow ...@@ -40,7 +40,6 @@ class EGLWindow
void swap(); void swap();
OSWindow *getWindow() const;
EGLConfig getConfig() const; EGLConfig getConfig() const;
EGLDisplay getDisplay() const; EGLDisplay getDisplay() const;
EGLSurface getSurface() const; EGLSurface getSurface() const;
...@@ -48,7 +47,7 @@ class EGLWindow ...@@ -48,7 +47,7 @@ class EGLWindow
size_t getWidth() const { return mWidth; } size_t getWidth() const { return mWidth; }
size_t getHeight() const { return mHeight; } size_t getHeight() const { return mHeight; }
bool initializeGL(); bool initializeGL(const OSWindow *osWindow);
void destroyGL(); void destroyGL();
private: private:
...@@ -63,8 +62,6 @@ class EGLWindow ...@@ -63,8 +62,6 @@ class EGLWindow
EGLint mRequestedRenderer; EGLint mRequestedRenderer;
size_t mWidth; size_t mWidth;
size_t mHeight; size_t mHeight;
std::unique_ptr<OSWindow> mOSWindow;
}; };
#endif // UTIL_EGLWINDOW_H_ #endif // UTIL_EGLWINDOW_H_
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