Flutter Impeller
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 
9 namespace impeller::interop {
10 
11 FragmentProgram::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  if (!stages.ok()) {
19  VALIDATION_LOG << "Failed to decode runtime stages: " << stages.status();
20  return;
21  }
22 
23  for (const auto& stage : stages.value()) {
24  if (auto data = stage.second) {
25  stages_[stage.first] = std::move(data);
26  }
27  }
28 
29  if (stages_.empty()) {
30  VALIDATION_LOG << "No valid runtime stages present in fragment program.";
31  return;
32  }
33 
34  is_valid_ = true;
35 }
36 
38 
40  return is_valid_;
41 }
42 
43 static std::string AvailableStagesAsString(
44  const std::set<RuntimeStageBackend>& stages) {
45  std::stringstream stream;
46  size_t count = 0;
47  for (const auto& stage : stages) {
48  stream << RuntimeStageBackendToString(stage);
49  count++;
50  if (count != stages.size()) {
51  stream << ", ";
52  }
53  }
54  return stream.str();
55 }
56 
57 std::shared_ptr<RuntimeStage> FragmentProgram::FindRuntimeStage(
58  RuntimeStageBackend backend) const {
59  if (backend == RuntimeStageBackend::kOpenGLES3) {
61  }
62  auto found = stages_.find(backend);
63  if (found == stages_.end()) {
64  VALIDATION_LOG << "Could not find runtime shader for backend: "
65  << RuntimeStageBackendToString(backend)
66  << ". Shaders were packaged for "
67  << AvailableStagesAsString(GetAvailableStages())
68  << ". Check your shader compiler options.";
69  return nullptr;
70  }
71  return found->second;
72 }
73 
75  switch (backend) {
77  return "SKSL";
79  return "Metal";
81  return "OpenGL ES2";
83  return "OpenGL ES3";
85  return "Vulkan";
86  }
87  return "Unknown";
88 }
89 
90 std::set<RuntimeStageBackend> FragmentProgram::GetAvailableStages() const {
91  std::set<RuntimeStageBackend> stages;
92  for (const auto& stage : stages_) {
93  stages.insert(stage.first);
94  }
95  return stages;
96 }
97 
98 } // namespace impeller::interop
static absl::StatusOr< 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
Definition: texture_gles.cc:69
#define VALIDATION_LOG
Definition: validation.h:91