| Flutter Impeller |

context_mtl.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 #include "impeller/toolkit/interop/backend/metal/context_mtl.h"
6
7 #include "impeller/base/validation.h"
8 #include "impeller/entity/mtl/entity_shaders.h"
9 #include "impeller/entity/mtl/framebuffer_blend_shaders.h"
10 #include "impeller/entity/mtl/modern_shaders.h"
11 #include "impeller/renderer/backend/metal/context_mtl.h"
12 #include "impeller/renderer/mtl/compute_shaders.h"
13
14 namespace impeller::interop {
15
16 static std::vector<std::shared_ptr<fml::Mapping>>
17 CreateShaderLibraryMappings() {
18 return {std::make_shared<fml::NonOwnedMapping>(
19 impeller_entity_shaders_data, impeller_entity_shaders_length),
20 std::make_shared<fml::NonOwnedMapping>(
21 impeller_modern_shaders_data, impeller_modern_shaders_length),
22 std::make_shared<fml::NonOwnedMapping>(
23 impeller_framebuffer_blend_shaders_data,
24 impeller_framebuffer_blend_shaders_length),
25 std::make_shared<fml::NonOwnedMapping>(
26 impeller_compute_shaders_data, impeller_compute_shaders_length)};
27 }
28
29 ScopedObject<Context> ContextMTL::Create() {
30 auto impeller_context =
31 impeller::ContextMTL::Create(Flags{}, CreateShaderLibraryMappings(), //
32 std::make_shared<fml::SyncSwitch>(), //
33 "Impeller" //
34 );
35 if (!impeller_context) {
36 VALIDATION_LOG << "Could not create Impeller context.";
37 return {};
38 }
39 return Create(std::move(impeller_context));
40 }
41
42 ScopedObject<Context> ContextMTL::Create(
43 const std::shared_ptr<impeller::Context>& impeller_context) {
44 // Can't call Create because of private constructor. Adopt the raw pointer
45 // instead.
46 auto context = Adopt<Context>(new ContextMTL(impeller_context));
47 if (!context->IsValid()) {
48 VALIDATION_LOG << " Could not create valid context.";
49 return {};
50 }
51 return context;
52 }
53
54 ContextMTL::ContextMTL(const std::shared_ptr<impeller::Context>& context)
55 : Context(context),
56 swapchain_transients_(std::make_shared<SwapchainTransientsMTL>(
57 context->GetResourceAllocator())) {}
58
59 ContextMTL::~ContextMTL() = default;
60
61 const std::shared_ptr<SwapchainTransientsMTL>&
62 ContextMTL::GetSwapchainTransients() const {
63 return swapchain_transients_;
64 }
65
66 } // namespace impeller::interop
impeller::ContextMTL::Create
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)
Definition: context_mtl.mm:229
impeller::SwapchainTransientsMTL
A cache for the onscreen texture attachments used in surface_mtl.
Definition: swapchain_transients_mtl.h:25
impeller::interop::Context
Definition: context.h:16
impeller::interop::ContextMTL::GetSwapchainTransients
const std::shared_ptr< SwapchainTransientsMTL > & GetSwapchainTransients() const
Definition: context_mtl.mm:62
impeller::interop::ContextMTL::Create
static ScopedObject< Context > Create()
Definition: context_mtl.mm:29
impeller::interop::ContextMTL::ContextMTL
ContextMTL(const ContextMTL &)=delete
impeller::interop::ContextMTL::~ContextMTL
~ContextMTL() override
impeller::interop::ScopedObject
Definition: object.h:67
impeller::interop
Definition: context_gles.cc:12
impeller::interop::CreateShaderLibraryMappings
static std::vector< std::shared_ptr< fml::Mapping > > CreateShaderLibraryMappings()
Definition: context_mtl.mm:17
std
Definition: comparable.h:95
context_mtl.h
impeller::Flags
Definition: flags.h:9
context_mtl.h
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91