• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_RENDER_3D_GRAPHICS_MANAGER_COMMON_H
17 #define OHOS_RENDER_3D_GRAPHICS_MANAGER_COMMON_H
18 
19 #include <unordered_set>
20 
21 #include <EGL/egl.h>
22 
23 #include "engine_factory.h"
24 #if defined(MULTI_ECS_UPDATE_AT_ONCE) && (MULTI_ECS_UPDATE_AT_ONCE == 1)
25 #include "frameworks/core/pipeline/pipeline_context.h"
26 #endif
27 #include "i_engine.h"
28 #include "offscreen_context_helper.h"
29 
30 namespace OHOS::Render3D {
31 struct TextureInfo;
32 struct PlatformData;
33 
34 enum class RenderBackend {
35     UNDEFINE,
36     GLES,
37     GL,
38     VULKAN,
39     METAL,
40 };
41 
42 class __attribute__((visibility("default"))) GraphicsManagerCommon {
43 public:
44     explicit GraphicsManagerCommon(const GraphicsManagerCommon&) = delete;
45     GraphicsManagerCommon& operator=(const GraphicsManagerCommon&) = delete;
46 
47     void Register(int32_t key, RenderBackend backend = RenderBackend::GLES);
48     void UnRegister(int32_t key);
49     std::unique_ptr<IEngine> GetEngine(EngineFactory::EngineType type, int32_t key);
50     std::unique_ptr<IEngine> GetEngine(EngineFactory::EngineType type, int32_t key, const HapInfo& hapInfo);
51     EGLContext GetOrCreateOffScreenContext(EGLContext eglContext);
52     void BindOffScreenContext();
53     virtual PlatformData GetPlatformData() const = 0;
54     virtual PlatformData GetPlatformData(const HapInfo& hapInfo) const = 0;
55     bool HasMultiEcs();
56     RenderBackend GetRenderBackendType(int32_t key);
57 #if defined(MULTI_ECS_UPDATE_AT_ONCE) && (MULTI_ECS_UPDATE_AT_ONCE == 1)
58     void AttachContext(const OHOS::Ace::WeakPtr<OHOS::Ace::PipelineContext> context);
59     void DrawFrame(void* ecs, void* handles);
60     void UnloadEcs(void* ecs);
61 #endif
62 
63 protected:
64     GraphicsManagerCommon() = default;
65     virtual ~GraphicsManagerCommon();
66     bool LoadEngineLib();
67     bool InitEngine(EGLContext eglContext, PlatformData data);
68     void DeInitEngine();
69     void UnloadEngineLib();
70 #if defined(MULTI_ECS_UPDATE_AT_ONCE) && (MULTI_ECS_UPDATE_AT_ONCE == 1)
71     void PerformDraw();
72 #endif
73 
74 private:
75     std::unordered_set<int32_t> viewTextures_;
76     OffScreenContextHelper offScreenContextHelper_;
77     std::unique_ptr<IEngine> engine_ = nullptr;
78     bool engineLoaded_ = false;
79     bool engineInited_ = false;
80     std::unordered_map<int32_t, RenderBackend> backends_;
81 #if defined(MULTI_ECS_UPDATE_AT_ONCE) && (MULTI_ECS_UPDATE_AT_ONCE == 1)
82     std::unordered_map<void*, void*> ecss_;
83 #endif
84 };
85 } // namespace OHOS::Render3D
86 #endif // OHOS_RENDER_3D_GRAPHICS_MANAGER_COMMON_H
87