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.h"
11 #include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
12 #import "flutter/shell/platform/darwin/ios/ios_external_texture_gl.h"
13 
14 namespace flutter {
15 
17  resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]);
18  if (resource_context_ != nullptr) {
19  context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3
20  sharegroup:resource_context_.get().sharegroup]);
21  } else {
22  resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]);
23  context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2
24  sharegroup:resource_context_.get().sharegroup]);
25  }
26 }
27 
29  if (main_context_) {
30  main_context_->releaseResourcesAndAbandonContext();
31  }
32 }
33 
34 std::unique_ptr<IOSRenderTargetGL> IOSContextGL::CreateRenderTarget(
36  return std::make_unique<IOSRenderTargetGL>(std::move(layer), context_);
37 }
38 
39 // |IOSContext|
40 sk_sp<GrDirectContext> IOSContextGL::CreateResourceContext() {
41  if (![EAGLContext setCurrentContext:resource_context_.get()]) {
42  FML_DLOG(INFO) << "Could not make resource context current on IO thread. Async texture uploads "
43  "will be disabled. On Simulators, this is expected.";
44  return nullptr;
45  }
46 
48  GrBackend::kOpenGL_GrBackend, GPUSurfaceGLDelegate::GetDefaultPlatformGLInterface());
49 }
50 
51 // |IOSContext|
52 sk_sp<GrDirectContext> IOSContextGL::GetMainContext() const {
53  return main_context_;
54 }
55 
56 void IOSContextGL::SetMainContext(const sk_sp<GrDirectContext>& main_context) {
57  main_context_ = main_context;
58 }
59 
60 // |IOSContext|
61 std::unique_ptr<GLContextResult> IOSContextGL::MakeCurrent() {
62  return std::make_unique<GLContextSwitch>(
63  std::make_unique<IOSSwitchableGLContext>(context_.get()));
64 }
65 
66 // |IOSContext|
67 std::unique_ptr<Texture> IOSContextGL::CreateExternalTexture(
68  int64_t texture_id,
69  fml::scoped_nsobject<NSObject<FlutterTexture>> texture) {
70  return std::make_unique<IOSExternalTextureGL>(texture_id, std::move(texture));
71 }
72 
73 } // namespace flutter
G_BEGIN_DECLS FlTexture * texture
std::unique_ptr< IOSRenderTargetGL > CreateRenderTarget(fml::scoped_nsobject< CAEAGLLayer > layer)
void reset(NST object=nil)
void SetMainContext(const sk_sp< GrDirectContext > &main_context)
int64_t texture_id
std::unique_ptr< GLContextResult > MakeCurrent() override
When using client rendering APIs whose contexts need to be bound to a specific thread, the engine will call this method to give the on-screen context a chance to bind to the current thread.
std::unique_ptr< Texture > CreateExternalTexture(int64_t texture_id, fml::scoped_nsobject< NSObject< FlutterTexture >> texture) override
Creates an external texture proxy of the appropriate client rendering API.
static sk_sp< GrDirectContext > CreateCompatibleResourceLoadingContext(GrBackend backend, sk_sp< const GrGLInterface > gl_interface)
sk_sp< GrDirectContext > GetMainContext() const override
Accessor for the Skia context associated with IOSSurfaces and the raster thread.
sk_sp< GrDirectContext > CreateResourceContext() override
Create a resource context for use on the IO task runner. This resource context is used by Skia to upl...
#define FML_DLOG(severity)
Definition: logging.h:85
static sk_sp< const GrGLInterface > GetDefaultPlatformGLInterface()