blob: 36461ba7b2176d34eab4b498d02fcc77b6d6a588 [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
16#elif defined(SK_BUILD_FOR_ANDROID)
17 #include <GLES2/gl2.h>
18 #include <EGL/egl.h>
bsalomon@google.com373a6632011-10-19 20:43:20 +000019#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
27class SkNativeGLContext : public SkGLContext {
28public:
29 SkNativeGLContext();
30
31 virtual ~SkNativeGLContext();
32
33 virtual void makeCurrent() const SK_OVERRIDE;
34
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)
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;
djsollen@google.com58629292011-11-03 13:08:29 +000050 #elif defined(SK_BUILD_FOR_ANDROID)
51 EGLContext fOldEGLContext;
52 EGLDisplay fOldDisplay;
53 EGLSurface fOldSurface;
bsalomon@google.com57f5d982011-10-24 21:17:53 +000054 #endif
55 };
56
bsalomon@google.com373a6632011-10-19 20:43:20 +000057protected:
58 virtual const GrGLInterface* createGLContext() SK_OVERRIDE;
bsalomon@google.com74913722011-10-27 20:44:19 +000059 virtual void destroyGLContext() SK_OVERRIDE;
bsalomon@google.com373a6632011-10-19 20:43:20 +000060
61private:
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;
djsollen@google.com58629292011-11-03 13:08:29 +000074#elif defined(SK_BUILD_FOR_ANDROID)
75 EGLContext fContext;
76 EGLDisplay fDisplay;
77 EGLSurface fSurface;
bsalomon@google.com373a6632011-10-19 20:43:20 +000078#endif
79};
80
81#endif