• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 RENDER_DATA_STORE_RENDER_DATA_STORE_FULLSCREEN_SHADER_H
17 #define RENDER_DATA_STORE_RENDER_DATA_STORE_FULLSCREEN_SHADER_H
18 
19 #include <atomic>
20 #include <cstdint>
21 #include <mutex>
22 
23 #include <base/containers/refcnt_ptr.h>
24 #include <base/containers/string.h>
25 #include <base/containers/string_view.h>
26 #include <base/containers/unordered_map.h>
27 #include <base/util/uid.h>
28 #include <render/datastore/intf_render_data_store_shader_passes.h>
29 #include <render/namespace.h>
30 
31 RENDER_BEGIN_NAMESPACE()
32 class IRenderContext;
33 /**
34  * RenderDataStoreFullscreenShader implementation.
35  */
36 class RenderDataStoreShaderPasses final : public IRenderDataStoreShaderPasses {
37 public:
38     RenderDataStoreShaderPasses(const IRenderContext& renderContex, BASE_NS::string_view name);
39     ~RenderDataStoreShaderPasses() override = default;
40 
41     // IRenderDataStoreShaderPasses
42     void AddRenderData(BASE_NS::string_view name, BASE_NS::array_view<const RenderPassData> data) override;
43     void AddComputeData(BASE_NS::string_view name, BASE_NS::array_view<const ComputePassData> data) override;
44 
45     BASE_NS::vector<RenderPassData> GetRenderData(BASE_NS::string_view name) const override;
46     BASE_NS::vector<ComputePassData> GetComputeData(BASE_NS::string_view name) const override;
47     BASE_NS::vector<RenderPassData> GetRenderData() const override;
48     BASE_NS::vector<ComputePassData> GetComputeData() const override;
49 
50     PropertyBindingDataInfo GetRenderPropertyBindingInfo(BASE_NS::string_view name) const override;
51     PropertyBindingDataInfo GetComputePropertyBindingInfo(BASE_NS::string_view name) const override;
52     PropertyBindingDataInfo GetRenderPropertyBindingInfo() const override;
53     PropertyBindingDataInfo GetComputePropertyBindingInfo() const override;
54 
55     // IRenderDataStore
PreRender()56     void PreRender() override {}
57     void PostRender() override;
PreRenderBackend()58     void PreRenderBackend() override {}
PostRenderBackend()59     void PostRenderBackend() override {}
60     void Clear() override;
GetFlags()61     uint32_t GetFlags() const override
62     {
63         return 0U;
64     }
65 
GetTypeName()66     BASE_NS::string_view GetTypeName() const override
67     {
68         return TYPE_NAME;
69     }
70 
GetName()71     BASE_NS::string_view GetName() const override
72     {
73         return name_;
74     }
75 
GetUid()76     const BASE_NS::Uid& GetUid() const override
77     {
78         return UID;
79     }
80 
81     void Ref() override;
82     void Unref() override;
83     int32_t GetRefCount() override;
84 
85     // for plugin / factory interface
86     static constexpr const char* const TYPE_NAME = "RenderDataStoreShaderPasses";
87 
88     static BASE_NS::refcnt_ptr<IRenderDataStore> Create(IRenderContext& renderContext, const char* name);
89 
90 private:
91     BASE_NS::string name_;
92 
93     struct RenderPassDataInfo {
94         BASE_NS::vector<RenderPassData> rpData;
95         uint32_t alignedPropertyByteSize { 0U };
96     };
97     struct ComputePassDataInfo {
98         BASE_NS::vector<ComputePassData> cpData;
99         uint32_t alignedPropertyByteSize { 0U };
100     };
101 
102     BASE_NS::unordered_map<BASE_NS::string, RenderPassDataInfo> nameToRenderObjects_;
103     BASE_NS::unordered_map<BASE_NS::string, ComputePassDataInfo> nameToComputeObjects_;
104 
105     mutable std::mutex mutex_;
106 
107     std::atomic_int32_t refcnt_ { 0 };
108 };
109 RENDER_END_NAMESPACE()
110 
111 #endif // RENDER_DATA_STORE_RENDER_DATA_STORE_FULLSCREEN_SHADER_H
112