blob: 4ab58fbd746e465b6a3f62472cf84028f1a22f82 [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>
15#elif defined(SK_BUILD_FOR_UNIX)
16 #include <X11/Xlib.h>
17 #include <GL/glx.h>
18#elif defined(SK_BUILD_FOR_WIN32)
19 #include <Windows.h>
20 #include <GL/GL.h>
21#endif
22
23class SkNativeGLContext : public SkGLContext {
24public:
25 SkNativeGLContext();
26
27 virtual ~SkNativeGLContext();
28
29 virtual void makeCurrent() const SK_OVERRIDE;
30
bsalomon@google.com57f5d982011-10-24 21:17:53 +000031 class AutoContextRestore {
32 public:
33 AutoContextRestore();
34 ~AutoContextRestore();
35
36 private:
37 #if defined(SK_BUILD_FOR_MAC)
38 AGLContext fOldAGLContext;
39 #elif defined(SK_BUILD_FOR_UNIX)
40 GLXContext fOldGLXContext;
41 Display* fOldDisplay;
42 GLXDrawable fOldDrawable;
43 #elif defined(SK_BUILD_FOR_WIN32)
44 HDC fOldHDC;
45 HGLRC fOldHGLRC;
46 #endif
47 };
48
bsalomon@google.com373a6632011-10-19 20:43:20 +000049protected:
50 virtual const GrGLInterface* createGLContext() SK_OVERRIDE;
bsalomon@google.com74913722011-10-27 20:44:19 +000051 virtual void destroyGLContext() SK_OVERRIDE;
bsalomon@google.com373a6632011-10-19 20:43:20 +000052
53private:
54#if defined(SK_BUILD_FOR_MAC)
55 AGLContext fContext;
56#elif defined(SK_BUILD_FOR_UNIX)
57 GLXContext fContext;
58 Display* fDisplay;
59 Pixmap fPixmap;
60 GLXPixmap fGlxPixmap;
61#elif defined(SK_BUILD_FOR_WIN32)
62 HWND fWindow;
63 HDC fDeviceContext;
64 HGLRC fGlRenderContext;
65 static ATOM gWC;
66#endif
67};
68
69#endif