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 "pipeline/rs_uni_render_thread.h"
28 #include "platform/ohos/rs_jank_stats.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 
58     RSUniRenderThread& unirenderInstance_;
59 
60     std::mutex frameMutex_;
61     std::condition_variable frameCV_;
62     bool canUnblockMainThread = false;
63     std::unique_ptr<RSRenderThreadParams> stagingRenderThreadParams_ = nullptr;
64     RsParallelType rsParallelType_;
65     static bool debugTraceEnabled_;
66 };
67 } // namespace Rosen
68 } // namespace OHOS
69 
70 #endif // RENDER_SERVICE_PIPELINE_RS_DRAW_FRAME_H
71