Changeset 207615 in webkit
- Timestamp:
- Oct 20, 2016 5:37:53 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207614 r207615 1 2016-10-20 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] Avoid including egl.h headers in internal headers 4 https://bugs.webkit.org/show_bug.cgi?id=163722 5 6 Reviewed by Žan Doberšek. 7 8 egl.h includes eglplatform.h that decides the native types for the platform at compile time. However, we support 9 to build with X11 and Wayland at the same time and decide what to use at runtime. Currently GLContext.h includes 10 eglplatform.h after wayland-egl.h if Wayland is enabled. That means that the wayland native types are used by 11 default from all cpp files including GLContext.h. It currently works in X11 because we cast the value anyway and 12 for example EGLNativeWindowType is a pointer in Wayland that can be casted to unsigned long in X11 to represent 13 the X Window. This is very fragile in any case, we should avoid adding egl headers in our headers and only 14 include it in cpp files. But we also need to ensure we don't use X11 and Wayland in the same cpp file. 15 16 * PlatformGTK.cmake: 17 * platform/graphics/GLContext.cpp: 18 (WebCore::GLContext::createContextForWindow): 19 * platform/graphics/GLContext.h: 20 * platform/graphics/egl/GLContextEGL.cpp: 21 (WebCore::GLContextEGL::createWindowContext): 22 (WebCore::GLContextEGL::createContext): 23 (WebCore::GLContextEGL::~GLContextEGL): 24 * platform/graphics/egl/GLContextEGL.h: 25 * platform/graphics/egl/GLContextEGLWayland.cpp: Added. 26 (WebCore::GLContextEGL::GLContextEGL): 27 (WebCore::GLContextEGL::createWindowSurfaceWayland): 28 (WebCore::GLContextEGL::createWaylandContext): 29 (WebCore::GLContextEGL::destroyWaylandWindow): 30 * platform/graphics/egl/GLContextEGLX11.cpp: Added. 31 (WebCore::GLContextEGL::GLContextEGL): 32 (WebCore::GLContextEGL::createWindowSurfaceX11): 33 (WebCore::GLContextEGL::createPixmapContext): 34 * platform/graphics/glx/GLContextGLX.cpp: 35 (WebCore::GLContextGLX::createWindowContext): 36 (WebCore::GLContextGLX::createContext): 37 (WebCore::GLContextGLX::GLContextGLX): 38 * platform/graphics/glx/GLContextGLX.h: 39 * platform/graphics/wayland/PlatformDisplayWayland.cpp: 40 * platform/graphics/x11/PlatformDisplayX11.cpp: 41 1 42 2016-10-20 Carlos Garcia Campos <cgarcia@igalia.com> 2 43 -
trunk/Source/WebCore/PlatformGTK.cmake
r207590 r207615 127 127 128 128 platform/graphics/egl/GLContextEGL.cpp 129 platform/graphics/egl/GLContextEGLWayland.cpp 130 platform/graphics/egl/GLContextEGLX11.cpp 129 131 130 132 platform/graphics/freetype/FontCacheFreeType.cpp -
trunk/Source/WebCore/platform/graphics/GLContext.cpp
r207614 r207615 85 85 86 86 #if USE(GLX) 87 #if PLATFORM(WAYLAND) // Building both X11 and Wayland targets 88 XID GLXWindowHandle = reinterpret_cast<XID>(windowHandle); 89 #else 90 XID GLXWindowHandle = static_cast<XID>(windowHandle); 91 #endif 92 if (auto glxContext = GLContextGLX::createContext(GLXWindowHandle, display)) 87 if (auto glxContext = GLContextGLX::createContext(windowHandle, display)) 93 88 return WTFMove(glxContext); 94 89 #endif -
trunk/Source/WebCore/platform/graphics/GLContext.h
r207614 r207615 27 27 #if USE(EGL) && !PLATFORM(GTK) 28 28 #include "eglplatform.h" 29 typedef EGLNativeWindowType GLNativeWindowType;30 #elif PLATFORM(GTK) && PLATFORM(WAYLAND) && !defined(GTK_API_VERSION_2)31 #include <wayland-egl.h>32 #include <EGL/eglplatform.h>33 29 typedef EGLNativeWindowType GLNativeWindowType; 34 30 #else -
trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp
r207614 r207615 23 23 24 24 #include "GraphicsContext3D.h" 25 #include "PlatformDisplay.h" 26 #include <EGL/egl.h> 25 27 26 28 #if USE(CAIRO) … … 33 35 #else 34 36 #include "OpenGLShims.h" 35 #endif36 37 #if PLATFORM(X11)38 #include "PlatformDisplayX11.h"39 #include "XErrorTrapper.h"40 #include "XUniquePtr.h"41 #include <X11/Xlib.h>42 #endif43 44 #if PLATFORM(WAYLAND)45 #include "PlatformDisplayWayland.h"46 #include <wayland-egl.h>47 37 #endif 48 38 … … 104 94 } 105 95 106 std::unique_ptr<GLContextEGL> GLContextEGL::createWindowContext( EGLNativeWindowType window, PlatformDisplay& platformDisplay, EGLContext sharingContext)96 std::unique_ptr<GLContextEGL> GLContextEGL::createWindowContext(GLNativeWindowType window, PlatformDisplay& platformDisplay, EGLContext sharingContext) 107 97 { 108 98 EGLDisplay display = platformDisplay.eglDisplay(); … … 115 105 return nullptr; 116 106 117 EGLSurface surface = eglCreateWindowSurface(display, config, window, 0); 107 EGLSurface surface = EGL_NO_SURFACE; 108 #if PLATFORM(GTK) 109 #if PLATFORM(X11) 110 if (platformDisplay.type() == PlatformDisplay::Type::X11) 111 surface = createWindowSurfaceX11(display, config, window); 112 #endif 113 #if PLATFORM(WAYLAND) 114 if (platformDisplay.type() == PlatformDisplay::Type::Wayland) 115 surface = createWindowSurfaceWayland(display, config, window); 116 #endif 117 #else 118 surface = eglCreateWindowSurface(display, config, static_cast<EGLNativeWindowType>(window), nullptr); 119 #endif 118 120 if (surface == EGL_NO_SURFACE) { 119 121 eglDestroyContext(display, context); … … 166 168 } 167 169 168 #if PLATFORM(X11) 169 std::unique_ptr<GLContextEGL> GLContextEGL::createPixmapContext(PlatformDisplay& platformDisplay, EGLContext sharingContext) 170 { 171 EGLDisplay display = platformDisplay.eglDisplay(); 172 EGLConfig config; 173 if (!getEGLConfig(display, &config, PixmapSurface)) 174 return nullptr; 175 176 EGLContext context = eglCreateContext(display, config, sharingContext, gContextAttributes); 177 if (context == EGL_NO_CONTEXT) 178 return nullptr; 179 180 EGLint visualId; 181 if (!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &visualId)) { 182 eglDestroyContext(display, context); 183 return nullptr; 184 } 185 186 Display* x11Display = downcast<PlatformDisplayX11>(platformDisplay).native(); 187 188 XVisualInfo visualInfo; 189 visualInfo.visualid = visualId; 190 int numVisuals = 0; 191 XUniquePtr<XVisualInfo> visualInfoList(XGetVisualInfo(x11Display, VisualIDMask, &visualInfo, &numVisuals)); 192 if (!visualInfoList || !numVisuals) { 193 eglDestroyContext(display, context); 194 return nullptr; 195 } 196 197 // We are using VisualIDMask so there must be only one. 198 ASSERT(numVisuals == 1); 199 XUniquePixmap pixmap = XCreatePixmap(x11Display, DefaultRootWindow(x11Display), 1, 1, visualInfoList.get()[0].depth); 200 if (!pixmap) { 201 eglDestroyContext(display, context); 202 return nullptr; 203 } 204 205 // Some drivers fail to create the surface producing BadDrawable X error and the default XError handler normally aborts. 206 // However, if the X error is ignored, eglCreatePixmapSurface() ends up returning a surface and we can continue creating 207 // the context. Since this is an offscreen context, it doesn't matter if the pixmap used is not valid because we never do 208 // swap buffers. So, we use a custom XError handler here that ignores BadDrawable errors and only warns about any other 209 // errors without aborting in any case. 210 XErrorTrapper trapper(x11Display, XErrorTrapper::Policy::Warn, { BadDrawable }); 211 EGLSurface surface = eglCreatePixmapSurface(display, config, reinterpret_cast<EGLNativePixmapType>(pixmap.get()), 0); 212 if (surface == EGL_NO_SURFACE) { 213 eglDestroyContext(display, context); 214 return nullptr; 215 } 216 217 return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, WTFMove(pixmap))); 218 } 219 #endif // PLATFORM(X11) 220 221 #if PLATFORM(WAYLAND) 222 std::unique_ptr<GLContextEGL> GLContextEGL::createWaylandContext(PlatformDisplay& platformDisplay, EGLContext sharingContext) 223 { 224 EGLDisplay display = platformDisplay.eglDisplay(); 225 EGLConfig config; 226 if (!getEGLConfig(display, &config, WindowSurface)) 227 return nullptr; 228 229 EGLContext context = eglCreateContext(display, config, sharingContext, gContextAttributes); 230 if (context == EGL_NO_CONTEXT) 231 return nullptr; 232 233 WlUniquePtr<struct wl_surface> wlSurface(downcast<PlatformDisplayWayland>(platformDisplay).createSurface()); 234 if (!wlSurface) { 235 eglDestroyContext(display, context); 236 return nullptr; 237 } 238 239 EGLNativeWindowType window = wl_egl_window_create(wlSurface.get(), 1, 1); 240 EGLSurface surface = eglCreateWindowSurface(display, config, window, 0); 241 if (surface == EGL_NO_SURFACE) { 242 eglDestroyContext(display, context); 243 wl_egl_window_destroy(window); 244 return nullptr; 245 } 246 247 return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, WTFMove(wlSurface), window)); 248 } 249 #endif 250 251 std::unique_ptr<GLContextEGL> GLContextEGL::createContext(EGLNativeWindowType window, PlatformDisplay& platformDisplay) 170 std::unique_ptr<GLContextEGL> GLContextEGL::createContext(GLNativeWindowType window, PlatformDisplay& platformDisplay) 252 171 { 253 172 if (platformDisplay.eglDisplay() == EGL_NO_DISPLAY) … … 312 231 } 313 232 314 #if PLATFORM(X11)315 GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, XUniquePixmap&& pixmap)316 : GLContext(display)317 , m_context(context)318 , m_surface(surface)319 , m_type(PixmapSurface)320 , m_pixmap(WTFMove(pixmap))321 {322 }323 #endif324 325 #if PLATFORM(WAYLAND)326 GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, WlUniquePtr<struct wl_surface>&& wlSurface, EGLNativeWindowType wlWindow)327 : GLContext(display)328 , m_context(context)329 , m_surface(surface)330 , m_type(WindowSurface)331 , m_wlSurface(WTFMove(wlSurface))332 , m_wlWindow(wlWindow)333 {334 }335 #endif336 337 233 GLContextEGL::~GLContextEGL() 338 234 { … … 353 249 354 250 #if PLATFORM(WAYLAND) 355 if (m_wlWindow) 356 wl_egl_window_destroy(m_wlWindow); 251 destroyWaylandWindow(); 357 252 #endif 358 253 } -
trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.h
r205116 r207615 18 18 */ 19 19 20 #ifndef GLContextEGL_h 21 #define GLContextEGL_h 20 #pragma once 22 21 23 22 #if USE(EGL) 24 23 25 24 #include "GLContext.h" 26 #include <EGL/egl.h>27 25 28 26 #if PLATFORM(X11) … … 32 30 #if PLATFORM(WAYLAND) 33 31 #include "WlUniquePtr.h" 32 struct wl_egl_window; 34 33 #endif 34 35 typedef void *EGLConfig; 36 typedef void *EGLContext; 37 typedef void *EGLDisplay; 38 typedef void *EGLSurface; 35 39 36 40 namespace WebCore { … … 39 43 WTF_MAKE_NONCOPYABLE(GLContextEGL); 40 44 public: 41 static std::unique_ptr<GLContextEGL> createContext( EGLNativeWindowType, PlatformDisplay&);45 static std::unique_ptr<GLContextEGL> createContext(GLNativeWindowType, PlatformDisplay&); 42 46 static std::unique_ptr<GLContextEGL> createSharingContext(PlatformDisplay&); 43 47 44 48 virtual ~GLContextEGL(); 45 49 50 private: 46 51 bool makeContextCurrent() override; 47 52 void swapBuffers() override; … … 59 64 #endif 60 65 61 private:62 66 enum EGLSurfaceType { PbufferSurface, WindowSurface, PixmapSurface, Surfaceless }; 63 67 … … 67 71 #endif 68 72 #if PLATFORM(WAYLAND) 69 GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, WlUniquePtr<struct wl_surface>&&, EGLNativeWindowType); 73 GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, WlUniquePtr<struct wl_surface>&&, struct wl_egl_window*); 74 void destroyWaylandWindow(); 70 75 #endif 71 76 72 static std::unique_ptr<GLContextEGL> createWindowContext( EGLNativeWindowType, PlatformDisplay&, EGLContext sharingContext = EGL_NO_CONTEXT);73 static std::unique_ptr<GLContextEGL> createPbufferContext(PlatformDisplay&, EGLContext sharingContext = EGL_NO_CONTEXT);74 static std::unique_ptr<GLContextEGL> createSurfacelessContext(PlatformDisplay&, EGLContext sharingContext = EGL_NO_CONTEXT);77 static std::unique_ptr<GLContextEGL> createWindowContext(GLNativeWindowType, PlatformDisplay&, EGLContext sharingContext = nullptr); 78 static std::unique_ptr<GLContextEGL> createPbufferContext(PlatformDisplay&, EGLContext sharingContext = nullptr); 79 static std::unique_ptr<GLContextEGL> createSurfacelessContext(PlatformDisplay&, EGLContext sharingContext = nullptr); 75 80 #if PLATFORM(X11) 76 static std::unique_ptr<GLContextEGL> createPixmapContext(PlatformDisplay&, EGLContext sharingContext = EGL_NO_CONTEXT); 81 static std::unique_ptr<GLContextEGL> createPixmapContext(PlatformDisplay&, EGLContext sharingContext = nullptr); 82 static EGLSurface createWindowSurfaceX11(EGLDisplay, EGLConfig, GLNativeWindowType); 77 83 #endif 78 84 #if PLATFORM(WAYLAND) 79 static std::unique_ptr<GLContextEGL> createWaylandContext(PlatformDisplay&, EGLContext sharingContext = EGL_NO_CONTEXT); 85 static std::unique_ptr<GLContextEGL> createWaylandContext(PlatformDisplay&, EGLContext sharingContext = nullptr); 86 static EGLSurface createWindowSurfaceWayland(EGLDisplay, EGLConfig, GLNativeWindowType); 80 87 #endif 81 88 82 89 static bool getEGLConfig(EGLDisplay, EGLConfig*, EGLSurfaceType); 83 90 84 EGLContext m_context { EGL_NO_CONTEXT};85 EGLSurface m_surface { EGL_NO_SURFACE};91 EGLContext m_context { nullptr }; 92 EGLSurface m_surface { nullptr }; 86 93 EGLSurfaceType m_type; 87 94 #if PLATFORM(X11) … … 100 107 101 108 #endif // USE(EGL) 102 103 #endif // GLContextEGL_h -
trunk/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp
r207614 r207615 53 53 } 54 54 55 std::unique_ptr<GLContextGLX> GLContextGLX::createWindowContext( XIDwindow, PlatformDisplay& platformDisplay, GLXContext sharingContext)55 std::unique_ptr<GLContextGLX> GLContextGLX::createWindowContext(GLNativeWindowType window, PlatformDisplay& platformDisplay, GLXContext sharingContext) 56 56 { 57 57 Display* display = downcast<PlatformDisplayX11>(platformDisplay).native(); 58 58 XWindowAttributes attributes; 59 if (!XGetWindowAttributes(display, window, &attributes))59 if (!XGetWindowAttributes(display, static_cast<Window>(window), &attributes)) 60 60 return nullptr; 61 61 … … 136 136 } 137 137 138 std::unique_ptr<GLContextGLX> GLContextGLX::createContext( XIDwindow, PlatformDisplay& platformDisplay)138 std::unique_ptr<GLContextGLX> GLContextGLX::createContext(GLNativeWindowType window, PlatformDisplay& platformDisplay) 139 139 { 140 140 GLXContext glxSharingContext = platformDisplay.sharingGLContext() ? static_cast<GLContextGLX*>(platformDisplay.sharingGLContext())->m_context.get() : nullptr; … … 156 156 } 157 157 158 GLContextGLX::GLContextGLX(PlatformDisplay& display, XUniqueGLXContext&& context, XIDwindow)158 GLContextGLX::GLContextGLX(PlatformDisplay& display, XUniqueGLXContext&& context, GLNativeWindowType window) 159 159 : GLContext(display) 160 160 , m_x11Display(downcast<PlatformDisplayX11>(m_display).native()) 161 161 , m_context(WTFMove(context)) 162 , m_window( window)162 , m_window(static_cast<Window>(window)) 163 163 { 164 164 } -
trunk/Source/WebCore/platform/graphics/glx/GLContextGLX.h
r205852 r207615 18 18 */ 19 19 20 #ifndef GLContextGLX_h 21 #define GLContextGLX_h 20 #pragma once 22 21 23 22 #if USE(GLX) … … 28 27 29 28 typedef unsigned char GLubyte; 30 typedef unsigned long XID;29 typedef unsigned long Window; 31 30 typedef void* ContextKeyType; 32 31 typedef struct _XDisplay Display; … … 37 36 WTF_MAKE_NONCOPYABLE(GLContextGLX); 38 37 public: 39 static std::unique_ptr<GLContextGLX> createContext( XID window, PlatformDisplay&);38 static std::unique_ptr<GLContextGLX> createContext(GLNativeWindowType, PlatformDisplay&); 40 39 static std::unique_ptr<GLContextGLX> createSharingContext(PlatformDisplay&); 41 40 42 41 virtual ~GLContextGLX(); 43 42 43 private: 44 44 bool makeContextCurrent() override; 45 45 void swapBuffers() override; … … 55 55 #endif 56 56 57 private: 58 GLContextGLX(PlatformDisplay&, XUniqueGLXContext&&, XID); 57 GLContextGLX(PlatformDisplay&, XUniqueGLXContext&&, GLNativeWindowType); 59 58 GLContextGLX(PlatformDisplay&, XUniqueGLXContext&&, XUniqueGLXPbuffer&&); 60 59 GLContextGLX(PlatformDisplay&, XUniqueGLXContext&&, XUniquePixmap&&, XUniqueGLXPixmap&&); 61 60 62 static std::unique_ptr<GLContextGLX> createWindowContext( XID window, PlatformDisplay&, GLXContext sharingContext = nullptr);61 static std::unique_ptr<GLContextGLX> createWindowContext(GLNativeWindowType, PlatformDisplay&, GLXContext sharingContext = nullptr); 63 62 static std::unique_ptr<GLContextGLX> createPbufferContext(PlatformDisplay&, GLXContext sharingContext = nullptr); 64 63 static std::unique_ptr<GLContextGLX> createPixmapContext(PlatformDisplay&, GLXContext sharingContext = nullptr); … … 66 65 Display* m_x11Display { nullptr }; 67 66 XUniqueGLXContext m_context; 68 XIDm_window { 0 };67 Window m_window { 0 }; 69 68 XUniqueGLXPbuffer m_pbuffer; 70 69 XUniquePixmap m_pixmap; … … 77 76 #endif // USE(GLX) 78 77 79 #endif // GLContextGLX_h -
trunk/Source/WebCore/platform/graphics/wayland/PlatformDisplayWayland.cpp
r205116 r207615 31 31 #include "GLContextEGL.h" 32 32 #include <cstring> 33 // These includes need to be in this order because wayland-egl.h defines WL_EGL_PLATFORM 34 // and egl.h checks that to decide whether it's Wayland platform. 33 35 #include <wayland-egl.h> 36 #include <EGL/egl.h> 34 37 #include <wtf/Assertions.h> 35 38 -
trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.cpp
r207403 r207615 27 27 #include "PlatformDisplayX11.h" 28 28 29 #include "GLContext.h" 30 29 31 #if PLATFORM(X11) 30 32 #include <X11/Xlib.h> … … 36 38 #if USE(EGL) 37 39 #include <EGL/egl.h> 38 #include <EGL/eglplatform.h>39 40 #endif 40 41 // FIXME: this needs to be here, after eglplatform.h, to avoid EGLNativeDisplayType to be defined as wl_display.42 // Since we support Wayland and X11 to be built at the same time, but eglplatform.h defines are decided at compile time43 // we need to ensure we only include eglplatform.h from X11 or Wayland specific files.44 #include "GLContext.h"45 41 46 42 namespace WebCore {
Note: See TracChangeset
for help on using the changeset viewer.