blob: 33c77baa4dd55e4df904d908ea0a39a46da16b2d [file] [log] [blame]
Lingfeng Yangee4aea32020-10-29 08:52:13 -07001// 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 Duongb4b52002023-04-26 09:07:58 -070016#include "render-utils/IOStream.h"
Lingfeng Yangee4aea32020-10-29 08:52:13 -070017#include "RenderChannelImpl.h"
18
19#include <memory>
20
Jason Macnaked0c9e62023-03-30 15:58:24 -070021namespace gfxstream {
Lingfeng Yangee4aea32020-10-29 08:52:13 -070022
23// An IOStream instance that can be used by the host RenderThread to
24// wrap a RenderChannelImpl channel.
25class ChannelStream final : public IOStream {
26public:
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
33protected:
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
44private:
45 RenderChannelImpl* mChannel;
46 RenderChannel::Buffer mWriteBuffer;
47 RenderChannel::Buffer mReadBuffer;
48 size_t mReadBufferLeft = 0;
49};
50
Jason Macnaked0c9e62023-03-30 15:58:24 -070051} // namespace gfxstream