Revert "Integrate RenderThread directly into our message processor"
This reverts commit 3e126fb252.
This commit is contained in:
parent
a6e26f46d6
commit
ca09dd1fa1
7 changed files with 70 additions and 141 deletions
|
|
@ -109,7 +109,9 @@ anbox::cmds::Run::Run(const BusFactory& bus_factory)
|
|||
auto qemu_pipe_connector = std::make_shared<network::PublishedSocketConnector>(
|
||||
utils::string_format("%s/qemu_pipe", config::socket_path()),
|
||||
rt,
|
||||
std::make_shared<qemu::PipeConnectionCreator>(rt));
|
||||
std::make_shared<qemu::PipeConnectionCreator>(rt,
|
||||
renderer->socket_path(),
|
||||
icon_));
|
||||
|
||||
auto android_api_stub = std::make_shared<bridge::AndroidApiStub>();
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
#include "anbox/logger.h"
|
||||
#include "anbox/graphics/gl_renderer_server.h"
|
||||
#include "anbox/graphics/window_creator.h"
|
||||
#include "anbox/graphics/emugl/FrameBuffer.h"
|
||||
|
||||
#include "OpenglRender/render_api.h"
|
||||
|
||||
|
|
@ -51,8 +50,8 @@ GLRendererServer::GLRendererServer(const std::shared_ptr<WindowCreator> &window_
|
|||
}
|
||||
|
||||
GLRendererServer::~GLRendererServer() {
|
||||
if (const auto fb = FrameBuffer::getFB())
|
||||
fb->finalize();
|
||||
// destroyOpenGLSubwindow();
|
||||
stopOpenGLRenderer();
|
||||
}
|
||||
|
||||
void logger_write(const char *format, ...) {
|
||||
|
|
@ -71,7 +70,22 @@ void GLRendererServer::start() {
|
|||
log_funcs.coarse = logger_write;
|
||||
log_funcs.fine = logger_write;
|
||||
|
||||
FrameBuffer::initialize(window_creator_->native_display());
|
||||
auto display_info = window_creator_->display_info();
|
||||
const auto width = display_info.horizontal_resolution;
|
||||
const auto height = display_info.vertical_resolution;
|
||||
|
||||
char server_addr[256] = { 0 };
|
||||
// The width & height we supply here are the dimensions the internal framebuffer
|
||||
// will use. Making this static prevents us for now to resize the window we create
|
||||
// later for the actual display.
|
||||
if (!initOpenGLRenderer(window_creator_->native_display(), server_addr, sizeof(server_addr), log_funcs, logger_write))
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error("Failed to setup OpenGL renderer"));
|
||||
|
||||
socket_path_ = server_addr;
|
||||
}
|
||||
|
||||
std::string GLRendererServer::socket_path() const {
|
||||
return socket_path_;
|
||||
}
|
||||
} // namespace graphics
|
||||
} // namespace anbox
|
||||
|
|
|
|||
|
|
@ -34,7 +34,10 @@ public:
|
|||
|
||||
void start();
|
||||
|
||||
std::string socket_path() const;
|
||||
|
||||
private:
|
||||
std::string socket_path_;
|
||||
std::shared_ptr<WindowCreator> window_creator_;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -20,139 +20,39 @@
|
|||
#include "anbox/network/local_socket_messenger.h"
|
||||
#include "anbox/network/connections.h"
|
||||
#include "anbox/network/delegate_message_processor.h"
|
||||
#include "anbox/graphics/emugl/RenderThread.h"
|
||||
|
||||
#include "external/android-emugl/host/include/libOpenglRender/IOStream.h"
|
||||
|
||||
#include <condition_variable>
|
||||
#include <queue>
|
||||
|
||||
namespace {
|
||||
class DirectIOStream : public IOStream {
|
||||
public:
|
||||
explicit DirectIOStream(const std::shared_ptr<anbox::network::SocketMessenger> &messenger,
|
||||
const size_t &buffer_size = 10000) :
|
||||
IOStream(buffer_size),
|
||||
messenger_(messenger) {
|
||||
}
|
||||
|
||||
virtual ~DirectIOStream() {
|
||||
if (send_buffer_ != nullptr) {
|
||||
free(send_buffer_);
|
||||
send_buffer_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void* allocBuffer(size_t min_size) override {
|
||||
size_t size = (send_buffer_size_ < min_size ? min_size : send_buffer_size_);
|
||||
if (!send_buffer_)
|
||||
send_buffer_ = (unsigned char *) malloc(size);
|
||||
else if (send_buffer_size_ < size) {
|
||||
unsigned char *p = (unsigned char *)realloc(send_buffer_, size);
|
||||
if (p != NULL) {
|
||||
send_buffer_ = p;
|
||||
send_buffer_size_ = size;
|
||||
} else {
|
||||
free(send_buffer_);
|
||||
send_buffer_ = NULL;
|
||||
send_buffer_size_ = 0;
|
||||
}
|
||||
}
|
||||
return send_buffer_;
|
||||
}
|
||||
|
||||
int commitBuffer(size_t size) override {
|
||||
messenger_->send(reinterpret_cast<const char*>(send_buffer_), size);
|
||||
return size;
|
||||
}
|
||||
|
||||
const unsigned char* readFully(void*, size_t) override {
|
||||
ERROR("Not implemented");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const unsigned char* read(void *data, size_t *size) override {
|
||||
if (!wait_for_data() || buffer_.size() == 0) {
|
||||
*size = 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto bytes_to_read = *size;
|
||||
if (bytes_to_read > buffer_.size())
|
||||
bytes_to_read = buffer_.size();
|
||||
|
||||
::memcpy(data, buffer_.data(), bytes_to_read);
|
||||
buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_read);
|
||||
|
||||
*size = bytes_to_read;
|
||||
|
||||
return static_cast<const unsigned char*>(data);
|
||||
}
|
||||
|
||||
int writeFully(const void*, size_t) override {
|
||||
ERROR("Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void forceStop() override {
|
||||
std::unique_lock<std::mutex> l(mutex_);
|
||||
buffer_.clear();
|
||||
}
|
||||
|
||||
void submitData(const std::vector<std::uint8_t> &data) {
|
||||
std::unique_lock<std::mutex> l(mutex_);
|
||||
for (const auto &byte : data)
|
||||
buffer_.push_back(byte);
|
||||
// buffer_.insert(buffer_.end(), data.begin(), data.end());
|
||||
lock_.notify_one();
|
||||
}
|
||||
|
||||
private:
|
||||
bool wait_for_data() {
|
||||
std::unique_lock<std::mutex> l(mutex_);
|
||||
|
||||
if (!l.owns_lock())
|
||||
return false;
|
||||
|
||||
lock_.wait(l, [&]() { return !buffer_.empty(); });
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<anbox::network::SocketMessenger> messenger_;
|
||||
std::mutex mutex_;
|
||||
std::condition_variable lock_;
|
||||
std::vector<std::uint8_t> buffer_;
|
||||
unsigned char *send_buffer_ = nullptr;
|
||||
size_t send_buffer_size_ = 0;
|
||||
};
|
||||
}
|
||||
|
||||
namespace anbox {
|
||||
namespace graphics {
|
||||
emugl::Mutex OpenGlesMessageProcessor::global_lock{};
|
||||
OpenGlesMessageProcessor::OpenGlesMessageProcessor(const std::string &renderer_socket_path,
|
||||
const std::shared_ptr<Runtime> &rt,
|
||||
const std::shared_ptr<network::SocketMessenger> &messenger) :
|
||||
client_messenger_(messenger) {
|
||||
|
||||
OpenGlesMessageProcessor::OpenGlesMessageProcessor(const std::shared_ptr<network::SocketMessenger> &messenger) :
|
||||
messenger_(messenger),
|
||||
stream_(std::make_shared<DirectIOStream>(messenger_)),
|
||||
renderer_(RenderThread::create(stream_.get(), &global_lock)) {
|
||||
|
||||
// We have to read the client flags first before we can continue
|
||||
// processing the actual commands
|
||||
std::array<std::uint8_t, sizeof(unsigned int)> buffer;
|
||||
messenger_->receive_msg(boost::asio::buffer(buffer));
|
||||
|
||||
renderer_->start();
|
||||
connect_and_attach(renderer_socket_path, rt);
|
||||
}
|
||||
|
||||
OpenGlesMessageProcessor::~OpenGlesMessageProcessor() {
|
||||
DEBUG("");
|
||||
renderer_->forceStop();
|
||||
renderer_->wait(nullptr);
|
||||
}
|
||||
|
||||
void OpenGlesMessageProcessor::connect_and_attach(const std::string &socket_path,
|
||||
const std::shared_ptr<Runtime> &rt) {
|
||||
|
||||
auto socket = std::make_shared<boost::asio::local::stream_protocol::socket>(rt->service());
|
||||
socket->connect(boost::asio::local::stream_protocol::endpoint(socket_path));
|
||||
|
||||
messenger_ = std::make_shared<network::LocalSocketMessenger>(socket);
|
||||
renderer_ = std::make_shared<network::SocketConnection>(
|
||||
messenger_, messenger_, 0, nullptr,
|
||||
std::make_shared<network::DelegateMessageProcessor>([&](const std::vector<std::uint8_t> &data) {
|
||||
client_messenger_->send(reinterpret_cast<const char*>(data.data()), data.size());
|
||||
return true;
|
||||
}));
|
||||
renderer_->set_name("opengles-renderer");
|
||||
renderer_->read_next_message();
|
||||
}
|
||||
|
||||
bool OpenGlesMessageProcessor::process_data(const std::vector<std::uint8_t> &data) {
|
||||
auto stream = std::static_pointer_cast<DirectIOStream>(stream_);
|
||||
stream->submitData(data);
|
||||
messenger_->send(reinterpret_cast<const char*>(data.data()), data.size());
|
||||
return true;
|
||||
}
|
||||
} // namespace graphics
|
||||
|
|
|
|||
|
|
@ -27,26 +27,24 @@
|
|||
#include "anbox/network/socket_messenger.h"
|
||||
#include "anbox/network/socket_connection.h"
|
||||
|
||||
#include "external/android-emugl/shared/emugl/common/mutex.h"
|
||||
|
||||
class IOStream;
|
||||
class RenderThread;
|
||||
|
||||
namespace anbox {
|
||||
namespace graphics {
|
||||
class OpenGlesMessageProcessor : public network::MessageProcessor {
|
||||
public:
|
||||
OpenGlesMessageProcessor(const std::shared_ptr<network::SocketMessenger> &messenger);
|
||||
OpenGlesMessageProcessor(const std::string &renderer_socket_path,
|
||||
const std::shared_ptr<Runtime> &rt,
|
||||
const std::shared_ptr<network::SocketMessenger> &messenger);
|
||||
~OpenGlesMessageProcessor();
|
||||
|
||||
bool process_data(const std::vector<std::uint8_t> &data) override;
|
||||
|
||||
private:
|
||||
static emugl::Mutex global_lock;
|
||||
void connect_and_attach(const std::string &socket_path,
|
||||
const std::shared_ptr<Runtime> &rt);
|
||||
|
||||
std::shared_ptr<network::SocketMessenger> client_messenger_;
|
||||
std::shared_ptr<network::SocketMessenger> messenger_;
|
||||
std::shared_ptr<IOStream> stream_;
|
||||
std::shared_ptr<RenderThread> renderer_;
|
||||
std::shared_ptr<network::SocketConnection> renderer_;
|
||||
};
|
||||
} // namespace graphics
|
||||
} // namespace anbox
|
||||
|
|
|
|||
|
|
@ -62,10 +62,14 @@ std::string client_type_to_string(const anbox::qemu::PipeConnectionCreator::clie
|
|||
}
|
||||
namespace anbox {
|
||||
namespace qemu {
|
||||
PipeConnectionCreator::PipeConnectionCreator(const std::shared_ptr<Runtime> &rt) :
|
||||
PipeConnectionCreator::PipeConnectionCreator(const std::shared_ptr<Runtime> &rt,
|
||||
const std::string &renderer_socket_path,
|
||||
const std::string &boot_animation_icon_path) :
|
||||
runtime_(rt),
|
||||
next_connection_id_(0),
|
||||
connections_(std::make_shared<network::Connections<network::SocketConnection>>()) {
|
||||
connections_(std::make_shared<network::Connections<network::SocketConnection>>()),
|
||||
renderer_socket_path_(renderer_socket_path),
|
||||
boot_animation_icon_path_(boot_animation_icon_path) {
|
||||
}
|
||||
|
||||
PipeConnectionCreator::~PipeConnectionCreator() {
|
||||
|
|
@ -133,7 +137,7 @@ PipeConnectionCreator::client_type PipeConnectionCreator::identify_client(
|
|||
|
||||
std::shared_ptr<network::MessageProcessor> PipeConnectionCreator::create_processor(const client_type &type, const std::shared_ptr<network::SocketMessenger> &messenger) {
|
||||
if (type == client_type::opengles)
|
||||
return std::make_shared<graphics::OpenGlesMessageProcessor>(messenger);
|
||||
return std::make_shared<graphics::OpenGlesMessageProcessor>(renderer_socket_path_, runtime_, messenger);
|
||||
else if (type == client_type::qemud_boot_properties)
|
||||
return std::make_shared<qemu::BootPropertiesMessageProcessor>(messenger);
|
||||
else if (type == client_type::qemud_hw_control)
|
||||
|
|
@ -146,6 +150,8 @@ std::shared_ptr<network::MessageProcessor> PipeConnectionCreator::create_process
|
|||
return std::make_shared<qemu::FingerprintMessageProcessor>(messenger);
|
||||
else if (type == client_type::qemud_gsm)
|
||||
return std::make_shared<qemu::GsmMessageProcessor>(messenger);
|
||||
else if (type == client_type::bootanimation)
|
||||
return std::make_shared<qemu::BootAnimationMessageProcessor>(messenger, boot_animation_icon_path_);
|
||||
else if (type == client_type::qemud_adb)
|
||||
return std::make_shared<qemu::AdbMessageProcessor>(runtime_, messenger);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,10 @@ namespace anbox {
|
|||
namespace qemu {
|
||||
class PipeConnectionCreator : public network::ConnectionCreator<boost::asio::local::stream_protocol> {
|
||||
public:
|
||||
PipeConnectionCreator(const std::shared_ptr<Runtime> &rt);
|
||||
PipeConnectionCreator(
|
||||
const std::shared_ptr<Runtime> &rt,
|
||||
const std::string &renderer_socket_path,
|
||||
const std::string &boot_animation_icon_path);
|
||||
~PipeConnectionCreator() noexcept;
|
||||
|
||||
void create_connection_for(
|
||||
|
|
@ -62,6 +65,9 @@ private:
|
|||
std::shared_ptr<Runtime> runtime_;
|
||||
std::atomic<int> next_connection_id_;
|
||||
std::shared_ptr<network::Connections<network::SocketConnection>> const connections_;
|
||||
|
||||
std::string renderer_socket_path_;
|
||||
std::string boot_animation_icon_path_;
|
||||
};
|
||||
} // namespace qemu
|
||||
} // namespace anbox
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue