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