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(CreateContextFlags flags, const SurfaceCaps& caps,
39                NSOpenGLContext* context, bool isOffscreen);
40 
41   ~GLContextCGL();
42 
GetContextType()43   virtual GLContextType GetContextType() const override {
44     return GLContextType::CGL;
45   }
46 
Cast(GLContext * gl)47   static GLContextCGL* Cast(GLContext* gl) {
48     MOZ_ASSERT(gl->GetContextType() == GLContextType::CGL);
49     return static_cast<GLContextCGL*>(gl);
50   }
51 
GetNSOpenGLContext()52   NSOpenGLContext* GetNSOpenGLContext() const { return mContext; }
53   CGLContextObj GetCGLContext() const;
54 
55   // Can be called on any thread
56   static void DisplayReconfigurationCallback(CGDirectDisplayID aDisplay,
57                                              CGDisplayChangeSummaryFlags aFlags,
58                                              void* aUserInfo);
59 
60   // Call at the beginning of a frame, on contexts that should stay on the
61   // active GPU. This method will migrate the context to the new active GPU, if
62   // the active GPU has changed since the last call.
63   void MigrateToActiveGPU();
64 
65   virtual bool MakeCurrentImpl() const override;
66 
67   virtual bool IsCurrentImpl() const override;
68 
69   virtual GLenum GetPreferredARGB32Format() const override;
70 
71   virtual bool SwapBuffers() override;
72 
73   virtual void GetWSIInfo(nsCString* const out) const override;
74 
75   Maybe<SymbolLoader> GetSymbolLoader() const override;
76 };
77 
78 }  // namespace gl
79 }  // namespace mozilla
80 
81 #endif  // GLCONTEXTCGL_H_
82