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 #if defined(NEW_SKIA) 24 #include "include/gpu/GrDirectContext.h" 25 #else 26 #include "include/gpu/GrContext.h" 27 #endif 28 #include "pipeline/parallel_render/rs_render_task.h" 29 #include "render_context/render_context.h" 30 #include "event_handler.h" 31 32 namespace OHOS::Rosen { 33 class RSSubThread { 34 public: RSSubThread(RenderContext * context,uint32_t threadIndex)35 RSSubThread(RenderContext* context, uint32_t threadIndex) : threadIndex_(threadIndex), renderContext_(context) {} 36 ~RSSubThread(); 37 38 void Start(); 39 void PostTask(const std::function<void()>& task); 40 void PostSyncTask(const std::function<void()>& task); 41 void RenderCache(const std::shared_ptr<RSSuperRenderTask>& threadTask); 42 void ResetGrContext(); 43 void DumpMem(DfxString& log); 44 private: 45 void CreateShareEglContext(); 46 void DestroyShareEglContext(); 47 #ifndef USE_ROSEN_DRAWING 48 #ifdef NEW_SKIA 49 sk_sp<GrDirectContext> CreateShareGrContext(); 50 #else 51 sk_sp<GrContext> CreateShareGrContext(); 52 #endif 53 #else 54 std::shared_ptr<Drawing::GPUContext> CreateShareGrContext(); 55 #endif 56 57 uint32_t threadIndex_; 58 std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr; 59 std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr; 60 RenderContext *renderContext_ = nullptr; 61 EGLContext eglShareContext_ = EGL_NO_CONTEXT; 62 #ifndef USE_ROSEN_DRAWING 63 #ifdef NEW_SKIA 64 sk_sp<GrDirectContext> grContext_ = nullptr; 65 #else 66 sk_sp<GrContext> grContext_ = nullptr; 67 #endif 68 #else 69 std::shared_ptr<Drawing::GPUContext> grContext_ = nullptr; 70 #endif 71 }; 72 } 73 #endif // RENDER_SERVICE_CORE_PIPELINE_PARALLEL_RENDER_RS_SUB_THREAD_H