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 | |
| 16 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 17 | #include <GLES2/gl2.h> |
| 18 | #include <EGL/egl.h> |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 19 | #elif defined(SK_BUILD_FOR_UNIX) |
| 20 | #include <X11/Xlib.h> |
| 21 | #include <GL/glx.h> |
| 22 | #elif defined(SK_BUILD_FOR_WIN32) |
| 23 | #include <Windows.h> |
| 24 | #include <GL/GL.h> |
| 25 | #endif |
| 26 | |
| 27 | class SkNativeGLContext : public SkGLContext { |
| 28 | public: |
| 29 | SkNativeGLContext(); |
| 30 | |
| 31 | virtual ~SkNativeGLContext(); |
| 32 | |
| 33 | virtual void makeCurrent() const SK_OVERRIDE; |
| 34 | |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 35 | class AutoContextRestore { |
| 36 | public: |
| 37 | AutoContextRestore(); |
| 38 | ~AutoContextRestore(); |
| 39 | |
| 40 | private: |
| 41 | #if defined(SK_BUILD_FOR_MAC) |
| 42 | AGLContext fOldAGLContext; |
| 43 | #elif defined(SK_BUILD_FOR_UNIX) |
| 44 | GLXContext fOldGLXContext; |
| 45 | Display* fOldDisplay; |
| 46 | GLXDrawable fOldDrawable; |
| 47 | #elif defined(SK_BUILD_FOR_WIN32) |
| 48 | HDC fOldHDC; |
| 49 | HGLRC fOldHGLRC; |
djsollen@google.com | 5862929 | 2011-11-03 13:08:29 +0000 | [diff] [blame^] | 50 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 51 | EGLContext fOldEGLContext; |
| 52 | EGLDisplay fOldDisplay; |
| 53 | EGLSurface fOldSurface; |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 54 | #endif |
| 55 | }; |
| 56 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 57 | protected: |
| 58 | virtual const GrGLInterface* createGLContext() SK_OVERRIDE; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 59 | virtual void destroyGLContext() SK_OVERRIDE; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 60 | |
| 61 | private: |
| 62 | #if defined(SK_BUILD_FOR_MAC) |
| 63 | AGLContext fContext; |
| 64 | #elif defined(SK_BUILD_FOR_UNIX) |
| 65 | GLXContext fContext; |
| 66 | Display* fDisplay; |
| 67 | Pixmap fPixmap; |
| 68 | GLXPixmap fGlxPixmap; |
| 69 | #elif defined(SK_BUILD_FOR_WIN32) |
| 70 | HWND fWindow; |
| 71 | HDC fDeviceContext; |
| 72 | HGLRC fGlRenderContext; |
| 73 | static ATOM gWC; |
djsollen@google.com | 5862929 | 2011-11-03 13:08:29 +0000 | [diff] [blame^] | 74 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 75 | EGLContext fContext; |
| 76 | EGLDisplay fDisplay; |
| 77 | EGLSurface fSurface; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 78 | #endif |
| 79 | }; |
| 80 | |
| 81 | #endif |