Skip to content

Commit

Permalink
Capture::Connection::Screen: use Blit::back2front
Browse files Browse the repository at this point in the history
  • Loading branch information
nfeske authored and cnuke committed Jan 23, 2025
1 parent d58a4cb commit 2305b50
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 32 deletions.
6 changes: 4 additions & 2 deletions repos/libports/src/driver/framebuffer/vesa/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ void Vesa_driver::Main::_handle_config()

using Attr = Capture::Connection::Screen::Attr;
_captured_screen.construct(_capture, _env.rm(), Attr {
.px = _size,
.mm = { } });
.px = _size,
.mm = { },
.rotate = { },
.flip = { } });

unsigned long const period_ms = config.attribute_value("period_ms", 20U);
_timer.trigger_periodic(period_ms*1000);
Expand Down
2 changes: 1 addition & 1 deletion repos/libports/src/lib/qemu-usb/webcam.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct Capture_webcam
/* construct/destruct capture connection and dataspace */
if (on) {
_capture.construct(_env, "webcam");
_capture->buffer({ .px = _area, .mm = { } });
_capture->buffer({ .px = _area, .mm = { }, .rotate = { }, .flip = { } });
_ds.construct(_env.rm(), _capture->dataspace());
} else {
_ds.destruct();
Expand Down
52 changes: 37 additions & 15 deletions repos/os/include/capture_session/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ class Capture::Connection : private Genode::Connection<Session>

public:

using Label = Genode::Session_label;
using Label = Genode::Session_label;
using Rotate = Blit::Rotate;
using Flip = Blit::Flip;

static Rotate rotate_from_xml(Xml_node const &node)
{
unsigned const v = node.attribute_value("rotate", 0u);
return (v == 90) ? Rotate::R90 :
(v == 180) ? Rotate::R180 :
(v == 270) ? Rotate::R270 :
Rotate::R0;
}

/**
* Constructor
Expand Down Expand Up @@ -98,8 +109,13 @@ class Capture::Connection::Screen

struct Attr
{
Area px; /* buffer area in pixels */
Area mm; /* physical size in millimeters */
Area px; /* buffer area in pixels */
Area mm; /* physical size in millimeters */
Rotate rotate;
Flip flip;

Area padded_px() const { return { .w = align_addr(px.w, 4),
.h = align_addr(px.h, 4) }; }
};

Attr const attr;
Expand All @@ -113,7 +129,8 @@ class Capture::Connection::Screen

Attached_dataspace _ds;

Texture<Pixel> const _texture { _ds.local_addr<Pixel>(), nullptr, attr.px };
Texture<Pixel> const _texture { _ds.local_addr<Pixel>(), nullptr,
attr.padded_px() };

public:

Expand All @@ -126,26 +143,31 @@ class Capture::Connection::Screen

Rect apply_to_surface(Surface<Pixel> &surface)
{
Rect bounding_box { };
/* record information about pixels affected by 'back2front' */
struct Flusher : Surface_base::Flusher
{
Rect bounding_box { };
void flush_pixels(Rect rect) override
{
bounding_box = bounding_box.area.count()
? Rect::compound(bounding_box, rect)
: rect;
};
} flusher { };

surface.flusher(&flusher);

using Affected_rects = Session::Affected_rects;

Affected_rects const affected = _connection.capture_at(Capture::Point(0, 0));

with_texture([&] (Texture<Pixel> const &texture) {

affected.for_each_rect([&] (Capture::Rect const rect) {

surface.clip(rect);

Blit_painter::paint(surface, texture, Capture::Point(0, 0));

bounding_box = bounding_box.area.count()
? Rect::compound(bounding_box, rect)
: rect;
Blit::back2front(surface, texture, rect, attr.rotate, attr.flip);
});
});
return bounding_box;
surface.flusher(nullptr);
return flusher.bounding_box;
}
};

Expand Down
6 changes: 4 additions & 2 deletions repos/os/src/driver/framebuffer/boot/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ struct Framebuffer::Main
Capture::Connection _capture { _env };

Capture::Connection::Screen _captured_screen { _capture, _env.rm(), {
.px = _info.size,
.mm = { } } };
.px = _info.size,
.mm = { },
.rotate = { },
.flip = { } } };
Timer::Connection _timer { _env };

Signal_handler<Main> _timer_handler { _env.ep(), *this, &Main::_handle_timer };
Expand Down
6 changes: 4 additions & 2 deletions repos/os/src/driver/framebuffer/pl11x/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ struct Pl11x_driver::Main
Capture::Connection _capture { _env };

Capture::Connection::Screen _captured_screen { _capture, _env.rm(), {
.px = _size,
.mm = { } } };
.px = _size,
.mm = { },
.rotate = { },
.flip = { } } };


/*
Expand Down
6 changes: 4 additions & 2 deletions repos/os/src/driver/framebuffer/ram/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ class Main
Capture::Area const _size { SCR_WIDTH, SCR_HEIGHT };
Capture::Connection _capture { _env };
Capture::Connection::Screen _captured_screen { _capture, _env.rm(), {
.px = _size,
.mm = { } } };
.px = _size,
.mm = { },
.rotate = { },
.flip = { } } };
Timer::Connection _timer { _env };

Signal_handler<Main> _timer_handler { _env.ep(), *this, &Main::_handle_timer };
Expand Down
6 changes: 4 additions & 2 deletions repos/os/src/driver/framebuffer/sdl/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,10 @@ struct Fb_sdl::Sdl : Noncopyable

using Attr = Capture::Connection::Screen::Attr;
_captured_screen.construct(_capture, _rm, Attr {
.px = size,
.mm = { } });
.px = size,
.mm = { },
.rotate = { },
.flip = { }});

_update_screen_from_capture();
_schedule_next_frame();
Expand Down
7 changes: 5 additions & 2 deletions repos/os/src/driver/framebuffer/virtio/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace Virtio_fb {
using namespace Genode;
class Driver;
using uint64_t = Genode::uint64_t;
}

/*
Expand Down Expand Up @@ -357,8 +358,10 @@ class Virtio_fb::Driver

using Attr = Capture::Connection::Screen::Attr;
_captured_screen.construct(_capture, _env.rm(), Attr {
.px = _display_area,
.mm = { } });
.px = _display_area,
.mm = { },
.rotate = { },
.flip = { } });
}

void _shutdown_display()
Expand Down
6 changes: 4 additions & 2 deletions repos/os/src/test/black_hole/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,10 @@ class Black_hole_test::Capture_test
Capture::Pixel _pixels[1];
Surface<Capture::Pixel> _surface { _pixels, _screen_size };
Capture::Connection::Screen _screen { _connection, _env.rm(),
{ .px = _screen_size,
.mm = { } } };
{ .px = _screen_size,
.mm = { },
.rotate = { },
.flip = { } } };
bool _finished { false };

public:
Expand Down
6 changes: 4 additions & 2 deletions repos/pc/src/driver/framebuffer/intel/pc/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ struct Framebuffer::Driver
if (!conn.size.valid())
return same;

Capture::Connection::Screen::Attr attr = { .px = conn.size,
.mm = conn.size_mm };
Capture::Connection::Screen::Attr attr = { .px = conn.size,
.mm = conn.size_mm,
.rotate = { },
.flip = { } };

conn.capture.construct(env, label);
conn.screen .construct(*conn.capture, env.rm(), attr);
Expand Down

0 comments on commit 2305b50

Please sign in to comment.