• 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 "src/sksl/dsl/priv/DSLFPs.h"
9 
10 #include "src/sksl/SkSLThreadContext.h"
11 #include "src/sksl/dsl/priv/DSLWriter.h"
12 #include "src/sksl/ir/SkSLCodeStringExpression.h"
13 
14 #if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
15 
16 namespace SkSL {
17 
18 namespace dsl {
19 
StartFragmentProcessor(GrFragmentProcessor::ProgramImpl * processor,GrFragmentProcessor::ProgramImpl::EmitArgs * emitArgs)20 void StartFragmentProcessor(GrFragmentProcessor::ProgramImpl* processor,
21                             GrFragmentProcessor::ProgramImpl::EmitArgs* emitArgs) {
22     ThreadContext::StartFragmentProcessor(processor, emitArgs);
23 }
24 
EndFragmentProcessor()25 void EndFragmentProcessor() {
26     ThreadContext::EndFragmentProcessor();
27 }
28 
sk_SampleCoord()29 DSLGlobalVar sk_SampleCoord() {
30     return DSLGlobalVar("sk_SampleCoord");
31 }
32 
SampleChild(int index,DSLExpression sampleExpr)33 DSLExpression SampleChild(int index, DSLExpression sampleExpr) {
34     std::unique_ptr<SkSL::Expression> expr = sampleExpr.releaseIfPossible();
35     if (expr) {
36         SkASSERT(expr->type().isVector());
37         SkASSERT(expr->type().componentType().isFloat());
38     }
39 
40     GrFragmentProcessor::ProgramImpl* proc = ThreadContext::CurrentProcessor();
41     GrFragmentProcessor::ProgramImpl::EmitArgs& emitArgs = *ThreadContext::CurrentEmitArgs();
42     SkString code;
43     switch (expr ? expr->type().columns() : 0) {
44         default:
45             SkASSERTF(0, "unsupported SampleChild type: %s", expr->type().description().c_str());
46             [[fallthrough]];
47         case 0:
48             code = proc->invokeChild(index, emitArgs);
49             break;
50         case 2:
51             code = proc->invokeChild(index, emitArgs, /*skslCoords=*/expr->description());
52             break;
53         case 4:
54             code = proc->invokeChild(index, /*inputColor=*/expr->description().c_str(), emitArgs);
55             break;
56     }
57 
58     return DSLExpression(std::make_unique<SkSL::CodeStringExpression>(
59             code.c_str(), ThreadContext::Context().fTypes.fHalf4.get()));
60 }
61 
VarUniformHandle(const DSLGlobalVar & var)62 GrGLSLUniformHandler::UniformHandle VarUniformHandle(const DSLGlobalVar& var) {
63     return DSLWriter::VarUniformHandle(var);
64 }
65 
66 } // namespace dsl
67 
68 } // namespace SkSL
69 
70 #endif // !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
71