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 API_RENDER_IRENDER_DATA_STORE_DEFAULT_GPU_RESOURCE_DATA_COPY_H
17 #define API_RENDER_IRENDER_DATA_STORE_DEFAULT_GPU_RESOURCE_DATA_COPY_H
18 
19 #include <base/containers/byte_array.h>
20 #include <base/util/uid.h>
21 #include <render/datastore/intf_render_data_store.h>
22 #include <render/namespace.h>
23 #include <render/resource_handle.h>
24 
RENDER_BEGIN_NAMESPACE()25 RENDER_BEGIN_NAMESPACE()
26 /**
27  * IRenderDataStoreDefaultGpuResourceDataCopy interface.
28  * Interface to add copy operations.
29  *
30  * Copy will happen after the frame has been rendered.
31  *
32  * Internally synchronized.
33  */
34 class IRenderDataStoreDefaultGpuResourceDataCopy : public IRenderDataStore {
35 public:
36     static constexpr BASE_NS::Uid UID { "f3ce24fd-a624-4b8f-9013-006fc5fd8760" };
37 
38     /* The type of the copy */
39     enum class CopyType : uint8_t {
40         /** Undefined */
41         UNDEFINED,
42         /** Wait for idle (waits for the GPU) */
43         WAIT_FOR_IDLE,
44     };
45 
46     struct GpuResourceDataCopy {
47         /* The type of the copy */
48         CopyType copyType { CopyType::UNDEFINED };
49         /* GPU resource handle that will be copied. */
50         RenderHandleReference gpuHandle;
51         /* Byte array where to copy. */
52         BASE_NS::ByteArray* byteArray { nullptr };
53     };
54 
55     /** Copy data to buffer on GPU through staging GPU buffer.
56      * @param data Byte data.
57      * @param dstHandle Dst resource.
58      * @param bufferCopy Buffer copy info struct.
59      */
60     virtual void AddCopyOperation(const GpuResourceDataCopy& copyOp) = 0;
61 
62 protected:
63     IRenderDataStoreDefaultGpuResourceDataCopy() = default;
64     ~IRenderDataStoreDefaultGpuResourceDataCopy() override = default;
65 };
66 RENDER_END_NAMESPACE()
67 
68 #endif // API_RENDER_IRENDER_DATA_STORE_DEFAULT_GPU_RESOURCE_DATA_COPY_H
69