1 /*
2  * Copyright (c) 2024 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_DEFAULT_GPU_RESOURCE_DATA_COPY_H
17 #define RENDER_DATA_STORE_RENDER_DATA_STORE_DEFAULT_GPU_RESOURCE_DATA_COPY_H
18 
19 #include <cstdint>
20 #include <mutex>
21 
22 #include <base/containers/string.h>
23 #include <base/containers/string_view.h>
24 #include <base/containers/vector.h>
25 #include <base/util/uid.h>
26 #include <render/datastore/intf_render_data_store_default_gpu_resource_data_copy.h>
27 #include <render/namespace.h>
28 
29 RENDER_BEGIN_NAMESPACE()
30 class IRenderContext;
31 class IDevice;
32 class GpuResourceManager;
33 /**
34 RenderDataStoreDefaultGpuResourceDataCopy implementation.
35 */
36 class RenderDataStoreDefaultGpuResourceDataCopy final : public IRenderDataStoreDefaultGpuResourceDataCopy {
37 public:
38     RenderDataStoreDefaultGpuResourceDataCopy(IRenderContext& renderContext, const BASE_NS::string_view name);
39     ~RenderDataStoreDefaultGpuResourceDataCopy() override = default;
40 
CommitFrameData()41     void CommitFrameData() override {};
PreRender()42     void PreRender() override {};
PostRender()43     void PostRender() override {};
PreRenderBackend()44     void PreRenderBackend() override {};
45     // Do copy operation in end frame.
46     void PostRenderBackend() override;
47     void Clear() override;
GetFlags()48     uint32_t GetFlags() const override
49     {
50         return 0;
51     };
52 
53     void AddCopyOperation(const GpuResourceDataCopy& copyOp) override;
54 
55     // for plugin / factory interface
56     static constexpr const char* const TYPE_NAME = "RenderDataStoreDefaultGpuResourceDataCopy";
57 
58     static IRenderDataStore* Create(IRenderContext& renderContext, char const* name);
59     static void Destroy(IRenderDataStore* instance);
60 
GetTypeName()61     BASE_NS::string_view GetTypeName() const override
62     {
63         return TYPE_NAME;
64     }
65 
GetName()66     BASE_NS::string_view GetName() const override
67     {
68         return name_;
69     }
70 
GetUid()71     const BASE_NS::Uid& GetUid() const override
72     {
73         return UID;
74     }
75 
76 private:
77     IDevice& device_;
78     GpuResourceManager& gpuResourceMgr_;
79     const BASE_NS::string name_;
80 
81     mutable std::mutex mutex_;
82 
83     bool waitForIdle_ { false };
84     BASE_NS::vector<GpuResourceDataCopy> copyData_;
85 };
86 RENDER_END_NAMESPACE()
87 
88 #endif // RENDER_DATA_STORE_RENDER_DATA_STORE_DEFAULT_GPU_RESOURCE_DATA_COPY_H
89