blob: 27a8f09bacb396771d1edf1083e1e00dd68474b8 [file] [log] [blame]
bsalomon@google.com373a6632011-10-19 20:43:20 +00001
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
robertphillips@google.com6177e692013-02-28 20:16:25 +000011#include "SkGLContextHelper.h"
bsalomon@google.com373a6632011-10-19 20:43:20 +000012
13#if defined(SK_BUILD_FOR_MAC)
bsalomon@google.com682e1f92013-02-14 15:10:59 +000014 #include <OpenGL/OpenGL.h>
borenet@google.com7158e6a2012-11-01 17:43:44 +000015#elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL)
djsollen@google.com58629292011-11-03 13:08:29 +000016 #include <GLES2/gl2.h>
17 #include <EGL/egl.h>
bsalomon@google.com373a6632011-10-19 20:43:20 +000018#elif defined(SK_BUILD_FOR_UNIX)
19 #include <X11/Xlib.h>
20 #include <GL/glx.h>
21#elif defined(SK_BUILD_FOR_WIN32)
22 #include <Windows.h>
23 #include <GL/GL.h>
24#endif
25
robertphillips@google.com6177e692013-02-28 20:16:25 +000026class SkNativeGLContext : public SkGLContextHelper {
bsalomon@google.com373a6632011-10-19 20:43:20 +000027public:
28 SkNativeGLContext();
29
30 virtual ~SkNativeGLContext();
31
32 virtual void makeCurrent() const SK_OVERRIDE;
33
bsalomon@google.com57f5d982011-10-24 21:17:53 +000034 class AutoContextRestore {
35 public:
36 AutoContextRestore();
37 ~AutoContextRestore();
38
39 private:
40 #if defined(SK_BUILD_FOR_MAC)
bsalomon@google.com682e1f92013-02-14 15:10:59 +000041 CGLContextObj fOldCGLContext;
borenet@google.com7158e6a2012-11-01 17:43:44 +000042 #elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL)
43 EGLContext fOldEGLContext;
44 EGLDisplay fOldDisplay;
45 EGLSurface fOldSurface;
bsalomon@google.com57f5d982011-10-24 21:17:53 +000046 #elif defined(SK_BUILD_FOR_UNIX)
47 GLXContext fOldGLXContext;
48 Display* fOldDisplay;
49 GLXDrawable fOldDrawable;
50 #elif defined(SK_BUILD_FOR_WIN32)
51 HDC fOldHDC;
52 HGLRC fOldHGLRC;
borenet@google.com7158e6a2012-11-01 17:43:44 +000053
bsalomon@google.com2b64f842012-10-02 15:25:12 +000054 #elif defined(SK_BUILD_FOR_IOS)
55 void* fEAGLContext;
bsalomon@google.com57f5d982011-10-24 21:17:53 +000056 #endif
57 };
58
bsalomon@google.com373a6632011-10-19 20:43:20 +000059protected:
60 virtual const GrGLInterface* createGLContext() SK_OVERRIDE;
bsalomon@google.com74913722011-10-27 20:44:19 +000061 virtual void destroyGLContext() SK_OVERRIDE;
bsalomon@google.com373a6632011-10-19 20:43:20 +000062
63private:
64#if defined(SK_BUILD_FOR_MAC)
bsalomon@google.com682e1f92013-02-14 15:10:59 +000065 CGLContextObj fContext;
borenet@google.com7158e6a2012-11-01 17:43:44 +000066#elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL)
67 EGLContext fContext;
68 EGLDisplay fDisplay;
69 EGLSurface fSurface;
bsalomon@google.com373a6632011-10-19 20:43:20 +000070#elif defined(SK_BUILD_FOR_UNIX)
71 GLXContext fContext;
72 Display* fDisplay;
73 Pixmap fPixmap;
74 GLXPixmap fGlxPixmap;
75#elif defined(SK_BUILD_FOR_WIN32)
76 HWND fWindow;
77 HDC fDeviceContext;
78 HGLRC fGlRenderContext;
79 static ATOM gWC;
bsalomon@google.com2b64f842012-10-02 15:25:12 +000080#elif defined(SK_BUILD_FOR_IOS)
81 void* fEAGLContext;
bsalomon@google.com373a6632011-10-19 20:43:20 +000082#endif
83};
84
85#endif