• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 INTERFACES_INNERKITS_INCLUDE_PIXEL_MAP_PARCEL_H
17 #define INTERFACES_INNERKITS_INCLUDE_PIXEL_MAP_PARCEL_H
18 
19 #include "message_parcel.h"
20 #include "image_type.h"
21 
22 namespace OHOS::Rosen {
23     class PixelMapStorage;
24     class RSProfiler;
25 };
26 
27 namespace OHOS {
28 namespace Media {
29 class PixelMap;
30 class PixelMapParcel {
31 public:
32     static std::unique_ptr<PixelMap> CreateFromParcel(OHOS::MessageParcel& data);
33     static uint8_t *ReadHeapDataFromParcel(OHOS::MessageParcel& data, int32_t bufferSize);
34     static uint8_t *ReadAshmemDataFromParcel(OHOS::MessageParcel& data, int32_t bufferSize, int32_t*& context);
35     static bool WriteToParcel(PixelMap* pixelMap, OHOS::MessageParcel& data);
36     static bool WriteImageInfo(PixelMap* pixelMap, OHOS::MessageParcel& data);
37 private:
38     static void ReleaseMemory(AllocatorType allocType, void *addr, void *context, uint32_t size);
39 };
40 
41 struct PixelMemInfo;
42 struct PixelMapError;
43 typedef struct PixelMapError PIXEL_MAP_ERR;
44 class PixelMapRecordParcel {
45 public:
46     static constexpr size_t MAX_IMAGEDATA_SIZE = 128 * 1024 * 1024; // 128M
47     static constexpr size_t MIN_IMAGEDATA_SIZE = 32 * 1024;         // 32k
48 
49     struct ParcelInfo {
50         YUVDataInfo yuvDataInfo_;
51         ImageInfo imageInfo_;
52         Size astcrealSize_;
53         AllocatorType allocatorType_;
54 #ifdef IMAGE_COLORSPACE_FLAG
55         std::shared_ptr<OHOS::ColorManager::ColorSpace> grColorSpace_ = nullptr;
56 #else
57         std::shared_ptr<uint8_t> grColorSpace_ = nullptr;
58 #endif
59         uint32_t versionId_ = 1;
60         uint8_t *data_ = nullptr;
61         int32_t rowDataSize_ = 0;
62         int32_t rowStride_ = 0;
63         int32_t pixelBytes_ = 0;
64         uint32_t uniqueId_ = 0;
65         uint32_t pixelsSize_ = 0;
66         void *context_ = nullptr;
67         bool isUnMap_ = false;
68         mutable bool isMemoryDirty_ = false;
69         bool editable_ = false;
70         bool isAstc_ = false;
71         bool displayOnly_ = false;
72     };
73     using ParcelInfo = struct ParcelInfo;
74 
75     static bool MarshallingPixelMapForRecord(Parcel& parcel, PixelMap& pixelmap);
76     static PixelMap *UnmarshallingPixelMapForRecord(Parcel &parcel,
77         std::function<int(Parcel &parcel, std::function<int(Parcel&)> readFdDefaultFunc)> readSafeFdFunc = nullptr);
78 
79     bool Marshalling(Parcel &parcel, PixelMap& pixelmap);
80     static bool IsYUV(const PixelFormat &format);
GetParcelInfo()81     ParcelInfo& GetParcelInfo() {
82         return parcelInfo_;
83     }
84 
85 private:
86     friend class OHOS::Rosen::PixelMapStorage;
87     friend class OHOS::Rosen::RSProfiler;
88     bool WriteMemInfoToParcel(Parcel &parcel, const int32_t &bufferSize);
89     bool WritePropertiesToParcel(Parcel &parcel);
90     bool WriteImageInfo(Parcel &parcel);
91     bool WriteAstcRealSizeToParcel(Parcel &parcel);
92     bool WriteImageData(Parcel &parcel, size_t size);
93     bool WriteAshmemDataToParcel(Parcel &parcel, size_t size);
94     bool WriteFileDescriptor(Parcel &parcel, int fd);
95     bool WriteTransformDataToParcel(Parcel &parcel) const;
96     bool WriteYuvDataInfoToParcel(Parcel &parcel) const;
97     static bool IsYuvFormat(PixelFormat format);
98     static PixelMap *Unmarshalling(Parcel &parcel, PIXEL_MAP_ERR &error,
99         std::function<int(Parcel &parcel, std::function<int(Parcel&)> readFdDefaultFunc)> readSafeFdFunc);
100     static bool ReadPropertiesFromParcel(Parcel& parcel, PixelMap*& pixelMap,
101         ImageInfo& imgInfo, PixelMemInfo& memInfo);
102     static PixelMap *StartUnmarshalling(Parcel &parcel, ImageInfo &imgInfo,
103         PixelMemInfo& pixelMemInfo, PIXEL_MAP_ERR &error);
104     static PixelMap *FinishUnmarshalling(PixelMap *pixelMap, Parcel &parcel,
105         ImageInfo &imgInfo, PixelMemInfo &pixelMemInfo, PIXEL_MAP_ERR &error);
106     static bool UpdatePixelMapMemInfo(PixelMap *pixelMap, ImageInfo &imgInfo, PixelMemInfo &pixelMemInfo);
107     static void ReleaseMemory(AllocatorType allocType, void *addr, void *context, uint32_t size);
108     static bool ReadMemInfoFromParcel(Parcel &parcel, PixelMemInfo &pixelMemInfo, PIXEL_MAP_ERR &error,
109         std::function<int(Parcel &parcel, std::function<int(Parcel&)> readFdDefaultFunc)> readSafeFdFunc);
110     static bool ReadDmaMemInfoFromParcel(Parcel &parcel, PixelMemInfo &pixelMemInfo,
111         std::function<int(Parcel &parcel, std::function<int(Parcel&)> readFdDefaultFunc)> readSafeFdFunc);
112     static uint8_t *ReadImageData(Parcel &parcel, int32_t bufferSize,
113         std::function<int(Parcel &parcel, std::function<int(Parcel&)> readFdDefaultFunc)> readSafeFdFunc);
114     static uint8_t *ReadHeapDataFromParcel(Parcel &parcel, int32_t bufferSize);
115     static uint8_t *ReadAshmemDataFromParcel(Parcel &parcel, int32_t bufferSize,
116         std::function<int(Parcel &parcel, std::function<int(Parcel&)> readFdDefaultFunc)> readSafeFdFunc);
117     static int ReadFileDescriptor(Parcel &parcel);
118     static bool ReadTransformData(Parcel &parcel, PixelMap *pixelMap);
119     static bool ReadYuvDataInfoFromParcel(Parcel &parcel, PixelMap *pixelMap);
120 
121     ParcelInfo parcelInfo_;
122 };
123 }  // namespace Media
124 }  // namespace OHOS
125 
126 #endif // INTERFACES_INNERKITS_INCLUDE_PIXEL_MAP_PARCEL_H
127