• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OH_VEF_GRAPHICS_RENDER_ENGINE_H
17 #define OH_VEF_GRAPHICS_RENDER_ENGINE_H
18 
19 #include <GLES3/gl3.h>
20 #include "native_image.h"
21 #include "render/graphics/base/render_attribute.h"
22 #include "render/graphics/base/render_context.h"
23 #include "render/graphics/base/render_surface.h"
24 #include "render/graphics/base/shader_pass/shader_pass_rotate.h"
25 #include "render/graphics/base/shader_pass/shader_pass_surface.h"
26 #include "render/graphics/base/shader_pass/shader_pass_on_screen.h"
27 #include "render/graphics/effect/image_effect_render.h"
28 #include "render/graphics/base/surface_texture.h"
29 #include "render/graphics/base/worker/render_work.h"
30 #include "render/graphics/graphics_render_engine.h"
31 
32 namespace OHOS {
33 namespace Media {
34 class GraphicsRenderEngineImpl : public IGraphicsRenderEngine {
35 public:
36     explicit GraphicsRenderEngineImpl(uint64_t id);
37     virtual ~GraphicsRenderEngineImpl();
38     VEFError Init(OHNativeWindow* outputWindow) override;
39     VEFError StartRender() override;
40     VEFError StopRender() override;
41     VEFError UnInit() override;
42     VEFError Render(uint64_t index, const std::shared_ptr<GraphicsRenderInfo>& effectInfo,
43         const RenderResultCallback& cb) override;
44     OHNativeWindow* GetInputWindow() override;
45 
46 private:
47     void Destroy();
48     std::string GetThreadId() const;
49     VEFError InitThread();
50     void ReleaseThread();
51     uint64_t RequestTaskId();
52     VEFError InitExportEngine(OHNativeWindow* window);
53     VEFError InitSurfaceTexture();
54     RenderTexturePtr RenderFrame(const std::shared_ptr<GraphicsRenderInfo>& graphicsRenderInfo);
55     RenderTexturePtr RenderEffects(const RenderTexturePtr& inputTexture,
56         const std::shared_ptr<GraphicsRenderInfo>& graphicsRenderInfo);
57     void DrawFrame(uint64_t pts, const RenderTexturePtr& renderTexture);
58 
59 private:
60     std::recursive_mutex renderMutex_;
61     volatile bool ready_ = { false };
62     RenderThread<>* renderThread_{ nullptr };
63     OHNativeWindow* exportWindow_{ nullptr };
64     RenderAttribute attribute_;
65     std::shared_ptr<SurfaceTexture> surfaceTexture_{ nullptr };
66     RenderSurface* surface_{ nullptr };
67     std::shared_ptr<RenderContext> context_{ nullptr };
68     std::atomic_uint64_t currentTaskId_{ 0 };
69 
70     std::shared_ptr<ShaderPassSurface> shaderPassSurface_{ nullptr };
71     std::shared_ptr<ShaderPassOnScreen> shaderPassOnScreen_{ nullptr };
72     std::shared_ptr<ShaderPassRotate> shaderPassRotate_{ nullptr };
73     std::unordered_map<uint64_t, std::shared_ptr<ImageEffectRender>> imageEffectRenderList_;
74 
75     uint64_t id_{ 0 };
76 };
77 }
78 }
79 
80 #endif