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 #include "ohos_adapter/bridge/ark_screen_capture_adapter_wrapper.h" 17 18 #include "ohos_adapter/bridge/ark_screen_capture_callback_adapter_impl.h" 19 #include "ohos_adapter/bridge/ark_screen_capture_config_adapter_impl.h" 20 #include "ohos_adapter/bridge/ark_surface_buffer_adapter_wrapper.h" 21 22 #include "base/bridge/ark_web_bridge_macros.h" 23 24 namespace OHOS::ArkWeb { 25 ArkScreenCaptureAdapterWrapper(ArkWebRefPtr<ArkScreenCaptureAdapter> ref)26ArkScreenCaptureAdapterWrapper::ArkScreenCaptureAdapterWrapper(ArkWebRefPtr<ArkScreenCaptureAdapter> ref) : ctocpp_(ref) 27 {} 28 Init(const std::shared_ptr<NWeb::ScreenCaptureConfigAdapter> config)29int32_t ArkScreenCaptureAdapterWrapper::Init(const std::shared_ptr<NWeb::ScreenCaptureConfigAdapter> config) 30 { 31 if (CHECK_SHARED_PTR_IS_NULL(config)) { 32 return ctocpp_->Init(nullptr); 33 } 34 return ctocpp_->Init(new ArkScreenCaptureConfigAdapterImpl(config)); 35 } 36 SetMicrophoneEnable(bool enable)37int32_t ArkScreenCaptureAdapterWrapper::SetMicrophoneEnable(bool enable) 38 { 39 return ctocpp_->SetMicrophoneEnable(enable); 40 } 41 StartCapture()42int32_t ArkScreenCaptureAdapterWrapper::StartCapture() 43 { 44 return ctocpp_->StartCapture(); 45 } 46 StopCapture()47int32_t ArkScreenCaptureAdapterWrapper::StopCapture() 48 { 49 return ctocpp_->StopCapture(); 50 } 51 SetCaptureCallback(const std::shared_ptr<OHOS::NWeb::ScreenCaptureCallbackAdapter> callback)52int32_t ArkScreenCaptureAdapterWrapper::SetCaptureCallback( 53 const std::shared_ptr<OHOS::NWeb::ScreenCaptureCallbackAdapter> callback) 54 { 55 if (CHECK_SHARED_PTR_IS_NULL(callback)) { 56 return ctocpp_->SetCaptureCallback(nullptr); 57 } 58 59 return ctocpp_->SetCaptureCallback(new ArkScreenCaptureCallbackAdapterImpl(callback)); 60 } 61 AcquireVideoBuffer()62std::shared_ptr<OHOS::NWeb::SurfaceBufferAdapter> ArkScreenCaptureAdapterWrapper::AcquireVideoBuffer() 63 { 64 ArkWebRefPtr<ArkSurfaceBufferAdapter> ref = ctocpp_->AcquireVideoBuffer(); 65 if (CHECK_REF_PTR_IS_NULL(ref)) { 66 return nullptr; 67 } 68 69 return std::make_shared<ArkSurfaceBufferAdapterWrapper>(ref); 70 } 71 ReleaseVideoBuffer()72int32_t ArkScreenCaptureAdapterWrapper::ReleaseVideoBuffer() 73 { 74 return ctocpp_->ReleaseVideoBuffer(); 75 } 76 77 } // namespace OHOS::ArkWeb 78