xref: /aosp_15_r20/external/skia/src/gpu/ganesh/glsl/GrGLSLVertexGeoBuilder.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2017 Google Inc.
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 #ifndef GrGLSLVertexGeoBuilder_DEFINED
9 #define GrGLSLVertexGeoBuilder_DEFINED
10 
11 #include "include/core/SkString.h"
12 #include "src/core/SkSLTypeShared.h"
13 #include "src/gpu/ganesh/GrGeometryProcessor.h"
14 #include "src/gpu/ganesh/glsl/GrGLSLShaderBuilder.h"
15 
16 class GrGLSLProgramBuilder;
17 
18 /**
19  * Base class for vertex shader builder. This is the stage that computes input geometry for the
20  * rasterizer.
21  */
22 class GrGLSLVertexGeoBuilder : public GrGLSLShaderBuilder {
23 public:
24     // Copies the given text verbatim to the function definitions section. Does not mangle the name.
25     // 'functionDefinition' should be a fully valid SkSL function, complete with return type, name,
26     // arguments, braces, and a body.
insertFunction(const char * functionDefinition)27     void insertFunction(const char* functionDefinition) {
28         this->functions().append(functionDefinition);
29     }
30     using GrGLSLShaderBuilder::functions;
31     using GrGLSLShaderBuilder::code;
32 
33 protected:
GrGLSLVertexGeoBuilder(GrGLSLProgramBuilder * program)34     GrGLSLVertexGeoBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
35 
36     void emitNormalizedSkPosition(const char* devPos, SkSLType devPosType = SkSLType::kFloat2) {
37         this->emitNormalizedSkPosition(&this->code(), devPos, devPosType);
38     }
39 
40     void emitNormalizedSkPosition(SkString* out, const char* devPos,
41                                   SkSLType devPosType = SkSLType::kFloat2);
42 
43     friend class GrGeometryProcessor::ProgramImpl;
44 
45     using INHERITED = GrGLSLShaderBuilder;
46 };
47 
48 
49 class GrGLSLVertexBuilder : public GrGLSLVertexGeoBuilder {
50 public:
GrGLSLVertexBuilder(GrGLSLProgramBuilder * program)51     GrGLSLVertexBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
52 
53 private:
54     void onFinalize() override;
55 
56     friend class GrGLProgramBuilder;
57 
58     using INHERITED = GrGLSLVertexGeoBuilder;
59 };
60 
61 #endif
62