#if USE(EGL) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
#include "EGLHelper.h"
+#include <wtf/HashMap.h>
namespace WebCore {
#define EGL_FORMAT_RGBA_8888_KHR 0x30C3
#endif
-EGLConfigSelector::EGLConfigSelector(GLPlatformSurface::SurfaceAttributes attributes)
- : m_pixmapFBConfig(0)
- , m_surfaceContextFBConfig(0)
- , m_attributes(attributes)
+class EGLConfigPool {
+public:
+ static inline EGLConfigPool& getInstance()
+ {
+ static EGLConfigPool eglConfigPool;
+ return eglConfigPool;
+ }
+ virtual ~EGLConfigPool();
+ EGLConfig pixmapContextConfig(GLPlatformSurface::SurfaceAttributes);
+ EGLConfig surfaceContextConfig(GLPlatformSurface::SurfaceAttributes);
+private:
+ EGLConfigPool(void);
+ EGLConfig createConfig(EGLint expectedSurfaceType, GLPlatformSurface::SurfaceAttributes);
+ typedef HashMap<GLPlatformSurface::SurfaceAttributes, EGLConfig> PixmapConfigMap;
+ PixmapConfigMap m_pixmapConfigs;
+ typedef HashMap<GLPlatformSurface::SurfaceAttributes, EGLConfig> WindowConfigMap;
+ WindowConfigMap m_windowConfigs;
+};
+
+EGLConfigPool::EGLConfigPool()
{
- m_sharedDisplay = EGLHelper::eglDisplay();
}
-EGLConfigSelector::~EGLConfigSelector()
+EGLConfigPool::~EGLConfigPool()
{
+ m_windowConfigs.clear();
+ m_pixmapConfigs.clear();
}
-EGLConfig EGLConfigSelector::pixmapContextConfig()
+EGLConfig EGLConfigPool::pixmapContextConfig(GLPlatformSurface::SurfaceAttributes attributes)
{
- if (!m_pixmapFBConfig)
- m_pixmapFBConfig = createConfig( m_attributes & GLPlatformSurface::Lockable ? EGL_PIXMAP_BIT | EGL_LOCK_SURFACE_BIT_KHR : EGL_PIXMAP_BIT);
-
- return m_pixmapFBConfig;
-}
+ EGLConfig config = 0;
+ PixmapConfigMap::iterator it = m_pixmapConfigs.find(attributes);
+ if (it != m_pixmapConfigs.end()) {
+ config = it->second;
+ return config;
+ }
-EGLConfig EGLConfigSelector::surfaceContextConfig()
-{
- if (!m_surfaceContextFBConfig)
- m_surfaceContextFBConfig = createConfig(EGL_WINDOW_BIT);
+ config = createConfig(attributes & GLPlatformSurface::Lockable ? EGL_PIXMAP_BIT | EGL_LOCK_SURFACE_BIT_KHR : EGL_PIXMAP_BIT, attributes);
+ if (config)
+ m_pixmapConfigs.add(attributes, config);
- return m_surfaceContextFBConfig;
+ return config;
}
-EGLint EGLConfigSelector::nativeVisualId(const EGLConfig& config) const
+EGLConfig EGLConfigPool::surfaceContextConfig(GLPlatformSurface::SurfaceAttributes attributes)
{
- if (m_sharedDisplay == EGL_NO_DISPLAY)
- return -1;
-
- EGLint eglValue = 0;
- eglGetConfigAttrib(m_sharedDisplay, config, EGL_NATIVE_VISUAL_ID, &eglValue);
-
- return eglValue;
-}
+ EGLConfig config = 0;
+ WindowConfigMap::iterator it = m_windowConfigs.find(attributes);
+ if (it != m_windowConfigs.end()) {
+ config = it->second;
+ return config;
+ }
-GLPlatformSurface::SurfaceAttributes EGLConfigSelector::attributes() const
-{
- return m_attributes;
-}
+ config = createConfig(attributes & GLPlatformSurface::Lockable ? EGL_WINDOW_BIT | EGL_LOCK_SURFACE_BIT_KHR : EGL_WINDOW_BIT, attributes);
+ if (config)
+ m_windowConfigs.add(attributes, config);
-void EGLConfigSelector::reset()
-{
- m_surfaceContextFBConfig = 0;
- m_pixmapFBConfig = 0;
+ return config;
}
-EGLConfig EGLConfigSelector::createConfig(EGLint expectedSurfaceType)
+EGLConfig EGLConfigPool::createConfig(EGLint expectedSurfaceType, GLPlatformSurface::SurfaceAttributes attributes)
{
- if (m_sharedDisplay == EGL_NO_DISPLAY)
+ EGLDisplay display = EGLHelper::eglDisplay();
+ if (display == EGL_NO_DISPLAY)
return 0;
EGLint numConfigs;
- eglGetConfigs(m_sharedDisplay, 0, 0, &numConfigs);
+ eglGetConfigs(display, 0, 0, &numConfigs);
if (!numConfigs) {
LOG_ERROR("Failed to retrieve number of EGL configs.");
}
EGLConfig configs[numConfigs];
- eglGetConfigs(m_sharedDisplay, configs, numConfigs, &numConfigs);
+ eglGetConfigs(display, configs, numConfigs, &numConfigs);
if (!numConfigs) {
LOG_ERROR("Failed to retrieve any EGL configs.");
EGLConfig config = 0;
EGLint alpha, surface, red, green, blue, renderType, stencil, depth, configAttribute, matchFormat, samples;
- EGLint expectedAlpha = m_attributes & GLPlatformSurface::SupportAlpha ? 8 : 0;
+ EGLint expectedAlpha = attributes & GLPlatformSurface::SupportAlpha ? 8 : 0;
EGLint expectedRed = 8;
EGLint expectedBlue = 8;
EGLint expectedGreen = 8;
- EGLint expectedStencilSize = m_attributes & GLPlatformSurface::SupportStencil ? 8 : 0;
- EGLint expectedDepthSize = m_attributes & GLPlatformSurface::SupportDepth ? 16 : 0;
+ EGLint expectedStencilSize = attributes & GLPlatformSurface::SupportStencil ? 8 : 0;
+ EGLint expectedDepthSize = attributes & GLPlatformSurface::SupportDepth ? 16 : 0;
EGLint expectedConfigAttribute = EGL_NONE;
EGLint expectedMatchFormat = EGL_NONE;
- EGLint expectedSamples = m_attributes & GLPlatformSurface::SupportSamples ? 4 : 0;
+ EGLint expectedSamples = attributes & GLPlatformSurface::SupportSamples ? 4 : 0;
#if USE(OPENGL_ES_2)
EGLint expectedRenderType = EGL_OPENGL_ES2_BIT;
#else
static bool isVendorArm = EGLHelper::isVendor("arm");
if (isVendorMesa) {
- // Force depth if stencil is true or depth if stencil is true.
- if ((m_attributes & GLPlatformSurface::SupportStencil) || (m_attributes & GLPlatformSurface::SupportDepth)) {
- m_attributes &= GLPlatformSurface::SupportStencil;
- m_attributes &= GLPlatformSurface::SupportDepth;
- }
-
- expectedDepthSize = m_attributes & GLPlatformSurface::SupportDepth ? 24 : 0;
- expectedStencilSize = m_attributes & GLPlatformSurface::SupportStencil ? 8 : 0;
- // Doesn't support EGLConfig with no alpha.
- expectedAlpha = 8;
+ expectedDepthSize = attributes & GLPlatformSurface::SupportDepth ? 24 : 0;
+ expectedStencilSize = attributes & GLPlatformSurface::SupportStencil ? 8 : 0;
}
if (!expectedAlpha && isVendorImagination)
expectedConfigAttribute = EGL_NON_CONFORMANT_CONFIG;
- if (m_attributes & GLPlatformSurface::Lockable) {
+ if (attributes & GLPlatformSurface::Lockable) {
if (isVendorImagination || isVendorArm)
matchFormat = EGL_FORMAT_RGBA_8888_EXACT_KHR;
else
for (int i = 0; i < numConfigs; i++) {
EGLConfig tempConfig = configs[i];
- eglGetConfigAttrib(m_sharedDisplay, tempConfig, EGL_RENDERABLE_TYPE, &renderType);
+ eglGetConfigAttrib(display, tempConfig, EGL_RENDERABLE_TYPE, &renderType);
if (!(renderType & expectedRenderType))
continue;
if (expectedConfigAttribute != EGL_NONE) {
- eglGetConfigAttrib(m_sharedDisplay, tempConfig, EGL_CONFIG_CAVEAT, &configAttribute);
+ eglGetConfigAttrib(display, tempConfig, EGL_CONFIG_CAVEAT, &configAttribute);
if (expectedConfigAttribute != configAttribute) {
LOG_ERROR("Expected config attribute didnt match. Checking next EGLConfig.");
}
if (expectedMatchFormat != EGL_NONE) {
- eglGetConfigAttrib(m_sharedDisplay, tempConfig, EGL_MATCH_FORMAT_KHR, &matchFormat);
+ eglGetConfigAttrib(display, tempConfig, EGL_MATCH_FORMAT_KHR, &matchFormat);
if (expectedMatchFormat != matchFormat) {
LOG_ERROR("ExpectedMatchFormat didnt match. Checking next EGLConfig.");
}
}
- eglGetConfigAttrib(m_sharedDisplay, tempConfig, EGL_ALPHA_SIZE, &alpha);
+ eglGetConfigAttrib(display, tempConfig, EGL_ALPHA_SIZE, &alpha);
if (alpha != expectedAlpha) {
LOG_ERROR("Failed to match %s Attribute Value. Retrieved %d, Expected: %d. Checking next EGLConfig.", "alpha", alpha, expectedAlpha);
continue;
}
- eglGetConfigAttrib(m_sharedDisplay, tempConfig, EGL_RED_SIZE, &red);
+ eglGetConfigAttrib(display, tempConfig, EGL_RED_SIZE, &red);
if (red != expectedRed) {
LOG_ERROR("Failed to match %s Attribute Value. Retrieved %d, Expected: %d. Checking next EGLConfig.", "red", red, expectedRed);
continue;
}
- eglGetConfigAttrib(m_sharedDisplay, tempConfig, EGL_GREEN_SIZE, &green);
+ eglGetConfigAttrib(display, tempConfig, EGL_GREEN_SIZE, &green);
if (green != expectedGreen) {
LOG_ERROR("Failed to match %s Attribute Value. Retrieved %d, Expected: %d. Checking next EGLConfig.", "Green", green, expectedGreen);
continue;
}
- eglGetConfigAttrib(m_sharedDisplay, tempConfig, EGL_BLUE_SIZE, &blue);
+ eglGetConfigAttrib(display, tempConfig, EGL_BLUE_SIZE, &blue);
if (blue != expectedBlue) {
LOG_ERROR("Failed to match %s Attribute Value. Retrieved %d, Expected: %d. Checking next EGLConfig.", "Blue", blue, expectedBlue);
continue;
}
- eglGetConfigAttrib(m_sharedDisplay, tempConfig, EGL_STENCIL_SIZE, &stencil);
+ eglGetConfigAttrib(display, tempConfig, EGL_STENCIL_SIZE, &stencil);
if (stencil != expectedStencilSize) {
LOG_ERROR("Failed to match %s Attribute Value. Retrieved %d, Expected: %d. Checking next EGLConfig.", "Stencil", stencil, expectedStencilSize);
continue;
}
- eglGetConfigAttrib(m_sharedDisplay, tempConfig, EGL_DEPTH_SIZE, &depth);
+ eglGetConfigAttrib(display, tempConfig, EGL_DEPTH_SIZE, &depth);
if (depth != expectedDepthSize) {
LOG_ERROR("Failed to match %s Attribute Value. Retrieved %d, Expected: %d. Checking next EGLConfig.", "Depth", depth, expectedDepthSize);
continue;
}
- eglGetConfigAttrib(m_sharedDisplay, tempConfig, EGL_SAMPLES, &samples);
+ eglGetConfigAttrib(display, tempConfig, EGL_SAMPLES, &samples);
if (samples != expectedSamples) {
LOG_ERROR("Failed to match %s Attribute Value. Retrieved %d, Expected: %d. Checking next EGLConfig.", "Samples", samples, expectedSamples);
continue;
}
- eglGetConfigAttrib(m_sharedDisplay, tempConfig, EGL_SURFACE_TYPE, &surface);
+ eglGetConfigAttrib(display, tempConfig, EGL_SURFACE_TYPE, &surface);
if (surface & expectedSurfaceType) {
config = configs[i];
}
}
- if ((m_attributes & GLPlatformSurface::SupportAlpha) && !config) {
+ if ((attributes & GLPlatformSurface::SupportAlpha) && !config) {
LOG_ERROR("Failed to retrieve EGL Configuration with alpha. Trying to find one without alpha support.");
- m_attributes &= ~GLPlatformSurface::SupportAlpha;
- config = createConfig(expectedSurfaceType);
+ attributes &= ~GLPlatformSurface::SupportAlpha;
+ config = createConfig(expectedSurfaceType, attributes);
}
if (!config)
return config;
}
+EGLConfigSelector::EGLConfigSelector(GLPlatformSurface::SurfaceAttributes attributes)
+ : m_attributes(attributes)
+{
+ static bool isVendorMesa = EGLHelper::isVendor("mesa");
+ if (isVendorMesa) {
+ if ((m_attributes & GLPlatformSurface::SupportStencil) || (m_attributes & GLPlatformSurface::SupportDepth)) {
+ m_attributes |= GLPlatformSurface::SupportStencil;
+ m_attributes |= GLPlatformSurface::SupportDepth;
+ }
+
+ m_attributes |= GLPlatformSurface::SupportAlpha;
+ }
+}
+
+EGLConfigSelector::~EGLConfigSelector()
+{
+}
+
+EGLConfig EGLConfigSelector::pixmapContextConfig()
+{
+ return EGLConfigPool::getInstance().pixmapContextConfig(m_attributes);
+}
+
+EGLConfig EGLConfigSelector::surfaceContextConfig()
+{
+ return EGLConfigPool::getInstance().surfaceContextConfig(m_attributes);
+}
+
+EGLint EGLConfigSelector::nativeVisualId(const EGLConfig& config) const
+{
+ EGLDisplay display = EGLHelper::eglDisplay();
+ if (display == EGL_NO_DISPLAY)
+ return -1;
+
+ EGLint eglValue = 0;
+ eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &eglValue);
+
+ return eglValue;
+}
+
+GLPlatformSurface::SurfaceAttributes EGLConfigSelector::attributes() const
+{
+ return m_attributes;
+}
+
+void EGLConfigSelector::reset()
+{
+}
+
#if PLATFORM(X11)
EGLConfig EGLConfigSelector::surfaceClientConfig(NativeVisualId id)
{
EGLConfig config = findMatchingConfigWithVisualId(id);
if (!config)
- config = createConfig(EGL_PIXMAP_BIT);
+ config = pixmapContextConfig();
return config;
}
EGLConfig EGLConfigSelector::findMatchingConfigWithVisualId(NativeVisualId id)
{
- if (m_sharedDisplay == EGL_NO_DISPLAY)
+ EGLDisplay display = EGLHelper::eglDisplay();
+ if (display == EGL_NO_DISPLAY)
return 0;
EGLint numConfigs;
EGLint visualId;
EGLConfig config = 0;
- eglGetConfigs(m_sharedDisplay, 0, 0, &numConfigs);
+ eglGetConfigs(display, 0, 0, &numConfigs);
if (!numConfigs) {
LOG_ERROR("Failed to retrieve any EGL configs.");
}
EGLConfig configs[numConfigs];
- eglGetConfigs(m_sharedDisplay, configs, numConfigs, &numConfigs);
+ eglGetConfigs(display, configs, numConfigs, &numConfigs);
if (!numConfigs) {
LOG_ERROR("Failed to retrieve any EGL configs.");
for (i = 0; i < numConfigs; i++) {
EGLint alpha, surfaces;
EGLConfig tempConfig = configs[i];
- eglGetConfigAttrib(m_sharedDisplay, tempConfig, EGL_NATIVE_VISUAL_ID, &visualId);
+ eglGetConfigAttrib(display, tempConfig, EGL_NATIVE_VISUAL_ID, &visualId);
if (static_cast<NativeVisualId>(visualId) != id)
continue;
- eglGetConfigAttrib(m_sharedDisplay, tempConfig, EGL_ALPHA_SIZE, &alpha);
+ eglGetConfigAttrib(display, tempConfig, EGL_ALPHA_SIZE, &alpha);
if (alphaChannelRequired != alpha)
continue;
- eglGetConfigAttrib(m_sharedDisplay, tempConfig, EGL_SURFACE_TYPE, &surfaces);
+ eglGetConfigAttrib(display, tempConfig, EGL_SURFACE_TYPE, &surfaces);
if (surfaces & EGL_PIXMAP_BIT) {
config = tempConfig;