Respect layer crop when calculating surface dimensions and position

This commit is contained in:
Simon Fels 2016-12-02 16:31:05 +01:00
commit 48bd7f9692
6 changed files with 31 additions and 5 deletions

View file

@ -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);
}

View file

@ -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_;

View file

@ -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_;
};

View file

@ -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,
};

View file

@ -18,6 +18,7 @@
#include "anbox/graphics/rect.h"
#include <algorithm>
#include <string>
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

View file

@ -20,6 +20,8 @@
#include <cstdint>
#include <ostream>
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