Flutter Engine
ios_surface_metal.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_metal.h"
6 
7 #include "flutter/shell/gpu/gpu_surface_metal.h"
8 #import "flutter/shell/platform/darwin/ios/ios_context_metal.h"
9 
10 namespace flutter {
11 
12 static IOSContextMetal* CastToMetalContext(const std::shared_ptr<IOSContext>& context) {
13  return reinterpret_cast<IOSContextMetal*>(context.get());
14 }
15 
17  std::shared_ptr<IOSContext> context,
18  FlutterPlatformViewsController* platform_views_controller)
19  : IOSSurface(std::move(context), platform_views_controller), layer_(std::move(layer)) {
20  if (!layer_) {
21  return;
22  }
23 
24  auto metal_context = CastToMetalContext(GetContext());
25 
26  layer_.get().device = metal_context->GetDevice().get();
27  layer_.get().presentsWithTransaction = YES;
28 
29  is_valid_ = true;
30 }
31 
32 // |IOSSurface|
34 
35 // |IOSSurface|
36 bool IOSSurfaceMetal::IsValid() const {
37  return is_valid_;
38 }
39 
40 // |IOSSurface|
41 void IOSSurfaceMetal::UpdateStorageSizeIfNecessary() {
42  // Nothing to do.
43 }
44 
45 // |IOSSurface|
46 std::unique_ptr<Surface> IOSSurfaceMetal::CreateGPUSurface(GrDirectContext* /* unused */) {
47  auto metal_context = CastToMetalContext(GetContext());
48 
49  return std::make_unique<GPUSurfaceMetal>(this, // Metal surface delegate
50  layer_, // layer
51  metal_context->GetMainContext(), // context
52  metal_context->GetMainCommandQueue() // command queue
53  );
54 }
55 
56 // |GPUSurfaceDelegate|
57 ExternalViewEmbedder* IOSSurfaceMetal::GetExternalViewEmbedder() {
58  return GetSurfaceExternalViewEmbedder().get();
59 }
60 
61 } // namespace flutter
std::shared_ptr< IOSContext > GetContext() const
Definition: ios_surface.mm:64
Definition: ref_ptr.h:252
static IOSContextMetal * CastToMetalContext(const std::shared_ptr< IOSContext > &context)
std::shared_ptr< IOSExternalViewEmbedder > GetSurfaceExternalViewEmbedder() const
Definition: ios_surface.mm:68
IOSSurfaceMetal(fml::scoped_nsobject< CAMetalLayer > layer, std::shared_ptr< IOSContext > context, FlutterPlatformViewsController *platform_views_controller)