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 RENDER_DATA_STORE_RENDER_DATA_STORE_POD_H 17 #define RENDER_DATA_STORE_RENDER_DATA_STORE_POD_H 18 19 #include <cstdint> 20 #include <mutex> 21 22 #include <base/containers/array_view.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 #include <render/datastore/intf_render_data_store_pod.h> 29 #include <render/namespace.h> 30 31 RENDER_BEGIN_NAMESPACE() 32 class IRenderContext; 33 /** 34 RenderDataStorePod implementation. 35 */ 36 class RenderDataStorePod final : public IRenderDataStorePod { 37 public: 38 explicit RenderDataStorePod(const BASE_NS::string_view name); 39 ~RenderDataStorePod() override = default; 40 CommitFrameData()41 void CommitFrameData() override {}; PreRender()42 void PreRender() override {}; PostRender()43 void PostRender() override {}; PreRenderBackend()44 void PreRenderBackend() override {}; PostRenderBackend()45 void PostRenderBackend() override {}; Clear()46 void Clear() override {}; GetFlags()47 uint32_t GetFlags() const override 48 { 49 return 0; 50 }; 51 52 void CreatePod(const BASE_NS::string_view typeName, const BASE_NS::string_view name, 53 const BASE_NS::array_view<const uint8_t> data) override; 54 void DestroyPod(const BASE_NS::string_view typeName, const BASE_NS::string_view name) override; 55 56 void Set(const BASE_NS::string_view name, const BASE_NS::array_view<const uint8_t> data) override; 57 BASE_NS::array_view<const uint8_t> Get(const BASE_NS::string_view name) const override; 58 59 BASE_NS::array_view<const BASE_NS::string> GetPodNames(const BASE_NS::string_view typeName) const override; 60 61 // for plugin / factory interface 62 static constexpr const char* const TYPE_NAME = "RenderDataStorePod"; 63 64 static IRenderDataStore* Create(IRenderContext& renderContext, char const* name); 65 static void Destroy(IRenderDataStore* instance); 66 GetTypeName()67 BASE_NS::string_view GetTypeName() const override 68 { 69 return TYPE_NAME; 70 } 71 GetName()72 BASE_NS::string_view GetName() const override 73 { 74 return name_; 75 } 76 GetUid()77 const BASE_NS::Uid& GetUid() const override 78 { 79 return UID; 80 } 81 82 private: 83 const BASE_NS::string name_; 84 85 // NOTE: allocate bigger blocks 86 BASE_NS::vector<uint8_t> dataStore_; 87 88 struct OffsetToData { 89 uint32_t index { 0 }; 90 uint32_t byteSize { 0 }; 91 }; 92 BASE_NS::unordered_map<BASE_NS::string, OffsetToData> nameToDataOffset_; 93 94 BASE_NS::unordered_map<BASE_NS::string, BASE_NS::vector<BASE_NS::string>> typeNameToPodNames_; 95 96 mutable std::mutex mutex_; 97 }; 98 RENDER_END_NAMESPACE() 99 100 #endif // RENDER_DATA_STORE_RENDER_DATA_STORE_POD_H 101