blob: 52118da86ed9182a5baf94f5d8d17b2064ef9ea8 [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
11#include "SkGLContext.h"
12
13#if defined(SK_BUILD_FOR_MAC)
14 #include <AGL/agl.h>
djsollen@google.com58629292011-11-03 13:08:29 +000015#elif defined(SK_BUILD_FOR_ANDROID)
16 #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)
22 #include <Windows.h>
23 #include <GL/GL.h>
24#endif
25
26class SkNativeGLContext : public SkGLContext {
27public:
28 SkNativeGLContext();
29
30 virtual ~SkNativeGLContext();
31
32 virtual void makeCurrent() const SK_OVERRIDE;
33
bsalomon@google.com57f5d982011-10-24 21:17:53 +000034 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_UNIX)
43 GLXContext fOldGLXContext;
44 Display* fOldDisplay;
45 GLXDrawable fOldDrawable;
46 #elif defined(SK_BUILD_FOR_WIN32)
47 HDC fOldHDC;
48 HGLRC fOldHGLRC;
djsollen@google.com58629292011-11-03 13:08:29 +000049 #elif defined(SK_BUILD_FOR_ANDROID)
50 EGLContext fOldEGLContext;
51 EGLDisplay fOldDisplay;
52 EGLSurface fOldSurface;
bsalomon@google.com2b64f842012-10-02 15:25:12 +000053 #elif defined(SK_BUILD_FOR_IOS)
54 void* fEAGLContext;
bsalomon@google.com57f5d982011-10-24 21:17:53 +000055 #endif
56 };
57
bsalomon@google.com373a6632011-10-19 20:43:20 +000058protected:
59 virtual const GrGLInterface* createGLContext() SK_OVERRIDE;
bsalomon@google.com74913722011-10-27 20:44:19 +000060 virtual void destroyGLContext() SK_OVERRIDE;
bsalomon@google.com373a6632011-10-19 20:43:20 +000061
62private:
63#if defined(SK_BUILD_FOR_MAC)
64 AGLContext fContext;
65#elif defined(SK_BUILD_FOR_UNIX)
66 GLXContext fContext;
67 Display* fDisplay;
68 Pixmap fPixmap;
69 GLXPixmap fGlxPixmap;
70#elif defined(SK_BUILD_FOR_WIN32)
71 HWND fWindow;
72 HDC fDeviceContext;
73 HGLRC fGlRenderContext;
74 static ATOM gWC;
djsollen@google.com58629292011-11-03 13:08:29 +000075#elif defined(SK_BUILD_FOR_ANDROID)
76 EGLContext fContext;
77 EGLDisplay fDisplay;
78 EGLSurface fSurface;
bsalomon@google.com2b64f842012-10-02 15:25:12 +000079#elif defined(SK_BUILD_FOR_IOS)
80 void* fEAGLContext;
bsalomon@google.com373a6632011-10-19 20:43:20 +000081#endif
82};
83
84#endif