Flutter Engine
 
Loading...
Searching...
No Matches
FlutterDarwinContextMetalImpeller.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
6
12#include "impeller/entity/mtl/entity_shaders.h"
13#include "impeller/entity/mtl/framebuffer_blend_shaders.h"
14#include "impeller/entity/mtl/modern_shaders.h"
15
17
18static std::shared_ptr<impeller::ContextMTL> CreateImpellerContext(
19 const impeller::Flags& flags,
20 const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch) {
21 std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
22 std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_data,
23 impeller_entity_shaders_length),
24 std::make_shared<fml::NonOwnedMapping>(impeller_modern_shaders_data,
25 impeller_modern_shaders_length),
26 std::make_shared<fml::NonOwnedMapping>(impeller_framebuffer_blend_shaders_data,
27 impeller_framebuffer_blend_shaders_length),
28 };
29 return impeller::ContextMTL::Create(flags, shader_mappings, is_gpu_disabled_sync_switch,
30 "Impeller Library");
31}
32
34
35- (instancetype)init:(const impeller::Flags&)flags
36 gpuDisabledSyncSwitch:
37 (const std::shared_ptr<const fml::SyncSwitch>&)is_gpu_disabled_sync_switch {
38 self = [super init];
39 if (self != nil) {
40 _context = CreateImpellerContext(flags, is_gpu_disabled_sync_switch);
41 FML_CHECK(_context) << "Could not create Metal Impeller Context.";
42 id<MTLDevice> device = _context->GetMTLDevice();
43 FML_CHECK(device) << "Could not acquire Metal device.";
44
45 CVMetalTextureCacheRef textureCache;
46 CVReturn cvReturn = CVMetalTextureCacheCreate(kCFAllocatorDefault, // allocator
47 nil, // cache attributes (nil default)
48 device, // metal device
49 nil, // texture attributes (nil default)
50 &textureCache // [out] cache
51 );
52
53 FML_CHECK(cvReturn == kCVReturnSuccess) << "Could not acquire Metal device.";
54 _textureCache.Reset(textureCache);
55 }
56 return self;
57}
58
60 createExternalTextureWithIdentifier:(int64_t)textureID
61 texture:(NSObject<FlutterTexture>*)texture {
62 return [[FlutterDarwinExternalTextureMetal alloc] initWithTextureCache:_textureCache
63 textureID:textureID
64 texture:texture
65 enableImpeller:YES];
66}
67
68@end
static std::shared_ptr< impeller::ContextMTL > CreateImpellerContext()
static std::shared_ptr< ContextMTL > Create(const Flags &flags, const std::vector< std::string > &shader_library_paths, std::shared_ptr< const fml::SyncSwitch > is_gpu_disabled_sync_switch)
VkDevice device
Definition main.cc:69
#define FML_CHECK(condition)
Definition logging.h:104
fml::CFRef< CVMetalTextureCacheRef > textureCache
id< FlutterKeyboardManagerEventContext > _context
Definition ref_ptr.h:261