| 1 | /* |
| 2 | * Copyright (C) 2012 Igalia S.L. |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free |
| 16 | * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #ifndef GLContext_h |
| 21 | #define GLContext_h |
| 22 | |
| 23 | #include "GraphicsContext3D.h" |
| 24 | #include "PlatformDisplay.h" |
| 25 | #include <wtf/Noncopyable.h> |
| 26 | |
| 27 | #if USE(EGL) && !PLATFORM(GTK) |
| 28 | #if PLATFORM(WPE) |
| 29 | // FIXME: For now default to the GBM EGL platform, but this should really be |
| 30 | // somehow deducible from the build configuration. |
| 31 | #define __GBM__ 1 |
| 32 | #endif // PLATFORM(WPE) |
| 33 | #include <EGL/eglplatform.h> |
| 34 | typedef EGLNativeWindowType GLNativeWindowType; |
| 35 | #else // !USE(EGL) || PLATFORM(GTK) |
| 36 | typedef uint64_t GLNativeWindowType; |
| 37 | #endif |
| 38 | |
| 39 | #if USE(CAIRO) |
| 40 | typedef struct _cairo_device cairo_device_t; |
| 41 | #endif |
| 42 | |
| 43 | namespace WebCore { |
| 44 | |
| 45 | class GLContext { |
| 46 | WTF_MAKE_NONCOPYABLE(GLContext); WTF_MAKE_FAST_ALLOCATED; |
| 47 | public: |
| 48 | WEBCORE_EXPORT static std::unique_ptr<GLContext> createContextForWindow(GLNativeWindowType windowHandle, PlatformDisplay* = nullptr); |
| 49 | static std::unique_ptr<GLContext> createOffscreenContext(PlatformDisplay* = nullptr); |
| 50 | static std::unique_ptr<GLContext> createSharingContext(PlatformDisplay&); |
| 51 | static GLContext* current(); |
| 52 | static bool isExtensionSupported(const char* extensionList, const char* extension); |
| 53 | |
| 54 | PlatformDisplay& display() const { return m_display; } |
| 55 | unsigned version(); |
| 56 | |
| 57 | virtual ~GLContext(); |
| 58 | virtual bool makeContextCurrent(); |
| 59 | virtual void swapBuffers() = 0; |
| 60 | virtual void waitNative() = 0; |
| 61 | virtual bool canRenderToDefaultFramebuffer() = 0; |
| 62 | virtual IntSize defaultFrameBufferSize() = 0; |
| 63 | virtual void swapInterval(int) = 0; |
| 64 | |
| 65 | virtual bool isEGLContext() const = 0; |
| 66 | |
| 67 | #if USE(CAIRO) |
| 68 | virtual cairo_device_t* cairoDevice() = 0; |
| 69 | #endif |
| 70 | |
| 71 | #if ENABLE(GRAPHICS_CONTEXT_3D) |
| 72 | virtual PlatformGraphicsContext3D platformContext() = 0; |
| 73 | #endif |
| 74 | |
| 75 | #if PLATFORM(X11) |
| 76 | private: |
| 77 | static void addActiveContext(GLContext*); |
| 78 | static void removeActiveContext(GLContext*); |
| 79 | static void cleanupActiveContextsAtExit(); |
| 80 | #endif |
| 81 | |
| 82 | protected: |
| 83 | GLContext(PlatformDisplay&); |
| 84 | |
| 85 | PlatformDisplay& m_display; |
| 86 | unsigned m_version { 0 }; |
| 87 | }; |
| 88 | |
| 89 | } // namespace WebCore |
| 90 | |
| 91 | #endif // GLContext_h |
| 92 | |