#include "config.h"
#include "EGLSurface.h"
#if USE(EGL) && USE(GRAPHICS_SURFACE)
#include "EGLConfigSelector.h"
#include "EGLHelper.h"
#include "GLPlatformContext.h"
#if PLATFORM(X11)
#include "EGLXSurface.h"
#endif
namespace WebCore {
PassOwnPtr<GLTransportSurface> EGLTransportSurface::createTransportSurface(const IntSize& size, SurfaceAttributes attributes)
{
OwnPtr<GLTransportSurface> surface;
#if PLATFORM(X11)
surface = adoptPtr(new EGLWindowTransportSurface(size, attributes));
#else
UNUSED_PARAM(size);
UNUSED_PARAM(attributes);
#endif
if (surface)
return surface.release();
return nullptr;
}
PassOwnPtr<GLTransportSurfaceClient> EGLTransportSurface::createTransportSurfaceClient(const PlatformBufferHandle handle, const IntSize& size, bool hasAlpha)
{
EGLHelper::resolveEGLBindings();
OwnPtr<GLTransportSurfaceClient> client;
#if PLATFORM(X11)
client = adoptPtr(new EGLXTransportSurfaceClient(handle, size, hasAlpha));
#else
UNUSED_PARAM(handle);
UNUSED_PARAM(size);
UNUSED_PARAM(hasAlpha);
#endif
if (client)
return client.release();
return nullptr;
}
EGLTransportSurface::EGLTransportSurface(const IntSize& size, SurfaceAttributes attributes)
: GLTransportSurface(size, attributes)
{
m_sharedDisplay = EGLHelper::eglDisplay();
if (m_sharedDisplay == EGL_NO_DISPLAY)
return;
m_configSelector = adoptPtr(new EGLConfigSelector(attributes));
}
GLPlatformSurface::SurfaceAttributes EGLTransportSurface::attributes() const
{
return m_configSelector->attributes();
}
EGLTransportSurface::~EGLTransportSurface()
{
}
void EGLTransportSurface::destroy()
{
if (m_drawable == EGL_NO_SURFACE || m_sharedDisplay == EGL_NO_DISPLAY)
return;
GLTransportSurface::destroy();
if (m_drawable) {
eglDestroySurface(m_sharedDisplay, m_drawable);
m_drawable = EGL_NO_SURFACE;
}
m_configSelector = nullptr;
}
PlatformSurfaceConfig EGLTransportSurface::configuration()
{
return m_configSelector->surfaceContextConfig();
}
std::unique_ptr<GLPlatformSurface> EGLOffScreenSurface::createOffScreenSurface(SurfaceAttributes attributes)
{
#if PLATFORM(X11)
return std::make_unique<EGLPixmapSurface>(attributes);
#else
UNUSED_PARAM(attributes);
return nullptr;
#endif
}
EGLOffScreenSurface::EGLOffScreenSurface(SurfaceAttributes surfaceAttributes)
: GLPlatformSurface(surfaceAttributes)
{
m_sharedDisplay = EGLHelper::eglDisplay();
if (m_sharedDisplay == EGL_NO_DISPLAY)
return;
m_configSelector = adoptPtr(new EGLConfigSelector(surfaceAttributes));
}
EGLOffScreenSurface::~EGLOffScreenSurface()
{
}
GLPlatformSurface::SurfaceAttributes EGLOffScreenSurface::attributes() const
{
return m_configSelector->attributes();
}
PlatformSurfaceConfig EGLOffScreenSurface::configuration()
{
return m_configSelector->pixmapContextConfig();
}
void EGLOffScreenSurface::destroy()
{
if (m_sharedDisplay == EGL_NO_DISPLAY || m_drawable == EGL_NO_SURFACE)
return;
if (m_drawable) {
eglDestroySurface(m_sharedDisplay, m_drawable);
m_drawable = EGL_NO_SURFACE;
}
m_configSelector = nullptr;
}
}
#endif