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_OFFSCREEN_RENDER_THREAD_H 17 #define RS_OFFSCREEN_RENDER_THREAD_H 18 19 #include <functional> 20 #include <event_handler.h> 21 #include <map> 22 #include <mutex> 23 #include <sched.h> 24 25 #include "common/rs_common_def.h" 26 27 namespace OHOS::Rosen { 28 class RenderContext; 29 class RSB_EXPORT RSOffscreenRenderThread { 30 public: 31 static RSOffscreenRenderThread& Instance(); 32 void PostTask(const std::function<void()>& task); 33 void InSertCaptureTask(NodeId nodeId, std::function<void()>& task); 34 const std::function<void()> GetCaptureTask(NodeId nodeId); 35 #ifdef ROSEN_OHOS 36 const std::shared_ptr<RenderContext> GetRenderContext(); 37 void CleanGrResource(); 38 #endif 39 private: 40 RSOffscreenRenderThread(); 41 ~RSOffscreenRenderThread() = default; 42 RSOffscreenRenderThread(const RSOffscreenRenderThread&); 43 RSOffscreenRenderThread(const RSOffscreenRenderThread&&); 44 RSOffscreenRenderThread& operator=(const RSOffscreenRenderThread&); 45 RSOffscreenRenderThread& operator=(const RSOffscreenRenderThread&&); 46 47 std::mutex mutex_; 48 int offscreenRenderNum_ = 0; 49 50 std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr; 51 std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr; 52 #ifdef ROSEN_OHOS 53 std::shared_ptr<RenderContext> renderContext_ = nullptr; 54 #endif 55 std::map<NodeId, std::function<void()>> taskMap_; 56 }; 57 } 58 #endif // RS_OFFSCREEN_RENDER_THREAD_H 59