Flutter Engine
ios_switchable_gl_context.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SWITCHABLE_GL_CONTEXT_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SWITCHABLE_GL_CONTEXT_H_
7 
8 #include "flutter/flow/gl_context_switch.h"
9 #include "flutter/fml/macros.h"
10 #include "flutter/fml/memory/thread_checker.h"
11 #include "flutter/fml/memory/weak_ptr.h"
12 
13 @class EAGLContext;
14 
15 namespace flutter {
16 
17 //------------------------------------------------------------------------------
18 /// The iOS implementation of a |SwitchableGLContext|.
19 ///
20 /// It wraps a pointer to an EAGLContext. When passed in the constructor of the |GLContextSwitch|,
21 /// this EAGLContext is set to current. When the |GLContextSwitch| destroys, the current context
22 /// will be restored to the context before setting this EAGLContext to current.
23 ///
24 /// Note: An |IOSSwitchableGLContext| doesn't retain the EAGLContext. Someone else must retain the
25 /// pointer and outlive all the |IOSSwitchableGLContext|. This object is meant to be only owned by a
26 /// |GLContextSwitch| and should be destroyed when The |GLContectSwitch| destroys.
28  public:
29  IOSSwitchableGLContext(EAGLContext* context);
30 
31  bool SetCurrent() override;
32 
33  bool RemoveCurrent() override;
34 
35  private:
36  // These pointers are managed by IOSRendererTarget/IOSContextGL or a 3rd party
37  // plugin that uses gl context. |IOSSwitchableGLContext| should never outlive
38  // those objects. Never release this pointer within this object.
39  EAGLContext* context_;
40  EAGLContext* previous_context_;
41 
42  FML_DECLARE_THREAD_CHECKER(checker);
43 
44  FML_DISALLOW_COPY_AND_ASSIGN(IOSSwitchableGLContext);
45 };
46 
47 } // namespace flutter
48 
49 #endif