1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 #include "aemu/base/files/Stream.h" 18 #include "render-utils/IOStream.h" 19 20 namespace gfxstream { 21 22 class ReadBuffer { 23 public: 24 explicit ReadBuffer(size_t bufSize); 25 ~ReadBuffer(); 26 27 void setNeededFreeTailSize(size_t size); 28 int getData(IOStream *stream, size_t minSize); // get fresh data from the stream buf()29 unsigned char *buf() { return m_readPtr; } // return the next read location validData()30 size_t validData() const { return m_validData; } // return the amount of valid data in readptr 31 void consume(size_t amount); // notify that 'amount' data has been consumed; 32 33 void onLoad(android::base::Stream* stream); 34 void onSave(android::base::Stream* stream); 35 36 void printStats(); 37 private: 38 unsigned char *m_buf; 39 unsigned char *m_readPtr; 40 size_t m_size; 41 size_t m_validData; 42 43 uint64_t m_tailMoveTimeUs = 0; 44 size_t m_neededFreeTailSize = 0; 45 }; 46 47 } // namespace gfxstream 48