1 /* 2 * Copyright (c) 2025 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 DRAWING_GPU_CONTEXT_MANAGER_H 17 #define DRAWING_GPU_CONTEXT_MANAGER_H 18 19 #include <mutex> 20 #include <unordered_map> 21 22 #include "render_context/render_context.h" 23 24 namespace OHOS { 25 namespace Rosen { 26 27 class DrawingGpuContextManager { 28 public: 29 DrawingGpuContextManager(const DrawingGpuContextManager&) = delete; 30 DrawingGpuContextManager(const DrawingGpuContextManager&&) = delete; 31 DrawingGpuContextManager& operator=(const DrawingGpuContextManager&) = delete; 32 DrawingGpuContextManager& operator=(const DrawingGpuContextManager&&) = delete; 33 34 static DrawingGpuContextManager& GetInstance(); 35 36 std::shared_ptr<RenderContext> GetRenderContext(); 37 38 std::shared_ptr<Drawing::GPUContext> CreateDrawingContext(); 39 40 void Insert(void* key, std::shared_ptr<Drawing::GPUContext> gpuContext); 41 std::shared_ptr<Drawing::GPUContext> Find(void* key); 42 bool Remove(void* key); 43 44 private: 45 DrawingGpuContextManager(); 46 47 std::shared_ptr<RenderContext> renderContext_ = nullptr; 48 std::unordered_map<void*, std::shared_ptr<Drawing::GPUContext>> gpuContext_; 49 std::mutex mutex_; 50 }; 51 } // namespace Rosen 52 } // namespace OHOS 53 #endif // DRAWING_GPU_CONTEXT_MANAGER_H