1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef GLCONTEXTCGL_H_
8 #define GLCONTEXTCGL_H_
9 
10 #include "GLContext.h"
11 
12 #include "OpenGL/OpenGL.h"
13 
14 #ifdef __OBJC__
15 #  include <AppKit/NSOpenGL.h>
16 #else
17 typedef void NSOpenGLContext;
18 #endif
19 
20 #include <CoreGraphics/CGDisplayConfiguration.h>
21 
22 #include "mozilla/Atomics.h"
23 
24 class nsIWidget;
25 
26 namespace mozilla {
27 namespace gl {
28 
29 class GLContextCGL : public GLContext {
30   friend class GLContextProviderCGL;
31 
32   NSOpenGLContext* mContext;
33 
34   mozilla::Atomic<bool> mActiveGPUSwitchMayHaveOccurred;
35 
36  public:
37   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextCGL, override)
38   GLContextCGL(const GLContextDesc&, NSOpenGLContext* context);
39 
40   ~GLContextCGL();
41 
GetContextType()42   virtual GLContextType GetContextType() const override {
43     return GLContextType::CGL;
44   }
45 
Cast(GLContext * gl)46   static GLContextCGL* Cast(GLContext* gl) {
47     MOZ_ASSERT(gl->GetContextType() == GLContextType::CGL);
48     return static_cast<GLContextCGL*>(gl);
49   }
50 
GetNSOpenGLContext()51   NSOpenGLContext* GetNSOpenGLContext() const { return mContext; }
52   CGLContextObj GetCGLContext() const;
53 
54   // Can be called on any thread
55   static void DisplayReconfigurationCallback(CGDirectDisplayID aDisplay,
56                                              CGDisplayChangeSummaryFlags aFlags,
57                                              void* aUserInfo);
58 
59   // Call at the beginning of a frame, on contexts that should stay on the
60   // active GPU. This method will migrate the context to the new active GPU, if
61   // the active GPU has changed since the last call.
62   void MigrateToActiveGPU();
63 
64   virtual bool MakeCurrentImpl() const override;
65 
66   virtual bool IsCurrentImpl() const override;
67 
68   virtual GLenum GetPreferredARGB32Format() const override;
69 
70   virtual bool SwapBuffers() override;
71 
72   virtual void GetWSIInfo(nsCString* const out) const override;
73 
74   Maybe<SymbolLoader> GetSymbolLoader() const override;
75 };
76 
77 }  // namespace gl
78 }  // namespace mozilla
79 
80 #endif  // GLCONTEXTCGL_H_
81