• 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 DrawableCache(std::shared_ptr<DrawableV2::RSSurfaceRenderNodeDrawable> nodeDrawable);
42     void ReleaseSurface();
43     void ReleaseCacheSurfaceOnly(std::shared_ptr<DrawableV2::RSSurfaceRenderNodeDrawable> nodeDrawable);
44     void AddToReleaseQueue(std::shared_ptr<Drawing::Surface>&& surface);
45     void ResetGrContext();
46     void ThreadSafetyReleaseTexture();
47     void DumpMem(DfxString& log);
48     MemoryGraphic CountSubMem(int pid);
49     float GetAppGpuMemoryInMB();
GetDoingCacheProcessNum()50     unsigned int GetDoingCacheProcessNum()
51     {
52         return doingCacheProcessNum_.load();
53     }
DoingCacheProcessNumInc()54     inline void DoingCacheProcessNumInc()
55     {
56         doingCacheProcessNum_++;
57     }
58     void DrawableCacheWithSkImage(std::shared_ptr<DrawableV2::RSSurfaceRenderNodeDrawable> nodeDrawable);
GetGrContext()59     std::shared_ptr<Drawing::GPUContext> GetGrContext() const
60     {
61         return grContext_;
62     }
63 
64 private:
65     void CreateShareEglContext();
66     void DestroyShareEglContext();
67     std::shared_ptr<Drawing::GPUContext> CreateShareGrContext();
68     void SetHighContrastIfEnabled(RSPaintFilterCanvas& canvas);
69 
70     std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
71     std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr;
72     uint32_t threadIndex_ = UNI_RENDER_THREAD_INDEX;
73     RenderContext *renderContext_ = nullptr;
74 #ifdef RS_ENABLE_GL
75     EGLContext eglShareContext_ = EGL_NO_CONTEXT;
76 #endif
77     std::shared_ptr<Drawing::GPUContext> grContext_ = nullptr;
78     std::mutex mutex_;
79     std::queue<std::shared_ptr<Drawing::Surface>> tmpSurfaces_;
80     std::atomic<unsigned int> doingCacheProcessNum_ = 0;
81 };
82 }
83 #endif // RENDER_SERVICE_CORE_PIPELINE_PARALLEL_RENDER_RS_SUB_THREAD_H