| Differences between
and this patch
- a/Source/WebCore/ChangeLog +71 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2015-05-02  Carlos Garcia Campos  <cgarcia@igalia.com>
2
3
        [X11] Add XUniquePtr and XUniqueResource to automatically free X resources
4
        https://bugs.webkit.org/show_bug.cgi?id=144521
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Add XUniquePtr as a template alias of std:unique_ptr to handle X
9
        resources using pointers and XUniqueResource as a new class to
10
        handle X resources using a long unsigned identifier. This
11
        simplifies the code and makes it more difficult to leak X resources.
12
13
        * PlatformEfl.cmake: Add new files to compilation.
14
        * PlatformGTK.cmake: Add new files to compilation.
15
        * platform/graphics/cairo/BackingStoreBackendCairoX11.cpp:
16
        (WebCore::BackingStoreBackendCairoX11::BackingStoreBackendCairoX11):
17
        Remove the display member, and use XUnique for Pixmap and GC.
18
        (WebCore::BackingStoreBackendCairoX11::~BackingStoreBackendCairoX11):
19
        Remove code to explicitly free Pixmap and GC.
20
        (WebCore::BackingStoreBackendCairoX11::scroll):
21
        * platform/graphics/cairo/BackingStoreBackendCairoX11.h:
22
        * platform/graphics/glx/GLContextGLX.cpp:
23
        (WebCore::GLContextGLX::createWindowContext): Use XUnique and the
24
        new constructor that receives a XID, since there's no longer
25
        conflict with the one receiving a Pbuffer.
26
        (WebCore::GLContextGLX::createPbufferContext): Use XUnique and the
27
        new constructor that receives a XUniqueGLXPbuffer&&.
28
        (WebCore::GLContextGLX::createPixmapContext):
29
        (WebCore::GLContextGLX::createContext):
30
        (WebCore::GLContextGLX::GLContextGLX):
31
        (WebCore::GLContextGLX::~GLContextGLX): Remove code to explicitly
32
        free X resources.
33
        (WebCore::GLContextGLX::makeContextCurrent):
34
        (WebCore::GLContextGLX::cairoDevice):
35
        (WebCore::GLContextGLX::platformContext):
36
        * platform/graphics/glx/GLContextGLX.h:
37
        * platform/graphics/surfaces/egl/EGLXSurface.cpp:
38
        (WebCore::EGLXTransportSurfaceClient::EGLXTransportSurfaceClient):
39
        (WebCore::EGLXTransportSurfaceClient::destroy):
40
        (WebCore::EGLXTransportSurfaceClient::prepareTexture):
41
        (WebCore::EGLTextureFromPixmap::EGLTextureFromPixmap): Deleted.
42
        * platform/graphics/surfaces/egl/EGLXSurface.h:
43
        * platform/graphics/surfaces/glx/GLXConfigSelector.h:
44
        (WebCore::GLXConfigSelector::findMatchingConfig): Use XUnique
45
        instead of the custom std::unique X11Deleter.
46
        (WebCore::GLXConfigSelector::findMatchingConfigWithVisualId): Ditto.
47
        * platform/graphics/surfaces/glx/GLXSurface.cpp:
48
        (WebCore::GLXTransportSurface::GLXTransportSurface): Ditto.
49
        (WebCore::GLXOffScreenSurface::initialize): Ditto.
50
        * platform/graphics/surfaces/glx/X11Helper.cpp:
51
        (WebCore::X11Helper::createOffScreenWindow): Ditto.
52
        (WebCore::X11Helper::createPixmap): Ditto.
53
        * platform/graphics/surfaces/glx/X11Helper.h: Remove X11Deleter.
54
        * platform/graphics/x11/XUnique.cpp: Added.
55
        (WebCore::XUniqueResource<XResource::Colormap>::deleteXResource):
56
        (WebCore::XUniqueResource<XResource::Damage>::deleteXResource):
57
        (WebCore::XUniqueResource<XResource::Pixmap>::deleteXResource):
58
        (WebCore::XUniqueResource<XResource::Window>::deleteXResource):
59
        (WebCore::XUniqueResource<XResource::GLXPbuffer>::deleteXResource):
60
        (WebCore::XUniqueResource<XResource::GLXPixmap>::deleteXResource):
61
        * platform/graphics/x11/XUnique.h: Added.
62
        (WebCore::XPtrDeleter::operator()):
63
        (WebCore::XUniqueResource::XUniqueResource):
64
        (WebCore::XUniqueResource::operator=):
65
        (WebCore::XUniqueResource::~XUniqueResource):
66
        (WebCore::XUniqueResource::get):
67
        (WebCore::XUniqueResource::release):
68
        (WebCore::XUniqueResource::reset):
69
        (WebCore::XUniqueResource::operator!):
70
        (WebCore::XUniqueResource::operator UnspecifiedBoolType*):
71
1
2015-05-05  Carlos Garcia Campos  <cgarcia@igalia.com>
72
2015-05-05  Carlos Garcia Campos  <cgarcia@igalia.com>
2
73
3
        [SOUP] Network Cache: Implement ShareableResource for Soup and enable it for GTK platform
74
        [SOUP] Network Cache: Implement ShareableResource for Soup and enable it for GTK platform
- a/Source/WebCore/PlatformEfl.cmake +1 lines
Lines 197-202 list(APPEND WebCore_SOURCES a/Source/WebCore/PlatformEfl.cmake_sec1
197
    platform/graphics/texmap/coordinated/UpdateAtlas.cpp
197
    platform/graphics/texmap/coordinated/UpdateAtlas.cpp
198
198
199
    platform/graphics/x11/PlatformDisplayX11.cpp
199
    platform/graphics/x11/PlatformDisplayX11.cpp
200
    platform/graphics/x11/XUnique.cpp
200
201
201
    platform/image-decoders/ImageDecoder.cpp
202
    platform/image-decoders/ImageDecoder.cpp
202
203
- a/Source/WebCore/PlatformGTK.cmake +1 lines
Lines 126-131 list(APPEND WebCore_SOURCES a/Source/WebCore/PlatformGTK.cmake_sec1
126
    platform/graphics/opentype/OpenTypeVerticalData.cpp
126
    platform/graphics/opentype/OpenTypeVerticalData.cpp
127
127
128
    platform/graphics/x11/PlatformDisplayX11.cpp
128
    platform/graphics/x11/PlatformDisplayX11.cpp
129
    platform/graphics/x11/XUnique.cpp
129
130
130
    platform/gtk/ErrorsGtk.cpp
131
    platform/gtk/ErrorsGtk.cpp
131
    platform/gtk/EventLoopGtk.cpp
132
    platform/gtk/EventLoopGtk.cpp
- a/Source/WebCore/platform/graphics/cairo/BackingStoreBackendCairoX11.cpp -8 / +6 lines
Lines 26-42 a/Source/WebCore/platform/graphics/cairo/BackingStoreBackendCairoX11.cpp_sec1
26
26
27
namespace WebCore {
27
namespace WebCore {
28
28
29
BackingStoreBackendCairoX11::BackingStoreBackendCairoX11(Display* display, unsigned long rootWindowID, Visual* visual, int depth, const IntSize& size, float deviceScaleFactor)
29
BackingStoreBackendCairoX11::BackingStoreBackendCairoX11(unsigned long rootWindowID, Visual* visual, int depth, const IntSize& size, float deviceScaleFactor)
30
    : BackingStoreBackendCairo(size)
30
    : BackingStoreBackendCairo(size)
31
    , m_display(display)
32
{
31
{
33
    IntSize scaledSize = size;
32
    IntSize scaledSize = size;
34
    scaledSize.scale(deviceScaleFactor);
33
    scaledSize.scale(deviceScaleFactor);
35
34
36
    m_pixmap = XCreatePixmap(m_display, rootWindowID, scaledSize.width(), scaledSize.height(), depth);
35
    auto* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
37
    m_gc = XCreateGC(m_display, m_pixmap, 0, nullptr);
36
    m_pixmap = XCreatePixmap(display, rootWindowID, scaledSize.width(), scaledSize.height(), depth);
37
    m_gc.reset(XCreateGC(display, m_pixmap.get(), 0, nullptr));
38
38
39
    m_surface = adoptRef(cairo_xlib_surface_create(m_display, m_pixmap, visual, scaledSize.width(), scaledSize.height()));
39
    m_surface = adoptRef(cairo_xlib_surface_create(display, m_pixmap.get(), visual, scaledSize.width(), scaledSize.height()));
40
    cairoSurfaceSetDeviceScale(m_surface.get(), deviceScaleFactor, deviceScaleFactor);
40
    cairoSurfaceSetDeviceScale(m_surface.get(), deviceScaleFactor, deviceScaleFactor);
41
}
41
}
42
42
Lines 44-51 BackingStoreBackendCairoX11::~BackingStoreBackendCairoX11() a/Source/WebCore/platform/graphics/cairo/BackingStoreBackendCairoX11.cpp_sec2
44
{
44
{
45
    // The pixmap needs to exist when the surface is destroyed, so begin by clearing it.
45
    // The pixmap needs to exist when the surface is destroyed, so begin by clearing it.
46
    m_surface.clear();
46
    m_surface.clear();
47
    XFreePixmap(m_display, m_pixmap);
48
    XFreeGC(m_display, m_gc);
49
}
47
}
50
48
51
void BackingStoreBackendCairoX11::scroll(const IntRect& scrollRect, const IntSize& scrollOffset)
49
void BackingStoreBackendCairoX11::scroll(const IntRect& scrollRect, const IntSize& scrollOffset)
Lines 65-71 void BackingStoreBackendCairoX11::scroll(const IntRect& scrollRect, const IntSiz a/Source/WebCore/platform/graphics/cairo/BackingStoreBackendCairoX11.cpp_sec3
65
    scaledScrollOffset.scale(xScale, yScale);
63
    scaledScrollOffset.scale(xScale, yScale);
66
64
67
    cairo_surface_flush(m_surface.get());
65
    cairo_surface_flush(m_surface.get());
68
    XCopyArea(m_display, m_pixmap, m_pixmap, m_gc,
66
    XCopyArea(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), m_pixmap.get(), m_pixmap.get(), m_gc.get(),
69
        targetRect.x() - scaledScrollOffset.width(), targetRect.y() - scaledScrollOffset.height(),
67
        targetRect.x() - scaledScrollOffset.width(), targetRect.y() - scaledScrollOffset.height(),
70
        targetRect.width(), targetRect.height(), targetRect.x(), targetRect.y());
68
        targetRect.width(), targetRect.height(), targetRect.x(), targetRect.y());
71
    cairo_surface_mark_dirty_rectangle(m_surface.get(), targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height());
69
    cairo_surface_mark_dirty_rectangle(m_surface.get(), targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height());
- a/Source/WebCore/platform/graphics/cairo/BackingStoreBackendCairoX11.h -5 / +4 lines
Lines 22-42 a/Source/WebCore/platform/graphics/cairo/BackingStoreBackendCairoX11.h_sec1
22
#include "BackingStoreBackendCairo.h"
22
#include "BackingStoreBackendCairo.h"
23
23
24
#if USE(CAIRO) && PLATFORM(X11)
24
#if USE(CAIRO) && PLATFORM(X11)
25
#include <X11/Xlib.h>
25
#include "XUnique.h"
26
26
27
namespace WebCore {
27
namespace WebCore {
28
28
29
class BackingStoreBackendCairoX11 final : public BackingStoreBackendCairo {
29
class BackingStoreBackendCairoX11 final : public BackingStoreBackendCairo {
30
public:
30
public:
31
    BackingStoreBackendCairoX11(Display*, unsigned long rootWindowID, Visual*, int depth, const IntSize&, float deviceScaleFactor);
31
    BackingStoreBackendCairoX11(unsigned long rootWindowID, Visual*, int depth, const IntSize&, float deviceScaleFactor);
32
    virtual ~BackingStoreBackendCairoX11();
32
    virtual ~BackingStoreBackendCairoX11();
33
33
34
    void scroll(const IntRect& scrollRect, const IntSize& scrollOffset) override;
34
    void scroll(const IntRect& scrollRect, const IntSize& scrollOffset) override;
35
35
36
private:
36
private:
37
    Display* m_display;
37
    XUniquePixmap m_pixmap;
38
    Pixmap m_pixmap;
38
    XUniqueGC m_gc;
39
    GC m_gc;
40
};
39
};
41
40
42
} // namespace WebCore
41
} // namespace WebCore
- a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp -79 / +44 lines
Lines 43-67 std::unique_ptr<GLContextGLX> GLContextGLX::createWindowContext(XID window, GLCo a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec1
43
    visualInfo.visualid = XVisualIDFromVisual(attributes.visual);
43
    visualInfo.visualid = XVisualIDFromVisual(attributes.visual);
44
44
45
    int numReturned = 0;
45
    int numReturned = 0;
46
    XVisualInfo* visualInfoList = XGetVisualInfo(display, VisualIDMask, &visualInfo, &numReturned);
46
    XUniquePtr<XVisualInfo> visualInfoList(XGetVisualInfo(display, VisualIDMask, &visualInfo, &numReturned));
47
48
    GLXContext glxSharingContext = sharingContext ? static_cast<GLContextGLX*>(sharingContext)->m_context : 0;
49
    GLXContext context = glXCreateContext(display, visualInfoList, glxSharingContext, True);
50
    XFree(visualInfoList);
51
47
48
    GLXContext glxSharingContext = sharingContext ? static_cast<GLContextGLX*>(sharingContext)->m_context.get() : nullptr;
49
    XUniqueGLXContext context(glXCreateContext(display, visualInfoList.get(), glxSharingContext, True));
52
    if (!context)
50
    if (!context)
53
        return nullptr;
51
        return nullptr;
54
52
55
    // GLXPbuffer and XID are both the same types underneath, so we have to share
53
    return std::make_unique<GLContextGLX>(WTF::move(context), window);
56
    // a constructor here with the window path.
57
    auto contextWrapper = std::make_unique<GLContextGLX>(context);
58
    contextWrapper->m_window = window;
59
    return WTF::move(contextWrapper);
60
}
54
}
61
55
62
std::unique_ptr<GLContextGLX> GLContextGLX::createPbufferContext(GLXContext sharingContext)
56
std::unique_ptr<GLContextGLX> GLContextGLX::createPbufferContext(GLXContext sharingContext)
63
{
57
{
64
    int fbConfigAttributes[] = {
58
    static const int fbConfigAttributes[] = {
65
        GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
59
        GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
66
        GLX_RENDER_TYPE, GLX_RGBA_BIT,
60
        GLX_RENDER_TYPE, GLX_RGBA_BIT,
67
        GLX_RED_SIZE, 1,
61
        GLX_RED_SIZE, 1,
Lines 74-105 std::unique_ptr<GLContextGLX> GLContextGLX::createPbufferContext(GLXContext shar a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec2
74
68
75
    int returnedElements;
69
    int returnedElements;
76
    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
70
    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
77
    GLXFBConfig* configs = glXChooseFBConfig(display, 0, fbConfigAttributes, &returnedElements);
71
    XUniquePtr<GLXFBConfig> configs(glXChooseFBConfig(display, 0, fbConfigAttributes, &returnedElements));
78
    if (!returnedElements) {
72
    if (!returnedElements)
79
        XFree(configs);
80
        return nullptr;
73
        return nullptr;
81
    }
82
74
83
    // We will be rendering to a texture, so our pbuffer does not need to be large.
75
    // We will be rendering to a texture, so our pbuffer does not need to be large.
84
    static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 };
76
    static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 };
85
    GLXPbuffer pbuffer = glXCreatePbuffer(display, configs[0], pbufferAttributes);
77
    XUniqueGLXPbuffer pbuffer(glXCreatePbuffer(display, configs.get()[0], pbufferAttributes));
86
    if (!pbuffer) {
78
    if (!pbuffer)
87
        XFree(configs);
88
        return nullptr;
79
        return nullptr;
89
    }
90
80
91
    GLXContext context = glXCreateNewContext(display, configs[0], GLX_RGBA_TYPE, sharingContext, GL_TRUE);
81
    XUniqueGLXContext context(glXCreateNewContext(display, configs.get()[0], GLX_RGBA_TYPE, sharingContext, GL_TRUE));
92
    XFree(configs);
82
    if (!context)
93
    if (!context) {
94
        glXDestroyPbuffer(display, pbuffer);
95
        return nullptr;
83
        return nullptr;
96
    }
97
84
98
    // GLXPbuffer and XID are both the same types underneath, so we have to share
85
    return std::make_unique<GLContextGLX>(WTF::move(context), WTF::move(pbuffer));
99
    // a constructor here with the window path.
100
    auto contextWrapper = std::make_unique<GLContextGLX>(context);
101
    contextWrapper->m_pbuffer = pbuffer;
102
    return WTF::move(contextWrapper);
103
}
86
}
104
87
105
std::unique_ptr<GLContextGLX> GLContextGLX::createPixmapContext(GLXContext sharingContext)
88
std::unique_ptr<GLContextGLX> GLContextGLX::createPixmapContext(GLXContext sharingContext)
Lines 114-144 std::unique_ptr<GLContextGLX> GLContextGLX::createPixmapContext(GLXContext shari a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec3
114
    };
97
    };
115
98
116
    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
99
    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
117
    XVisualInfo* visualInfo = glXChooseVisual(display, DefaultScreen(display), visualAttributes);
100
    XUniquePtr<XVisualInfo> visualInfo(glXChooseVisual(display, DefaultScreen(display), visualAttributes));
118
    if (!visualInfo)
101
    if (!visualInfo)
119
        return nullptr;
102
        return nullptr;
120
103
121
    GLXContext context = glXCreateContext(display, visualInfo, sharingContext, GL_TRUE);
104
    XUniqueGLXContext context(glXCreateContext(display, visualInfo.get(), sharingContext, GL_TRUE));
122
    if (!context) {
105
    if (!context)
123
        XFree(visualInfo);
124
        return nullptr;
106
        return nullptr;
125
    }
126
107
127
    Pixmap pixmap = XCreatePixmap(display, DefaultRootWindow(display), 1, 1, visualInfo->depth);
108
    XUniquePixmap pixmap(XCreatePixmap(display, DefaultRootWindow(display), 1, 1, visualInfo->depth));
128
    if (!pixmap) {
109
    if (!pixmap)
129
        XFree(visualInfo);
130
        return nullptr;
110
        return nullptr;
131
    }
132
111
133
    GLXPixmap glxPixmap = glXCreateGLXPixmap(display, visualInfo, pixmap);
112
    XUniqueGLXPixmap glxPixmap(glXCreateGLXPixmap(display, visualInfo.get(), pixmap.get()));
134
    if (!glxPixmap) {
113
    if (!glxPixmap)
135
        XFreePixmap(display, pixmap);
136
        XFree(visualInfo);
137
        return nullptr;
114
        return nullptr;
138
    }
139
115
140
    XFree(visualInfo);
116
    return std::make_unique<GLContextGLX>(WTF::move(context), WTF::move(pixmap), WTF::move(glxPixmap));
141
    return std::make_unique<GLContextGLX>(context, pixmap, glxPixmap);
142
}
117
}
143
118
144
std::unique_ptr<GLContextGLX> GLContextGLX::createContext(XID window, GLContext* sharingContext)
119
std::unique_ptr<GLContextGLX> GLContextGLX::createContext(XID window, GLContext* sharingContext)
Lines 152-158 std::unique_ptr<GLContextGLX> GLContextGLX::createContext(XID window, GLContext* a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec4
152
    if (!success)
127
    if (!success)
153
        return nullptr;
128
        return nullptr;
154
129
155
    GLXContext glxSharingContext = sharingContext ? static_cast<GLContextGLX*>(sharingContext)->m_context : 0;
130
    GLXContext glxSharingContext = sharingContext ? static_cast<GLContextGLX*>(sharingContext)->m_context.get() : nullptr;
156
    auto context = window ? createWindowContext(window, sharingContext) : nullptr;
131
    auto context = window ? createWindowContext(window, sharingContext) : nullptr;
157
    if (!context)
132
    if (!context)
158
        context = createPbufferContext(glxSharingContext);
133
        context = createPbufferContext(glxSharingContext);
Lines 164-186 std::unique_ptr<GLContextGLX> GLContextGLX::createContext(XID window, GLContext* a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec5
164
    return WTF::move(context);
139
    return WTF::move(context);
165
}
140
}
166
141
167
GLContextGLX::GLContextGLX(GLXContext context)
142
GLContextGLX::GLContextGLX(XUniqueGLXContext&& context, XID window)
168
    : m_context(context)
143
    : m_context(WTF::move(context))
144
    , m_window(window)
145
    , m_cairoDevice(nullptr)
146
{
147
}
148
149
GLContextGLX::GLContextGLX(XUniqueGLXContext&& context, XUniqueGLXPbuffer&& pbuffer)
150
    : m_context(WTF::move(context))
169
    , m_window(0)
151
    , m_window(0)
170
    , m_pbuffer(0)
152
    , m_pbuffer(WTF::move(pbuffer))
171
    , m_pixmap(0)
153
    , m_cairoDevice(nullptr)
172
    , m_glxPixmap(0)
173
    , m_cairoDevice(0)
174
{
154
{
175
}
155
}
176
156
177
GLContextGLX::GLContextGLX(GLXContext context, Pixmap pixmap, GLXPixmap glxPixmap)
157
GLContextGLX::GLContextGLX(XUniqueGLXContext&& context, XUniquePixmap&& pixmap, XUniqueGLXPixmap&& glxPixmap)
178
    : m_context(context)
158
    : m_context(WTF::move(context))
179
    , m_window(0)
159
    , m_window(0)
180
    , m_pbuffer(0)
160
    , m_pixmap(WTF::move(pixmap))
181
    , m_pixmap(pixmap)
161
    , m_glxPixmap(WTF::move(glxPixmap))
182
    , m_glxPixmap(glxPixmap)
162
    , m_cairoDevice(nullptr)
183
    , m_cairoDevice(0)
184
{
163
{
185
}
164
}
186
165
Lines 189-214 GLContextGLX::~GLContextGLX() a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec6
189
    if (m_cairoDevice)
168
    if (m_cairoDevice)
190
        cairo_device_destroy(m_cairoDevice);
169
        cairo_device_destroy(m_cairoDevice);
191
170
192
    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
193
    if (m_context) {
171
    if (m_context) {
194
        // This may be necessary to prevent crashes with NVidia's closed source drivers. Originally
172
        // This may be necessary to prevent crashes with NVidia's closed source drivers. Originally
195
        // from Mozilla's 3D canvas implementation at: http://bitbucket.org/ilmari/canvas3d/
173
        // from Mozilla's 3D canvas implementation at: http://bitbucket.org/ilmari/canvas3d/
174
        Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
196
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
175
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
197
        glXMakeCurrent(display, None, None);
176
        glXMakeCurrent(display, None, None);
198
        glXDestroyContext(display, m_context);
199
    }
200
201
    if (m_pbuffer) {
202
        glXDestroyPbuffer(display, m_pbuffer);
203
        m_pbuffer = 0;
204
    }
205
    if (m_glxPixmap) {
206
        glXDestroyGLXPixmap(display, m_glxPixmap);
207
        m_glxPixmap = 0;
208
    }
209
    if (m_pixmap) {
210
        XFreePixmap(display, m_pixmap);
211
        m_pixmap = 0;
212
    }
177
    }
213
}
178
}
214
179
Lines 237-253 bool GLContextGLX::makeContextCurrent() a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec7
237
    ASSERT(m_context && (m_window || m_pbuffer || m_glxPixmap));
202
    ASSERT(m_context && (m_window || m_pbuffer || m_glxPixmap));
238
203
239
    GLContext::makeContextCurrent();
204
    GLContext::makeContextCurrent();
240
    if (glXGetCurrentContext() == m_context)
205
    if (glXGetCurrentContext() == m_context.get())
241
        return true;
206
        return true;
242
207
243
    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
208
    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
244
    if (m_window)
209
    if (m_window)
245
        return glXMakeCurrent(display, m_window, m_context);
210
        return glXMakeCurrent(display, m_window, m_context.get());
246
211
247
    if (m_pbuffer)
212
    if (m_pbuffer)
248
        return glXMakeCurrent(display, m_pbuffer, m_context);
213
        return glXMakeCurrent(display, m_pbuffer.get(), m_context.get());
249
214
250
    return ::glXMakeCurrent(display, m_glxPixmap, m_context);
215
    return ::glXMakeCurrent(display, m_glxPixmap.get(), m_context.get());
251
}
216
}
252
217
253
void GLContextGLX::swapBuffers()
218
void GLContextGLX::swapBuffers()
Lines 267-273 cairo_device_t* GLContextGLX::cairoDevice() a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec8
267
        return m_cairoDevice;
232
        return m_cairoDevice;
268
233
269
#if ENABLE(ACCELERATED_2D_CANVAS)
234
#if ENABLE(ACCELERATED_2D_CANVAS)
270
    m_cairoDevice = cairo_glx_device_create(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), m_context);
235
    m_cairoDevice = cairo_glx_device_create(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), m_context.get());
271
#endif
236
#endif
272
237
273
    return m_cairoDevice;
238
    return m_cairoDevice;
Lines 276-282 cairo_device_t* GLContextGLX::cairoDevice() a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec9
276
#if ENABLE(GRAPHICS_CONTEXT_3D)
241
#if ENABLE(GRAPHICS_CONTEXT_3D)
277
PlatformGraphicsContext3D GLContextGLX::platformContext()
242
PlatformGraphicsContext3D GLContextGLX::platformContext()
278
{
243
{
279
    return m_context;
244
    return m_context.get();
280
}
245
}
281
#endif
246
#endif
282
247
- a/Source/WebCore/platform/graphics/glx/GLContextGLX.h -10 / +8 lines
Lines 23-34 a/Source/WebCore/platform/graphics/glx/GLContextGLX.h_sec1
23
#if USE(GLX)
23
#if USE(GLX)
24
24
25
#include "GLContext.h"
25
#include "GLContext.h"
26
#include "XUnique.h"
26
27
27
typedef struct __GLXcontextRec* GLXContext;
28
typedef unsigned long GLXPbuffer;
29
typedef unsigned long GLXPixmap;
30
typedef unsigned char GLubyte;
28
typedef unsigned char GLubyte;
31
typedef unsigned long Pixmap;
32
typedef unsigned long XID;
29
typedef unsigned long XID;
33
typedef void* ContextKeyType;
30
typedef void* ContextKeyType;
34
31
Lines 40-47 public: a/Source/WebCore/platform/graphics/glx/GLContextGLX.h_sec2
40
    static std::unique_ptr<GLContextGLX> createContext(XID window, GLContext* sharingContext);
37
    static std::unique_ptr<GLContextGLX> createContext(XID window, GLContext* sharingContext);
41
    static std::unique_ptr<GLContextGLX> createWindowContext(XID window, GLContext* sharingContext);
38
    static std::unique_ptr<GLContextGLX> createWindowContext(XID window, GLContext* sharingContext);
42
39
43
    GLContextGLX(GLXContext);
40
    GLContextGLX(XUniqueGLXContext&&, XID);
44
    GLContextGLX(GLXContext, Pixmap, GLXPixmap);
41
    GLContextGLX(XUniqueGLXContext&&, XUniqueGLXPbuffer&&);
42
    GLContextGLX(XUniqueGLXContext&&, XUniquePixmap&&, XUniqueGLXPixmap&&);
45
    virtual ~GLContextGLX();
43
    virtual ~GLContextGLX();
46
    virtual bool makeContextCurrent();
44
    virtual bool makeContextCurrent();
47
    virtual void swapBuffers();
45
    virtual void swapBuffers();
Lines 59-69 private: a/Source/WebCore/platform/graphics/glx/GLContextGLX.h_sec3
59
    static std::unique_ptr<GLContextGLX> createPbufferContext(GLXContext sharingContext);
57
    static std::unique_ptr<GLContextGLX> createPbufferContext(GLXContext sharingContext);
60
    static std::unique_ptr<GLContextGLX> createPixmapContext(GLXContext sharingContext);
58
    static std::unique_ptr<GLContextGLX> createPixmapContext(GLXContext sharingContext);
61
59
62
    GLXContext m_context;
60
    XUniqueGLXContext m_context;
63
    XID m_window;
61
    XID m_window;
64
    GLXPbuffer m_pbuffer;
62
    XUniqueGLXPbuffer m_pbuffer;
65
    Pixmap m_pixmap;
63
    XUniquePixmap m_pixmap;
66
    GLXPixmap m_glxPixmap;
64
    XUniqueGLXPixmap m_glxPixmap;
67
    cairo_device_t* m_cairoDevice;
65
    cairo_device_t* m_cairoDevice;
68
};
66
};
69
67
- a/Source/WebCore/platform/graphics/surfaces/egl/EGLXSurface.cpp -11 / +3 lines
Lines 141-147 void EGLPixmapSurface::destroy() a/Source/WebCore/platform/graphics/surfaces/egl/EGLXSurface.cpp_sec1
141
141
142
EGLXTransportSurfaceClient::EGLXTransportSurfaceClient(const PlatformBufferHandle handle, const IntSize& size, bool hasAlpha)
142
EGLXTransportSurfaceClient::EGLXTransportSurfaceClient(const PlatformBufferHandle handle, const IntSize& size, bool hasAlpha)
143
    : GLTransportSurfaceClient()
143
    : GLTransportSurfaceClient()
144
    , m_image(0)
145
    , m_size(size)
144
    , m_size(size)
146
    , m_totalBytes(0)
145
    , m_totalBytes(0)
147
{
146
{
Lines 197-207 void EGLXTransportSurfaceClient::destroy() a/Source/WebCore/platform/graphics/surfaces/egl/EGLXSurface.cpp_sec2
197
    }
196
    }
198
197
199
    eglWaitGL();
198
    eglWaitGL();
200
199
    m_image.reset();
201
    if (m_image) {
202
        XDestroyImage(m_image);
203
        m_image = 0;
204
    }
205
}
200
}
206
201
207
void EGLXTransportSurfaceClient::prepareTexture()
202
void EGLXTransportSurfaceClient::prepareTexture()
Lines 214-220 void EGLXTransportSurfaceClient::prepareTexture() a/Source/WebCore/platform/graphics/surfaces/egl/EGLXSurface.cpp_sec3
214
    }
209
    }
215
210
216
    // Fallback to use XImage in case EGLImage and TextureToPixmap are not supported.
211
    // Fallback to use XImage in case EGLImage and TextureToPixmap are not supported.
217
    m_image = XGetImage(NativeWrapper::nativeDisplay(), m_handle, 0, 0, m_size.width(), m_size.height(), AllPlanes, ZPixmap);
212
    m_image.reset(XGetImage(NativeWrapper::nativeDisplay(), m_handle, 0, 0, m_size.width(), m_size.height(), AllPlanes, ZPixmap));
218
213
219
#if USE(OPENGL_ES_2)
214
#if USE(OPENGL_ES_2)
220
    if (m_format != GraphicsContext3D::BGRA) {
215
    if (m_format != GraphicsContext3D::BGRA) {
Lines 225-234 void EGLXTransportSurfaceClient::prepareTexture() a/Source/WebCore/platform/graphics/surfaces/egl/EGLXSurface.cpp_sec4
225
220
226
    glTexImage2D(GL_TEXTURE_2D, 0, m_format, m_size.width(), m_size.height(), 0, m_format, GL_UNSIGNED_BYTE, m_image->data);
221
    glTexImage2D(GL_TEXTURE_2D, 0, m_format, m_size.width(), m_size.height(), 0, m_format, GL_UNSIGNED_BYTE, m_image->data);
227
222
228
    if (m_image) {
223
    m_image.reset();
229
        XDestroyImage(m_image);
230
        m_image = 0;
231
    }
232
}
224
}
233
225
234
EGLTextureFromPixmap::EGLTextureFromPixmap(const NativePixmap handle, bool hasAlpha, EGLConfig config)
226
EGLTextureFromPixmap::EGLTextureFromPixmap(const NativePixmap handle, bool hasAlpha, EGLConfig config)
- a/Source/WebCore/platform/graphics/surfaces/egl/EGLXSurface.h -1 / +2 lines
Lines 29-34 a/Source/WebCore/platform/graphics/surfaces/egl/EGLXSurface.h_sec1
29
#if PLATFORM(X11) && USE(EGL) && USE(GRAPHICS_SURFACE)
29
#if PLATFORM(X11) && USE(EGL) && USE(GRAPHICS_SURFACE)
30
30
31
#include "EGLSurface.h"
31
#include "EGLSurface.h"
32
#include "XUnique.h"
32
#include <glx/X11Helper.h>
33
#include <glx/X11Helper.h>
33
34
34
namespace WebCore {
35
namespace WebCore {
Lines 74-80 public: a/Source/WebCore/platform/graphics/surfaces/egl/EGLXSurface.h_sec2
74
    virtual void destroy() override;
75
    virtual void destroy() override;
75
76
76
private:
77
private:
77
    XImage* m_image;
78
    XUnique<XImage> m_image;
78
    IntSize m_size;
79
    IntSize m_size;
79
    PlatformBufferHandle m_handle;
80
    PlatformBufferHandle m_handle;
80
    GLuint m_format;
81
    GLuint m_format;
- a/Source/WebCore/platform/graphics/surfaces/glx/GLXConfigSelector.h -10 / +11 lines
Lines 29-34 a/Source/WebCore/platform/graphics/surfaces/glx/GLXConfigSelector.h_sec1
29
#if USE(GLX)
29
#if USE(GLX)
30
30
31
#include "X11Helper.h"
31
#include "X11Helper.h"
32
#include "XUnique.h"
32
#include <opengl/GLDefs.h>
33
#include <opengl/GLDefs.h>
33
#include <opengl/GLPlatformSurface.h>
34
#include <opengl/GLPlatformSurface.h>
34
35
Lines 140-152 private: a/Source/WebCore/platform/graphics/surfaces/glx/GLXConfigSelector.h_sec2
140
    GLXFBConfig findMatchingConfig(const int attributes[], int depth = 32)
141
    GLXFBConfig findMatchingConfig(const int attributes[], int depth = 32)
141
    {
142
    {
142
        int numAvailableConfigs;
143
        int numAvailableConfigs;
143
        std::unique_ptr<GLXFBConfig[], X11Deleter> temp(glXChooseFBConfig(X11Helper::nativeDisplay(), DefaultScreen(X11Helper::nativeDisplay()), attributes, &numAvailableConfigs));
144
        XUniquePtr<GLXFBConfig> temp(glXChooseFBConfig(X11Helper::nativeDisplay(), DefaultScreen(X11Helper::nativeDisplay()), attributes, &numAvailableConfigs));
144
145
145
        if (!numAvailableConfigs || !temp.get())
146
        if (!numAvailableConfigs || !temp.get())
146
            return 0;
147
            return 0;
147
148
148
        for (int i = 0; i < numAvailableConfigs; ++i) {
149
        for (int i = 0; i < numAvailableConfigs; ++i) {
149
            std::unique_ptr<XVisualInfo, X11Deleter> scopedVisualInfo { glXGetVisualFromFBConfig(X11Helper::nativeDisplay(), temp[i]) };
150
            XUniquePtr<XVisualInfo> scopedVisualInfo { glXGetVisualFromFBConfig(X11Helper::nativeDisplay(), temp.get()[i]) };
150
            if (!scopedVisualInfo.get())
151
            if (!scopedVisualInfo.get())
151
                continue;
152
                continue;
152
153
Lines 157-196 private: a/Source/WebCore/platform/graphics/surfaces/glx/GLXConfigSelector.h_sec3
157
                if (format) {
158
                if (format) {
158
                    if (m_attributes & GLPlatformSurface::SupportAlpha) {
159
                    if (m_attributes & GLPlatformSurface::SupportAlpha) {
159
                        if (scopedVisualInfo->depth == depth && format->direct.alphaMask > 0)
160
                        if (scopedVisualInfo->depth == depth && format->direct.alphaMask > 0)
160
                            return temp[i];
161
                            return temp.get()[i];
161
                    } else if (!format->direct.alphaMask)
162
                    } else if (!format->direct.alphaMask)
162
                        return temp[i];
163
                        return temp.get()[i];
163
                }
164
                }
164
            }
165
            }
165
#endif
166
#endif
166
            if (scopedVisualInfo->depth == depth)
167
            if (scopedVisualInfo->depth == depth)
167
                return temp[i];
168
                return temp.get()[i];
168
        }
169
        }
169
170
170
        // Did not find any visual supporting alpha, select the first available config.
171
        // Did not find any visual supporting alpha, select the first available config.
171
        std::unique_ptr<XVisualInfo, X11Deleter> scopedVisualInfo { glXGetVisualFromFBConfig(X11Helper::nativeDisplay(), temp[0]) };
172
        XUniquePtr<XVisualInfo> scopedVisualInfo { glXGetVisualFromFBConfig(X11Helper::nativeDisplay(), temp.get()[0]) };
172
173
173
        if ((m_attributes & GLPlatformSurface::SupportAlpha) && (scopedVisualInfo->depth != 32))
174
        if ((m_attributes & GLPlatformSurface::SupportAlpha) && (scopedVisualInfo->depth != 32))
174
            m_attributes &= ~GLPlatformSurface::SupportAlpha;
175
            m_attributes &= ~GLPlatformSurface::SupportAlpha;
175
176
176
        return temp[0];
177
        return temp.get()[0];
177
    }
178
    }
178
179
179
    GLXFBConfig findMatchingConfigWithVisualId(const int attributes[], int depth, VisualID id)
180
    GLXFBConfig findMatchingConfigWithVisualId(const int attributes[], int depth, VisualID id)
180
    {
181
    {
181
        int numAvailableConfigs;
182
        int numAvailableConfigs;
182
        std::unique_ptr<GLXFBConfig[], X11Deleter> temp(glXChooseFBConfig(X11Helper::nativeDisplay(), DefaultScreen(X11Helper::nativeDisplay()), attributes, &numAvailableConfigs));
183
        XUniquePtr<GLXFBConfig> temp(glXChooseFBConfig(X11Helper::nativeDisplay(), DefaultScreen(X11Helper::nativeDisplay()), attributes, &numAvailableConfigs));
183
184
184
        if (!numAvailableConfigs || !temp.get())
185
        if (!numAvailableConfigs || !temp.get())
185
            return 0;
186
            return 0;
186
187
187
        for (int i = 0; i < numAvailableConfigs; ++i) {
188
        for (int i = 0; i < numAvailableConfigs; ++i) {
188
            std::unique_ptr<XVisualInfo, X11Deleter> scopedVisualInfo { glXGetVisualFromFBConfig(X11Helper::nativeDisplay(), temp[i]) };
189
            XUniquePtr<XVisualInfo> scopedVisualInfo { glXGetVisualFromFBConfig(X11Helper::nativeDisplay(), temp.get()[i]) };
189
            if (!scopedVisualInfo.get())
190
            if (!scopedVisualInfo.get())
190
                continue;
191
                continue;
191
192
192
            if (id && scopedVisualInfo->depth == depth && scopedVisualInfo->visualid == id)
193
            if (id && scopedVisualInfo->depth == depth && scopedVisualInfo->visualid == id)
193
                return temp[i];
194
                return temp.get()[i];
194
        }
195
        }
195
196
196
        return 0;
197
        return 0;
- a/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp -2 / +4 lines
Lines 28-33 a/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp_sec1
28
28
29
#if USE(GLX)
29
#if USE(GLX)
30
30
31
#include "XUnique.h"
32
31
namespace WebCore {
33
namespace WebCore {
32
34
33
static PFNGLXBINDTEXIMAGEEXTPROC pGlXBindTexImageEXT = 0;
35
static PFNGLXBINDTEXIMAGEEXTPROC pGlXBindTexImageEXT = 0;
Lines 66-72 GLXTransportSurface::GLXTransportSurface(const IntSize& size, SurfaceAttributes a/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp_sec2
66
{
68
{
67
    attributes |= GLPlatformSurface::DoubleBuffered;
69
    attributes |= GLPlatformSurface::DoubleBuffered;
68
    m_configSelector = std::make_unique<GLXConfigSelector>(attributes);
70
    m_configSelector = std::make_unique<GLXConfigSelector>(attributes);
69
    std::unique_ptr<XVisualInfo, X11Deleter> visInfo(m_configSelector->visualInfo(m_configSelector->surfaceContextConfig()));
71
    XUniquePtr<XVisualInfo> visInfo(m_configSelector->visualInfo(m_configSelector->surfaceContextConfig()));
70
72
71
    if (!visInfo.get()) {
73
    if (!visInfo.get()) {
72
        destroy();
74
        destroy();
Lines 142-148 void GLXOffScreenSurface::initialize(SurfaceAttributes attributes) a/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp_sec3
142
{
144
{
143
    m_configSelector = std::make_unique<GLXConfigSelector>(attributes);
145
    m_configSelector = std::make_unique<GLXConfigSelector>(attributes);
144
146
145
    std::unique_ptr<XVisualInfo, X11Deleter> visualInfo(m_configSelector->visualInfo(m_configSelector->pixmapContextConfig()));
147
    XUniquePtr<XVisualInfo> visualInfo(m_configSelector->visualInfo(m_configSelector->pixmapContextConfig()));
146
    X11Helper::createPixmap(&m_pixmap, *visualInfo.get());
148
    X11Helper::createPixmap(&m_pixmap, *visualInfo.get());
147
149
148
    if (!m_pixmap) {
150
    if (!m_pixmap) {
- a/Source/WebCore/platform/graphics/surfaces/glx/X11Helper.cpp -2 / +3 lines
Lines 27-32 a/Source/WebCore/platform/graphics/surfaces/glx/X11Helper.cpp_sec1
27
#include "X11Helper.h"
27
#include "X11Helper.h"
28
28
29
#include "PlatformDisplayX11.h"
29
#include "PlatformDisplayX11.h"
30
#include "XUnique.h"
30
31
31
namespace WebCore {
32
namespace WebCore {
32
33
Lines 223-229 void X11Helper::createOffScreenWindow(uint32_t* handleId, const EGLint id, bool a/Source/WebCore/platform/graphics/surfaces/glx/X11Helper.cpp_sec2
223
    memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
224
    memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
224
    visualInfoTemplate.visualid = visualId;
225
    visualInfoTemplate.visualid = visualId;
225
    int matchingCount = 0;
226
    int matchingCount = 0;
226
    std::unique_ptr<XVisualInfo, X11Deleter> matchingVisuals(XGetVisualInfo(nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount));
227
    XUnique<XVisualInfo> matchingVisuals(XGetVisualInfo(nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount));
227
    XVisualInfo* foundVisual = 0;
228
    XVisualInfo* foundVisual = 0;
228
229
229
    if (matchingVisuals) {
230
    if (matchingVisuals) {
Lines 260-266 void X11Helper::createPixmap(Pixmap* handleId, const EGLint id, bool hasAlpha, c a/Source/WebCore/platform/graphics/surfaces/glx/X11Helper.cpp_sec3
260
    memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
261
    memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
261
    visualInfoTemplate.visualid = visualId;
262
    visualInfoTemplate.visualid = visualId;
262
    int matchingCount = 0;
263
    int matchingCount = 0;
263
    std::unique_ptr<XVisualInfo, X11Deleter> matchingVisuals(XGetVisualInfo(nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount));
264
    XUnique<XVisualInfo> matchingVisuals(XGetVisualInfo(nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount));
264
    XVisualInfo* foundVisual = 0;
265
    XVisualInfo* foundVisual = 0;
265
    int requiredDepth = hasAlpha ? 32 : 24;
266
    int requiredDepth = hasAlpha ? 32 : 24;
266
267
- a/Source/WebCore/platform/graphics/surfaces/glx/X11Helper.h -9 lines
Lines 42-56 a/Source/WebCore/platform/graphics/surfaces/glx/X11Helper.h_sec1
42
42
43
namespace WebCore {
43
namespace WebCore {
44
44
45
class X11Deleter {
46
public:
47
    template<typename T> void operator()(T* resource)
48
    {
49
        if (resource)
50
            XFree(resource);
51
    }
52
};
53
54
class X11Helper {
45
class X11Helper {
55
public:
46
public:
56
    static void createPixmap(Pixmap*, const XVisualInfo&, const IntSize& = IntSize(1, 1));
47
    static void createPixmap(Pixmap*, const XVisualInfo&, const IntSize& = IntSize(1, 1));
- a/Source/WebCore/platform/graphics/x11/XUnique.cpp +84 lines
Line 0 a/Source/WebCore/platform/graphics/x11/XUnique.cpp_sec1
1
/*
2
 * Copyright (C) 2015 Igalia S.L
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
 *
8
 * 1.  Redistributions of source code must retain the above copyright
9
 *     notice, this list of conditions and the following disclaimer.
10
 * 2.  Redistributions in binary form must reproduce the above copyright
11
 *     notice, this list of conditions and the following disclaimer in the
12
 *     documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#include "config.h"
27
#include "XUnique.h"
28
29
#if PLATFORM(X11)
30
#include <X11/Xlib.h>
31
32
#if PLATFORM(GTK)
33
#include <X11/extensions/Xdamage.h>
34
#endif
35
36
#if USE(GLX)
37
#include <GL/glx.h>
38
#endif
39
40
namespace WebCore {
41
42
template<> void XUniqueResource<XResource::Colormap>::deleteXResource(long unsigned resource)
43
{
44
    if (resource)
45
        XFreeColormap(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), resource);
46
}
47
48
#if PLATFORM(GTK)
49
template <> void XUniqueResource<XResource::Damage>::deleteXResource(long unsigned resource)
50
{
51
    if (resource)
52
        XDamageDestroy(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), resource);
53
}
54
#endif
55
56
template <> void XUniqueResource<XResource::Pixmap>::deleteXResource(long unsigned resource)
57
{
58
    if (resource)
59
        XFreePixmap(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), resource);
60
}
61
62
template <> void XUniqueResource<XResource::Window>::deleteXResource(long unsigned resource)
63
{
64
    if (resource)
65
        XDestroyWindow(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), resource);
66
}
67
68
#if USE(GLX)
69
template<> void XUniqueResource<XResource::GLXPbuffer>::deleteXResource(long unsigned resource)
70
{
71
    if (resource)
72
        glXDestroyPbuffer(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), resource);
73
}
74
75
template<> void XUniqueResource<XResource::GLXPixmap>::deleteXResource(long unsigned resource)
76
{
77
    if (resource)
78
        glXDestroyGLXPixmap(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), resource);
79
}
80
#endif // USE(GLX)
81
82
} // namespace WebCore
83
84
#endif // PLATFORM(X11)
- a/Source/WebCore/platform/graphics/x11/XUnique.h +170 lines
Line 0 a/Source/WebCore/platform/graphics/x11/XUnique.h_sec1
1
/*
2
 * Copyright (C) 2015 Igalia S.L
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
 *
8
 * 1.  Redistributions of source code must retain the above copyright
9
 *     notice, this list of conditions and the following disclaimer.
10
 * 2.  Redistributions in binary form must reproduce the above copyright
11
 *     notice, this list of conditions and the following disclaimer in the
12
 *     documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#ifndef XUnique_h
27
#define XUnique_h
28
29
#if PLATFORM(X11)
30
#include "PlatformDisplayX11.h"
31
#include <X11/Xutil.h>
32
33
#if USE(GLX)
34
typedef struct __GLXcontextRec* GLXContext;
35
typedef unsigned long GLXPbuffer;
36
typedef unsigned long GLXPixmap;
37
38
extern "C" void glXDestroyContext(Display*, GLXContext);
39
#endif
40
41
namespace WebCore {
42
43
template<typename T>
44
struct XPtrDeleter {
45
    void operator()(T* ptr) const { XFree(ptr); }
46
};
47
48
template<typename T>
49
using XUniquePtr = std::unique_ptr<T, XPtrDeleter<T>>;
50
51
#define DEFINE_XPTR_DELETER(typeName, deleterFunc) \
52
    template<> struct XPtrDeleter<typeName> \
53
    { \
54
        void operator() (typeName* ptr) const \
55
        { \
56
            if (ptr) \
57
                deleterFunc(ptr); \
58
        } \
59
    };
60
61
#define DEFINE_XPTR_DELETER_WITH_DISPLAY(typeName, deleterFunc) \
62
    template<> struct XPtrDeleter<typeName> \
63
    { \
64
        void operator() (typeName* ptr) const \
65
        { \
66
            if (ptr) \
67
                deleterFunc(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), ptr); \
68
        } \
69
    };
70
71
72
DEFINE_XPTR_DELETER(XImage, XDestroyImage)
73
DEFINE_XPTR_DELETER_WITH_DISPLAY(_XGC, XFreeGC)
74
75
#if USE(GLX)
76
DEFINE_XPTR_DELETER_WITH_DISPLAY(__GLXcontextRec, glXDestroyContext)
77
#endif
78
79
#undef DEFINE_XPTR_DELETER
80
#undef DEFINE_XPTR_DELETER_WITH_DISPLAY
81
82
enum class XResource {
83
    Colormap,
84
#if PLATFORM(GTK)
85
    Damage,
86
#endif
87
    Pixmap,
88
    Window,
89
#if USE(GLX)
90
    GLXPbuffer,
91
    GLXPixmap,
92
#endif
93
};
94
95
template <XResource T> class XUniqueResource {
96
public:
97
    XUniqueResource()
98
        : m_resource(0)
99
    {
100
    }
101
102
    XUniqueResource(long unsigned resource)
103
        : m_resource(resource)
104
    {
105
    }
106
107
    XUniqueResource(XUniqueResource&& uniqueResource)
108
        : m_resource(uniqueResource.release())
109
    {
110
    }
111
112
    XUniqueResource& operator=(XUniqueResource&& uniqueResource)
113
    {
114
        reset(uniqueResource.release());
115
        return *this;
116
    }
117
118
    ~XUniqueResource()
119
    {
120
        reset();
121
    }
122
123
    long unsigned get() const { return m_resource; }
124
    long unsigned release() { long unsigned resource = m_resource; m_resource = 0; return resource; }
125
126
    void reset(long unsigned resource = 0)
127
    {
128
        std::swap(m_resource, resource);
129
        deleteXResource(resource);
130
    }
131
132
    bool operator!() const { return !m_resource; }
133
134
    // This conversion operator allows implicit conversion to bool but not to other integer types.
135
    typedef void* (XUniqueResource::*UnspecifiedBoolType);
136
    operator UnspecifiedBoolType*() const
137
    {
138
        return m_resource ? reinterpret_cast<UnspecifiedBoolType*>(1) : 0;
139
    }
140
141
    XUniqueResource(const XUniqueResource&) = delete;
142
    XUniqueResource& operator=(const XUniqueResource&) = delete;
143
private:
144
    static void deleteXResource(long unsigned resource);
145
146
    long unsigned m_resource;
147
};
148
149
typedef XUniqueResource<XResource::Colormap> XUniqueColormap;
150
#if PLATFORM(GTK)
151
typedef XUniqueResource<XResource::Damage> XUniqueDamage;
152
#endif
153
typedef XUniqueResource<XResource::Pixmap> XUniquePixmap;
154
typedef XUniqueResource<XResource::Window> XUniqueWindow;
155
#if USE(GLX)
156
typedef XUniqueResource<XResource::GLXPbuffer> XUniqueGLXPbuffer;
157
typedef XUniqueResource<XResource::GLXPixmap> XUniqueGLXPixmap;
158
#endif
159
160
// Give a name also to these XUniquePtr to avoid having to use the internal struct names (_XGC, __GLXcontextRec, ...).
161
typedef XUniquePtr<_XGC> XUniqueGC;
162
#if USE(GLX)
163
typedef XUniquePtr<__GLXcontextRec> XUniqueGLXContext;
164
#endif
165
166
} // namespace WebCore
167
168
#endif // PLATFORM(X11)
169
170
#endif // XUnique_h
- a/Source/WebKit2/ChangeLog +30 lines
Lines 1-3 a/Source/WebKit2/ChangeLog_sec1
1
2015-05-02  Carlos Garcia Campos  <cgarcia@igalia.com>
2
3
        [X11] Add XUniquePtr and XUniqueResource to automatically free X resources
4
        https://bugs.webkit.org/show_bug.cgi?id=144521
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Use XUniquePtr and XUniqueResource to free X resources.
9
10
        * PlatformEfl.cmake: Add Source/WebCore/platform/graphics/x11 dir
11
        to the include dir list.
12
        * PlatformGTK.cmake: Ditto.
13
        * UIProcess/cairo/BackingStoreCairo.cpp:
14
        (WebKit::BackingStore::createBackend): Do not pass the display to
15
        the BackingStoreBackendCairoX11 constructor.
16
        * UIProcess/gtk/RedirectedXCompositeWindow.cpp:
17
        (WebKit::RedirectedXCompositeWindow::RedirectedXCompositeWindow):
18
        (WebKit::RedirectedXCompositeWindow::~RedirectedXCompositeWindow):
19
        (WebKit::RedirectedXCompositeWindow::resize):
20
        (WebKit::RedirectedXCompositeWindow::cleanupPixmapAndPixmapSurface):
21
        (WebKit::RedirectedXCompositeWindow::surface):
22
        * UIProcess/gtk/RedirectedXCompositeWindow.h:
23
        (WebKit::RedirectedXCompositeWindow::windowID):
24
        * WebProcess/Plugins/Netscape/NetscapePlugin.h:
25
        * WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp:
26
        (WebKit::NetscapePlugin::platformPostInitializeWindowless):
27
        (WebKit::NetscapePlugin::platformDestroy):
28
        (WebKit::NetscapePlugin::platformGeometryDidChange):
29
        (WebKit::NetscapePlugin::platformPaint):
30
1
2015-05-05  Carlos Garcia Campos  <cgarcia@igalia.com>
31
2015-05-05  Carlos Garcia Campos  <cgarcia@igalia.com>
2
32
3
        [SOUP] Network Cache: Implement ShareableResource for Soup and enable it for GTK platform
33
        [SOUP] Network Cache: Implement ShareableResource for Soup and enable it for GTK platform
- a/Source/WebKit2/PlatformEfl.cmake +1 lines
Lines 226-231 list(APPEND WebKit2_INCLUDE_DIRECTORIES a/Source/WebKit2/PlatformEfl.cmake_sec1
226
    "${WEBCORE_DIR}/platform/graphics/cairo"
226
    "${WEBCORE_DIR}/platform/graphics/cairo"
227
    "${WEBCORE_DIR}/platform/graphics/efl"
227
    "${WEBCORE_DIR}/platform/graphics/efl"
228
    "${WEBCORE_DIR}/platform/graphics/opentype"
228
    "${WEBCORE_DIR}/platform/graphics/opentype"
229
    "${WEBCORE_DIR}/platform/graphics/x11"
229
    "${WEBCORE_DIR}/platform/network/soup"
230
    "${WEBCORE_DIR}/platform/network/soup"
230
    "${WEBCORE_DIR}/platform/text/enchant"
231
    "${WEBCORE_DIR}/platform/text/enchant"
231
    "${WEBKIT2_DIR}/NetworkProcess/efl"
232
    "${WEBKIT2_DIR}/NetworkProcess/efl"
- a/Source/WebKit2/PlatformGTK.cmake +1 lines
Lines 458-463 list(APPEND WebKit2_INCLUDE_DIRECTORIES a/Source/WebKit2/PlatformGTK.cmake_sec1
458
    "${WEBCORE_DIR}/platform/gtk"
458
    "${WEBCORE_DIR}/platform/gtk"
459
    "${WEBCORE_DIR}/platform/graphics/cairo"
459
    "${WEBCORE_DIR}/platform/graphics/cairo"
460
    "${WEBCORE_DIR}/platform/graphics/opentype"
460
    "${WEBCORE_DIR}/platform/graphics/opentype"
461
    "${WEBCORE_DIR}/platform/graphics/x11"
461
    "${WEBCORE_DIR}/platform/network/soup"
462
    "${WEBCORE_DIR}/platform/network/soup"
462
    "${WEBCORE_DIR}/platform/text/enchant"
463
    "${WEBCORE_DIR}/platform/text/enchant"
463
    "${WEBKIT2_DIR}/DatabaseProcess/unix"
464
    "${WEBKIT2_DIR}/DatabaseProcess/unix"
- a/Source/WebKit2/UIProcess/cairo/BackingStoreCairo.cpp -1 / +1 lines
Lines 54-60 std::unique_ptr<BackingStoreBackendCairo> BackingStore::createBackend() a/Source/WebKit2/UIProcess/cairo/BackingStoreCairo.cpp_sec1
54
        GdkVisual* visual = gtk_widget_get_visual(m_webPageProxy.viewWidget());
54
        GdkVisual* visual = gtk_widget_get_visual(m_webPageProxy.viewWidget());
55
        GdkScreen* screen = gdk_visual_get_screen(visual);
55
        GdkScreen* screen = gdk_visual_get_screen(visual);
56
        ASSERT(downcast<PlatformDisplayX11>(sharedDisplay).native() == GDK_SCREEN_XDISPLAY(screen));
56
        ASSERT(downcast<PlatformDisplayX11>(sharedDisplay).native() == GDK_SCREEN_XDISPLAY(screen));
57
        return std::make_unique<BackingStoreBackendCairoX11>(downcast<PlatformDisplayX11>(sharedDisplay).native(), GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
57
        return std::make_unique<BackingStoreBackendCairoX11>(GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
58
            GDK_VISUAL_XVISUAL(visual), gdk_visual_get_depth(visual), m_size, m_deviceScaleFactor);
58
            GDK_VISUAL_XVISUAL(visual), gdk_visual_get_depth(visual), m_size, m_deviceScaleFactor);
59
    }
59
    }
60
#endif
60
#endif
- a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp -30 / +24 lines
Lines 29-34 a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp_sec1
29
29
30
#if USE(REDIRECTED_XCOMPOSITE_WINDOW)
30
#if USE(REDIRECTED_XCOMPOSITE_WINDOW)
31
31
32
#include <X11/Xlib.h>
32
#include <X11/extensions/Xcomposite.h>
33
#include <X11/extensions/Xcomposite.h>
33
#include <X11/extensions/Xdamage.h>
34
#include <X11/extensions/Xdamage.h>
34
#include <cairo-xlib.h>
35
#include <cairo-xlib.h>
Lines 135-155 std::unique_ptr<RedirectedXCompositeWindow> RedirectedXCompositeWindow::create(G a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp_sec2
135
136
136
RedirectedXCompositeWindow::RedirectedXCompositeWindow(GdkWindow* parentWindow, std::function<void()> damageNotify)
137
RedirectedXCompositeWindow::RedirectedXCompositeWindow(GdkWindow* parentWindow, std::function<void()> damageNotify)
137
    : m_display(GDK_DISPLAY_XDISPLAY(gdk_window_get_display(parentWindow)))
138
    : m_display(GDK_DISPLAY_XDISPLAY(gdk_window_get_display(parentWindow)))
138
    , m_window(0)
139
    , m_parentWindow(0)
140
    , m_pixmap(0)
141
    , m_damage(0)
142
    , m_needsNewPixmapAfterResize(false)
139
    , m_needsNewPixmapAfterResize(false)
143
{
140
{
141
    ASSERT(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native() == m_display);
144
    Screen* screen = DefaultScreenOfDisplay(m_display);
142
    Screen* screen = DefaultScreenOfDisplay(m_display);
145
143
146
    GdkVisual* visual = gdk_window_get_visual(parentWindow);
144
    GdkVisual* visual = gdk_window_get_visual(parentWindow);
147
    Colormap colormap = XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone);
145
    XUniqueColormap colormap(XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone));
148
146
149
    // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc
147
    // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc
150
    XSetWindowAttributes windowAttributes;
148
    XSetWindowAttributes windowAttributes;
151
    windowAttributes.override_redirect = True;
149
    windowAttributes.override_redirect = True;
152
    windowAttributes.colormap = colormap;
150
    windowAttributes.colormap = colormap.get();
153
151
154
    // CWBorderPixel must be present when the depth doesn't match the parent's one.
152
    // CWBorderPixel must be present when the depth doesn't match the parent's one.
155
    // See http://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c?id=xorg-server-1.16.0#n703.
153
    // See http://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c?id=xorg-server-1.16.0#n703.
Lines 164-176 RedirectedXCompositeWindow::RedirectedXCompositeWindow(GdkWindow* parentWindow, a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp_sec3
164
        GDK_VISUAL_XVISUAL(visual),
162
        GDK_VISUAL_XVISUAL(visual),
165
        CWOverrideRedirect | CWColormap | CWBorderPixel,
163
        CWOverrideRedirect | CWColormap | CWBorderPixel,
166
        &windowAttributes);
164
        &windowAttributes);
167
    XMapWindow(m_display, m_parentWindow);
165
    XMapWindow(m_display, m_parentWindow.get());
168
166
169
    windowAttributes.event_mask = StructureNotifyMask;
167
    windowAttributes.event_mask = StructureNotifyMask;
170
    windowAttributes.override_redirect = False;
168
    windowAttributes.override_redirect = False;
171
    // Create the window of at last 1x1 since X doesn't allow to create empty windows.
169
    // Create the window of at last 1x1 since X doesn't allow to create empty windows.
172
    m_window = XCreateWindow(m_display,
170
    m_window = XCreateWindow(m_display,
173
        m_parentWindow,
171
        m_parentWindow.get(),
174
        0, 0,
172
        0, 0,
175
        std::max(1, m_size.width()),
173
        std::max(1, m_size.width()),
176
        std::max(1, m_size.height()),
174
        std::max(1, m_size.height()),
Lines 180-200 RedirectedXCompositeWindow::RedirectedXCompositeWindow(GdkWindow* parentWindow, a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp_sec4
180
        CopyFromParent,
178
        CopyFromParent,
181
        CWEventMask,
179
        CWEventMask,
182
        &windowAttributes);
180
        &windowAttributes);
183
    XMapWindow(m_display, m_window);
181
    XMapWindow(m_display, m_window.get());
184
182
185
    XFreeColormap(m_display, colormap);
183
    xDamageNotifier().add(m_window.get(), WTF::move(damageNotify));
186
187
    xDamageNotifier().add(m_window, WTF::move(damageNotify));
188
184
189
    while (1) {
185
    while (1) {
190
        XEvent event;
186
        XEvent event;
191
        XWindowEvent(m_display, m_window, StructureNotifyMask, &event);
187
        XWindowEvent(m_display, m_window.get(), StructureNotifyMask, &event);
192
        if (event.type == MapNotify && event.xmap.window == m_window)
188
        if (event.type == MapNotify && event.xmap.window == m_window.get())
193
            break;
189
            break;
194
    }
190
    }
195
    XSelectInput(m_display, m_window, NoEventMask);
191
    XSelectInput(m_display, m_window.get(), NoEventMask);
196
    XCompositeRedirectWindow(m_display, m_window, CompositeRedirectManual);
192
    XCompositeRedirectWindow(m_display, m_window.get(), CompositeRedirectManual);
197
    m_damage = XDamageCreate(m_display, m_window, XDamageReportNonEmpty);
193
    m_damage = XDamageCreate(m_display, m_window.get(), XDamageReportNonEmpty);
198
}
194
}
199
195
200
RedirectedXCompositeWindow::~RedirectedXCompositeWindow()
196
RedirectedXCompositeWindow::~RedirectedXCompositeWindow()
Lines 204-215 RedirectedXCompositeWindow::~RedirectedXCompositeWindow() a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp_sec5
204
    ASSERT(m_window);
200
    ASSERT(m_window);
205
    ASSERT(m_parentWindow);
201
    ASSERT(m_parentWindow);
206
202
207
    xDamageNotifier().remove(m_window);
203
    xDamageNotifier().remove(m_window.get());
208
204
209
    XDamageDestroy(m_display, m_damage);
205
    // Explicit reset these because we need to ensure it happens in this order.
210
    XDestroyWindow(m_display, m_window);
206
    m_damage.reset();
211
    XDestroyWindow(m_display, m_parentWindow);
207
    m_window.reset();
212
    cleanupPixmapAndPixmapSurface();
208
    m_parentWindow.reset();
213
}
209
}
214
210
215
void RedirectedXCompositeWindow::resize(const IntSize& size)
211
void RedirectedXCompositeWindow::resize(const IntSize& size)
Lines 218-224 void RedirectedXCompositeWindow::resize(const IntSize& size) a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp_sec6
218
        return;
214
        return;
219
215
220
    // Resize the window to at last 1x1 since X doesn't allow to create empty windows.
216
    // Resize the window to at last 1x1 since X doesn't allow to create empty windows.
221
    XResizeWindow(m_display, m_window, std::max(1, size.width()), std::max(1, size.height()));
217
    XResizeWindow(m_display, m_window.get(), std::max(1, size.width()), std::max(1, size.height()));
222
    XFlush(m_display);
218
    XFlush(m_display);
223
219
224
    m_size = size;
220
    m_size = size;
Lines 232-240 void RedirectedXCompositeWindow::cleanupPixmapAndPixmapSurface() a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp_sec7
232
    if (!m_pixmap)
228
    if (!m_pixmap)
233
        return;
229
        return;
234
230
235
    XFreePixmap(m_display, m_pixmap);
236
    m_pixmap = 0;
237
    m_surface = nullptr;
231
    m_surface = nullptr;
232
    m_pixmap.reset();
238
}
233
}
239
234
240
cairo_surface_t* RedirectedXCompositeWindow::surface()
235
cairo_surface_t* RedirectedXCompositeWindow::surface()
Lines 247-266 cairo_surface_t* RedirectedXCompositeWindow::surface() a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp_sec8
247
242
248
    m_needsNewPixmapAfterResize = false;
243
    m_needsNewPixmapAfterResize = false;
249
244
250
    Pixmap newPixmap = XCompositeNameWindowPixmap(m_display, m_window);
245
    XUniquePixmap newPixmap(XCompositeNameWindowPixmap(m_display, m_window.get()));
251
    if (!newPixmap) {
246
    if (!newPixmap) {
252
        cleanupPixmapAndPixmapSurface();
247
        cleanupPixmapAndPixmapSurface();
253
        return nullptr;
248
        return nullptr;
254
    }
249
    }
255
250
256
    XWindowAttributes windowAttributes;
251
    XWindowAttributes windowAttributes;
257
    if (!XGetWindowAttributes(m_display, m_window, &windowAttributes)) {
252
    if (!XGetWindowAttributes(m_display, m_window.get(), &windowAttributes)) {
258
        cleanupPixmapAndPixmapSurface();
253
        cleanupPixmapAndPixmapSurface();
259
        XFreePixmap(m_display, newPixmap);
260
        return nullptr;
254
        return nullptr;
261
    }
255
    }
262
256
263
    RefPtr<cairo_surface_t> newSurface = adoptRef(cairo_xlib_surface_create(m_display, newPixmap, windowAttributes.visual, m_size.width(), m_size.height()));
257
    RefPtr<cairo_surface_t> newSurface = adoptRef(cairo_xlib_surface_create(m_display, newPixmap.get(), windowAttributes.visual, m_size.width(), m_size.height()));
264
258
265
    // Nvidia drivers seem to prepare their redirected window pixmap asynchronously, so for a few fractions
259
    // Nvidia drivers seem to prepare their redirected window pixmap asynchronously, so for a few fractions
266
    // of a second after each resize, while doing continuous resizing (which constantly destroys and creates
260
    // of a second after each resize, while doing continuous resizing (which constantly destroys and creates
Lines 275-281 cairo_surface_t* RedirectedXCompositeWindow::surface() a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp_sec9
275
    }
269
    }
276
270
277
    cleanupPixmapAndPixmapSurface();
271
    cleanupPixmapAndPixmapSurface();
278
    m_pixmap = newPixmap;
272
    m_pixmap = WTF::move(newPixmap);
279
    m_surface = newSurface;
273
    m_surface = newSurface;
280
    return m_surface.get();
274
    return m_surface.get();
281
}
275
}
- a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.h -6 / +7 lines
Lines 31-41 a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.h_sec1
31
31
32
#include <WebCore/IntSize.h>
32
#include <WebCore/IntSize.h>
33
#include <WebCore/RefPtrCairo.h>
33
#include <WebCore/RefPtrCairo.h>
34
#include <X11/Xlib.h>
34
#include <WebCore/XUnique.h>
35
#include <functional>
35
#include <functional>
36
36
37
typedef struct _GdkWindow GdkWindow;
37
typedef struct _GdkWindow GdkWindow;
38
typedef unsigned long Damage;
38
typedef unsigned long Damage;
39
typedef unsigned long Window;
39
40
40
namespace WebKit {
41
namespace WebKit {
41
42
Lines 44-50 public: a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.h_sec2
44
    static std::unique_ptr<RedirectedXCompositeWindow> create(GdkWindow*, std::function<void()> damageNotify);
45
    static std::unique_ptr<RedirectedXCompositeWindow> create(GdkWindow*, std::function<void()> damageNotify);
45
    ~RedirectedXCompositeWindow();
46
    ~RedirectedXCompositeWindow();
46
47
47
    Window windowID() const { return m_window; }
48
    Window windowID() const { return m_window.get(); }
48
    void resize(const WebCore::IntSize&);
49
    void resize(const WebCore::IntSize&);
49
    cairo_surface_t* surface();
50
    cairo_surface_t* surface();
50
51
Lines 54-63 private: a/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.h_sec3
54
55
55
    Display* m_display;
56
    Display* m_display;
56
    WebCore::IntSize m_size;
57
    WebCore::IntSize m_size;
57
    Window m_window;
58
    WebCore::XUniqueWindow m_window;
58
    Window m_parentWindow;
59
    WebCore::XUniqueWindow m_parentWindow;
59
    Pixmap m_pixmap;
60
    WebCore::XUniquePixmap m_pixmap;
60
    Damage m_damage;
61
    WebCore::XUniqueDamage m_damage;
61
    RefPtr<cairo_surface_t> m_surface;
62
    RefPtr<cairo_surface_t> m_surface;
62
    bool m_needsNewPixmapAfterResize;
63
    bool m_needsNewPixmapAfterResize;
63
};
64
};
- a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h -1 / +5 lines
Lines 42-47 a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h_sec1
42
#include "WebHitTestResult.h"
42
#include "WebHitTestResult.h"
43
#endif
43
#endif
44
44
45
#if PLUGIN_ARCHITECTURE(X11)
46
#include <WebCore/XUnique.h>
47
#endif
48
45
namespace WebCore {
49
namespace WebCore {
46
class MachSendRight;
50
class MachSendRight;
47
class HTTPHeaderMap;
51
class HTTPHeaderMap;
Lines 387-393 private: a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h_sec2
387
    NP_CGContext m_npCGContext;
391
    NP_CGContext m_npCGContext;
388
#endif
392
#endif
389
#elif PLUGIN_ARCHITECTURE(X11)
393
#elif PLUGIN_ARCHITECTURE(X11)
390
    Pixmap m_drawable;
394
    WebCore::XUniquePixmap m_drawable;
391
    Display* m_pluginDisplay;
395
    Display* m_pluginDisplay;
392
#if PLATFORM(GTK)
396
#if PLATFORM(GTK)
393
    GtkWidget* m_platformPluginWidget;
397
    GtkWidget* m_platformPluginWidget;
- a/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp -24 / +11 lines
Lines 34-39 a/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp_sec1
34
#include <WebCore/GraphicsContext.h>
34
#include <WebCore/GraphicsContext.h>
35
#include <WebCore/NotImplemented.h>
35
#include <WebCore/NotImplemented.h>
36
#include <WebCore/PlatformDisplayX11.h>
36
#include <WebCore/PlatformDisplayX11.h>
37
#include <WebCore/XUnique.h>
37
38
38
#if PLATFORM(GTK)
39
#if PLATFORM(GTK)
39
#include <gtk/gtk.h>
40
#include <gtk/gtk.h>
Lines 175-186 bool NetscapePlugin::platformPostInitializeWindowless() a/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp_sec2
175
    visualTemplate.depth = depth;
176
    visualTemplate.depth = depth;
176
    visualTemplate.c_class = TrueColor;
177
    visualTemplate.c_class = TrueColor;
177
    int numMatching;
178
    int numMatching;
178
    XVisualInfo* visualInfo = XGetVisualInfo(display, VisualScreenMask | VisualDepthMask | VisualClassMask,
179
    XUniquePtr<XVisualInfo> visualInfo(XGetVisualInfo(display, VisualScreenMask | VisualDepthMask | VisualClassMask, &visualTemplate, &numMatching));
179
                                             &visualTemplate, &numMatching);
180
    ASSERT(visualInfo);
180
    ASSERT(visualInfo);
181
    Visual* visual = visualInfo[0].visual;
181
    Visual* visual = visualInfo.get()[0].visual;
182
    ASSERT(visual);
182
    ASSERT(visual);
183
    XFree(visualInfo);
184
183
185
    callbackStruct->visual = visual;
184
    callbackStruct->visual = visual;
186
    callbackStruct->colormap = XCreateColormap(display, rootWindowID(), visual, AllocNone);
185
    callbackStruct->colormap = XCreateColormap(display, rootWindowID(), visual, AllocNone);
Lines 232-241 void NetscapePlugin::platformDestroy() a/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp_sec3
232
    XFreeColormap(hostDisplay, callbackStruct->colormap);
231
    XFreeColormap(hostDisplay, callbackStruct->colormap);
233
    delete callbackStruct;
232
    delete callbackStruct;
234
233
235
    if (m_drawable) {
234
    m_drawable.reset();
236
        XFreePixmap(hostDisplay, m_drawable);
237
        m_drawable = 0;
238
    }
239
235
240
#if PLATFORM(GTK)
236
#if PLATFORM(GTK)
241
    if (m_platformPluginWidget) {
237
    if (m_platformPluginWidget) {
Lines 262-279 void NetscapePlugin::platformGeometryDidChange() a/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp_sec4
262
        return;
258
        return;
263
    }
259
    }
264
260
265
    Display* display = x11HostDisplay();
261
    m_drawable.reset();
266
    if (m_drawable)
262
    if (m_pluginSize.isEmpty())
267
        XFreePixmap(display, m_drawable);
268
269
    if (m_pluginSize.isEmpty()) {
270
        m_drawable = 0;
271
        return;
263
        return;
272
    }
273
274
    m_drawable = XCreatePixmap(display, rootWindowID(), m_pluginSize.width(), m_pluginSize.height(), displayDepth());
275
264
276
    XSync(display, false); // Make sure that the server knows about the Drawable.
265
    m_drawable = XCreatePixmap(x11HostDisplay(), rootWindowID(), m_pluginSize.width(), m_pluginSize.height(), displayDepth());
266
    XSync(x11HostDisplay(), false); // Make sure that the server knows about the Drawable.
277
}
267
}
278
268
279
void NetscapePlugin::platformVisibilityDidChange()
269
void NetscapePlugin::platformVisibilityDidChange()
Lines 307-313 void NetscapePlugin::platformPaint(GraphicsContext* context, const IntRect& dirt a/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp_sec5
307
    XGraphicsExposeEvent& exposeEvent = xevent.xgraphicsexpose;
297
    XGraphicsExposeEvent& exposeEvent = xevent.xgraphicsexpose;
308
    exposeEvent.type = GraphicsExpose;
298
    exposeEvent.type = GraphicsExpose;
309
    exposeEvent.display = x11HostDisplay();
299
    exposeEvent.display = x11HostDisplay();
310
    exposeEvent.drawable = m_drawable;
300
    exposeEvent.drawable = m_drawable.get();
311
301
312
    IntRect exposedRect(dirtyRect);
302
    IntRect exposedRect(dirtyRect);
313
    exposeEvent.x = exposedRect.x();
303
    exposeEvent.x = exposedRect.x();
Lines 324-334 void NetscapePlugin::platformPaint(GraphicsContext* context, const IntRect& dirt a/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp_sec6
324
        XSync(m_pluginDisplay, false);
314
        XSync(m_pluginDisplay, false);
325
315
326
#if PLATFORM(GTK) || (PLATFORM(EFL) && USE(CAIRO))
316
#if PLATFORM(GTK) || (PLATFORM(EFL) && USE(CAIRO))
327
    RefPtr<cairo_surface_t> drawableSurface = adoptRef(cairo_xlib_surface_create(m_pluginDisplay,
317
    RefPtr<cairo_surface_t> drawableSurface = adoptRef(cairo_xlib_surface_create(m_pluginDisplay, m_drawable.get(),
328
                                                                                 m_drawable,
318
        static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info)->visual, m_pluginSize.width(), m_pluginSize.height()));
329
                                                                                 static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info)->visual,
330
                                                                                 m_pluginSize.width(),
331
                                                                                 m_pluginSize.height()));
332
    cairo_t* cr = context->platformContext()->cr();
319
    cairo_t* cr = context->platformContext()->cr();
333
    cairo_save(cr);
320
    cairo_save(cr);
334
321

Return to Bug 144521