• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CONTEXT_H
17 #define API_RENDER_IRENDER_CONTEXT_H
18 
19 #include <base/containers/string.h>
20 #include <base/containers/string_view.h>
21 #include <base/util/color.h>
22 #include <core/plugin/intf_class_factory.h>
23 #include <render/device/intf_device.h>
24 #include <render/namespace.h>
25 #include <render/resource_handle.h>
26 
27 CORE_BEGIN_NAMESPACE()
28 class IEngine;
29 CORE_END_NAMESPACE()
30 
31 RENDER_BEGIN_NAMESPACE()
32 class IRenderDataStoreManager;
33 class IRenderNodeGraphManager;
34 class IRenderer;
35 class IRenderUtil;
36 
37 /**
38  * RenderResultCode
39  */
40 enum class RenderResultCode : uint32_t {
41     RENDER_SUCCESS = 0,
42     RENDER_ERROR = 1,
43 };
44 
45 /**
46  * VersionInfo
47  */
48 struct VersionInfo {
49     /** Name, default is "no_name" */
50     BASE_NS::string name { "no_name" };
51     /** Major number of version */
52     uint32_t versionMajor { 0 };
53     /** Minor number of version */
54     uint32_t versionMinor { 0 };
55     /** Patch number of version */
56     uint32_t versionPatch { 0 };
57 };
58 
59 /**
60  * RenderCreateInfo
61  */
62 struct RenderCreateInfo {
63     /** Create info flag bits to setup configuration flags */
64     enum CreateInfoFlagBits : uint32_t {
65         /** Request separate render frame backend (backend graphics API control) */
66         CREATE_INFO_SEPARATE_RENDER_FRAME_BACKEND_BIT = 0x00000002,
67         /** Request separate render frame present (backend graphics API presentation) */
68         CREATE_INFO_SEPARATE_RENDER_FRAME_PRESENT_BIT = 0x00000004,
69     };
70     /** Container for render create info flag bits */
71     using CreateInfoFlags = uint32_t;
72     /** Thread pool create info */
73     struct ThreadPoolCreateInfo {
74         /** Coefficient to hardware registered number of cores
75          * With 1.0f and maxCount { ~0U }, the maximum number of core tasks are in use
76          */
77         float threadCountCoefficient { 0.5f };
78         /** Minimum count of threads in the thread pool.
79          * The renderer should have at least 4 threads to parallelize correctly.
80          */
81         uint32_t minCount { 4U };
82         /** Maximum count of threads in the thread pool.
83          * The renderer thread count should not exceed the expected task count.
84          */
85         uint32_t maxCount { ~0U };
86     };
87 
88     /** Application version info */
89     VersionInfo applicationInfo;
90     /** Device create info */
91     DeviceCreateInfo deviceCreateInfo;
92     /** Creation flags */
93     CreateInfoFlags createFlags { 0U };
94     /** Threadpool create info */
95     ThreadPoolCreateInfo threadPoolCreateInfo;
96     /** Color space flags (defaults to linear) */
97     BASE_NS::ColorSpaceFlags colorSpaceFlags { 0U };
98 };
99 
100 /**
101  * IRenderContext interface for accessing managers and renderer.
102  * Device must be created to access valid renderer, render node graph manager, and render data store manager.
103  */
104 class IRenderContext : public CORE_NS::IClassFactory {
105 public:
106     static constexpr auto UID = BASE_NS::Uid { "c8d8650b-efac-4e04-8e66-e12b35d2749e" };
107     using Ptr = BASE_NS::refcnt_ptr<IRenderContext>;
108 
109     /** Init, create device for render use.
110      *  @param createInfo Device creation info.
111      */
112     virtual RenderResultCode Init(const RenderCreateInfo& createInfo) = 0;
113 
114     /** Get active device. */
115     virtual IDevice& GetDevice() const = 0;
116     /** Get rendererer */
117     virtual IRenderer& GetRenderer() const = 0;
118     /** Get render node graph manager */
119     virtual IRenderNodeGraphManager& GetRenderNodeGraphManager() const = 0;
120     /** Get render data store manager */
121     virtual IRenderDataStoreManager& GetRenderDataStoreManager() const = 0;
122 
123     /** Get render utilities */
124     virtual IRenderUtil& GetRenderUtil() const = 0;
125 
126     /** Get engine */
127     virtual CORE_NS::IEngine& GetEngine() const = 0;
128 
129     /** Get color space flags */
130     virtual BASE_NS::ColorSpaceFlags GetColorSpaceFlags() const = 0;
131 
132     /** Get version */
133     virtual BASE_NS::string_view GetVersion() = 0;
134 
135     /** Writes current pipelines to disk if cache:// location exists. */
136     virtual void WritePipelineCache() const = 0;
137 
138 protected:
139     IRenderContext() = default;
140     virtual ~IRenderContext() = default;
141 };
142 
GetName(const IRenderContext *)143 inline constexpr BASE_NS::string_view GetName(const IRenderContext*)
144 {
145     return "IRenderContext";
146 }
147 RENDER_END_NAMESPACE()
148 
149 #endif // API_RENDER_IRENDER_CONTEXT_H
150