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_UTIL_IRENDER_UTIL_H
17 #define API_RENDER_UTIL_IRENDER_UTIL_H
18 
19 #include <cstdint>
20 
21 #include <base/containers/string.h>
22 #include <render/namespace.h>
23 #include <render/resource_handle.h>
24 
25 RENDER_BEGIN_NAMESPACE()
26 /** @ingroup group_util_irenderutil */
27 class IRenderFrameUtil;
28 
29 /**
30  * Render timings
31  */
32 struct RenderTimings {
33     struct Times {
34         /** Time stamp at the beginning of RenderFrame() */
35         int64_t begin { 0 };
36         /** Time stamp at the end of RenderFrame() */
37         int64_t end { 0 };
38 
39         /** Time stamp at the beginning of backend command list processing */
40         int64_t beginBackend { 0 };
41         /** Time stamp at the end of backend command list processing and submits */
42         int64_t endBackend { 0 };
43         /** Time stamp at the beginning of backend presentation start */
44         int64_t beginBackendPresent { 0 };
45         /** Time stamp at the end of backend presentation */
46         int64_t endBackendPresent { 0 };
47     };
48     /** Current results after RenderFrame() has returned */
49     Times frame;
50     /** Previous frame results after RenderFrame() has returned */
51     Times prevFrame;
52 };
53 
54 /** Render handle description */
55 struct RenderHandleDesc {
56     /** Type */
57     RenderHandleType type { RenderHandleType::UNDEFINED };
58     /** Additional ID */
59     uint64_t id { 0 };
60     /** Reference count for this handle as seen from the client side */
61     int32_t refCount { 0 };
62     /** Name and/or path of the resource */
63     BASE_NS::string name;
64     /** Additional name of the resource */
65     BASE_NS::string additionalName;
66 };
67 
68 /** Interface for rendering utilities.
69  */
70 class IRenderUtil {
71 public:
72     /** Get description for given handle.
73      * @param handle Render handle reference of the resource.
74      * @return RenderHandleDesc Return render handle desc for given handle.
75      */
76     virtual RenderHandleDesc GetRenderHandleDesc(const RenderHandleReference& handle) const = 0;
77 
78     /** Get handle for given description.
79      * @param desc Render handle description.
80      * @return RenderHandleReference Return render handle for given desc.
81      */
82     virtual RenderHandleReference GetRenderHandle(const RenderHandleDesc& desc) const = 0;
83 
84     /** Get last render timings. Should be usually called after RenderFrame() has returned.
85      * @return RenderTimings Results from the last RenderFrame() call.
86      */
87     virtual RenderTimings GetRenderTimings() const = 0;
88 
89     /** Get render frame util with frame related utilities.
90      * @return Reference to render frame util interface.
91      */
92     virtual IRenderFrameUtil& GetRenderFrameUtil() const = 0;
93 
94 protected:
95     IRenderUtil() = default;
96     virtual ~IRenderUtil() = default;
97 };
98 RENDER_END_NAMESPACE()
99 
100 #endif // API_RENDER_UTIL_IRENDER_UTIL_H
101