1 /* 2 * Copyright (c) 2021-2025 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_PIPELINE_RS_DRAW_FRAME_H 17 #define RENDER_SERVICE_PIPELINE_RS_DRAW_FRAME_H 18 #include <condition_variable> 19 #include <cstdint> 20 #include <list> 21 #include <mutex> 22 23 #include "system/rs_system_parameters.h" 24 25 #include "common/rs_exception_check.h" 26 #include "params/rs_render_thread_params.h" 27 #include "pipeline/rs_render_node.h" 28 #include "platform/ohos/rs_jank_stats_helper.h" 29 #include "rs_uni_render_thread.h" 30 31 namespace OHOS { 32 namespace Rosen { 33 class RSDrawFrame { 34 public: 35 RSDrawFrame(); 36 ~RSDrawFrame() noexcept; 37 38 RSDrawFrame(const RSDrawFrame&) = delete; 39 RSDrawFrame(const RSDrawFrame&&) = delete; 40 RSDrawFrame& operator=(const RSDrawFrame&) = delete; 41 RSDrawFrame& operator=(const RSDrawFrame&&) = delete; 42 43 void SetRenderThreadParams(std::unique_ptr<RSRenderThreadParams>& stagingRenderThreadParams); 44 void PostAndWait(); 45 void PostDirectCompositionJankStats(const JankDurationParams& rsParams, bool optimizeLoad); 46 47 private: 48 void RenderFrame(); 49 void SetEarlyZEnabled(Drawing::GPUContext* gpuContext); 50 void UnblockMainThread(); 51 void Sync(); 52 void Render(); 53 void ReleaseSpecialDrawingNodeBuffer(); 54 void NotifyClearGpuCache(); 55 bool CheckCanvasSkipSync(std::shared_ptr<RSRenderNode>); 56 void StartCheck(); 57 void EndCheck(); 58 59 RSUniRenderThread& unirenderInstance_; 60 61 std::mutex frameMutex_; 62 std::condition_variable frameCV_; 63 bool canUnblockMainThread = false; 64 std::unique_ptr<RSRenderThreadParams> stagingRenderThreadParams_ = nullptr; 65 std::unordered_map<NodeId, std::weak_ptr<RSRenderNode>> stagingSyncCanvasDrawingNodes_; 66 RsParallelType rsParallelType_; 67 static bool debugTraceEnabled_; 68 std::shared_ptr<RSTimer> timer_ = nullptr; 69 int longFrameCount_ = 0; 70 ExceptionCheck exceptionCheck_; 71 }; 72 } // namespace Rosen 73 } // namespace OHOS 74 75 #endif // RENDER_SERVICE_PIPELINE_RS_DRAW_FRAME_H 76