Flutter Engine
ios_context_gl.mm
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 #import "flutter/shell/platform/darwin/ios/ios_context_gl.h"
6 
7 #import <OpenGLES/EAGL.h>
8 
9 #include "flutter/shell/common/shell_io_manager.h"
10 #include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
11 #import "flutter/shell/platform/darwin/ios/ios_external_texture_gl.h"
12 
13 namespace flutter {
14 
16  resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]);
17  if (resource_context_ != nullptr) {
18  context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3
19  sharegroup:resource_context_.get().sharegroup]);
20  } else {
21  resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]);
22  context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2
23  sharegroup:resource_context_.get().sharegroup]);
24  }
25 }
26 
27 IOSContextGL::~IOSContextGL() = default;
28 
29 std::unique_ptr<IOSRenderTargetGL> IOSContextGL::CreateRenderTarget(
31  return std::make_unique<IOSRenderTargetGL>(std::move(layer), context_);
32 }
33 
34 // |IOSContext|
35 sk_sp<GrDirectContext> IOSContextGL::CreateResourceContext() {
36  if (![EAGLContext setCurrentContext:resource_context_.get()]) {
37  FML_DLOG(INFO) << "Could not make resource context current on IO thread. Async texture uploads "
38  "will be disabled. On Simulators, this is expected.";
39  return nullptr;
40  }
41 
43  GrBackend::kOpenGL_GrBackend, GPUSurfaceGLDelegate::GetDefaultPlatformGLInterface());
44 }
45 
46 // |IOSContext|
47 std::unique_ptr<GLContextResult> IOSContextGL::MakeCurrent() {
48  return std::make_unique<GLContextSwitch>(
49  std::make_unique<IOSSwitchableGLContext>(context_.get()));
50 }
51 
52 // |IOSContext|
53 std::unique_ptr<Texture> IOSContextGL::CreateExternalTexture(
54  int64_t texture_id,
55  fml::scoped_nsobject<NSObject<FlutterTexture>> texture) {
56  return std::make_unique<IOSExternalTextureGL>(texture_id, std::move(texture));
57 }
58 
59 } // namespace flutter
std::unique_ptr< IOSRenderTargetGL > CreateRenderTarget(fml::scoped_nsobject< CAEAGLLayer > layer)
~IOSContextGL() override
void reset(NST object=nil)
static sk_sp< GrDirectContext > CreateCompatibleResourceLoadingContext(GrBackend backend, sk_sp< const GrGLInterface > gl_interface)
#define FML_DLOG(severity)
Definition: logging.h:85
static sk_sp< const GrGLInterface > GetDefaultPlatformGLInterface()