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