[EFL][WebGL] Refactor GLXImplementation.

https://bugs.webkit.org/show_bug.cgi?id=105825

Patch by Kondapally Kalyan <kalyan.kondapally@intel.com> on 2012-12-29
Reviewed by Kenneth Rohde Christiansen.

This patch decouples native window management and logic to find surface configuration in GLX implementation.

* platform/graphics/opengl/GLDefs.h:
* platform/graphics/surfaces/glx/GLXConfigSelector.h: Renamed from Source/WebCore/platform/graphics/surfaces/glx/GLXWindowResources.h.
(WebCore):
(GLXConfigSelector):
(WebCore::GLXConfigSelector::GLXConfigSelector):
(WebCore::GLXConfigSelector::~GLXConfigSelector):
(WebCore::GLXConfigSelector::visualInfo):
(WebCore::GLXConfigSelector::pBufferContextConfig):
(WebCore::GLXConfigSelector::surfaceContextConfig):
(WebCore::GLXConfigSelector::reset):
(WebCore::GLXConfigSelector::createConfig):

Helper class to find surface configuration.

* platform/graphics/surfaces/glx/GLXContext.h:
(GLXOffScreenContext):
* platform/graphics/surfaces/glx/GLXSurface.cpp:
(WebCore::GLXTransportSurface::GLXTransportSurface):
(WebCore::GLXTransportSurface::configuration):
(WebCore::GLXTransportSurface::setGeometry):
(WebCore::GLXTransportSurface::destroy):
(WebCore::GLXPBuffer::GLXPBuffer):
(WebCore::GLXPBuffer::initialize):
(WebCore::GLXPBuffer::configuration):
* platform/graphics/surfaces/glx/GLXSurface.h:
(GLXTransportSurface):
(GLXPBuffer):

Inheritance changed from X11OffScreenWindow to GLPlatformSurface.

* platform/graphics/surfaces/glx/X11WindowResources.cpp:
(WebCore):
(WebCore::X11OffScreenWindow::X11OffScreenWindow):
(WebCore::X11OffScreenWindow::reSizeWindow):
(WebCore::X11OffScreenWindow::createOffscreenWindow):
(WebCore::X11OffScreenWindow::destroyWindow):
(WebCore::X11OffScreenWindow::nativeSharedDisplay):
(WebCore::X11OffScreenWindow::setVisualInfo):
(WebCore::X11OffScreenWindow::isXRenderExtensionSupported):
* platform/graphics/surfaces/glx/X11WindowResources.h:
(WebCore::SharedX11Resources::create):
(SharedX11Resources):
(X11OffScreenWindow):

 Removed code related to surface configiration.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@138567 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 82837d46
2012-12-29 Kondapally Kalyan <kalyan.kondapally@intel.com>
[EFL][WebGL] Refactor GLXImplementation.
https://bugs.webkit.org/show_bug.cgi?id=105825
Reviewed by Kenneth Rohde Christiansen.
This patch decouples native window management and logic to find surface configuration in GLX implementation.
* platform/graphics/opengl/GLDefs.h:
* platform/graphics/surfaces/glx/GLXConfigSelector.h: Renamed from Source/WebCore/platform/graphics/surfaces/glx/GLXWindowResources.h.
(WebCore):
(GLXConfigSelector):
(WebCore::GLXConfigSelector::GLXConfigSelector):
(WebCore::GLXConfigSelector::~GLXConfigSelector):
(WebCore::GLXConfigSelector::visualInfo):
(WebCore::GLXConfigSelector::pBufferContextConfig):
(WebCore::GLXConfigSelector::surfaceContextConfig):
(WebCore::GLXConfigSelector::reset):
(WebCore::GLXConfigSelector::createConfig):
Helper class to find surface configuration.
* platform/graphics/surfaces/glx/GLXContext.h:
(GLXOffScreenContext):
* platform/graphics/surfaces/glx/GLXSurface.cpp:
(WebCore::GLXTransportSurface::GLXTransportSurface):
(WebCore::GLXTransportSurface::configuration):
(WebCore::GLXTransportSurface::setGeometry):
(WebCore::GLXTransportSurface::destroy):
(WebCore::GLXPBuffer::GLXPBuffer):
(WebCore::GLXPBuffer::initialize):
(WebCore::GLXPBuffer::configuration):
* platform/graphics/surfaces/glx/GLXSurface.h:
(GLXTransportSurface):
(GLXPBuffer):
Inheritance changed from X11OffScreenWindow to GLPlatformSurface.
* platform/graphics/surfaces/glx/X11WindowResources.cpp:
(WebCore):
(WebCore::X11OffScreenWindow::X11OffScreenWindow):
(WebCore::X11OffScreenWindow::reSizeWindow):
(WebCore::X11OffScreenWindow::createOffscreenWindow):
(WebCore::X11OffScreenWindow::destroyWindow):
(WebCore::X11OffScreenWindow::nativeSharedDisplay):
(WebCore::X11OffScreenWindow::setVisualInfo):
(WebCore::X11OffScreenWindow::isXRenderExtensionSupported):
* platform/graphics/surfaces/glx/X11WindowResources.h:
(WebCore::SharedX11Resources::create):
(SharedX11Resources):
(X11OffScreenWindow):
Removed code related to surface configiration.
2012-12-29 Eugene Klyuchnikov <eustas@chromium.org>
Web Inspector: [Timeline] cpu bar popover shows wrong duration / cpu time.
......@@ -41,7 +41,9 @@
#include <GL/gl.h>
#include <GL/glext.h>
#if USE(GLX)
#define GLX_GLXEXT_PROTOTYPES 1
#include <GL/glx.h>
#include <GL/glxext.h>
#endif
#endif
......
......@@ -23,8 +23,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GLXWindowResources_h
#define GLXWindowResources_h
#ifndef GLXConfigSelector_h
#define GLXConfigSelector_h
#include "X11WindowResources.h"
......@@ -32,36 +32,31 @@
namespace WebCore {
class SharedGLXResources : public SharedX11Resources {
WTF_MAKE_NONCOPYABLE(SharedGLXResources);
class GLXConfigSelector {
WTF_MAKE_NONCOPYABLE(GLXConfigSelector);
public:
static PassRefPtr<SharedGLXResources> create()
GLXConfigSelector(Display* xDisplay, bool supportsXRenderExtension)
: m_pbufferFBConfig(0)
, m_surfaceContextFBConfig(0)
, m_visualInfo(0)
, m_sharedDisplay(xDisplay)
, m_supportsXRenderExtension(supportsXRenderExtension)
{
if (!m_staticSharedResource)
m_staticSharedResource = new SharedGLXResources();
else
m_staticSharedResource->ref();
return adoptRef(m_staticSharedResource);
}
PlatformDisplay nativeDisplay()
virtual ~GLXConfigSelector()
{
return SharedX11Resources::x11Display();
}
XVisualInfo* visualInfo()
XVisualInfo* visualInfo() const
{
if (!m_VisualInfo)
surfaceContextConfig();
return m_VisualInfo;
return m_visualInfo;
}
virtual GLXFBConfig pBufferContextConfig()
GLXFBConfig pBufferContextConfig()
{
if (!m_pbufferfbConfig) {
if (!m_pbufferFBConfig) {
static const int attributes[] = {
GLX_LEVEL, 0,
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
......@@ -73,19 +68,19 @@ public:
None
};
int numReturned;
GLXFBConfig* temp = glXChooseFBConfig(nativeDisplay(), DefaultScreen(nativeDisplay()), attributes, &numReturned);
if (numReturned)
m_pbufferfbConfig = temp[0];
int numAvailableConfigs;
GLXFBConfig* temp = glXChooseFBConfig(m_sharedDisplay, DefaultScreen(m_sharedDisplay), attributes, &numAvailableConfigs);
if (numAvailableConfigs)
m_pbufferFBConfig = temp[0];
XFree(temp);
}
return m_pbufferfbConfig;
return m_pbufferFBConfig;
}
virtual GLXFBConfig surfaceContextConfig()
GLXFBConfig surfaceContextConfig()
{
if (!m_surfaceContextfbConfig) {
if (!m_surfaceContextFBConfig) {
static int attributes[] = {
GLX_LEVEL, 0,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
......@@ -100,48 +95,46 @@ public:
None
};
m_surfaceContextfbConfig = createConfig(attributes);
m_surfaceContextFBConfig = createConfig(attributes);
}
return m_surfaceContextfbConfig;
return m_surfaceContextFBConfig;
}
protected:
SharedGLXResources()
: SharedX11Resources()
, m_pbufferfbConfig(0)
, m_surfaceContextfbConfig(0)
, m_VisualInfo(0)
void reset()
{
m_pbufferFBConfig = 0;
m_surfaceContextFBConfig = 0;
}
private:
GLXFBConfig createConfig(const int attributes[])
{
int numReturned;
m_VisualInfo = 0;
GLXFBConfig* temp = glXChooseFBConfig(nativeDisplay(), DefaultScreen(nativeDisplay()), attributes, &numReturned);
int numAvailableConfigs;
m_visualInfo = 0;
GLXFBConfig* temp = glXChooseFBConfig(m_sharedDisplay, DefaultScreen(m_sharedDisplay), attributes, &numAvailableConfigs);
if (!numReturned)
if (!numAvailableConfigs)
return 0;
GLXFBConfig selectedConfig = 0;
bool found = false;
for (int i = 0; i < numReturned; ++i) {
m_VisualInfo = glXGetVisualFromFBConfig(nativeDisplay(), temp[i]);
if (!m_VisualInfo)
for (int i = 0; i < numAvailableConfigs; ++i) {
m_visualInfo = glXGetVisualFromFBConfig(m_sharedDisplay, temp[i]);
if (!m_visualInfo)
continue;
#if USE(GRAPHICS_SURFACE)
if (m_supportsXRenderExtension) {
XRenderPictFormat* format = XRenderFindVisualFormat(nativeDisplay(), m_VisualInfo->visual);
XRenderPictFormat* format = XRenderFindVisualFormat(m_sharedDisplay, m_visualInfo->visual);
if (format && format->direct.alphaMask > 0) {
selectedConfig = temp[i];
found = true;
break;
}
} else if (m_VisualInfo->depth == 32) {
} else if (m_visualInfo->depth == 32) {
#else
if (m_VisualInfo->depth == 32) {
if (m_visualInfo->depth == 32) {
#endif
selectedConfig = temp[i];
found = true;
......@@ -151,7 +144,7 @@ protected:
// Did not find any visual supporting alpha, select the first available config.
if (!found) {
selectedConfig = temp[0];
m_VisualInfo = glXGetVisualFromFBConfig(m_display, temp[0]);
m_visualInfo = glXGetVisualFromFBConfig(m_sharedDisplay, temp[0]);
}
XFree(temp);
......@@ -159,26 +152,11 @@ protected:
return selectedConfig;
}
virtual ~SharedGLXResources()
{
if (!m_display)
return;
if (m_pbufferfbConfig)
m_pbufferfbConfig = 0;
if (m_surfaceContextfbConfig)
m_surfaceContextfbConfig = 0;
if (m_VisualInfo) {
XFree(m_VisualInfo);
m_VisualInfo = 0;
}
}
GLXFBConfig m_pbufferfbConfig;
GLXFBConfig m_surfaceContextfbConfig;
XVisualInfo* m_VisualInfo;
GLXFBConfig m_pbufferFBConfig;
GLXFBConfig m_surfaceContextFBConfig;
XVisualInfo* m_visualInfo;
Display* m_sharedDisplay;
bool m_supportsXRenderExtension;
};
}
......
......@@ -33,7 +33,6 @@
namespace WebCore {
class GLXCurrentContextWrapper : public GLPlatformContext {
WTF_MAKE_NONCOPYABLE(GLXCurrentContextWrapper);
public:
GLXCurrentContextWrapper()
......@@ -46,16 +45,15 @@ public:
};
class GLXOffScreenContext : public GLPlatformContext {
WTF_MAKE_NONCOPYABLE(GLXOffScreenContext);
public:
GLXOffScreenContext();
virtual ~GLXOffScreenContext();
bool initialize(GLPlatformSurface*);
bool platformMakeCurrent(GLPlatformSurface*);
void platformReleaseCurrent();
void destroy();
bool isCurrentContext() const;
virtual bool initialize(GLPlatformSurface*) OVERRIDE;
virtual bool platformMakeCurrent(GLPlatformSurface*) OVERRIDE;
virtual void platformReleaseCurrent() OVERRIDE;
virtual void destroy() OVERRIDE;
virtual bool isCurrentContext() const OVERRIDE;
private:
void freeResources();
......
......@@ -34,9 +34,31 @@ static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGH
#if USE(GRAPHICS_SURFACE)
GLXTransportSurface::GLXTransportSurface()
: X11OffScreenWindow()
: GLPlatformSurface()
{
createOffscreenWindow(&m_bufferHandle);
m_nativeResource = adoptPtr(new X11OffScreenWindow());
m_sharedDisplay = m_nativeResource->nativeSharedDisplay();
if (!m_sharedDisplay) {
m_nativeResource = nullptr;
return;
}
m_configSelector = adoptPtr(new GLXConfigSelector(m_sharedDisplay, m_nativeResource->isXRenderExtensionSupported()));
if (!configuration()) {
destroy();
return;
}
m_nativeResource->setVisualInfo(m_configSelector->visualInfo());
m_nativeResource->createOffscreenWindow(&m_bufferHandle);
if (!m_bufferHandle) {
destroy();
return;
}
m_drawable = m_bufferHandle;
}
......@@ -46,13 +68,13 @@ GLXTransportSurface::~GLXTransportSurface()
PlatformSurfaceConfig GLXTransportSurface::configuration()
{
return m_sharedResources->surfaceContextConfig();
return m_configSelector->surfaceContextConfig();
}
void GLXTransportSurface::setGeometry(const IntRect& newRect)
{
GLPlatformSurface::setGeometry(newRect);
reSizeWindow(newRect, m_drawable);
m_nativeResource->reSizeWindow(newRect, m_drawable);
}
void GLXTransportSurface::swapBuffers()
......@@ -72,14 +94,20 @@ void GLXTransportSurface::swapBuffers()
void GLXTransportSurface::destroy()
{
destroyWindow(m_bufferHandle);
m_bufferHandle = 0;
if (m_bufferHandle) {
m_nativeResource->destroyWindow(m_bufferHandle);
m_bufferHandle = 0;
m_drawable = 0;
}
m_nativeResource = nullptr;
m_configSelector = nullptr;
}
#endif
GLXPBuffer::GLXPBuffer()
: X11OffScreenWindow()
: GLPlatformSurface()
{
initialize();
}
......@@ -90,18 +118,35 @@ GLXPBuffer::~GLXPBuffer()
void GLXPBuffer::initialize()
{
Display* display = sharedDisplay();
GLXFBConfig config = m_sharedResources->pBufferContextConfig();
if (!config)
m_nativeResource = adoptPtr(new X11OffScreenWindow());
m_sharedDisplay = m_nativeResource->nativeSharedDisplay();
if (!m_sharedDisplay) {
m_nativeResource = nullptr;
return;
}
m_configSelector = adoptPtr(new GLXConfigSelector(m_sharedDisplay, m_nativeResource->isXRenderExtensionSupported()));
GLXFBConfig config = m_configSelector->pBufferContextConfig();
if (!config) {
destroy();
return;
}
m_drawable = glXCreatePbuffer(m_sharedDisplay, config, pbufferAttributes);
if (!m_drawable) {
destroy();
return;
}
m_drawable = glXCreatePbuffer(display, config, pbufferAttributes);
m_bufferHandle = m_drawable;
}
PlatformSurfaceConfig GLXPBuffer::configuration()
{
return m_sharedResources->pBufferContextConfig();
return m_configSelector->pBufferContextConfig();
}
void GLXPBuffer::destroy()
......@@ -111,17 +156,17 @@ void GLXPBuffer::destroy()
void GLXPBuffer::freeResources()
{
if (!m_drawable)
return;
GLPlatformSurface::destroy();
Display* display = sharedDisplay();
if (!display)
return;
glXDestroyPbuffer(display, m_drawable);
m_drawable = 0;
m_bufferHandle = 0;
if (m_drawable && display) {
glXDestroyPbuffer(display, m_drawable);
m_drawable = 0;
m_bufferHandle = 0;
}
m_configSelector = nullptr;
m_nativeResource = nullptr;
}
void GLXPBuffer::setGeometry(const IntRect& newRect)
......
......@@ -28,42 +28,44 @@
#if USE(ACCELERATED_COMPOSITING) && USE(GLX)
#include "GLXWindowResources.h"
#include <wtf/Noncopyable.h>
#include "GLPlatformSurface.h"
#include "GLXConfigSelector.h"
#include "X11WindowResources.h"
namespace WebCore {
#if USE(GRAPHICS_SURFACE)
class GLXTransportSurface : public X11OffScreenWindow {
WTF_MAKE_NONCOPYABLE(GLXTransportSurface);
class GLXTransportSurface : public GLPlatformSurface {
public:
GLXTransportSurface();
virtual ~GLXTransportSurface();
PlatformSurfaceConfig configuration();
void swapBuffers();
void setGeometry(const IntRect&);
void destroy();
virtual PlatformSurfaceConfig configuration() OVERRIDE;
virtual void swapBuffers() OVERRIDE;
virtual void setGeometry(const IntRect&) OVERRIDE;
virtual void destroy() OVERRIDE;
private:
void initialize();
OwnPtr<X11OffScreenWindow> m_nativeResource;
OwnPtr<GLXConfigSelector> m_configSelector;
};
#endif
class GLXPBuffer : public X11OffScreenWindow {
WTF_MAKE_NONCOPYABLE(GLXPBuffer);
class GLXPBuffer : public GLPlatformSurface {
public:
GLXPBuffer();
virtual ~GLXPBuffer();
PlatformSurfaceConfig configuration();
void setGeometry(const IntRect&);
void destroy();
virtual PlatformSurfaceConfig configuration() OVERRIDE;
virtual void setGeometry(const IntRect&) OVERRIDE;
virtual void destroy() OVERRIDE;
private:
void initialize();
void freeResources();
OwnPtr<X11OffScreenWindow> m_nativeResource;
OwnPtr<GLXConfigSelector> m_configSelector;
};
}
......
......@@ -28,25 +28,15 @@
#if USE(ACCELERATED_COMPOSITING)
#if USE(GLX)
#include "GLXWindowResources.h"
#endif
namespace WebCore {
PlatformSharedResources* SharedX11Resources::m_staticSharedResource = 0;
SharedX11Resources* SharedX11Resources::m_staticSharedResource = 0;
X11OffScreenWindow::X11OffScreenWindow()
: GLPlatformSurface()
, m_sharedResources(0)
: m_sharedResources(0)
, m_configVisualInfo(0)
{
m_sharedResources = PlatformSharedResources::create();
if (!m_sharedResources)
return;
m_sharedDisplay = m_sharedResources->x11Display();
m_sharedResources = SharedX11Resources::create();
}
X11OffScreenWindow::~X11OffScreenWindow()
......@@ -57,12 +47,12 @@ X11OffScreenWindow::~X11OffScreenWindow()
}
}
void X11OffScreenWindow::reSizeWindow(const IntRect& newRect, PlatformBufferHandle windowId)
void X11OffScreenWindow::reSizeWindow(const IntRect& newRect, const uint32_t windowId)
{
XResizeWindow(m_sharedResources->x11Display(), windowId, newRect.width(), newRect.height());
}
void X11OffScreenWindow::createOffscreenWindow(PlatformBufferHandle* handleId)
void X11OffScreenWindow::createOffscreenWindow(uint32_t* handleId)
{
if (!m_sharedResources)
return;
......@@ -71,14 +61,8 @@ void X11OffScreenWindow::createOffscreenWindow(PlatformBufferHandle* handleId)
if (!display)
return;
#if USE(GLX)
XVisualInfo* visInfo = m_sharedResources->visualInfo();
#else
XVisualInfo* visInfo = m_configVisualInfo;
#endif
if (!visInfo) {
LOG_ERROR("Failed to find valid XVisual");
if (!m_configVisualInfo) {
LOG_ERROR("Failed to find valid XVisual.");
return;
}
......@@ -86,35 +70,33 @@ void X11OffScreenWindow::createOffscreenWindow(PlatformBufferHandle* handleId)
if (!xWindow)
return;
Colormap cmap = XCreateColormap(display, xWindow, visInfo->visual, AllocNone);
Colormap cmap = XCreateColormap(display, xWindow, m_configVisualInfo->visual, AllocNone);
XSetWindowAttributes attribute;
attribute.background_pixel = WhitePixel(display, 0);
attribute.border_pixel = BlackPixel(display, 0);
attribute.colormap = cmap;
PlatformBufferHandle tempHandleId;
tempHandleId = XCreateWindow(display, xWindow, 0, 0, 1, 1, 0, visInfo->depth, InputOutput, visInfo->visual, CWBackPixel | CWBorderPixel | CWColormap, &attribute);
uint32_t tempHandleId;
tempHandleId = XCreateWindow(display, xWindow, 0, 0, 1, 1, 0, m_configVisualInfo->depth, InputOutput, m_configVisualInfo->visual, CWBackPixel | CWBorderPixel | CWColormap, &attribute);
if (!tempHandleId) {
LOG_ERROR("Failed to create offscreen window");
LOG_ERROR("Failed to create offscreen window.");
return;
}
XSetWindowBackgroundPixmap(display, tempHandleId, 0);
XCompositeRedirectWindow(display, tempHandleId, CompositeRedirectManual);
*handleId = tempHandleId;
m_bufferHandle = tempHandleId;
if (m_sharedResources->isXRenderExtensionSupported())
XMapWindow(display, tempHandleId);
}
void X11OffScreenWindow::destroyWindow(PlatformBufferHandle windowId)
void X11OffScreenWindow::destroyWindow(const uint32_t windowId)
{
if (!windowId)
return;
GLPlatformSurface::destroy();
Display* display = m_sharedResources->x11Display();
if (!display)
return;
......@@ -122,7 +104,7 @@ void X11OffScreenWindow::destroyWindow(PlatformBufferHandle windowId)
XDestroyWindow(display, windowId);
}
Display* X11OffScreenWindow::nativeSharedDisplay()
Display* X11OffScreenWindow::nativeSharedDisplay() const
{
return m_sharedResources->x11Display();
}
......@@ -181,6 +163,16 @@ bool X11OffScreenWindow::setVisualId(const EGLint id)
}
#endif
void X11OffScreenWindow::setVisualInfo(XVisualInfo* visInfo)
{
m_configVisualInfo = visInfo;
}
bool X11OffScreenWindow::isXRenderExtensionSupported() const
{
return m_sharedResources->isXRenderExtensionSupported();
}
}
#endif