Flutter Engine
ios_surface_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_surface_gl.h"
6 
7 #include "flutter/fml/trace_event.h"
8 #include "flutter/shell/gpu/gpu_surface_gl.h"
9 #import "flutter/shell/platform/darwin/ios/ios_context_gl.h"
10 
11 namespace flutter {
12 
13 static IOSContextGL* CastToGLContext(const std::shared_ptr<IOSContext>& context) {
14  return reinterpret_cast<IOSContextGL*>(context.get());
15 }
16 
18  std::shared_ptr<IOSContext> context,
19  const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder)
20  : IOSSurface(context, external_view_embedder) {
21  render_target_ = CastToGLContext(context)->CreateRenderTarget(std::move(layer));
22 }
23 
24 IOSSurfaceGL::~IOSSurfaceGL() = default;
25 
26 // |IOSSurface|
27 bool IOSSurfaceGL::IsValid() const {
28  return render_target_->IsValid();
29 }
30 
31 // |IOSSurface|
33  if (IsValid()) {
34  render_target_->UpdateStorageSizeIfNecessary();
35  }
36 }
37 
38 // |IOSSurface|
39 std::unique_ptr<Surface> IOSSurfaceGL::CreateGPUSurface(GrDirectContext* gr_context) {
40  if (gr_context) {
41  return std::make_unique<GPUSurfaceGL>(sk_ref_sp(gr_context), this, true);
42  }
43  return std::make_unique<GPUSurfaceGL>(this, true);
44 }
45 
46 // |GPUSurfaceGLDelegate|
47 intptr_t IOSSurfaceGL::GLContextFBO(GLFrameInfo frame_info) const {
48  return IsValid() ? render_target_->GetFramebuffer() : GL_NONE;
49 }
50 
51 // |GPUSurfaceGLDelegate|
53  // The onscreen surface wraps a GL renderbuffer, which is extremely slow to read on iOS.
54  // Certain filter effects, in particular BackdropFilter, require making a copy of
55  // the current destination. For performance, the iOS surface will specify that it
56  // does not support readback so that the engine compositor can implement a workaround
57  // such as rendering the scene to an offscreen surface or Skia saveLayer.
58  return false;
59 }
60 
61 // |GPUSurfaceGLDelegate|
62 std::unique_ptr<GLContextResult> IOSSurfaceGL::GLContextMakeCurrent() {
63  if (!IsValid()) {
64  return std::make_unique<GLContextDefaultResult>(false);
65  }
66  bool update_if_necessary = render_target_->UpdateStorageSizeIfNecessary();
67  if (!update_if_necessary) {
68  return std::make_unique<GLContextDefaultResult>(false);
69  }
70  return GetContext()->MakeCurrent();
71 }
72 
73 // |GPUSurfaceGLDelegate|
75  // |GLContextMakeCurrent| should handle the scope of the gl context.
76  return true;
77 }
78 
79 // |GPUSurfaceGLDelegate|
80 bool IOSSurfaceGL::GLContextPresent(uint32_t fbo_id) {
81  TRACE_EVENT0("flutter", "IOSSurfaceGL::GLContextPresent");
82  return IsValid() && render_target_->PresentRenderBuffer();
83 }
84 
85 // |GPUSurfaceGLDelegate|
87  return GetSurfaceExternalViewEmbedder().get();
88 }
89 
90 } // namespace flutter
std::shared_ptr< IOSContext > GetContext() const
Definition: ios_surface.mm:61
std::unique_ptr< IOSRenderTargetGL > CreateRenderTarget(fml::scoped_nsobject< CAEAGLLayer > layer)
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
IOSSurfaceGL(fml::scoped_nsobject< CAEAGLLayer > layer, std::shared_ptr< IOSContext > context, const std::shared_ptr< IOSExternalViewEmbedder > &external_view_embedder=nullptr)
bool GLContextPresent(uint32_t fbo_id) override
~IOSSurfaceGL() override
ExternalViewEmbedder * GetExternalViewEmbedder() override
Gets the view embedder that controls how the Flutter layer hierarchy split into multiple chunks shoul...
std::unique_ptr< Surface > CreateGPUSurface(GrDirectContext *gr_context) override
std::shared_ptr< IOSExternalViewEmbedder > GetSurfaceExternalViewEmbedder() const
Definition: ios_surface.mm:65
static IOSContextGL * CastToGLContext(const std::shared_ptr< IOSContext > &context)
bool SurfaceSupportsReadback() const override
intptr_t GLContextFBO(GLFrameInfo frame_info) const override
bool GLContextClearCurrent() override
std::unique_ptr< GLContextResult > GLContextMakeCurrent() override
void UpdateStorageSizeIfNecessary() override
bool IsValid() const override