Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 1 | // Copyright (C) 2016 The Android Open Source Project |
| 2 | // |
| 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 | #pragma once |
| 15 | |
Joshua Duong | b4b5200 | 2023-04-26 09:07:58 -0700 | [diff] [blame] | 16 | #include "render-utils/IOStream.h" |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 17 | #include "RenderChannelImpl.h" |
| 18 | |
| 19 | #include <memory> |
| 20 | |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 21 | namespace gfxstream { |
Lingfeng Yang | ee4aea3 | 2020-10-29 08:52:13 -0700 | [diff] [blame] | 22 | |
| 23 | // An IOStream instance that can be used by the host RenderThread to |
| 24 | // wrap a RenderChannelImpl channel. |
| 25 | class ChannelStream final : public IOStream { |
| 26 | public: |
| 27 | ChannelStream(RenderChannelImpl* channel, size_t bufSize); |
| 28 | |
| 29 | void forceStop(); |
| 30 | int writeFully(const void* buf, size_t len) override; |
| 31 | const unsigned char *readFully( void *buf, size_t len) override; |
| 32 | |
| 33 | protected: |
| 34 | virtual void* allocBuffer(size_t minSize) override final; |
| 35 | virtual int commitBuffer(size_t size) override final; |
| 36 | virtual const unsigned char* readRaw(void* buf, size_t* inout_len) |
| 37 | override final; |
| 38 | virtual void* getDmaForReading(uint64_t guest_paddr) override final; |
| 39 | virtual void unlockDma(uint64_t guest_paddr) override final; |
| 40 | |
| 41 | void onSave(android::base::Stream* stream) override; |
| 42 | unsigned char* onLoad(android::base::Stream* stream) override; |
| 43 | |
| 44 | private: |
| 45 | RenderChannelImpl* mChannel; |
| 46 | RenderChannel::Buffer mWriteBuffer; |
| 47 | RenderChannel::Buffer mReadBuffer; |
| 48 | size_t mReadBufferLeft = 0; |
| 49 | }; |
| 50 | |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 51 | } // namespace gfxstream |