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> 15 16 #elif defined(SK_BUILD_FOR_ANDROID) 17 #include <GLES2/gl2.h> 18 #include <EGL/egl.h> 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 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; 50 #elif defined(SK_BUILD_FOR_ANDROID) 51 EGLContext fOldEGLContext; 52 EGLDisplay fOldDisplay; 53 EGLSurface fOldSurface; 54 #endif 55 }; 56 57 protected: 58 virtual const GrGLInterface* createGLContext() SK_OVERRIDE; 59 virtual void destroyGLContext() SK_OVERRIDE; 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; 74 #elif defined(SK_BUILD_FOR_ANDROID) 75 EGLContext fContext; 76 EGLDisplay fDisplay; 77 EGLSurface fSurface; 78 #endif 79 }; 80 81 #endif 82