| Differences between
and this patch
- Source/WebCore/ChangeLog +56 lines
Lines 1-3 Source/WebCore/ChangeLog_sec1
1
2012-12-18  Kondapally Kalyan  <kalyan.kondapally@intel.com>
2
3
        [EFL][WebGL] Refactor GLXSurface.
4
        https://bugs.webkit.org/show_bug.cgi?id=105357
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        This is in preparation for adding EGL support.
9
        There is lot of X related code which could be shared between our current GLX implementation
10
        and EGL. This patch makes it possible to share the common code but doesn't change any functionality.
11
12
        * PlatformEfl.cmake:
13
        * platform/graphics/surfaces/glx/GLXSurface.cpp:
14
        (WebCore):
15
        (WebCore::GLXTransportSurface::GLXTransportSurface):
16
        (WebCore::GLXTransportSurface::configuration):
17
        (WebCore::GLXTransportSurface::destroy):
18
        (WebCore::GLXTransportSurface::freeResources):
19
        (WebCore::GLXPBuffer::GLXPBuffer):
20
        (WebCore::GLXPBuffer::initialize):
21
        (WebCore::GLXPBuffer::configuration):
22
        (WebCore::GLXPBuffer::setGeometry):
23
        * platform/graphics/surfaces/glx/GLXSurface.h:
24
        (GLXTransportSurface):
25
        (GLXPBuffer):
26
27
        GLX related implementation.
28
        * platform/graphics/surfaces/glx/GLXWindowResources.h: Added.
29
        (WebCore):
30
        (SharedGLXResources):
31
        (WebCore::SharedGLXResources::create):
32
        (WebCore::SharedGLXResources::nativeDisplay):
33
        (WebCore::SharedGLXResources::pBufferContextConfig):
34
        (WebCore::SharedGLXResources::surfaceContextConfig):
35
        (WebCore::SharedGLXResources::SharedGLXResources):
36
        (WebCore::SharedGLXResources::createConfig):
37
38
        Moving X related code to a seperate class.
39
        * platform/graphics/surfaces/glx/X11WindowResources.cpp: Added.
40
        (WebCore):
41
        (WebCore::X11OffScreenWindow::X11OffScreenWindow):
42
        (WebCore::X11OffScreenWindow::~X11OffScreenWindow):
43
        (WebCore::X11OffScreenWindow::setGeometry):
44
        (WebCore::X11OffScreenWindow::createOffscreenWindow):
45
        * platform/graphics/surfaces/glx/X11WindowResources.h: Added.
46
        (WebCore):
47
        (SharedX11Resources):
48
        (WebCore::SharedX11Resources::deref):
49
        (WebCore::SharedX11Resources::x11Display):
50
        (WebCore::SharedX11Resources::getXWindow):
51
        (WebCore::SharedX11Resources::visualInfo):
52
        (WebCore::SharedX11Resources::isXRenderExtensionSupported):
53
        (WebCore::SharedX11Resources::SharedX11Resources):
54
        (WebCore::SharedX11Resources::~SharedX11Resources):
55
        (X11OffScreenWindow):
56
1
2012-12-12  Simon Hausmann  <simon.hausmann@digia.com>
57
2012-12-12  Simon Hausmann  <simon.hausmann@digia.com>
2
58
3
        [Qt] Fix build on Mac
59
        [Qt] Fix build on Mac
- Source/WebCore/PlatformEfl.cmake +1 lines
Lines 294-299 if (WTF_USE_3D_GRAPHICS) Source/WebCore/PlatformEfl.cmake_sec1
294
        platform/graphics/surfaces/glx/GLXSurface.cpp
294
        platform/graphics/surfaces/glx/GLXSurface.cpp
295
        platform/graphics/surfaces/glx/GLXContext.cpp
295
        platform/graphics/surfaces/glx/GLXContext.cpp
296
        platform/graphics/surfaces/glx/GraphicsSurfaceGLX.cpp
296
        platform/graphics/surfaces/glx/GraphicsSurfaceGLX.cpp
297
        platform/graphics/surfaces/glx/X11WindowResources.cpp
297
        platform/graphics/texmap/TextureMapperGL.cpp
298
        platform/graphics/texmap/TextureMapperGL.cpp
298
        platform/graphics/texmap/TextureMapperShaderManager.cpp
299
        platform/graphics/texmap/TextureMapperShaderManager.cpp
299
    )
300
    )
- Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp -80 / +11 lines
Lines 30-80 Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp_sec1
30
30
31
namespace WebCore {
31
namespace WebCore {
32
32
33
SharedX11Resources* SharedX11Resources::m_staticSharedResource = 0;
34
35
static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 };
33
static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 };
36
34
37
GLXSurface::GLXSurface()
38
    : GLPlatformSurface()
39
{
40
    m_sharedResources = SharedX11Resources::create();
41
    m_sharedDisplay = m_sharedResources->display();
42
}
43
44
GLXSurface::~GLXSurface()
45
{
46
}
47
48
XVisualInfo* GLXSurface::visualInfo()
49
{
50
    return m_sharedResources->visualInfo();
51
}
52
53
Window GLXSurface::xWindow()
54
{
55
    return m_sharedResources->getXWindow();
56
}
57
58
GLXFBConfig GLXSurface::pBufferConfiguration()
59
{
60
    return m_sharedResources->pBufferContextConfig();
61
}
62
63
GLXFBConfig GLXSurface::transportSurfaceConfiguration()
64
{
65
    return m_sharedResources->surfaceContextConfig();
66
}
67
68
bool GLXSurface::isXRenderExtensionSupported()
69
{
70
    return m_sharedResources->isXRenderExtensionSupported();
71
}
72
73
#if USE(GRAPHICS_SURFACE)
35
#if USE(GRAPHICS_SURFACE)
74
GLXTransportSurface::GLXTransportSurface()
36
GLXTransportSurface::GLXTransportSurface()
75
    : GLXSurface()
37
    : X11OffScreenWindow()
76
{
38
{
77
    initialize();
39
    createOffscreenWindow();
78
}
40
}
79
41
80
GLXTransportSurface::~GLXTransportSurface()
42
GLXTransportSurface::~GLXTransportSurface()
Lines 83-89 GLXTransportSurface::~GLXTransportSurface() Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp_sec2
83
45
84
PlatformSurfaceConfig GLXTransportSurface::configuration()
46
PlatformSurfaceConfig GLXTransportSurface::configuration()
85
{
47
{
86
    return transportSurfaceConfiguration();
48
    return m_sharedResources->surfaceContextConfig();
87
}
49
}
88
50
89
void GLXTransportSurface::swapBuffers()
51
void GLXTransportSurface::swapBuffers()
Lines 101-145 void GLXTransportSurface::swapBuffers() Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp_sec3
101
        glXSwapBuffers(sharedDisplay(), m_drawable);
63
        glXSwapBuffers(sharedDisplay(), m_drawable);
102
}
64
}
103
65
104
void GLXTransportSurface::setGeometry(const IntRect& newRect)
105
{
106
    GLPlatformSurface::setGeometry(newRect);
107
    int width = newRect.width();
108
    int height = newRect.height();
109
    XResizeWindow(sharedDisplay(), m_drawable, width, height);
110
}
111
112
void GLXTransportSurface::initialize()
113
{
114
    Display* display = sharedDisplay();
115
    GLXFBConfig config = transportSurfaceConfiguration();
116
    if (!config)
117
        return;
118
119
    XVisualInfo* visInfo = visualInfo();
120
    if (!visInfo)
121
        return;
122
123
    Colormap cmap = XCreateColormap(display, xWindow(), visInfo->visual, AllocNone);
124
    XSetWindowAttributes attribute;
125
    attribute.background_pixel = WhitePixel(display, 0);
126
    attribute.border_pixel = BlackPixel(display, 0);
127
    attribute.colormap = cmap;
128
    m_drawable = XCreateWindow(display, xWindow(), 0, 0, 1, 1, 0, visInfo->depth, InputOutput, visInfo->visual, CWBackPixel | CWBorderPixel | CWColormap, &attribute);
129
    if (!m_drawable)
130
        return;
131
132
    XSetWindowBackgroundPixmap(display, m_drawable, 0);
133
    XCompositeRedirectWindow(display, m_drawable, CompositeRedirectManual);
134
135
    if (isXRenderExtensionSupported())
136
        XMapWindow(display, m_drawable);
137
}
138
139
void GLXTransportSurface::destroy()
66
void GLXTransportSurface::destroy()
140
{
67
{
141
    freeResources();
68
    freeResources();
142
    GLPlatformSurface::destroy();
143
}
69
}
144
70
145
void GLXTransportSurface::freeResources()
71
void GLXTransportSurface::freeResources()
Lines 158-164 void GLXTransportSurface::freeResources() Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp_sec4
158
#endif
84
#endif
159
85
160
GLXPBuffer::GLXPBuffer()
86
GLXPBuffer::GLXPBuffer()
161
    : GLXSurface()
87
    : X11OffScreenWindow()
162
{
88
{
163
    initialize();
89
    initialize();
164
}
90
}
Lines 170-176 GLXPBuffer::~GLXPBuffer() Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp_sec5
170
void GLXPBuffer::initialize()
96
void GLXPBuffer::initialize()
171
{
97
{
172
    Display* display = sharedDisplay();
98
    Display* display = sharedDisplay();
173
    GLXFBConfig config = pBufferConfiguration();
99
    GLXFBConfig config = m_sharedResources->pBufferContextConfig();
174
    if (!config)
100
    if (!config)
175
        return;
101
        return;
176
102
Lines 179-185 void GLXPBuffer::initialize() Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp_sec6
179
105
180
PlatformSurfaceConfig GLXPBuffer::configuration()
106
PlatformSurfaceConfig GLXPBuffer::configuration()
181
{
107
{
182
    return pBufferConfiguration();
108
    return m_sharedResources->pBufferContextConfig();
183
}
109
}
184
110
185
void GLXPBuffer::destroy()
111
void GLXPBuffer::destroy()
Lines 201-206 void GLXPBuffer::freeResources() Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp_sec7
201
    m_drawable = 0;
127
    m_drawable = 0;
202
}
128
}
203
129
130
void GLXPBuffer::setGeometry(const IntRect& newRect)
131
{
132
    GLPlatformSurface::setGeometry(newRect);
133
}
134
204
}
135
}
205
136
206
#endif
137
#endif
- Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.h -227 / +5 lines
Lines 28-263 Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.h_sec1
28
28
29
#if USE(ACCELERATED_COMPOSITING) && HAVE(GLX)
29
#if USE(ACCELERATED_COMPOSITING) && HAVE(GLX)
30
30
31
#include "GLPlatformSurface.h"
31
#include "GLXWindowResources.h"
32
#if USE(GRAPHICS_SURFACE)
32
33
#include <X11/extensions/Xcomposite.h>
34
#include <X11/extensions/Xrender.h>
35
#endif
36
#include <wtf/Noncopyable.h>
33
#include <wtf/Noncopyable.h>
37
#include <wtf/RefCounted.h>
38
34
39
namespace WebCore {
35
namespace WebCore {
40
36
41
class SharedX11Resources : public WTF::RefCountedBase {
42
    WTF_MAKE_NONCOPYABLE(SharedX11Resources);
43
44
public:
45
    static PassRefPtr<SharedX11Resources> create()
46
    {
47
        if (!m_staticSharedResource)
48
            m_staticSharedResource = new SharedX11Resources();
49
        else
50
            m_staticSharedResource->ref();
51
52
        return adoptRef(m_staticSharedResource);
53
    }
54
55
    void deref()
56
    {
57
        if (derefBase()) {
58
            m_staticSharedResource = 0;
59
            delete this;
60
        }
61
    }
62
63
    Window getXWindow()
64
    {
65
        if (!m_window) {
66
            Display* dpy = display();
67
            XSetWindowAttributes attributes;
68
            attributes.override_redirect = true;
69
            m_window = XCreateSimpleWindow(dpy, XDefaultRootWindow(dpy), -1, -1, 1, 1, 0, BlackPixel(dpy, 0), WhitePixel(dpy, 0));
70
            // From http://tronche.com/gui/x/xlib/window/attributes/
71
            XChangeWindowAttributes(dpy, m_window, CWOverrideRedirect, &attributes);
72
            XMapWindow(dpy, m_window);
73
        }
74
75
        return m_window;
76
    }
77
78
    Display* display()
79
    {
80
        if (!m_display)
81
            m_display = XOpenDisplay(0);
82
83
        return m_display;
84
    }
85
86
    XVisualInfo* visualInfo()
87
    {
88
        if (!m_VisualInfo)
89
            surfaceContextConfig();
90
91
        return m_VisualInfo;
92
    }
93
94
    GLXFBConfig createConfig(const int attributes[])
95
    {
96
        int numReturned;
97
        m_VisualInfo = 0;
98
        GLXFBConfig* temp = glXChooseFBConfig(display(), DefaultScreen(display()), attributes, &numReturned);
99
100
        if (!numReturned)
101
            return 0;
102
103
        GLXFBConfig selectedConfig = 0;
104
        bool found = false;
105
106
        for (int i = 0; i < numReturned; ++i) {
107
            m_VisualInfo = glXGetVisualFromFBConfig(display(), temp[i]);
108
            if (!m_VisualInfo)
109
                continue;
110
#if USE(GRAPHICS_SURFACE)
111
            if (m_supportsXRenderExtension) {
112
                XRenderPictFormat* format = XRenderFindVisualFormat(display(), m_VisualInfo->visual);
113
                if (format && format->direct.alphaMask > 0) {
114
                    selectedConfig = temp[i];
115
                    found = true;
116
                    break;
117
                }
118
            } else if (m_VisualInfo->depth == 32) {
119
#else
120
            if (m_VisualInfo->depth == 32) {
121
#endif
122
                selectedConfig = temp[i];
123
                found = true;
124
            }
125
        }
126
127
        // Did not find any visual supporting alpha, select the first available config.
128
        if (!found) {
129
            selectedConfig = temp[0];
130
            m_VisualInfo = glXGetVisualFromFBConfig(m_display, temp[0]);
131
        }
132
133
        XFree(temp);
134
135
        return selectedConfig;
136
    }
137
138
    GLXFBConfig pBufferContextConfig()
139
    {
140
        if (!m_pbufferfbConfig) {
141
            static const int attributes[] = {
142
                GLX_LEVEL, 0,
143
                GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
144
                GLX_RENDER_TYPE,   GLX_RGBA_BIT,
145
                GLX_RED_SIZE,      1,
146
                GLX_GREEN_SIZE,    1,
147
                GLX_BLUE_SIZE,     1,
148
                GLX_DOUBLEBUFFER,  GL_FALSE,
149
                None
150
            };
151
152
            int numReturned;
153
            GLXFBConfig* temp = glXChooseFBConfig(display(), DefaultScreen(display()), attributes, &numReturned);
154
            if (numReturned)
155
                m_pbufferfbConfig = temp[0];
156
            XFree(temp);
157
        }
158
159
        return m_pbufferfbConfig;
160
    }
161
162
    GLXFBConfig surfaceContextConfig()
163
    {
164
        if (!m_surfaceContextfbConfig) {
165
            static int attributes[] = {
166
                GLX_LEVEL, 0,
167
                GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
168
                GLX_RENDER_TYPE,   GLX_RGBA_BIT,
169
                GLX_RED_SIZE,      1,
170
                GLX_GREEN_SIZE,    1,
171
                GLX_BLUE_SIZE,     1,
172
                GLX_ALPHA_SIZE,    1,
173
                GLX_DEPTH_SIZE,    1,
174
                GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
175
                GLX_DOUBLEBUFFER,  True,
176
                None
177
            };
178
#if USE(GRAPHICS_SURFACE)
179
            int eventBasep, errorBasep;
180
            m_supportsXRenderExtension = XRenderQueryExtension(display(), &eventBasep, &errorBasep);
181
#endif
182
            m_surfaceContextfbConfig = createConfig(attributes);
183
        }
184
185
        return m_surfaceContextfbConfig;
186
    }
187
188
    bool isXRenderExtensionSupported()
189
    {
190
        return m_supportsXRenderExtension;
191
    }
192
193
private:
194
    SharedX11Resources()
195
        : m_supportsXRenderExtension(false)
196
        , m_markForDeletion(false)
197
        , m_window(0)
198
        , m_display(0)
199
        , m_pbufferfbConfig(0)
200
        , m_surfaceContextfbConfig(0)
201
        , m_VisualInfo(0)
202
    {
203
    }
204
205
    ~SharedX11Resources()
206
    {
207
        if (!m_display)
208
            return;
209
210
        if (m_window) {
211
            XUnmapWindow(m_display, m_window);
212
            XDestroyWindow(m_display, m_window);
213
            m_window = 0;
214
        }
215
216
        if (m_pbufferfbConfig)
217
            m_pbufferfbConfig = 0;
218
219
        if (m_surfaceContextfbConfig)
220
            m_surfaceContextfbConfig = 0;
221
222
        if (m_VisualInfo) {
223
            XFree(m_VisualInfo);
224
            m_VisualInfo = 0;
225
        }
226
227
        XCloseDisplay(m_display);
228
        m_display = 0;
229
    }
230
231
    static SharedX11Resources* m_staticSharedResource;
232
    bool m_supportsXRenderExtension;
233
    bool m_markForDeletion;
234
    Window m_window;
235
    Display* m_display;
236
    GLXFBConfig m_pbufferfbConfig;
237
    GLXFBConfig m_surfaceContextfbConfig;
238
    XVisualInfo* m_VisualInfo;
239
};
240
241
class GLXSurface : public GLPlatformSurface {
242
    WTF_MAKE_NONCOPYABLE(GLXSurface);
243
244
public:
245
    GLXSurface();
246
    virtual ~GLXSurface();
247
248
protected:
249
    XVisualInfo* visualInfo();
250
    Window xWindow();
251
    GLXFBConfig pBufferConfiguration();
252
    GLXFBConfig transportSurfaceConfiguration();
253
    bool isXRenderExtensionSupported();
254
255
private:
256
    RefPtr<SharedX11Resources> m_sharedResources;
257
};
258
259
#if USE(GRAPHICS_SURFACE)
37
#if USE(GRAPHICS_SURFACE)
260
class GLXTransportSurface : public GLXSurface {
38
class GLXTransportSurface : public X11OffScreenWindow {
261
    WTF_MAKE_NONCOPYABLE(GLXTransportSurface);
39
    WTF_MAKE_NONCOPYABLE(GLXTransportSurface);
262
40
263
public:
41
public:
Lines 265-271 public: Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.h_sec2
265
    virtual ~GLXTransportSurface();
43
    virtual ~GLXTransportSurface();
266
    PlatformSurfaceConfig configuration();
44
    PlatformSurfaceConfig configuration();
267
    void swapBuffers();
45
    void swapBuffers();
268
    void setGeometry(const IntRect& newRect);
269
    void destroy();
46
    void destroy();
270
47
271
private:
48
private:
Lines 274-286 private: Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.h_sec3
274
};
51
};
275
#endif
52
#endif
276
53
277
class GLXPBuffer : public GLXSurface {
54
class GLXPBuffer : public X11OffScreenWindow {
278
    WTF_MAKE_NONCOPYABLE(GLXPBuffer);
55
    WTF_MAKE_NONCOPYABLE(GLXPBuffer);
279
56
280
public:
57
public:
281
    GLXPBuffer();
58
    GLXPBuffer();
282
    virtual ~GLXPBuffer();
59
    virtual ~GLXPBuffer();
283
    PlatformSurfaceConfig configuration();
60
    PlatformSurfaceConfig configuration();
61
    void setGeometry(const IntRect&);
284
    void destroy();
62
    void destroy();
285
63
286
private:
64
private:
- Source/WebCore/platform/graphics/surfaces/glx/GLXWindowResources.h +174 lines
Line 0 Source/WebCore/platform/graphics/surfaces/glx/GLXWindowResources.h_sec1
1
/*
2
 * Copyright (C) 2012 Intel Corporation. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#ifndef GLXWindowResources_h
27
#define GLXWindowResources_h
28
29
#include "X11WindowResources.h"
30
31
#if USE(ACCELERATED_COMPOSITING) && HAVE(GLX)
32
33
namespace WebCore {
34
35
class SharedGLXResources : public SharedX11Resources {
36
    WTF_MAKE_NONCOPYABLE(SharedGLXResources);
37
38
public:
39
    static PassRefPtr<SharedGLXResources> create()
40
    {
41
        if (!m_staticSharedResource)
42
            m_staticSharedResource = new SharedGLXResources();
43
        else
44
            m_staticSharedResource->ref();
45
46
        return adoptRef(m_staticSharedResource);
47
    }
48
49
    PlatformDisplay nativeDisplay()
50
    {
51
        return SharedX11Resources::x11Display();
52
    }
53
54
    virtual GLXFBConfig pBufferContextConfig()
55
    {
56
        if (!m_pbufferfbConfig) {
57
            static const int attributes[] = {
58
                GLX_LEVEL, 0,
59
                GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
60
                GLX_RENDER_TYPE,   GLX_RGBA_BIT,
61
                GLX_RED_SIZE,      1,
62
                GLX_GREEN_SIZE,    1,
63
                GLX_BLUE_SIZE,     1,
64
                GLX_DOUBLEBUFFER,  GL_FALSE,
65
                None
66
            };
67
68
            int numReturned;
69
            GLXFBConfig* temp = glXChooseFBConfig(nativeDisplay(), DefaultScreen(nativeDisplay()), attributes, &numReturned);
70
            if (numReturned)
71
                m_pbufferfbConfig = temp[0];
72
            XFree(temp);
73
        }
74
75
        return m_pbufferfbConfig;
76
    }
77
78
    virtual GLXFBConfig surfaceContextConfig()
79
    {
80
        if (!m_surfaceContextfbConfig) {
81
            static int attributes[] = {
82
                GLX_LEVEL, 0,
83
                GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
84
                GLX_RENDER_TYPE,   GLX_RGBA_BIT,
85
                GLX_RED_SIZE,      1,
86
                GLX_GREEN_SIZE,    1,
87
                GLX_BLUE_SIZE,     1,
88
                GLX_ALPHA_SIZE,    1,
89
                GLX_DEPTH_SIZE,    1,
90
                GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
91
                GLX_DOUBLEBUFFER,  True,
92
                None
93
            };
94
95
            m_surfaceContextfbConfig = createConfig(attributes);
96
        }
97
98
        return m_surfaceContextfbConfig;
99
    }
100
101
private:
102
    SharedGLXResources()
103
        : SharedX11Resources()
104
        , m_pbufferfbConfig(0)
105
        , m_surfaceContextfbConfig(0)
106
    {
107
    }
108
109
    GLXFBConfig createConfig(const int attributes[])
110
    {
111
        int numReturned;
112
        m_VisualInfo = 0;
113
        GLXFBConfig* temp = glXChooseFBConfig(nativeDisplay(), DefaultScreen(nativeDisplay()), attributes, &numReturned);
114
115
        if (!numReturned)
116
            return 0;
117
118
        GLXFBConfig selectedConfig = 0;
119
        bool found = false;
120
121
        for (int i = 0; i < numReturned; ++i) {
122
            m_VisualInfo = glXGetVisualFromFBConfig(nativeDisplay(), temp[i]);
123
            if (!m_VisualInfo)
124
                continue;
125
#if USE(GRAPHICS_SURFACE)
126
            if (m_supportsXRenderExtension) {
127
                XRenderPictFormat* format = XRenderFindVisualFormat(nativeDisplay(), m_VisualInfo->visual);
128
                if (format && format->direct.alphaMask > 0) {
129
                    selectedConfig = temp[i];
130
                    found = true;
131
                    break;
132
                }
133
            } else if (m_VisualInfo->depth == 32) {
134
#else
135
            if (m_VisualInfo->depth == 32) {
136
#endif
137
                selectedConfig = temp[i];
138
                found = true;
139
            }
140
        }
141
142
        // Did not find any visual supporting alpha, select the first available config.
143
        if (!found) {
144
            selectedConfig = temp[0];
145
            m_VisualInfo = glXGetVisualFromFBConfig(m_display, temp[0]);
146
        }
147
148
        XFree(temp);
149
150
        return selectedConfig;
151
    }
152
153
    virtual ~SharedGLXResources()
154
    {
155
        if (!m_display)
156
            return;
157
158
        if (m_pbufferfbConfig)
159
            m_pbufferfbConfig = 0;
160
161
        if (m_surfaceContextfbConfig)
162
            m_surfaceContextfbConfig = 0;
163
    }
164
165
    GLXFBConfig m_pbufferfbConfig;
166
    GLXFBConfig m_surfaceContextfbConfig;
167
168
};
169
170
}
171
172
#endif
173
174
#endif
- Source/WebCore/platform/graphics/surfaces/glx/X11WindowResources.cpp +102 lines
Line 0 Source/WebCore/platform/graphics/surfaces/glx/X11WindowResources.cpp_sec1
1
/*
2
 * Copyright (C) 2012 Intel Corporation. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#include "config.h"
27
#include "X11WindowResources.h"
28
29
#if USE(ACCELERATED_COMPOSITING)
30
31
#include "GLXWindowResources.h"
32
33
namespace WebCore {
34
35
PlatformSharedResources* SharedX11Resources::m_staticSharedResource = 0;
36
37
X11OffScreenWindow::X11OffScreenWindow()
38
    : GLPlatformSurface()
39
{
40
    m_sharedResources = PlatformSharedResources::create();
41
    m_sharedDisplay = m_sharedResources->nativeDisplay();
42
}
43
44
X11OffScreenWindow::~X11OffScreenWindow()
45
{
46
}
47
48
void X11OffScreenWindow::setGeometry(const IntRect& newRect)
49
{
50
    GLPlatformSurface::setGeometry(newRect);
51
    XResizeWindow(m_sharedResources->x11Display(), m_drawable, newRect.width(), newRect.height());
52
}
53
54
void X11OffScreenWindow::createOffscreenWindow()
55
{
56
    Display* display = m_sharedResources->x11Display();
57
58
    if (!display)
59
        return;
60
61
    GLXFBConfig config = m_sharedResources->surfaceContextConfig();
62
63
    if (!config) {
64
        LOG_ERROR("Failed to retrieve a valid configiration.");
65
        return;
66
    }
67
68
    XVisualInfo* visInfo = m_sharedResources->visualInfo();
69
70
    if (!visInfo) {
71
        LOG_ERROR("Failed to find valid XVisual");
72
        return;
73
    }
74
75
    Window xWindow = m_sharedResources->getXWindow();
76
77
    if (!xWindow)
78
        return;
79
80
    Colormap cmap = XCreateColormap(display, xWindow, visInfo->visual, AllocNone);
81
    XSetWindowAttributes attribute;
82
    attribute.background_pixel = WhitePixel(display, 0);
83
    attribute.border_pixel = BlackPixel(display, 0);
84
    attribute.colormap = cmap;
85
    m_drawable = XCreateWindow(display, xWindow, 0, 0, 1, 1, 0, visInfo->depth, InputOutput, visInfo->visual, CWBackPixel | CWBorderPixel | CWColormap, &attribute);
86
87
    if (!m_drawable) {
88
        LOG_ERROR("Failed to create offscreen window");
89
        return;
90
    }
91
92
    XSetWindowBackgroundPixmap(display, m_drawable, 0);
93
    XCompositeRedirectWindow(display, m_drawable, CompositeRedirectManual);
94
95
    if (m_sharedResources->isXRenderExtensionSupported())
96
        XMapWindow(display, m_drawable);
97
98
}
99
100
}
101
102
#endif
- Source/WebCore/platform/graphics/surfaces/glx/X11WindowResources.h +170 lines
Line 0 Source/WebCore/platform/graphics/surfaces/glx/X11WindowResources.h_sec1
1
/*
2
 * Copyright (C) 2012 Intel Corporation. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#ifndef X11WindowResources_h
27
#define X11WindowResources_h
28
29
#if USE(ACCELERATED_COMPOSITING)
30
31
#include "GLPlatformSurface.h"
32
33
#if USE(GRAPHICS_SURFACE)
34
#include <X11/extensions/Xcomposite.h>
35
#include <X11/extensions/Xrender.h>
36
#endif
37
38
#include <wtf/Noncopyable.h>
39
#include <wtf/RefCounted.h>
40
41
namespace WebCore {
42
43
class SharedGLXResources;
44
typedef SharedGLXResources PlatformSharedResources;
45
46
class SharedX11Resources : public WTF::RefCountedBase {
47
    WTF_MAKE_NONCOPYABLE(SharedX11Resources);
48
49
public:
50
    void deref()
51
    {
52
        if (derefBase()) {
53
            m_staticSharedResource = 0;
54
            delete this;
55
        }
56
    }
57
58
    Display* x11Display()
59
    {
60
        if (!m_display) {
61
            m_display = XOpenDisplay(0);
62
            if (!m_display) {
63
                LOG_ERROR("Failed to make connection with X");
64
                return 0;
65
            }
66
#if USE(GRAPHICS_SURFACE)
67
            if (m_display) {
68
                int eventBasep, errorBasep;
69
                m_supportsXRenderExtension = XRenderQueryExtension(m_display, &eventBasep, &errorBasep);
70
            }
71
#endif
72
        }
73
74
        return m_display;
75
    }
76
77
    Window getXWindow()
78
    {
79
        if (!m_window) {
80
            Display* dpy = x11Display();
81
            XSetWindowAttributes attributes;
82
            attributes.override_redirect = true;
83
            m_window = XCreateSimpleWindow(dpy, XDefaultRootWindow(dpy), -1, -1, 1, 1, 0, BlackPixel(dpy, 0), WhitePixel(dpy, 0));
84
            // From http://tronche.com/gui/x/xlib/window/attributes/
85
            XChangeWindowAttributes(dpy, m_window, CWOverrideRedirect, &attributes);
86
            XMapWindow(dpy, m_window);
87
88
            if (!m_window) {
89
                LOG_ERROR("Failed to create SimpleWindow");
90
                return 0;
91
            }
92
        }
93
94
        return m_window;
95
    }
96
97
98
    XVisualInfo* visualInfo()
99
    {
100
        if (!m_VisualInfo)
101
            surfaceContextConfig();
102
103
        return m_VisualInfo;
104
    }
105
106
107
108
    bool isXRenderExtensionSupported()
109
    {
110
        return m_supportsXRenderExtension;
111
    }
112
113
    virtual PlatformSurfaceConfig pBufferContextConfig() = 0;
114
    virtual PlatformSurfaceConfig surfaceContextConfig() = 0;
115
    virtual PlatformDisplay nativeDisplay() = 0;
116
117
protected:
118
    SharedX11Resources()
119
        : m_supportsXRenderExtension(false)
120
        , m_window(0)
121
        , m_display(0)
122
        , m_VisualInfo(0)
123
    {
124
    }
125
126
    virtual ~SharedX11Resources()
127
    {
128
        if (!m_display)
129
            return;
130
131
        if (m_window) {
132
            XUnmapWindow(m_display, m_window);
133
            XDestroyWindow(m_display, m_window);
134
            m_window = 0;
135
        }
136
137
        if (m_VisualInfo) {
138
            XFree(m_VisualInfo);
139
            m_VisualInfo = 0;
140
        }
141
142
        XCloseDisplay(m_display);
143
        m_display = 0;
144
    }
145
146
    static PlatformSharedResources* m_staticSharedResource;
147
    bool m_supportsXRenderExtension;
148
    Window m_window;
149
    Display* m_display;
150
    XVisualInfo* m_VisualInfo;
151
};
152
153
class X11OffScreenWindow : public GLPlatformSurface {
154
    WTF_MAKE_NONCOPYABLE(X11OffScreenWindow);
155
156
public:
157
    X11OffScreenWindow();
158
    virtual ~X11OffScreenWindow();
159
    void setGeometry(const IntRect&);
160
    void createOffscreenWindow();
161
162
protected:
163
    RefPtr<PlatformSharedResources> m_sharedResources;
164
};
165
166
}
167
168
#endif
169
170
#endif

Return to Bug 105357