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 SurfaceBufferAdapterImpl() = default; 27 28 explicit SurfaceBufferAdapterImpl(sptr<SurfaceBuffer> buffer); 29 30 ~SurfaceBufferAdapterImpl() override = default; 31 32 int32_t GetFileDescriptor() override; 33 34 int32_t GetWidth() override; 35 36 int32_t GetHeight() override; 37 38 int32_t GetStride() override; 39 40 int32_t GetFormat() override; 41 42 uint32_t GetSize() override; 43 44 void* GetVirAddr() override; 45 46 sptr<SurfaceBuffer>& GetBuffer(); 47 48 private: 49 sptr<SurfaceBuffer> buffer_ = nullptr; 50 }; 51 52 class BufferConsumerListenerImpl : public IBufferConsumerListener { 53 public: 54 BufferConsumerListenerImpl( 55 wptr<IConsumerSurface> surface, std::shared_ptr<IBufferConsumerListenerAdapter> listener); 56 57 ~BufferConsumerListenerImpl() override = default; 58 59 void OnBufferAvailable() override; 60 61 private: 62 wptr<IConsumerSurface> cSurface_ = nullptr; 63 64 std::shared_ptr<IBufferConsumerListenerAdapter> listener_ = nullptr; 65 }; 66 67 class ConsumerSurfaceAdapterImpl : public IConsumerSurfaceAdapter { 68 public: 69 ConsumerSurfaceAdapterImpl(); 70 71 ~ConsumerSurfaceAdapterImpl() = default; 72 73 int32_t RegisterConsumerListener(std::shared_ptr<IBufferConsumerListenerAdapter> listenerAdapter) override; 74 75 int32_t ReleaseBuffer(std::shared_ptr<SurfaceBufferAdapter> bufferAdapter, int32_t fence) override; 76 77 int32_t SetUserData(const std::string& key, const std::string& val) override; 78 79 int32_t SetQueueSize(uint32_t queueSize) override; 80 81 sptr<IConsumerSurface>& GetConsumerSurface(); 82 83 private: 84 sptr<IConsumerSurface> cSurface_ = nullptr; 85 }; 86 87 class ProducerSurfaceAdapterImpl : public ProducerSurfaceAdapter { 88 public: 89 explicit ProducerSurfaceAdapterImpl(sptr<Surface> surface); 90 91 ~ProducerSurfaceAdapterImpl() = default; 92 93 std::shared_ptr<SurfaceBufferAdapter> RequestBuffer( 94 int32_t& fence, std::shared_ptr<BufferRequestConfigAdapter> config) override; 95 96 int32_t FlushBuffer(std::shared_ptr<SurfaceBufferAdapter> bufferAdapter, int32_t fence, 97 std::shared_ptr<BufferFlushConfigAdapter> flushConfigAdapter) override; 98 99 private: 100 void TransToBufferConfig( 101 const std::shared_ptr<BufferRequestConfigAdapter> configAdapter, BufferRequestConfig& config); 102 GraphicColorGamut TransToGraphicColorGamut(const ColorGamutAdapter& colorGamut); 103 GraphicTransformType TransToTransformType(const TransformTypeAdapter& type); 104 sptr<Surface> surface_ = nullptr; 105 }; 106 } // namespace OHOS::NWeb 107 108 #endif // SURFACE_ADAPTER_IMPL_H 109