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 #ifndef OHOS_HDI_BUFFER_HANDLE_PARCELABLE_H 17 #define OHOS_HDI_BUFFER_HANDLE_PARCELABLE_H 18 19 #include <string> 20 #include <vector> 21 #include <message_parcel.h> 22 #include "buffer_handle.h" 23 24 namespace OHOS { 25 namespace HDI { 26 namespace Display { 27 using namespace OHOS; 28 29 class BufferHandleParcelable : public Parcelable { 30 public: 31 BufferHandleParcelable(); 32 explicit BufferHandleParcelable(BufferHandle &handle); 33 virtual ~BufferHandleParcelable(); 34 35 bool Init(const BufferHandle &handle); 36 bool ExtractFromParcel(Parcel &parcel); 37 bool Marshalling(Parcel &parcel) const override; 38 static sptr<BufferHandleParcelable> Unmarshalling(Parcel &parcel); 39 BufferHandle *GetBufferHandle(); 40 BufferHandle *Move(); 41 std::string Dump() const; 42 43 private: 44 static bool WriteFileDescriptor(const int fd, Parcel &parcel); 45 static int ReadFileDescriptor(Parcel &parcel); 46 static void FreeBufferHandle(BufferHandle *handle); 47 48 private: 49 bool init_; 50 BufferHandle *handle_; 51 }; 52 } // namespace Display 53 } // namespace HDI 54 } // namespace OHOS 55 #endif // OHOS_HDI_BUFFER_HANDLE_PARCELABLE_H 56