/* * \brief Generic interface of graphics backend and chunky template * \date 2005-10-24 * \author Norman Feske */ /* * Copyright (C) 2005-2017 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__SCOUT__CANVAS_H_ #define _INCLUDE__SCOUT__CANVAS_H_ #include #include #include #include #include #include #include #include #include #include #include #include namespace Scout { using Genode::Color; using Genode::Pixel_rgba; typedef Text_painter::Font Font; struct Canvas_base; template class Canvas; } struct Scout::Canvas_base : Texture_allocator { virtual ~Canvas_base() { } virtual Area size() const = 0; virtual Rect clip() const = 0; virtual void clip(Rect rect) = 0; virtual void draw_box(int x, int y, int w, int h, Color c) = 0; virtual void draw_string(int x, int y, Font *font, Color color, char const *str, size_t len) = 0; virtual void draw_horizontal_shadow(Rect rect, int intensity) = 0; virtual void draw_icon(Rect, Texture_base const &, unsigned alpha) = 0; virtual void draw_sky_texture(int py, Sky_texture_painter::Sky_texture_base const &, bool detail) = 0; virtual void draw_refracted_icon(Point pos, Scout::Refracted_icon_painter::Distmap const &distmap, Texture_base &tmp, Texture_base const &foreground, bool detail, bool filter_backbuf) = 0; virtual void draw_texture(Point pos, Texture_base const &texture) = 0; }; #include #include template class Scout::Canvas : public Canvas_base { private: Genode::Allocator &_alloc; Genode::Surface _surface; public: /** * Constructor * * \param alloc allocator to be used for allocating textures */ Canvas(PT *base, Area size, Genode::Allocator &alloc) : _alloc(alloc), _surface(base, size) { } Area size() const override { return _surface.size(); } Rect clip() const override { return _surface.clip(); } void clip(Rect rect) override { _surface.clip(rect); } void draw_string(int x, int y, Font *font, Color color, char const *str, size_t len) override { char buf[len + 1]; Genode::copy_cstring(buf, str, len + 1); Text_painter::paint(_surface, Text_painter::Position(x, y), *font, color, buf); } void draw_box(int x, int y, int w, int h, Color c) override { Box_painter::paint(_surface, Rect(Point(x, y), Area(w, h)), c); } void draw_horizontal_shadow(Rect rect, int intensity) override { Horizontal_shadow_painter::paint(_surface, rect, intensity); } void draw_icon(Rect rect, Texture_base const &icon, unsigned alpha) override { Icon_painter::paint(_surface, rect, static_cast const &>(icon), alpha); } void draw_sky_texture(int py, Sky_texture_painter::Sky_texture_base const &texture, bool detail) override { Sky_texture_painter::paint(_surface, py, texture, detail); } void draw_refracted_icon(Point pos, Scout::Refracted_icon_painter::Distmap const &distmap, Texture_base &tmp, Texture_base const &foreground, bool detail, bool filter_backbuf) override { using namespace Scout; Refracted_icon_painter::paint(_surface, pos, distmap, static_cast &>(tmp), static_cast const &>(foreground), detail, filter_backbuf); } void draw_texture(Point pos, Texture_base const &texture_base) override { Texture const &texture = static_cast const &>(texture_base); Texture_painter::paint(_surface, texture, Color::black(), pos, Texture_painter::SOLID, true); } Texture_base *alloc_texture(Area size, bool has_alpha) override { using namespace Genode; PT *pixel = (PT *)_alloc.alloc(size.count()*sizeof(PT)); unsigned char *alpha = 0; if (has_alpha) alpha = (unsigned char *)_alloc.alloc(size.count()); return new (_alloc) Genode::Texture(pixel, alpha, size); } void free_texture(Texture_base *texture_base) override { using namespace Genode; Texture *texture = static_cast *>(texture_base); Genode::size_t const num_pixels = texture->size().count(); if (texture->alpha()) _alloc.free(texture->alpha(), num_pixels); _alloc.free(texture->pixel(), sizeof(PT)*num_pixels); destroy(_alloc, texture); } void set_rgba_texture(Texture_base *texture_base, unsigned char const *rgba, size_t len, int y) override { Texture *texture = static_cast *>(texture_base); texture->rgba(rgba, len, y); } }; #endif /* _INCLUDE__SCOUT__CANVAS_H_ */