Flutter Engine
 
Loading...
Searching...
No Matches
fragment_program.cc
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
8
9namespace impeller::interop {
10
11FragmentProgram::FragmentProgram(const std::shared_ptr<fml::Mapping>& data) {
12 if (data == nullptr || data->GetSize() == 0) {
13 VALIDATION_LOG << "No data provided to create fragment program.";
14 return;
15 }
16
18
19 for (const auto& stage : stages) {
20 if (auto data = stage.second) {
21 stages_[stage.first] = std::move(data);
22 }
23 }
24
25 if (stages_.empty()) {
26 VALIDATION_LOG << "No valid runtime stages present in fragment program.";
27 return;
28 }
29
30 is_valid_ = true;
31}
32
34
36 return is_valid_;
37}
38
39static std::string AvailableStagesAsString(
40 const std::set<RuntimeStageBackend>& stages) {
41 std::stringstream stream;
42 size_t count = 0;
43 for (const auto& stage : stages) {
44 stream << RuntimeStageBackendToString(stage);
45 count++;
46 if (count != stages.size()) {
47 stream << ", ";
48 }
49 }
50 return stream.str();
51}
52
53std::shared_ptr<RuntimeStage> FragmentProgram::FindRuntimeStage(
54 RuntimeStageBackend backend) const {
55 if (backend == RuntimeStageBackend::kOpenGLES3) {
57 }
58 auto found = stages_.find(backend);
59 if (found == stages_.end()) {
60 VALIDATION_LOG << "Could not find runtime shader for backend: "
62 << ". Shaders were packaged for "
63 << AvailableStagesAsString(GetAvailableStages())
64 << ". Check your shader compiler options.";
65 return nullptr;
66 }
67 return found->second;
68}
69
71 switch (backend) {
73 return "SKSL";
75 return "Metal";
77 return "OpenGL ES2";
79 return "OpenGL ES3";
81 return "Vulkan";
82 }
83 return "Unknown";
84}
85
86std::set<RuntimeStageBackend> FragmentProgram::GetAvailableStages() const {
87 std::set<RuntimeStageBackend> stages;
88 for (const auto& stage : stages_) {
89 stages.insert(stage.first);
90 }
91 return stages;
92}
93
94} // namespace impeller::interop
static Map DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
std::shared_ptr< RuntimeStage > FindRuntimeStage(RuntimeStageBackend backend) const
FragmentProgram(const std::shared_ptr< fml::Mapping > &mapping)
const char * RuntimeStageBackendToString(RuntimeStageBackend backend)
static std::string AvailableStagesAsString(const std::set< RuntimeStageBackend > &stages)
std::shared_ptr< const fml::Mapping > data
#define VALIDATION_LOG
Definition validation.h:91