1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef LOADER_PIPELINE_LAYOUT_LOADER_H
17 #define LOADER_PIPELINE_LAYOUT_LOADER_H
18
19 #include <base/containers/string.h>
20 #include <core/namespace.h>
21 #include <render/device/pipeline_layout_desc.h>
22 #include <render/namespace.h>
23
24 CORE_BEGIN_NAMESPACE()
25 class IFileManager;
26 CORE_END_NAMESPACE()
RENDER_BEGIN_NAMESPACE()27 RENDER_BEGIN_NAMESPACE()
28
29 /** Pipeline layout loader.
30 * A class that can be used to load pipeline layout from json structure.
31 */
32 class PipelineLayoutLoader final {
33 public:
34 /** Describes result of the parsing operation. */
35 struct LoadResult {
36 LoadResult() = default;
37 explicit LoadResult(BASE_NS::string_view error) : success(false), error(error) {}
38
39 /** Indicates, whether the parsing operation is successful. */
40 bool success { true };
41
42 /** In case of parsing error, contains the description of the error. */
43 BASE_NS::string error;
44 };
45
46 /** Retrieve uri of the pipeline layout.
47 * @return String view to uri of the pipeline layout.
48 */
49 BASE_NS::string_view GetUri() const;
50
51 /** Retrieve pipeline layout.
52 * @return A pipeline layout, as defined in the json file.
53 */
54 const PipelineLayout& GetPipelineLayout() const;
55
56 /** Get optional render slot.
57 * @return A render slot (optional)
58 */
59 BASE_NS::string_view GetRenderSlot() const;
60
61 /** Get optional render slot.
62 * @return A render slot (optional)
63 */
64 bool GetDefaultRenderSlot() const;
65
66 /** Loads pipeline layout from json string.
67 * @param jsonString A string containing valid json as content.
68 * @return A structure containing result for the parsing operation.
69 */
70 LoadResult Load(BASE_NS::string_view jsonString);
71
72 /** Loads pipeline layout from given uri, using file manager.
73 * @param fileManager A file manager to access the file in given uri.
74 * @param uri Uri to json file.
75 * @return A structure containing result for the parsing operation.
76 */
77 LoadResult Load(CORE_NS::IFileManager& fileManager, BASE_NS::string_view uri);
78
79 private:
80 PipelineLayout pipelineLayout_;
81 BASE_NS::string uri_;
82 BASE_NS::string renderSlotName_;
83 bool renderSlotDefaultPl_ { false };
84 };
85 RENDER_END_NAMESPACE()
86
87 #endif // LOADER_PIPELINE_LAYOUT_LOADER_H
88