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