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 PlatformDisplay_h
27#define PlatformDisplay_h
28
29#include <wtf/Noncopyable.h>
30#include <wtf/TypeCasts.h>
31
32#if USE(EGL)
33typedef void *EGLDisplay;
34#endif
35
36namespace WebCore {
37
38class GLContext;
39
40class PlatformDisplay {
41 WTF_MAKE_NONCOPYABLE(PlatformDisplay); WTF_MAKE_FAST_ALLOCATED;
42public:
43 WEBCORE_EXPORT static PlatformDisplay& sharedDisplay();
44 WEBCORE_EXPORT static PlatformDisplay& sharedDisplayForCompositing();
45 virtual ~PlatformDisplay();
46
47 enum class Type {
48#if PLATFORM(X11)
49 X11,
50#endif
51#if PLATFORM(WAYLAND)
52 Wayland,
53#endif
54#if PLATFORM(WIN)
55 Windows,
56#endif
57#if USE(LIBWPE)
58 WPE,
59#endif
60 };
61
62 virtual Type type() const = 0;
63
64#if USE(EGL) || USE(GLX)
65 WEBCORE_EXPORT GLContext* sharingGLContext();
66#endif
67
68#if USE(EGL)
69 EGLDisplay eglDisplay() const;
70 bool eglCheckVersion(int major, int minor) const;
71 static void shutDownEglDisplays();
72#endif
73
74protected:
75 enum class NativeDisplayOwned { No, Yes };
76 explicit PlatformDisplay(NativeDisplayOwned);
77
78 static void setSharedDisplayForCompositing(PlatformDisplay&);
79
80 NativeDisplayOwned m_nativeDisplayOwned { NativeDisplayOwned::No };
81
82#if USE(EGL)
83 virtual void initializeEGLDisplay();
84
85 EGLDisplay m_eglDisplay;
86#endif
87
88#if USE(EGL) || USE(GLX)
89 std::unique_ptr<GLContext> m_sharingGLContext;
90#endif
91
92private:
93 static std::unique_ptr<PlatformDisplay> createPlatformDisplay();
94
95#if USE(EGL)
96 void terminateEGLDisplay();
97
98 bool m_eglDisplayInitialized { false };
99 int m_eglMajorVersion { 0 };
100 int m_eglMinorVersion { 0 };
101#endif
102};
103
104} // namespace WebCore
105
106#define SPECIALIZE_TYPE_TRAITS_PLATFORM_DISPLAY(ToClassName, DisplayType) \
107SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToClassName) \
108 static bool isType(const WebCore::PlatformDisplay& display) { return display.type() == WebCore::PlatformDisplay::Type::DisplayType; } \
109SPECIALIZE_TYPE_TRAITS_END()
110
111#endif // PltformDisplay_h
112