Diff
Modified: trunk/Source/WebCore/ChangeLog (141403 => 141404)
--- trunk/Source/WebCore/ChangeLog 2013-01-31 12:45:12 UTC (rev 141403)
+++ trunk/Source/WebCore/ChangeLog 2013-01-31 12:47:22 UTC (rev 141404)
@@ -1,3 +1,51 @@
+2013-01-20 Kondapally Kalyan <kalyan.kondapa...@intel.com>
+
+ [Efl][WebGL] Add better support to track and free XResources.
+ https://bugs.webkit.org/show_bug.cgi?id=107397
+
+ Reviewed by Noam Rosenthal.
+
+ We leak Memory during config selection as we dont free temporary
+ allocated visuals, config etc. This patch ensures that we dont leak any
+ memory.
+
+ Covered by existing WebGL tests.
+
+ * platform/graphics/surfaces/egl/EGLSurface.cpp:
+ (WebCore::EGLWindowTransportSurface::EGLWindowTransportSurface):
+ * platform/graphics/surfaces/glx/GLXConfigSelector.h:
+ (WebCore::GLXConfigSelector::GLXConfigSelector):
+ (WebCore::GLXConfigSelector::visualInfo):
+ (WebCore::GLXConfigSelector::pBufferContextConfig):
+ (WebCore::GLXConfigSelector::surfaceContextConfig):
+ (WebCore::GLXConfigSelector::createSurfaceConfig):
+ (GLXConfigSelector):
+ Removed XVisualInfo as member variable. Fixed memory leaks.
+
+ * platform/graphics/surfaces/glx/GLXSurface.cpp:
+ (WebCore::GLXTransportSurface::GLXTransportSurface):
+ * platform/graphics/surfaces/glx/OwnPtrX11.h: Added.
+ (OwnPtrX11):
+ (WebCore::OwnPtrX11::OwnPtrX11):
+ (WebCore::OwnPtrX11::~OwnPtrX11):
+ (WebCore::OwnPtrX11::operator=):
+ (WebCore::OwnPtrX11::operator T*):
+ (WebCore::OwnPtrX11::operator->):
+ (WebCore::OwnPtrX11::get):
+ Calls XFree on pointer to memory allocated by X when the class goes out of scope.
+ OwnPtr cannot be used here as GLXFBConfig is a pointer to an array of pointers.
+
+ * platform/graphics/surfaces/glx/X11WindowResources.cpp:
+ (WebCore::X11OffScreenWindow::X11OffScreenWindow):
+ (WebCore::X11OffScreenWindow::~X11OffScreenWindow):
+ (WebCore):
+ (WebCore::X11OffScreenWindow::createOffScreenWindow):
+ (WebCore::X11OffScreenWindow::destroyWindow):
+ (WebCore::X11OffScreenWindow::nativeSharedDisplay):
+ * platform/graphics/surfaces/glx/X11WindowResources.h:
+ (X11OffScreenWindow):
+ Removed unused code. Fixed memory leaks.
+
2013-01-31 Andrey Adaikin <aand...@chromium.org>
Web Inspector: [Canvas] remove invalid canvas profile trace logs upon frame navigation
Modified: trunk/Source/WebCore/platform/graphics/surfaces/egl/EGLSurface.cpp (141403 => 141404)
--- trunk/Source/WebCore/platform/graphics/surfaces/egl/EGLSurface.cpp 2013-01-31 12:45:12 UTC (rev 141403)
+++ trunk/Source/WebCore/platform/graphics/surfaces/egl/EGLSurface.cpp 2013-01-31 12:47:22 UTC (rev 141404)
@@ -57,13 +57,8 @@
return;
}
- if (!m_nativeResource->setVisualId(visualId)) {
- destroy();
- return;
- }
+ m_nativeResource->createOffScreenWindow(&m_bufferHandle, visualId);
- m_nativeResource->createOffscreenWindow(&m_bufferHandle);
-
if (!m_bufferHandle) {
destroy();
return;
Modified: trunk/Source/WebCore/platform/graphics/surfaces/glx/GLXConfigSelector.h (141403 => 141404)
--- trunk/Source/WebCore/platform/graphics/surfaces/glx/GLXConfigSelector.h 2013-01-31 12:45:12 UTC (rev 141403)
+++ trunk/Source/WebCore/platform/graphics/surfaces/glx/GLXConfigSelector.h 2013-01-31 12:47:22 UTC (rev 141404)
@@ -39,7 +39,6 @@
GLXConfigSelector(Display* xDisplay, bool supportsXRenderExtension)
: m_pbufferFBConfig(0)
, m_surfaceContextFBConfig(0)
- , m_visualInfo(0)
, m_sharedDisplay(xDisplay)
, m_supportsXRenderExtension(supportsXRenderExtension)
{
@@ -49,9 +48,12 @@
{
}
- XVisualInfo* visualInfo() const
+ XVisualInfo* visualInfo()
{
- return m_visualInfo;
+ if (!surfaceContextConfig())
+ return 0;
+
+ return glXGetVisualFromFBConfig(m_sharedDisplay, m_surfaceContextFBConfig);
}
GLXFBConfig pBufferContextConfig()
@@ -69,10 +71,9 @@
};
int numAvailableConfigs;
- GLXFBConfig* temp = glXChooseFBConfig(m_sharedDisplay, DefaultScreen(m_sharedDisplay), attributes, &numAvailableConfigs);
+ OwnPtrX11<GLXFBConfig> temp(glXChooseFBConfig(m_sharedDisplay, DefaultScreen(m_sharedDisplay), attributes, &numAvailableConfigs));
if (numAvailableConfigs)
m_pbufferFBConfig = temp[0];
- XFree(temp);
}
return m_pbufferFBConfig;
@@ -80,24 +81,9 @@
GLXFBConfig surfaceContextConfig()
{
- if (!m_surfaceContextFBConfig) {
- static int attributes[] = {
- GLX_LEVEL, 0,
- GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
- GLX_RENDER_TYPE, GLX_RGBA_BIT,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_ALPHA_SIZE, 1,
- GLX_DEPTH_SIZE, 1,
- GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
- GLX_DOUBLEBUFFER, True,
- None
- };
+ if (!m_surfaceContextFBConfig)
+ createSurfaceConfig();
- m_surfaceContextFBConfig = createConfig(attributes);
- }
-
return m_surfaceContextFBConfig;
}
@@ -108,56 +94,57 @@
}
private:
- GLXFBConfig createConfig(const int attributes[])
+ void createSurfaceConfig()
{
+ static int attributes[] = {
+ GLX_LEVEL, 0,
+ GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
+ GLX_RENDER_TYPE, GLX_RGBA_BIT,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_ALPHA_SIZE, 1,
+ GLX_DEPTH_SIZE, 1,
+ GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
+ GLX_DOUBLEBUFFER, True,
+ None
+ };
+
int numAvailableConfigs;
- m_visualInfo = 0;
- GLXFBConfig* temp = glXChooseFBConfig(m_sharedDisplay, DefaultScreen(m_sharedDisplay), attributes, &numAvailableConfigs);
+ OwnPtrX11<GLXFBConfig> temp(glXChooseFBConfig(m_sharedDisplay, DefaultScreen(m_sharedDisplay), attributes, &numAvailableConfigs));
- if (!numAvailableConfigs)
- return 0;
+ if (!numAvailableConfigs) {
+ m_surfaceContextFBConfig = 0;
+ return;
+ }
- GLXFBConfig selectedConfig = 0;
- bool found = false;
-
+ OwnPtrX11<XVisualInfo> scopedVisualInfo;
for (int i = 0; i < numAvailableConfigs; ++i) {
- if (m_visualInfo)
- XFree(m_visualInfo);
-
- m_visualInfo = glXGetVisualFromFBConfig(m_sharedDisplay, temp[i]);
- if (!m_visualInfo)
+ scopedVisualInfo = glXGetVisualFromFBConfig(m_sharedDisplay, temp[i]);
+ if (!scopedVisualInfo.get())
continue;
#if USE(GRAPHICS_SURFACE)
if (m_supportsXRenderExtension) {
- XRenderPictFormat* format = XRenderFindVisualFormat(m_sharedDisplay, m_visualInfo->visual);
+ XRenderPictFormat* format = XRenderFindVisualFormat(m_sharedDisplay, scopedVisualInfo->visual);
if (format && format->direct.alphaMask > 0) {
- selectedConfig = temp[i];
- found = true;
+ m_surfaceContextFBConfig = temp[i];
break;
}
- } else if (m_visualInfo->depth == 32) {
-#else
- if (m_visualInfo->depth == 32) {
+ }
#endif
- selectedConfig = temp[i];
- found = true;
+ if (!m_surfaceContextFBConfig && scopedVisualInfo->depth == 32) {
+ m_surfaceContextFBConfig = temp[i];
+ break;
}
}
// Did not find any visual supporting alpha, select the first available config.
- if (!found) {
- selectedConfig = temp[0];
- m_visualInfo = glXGetVisualFromFBConfig(m_sharedDisplay, temp[0]);
- }
-
- XFree(temp);
-
- return selectedConfig;
+ if (!m_surfaceContextFBConfig)
+ m_surfaceContextFBConfig = temp[0];
}
GLXFBConfig m_pbufferFBConfig;
GLXFBConfig m_surfaceContextFBConfig;
- XVisualInfo* m_visualInfo;
Display* m_sharedDisplay;
bool m_supportsXRenderExtension;
};
Modified: trunk/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp (141403 => 141404)
--- trunk/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp 2013-01-31 12:45:12 UTC (rev 141403)
+++ trunk/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp 2013-01-31 12:47:22 UTC (rev 141404)
@@ -45,14 +45,14 @@
}
m_configSelector = adoptPtr(new GLXConfigSelector(m_sharedDisplay, m_nativeResource->isXRenderExtensionSupported()));
+ OwnPtrX11<XVisualInfo> visInfo(m_configSelector->visualInfo());
- if (!configuration()) {
+ if (!visInfo.get()) {
destroy();
return;
}
- m_nativeResource->setVisualInfo(m_configSelector->visualInfo());
- m_nativeResource->createOffscreenWindow(&m_bufferHandle);
+ m_nativeResource->createOffScreenWindow(&m_bufferHandle, *visInfo.get());
if (!m_bufferHandle) {
destroy();
Added: trunk/Source/WebCore/platform/graphics/surfaces/glx/OwnPtrX11.h (0 => 141404)
--- trunk/Source/WebCore/platform/graphics/surfaces/glx/OwnPtrX11.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/surfaces/glx/OwnPtrX11.h 2013-01-31 12:47:22 UTC (rev 141404)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef OwnPtrX11_h
+#define OwnPtrX11_h
+
+namespace WebCore {
+
+template<typename T>
+struct OwnPtrX11 {
+
+ OwnPtrX11() : m_xResource(0) { }
+ OwnPtrX11(T* xResource) : m_xResource(xResource) { }
+
+ ~OwnPtrX11()
+ {
+ if (m_xResource)
+ XFree(m_xResource);
+ }
+
+ OwnPtrX11& operator=(T* xResource)
+ {
+ if (m_xResource)
+ XFree(m_xResource);
+
+ m_xResource = xResource;
+ return *this;
+ }
+
+ operator T*() const { return m_xResource; }
+ T* operator->() const { return m_xResource; }
+ T* get() const { return m_xResource; }
+
+private:
+ OwnPtrX11(const OwnPtrX11&);
+ OwnPtrX11& operator=(const OwnPtrX11&);
+ static void* operator new (size_t);
+ static void operator delete (void*);
+ T* m_xResource;
+};
+
+}
+
+#endif
Modified: trunk/Source/WebCore/platform/graphics/surfaces/glx/X11WindowResources.cpp (141403 => 141404)
--- trunk/Source/WebCore/platform/graphics/surfaces/glx/X11WindowResources.cpp 2013-01-31 12:45:12 UTC (rev 141403)
+++ trunk/Source/WebCore/platform/graphics/surfaces/glx/X11WindowResources.cpp 2013-01-31 12:47:22 UTC (rev 141404)
@@ -34,17 +34,12 @@
X11OffScreenWindow::X11OffScreenWindow()
: m_sharedResources(0)
- , m_configVisualInfo(0)
{
m_sharedResources = SharedX11Resources::create();
}
X11OffScreenWindow::~X11OffScreenWindow()
{
- if (m_configVisualInfo) {
- XFree(m_configVisualInfo);
- m_configVisualInfo = 0;
- }
}
void X11OffScreenWindow::reSizeWindow(const IntRect& newRect, const uint32_t windowId)
@@ -53,7 +48,8 @@
XFlush(m_sharedResources->x11Display());
}
-void X11OffScreenWindow::createOffscreenWindow(uint32_t* handleId)
+#if USE(GRAPHICS_SURFACE)
+void X11OffScreenWindow::createOffScreenWindow(uint32_t* handleId, const XVisualInfo& visInfo, const IntSize& size)
{
if (!m_sharedResources)
return;
@@ -62,7 +58,7 @@
if (!display)
return;
- if (!m_configVisualInfo) {
+ if (!visInfo.visual) {
LOG_ERROR("Failed to find valid XVisual.");
return;
}
@@ -71,13 +67,14 @@
if (!xWindow)
return;
- Colormap cmap = XCreateColormap(display, xWindow, m_configVisualInfo->visual, AllocNone);
+ Colormap cmap = XCreateColormap(display, xWindow, visInfo.visual, AllocNone);
XSetWindowAttributes attribute;
attribute.background_pixel = WhitePixel(display, 0);
attribute.border_pixel = BlackPixel(display, 0);
attribute.colormap = cmap;
+ attribute.event_mask = ResizeRedirectMask;
uint32_t tempHandleId;
- tempHandleId = XCreateWindow(display, xWindow, 0, 0, 1, 1, 0, m_configVisualInfo->depth, InputOutput, m_configVisualInfo->visual, CWBackPixel | CWBorderPixel | CWColormap, &attribute);
+ tempHandleId = XCreateWindow(display, xWindow, 0, 0, size.width(), size.height(), 0, visInfo.depth, InputOutput, visInfo.visual, CWBackPixel | CWBorderPixel | CWColormap, &attribute);
if (!tempHandleId) {
LOG_ERROR("Failed to create offscreen window.");
@@ -86,87 +83,67 @@
XSetWindowBackgroundPixmap(display, tempHandleId, 0);
XCompositeRedirectWindow(display, tempHandleId, CompositeRedirectManual);
+ XMapWindow(display, tempHandleId);
*handleId = tempHandleId;
-
- if (m_sharedResources->isXRenderExtensionSupported())
- XMapWindow(display, tempHandleId);
-
}
-void X11OffScreenWindow::destroyWindow(const uint32_t windowId)
-{
- if (!windowId)
- return;
-
- Display* display = m_sharedResources->x11Display();
- if (!display)
- return;
-
- XDestroyWindow(display, windowId);
-}
-
-Display* X11OffScreenWindow::nativeSharedDisplay() const
-{
- return m_sharedResources->x11Display();
-}
-
#if USE(EGL)
-bool X11OffScreenWindow::setVisualId(const EGLint id)
+void X11OffScreenWindow::createOffScreenWindow(uint32_t* handleId, const EGLint id, const IntSize& size)
{
VisualID visualId = static_cast<VisualID>(id);
if (!visualId)
- return false;
+ return;
// EGL has suggested a visual id, so get the rest of the visual info for that id.
XVisualInfo visualInfoTemplate;
memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
visualInfoTemplate.visualid = visualId;
-
- XVisualInfo* chosenVisualInfo;
int matchingCount = 0;
- chosenVisualInfo = XGetVisualInfo(m_sharedResources->x11Display(), VisualIDMask, &visualInfoTemplate, &matchingCount);
- if (chosenVisualInfo) {
-#if USE(GRAPHICS_SURFACE)
- if (m_sharedResources->isXRenderExtensionSupported()) {
- XRenderPictFormat* format = XRenderFindVisualFormat(m_sharedResources->x11Display(), chosenVisualInfo->visual);
- if (format && format->direct.alphaMask > 0) {
- m_configVisualInfo = chosenVisualInfo;
- return true;
- }
- }
-#endif
- if (chosenVisualInfo->depth == 32) {
- m_configVisualInfo = chosenVisualInfo;
- return true;
- }
- }
+ OwnPtrX11<XVisualInfo> matchingVisuals = adoptPtr(XGetVisualInfo(m_sharedResources->x11Display(), VisualIDMask, &visualInfoTemplate, &matchingCount));
+ XVisualInfo* foundVisual = 0;
- if (!m_configVisualInfo) {
- memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
- XVisualInfo* matchingVisuals;
- int matchingCount = 0;
+ if (matchingVisuals) {
+ for (int i = 0; i< matchingCount; i++) {
+ XVisualInfo* temp = &matchingVisuals[i];
- visualInfoTemplate.depth = chosenVisualInfo->depth;
- matchingVisuals = XGetVisualInfo(m_sharedResources->x11Display(), VisualDepthMask, &visualInfoTemplate, &matchingCount);
+ if (m_sharedResources->isXRenderExtensionSupported()) {
+ XRenderPictFormat* format = XRenderFindVisualFormat(m_sharedResources->x11Display(), temp->visual);
+ if (format && format->direct.alphaMask > 0) {
+ foundVisual = temp;
+ break;
+ }
+ }
- if (matchingVisuals) {
- m_configVisualInfo = &matchingVisuals[0];
- XFree(matchingVisuals);
- return true;
+ if (temp->depth == 32) {
+ foundVisual = temp;
+ break;
+ }
}
+
+ if (foundVisual)
+ createOffScreenWindow(handleId, *foundVisual, size);
}
+}
+#endif
- if (!m_configVisualInfo)
- LOG_ERROR("Failed to retrieve XVisual Info.");
+#endif
- return false;
+void X11OffScreenWindow::destroyWindow(const uint32_t windowId)
+{
+ if (!windowId)
+ return;
+
+ Display* display = m_sharedResources->x11Display();
+ if (!display)
+ return;
+
+ XDestroyWindow(display, windowId);
}
-#endif
-void X11OffScreenWindow::setVisualInfo(XVisualInfo* visInfo)
+Display* X11OffScreenWindow::nativeSharedDisplay() const
{
- m_configVisualInfo = visInfo;
+ return m_sharedResources->x11Display();
}
bool X11OffScreenWindow::isXRenderExtensionSupported() const
Modified: trunk/Source/WebCore/platform/graphics/surfaces/glx/X11WindowResources.h (141403 => 141404)
--- trunk/Source/WebCore/platform/graphics/surfaces/glx/X11WindowResources.h 2013-01-31 12:45:12 UTC (rev 141403)
+++ trunk/Source/WebCore/platform/graphics/surfaces/glx/X11WindowResources.h 2013-01-31 12:47:22 UTC (rev 141404)
@@ -29,13 +29,18 @@
#if USE(ACCELERATED_COMPOSITING)
#include "IntRect.h"
+#include "OwnPtrX11.h"
-#include <opengl/GLDefs.h>
#include <wtf/Noncopyable.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#if USE(GRAPHICS_SURFACE)
+
+#if USE(EGL)
+#include <opengl/GLDefs.h>
+#endif
+
#include <X11/extensions/Xcomposite.h>
#include <X11/extensions/Xrender.h>
#endif
@@ -143,19 +148,19 @@
public:
X11OffScreenWindow();
virtual ~X11OffScreenWindow();
- void createOffscreenWindow(uint32_t*);
+#if USE(GRAPHICS_SURFACE)
+ void createOffScreenWindow(uint32_t*, const XVisualInfo&, const IntSize& = IntSize(1, 1));
+#if USE(EGL)
+ void createOffScreenWindow(uint32_t*, const EGLint, const IntSize& = IntSize(1, 1));
+#endif
+#endif
void destroyWindow(const uint32_t);
void reSizeWindow(const IntRect&, const uint32_t);
Display* nativeSharedDisplay() const;
-#if USE(EGL)
- bool setVisualId(const EGLint);
-#endif
- void setVisualInfo(XVisualInfo*);
bool isXRenderExtensionSupported() const;
private:
RefPtr<SharedX11Resources> m_sharedResources;
- XVisualInfo* m_configVisualInfo;
};
}