1 /* 2 * Copyright (c) 2022 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 CORE__RENDER__NODE_DATA__RENDER_DATA_STORE_DEFAULT_SCENE_H 17 #define CORE__RENDER__NODE_DATA__RENDER_DATA_STORE_DEFAULT_SCENE_H 18 19 #include <atomic> 20 #include <cstdint> 21 22 #include <3d/render/intf_render_data_store_default_scene.h> 23 #include <base/containers/string.h> 24 #include <base/containers/string_view.h> 25 #include <base/containers/unordered_map.h> 26 #include <base/containers/vector.h> 27 #include <base/util/uid.h> 28 29 RENDER_BEGIN_NAMESPACE() 30 class IRenderContext; 31 RENDER_END_NAMESPACE() 32 CORE3D_BEGIN_NAMESPACE()33CORE3D_BEGIN_NAMESPACE() 34 /** 35 RenderDataStoreDefaultScene implementation. 36 */ 37 class RenderDataStoreDefaultScene final : public IRenderDataStoreDefaultScene { 38 public: 39 explicit RenderDataStoreDefaultScene(const BASE_NS::string_view name); 40 ~RenderDataStoreDefaultScene() override = default; 41 42 // IRenderDataStore 43 void PreRender() override {} 44 // Reset and start indexing from the beginning. i.e. frame boundary reset. 45 void PostRender() override; 46 void PreRenderBackend() override {} 47 void PostRenderBackend() override {} 48 void Clear() override; 49 uint32_t GetFlags() const override 50 { 51 return 0; 52 } 53 BASE_NS::string_view GetTypeName() const override 54 { 55 return TYPE_NAME; 56 } 57 58 BASE_NS::string_view GetName() const override 59 { 60 return name_; 61 } 62 63 const BASE_NS::Uid& GetUid() const override 64 { 65 return UID; 66 } 67 68 void Ref() override; 69 void Unref() override; 70 int32_t GetRefCount() override; 71 72 // IRenderDataStoreDefaultScene 73 void SetScene(const RenderScene& scene) override; 74 RenderScene GetScene(const BASE_NS::string_view sceneName) const override; 75 RenderScene GetScene() const override; 76 77 // for plugin / factory interface 78 static constexpr const char* const TYPE_NAME = "RenderDataStoreDefaultScene"; 79 static BASE_NS::refcnt_ptr<IRenderDataStore> Create(RENDER_NS::IRenderContext& renderContext, char const* name); 80 81 private: 82 BASE_NS::string name_; 83 84 BASE_NS::vector<RenderScene> scenes_; 85 BASE_NS::unordered_map<BASE_NS::string, size_t> nameToScene_; 86 uint32_t nextId { 0u }; 87 88 std::atomic_int32_t refcnt_ { 0 }; 89 }; 90 CORE3D_END_NAMESPACE() 91 92 #endif // CORE__RENDER__NODE_DATA__RENDER_DATA_STORE_DEFAULT_SCENE_H 93