bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 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 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 11 | #include "SkGLContextHelper.h" |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 12 | |
| 13 | #if defined(SK_BUILD_FOR_MAC) |
bsalomon@google.com | 682e1f9 | 2013-02-14 15:10:59 +0000 | [diff] [blame] | 14 | #include <OpenGL/OpenGL.h> |
borenet@google.com | 7158e6a | 2012-11-01 17:43:44 +0000 | [diff] [blame] | 15 | #elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL) |
djsollen@google.com | 5862929 | 2011-11-03 13:08:29 +0000 | [diff] [blame] | 16 | #include <GLES2/gl2.h> |
| 17 | #include <EGL/egl.h> |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 18 | #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.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 26 | class SkNativeGLContext : public SkGLContextHelper { |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 27 | public: |
| 28 | SkNativeGLContext(); |
| 29 | |
| 30 | virtual ~SkNativeGLContext(); |
| 31 | |
| 32 | virtual void makeCurrent() const SK_OVERRIDE; |
| 33 | |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 34 | class AutoContextRestore { |
| 35 | public: |
| 36 | AutoContextRestore(); |
| 37 | ~AutoContextRestore(); |
| 38 | |
| 39 | private: |
| 40 | #if defined(SK_BUILD_FOR_MAC) |
bsalomon@google.com | 682e1f9 | 2013-02-14 15:10:59 +0000 | [diff] [blame] | 41 | CGLContextObj fOldCGLContext; |
borenet@google.com | 7158e6a | 2012-11-01 17:43:44 +0000 | [diff] [blame] | 42 | #elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL) |
| 43 | EGLContext fOldEGLContext; |
| 44 | EGLDisplay fOldDisplay; |
| 45 | EGLSurface fOldSurface; |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 46 | #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.com | 7158e6a | 2012-11-01 17:43:44 +0000 | [diff] [blame] | 53 | |
bsalomon@google.com | 2b64f84 | 2012-10-02 15:25:12 +0000 | [diff] [blame] | 54 | #elif defined(SK_BUILD_FOR_IOS) |
| 55 | void* fEAGLContext; |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 56 | #endif |
| 57 | }; |
| 58 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 59 | protected: |
| 60 | virtual const GrGLInterface* createGLContext() SK_OVERRIDE; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 61 | virtual void destroyGLContext() SK_OVERRIDE; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 62 | |
| 63 | private: |
| 64 | #if defined(SK_BUILD_FOR_MAC) |
bsalomon@google.com | 682e1f9 | 2013-02-14 15:10:59 +0000 | [diff] [blame] | 65 | CGLContextObj fContext; |
borenet@google.com | 7158e6a | 2012-11-01 17:43:44 +0000 | [diff] [blame] | 66 | #elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL) |
| 67 | EGLContext fContext; |
| 68 | EGLDisplay fDisplay; |
| 69 | EGLSurface fSurface; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 70 | #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.com | 2b64f84 | 2012-10-02 15:25:12 +0000 | [diff] [blame] | 80 | #elif defined(SK_BUILD_FOR_IOS) |
| 81 | void* fEAGLContext; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 82 | #endif |
| 83 | }; |
| 84 | |
| 85 | #endif |