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 "XUniqueResource.h"
28
29#if PLATFORM(X11)
30#include "PlatformDisplayX11.h"
31#include <X11/Xlib.h>
32#include <X11/Xutil.h>
33
34#if PLATFORM(GTK)
35#include <X11/extensions/Xdamage.h>
36#endif
37
38#if USE(GLX)
39#include <GL/glx.h>
40#endif
41
42namespace WebCore {
43
44static inline Display* sharedDisplay()
45{
46 return downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
47}
48
49template<> void XUniqueResource<XResource::Colormap>::deleteXResource(unsigned long resource)
50{
51 if (resource)
52 XFreeColormap(sharedDisplay(), resource);
53}
54
55#if PLATFORM(GTK)
56template<> void XUniqueResource<XResource::Damage>::deleteXResource(unsigned long resource)
57{
58 if (resource)
59 XDamageDestroy(sharedDisplay(), resource);
60}
61#endif
62
63template<> void XUniqueResource<XResource::Pixmap>::deleteXResource(unsigned long resource)
64{
65 if (resource)
66 XFreePixmap(sharedDisplay(), resource);
67}
68
69template<> void XUniqueResource<XResource::Window>::deleteXResource(unsigned long resource)
70{
71 if (resource)
72 XDestroyWindow(sharedDisplay(), resource);
73}
74
75#if USE(GLX)
76template<> void XUniqueResource<XResource::GLXPbuffer>::deleteXResource(unsigned long resource)
77{
78 if (resource)
79 glXDestroyPbuffer(sharedDisplay(), resource);
80}
81
82template<> void XUniqueResource<XResource::GLXPixmap>::deleteXResource(unsigned long resource)
83{
84 if (resource)
85 glXDestroyGLXPixmap(sharedDisplay(), resource);
86}
87#endif // USE(GLX)
88
89} // namespace WebCore
90
91#endif // PLATFORM(X11)
92