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/render_thread/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() const30void 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 if (auto canvas = 39 RSCaptureRecorder::GetInstance().TryInstantCapture(static_cast<float>(curCanvas_->GetWidth()), 40 static_cast<float>(curCanvas_->GetHeight()), SkpCaptureType::DEFAULT)) { 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() const50void RSSkpCaptureDfx::EndCapture() const 51 { 52 #ifdef RS_ENABLE_GPU 53 auto renderContext = RSUniRenderThread::Instance().GetRenderEngine()->GetRenderContext(); 54 if (!renderContext) { 55 RS_LOGE("EndCapture renderContext is nullptr"); 56 return; 57 } 58 #endif 59 #ifdef RS_PROFILER_ENABLED 60 RSCaptureRecorder::GetInstance().EndInstantCapture(SkpCaptureType::DEFAULT); 61 #endif 62 return; 63 } 64 65 } // namespace OHOS::Rosen