1 /* 2 * Copyright (C) 2023 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 PreRender()41 void PreRender() override {}; PreRenderBackend()42 void PreRenderBackend() override {}; PostRender()43 void PostRender() override {}; Clear()44 void Clear() override {}; 45 46 void CreatePod(const BASE_NS::string_view typeName, const BASE_NS::string_view name, 47 const BASE_NS::array_view<const uint8_t> data) override; 48 void DestroyPod(const BASE_NS::string_view typeName, const BASE_NS::string_view name) override; 49 50 void Set(const BASE_NS::string_view name, const BASE_NS::array_view<const uint8_t> data) override; 51 BASE_NS::array_view<const uint8_t> Get(const BASE_NS::string_view name) const override; 52 53 BASE_NS::array_view<const BASE_NS::string> GetPodNames(const BASE_NS::string_view typeName) const override; 54 55 // for plugin / factory interface 56 static constexpr const char* const TYPE_NAME = "RenderDataStorePod"; 57 58 static IRenderDataStore* Create(IRenderContext& renderContext, char const* name); 59 static void Destroy(IRenderDataStore* instance); 60 GetTypeName()61 BASE_NS::string_view GetTypeName() const override 62 { 63 return TYPE_NAME; 64 } 65 GetName()66 BASE_NS::string_view GetName() const override 67 { 68 return name_; 69 } 70 GetUid()71 const BASE_NS::Uid& GetUid() const override 72 { 73 return UID; 74 } 75 76 private: 77 const BASE_NS::string name_; 78 79 // NOTE: allocate bigger blocks 80 BASE_NS::vector<uint8_t> dataStore_; 81 82 struct OffsetToData { 83 uint32_t index { 0 }; 84 uint32_t byteSize { 0 }; 85 uint32_t typeNameVectorIndex { 0 }; 86 }; 87 BASE_NS::unordered_map<BASE_NS::string, OffsetToData> nameToDataOffset_; 88 89 BASE_NS::unordered_map<BASE_NS::string, BASE_NS::vector<BASE_NS::string>> typeNameToPodNames_; 90 91 mutable std::mutex mutex_; 92 }; 93 RENDER_END_NAMESPACE() 94 95 #endif // RENDER_DATA_STORE_RENDER_DATA_STORE_POD_H 96