9 #include "flutter/fml/closure.h"
32 std::stringstream stream;
36 stream <<
"_unknown_";
42 stream <<
"_fragment_";
45 stream <<
"_compute_";
52 ShaderLibraryGLES::ShaderLibraryGLES(
53 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries) {
55 auto iterator = [&functions, library_id = library_id_](
auto type,
62 functions[ShaderKey{key_name, stage}] = std::shared_ptr<ShaderFunctionGLES>(
63 new ShaderFunctionGLES(library_id,
71 for (
auto library : shader_libraries) {
74 if (!gles_archive || !gles_archive->IsValid()) {
78 gles_archive->IterateAllShaders(iterator);
81 functions_ = functions;
94 std::shared_ptr<const ShaderFunction> ShaderLibraryGLES::GetFunction(
95 std::string_view name,
99 if (
auto found = functions_.find(key); found != functions_.end()) {
100 return found->second;
106 void ShaderLibraryGLES::RegisterFunction(std::string name,
108 std::shared_ptr<fml::Mapping> code,
109 RegistrationCallback callback) {
111 callback = [](
auto) {};
113 fml::ScopedCleanupClosure auto_fail([callback]() { callback(
false); });
115 code->GetMapping() ==
nullptr) {
119 const auto key = ShaderKey{name, stage};
120 WriterLock lock(functions_mutex_);
121 if (functions_.count(key) != 0) {
123 <<
" has already been registered.";
126 functions_[key] = std::shared_ptr<ShaderFunctionGLES>(
new ShaderFunctionGLES(
137 void ShaderLibraryGLES::UnregisterFunction(std::string name,
139 ReaderLock lock(functions_mutex_);
141 const auto key = ShaderKey{name, stage};
143 auto found = functions_.find(key);
144 if (found == functions_.end()) {
146 <<
" was not found, so it couldn't be unregistered.";
150 functions_.erase(found);