/* * \brief Connection to capture service * \author Norman Feske * \date 2020-06-26 */ /* * Copyright (C) 2020 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. */ #ifndef _INCLUDE__CAPTURE_SESSION__CONNECTION_H_ #define _INCLUDE__CAPTURE_SESSION__CONNECTION_H_ #include #include #include #include #include namespace Capture { class Connection; } class Capture::Connection : public Genode::Connection, public Session_client { private: size_t _session_quota = 0; public: /** * Constructor */ Connection(Genode::Env &env, Label const &label = Label()) : Genode::Connection(env, label, Ram_quota { 36*1024 }, Args()), Session_client(cap()) { } void buffer(Area size) override { size_t const needed = buffer_bytes(size); size_t const upgrade = needed > _session_quota ? needed - _session_quota : 0; if (upgrade > 0) { this->upgrade_ram(upgrade); _session_quota += upgrade; } Session_client::buffer(size); } struct Screen; }; class Capture::Connection::Screen { public: Area const size; private: Capture::Connection &_connection; bool const _buffer_initialized = ( _connection.buffer(size), true ); Attached_dataspace _ds; Texture const _texture { _ds.local_addr(), nullptr, size }; public: Screen(Capture::Connection &connection, Region_map &rm, Area size) : size(size), _connection(connection), _ds(rm, _connection.dataspace()) { } void with_texture(auto const &fn) const { fn(_texture); } void apply_to_surface(Surface &surface) { Affected_rects const affected = _connection.capture_at(Capture::Point(0, 0)); with_texture([&] (Texture const &texture) { affected.for_each_rect([&] (Capture::Rect const rect) { surface.clip(rect); Blit_painter::paint(surface, texture, Capture::Point(0, 0)); }); }); } }; #endif /* _INCLUDE__CAPTURE_SESSION__CONNECTION_H_ */