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_MANAGER_H 17 #define API_RENDER_IRENDER_DATA_STORE_MANAGER_H 18 19 #include <base/containers/string_view.h> 20 #include <render/namespace.h> 21 22 BASE_BEGIN_NAMESPACE() 23 struct Uid; 24 BASE_END_NAMESPACE() 25 26 RENDER_BEGIN_NAMESPACE() 27 class IRenderDataStore; 28 /** @ingroup group_render_irenderdatastoremanager */ 29 /** IRenderDataStoreManager interface. 30 * Interface class to hold all render data stores. 31 32 * Internally synchronized 33 */ 34 class IRenderDataStoreManager { 35 public: 36 IRenderDataStoreManager(const IRenderDataStoreManager&) = delete; 37 IRenderDataStoreManager& operator=(const IRenderDataStoreManager&) = delete; 38 39 /** Get a previously created render data store 40 * Uses lock, prefer fetching once if you're certain that the data store won't be destroyed 41 * @param name Name of the render data store instance 42 * @return Pointer to the instance or nullptr if instance doesn't exist. 43 */ 44 virtual IRenderDataStore* GetRenderDataStore(const BASE_NS::string_view name) const = 0; 45 46 /** Creates a new render data store. 47 * @param dataStoreTypeUid Type UID of the render data store instance 48 * @param dataStoreName Name of the render data store instance 49 * @return Pointer to a new instance or nullptr if creation failed. 50 */ 51 virtual IRenderDataStore* Create(const BASE_NS::Uid& dataStoreTypeUid, char const* dataStoreName) = 0; 52 53 /** Destroys a render data store. 54 * @param dataStoreeUid Type UID of the render data store instance 55 * @param instance Instance to destroy 56 */ 57 virtual void Destroy(const BASE_NS::Uid& dataStoreTypeUid, IRenderDataStore* instance) = 0; 58 59 /** Render data store flag bits, which data store implemented should check. 60 */ 61 enum RenderDataStoreFlagBits : uint32_t { 62 /** Flag that tells the user that one should use double buffered data stores. 63 * This can enable multi-threading from client-side with filling data stores when rendering previous. 64 */ 65 DOUBLE_BUFFERED_RENDER_DATA_STORES = 0x00000001, 66 }; 67 /** Container for render data store flag bits */ 68 using RenderDataStoreFlags = uint32_t; 69 70 /** Get render data store flags. Render data store implementer should evaluate these. 71 * @return RenderDataStoreFlags. 72 */ 73 virtual RenderDataStoreFlags GetRenderDataStoreFlags() const = 0; 74 75 /** Commit frame data for rendering. I.e. commit render data stores for rendering. 76 * Needs to be called before RenderFrame is called if using DOUBLE_BUFFERED_RENDER_DATA_STORES 77 * and users renderer in separate thread. 78 * 79 * This is automatically called by the RenderFrame and/or RenderDeferredFrame methods in the renderer 80 * and does not need to worry about this when typical main thread is used for logic and rendering. 81 * 82 * This method is not internally synchronized and needs to be called before rendering and 83 * rendering cannot be then active. 84 * Logic and render syncronization point one should call these (after rendering has finished): 85 * CommitFrameData() // to flip the read and write indices. 86 * RenderFrame(...) // can then processed in the own thread. 87 */ 88 virtual void CommitFrameData() = 0; 89 90 /** Frame indices struct */ 91 struct FrameIndices { 92 /** Write index inside render data stores */ 93 uint32_t writeIdx { 0u }; 94 /** Read index inside render data stores */ 95 uint32_t readIdx { 1u }; 96 }; 97 /** Get frame indices for data store usage. Returns the write and read indices of current rendering. 98 * @return FrameIndices indices for data store data processing in render data stores. 99 */ 100 virtual FrameIndices GetFrameIndices() const = 0; 101 102 protected: 103 IRenderDataStoreManager() = default; 104 virtual ~IRenderDataStoreManager() = default; 105 }; 106 107 /** IRenderNodeRenderDataStoreManager interface. 108 * Interface class to access all render data stores. 109 110 * Safe usage without locking in render nodes. 111 */ 112 class IRenderNodeRenderDataStoreManager { 113 public: 114 IRenderNodeRenderDataStoreManager(const IRenderNodeRenderDataStoreManager&) = delete; 115 IRenderNodeRenderDataStoreManager& operator=(const IRenderNodeRenderDataStoreManager&) = delete; 116 117 /** Get a previously created render data store 118 * @param name Name of the render data store instance 119 * @return Pointer to the instance or nullptr if instance doesn't exist. 120 */ 121 virtual IRenderDataStore* GetRenderDataStore(const BASE_NS::string_view name) const = 0; 122 123 protected: 124 IRenderNodeRenderDataStoreManager() = default; 125 virtual ~IRenderNodeRenderDataStoreManager() = default; 126 }; 127 RENDER_END_NAMESPACE() 128 129 #endif // API_RENDER_IRENDER_DATA_STORE_MANAGER_H 130