9 #include "flutter/fml/closure.h"
31 std::stringstream stream;
35 stream <<
"_unknown_";
41 stream <<
"_fragment_";
44 stream <<
"_tessellation_control_";
47 stream <<
"_tessellation_evaluation_";
50 stream <<
"_compute_";
57 ShaderLibraryGLES::ShaderLibraryGLES(
58 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries) {
60 auto iterator = [&functions, library_id = library_id_](
auto type,
67 functions[ShaderKey{key_name, stage}] = std::shared_ptr<ShaderFunctionGLES>(
68 new ShaderFunctionGLES(library_id,
76 for (
auto library : shader_libraries) {
77 auto blob_library = BlobLibrary{std::move(library)};
78 if (!blob_library.IsValid()) {
82 blob_library.IterateAllBlobs(iterator);
85 functions_ = functions;
98 std::shared_ptr<const ShaderFunction> ShaderLibraryGLES::GetFunction(
99 std::string_view name,
103 if (
auto found = functions_.find(key); found != functions_.end()) {
104 return found->second;
110 void ShaderLibraryGLES::RegisterFunction(std::string name,
112 std::shared_ptr<fml::Mapping> code,
113 RegistrationCallback callback) {
115 callback = [](
auto) {};
117 fml::ScopedCleanupClosure auto_fail([callback]() { callback(
false); });
119 code->GetMapping() ==
nullptr) {
123 const auto key = ShaderKey{name, stage};
124 WriterLock lock(functions_mutex_);
125 if (functions_.count(key) != 0) {
127 <<
" has already been registered.";
130 functions_[key] = std::shared_ptr<ShaderFunctionGLES>(
new ShaderFunctionGLES(
141 void ShaderLibraryGLES::UnregisterFunction(std::string name,
143 ReaderLock lock(functions_mutex_);
145 const auto key = ShaderKey{name, stage};
147 auto found = functions_.find(key);
148 if (found != functions_.end()) {
150 <<
" was not found, so it couldn't be unregistered.";
154 functions_.erase(found);