Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / gpu / ganesh / mtl / GrMtlPipelineStateBuilder.h
1 /*
2  * Copyright 2018 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 GrMtlPipelineStateBuilder_DEFINED
9 #define GrMtlPipelineStateBuilder_DEFINED
10
11 #include "include/gpu/GrContextOptions.h"
12 #include "src/gpu/ganesh/GrPipeline.h"
13 #include "src/gpu/ganesh/glsl/GrGLSLProgramBuilder.h"
14 #include "src/gpu/ganesh/mtl/GrMtlUniformHandler.h"
15 #include "src/gpu/ganesh/mtl/GrMtlVaryingHandler.h"
16 #include "src/sksl/SkSLCompiler.h"
17
18 #import <Metal/Metal.h>
19
20 class GrProgramDesc;
21 class GrProgramInfo;
22 class GrMtlCaps;
23 class GrMtlGpu;
24 class GrMtlPipelineState;
25 class SkReadBuffer;
26
27 struct GrMtlPrecompiledLibraries {
28     // TODO: wrap these in sk_cfp<> or unique_ptr<> when we remove ARC
29     id<MTLLibrary> fVertexLibrary;
30     id<MTLLibrary> fFragmentLibrary;
31     bool fRTFlip = false;
32 };
33
34 class GrMtlPipelineStateBuilder : public GrGLSLProgramBuilder {
35 public:
36     /** Generates a pipeline state.
37      *
38      * The returned GrMtlPipelineState implements the supplied GrProgramInfo.
39      *
40      * @return the created pipeline if generation was successful; nullptr otherwise
41      */
42     static GrMtlPipelineState* CreatePipelineState(
43                                        GrMtlGpu*,
44                                        const GrProgramDesc&,
45                                        const GrProgramInfo&,
46                                        const GrMtlPrecompiledLibraries* precompiledLibs = nullptr);
47
48     static bool PrecompileShaders(GrMtlGpu*, const SkData&,
49                                   GrMtlPrecompiledLibraries* precompiledLibs);
50
51 private:
52     GrMtlPipelineStateBuilder(GrMtlGpu*, const GrProgramDesc&, const GrProgramInfo&);
53
54     GrMtlPipelineState* finalize(const GrProgramDesc&, const GrProgramInfo&,
55                                  const GrMtlPrecompiledLibraries* precompiledLibraries);
56
57     const GrCaps* caps() const override;
58
59     SkSL::Compiler* shaderCompiler() const override;
60
61     void finalizeFragmentOutputColor(GrShaderVar& outputColor) override;
62
63     void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override;
64
65     id<MTLLibrary> compileMtlShaderLibrary(const std::string& shader,
66                                            SkSL::Program::Inputs inputs,
67                                            GrContextOptions::ShaderErrorHandler* errorHandler);
68     void storeShadersInCache(const std::string shaders[], const SkSL::Program::Inputs inputs[],
69                              SkSL::Program::Settings*, sk_sp<SkData>, bool isSkSL);
70
71     GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
72     const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
73     GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
74
75     GrMtlGpu* fGpu;
76     GrMtlUniformHandler fUniformHandler;
77     GrMtlVaryingHandler fVaryingHandler;
78
79     using INHERITED = GrGLSLProgramBuilder;
80 };
81 #endif