• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "drawable/dfx/rs_skp_capture_dfx.h"
17 
18 #include "benchmarks/rs_recording_thread.h"
19 #include "rs_trace.h"
20 
21 #include "pipeline/rs_uni_render_thread.h"
22 #include "platform/common/rs_log.h"
23 #include "platform/common/rs_system_properties.h"
24 
25 #ifdef RS_PROFILER_ENABLED
26 #include "rs_profiler_capture_recorder.h"
27 #endif
28 
29 namespace OHOS::Rosen {
30 
TryCapture() const31 void RSSkpCaptureDfx::TryCapture() const
32 {
33     if (!curCanvas_) {
34         return;
35     }
36     if (!RSSystemProperties::GetRecordingEnabled()) {
37 #ifdef RS_PROFILER_ENABLED
38         auto width = curCanvas_->GetWidth();
39         auto height = curCanvas_->GetHeight();
40         if (auto canvas = RSCaptureRecorder::GetInstance().TryInstantCapture(width, height)) {
41             curCanvas_->AddCanvas(canvas);
42         }
43 #endif
44         return;
45     }
46     recordingCanvas_ = std::make_shared<ExtendRecordingCanvas>(curCanvas_->GetWidth(), curCanvas_->GetHeight());
47     RS_TRACE_NAME("RSDisplayRenderNodeDrawable:Recording begin");
48     std::shared_ptr<RenderContext> renderContext;
49 #if defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK)
50     renderContext = RSUniRenderThread::Instance().GetRenderEngine()->GetRenderContext();
51     if (!recordingCanvas_) {
52         RS_LOGE("TryCapture recordingCanvas_ is nullptr");
53         return;
54     }
55     if (!renderContext) {
56         RS_LOGE("TryCapture renderContext is nullptr");
57         return;
58     }
59     recordingCanvas_->SetGrRecordingContext(renderContext->GetSharedDrGPUContext());
60 #endif
61     if (!curCanvas_) {
62         RS_LOGE("TryCapture curCanvas_ is nullptr");
63         return;
64     }
65     curCanvas_->AddCanvas(recordingCanvas_.get());
66     RSRecordingThread::Instance(renderContext.get()).CheckAndRecording();
67 }
68 
EndCapture() const69 void RSSkpCaptureDfx::EndCapture() const
70 {
71     auto renderContext = RSUniRenderThread::Instance().GetRenderEngine()->GetRenderContext();
72     if (!renderContext) {
73         RS_LOGE("EndCapture renderContext is nullptr");
74         return;
75     }
76     if (!RSRecordingThread::Instance(renderContext.get()).GetRecordingEnabled()) {
77 #ifdef RS_PROFILER_ENABLED
78         RSCaptureRecorder::GetInstance().EndInstantCapture();
79 #endif
80         return;
81     }
82     auto drawCmdList = recordingCanvas_->GetDrawCmdList();
83     RS_TRACE_NAME("RSUniRender:RecordingToFile curFrameNum = " +
84                   std::to_string(RSRecordingThread::Instance(renderContext.get()).GetCurDumpFrame()));
85     RSRecordingThread::Instance(renderContext.get()).RecordingToFile(drawCmdList);
86 }
87 
88 } // namespace OHOS::Rosen