From 2f849059c20b6b56593f363c1b7edd0277ca4d48 Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Mon, 19 Dec 2016 07:21:12 +0100 Subject: [PATCH] Correct texture and frame size calculation to be correct in offscreen areas --- src/anbox/graphics/emugl/Renderer.cpp | 14 ++++++++------ src/anbox/graphics/layer_composer.cpp | 7 +++---- src/anbox/graphics/rect.cpp | 2 +- src/anbox/ubuntu/platform_policy.cpp | 2 +- src/anbox/ubuntu/window.cpp | 7 ------- src/anbox/wm/window.cpp | 12 +++++++++++- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/anbox/graphics/emugl/Renderer.cpp b/src/anbox/graphics/emugl/Renderer.cpp index 93a7737c..df877309 100644 --- a/src/anbox/graphics/emugl/Renderer.cpp +++ b/src/anbox/graphics/emugl/Renderer.cpp @@ -996,7 +996,7 @@ void Renderer::setupViewport(RendererWindow *window, void Renderer::tessellate(std::vector &primitives, const anbox::graphics::Rect &buf_size, const Renderable &renderable) { - auto rect = renderable.screen_position(); + auto rect = renderable.crop(); GLfloat left = rect.left(); GLfloat right = rect.right(); GLfloat top = rect.top(); @@ -1006,13 +1006,15 @@ void Renderer::tessellate(std::vector &primitives, rectangle.tex_id = 0; rectangle.type = GL_TRIANGLE_STRIP; - GLfloat tex_right = static_cast(rect.width()) / buf_size.width(); - GLfloat tex_bottom = static_cast(rect.height()) / buf_size.height(); + GLfloat tex_left = static_cast(left) / buf_size.width(); + GLfloat tex_top = static_cast(top) / buf_size.height(); + GLfloat tex_right = static_cast(right) / buf_size.width(); + GLfloat tex_bottom = static_cast(bottom) / buf_size.height(); auto &vertices = rectangle.vertices; - vertices[0] = {{left, top, 0.0f}, {0.0f, 0.0f}}; - vertices[1] = {{left, bottom, 0.0f}, {0.0f, tex_bottom}}; - vertices[2] = {{right, top, 0.0f}, {tex_right, 0.0f}}; + vertices[0] = {{left, top, 0.0f}, {tex_left, tex_top}}; + vertices[1] = {{left, bottom, 0.0f}, {tex_left, tex_bottom}}; + vertices[2] = {{right, top, 0.0f}, {tex_right, tex_top}}; vertices[3] = {{right, bottom, 0.0f}, {tex_right, tex_bottom}}; primitives.resize(1); diff --git a/src/anbox/graphics/layer_composer.cpp b/src/anbox/graphics/layer_composer.cpp index 3f594f82..49e8c659 100644 --- a/src/anbox/graphics/layer_composer.cpp +++ b/src/anbox/graphics/layer_composer.cpp @@ -72,9 +72,9 @@ void LayerComposer::submit_layers(const RenderableList &renderables) { auto top = r.screen_position().top() - new_window_frame.top(); auto rect = Rect{ - left - r.crop().left(), top - r.crop().top(), - r.screen_position().width() + left, - r.screen_position().height() + top, + left + r.crop().left(), top + r.crop().top(), + r.crop().right(), + r.crop().bottom(), }; auto new_renderable = r; @@ -82,7 +82,6 @@ void LayerComposer::submit_layers(const RenderableList &renderables) { final_renderables.push_back(new_renderable); } - w.first->update_frame(new_window_frame); Renderer::get()->draw( window->native_handle(), diff --git a/src/anbox/graphics/rect.cpp b/src/anbox/graphics/rect.cpp index 2dd5c613..0caf9cc3 100644 --- a/src/anbox/graphics/rect.cpp +++ b/src/anbox/graphics/rect.cpp @@ -48,7 +48,7 @@ void Rect::resize(const std::int32_t &width, const std::int32_t &height) { std::ostream &operator<<(std::ostream &out, const Rect &rect) { return out << "{" << rect.left() << "," << rect.top() << "," << rect.right() - << "," << rect.bottom() << "}"; + << "," << rect.bottom() << "} {" << rect.width() << "," << rect.height() << "}"; } } // namespace graphics } // namespace anbox diff --git a/src/anbox/ubuntu/platform_policy.cpp b/src/anbox/ubuntu/platform_policy.cpp index 2414eda4..df0fcfa0 100644 --- a/src/anbox/ubuntu/platform_policy.cpp +++ b/src/anbox/ubuntu/platform_policy.cpp @@ -232,7 +232,7 @@ void PlatformPolicy::window_resized(const Window::Id &id, // representing this window and then we're back to the original size of // the task. window->update_frame(new_frame); - android_api_->resize_task(window->task(), new_frame, 1); + android_api_->resize_task(window->task(), new_frame, 3); } } diff --git a/src/anbox/ubuntu/window.cpp b/src/anbox/ubuntu/window.cpp index 9a5a4dea..9f228218 100644 --- a/src/anbox/ubuntu/window.cpp +++ b/src/anbox/ubuntu/window.cpp @@ -65,17 +65,10 @@ Window::Window(const Id &id, const wm::Task::Id &task, ERROR("Unknown subsystem (%d)", info.subsystem); BOOST_THROW_EXCEPTION(std::runtime_error("SDL subsystem not suported")); } - - int actual_width = 0, actual_height = 0; - int actual_x = 0, actual_y = 0; - SDL_GetWindowSize(window_, &actual_width, &actual_height); - SDL_GetWindowPosition(window_, &actual_x, &actual_y); } Window::~Window() { if (window_) SDL_DestroyWindow(window_); - - // if (observer_) observer_->window_deleted(id_); } void Window::process_event(const SDL_Event &event) { diff --git a/src/anbox/wm/window.cpp b/src/anbox/wm/window.cpp index 398ebb2d..70fb60d8 100644 --- a/src/anbox/wm/window.cpp +++ b/src/anbox/wm/window.cpp @@ -26,7 +26,17 @@ Window::Window(const Task::Id &task, const graphics::Rect &frame) Window::~Window() {} -void Window::update_state(const WindowState::List &states) {} +void Window::update_state(const WindowState::List &states) { + graphics::Rect new_frame = graphics::Rect::Invalid; + for (const auto &s : states) { + if (new_frame == graphics::Rect::Invalid) + new_frame = s.frame(); + else + new_frame.merge(s.frame()); + } + + update_frame(new_frame); +} void Window::update_frame(const graphics::Rect &frame) { if (frame == frame_) return; -- GitLab