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 "Widget.h"
25#include <wtf/Noncopyable.h>
26#include <wtf/PassOwnPtr.h>
27
28typedef struct _cairo_device cairo_device_t;
29
30#if PLATFORM(X11)
31typedef struct _XDisplay Display;
32#endif
33
34namespace WebCore {
35
36class GLContext {
37    WTF_MAKE_NONCOPYABLE(GLContext);
38public:
39    static PassOwnPtr<GLContext> createContextForWindow(uint64_t windowHandle, GLContext* sharingContext);
40    static PassOwnPtr<GLContext> createOffscreenContext(GLContext* sharing = 0);
41    static GLContext* getCurrent();
42    static GLContext* sharingContext();
43
44    GLContext();
45    virtual ~GLContext();
46    virtual bool makeContextCurrent();
47    virtual void swapBuffers() = 0;
48    virtual void waitNative() = 0;
49    virtual bool canRenderToDefaultFramebuffer() = 0;
50    virtual IntSize defaultFrameBufferSize() = 0;
51    virtual cairo_device_t* cairoDevice() = 0;
52
53#if PLATFORM(X11)
54    static Display* sharedX11Display();
55    static void cleanupSharedX11Display();
56#endif
57
58    static void addActiveContext(GLContext*);
59    static void removeActiveContext(GLContext*);
60    static void cleanupActiveContextsAtExit();
61
62#if USE(3D_GRAPHICS)
63    virtual PlatformGraphicsContext3D platformContext() = 0;
64#endif
65};
66
67} // namespace WebCore
68
69#endif // GLContext_h
70