• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_iconsumer_surface_adapter_wrapper.h"
17 
18 #include "ohos_adapter/bridge/ark_ibuffer_consumer_listener_adapter_impl.h"
19 #include "ohos_adapter/bridge/ark_surface_buffer_adapter_wrapper.h"
20 
21 #include "base/bridge/ark_web_bridge_macros.h"
22 
23 namespace OHOS::ArkWeb {
24 
ArkIConsumerSurfaceAdapterWrapper(ArkWebRefPtr<ArkIConsumerSurfaceAdapter> ref)25 ArkIConsumerSurfaceAdapterWrapper::ArkIConsumerSurfaceAdapterWrapper(ArkWebRefPtr<ArkIConsumerSurfaceAdapter> ref)
26     : ctocpp_(ref)
27 {}
28 
RegisterConsumerListener(std::shared_ptr<OHOS::NWeb::IBufferConsumerListenerAdapter> listener)29 int32_t ArkIConsumerSurfaceAdapterWrapper::RegisterConsumerListener(
30     std::shared_ptr<OHOS::NWeb::IBufferConsumerListenerAdapter> listener)
31 {
32     if (CHECK_SHARED_PTR_IS_NULL(listener)) {
33         return ctocpp_->RegisterConsumerListener(nullptr);
34     }
35 
36     return ctocpp_->RegisterConsumerListener(new ArkIBufferConsumerListenerAdapterImpl(listener));
37 }
38 
ReleaseBuffer(std::shared_ptr<OHOS::NWeb::SurfaceBufferAdapter> buffer,int32_t fence)39 int32_t ArkIConsumerSurfaceAdapterWrapper::ReleaseBuffer(
40     std::shared_ptr<OHOS::NWeb::SurfaceBufferAdapter> buffer, int32_t fence)
41 {
42     std::shared_ptr<ArkSurfaceBufferAdapterWrapper> bufferWrapper =
43         std::static_pointer_cast<ArkSurfaceBufferAdapterWrapper>(buffer);
44     return ctocpp_->ReleaseBuffer(bufferWrapper->ctocpp_, fence);
45 }
46 
SetUserData(const std::string & key,const std::string & val)47 int32_t ArkIConsumerSurfaceAdapterWrapper::SetUserData(const std::string& key, const std::string& val)
48 {
49     ArkWebString ark_key = ArkWebStringClassToStruct(key);
50     ArkWebString ark_val = ArkWebStringClassToStruct(val);
51     int32_t result = ctocpp_->SetUserData(ark_key, ark_val);
52     ArkWebStringStructRelease(ark_key);
53     ArkWebStringStructRelease(ark_val);
54     return result;
55 }
56 
SetQueueSize(uint32_t queueSize)57 int32_t ArkIConsumerSurfaceAdapterWrapper::SetQueueSize(uint32_t queueSize)
58 {
59     return ctocpp_->SetQueueSize(queueSize);
60 }
61 
62 } // namespace OHOS::ArkWeb
63