• 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::Context().fConfig->fSettings;
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     ThreadContext::ReportErrors(PositionInfo{});
33     sk_sp<SkRuntimeEffect> result;
34     if (program) {
35         result = SkRuntimeEffect::MakeForShader(std::move(program), options, &GetErrorReporter());
36     }
37     End();
38     return result;
39 }
40 
41 #endif // SKSL_STANDALONE
42 
43 } // namespace dsl
44 
45 } // namespace SkSL
46