• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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 "include/sksl/DSLRuntimeEffects.h"
9 
10 #include "include/effects/SkRuntimeEffect.h"
11 #include "include/sksl/DSLCore.h"
12 #include "src/sksl/SkSLCompiler.h"
13 #include "src/sksl/SkSLThreadContext.h"
14 
15 namespace SkSL {
16 
17 namespace dsl {
18 
19 #ifndef SKSL_STANDALONE
20 
StartRuntimeShader(SkSL::Compiler * compiler)21 void StartRuntimeShader(SkSL::Compiler* compiler) {
22     Start(compiler, SkSL::ProgramKind::kRuntimeShader);
23     SkSL::ProgramSettings& settings = ThreadContext::Settings();
24     SkASSERT(settings.fInlineThreshold == SkSL::kDefaultInlineThreshold);
25     settings.fInlineThreshold = 0;
26     SkASSERT(!settings.fAllowNarrowingConversions);
27     settings.fAllowNarrowingConversions = true;
28 }
29 
EndRuntimeShader(SkRuntimeEffect::Options options)30 sk_sp<SkRuntimeEffect> EndRuntimeShader(SkRuntimeEffect::Options options) {
31     std::unique_ptr<SkSL::Program> program = ReleaseProgram();
32     SkRuntimeEffect::Result result;
33     if (program) {
34         result = SkRuntimeEffect::MakeForShader(std::move(program), options);
35         // TODO(skbug.com/11862): propagate errors properly
36         SkASSERTF(result.effect, "%s\n", result.errorText.c_str());
37     }
38     End();
39     return result.effect;
40 }
41 
42 #endif // SKSL_STANDALONE
43 
44 } // namespace dsl
45 
46 } // namespace SkSL
47