blob: 7254de1509cfb490d2aed8da1050ac0a861691c6 [file] [log] [blame]
bsalomon@google.com373a6632011-10-19 20:43:20 +00001
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
robertphillips@google.com6177e692013-02-28 20:16:25 +000011#include "SkGLContextHelper.h"
bsalomon@google.com373a6632011-10-19 20:43:20 +000012
13#if defined(SK_BUILD_FOR_MAC)
bsalomon@google.com682e1f92013-02-14 15:10:59 +000014 #include <OpenGL/OpenGL.h>
borenet@google.com7158e6a2012-11-01 17:43:44 +000015#elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL)
djsollen@google.com58629292011-11-03 13:08:29 +000016 #include <GLES2/gl2.h>
17 #include <EGL/egl.h>
bsalomon@google.com373a6632011-10-19 20:43:20 +000018#elif defined(SK_BUILD_FOR_UNIX)
19 #include <X11/Xlib.h>
20 #include <GL/glx.h>
21#elif defined(SK_BUILD_FOR_WIN32)
bungeman@google.com0d9e3da2013-12-03 15:23:37 +000022 #include <windows.h>
bsalomon@google.com373a6632011-10-19 20:43:20 +000023 #include <GL/GL.h>
24#endif
25
robertphillips@google.com6177e692013-02-28 20:16:25 +000026class SkNativeGLContext : public SkGLContextHelper {
bsalomon@google.com373a6632011-10-19 20:43:20 +000027public:
28 SkNativeGLContext();
29
30 virtual ~SkNativeGLContext();
31
32 virtual void makeCurrent() const SK_OVERRIDE;
djsollen@google.comc9542ca2013-10-09 18:25:38 +000033 virtual void swapBuffers() const SK_OVERRIDE;
bsalomon@google.com373a6632011-10-19 20:43:20 +000034
bsalomon@google.com57f5d982011-10-24 21:17:53 +000035 class AutoContextRestore {
36 public:
37 AutoContextRestore();
38 ~AutoContextRestore();
39
40 private:
41 #if defined(SK_BUILD_FOR_MAC)
bsalomon@google.com682e1f92013-02-14 15:10:59 +000042 CGLContextObj fOldCGLContext;
borenet@google.com7158e6a2012-11-01 17:43:44 +000043 #elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL)
44 EGLContext fOldEGLContext;
45 EGLDisplay fOldDisplay;
46 EGLSurface fOldSurface;
bsalomon@google.com57f5d982011-10-24 21:17:53 +000047 #elif defined(SK_BUILD_FOR_UNIX)
48 GLXContext fOldGLXContext;
49 Display* fOldDisplay;
50 GLXDrawable fOldDrawable;
51 #elif defined(SK_BUILD_FOR_WIN32)
52 HDC fOldHDC;
53 HGLRC fOldHGLRC;
borenet@google.com7158e6a2012-11-01 17:43:44 +000054
bsalomon@google.com2b64f842012-10-02 15:25:12 +000055 #elif defined(SK_BUILD_FOR_IOS)
56 void* fEAGLContext;
bsalomon@google.com57f5d982011-10-24 21:17:53 +000057 #endif
58 };
59
bsalomon@google.com373a6632011-10-19 20:43:20 +000060protected:
61 virtual const GrGLInterface* createGLContext() SK_OVERRIDE;
bsalomon@google.com74913722011-10-27 20:44:19 +000062 virtual void destroyGLContext() SK_OVERRIDE;
bsalomon@google.com373a6632011-10-19 20:43:20 +000063
64private:
65#if defined(SK_BUILD_FOR_MAC)
bsalomon@google.com682e1f92013-02-14 15:10:59 +000066 CGLContextObj fContext;
borenet@google.com7158e6a2012-11-01 17:43:44 +000067#elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_NACL)
68 EGLContext fContext;
69 EGLDisplay fDisplay;
70 EGLSurface fSurface;
bsalomon@google.com373a6632011-10-19 20:43:20 +000071#elif defined(SK_BUILD_FOR_UNIX)
72 GLXContext fContext;
73 Display* fDisplay;
74 Pixmap fPixmap;
75 GLXPixmap fGlxPixmap;
76#elif defined(SK_BUILD_FOR_WIN32)
77 HWND fWindow;
78 HDC fDeviceContext;
79 HGLRC fGlRenderContext;
80 static ATOM gWC;
bsalomon@google.com2b64f842012-10-02 15:25:12 +000081#elif defined(SK_BUILD_FOR_IOS)
82 void* fEAGLContext;
bsalomon@google.com373a6632011-10-19 20:43:20 +000083#endif
84};
85
86#endif