1 /* 2 * Copyright (c) 2021-2022 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 "params/rs_render_thread_params.h" 26 #include "pipeline/rs_render_node.h" 27 #include "platform/ohos/rs_jank_stats.h" 28 #include "rs_uni_render_thread.h" 29 30 namespace OHOS { 31 namespace Rosen { 32 class RSDrawFrame { 33 public: 34 RSDrawFrame(); 35 ~RSDrawFrame() noexcept; 36 37 RSDrawFrame(const RSDrawFrame&) = delete; 38 RSDrawFrame(const RSDrawFrame&&) = delete; 39 RSDrawFrame& operator=(const RSDrawFrame&) = delete; 40 RSDrawFrame& operator=(const RSDrawFrame&&) = delete; 41 42 void SetRenderThreadParams(std::unique_ptr<RSRenderThreadParams>& stagingRenderThreadParams); 43 void PostAndWait(); 44 void PostDirectCompositionJankStats(const JankDurationParams& rsParams); 45 46 private: 47 void RenderFrame(); 48 void UnblockMainThread(); 49 void Sync(); 50 void Render(); 51 void ReleaseSelfDrawingNodeBuffer(); 52 void JankStatsRenderFrameStart(); 53 bool IsUniRenderAndOnVsync() const; 54 void NotifyClearGpuCache(); 55 void JankStatsRenderFrameAfterSync(bool doJankStats); 56 void JankStatsRenderFrameEnd(bool doJankStats); 57 bool CheckCanvasSkipSync(std::shared_ptr<RSRenderNode>); 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 }; 69 } // namespace Rosen 70 } // namespace OHOS 71 72 #endif // RENDER_SERVICE_PIPELINE_RS_DRAW_FRAME_H 73