• 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 RS_BACKGROUND_THREAD_H
17 #define RS_BACKGROUND_THREAD_H
18 
19 #include "event_handler.h"
20 #include "common/rs_macros.h"
21 #if defined(RS_ENABLE_UNI_RENDER) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
22 #ifndef USE_ROSEN_DRAWING
23 #ifdef RS_ENABLE_GL
24 #include "EGL/egl.h"
25 #include "EGL/eglext.h"
26 #endif
27 #include "include/core/SkSurface.h"
28 #if defined(NEW_SKIA)
29 #include "include/gpu/GrDirectContext.h"
30 #endif
31 #else
32 #include "image/gpu_context.h"
33 #endif
34 #endif
35 
36 namespace OHOS::Rosen {
37 class RenderContext;
38 
39 class RSB_EXPORT RSBackgroundThread final {
40 public:
41     static RSBackgroundThread& Instance();
42     void PostTask(const std::function<void()>& task);
43 #if defined(RS_ENABLE_UNI_RENDER) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
44     void InitRenderContext(RenderContext* context);
45     void CleanGrResource();
46 #ifndef USE_ROSEN_DRAWING
47     sk_sp<GrDirectContext> GetShareGrContext() const;
48 #else
49     std::shared_ptr<Drawing::GPUContext> GetShareGPUContext() const;
50 #endif
51 #endif
52 private:
53     RSBackgroundThread();
54     ~RSBackgroundThread() = default;
55     RSBackgroundThread(const RSBackgroundThread&);
56     RSBackgroundThread(const RSBackgroundThread&&);
57     RSBackgroundThread& operator=(const RSBackgroundThread&);
58     RSBackgroundThread& operator=(const RSBackgroundThread&&);
59 
60     std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
61     std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr;
62 #if defined(RS_ENABLE_UNI_RENDER) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
63 #ifdef RS_ENABLE_GL
64     void CreateShareEglContext();
65 #ifndef USE_ROSEN_DRAWING
66     EGLContext eglShareContext_ = EGL_NO_CONTEXT;
67 #else
68     EGLContext eglShareContext_ = static_cast<EGLContext>(0);
69 #endif
70 #endif
71     RenderContext* renderContext_ = nullptr;
72 #ifndef USE_ROSEN_DRAWING
73     sk_sp<GrDirectContext> CreateShareGrContext();
74     sk_sp<GrDirectContext> grContext_ = nullptr;
75 #else
76     std::shared_ptr<Drawing::GPUContext> CreateShareGPUContext();
77     std::shared_ptr<Drawing::GPUContext> gpuContext_ = nullptr;
78 #endif
79 #endif
80 };
81 }
82 #endif // RS_BACKGROUND_THREAD_H
83