2 * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef ANBOX_GRAPHICS_BUFFERED_IO_STREAM_H_
19 #define ANBOX_GRAPHICS_BUFFERED_IO_STREAM_H_
21 #include "external/android-emugl/host/include/libOpenglRender/IOStream.h"
23 #include "anbox/graphics/buffer_queue.h"
24 #include "anbox/network/socket_messenger.h"
31 class BufferedIOStream : public IOStream {
33 static const size_t default_buffer_size{384};
35 explicit BufferedIOStream(
36 const std::shared_ptr<anbox::network::SocketMessenger> &messenger,
37 size_t buffer_size = default_buffer_size);
39 virtual ~BufferedIOStream();
41 void *allocBuffer(size_t min_size) override;
42 size_t commitBuffer(size_t size) override;
43 const unsigned char *read(void *buf, size_t *inout_len) override;
44 void forceStop() override;
45 void post_data(Buffer &&data);
52 std::shared_ptr<anbox::network::SocketMessenger> messenger_;
57 size_t read_buffer_left_ = 0;
58 BufferQueue in_queue_;
59 BufferQueue out_queue_;
60 std::thread worker_thread_;
62 } // namespace graphics