1 /* 2 * Copyright 2024 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "src/sksl/SkSLModule.h" 9 10 #include "include/core/SkString.h" 11 #include "src/utils/SkGetExecutablePath.h" 12 #include "src/utils/SkOSPath.h" 13 14 #include <fstream> 15 #ifdef SKSL_EXT 16 #include "src/sksl/sksl_ext.sksl.h" 17 #endif 18 namespace SkSL { 19 GetModuleData(ModuleType,const char * filename)20std::string GetModuleData(ModuleType /*name*/, const char* filename) { 21 #ifdef SKSL_EXT 22 return extModuleData[filename]; 23 #endif 24 std::string exePath = SkGetExecutablePath(); 25 SkString exeDir = SkOSPath::Dirname(exePath.c_str()); 26 SkString modulePath = SkOSPath::Join(exeDir.c_str(), filename); 27 std::ifstream in(std::string{modulePath.c_str()}); 28 std::string moduleSource{std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>()}; 29 if (in.rdstate()) { 30 SK_ABORT("Error reading %s\n", modulePath.c_str()); 31 } 32 return moduleSource; 33 } 34 35 } // namespace SkSL 36