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 XUniquePtr_h |
27 | #define XUniquePtr_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 | extern "C" void glXDestroyContext(Display*, GLXContext); |
36 | #endif |
37 | |
38 | namespace WebCore { |
39 | |
40 | template<typename T> |
41 | struct XPtrDeleter { |
42 | void operator()(T* ptr) const |
43 | { |
44 | XFree(ptr); |
45 | } |
46 | }; |
47 | |
48 | template<typename T> |
49 | using XUniquePtr = std::unique_ptr<T, XPtrDeleter<T>>; |
50 | |
51 | template<> struct XPtrDeleter<XImage> { |
52 | void operator() (XImage* ptr) const |
53 | { |
54 | XDestroyImage(ptr); |
55 | } |
56 | }; |
57 | |
58 | template<> struct XPtrDeleter<_XGC> { |
59 | void operator() (_XGC* ptr) const |
60 | { |
61 | XFreeGC(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), ptr); |
62 | } |
63 | }; |
64 | // Give a name to this to avoid having to use the internal struct name. |
65 | using XUniqueGC = XUniquePtr<_XGC>; |
66 | |
67 | #if USE(GLX) |
68 | template<> struct XPtrDeleter<__GLXcontextRec> { |
69 | void operator() (__GLXcontextRec* ptr) |
70 | { |
71 | glXDestroyContext(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), ptr); |
72 | } |
73 | }; |
74 | // Give a name to this to avoid having to use the internal struct name. |
75 | using XUniqueGLXContext = XUniquePtr<__GLXcontextRec>; |
76 | #endif |
77 | |
78 | } // namespace WebCore |
79 | |
80 | #endif // PLATFORM(X11) |
81 | |
82 | #endif // XUniquePtr_h |
83 | |