X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Fgraphics%2Fbuffered_io_stream.h;fp=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Fgraphics%2Fbuffered_io_stream.h;h=467dded274c24c6fb81ad6e750ebf5284174c8a1;hb=e26c1ec581be598521517829adba8c8dd23a768f;hp=0000000000000000000000000000000000000000;hpb=6699c1aea74eeb0eb400e6299079f0c7576f716f;p=iec.git diff --git a/src/type3_AndroidCloud/anbox-master/src/anbox/graphics/buffered_io_stream.h b/src/type3_AndroidCloud/anbox-master/src/anbox/graphics/buffered_io_stream.h new file mode 100644 index 0000000..467dded --- /dev/null +++ b/src/type3_AndroidCloud/anbox-master/src/anbox/graphics/buffered_io_stream.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2016 Simon Fels + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + */ + +#ifndef ANBOX_GRAPHICS_BUFFERED_IO_STREAM_H_ +#define ANBOX_GRAPHICS_BUFFERED_IO_STREAM_H_ + +#include "external/android-emugl/host/include/libOpenglRender/IOStream.h" + +#include "anbox/graphics/buffer_queue.h" +#include "anbox/network/socket_messenger.h" + +#include +#include + +namespace anbox { +namespace graphics { +class BufferedIOStream : public IOStream { + public: + static const size_t default_buffer_size{384}; + + explicit BufferedIOStream( + const std::shared_ptr &messenger, + size_t buffer_size = default_buffer_size); + + virtual ~BufferedIOStream(); + + void *allocBuffer(size_t min_size) override; + size_t commitBuffer(size_t size) override; + const unsigned char *read(void *buf, size_t *inout_len) override; + void forceStop() override; + void post_data(Buffer &&data); + + bool needs_data(); + + private: + void thread_main(); + + std::shared_ptr messenger_; + std::mutex lock_; + std::mutex out_lock_; + Buffer write_buffer_; + Buffer read_buffer_; + size_t read_buffer_left_ = 0; + BufferQueue in_queue_; + BufferQueue out_queue_; + std::thread worker_thread_; +}; +} // namespace graphics +} // namespace anbox + +#endif