-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "kind.h" | ||
|
||
#include <cstdint> | ||
#include <regex> | ||
#include <string> | ||
|
||
#include "hash.h" | ||
|
||
std::optional<Kind> GetKind(const std::string& content) { | ||
std::regex re(R"(^[ \t]*\/\/[ /\t]*kind[ \t]*[:=][ \t]*(\w+))", std::regex_constants::ECMAScript); | ||
std::cmatch match; | ||
if (!std::regex_search(content.data(), match, re)) { | ||
return std::nullopt; | ||
} | ||
return Kind { | ||
.str = match.str(1), | ||
.position = static_cast<std::uint32_t>(match.position(1)), | ||
.length = static_cast<std::uint32_t>(match.length(1)), | ||
}; | ||
} | ||
|
||
std::optional<SkSL::ProgramKind> ToSkSLProgramKind(const std::string& kind) { | ||
switch (Hash(kind.c_str())) { | ||
case Hash("shader"): | ||
return SkSL::ProgramKind::kRuntimeShader; | ||
case Hash("colorfilter"): | ||
return SkSL::ProgramKind::kRuntimeColorFilter; | ||
case Hash("blender"): | ||
return SkSL::ProgramKind::kRuntimeBlender; | ||
case Hash("meshfrag"): | ||
return SkSL::ProgramKind::kMeshFragment; | ||
case Hash("meshvert"): | ||
return SkSL::ProgramKind::kMeshVertex; | ||
default: | ||
return std::nullopt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include <src/sksl/SkSLProgramKind.h> | ||
|
||
#include <cstdint> | ||
#include <string> | ||
|
||
struct Kind { | ||
std::string str; | ||
std::uint32_t position; | ||
std::uint32_t length; | ||
}; | ||
|
||
std::optional<Kind> GetKind(const std::string& content); | ||
|
||
std::optional<SkSL::ProgramKind> ToSkSLProgramKind(const std::string& kind); |