1
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8#ifndef SkNativeGLContext_DEFINED
9#define SkNativeGLContext_DEFINED
10
11#include "SkGLContextHelper.h"
12
13/* This struct is taken from a mesa demo.  Please update as required */
14static const struct { int major, minor; } gl_versions[] = {
15   {1, 0},
16   {1, 1},
17   {1, 2},
18   {1, 3},
19   {1, 4},
20   {1, 5},
21   {2, 0},
22   {2, 1},
23   {3, 0},
24   {3, 1},
25   {3, 2},
26   {3, 3},
27   {4, 0},
28   {4, 1},
29   {4, 2},
30   {4, 3},
31   {4, 4},
32   {0, 0} /* end of list */
33};
34#define NUM_GL_VERSIONS SK_ARRAY_COUNT(gl_versions)
35
36#if defined(SK_BUILD_FOR_MAC)
37    #include <OpenGL/OpenGL.h>
38#elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL)
39    #include <GLES2/gl2.h>
40    #include <EGL/egl.h>
41#elif defined(SK_BUILD_FOR_UNIX)
42    #include <X11/Xlib.h>
43    #include <GL/glx.h>
44#elif defined(SK_BUILD_FOR_WIN32)
45    #include <windows.h>
46    #include <GL/GL.h>
47    #include "SkWGL.h"
48#endif
49
50class SkNativeGLContext : public SkGLContextHelper {
51public:
52    SkNativeGLContext();
53
54    virtual ~SkNativeGLContext();
55
56    virtual void makeCurrent() const SK_OVERRIDE;
57    virtual void swapBuffers() const SK_OVERRIDE;
58
59    class AutoContextRestore {
60    public:
61        AutoContextRestore();
62        ~AutoContextRestore();
63
64    private:
65    #if defined(SK_BUILD_FOR_MAC)
66        CGLContextObj fOldCGLContext;
67    #elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL)
68        EGLContext fOldEGLContext;
69        EGLDisplay fOldDisplay;
70        EGLSurface fOldSurface;
71    #elif defined(SK_BUILD_FOR_UNIX)
72        GLXContext fOldGLXContext;
73        Display* fOldDisplay;
74        GLXDrawable fOldDrawable;
75    #elif defined(SK_BUILD_FOR_WIN32)
76        HDC fOldHDC;
77        HGLRC fOldHGLRC;
78
79    #elif defined(SK_BUILD_FOR_IOS)
80        void* fEAGLContext;
81    #endif
82    };
83
84protected:
85    virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) SK_OVERRIDE;
86    virtual void destroyGLContext() SK_OVERRIDE;
87
88private:
89#if defined(SK_BUILD_FOR_MAC)
90    CGLContextObj fContext;
91#elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL)
92    EGLContext fContext;
93    EGLDisplay fDisplay;
94    EGLSurface fSurface;
95#elif defined(SK_BUILD_FOR_UNIX)
96    GLXContext fContext;
97    Display* fDisplay;
98    Pixmap fPixmap;
99    GLXPixmap fGlxPixmap;
100#elif defined(SK_BUILD_FOR_WIN32)
101    HWND fWindow;
102    HDC fDeviceContext;
103    HGLRC fGlRenderContext;
104    static ATOM gWC;
105    SkWGLPbufferContext* fPbufferContext;
106#elif defined(SK_BUILD_FOR_IOS)
107    void* fEAGLContext;
108#endif
109};
110
111#endif
112