9 #include "flutter/fml/closure.h"
31 std::stringstream stream;
35 stream <<
"_unknown_";
41 stream <<
"_fragment_";
44 stream <<
"_compute_";
51 ShaderLibraryGLES::ShaderLibraryGLES(
52 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries) {
54 auto iterator = [&functions, library_id = library_id_](
auto type,
61 functions[ShaderKey{key_name, stage}] = std::shared_ptr<ShaderFunctionGLES>(
62 new ShaderFunctionGLES(library_id,
70 for (
auto library : shader_libraries) {
71 auto blob_library = ShaderArchive{std::move(library)};
72 if (!blob_library.IsValid()) {
76 blob_library.IterateAllShaders(iterator);
79 functions_ = functions;
92 std::shared_ptr<const ShaderFunction> ShaderLibraryGLES::GetFunction(
93 std::string_view name,
97 if (
auto found = functions_.find(key); found != functions_.end()) {
104 void ShaderLibraryGLES::RegisterFunction(std::string name,
106 std::shared_ptr<fml::Mapping> code,
107 RegistrationCallback callback) {
109 callback = [](
auto) {};
111 fml::ScopedCleanupClosure auto_fail([callback]() { callback(
false); });
113 code->GetMapping() ==
nullptr) {
117 const auto key = ShaderKey{name, stage};
118 WriterLock lock(functions_mutex_);
119 if (functions_.count(key) != 0) {
121 <<
" has already been registered.";
124 functions_[key] = std::shared_ptr<ShaderFunctionGLES>(
new ShaderFunctionGLES(
135 void ShaderLibraryGLES::UnregisterFunction(std::string name,
137 ReaderLock lock(functions_mutex_);
139 const auto key = ShaderKey{name, stage};
141 auto found = functions_.find(key);
142 if (found == functions_.end()) {
144 <<
" was not found, so it couldn't be unregistered.";
148 functions_.erase(found);