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 #ifndef HARDWARE_BUFFER_H 16 #define HARDWARE_BUFFER_H 17 #include "surface_buffer.h" 18 namespace OHOS { 19 class HardwareBuffer : public OHOS::SurfaceBuffer { 20 public: 21 static OHOS::sptr<OHOS::SurfaceBuffer> Create(const BufferHandle &handle); 22 BufferHandle *GetBufferHandle() const override; 23 explicit HardwareBuffer(const BufferHandle &handle); 24 virtual ~HardwareBuffer(); 25 26 virtual int32_t GetWidth() const override; 27 virtual int32_t GetHeight() const override; 28 virtual int32_t GetStride() const override; 29 virtual int32_t GetSurfaceBufferWidth() const override; 30 virtual int32_t GetSurfaceBufferHeight() const override; 31 virtual SurfaceColorGamut GetSurfaceBufferColorGamut() const override; 32 virtual GSError SetSurfaceBufferWidth(int32_t width) override; 33 virtual GSError SetSurfaceBufferHeight(int32_t height) override; 34 virtual GSError SetSurfaceBufferColorGamut(SurfaceColorGamut colorGamut) override; 35 virtual int32_t GetFormat() const override; 36 virtual int64_t GetUsage() const override; 37 virtual uint64_t GetPhyAddr() const override; 38 virtual int32_t GetKey() const override; 39 virtual void *GetVirAddr() const override; 40 virtual int GetFileDescriptor() const override; 41 virtual uint32_t GetSize() const override; 42 virtual GSError SetInt32(uint32_t key, int32_t value) override; 43 virtual GSError GetInt32(uint32_t key, int32_t &value) override; 44 virtual GSError SetInt64(uint32_t key, int64_t value) override; 45 virtual GSError GetInt64(uint32_t key, int64_t &value) override; 46 virtual sptr<EglData> GetEglData() const override; 47 48 // support ipc data 49 virtual GSError ExtraGet(std::string key, int32_t &value) const override; 50 virtual GSError ExtraGet(std::string key, int64_t &value) const override; 51 virtual GSError ExtraGet(std::string key, double &value) const override; 52 virtual GSError ExtraGet(std::string key, std::string &value) const override; 53 virtual GSError ExtraSet(std::string key, int32_t value) override; 54 virtual GSError ExtraSet(std::string key, int64_t value) override; 55 virtual GSError ExtraSet(std::string key, double value) override; 56 virtual GSError ExtraSet(std::string key, std::string value) override; 57 void SetAcquireFence(int32_t fd); 58 int32_t GetAcquireFence() const; 59 void SetReleaseFence(int32_t fd); 60 int32_t GetReleaseFence() const; 61 62 private: 63 BufferHandle *handle_ = nullptr; 64 int32_t acquireFence_ = -1; 65 int32_t relesaeFence_ = -1; 66 }; 67 } 68 #endif // HARDWARE_BUFFER_H