liyujie
2025-08-28 b3810562527858a3b3d98ffa6e9c9c5b0f4a9a8e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
 
#ifndef SKSL_HCODEGENERATOR
#define SKSL_HCODEGENERATOR
 
#include "SkSLCodeGenerator.h"
#include "SkSLSectionAndParameterHelper.h"
#include "ir/SkSLType.h"
#include "ir/SkSLVariable.h"
 
#include <cctype>
 
constexpr const char* kFragmentProcessorHeader =
R"(
/**************************************************************************************************
 *** This file was autogenerated from %s.fp; do not modify.
 **************************************************************************************************/
)";
 
namespace SkSL {
 
class HCodeGenerator : public CodeGenerator {
public:
    HCodeGenerator(const Context* context, const Program* program, ErrorReporter* errors,
                   String name, OutputStream* out);
 
    bool generateCode() override;
 
    static String ParameterType(const Context& context, const Type& type, const Layout& layout);
 
    static Layout::CType ParameterCType(const Context& context, const Type& type,
                                        const Layout& layout);
 
    static String FieldType(const Context& context, const Type& type, const Layout& layout);
 
    // Either the field type, or a const reference of the field type if the field type is complex.
    static String AccessType(const Context& context, const Type& type, const Layout& layout);
 
    static String FieldName(const char* varName) {
        return String::printf("f%c%s", toupper(varName[0]), varName + 1);
    }
 
    static String CoordTransformName(const String& arg, int index) {
        if (arg.size()) {
            return HCodeGenerator::FieldName(arg.c_str()) + "CoordTransform";
        }
        return "fCoordTransform" + to_string(index);
    }
 
    static String GetHeader(const Program& program, ErrorReporter& errors);
 
private:
    void writef(const char* s, va_list va) SKSL_PRINTF_LIKE(2, 0);
 
    void writef(const char* s, ...) SKSL_PRINTF_LIKE(2, 3);
 
    bool writeSection(const char* name, const char* prefix = "");
 
    // given a @constructorParams section of e.g. 'int x, float y', writes out "<separator>x, y".
    // Writes nothing (not even the separator) if there is no @constructorParams section.
    void writeExtraConstructorParams(const char* separator);
 
    void writeMake();
 
    void writeConstructor();
 
    void writeFields();
 
    void failOnSection(const char* section, const char* msg);
 
    const Context& fContext;
    String fName;
    String fFullName;
    SectionAndParameterHelper fSectionAndParameterHelper;
 
    typedef CodeGenerator INHERITED;
};
 
} // namespace SkSL
 
#endif