• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 EFFECT_VULKAN_CONTEXT_H
17 #define EFFECT_VULKAN_CONTEXT_H
18 
19 #include "platform/ohos/backend/rs_vulkan_context.h"
20 
21 namespace OHOS::Rosen {
22 class EffectVulkanContext {
23 public:
24     class DrawContextHolder {
25     public:
DrawContextHolder(std::function<void ()> callback)26         explicit DrawContextHolder(std::function<void()> callback) : destructCallback_(std::move(callback)) {}
27 
~DrawContextHolder()28         ~DrawContextHolder()
29         {
30             destructCallback_();
31         }
32     private:
33         std::function<void()> destructCallback_;
34     };
35     static EffectVulkanContext& GetSingleton(const std::string& cacheDir = "");
36     explicit EffectVulkanContext(std::string cacheDir = "");
37     ~EffectVulkanContext();
38 
39     EffectVulkanContext(const EffectVulkanContext&) = delete;
40     EffectVulkanContext &operator=(const EffectVulkanContext&) = delete;
41     EffectVulkanContext(const EffectVulkanContext&&) = delete;
42     EffectVulkanContext &operator=(const EffectVulkanContext&&) = delete;
43 
44     std::shared_ptr<Drawing::GPUContext> CreateDrawingContext();
45     static void ReleaseDrawingContextForThread(int tid);
46 
47     static void SaveNewDrawingContext(int tid, std::shared_ptr<Drawing::GPUContext> drawingContext);
48 private:
49     std::shared_ptr<RsVulkanInterface> vulkanInterface_;
50     static std::map<int, std::shared_ptr<Drawing::GPUContext>> drawingContextMap_;
51     static std::mutex drawingContextMutex_;
52 };
53 }
54 
55 #endif