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_producer_surface_adapter_wrapper.h"
17
18 #include "ohos_adapter/bridge/ark_buffer_flush_config_adapter_impl.h"
19 #include "ohos_adapter/bridge/ark_buffer_request_config_adapter_impl.h"
20 #include "ohos_adapter/bridge/ark_ibuffer_consumer_listener_adapter_impl.h"
21 #include "ohos_adapter/bridge/ark_surface_buffer_adapter_wrapper.h"
22
23 #include "base/bridge/ark_web_bridge_macros.h"
24
25 namespace OHOS::ArkWeb {
26
ArkProducerSurfaceAdapterWrapper(ArkWebRefPtr<ArkProducerSurfaceAdapter> ref)27 ArkProducerSurfaceAdapterWrapper::ArkProducerSurfaceAdapterWrapper(ArkWebRefPtr<ArkProducerSurfaceAdapter> ref)
28 : ctocpp_(ref)
29 {}
30
RequestBuffer(int32_t & fence,std::shared_ptr<OHOS::NWeb::BufferRequestConfigAdapter> config)31 std::shared_ptr<OHOS::NWeb::SurfaceBufferAdapter> ArkProducerSurfaceAdapterWrapper::RequestBuffer(
32 int32_t& fence, std::shared_ptr<OHOS::NWeb::BufferRequestConfigAdapter> config)
33 {
34 ArkWebRefPtr<ArkSurfaceBufferAdapter> surface;
35 if (CHECK_SHARED_PTR_IS_NULL(config)) {
36 surface = ctocpp_->RequestBuffer(fence, nullptr);
37 } else {
38 surface = ctocpp_->RequestBuffer(fence, new ArkBufferRequestConfigAdapterImpl(config));
39 }
40
41 if (CHECK_REF_PTR_IS_NULL(surface)) {
42 return nullptr;
43 }
44
45 return std::make_shared<ArkSurfaceBufferAdapterWrapper>(surface);
46 }
47
FlushBuffer(std::shared_ptr<OHOS::NWeb::SurfaceBufferAdapter> buffer,int32_t fence,std::shared_ptr<OHOS::NWeb::BufferFlushConfigAdapter> config)48 int32_t ArkProducerSurfaceAdapterWrapper::FlushBuffer(std::shared_ptr<OHOS::NWeb::SurfaceBufferAdapter> buffer,
49 int32_t fence, std::shared_ptr<OHOS::NWeb::BufferFlushConfigAdapter> config)
50 {
51 std::shared_ptr<ArkSurfaceBufferAdapterWrapper> bufferWrapper =
52 std::static_pointer_cast<ArkSurfaceBufferAdapterWrapper>(buffer);
53 if (CHECK_SHARED_PTR_IS_NULL(config)) {
54 return ctocpp_->FlushBuffer(bufferWrapper->ctocpp_, fence, nullptr);
55 }
56
57 return ctocpp_->FlushBuffer(bufferWrapper->ctocpp_, fence, new ArkBufferFlushConfigAdapterImpl(config));
58 }
59 } // namespace OHOS::ArkWeb
60