• 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 RENDER_SERVICE_CORE_PIPELINE_PARALLEL_RENDER_RS_SUB_THREAD_H
17 #define RENDER_SERVICE_CORE_PIPELINE_PARALLEL_RENDER_RS_SUB_THREAD_H
18 
19 #include <cstdint>
20 #include "EGL/egl.h"
21 #include "EGL/eglext.h"
22 #include "include/core/SkSurface.h"
23 #include "include/gpu/GrDirectContext.h"
24 #ifdef RS_ENABLE_VK
25 #include"include/gpu/vk/GrVkBackendContext.h"
26 #endif
27 #include "pipeline/parallel_render/rs_render_task.h"
28 #include "render_context/render_context.h"
29 #include "event_handler.h"
30 
31 namespace OHOS::Rosen {
32 class RSSubThread {
33 public:
RSSubThread(RenderContext * context,uint32_t threadIndex)34     RSSubThread(RenderContext* context, uint32_t threadIndex) : threadIndex_(threadIndex), renderContext_(context) {}
35     ~RSSubThread();
36 
37     pid_t Start();
38     void PostTask(const std::function<void()>& task, const std::string& name = std::string());
39     void PostSyncTask(const std::function<void()>& task);
40     void RemoveTask(const std::string& name);
41     void RenderCache(const std::shared_ptr<RSSuperRenderTask>& threadTask);
42     void ReleaseSurface();
43 #ifndef USE_ROSEN_DRAWING
44     void AddToReleaseQueue(sk_sp<SkSurface>&& surface);
45 #else
46     void AddToReleaseQueue(std::shared_ptr<Drawing::Surface>&& surface);
47 #endif
48     void ResetGrContext();
49     void DumpMem(DfxString& log);
50     MemoryGraphic CountSubMem(int pid);
51     float GetAppGpuMemoryInMB();
52 private:
53     void CreateShareEglContext();
54     void DestroyShareEglContext();
55 #ifndef USE_ROSEN_DRAWING
56     sk_sp<GrDirectContext> CreateShareGrContext();
57 #else
58     std::shared_ptr<Drawing::GPUContext> CreateShareGrContext();
59 #endif
60 
61     uint32_t threadIndex_;
62     std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
63     std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr;
64     RenderContext *renderContext_ = nullptr;
65 #ifdef RS_ENABLE_GL
66     EGLContext eglShareContext_ = EGL_NO_CONTEXT;
67 #endif
68 #ifndef USE_ROSEN_DRAWING
69     sk_sp<GrDirectContext> grContext_ = nullptr;
70 #else
71     std::shared_ptr<Drawing::GPUContext> grContext_ = nullptr;
72 #endif
73     std::mutex mutex_;
74 #ifndef USE_ROSEN_DRAWING
75     std::queue<sk_sp<SkSurface>> tmpSurfaces_;
76 #else
77     std::queue<std::shared_ptr<Drawing::Surface>> tmpSurfaces_;
78 #endif
79 };
80 }
81 #endif // RENDER_SERVICE_CORE_PIPELINE_PARALLEL_RENDER_RS_SUB_THREAD_H