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 #include "image/gpu_context.h" 23 #endif 24 25 namespace OHOS::Rosen { 26 class RenderContext; 27 28 class RSB_EXPORT RSBackgroundThread final { 29 public: 30 static RSBackgroundThread& Instance(); 31 void PostTask(const std::function<void()>& task); 32 void PostSyncTask(const std::function<void()>& task); 33 #if defined(RS_ENABLE_UNI_RENDER) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK)) 34 void InitRenderContext(RenderContext* context); 35 void CleanGrResource(); 36 std::shared_ptr<Drawing::GPUContext> GetShareGPUContext() const; 37 #endif 38 private: 39 RSBackgroundThread(); 40 ~RSBackgroundThread() = default; 41 RSBackgroundThread(const RSBackgroundThread&); 42 RSBackgroundThread(const RSBackgroundThread&&); 43 RSBackgroundThread& operator=(const RSBackgroundThread&); 44 RSBackgroundThread& operator=(const RSBackgroundThread&&); 45 46 std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr; 47 std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr; 48 #if defined(RS_ENABLE_UNI_RENDER) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK)) 49 #ifdef RS_ENABLE_GL 50 void CreateShareEglContext(); 51 EGLContext eglShareContext_ = static_cast<EGLContext>(0); 52 #endif 53 RenderContext* renderContext_ = nullptr; 54 std::shared_ptr<Drawing::GPUContext> CreateShareGPUContext(); 55 std::shared_ptr<Drawing::GPUContext> gpuContext_ = nullptr; 56 #endif 57 }; 58 } 59 #endif // RS_BACKGROUND_THREAD_H 60