Use make_shader() helper function to create ColorSelector shaders

This commit is contained in:
David Capello 2024-03-11 17:48:11 -03:00
parent 7905acf38a
commit a0e469624a
2 changed files with 3 additions and 17 deletions

View File

@ -655,35 +655,22 @@ bool ColorSelector::buildEffects()
if (!m_mainEffect) {
if (const char* code = getMainAreaShader())
m_mainEffect = buildEffect(code);
m_mainEffect = make_shader(code);
}
if (!m_bottomEffect) {
if (const char* code = getBottomBarShader())
m_bottomEffect = buildEffect(code);
m_bottomEffect = make_shader(code);
}
if (!m_alphaEffect) {
if (const char* code = getAlphaBarShader())
m_alphaEffect = buildEffect(code);
m_alphaEffect = make_shader(code);
}
return (m_mainEffect && m_bottomEffect && m_alphaEffect);
}
sk_sp<SkRuntimeEffect> ColorSelector::buildEffect(const char* code)
{
auto result = SkRuntimeEffect::MakeForShader(SkString(code));
if (!result.errorText.isEmpty()) {
LOG(ERROR, "Shader error: %s\n", result.errorText.c_str());
std::printf("Shader error: %s\n", result.errorText.c_str());
return nullptr;
}
else {
return result.effect;
}
}
void ColorSelector::resetBottomEffect()
{
m_bottomEffect.reset();

View File

@ -121,7 +121,6 @@ namespace app {
#if SK_ENABLE_SKSL
static const char* getAlphaBarShader();
bool buildEffects();
sk_sp<SkRuntimeEffect> buildEffect(const char* code);
#endif
// Internal flag used to lock the modification of m_color.