Home | History | Annotate | Download | only in gl
      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 #elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL)
     16     #include <GLES2/gl2.h>
     17     #include <EGL/egl.h>
     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 
     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_ANDROID) || defined(SK_BUILD_FOR_NACL)
     43         EGLContext fOldEGLContext;
     44         EGLDisplay fOldDisplay;
     45         EGLSurface fOldSurface;
     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;
     53 
     54     #elif defined(SK_BUILD_FOR_IOS)
     55         void* fEAGLContext;
     56     #endif
     57     };
     58 
     59 protected:
     60     virtual const GrGLInterface* createGLContext() SK_OVERRIDE;
     61     virtual void destroyGLContext() SK_OVERRIDE;
     62 
     63 private:
     64 #if defined(SK_BUILD_FOR_MAC)
     65     AGLContext fContext;
     66 #elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL)
     67     EGLContext fContext;
     68     EGLDisplay fDisplay;
     69     EGLSurface fSurface;
     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;
     80 #elif defined(SK_BUILD_FOR_IOS)
     81     void* fEAGLContext;
     82 #endif
     83 };
     84 
     85 #endif
     86