• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SURFACE_ADAPTER_IMPL_H
17 #define SURFACE_ADAPTER_IMPL_H
18 
19 #include "graphic_adapter.h"
20 #include "ibuffer_consumer_listener.h"
21 #include "iconsumer_surface.h"
22 
23 namespace OHOS::NWeb {
24 class SurfaceBufferAdapterImpl : public SurfaceBufferAdapter {
25 public:
26     explicit SurfaceBufferAdapterImpl(sptr<SurfaceBuffer> buffer);
27 
28     ~SurfaceBufferAdapterImpl() override = default;
29 
30     int32_t GetFileDescriptor() const override;
31 
32     int32_t GetWidth() const override;
33 
34     int32_t GetHeight() const override;
35 
36     int32_t GetStride() const override;
37 
38     int32_t GetFormat() const override;
39 
40     uint32_t GetSize() const override;
41 
42     void *GetVirAddr() const override;
43 
44     sptr<SurfaceBuffer>& GetBuffer();
45 
46 private:
47     sptr<SurfaceBuffer> buffer_ = nullptr;
48 };
49 
50 class BufferConsumerListenerImpl : public IBufferConsumerListener {
51 public:
52     BufferConsumerListenerImpl(
53         wptr<IConsumerSurface> surface, std::unique_ptr<IBufferConsumerListenerAdapter> listener);
54 
55     ~BufferConsumerListenerImpl() override = default;
56 
57     void OnBufferAvailable() override;
58 
59 private:
60     wptr<IConsumerSurface> cSurface_ = nullptr;
61 
62     std::unique_ptr<IBufferConsumerListenerAdapter> listener_ = nullptr;
63 };
64 
65 class ConsumerSurfaceAdapterImpl : public IConsumerSurfaceAdapter {
66 public:
67     ConsumerSurfaceAdapterImpl();
68 
69     ~ConsumerSurfaceAdapterImpl() = default;
70 
71     int32_t RegisterConsumerListener(std::unique_ptr<IBufferConsumerListenerAdapter> listenerAdapter) override;
72 
73     int32_t ReleaseBuffer(std::unique_ptr<SurfaceBufferAdapter> bufferAdapter, int32_t fence) override;
74 
75     int32_t SetUserData(const std::string& key, const std::string& val) override;
76 
77     int32_t SetQueueSize(uint32_t queueSize) override;
78 
79     sptr<IConsumerSurface>& GetConsumerSurface();
80 
81 private:
82     sptr<IConsumerSurface> cSurface_ = nullptr;
83 };
84 } // namespace OHOS::NWeb
85 
86 #endif // SURFACE_ADAPTER_IMPL_H
87