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 "rs_trace.h"
19 
20 #include "pipeline/rs_uni_render_thread.h"
21 #include "platform/common/rs_log.h"
22 #include "platform/common/rs_system_properties.h"
23 
24 #ifdef RS_PROFILER_ENABLED
25 #include "rs_profiler_capture_recorder.h"
26 #endif
27 
28 namespace OHOS::Rosen {
29 
TryCapture() const30 void RSSkpCaptureDfx::TryCapture() const
31 {
32     if (!curCanvas_) {
33         RS_LOGE("TryCapture curCanvas_ is nullptr");
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     } else {
46         RS_LOGE("TryCapture failed, the recording parameters have not been set.");
47     }
48 }
49 
EndCapture() const50 void RSSkpCaptureDfx::EndCapture() const
51 {
52     auto renderContext = RSUniRenderThread::Instance().GetRenderEngine()->GetRenderContext();
53     if (!renderContext) {
54         RS_LOGE("EndCapture renderContext is nullptr");
55         return;
56     }
57 #ifdef RS_PROFILER_ENABLED
58     RSCaptureRecorder::GetInstance().EndInstantCapture();
59 #endif
60     return;
61 }
62 
63 } // namespace OHOS::Rosen