From 48bd7f969295de1c0186d43df5e3facfd9fb3d5b Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Fri, 2 Dec 2016 16:31:05 +0100 Subject: [PATCH] Respect layer crop when calculating surface dimensions and position --- src/anbox/graphics/emugl/RenderControl.cpp | 7 ++++++- src/anbox/graphics/emugl/Renderable.cpp | 7 +++++++ src/anbox/graphics/emugl/Renderable.h | 3 +++ src/anbox/graphics/layer_composer.cpp | 9 +++++---- src/anbox/graphics/rect.cpp | 6 ++++++ src/anbox/graphics/rect.h | 4 ++++ 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/anbox/graphics/emugl/RenderControl.cpp b/src/anbox/graphics/emugl/RenderControl.cpp index ef32831..5ea6d96 100644 --- a/src/anbox/graphics/emugl/RenderControl.cpp +++ b/src/anbox/graphics/emugl/RenderControl.cpp @@ -444,7 +444,12 @@ void rcPostLayer(const char *name, uint32_t color_buffer, int32_t displayFrameLeft, int32_t displayFrameTop, int32_t displayFrameRight, int32_t displayFrameBottom) { - Renderable r{name, color_buffer, {displayFrameLeft, displayFrameTop, displayFrameRight, displayFrameBottom}}; + Renderable r{ + name, + color_buffer, + {displayFrameLeft, displayFrameTop, displayFrameRight, displayFrameBottom}, + {sourceCropLeft, sourceCropTop, sourceCropRight, sourceCropBottom} + }; frame_layers.push_back(r); } diff --git a/src/anbox/graphics/emugl/Renderable.cpp b/src/anbox/graphics/emugl/Renderable.cpp index 232f3a1..6d8a997 100644 --- a/src/anbox/graphics/emugl/Renderable.cpp +++ b/src/anbox/graphics/emugl/Renderable.cpp @@ -19,11 +19,13 @@ Renderable::Renderable(const std::string &name, const std::uint32_t &buffer, const anbox::graphics::Rect &screen_position, + const anbox::graphics::Rect &crop, const glm::mat4 &transformation, const float &alpha) : name_(name), buffer_(buffer), screen_position_(screen_position), + crop_(crop), transformation_(transformation), alpha_(alpha) { @@ -48,6 +50,11 @@ anbox::graphics::Rect Renderable::screen_position() const return screen_position_; } +anbox::graphics::Rect Renderable::crop() const +{ + return crop_; +} + glm::mat4 Renderable::transformation() const { return transformation_; diff --git a/src/anbox/graphics/emugl/Renderable.h b/src/anbox/graphics/emugl/Renderable.h index 819f1b7..0cd5205 100644 --- a/src/anbox/graphics/emugl/Renderable.h +++ b/src/anbox/graphics/emugl/Renderable.h @@ -32,6 +32,7 @@ public: Renderable(const std::string &name, const std::uint32_t &buffer, const anbox::graphics::Rect &screen_position, + const anbox::graphics::Rect &crop = {}, const glm::mat4 &transformation = {}, const float &alpha = 1.0f); ~Renderable(); @@ -39,6 +40,7 @@ public: std::string name() const; std::uint32_t buffer() const; anbox::graphics::Rect screen_position() const; + anbox::graphics::Rect crop() const; glm::mat4 transformation() const; float alpha() const; @@ -48,6 +50,7 @@ private: std::string name_; std::uint32_t buffer_; anbox::graphics::Rect screen_position_; + anbox::graphics::Rect crop_; glm::mat4 transformation_; float alpha_; }; diff --git a/src/anbox/graphics/layer_composer.cpp b/src/anbox/graphics/layer_composer.cpp index 9d31c3f..b595afc 100644 --- a/src/anbox/graphics/layer_composer.cpp +++ b/src/anbox/graphics/layer_composer.cpp @@ -63,9 +63,6 @@ void LayerComposer::submit_layers(const RenderableList &renderables) RenderableList final_renderables; auto new_window_frame = Rect::Invalid; - // As we get absolute display coordinates from the Android hwcomposer we - // need to recalculate all layer coordinates into relatives ones to the - // window they are drawn into. for (auto &r : renderables) { if (new_window_frame == Rect::Invalid) @@ -76,11 +73,15 @@ void LayerComposer::submit_layers(const RenderableList &renderables) for (auto &r : renderables) { + // As we get absolute display coordinates from the Android hwcomposer we + // need to recalculate all layer coordinates into relatives ones to the + // window they are drawn into. auto left = r.screen_position().left() - new_window_frame.left(); auto top = r.screen_position().top() - new_window_frame.top(); auto rect = Rect{ - left, top, + left - r.crop().left(), + top - r.crop().top(), r.screen_position().width() + left, r.screen_position().height() + top, }; diff --git a/src/anbox/graphics/rect.cpp b/src/anbox/graphics/rect.cpp index e8cbb13..707dfeb 100644 --- a/src/anbox/graphics/rect.cpp +++ b/src/anbox/graphics/rect.cpp @@ -18,6 +18,7 @@ #include "anbox/graphics/rect.h" #include +#include namespace anbox { namespace graphics { @@ -31,5 +32,10 @@ void Rect::merge(const Rect &rhs) right_ = std::max(right_, rhs.right()); bottom_ = std::max(bottom_, rhs.bottom()); } + +std::ostream& operator<<(std::ostream &out, const Rect &rect) +{ + return out << "{" << rect.left() << "," << rect.top() << ","<< rect.right() << "," << rect.bottom() << "}"; +} } // namespace graphics } // namespace anbox diff --git a/src/anbox/graphics/rect.h b/src/anbox/graphics/rect.h index 15949c2..0ef812b 100644 --- a/src/anbox/graphics/rect.h +++ b/src/anbox/graphics/rect.h @@ -20,6 +20,8 @@ #include +#include + namespace anbox { namespace graphics { class Rect { @@ -97,6 +99,8 @@ private: std::int32_t right_; std::int32_t bottom_; }; + +std::ostream& operator<<(std::ostream &out, const Rect &rect); } // namespace graphics } // namespace anbox