• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ROSEN_RENDER_SERVICE_BASE_BENCHMARKS_RS_RECORDING_THREAD_H
17 #define ROSEN_RENDER_SERVICE_BASE_BENCHMARKS_RS_RECORDING_THREAD_H
18 
19 
20 #include <cstdint>
21 #include <sys/stat.h>
22 #include "benchmarks/file_utils.h"
23 #include "common/rs_common_def.h"
24 #include "common/rs_macros.h"
25 #include "event_handler.h"
26 #include "EGL/egl.h"
27 #include "EGL/eglext.h"
28 #include "include/core/SkSurface.h"
29 #if defined(NEW_SKIA)
30 #include "include/gpu/GrDirectContext.h"
31 #else
32 #include "include/gpu/GrContext.h"
33 #endif
34 #ifndef USE_ROSEN_DRAWING
35 #include "pipeline/rs_draw_cmd_list.h"
36 #else
37 #include "recording/draw_cmd_list.h"
38 #endif
39 #include "render_context/render_context.h"
40 
41 namespace OHOS::Rosen {
42 class RSB_EXPORT RSRecordingThread {
43 public:
44     enum class RecordingMode {
45         STOP_RECORDING,
46         LOW_SPEED_RECORDING,
47         HIGH_SPPED_RECORDING,
48     };
49 
RSRecordingThread(RenderContext * context)50     RSRecordingThread(RenderContext* context) : renderContext_(context){};
51     ~RSRecordingThread();
52 
53     static RSRecordingThread& Instance(RenderContext* context);
54     void Start();
55     bool IsIdle();
56     void PostTask(const std::function<void()> & task);
57     bool CheckAndRecording();
58     void FinishRecordingOneFrame();
59 #ifndef USE_ROSEN_DRAWING
60     void RecordingToFile(const std::shared_ptr<DrawCmdList> & drawCmdList);
61 #else
62     void RecordingToFile(const std::shared_ptr<Drawing::DrawCmdList> & drawCmdList);
63 #endif
GetCurDumpFrame()64     [[nodiscard]] int GetCurDumpFrame() const
65     {
66         return curDumpFrame_;
67     }
GetRecordingEnabled()68     bool GetRecordingEnabled() const
69     {
70         return mode_ != RecordingMode::STOP_RECORDING;
71     }
72 
73 private:
74     void CreateShareEglContext();
75     void DestroyShareEglContext();
76     void FinishRecordingOneFrameTask(RecordingMode mode);
77 #ifndef USE_ROSEN_DRAWING
78 #ifdef NEW_SKIA
79     sk_sp<GrDirectContext> CreateShareGrContext();
80 #else
81     sk_sp<GrContext> CreateShareGrContext();
82 #endif
83 #else
84     std::shared_ptr<Drawing::GPUContext> CreateShareGrContext();
85 #endif
86 
87     const static size_t RECORDING_PARCEL_CAPCITY = 234 * 1000 * 1024;
88     RenderContext *renderContext_ = nullptr;
89 #ifdef RS_ENABLE_GL
90     EGLContext eglShareContext_ = EGL_NO_CONTEXT;
91 #endif
92 #ifndef USE_ROSEN_DRAWING
93 #ifdef NEW_SKIA
94     sk_sp<GrDirectContext> grContext_ = nullptr;
95 #else
96     sk_sp<GrContext> grContext_ = nullptr;
97 #endif
98 #else
99     std::shared_ptr<Drawing::GPUContext> grContext_ = nullptr;
100 #endif
101     RecordingMode mode_ = RecordingMode::STOP_RECORDING;
102 #ifndef USE_ROSEN_DRAWING
103     std::vector<std::shared_ptr<DrawCmdList>> drawCmdListVec_;
104 #else
105     std::vector<std::shared_ptr<Drawing::DrawCmdList>> drawCmdListVec_;
106 #endif
107     std::vector<std::shared_ptr<MessageParcel>> messageParcelVec_;
108     std::vector<std::string> opsDescriptionVec_;
109     std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
110     std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr;
111     std::string fileDir_ = "/data/";
112     int dumpFrameNum_ = 0;
113     int curDumpFrame_ = 0;
114 };
115 } // namespace OHOS::Rosen
116 
117 #endif // ROSEN_RENDER_SERVICE_BASE_BENCHMARKS_RS_RECORDING_THREAD_H