1 /* 2 * Copyright (c) 2022-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 OHOS_DATA_BUFFER_H 17 #define OHOS_DATA_BUFFER_H 18 19 #include <cstdint> 20 #include <cstddef> 21 #include <vector> 22 23 #include "dscreen_constants.h" 24 25 namespace OHOS { 26 namespace DistributedHardware { 27 struct DirtyRect { 28 int32_t xPos; 29 int32_t yPos; 30 int32_t width; 31 int32_t height; 32 int32_t dirtySize; 33 }; 34 class DataBuffer { 35 public: 36 explicit DataBuffer(size_t capacity); 37 ~DataBuffer(); 38 39 size_t Capacity() const; 40 uint8_t *Data() const; 41 void SetSize(size_t size); 42 void SetDataType(uint8_t dataType); 43 uint8_t DataType(); 44 void SetDataNumber(size_t number); 45 size_t DataNumber(); 46 void ResetCapcity(size_t capacity); 47 void AddData(size_t dataSize, unsigned char* &inputData); 48 void AddDirtyRect(DirtyRect rec); 49 std::vector<DirtyRect> GetDirtyRectVec(); 50 int32_t GetData(int32_t offset, int32_t datasize, uint8_t* &output); 51 private: 52 static const constexpr char *DSCREEN_LOG_TAG = "DataBuffer"; 53 std::vector<DirtyRect> dirtyRectVec_; 54 size_t capacity_ = 0; 55 uint8_t *data_ = nullptr; 56 uint8_t dataType_ = 0; 57 size_t frameNumber_ = 0; 58 }; 59 } // namespace DistributedHardware 60 } // namespace OHOS 61 #endif