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 | |
| 11 | #include "SkGLContext.h" |
| 12 | |
| 13 | #if defined(SK_BUILD_FOR_MAC) |
| 14 | #include <AGL/agl.h> |
djsollen@google.com | 5862929 | 2011-11-03 13:08:29 +0000 | [diff] [blame] | 15 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 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 | |
| 26 | class SkNativeGLContext : public SkGLContext { |
| 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) |
| 41 | AGLContext fOldAGLContext; |
| 42 | #elif defined(SK_BUILD_FOR_UNIX) |
| 43 | GLXContext fOldGLXContext; |
| 44 | Display* fOldDisplay; |
| 45 | GLXDrawable fOldDrawable; |
| 46 | #elif defined(SK_BUILD_FOR_WIN32) |
| 47 | HDC fOldHDC; |
| 48 | HGLRC fOldHGLRC; |
djsollen@google.com | 5862929 | 2011-11-03 13:08:29 +0000 | [diff] [blame] | 49 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 50 | EGLContext fOldEGLContext; |
| 51 | EGLDisplay fOldDisplay; |
| 52 | EGLSurface fOldSurface; |
bsalomon@google.com | 2b64f84 | 2012-10-02 15:25:12 +0000 | [diff] [blame^] | 53 | #elif defined(SK_BUILD_FOR_IOS) |
| 54 | void* fEAGLContext; |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 55 | #endif |
| 56 | }; |
| 57 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 58 | protected: |
| 59 | virtual const GrGLInterface* createGLContext() SK_OVERRIDE; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 60 | virtual void destroyGLContext() SK_OVERRIDE; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 61 | |
| 62 | private: |
| 63 | #if defined(SK_BUILD_FOR_MAC) |
| 64 | AGLContext fContext; |
| 65 | #elif defined(SK_BUILD_FOR_UNIX) |
| 66 | GLXContext fContext; |
| 67 | Display* fDisplay; |
| 68 | Pixmap fPixmap; |
| 69 | GLXPixmap fGlxPixmap; |
| 70 | #elif defined(SK_BUILD_FOR_WIN32) |
| 71 | HWND fWindow; |
| 72 | HDC fDeviceContext; |
| 73 | HGLRC fGlRenderContext; |
| 74 | static ATOM gWC; |
djsollen@google.com | 5862929 | 2011-11-03 13:08:29 +0000 | [diff] [blame] | 75 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 76 | EGLContext fContext; |
| 77 | EGLDisplay fDisplay; |
| 78 | EGLSurface fSurface; |
bsalomon@google.com | 2b64f84 | 2012-10-02 15:25:12 +0000 | [diff] [blame^] | 79 | #elif defined(SK_BUILD_FOR_IOS) |
| 80 | void* fEAGLContext; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 81 | #endif |
| 82 | }; |
| 83 | |
| 84 | #endif |