michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: #ifndef SkNativeGLContext_DEFINED michael@0: #define SkNativeGLContext_DEFINED michael@0: michael@0: #include "SkGLContextHelper.h" michael@0: michael@0: #if defined(SK_BUILD_FOR_MAC) michael@0: #include michael@0: #elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL) michael@0: #include michael@0: #include michael@0: #elif defined(SK_BUILD_FOR_UNIX) michael@0: #include michael@0: #include michael@0: #elif defined(SK_BUILD_FOR_WIN32) michael@0: #include michael@0: #include michael@0: #endif michael@0: michael@0: class SkNativeGLContext : public SkGLContextHelper { michael@0: public: michael@0: SkNativeGLContext(); michael@0: michael@0: virtual ~SkNativeGLContext(); michael@0: michael@0: virtual void makeCurrent() const SK_OVERRIDE; michael@0: virtual void swapBuffers() const SK_OVERRIDE; michael@0: michael@0: class AutoContextRestore { michael@0: public: michael@0: AutoContextRestore(); michael@0: ~AutoContextRestore(); michael@0: michael@0: private: michael@0: #if defined(SK_BUILD_FOR_MAC) michael@0: CGLContextObj fOldCGLContext; michael@0: #elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL) michael@0: EGLContext fOldEGLContext; michael@0: EGLDisplay fOldDisplay; michael@0: EGLSurface fOldSurface; michael@0: #elif defined(SK_BUILD_FOR_UNIX) michael@0: GLXContext fOldGLXContext; michael@0: Display* fOldDisplay; michael@0: GLXDrawable fOldDrawable; michael@0: #elif defined(SK_BUILD_FOR_WIN32) michael@0: HDC fOldHDC; michael@0: HGLRC fOldHGLRC; michael@0: michael@0: #elif defined(SK_BUILD_FOR_IOS) michael@0: void* fEAGLContext; michael@0: #endif michael@0: }; michael@0: michael@0: protected: michael@0: virtual const GrGLInterface* createGLContext() SK_OVERRIDE; michael@0: virtual void destroyGLContext() SK_OVERRIDE; michael@0: michael@0: private: michael@0: #if defined(SK_BUILD_FOR_MAC) michael@0: CGLContextObj fContext; michael@0: #elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL) michael@0: EGLContext fContext; michael@0: EGLDisplay fDisplay; michael@0: EGLSurface fSurface; michael@0: #elif defined(SK_BUILD_FOR_UNIX) michael@0: GLXContext fContext; michael@0: Display* fDisplay; michael@0: Pixmap fPixmap; michael@0: GLXPixmap fGlxPixmap; michael@0: #elif defined(SK_BUILD_FOR_WIN32) michael@0: HWND fWindow; michael@0: HDC fDeviceContext; michael@0: HGLRC fGlRenderContext; michael@0: static ATOM gWC; michael@0: #elif defined(SK_BUILD_FOR_IOS) michael@0: void* fEAGLContext; michael@0: #endif michael@0: }; michael@0: michael@0: #endif