2013-12-30 00:21:53 +00:00
|
|
|
/*
|
|
|
|
* \brief Generic interface of graphics backend and chunky template
|
|
|
|
* \date 2005-10-24
|
|
|
|
* \author Norman Feske <norman.feske@genode-labs.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2005-2017 Genode Labs GmbH
|
2013-12-30 00:21:53 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2013-12-30 00:21:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__SCOUT__CANVAS_H_
|
|
|
|
#define _INCLUDE__SCOUT__CANVAS_H_
|
|
|
|
|
2019-01-21 13:27:12 +00:00
|
|
|
#include <base/allocator.h>
|
2013-12-30 00:21:53 +00:00
|
|
|
#include <scout/texture_allocator.h>
|
|
|
|
#include <os/pixel_rgba.h>
|
|
|
|
#include <util/color.h>
|
|
|
|
#include <util/dither_matrix.h>
|
|
|
|
|
|
|
|
#include <nitpicker_gfx/texture_painter.h>
|
|
|
|
#include <nitpicker_gfx/text_painter.h>
|
|
|
|
#include <nitpicker_gfx/box_painter.h>
|
|
|
|
#include <scout_gfx/icon_painter.h>
|
|
|
|
#include <scout_gfx/sky_texture_painter.h>
|
|
|
|
#include <scout_gfx/horizontal_shadow_painter.h>
|
|
|
|
#include <scout_gfx/refracted_icon_painter.h>
|
|
|
|
|
|
|
|
namespace Scout {
|
|
|
|
using Genode::Color;
|
|
|
|
using Genode::Pixel_rgba;
|
|
|
|
|
|
|
|
typedef Text_painter::Font Font;
|
|
|
|
|
|
|
|
struct Canvas_base;
|
|
|
|
template <typename PT> 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, int 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<short> 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-11 14:28:20 +00:00
|
|
|
#include <os/texture_rgb565.h>
|
2013-12-30 00:21:53 +00:00
|
|
|
#include <base/env.h>
|
|
|
|
|
|
|
|
|
|
|
|
template <typename PT>
|
|
|
|
class Scout::Canvas : public Canvas_base
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2017-01-11 15:06:26 +00:00
|
|
|
Genode::Allocator &_alloc;
|
2013-12-30 00:21:53 +00:00
|
|
|
Genode::Surface<PT> _surface;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-01-11 15:06:26 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \param alloc allocator to be used for allocating textures
|
|
|
|
*/
|
|
|
|
Canvas(PT *base, Area size, Genode::Allocator &alloc)
|
|
|
|
: _alloc(alloc), _surface(base, size) { }
|
2013-12-30 00:21:53 +00:00
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
Area size() const override { return _surface.size(); }
|
2013-12-30 00:21:53 +00:00
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
Rect clip() const override { return _surface.clip(); }
|
2013-12-30 00:21:53 +00:00
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void clip(Rect rect) override { _surface.clip(rect); }
|
2013-12-30 00:21:53 +00:00
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void draw_string(int x, int y, Font *font, Color color, char const *str, int len) override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
char buf[len + 1];
|
|
|
|
Genode::strncpy(buf, str, len + 1);
|
2018-03-08 17:27:42 +00:00
|
|
|
Text_painter::paint(_surface, Text_painter::Position(x, y), *font, color, buf);
|
2013-12-30 00:21:53 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void draw_box(int x, int y, int w, int h, Color c) override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
Box_painter::paint(_surface, Rect(Point(x, y), Area(w, h)), c);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void draw_horizontal_shadow(Rect rect, int intensity) override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
Horizontal_shadow_painter::paint(_surface, rect, intensity);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void draw_icon(Rect rect, Texture_base const &icon, unsigned alpha) override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
Icon_painter::paint(_surface, rect,
|
|
|
|
static_cast<Texture<PT> const &>(icon), alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_sky_texture(int py,
|
|
|
|
Sky_texture_painter::Sky_texture_base const &texture,
|
2019-02-14 21:39:08 +00:00
|
|
|
bool detail) override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
Sky_texture_painter::paint(_surface, py, texture, detail);
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_refracted_icon(Point pos,
|
|
|
|
Scout::Refracted_icon_painter::Distmap<short> const &distmap,
|
|
|
|
Texture_base &tmp, Texture_base const &foreground,
|
2019-02-14 21:39:08 +00:00
|
|
|
bool detail, bool filter_backbuf) override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
using namespace Scout;
|
|
|
|
Refracted_icon_painter::paint(_surface, pos, distmap,
|
|
|
|
static_cast<Texture<PT> &>(tmp),
|
|
|
|
static_cast<Texture<PT> const &>(foreground),
|
|
|
|
detail, filter_backbuf);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void draw_texture(Point pos, Texture_base const &texture_base) override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
Texture<PT> const &texture = static_cast<Texture<PT> const &>(texture_base);
|
|
|
|
|
|
|
|
Texture_painter::paint(_surface, texture, Color(0, 0, 0), pos,
|
|
|
|
Texture_painter::SOLID, true);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
Texture_base *alloc_texture(Area size, bool has_alpha) override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
|
2017-01-11 15:06:26 +00:00
|
|
|
PT *pixel = (PT *)_alloc.alloc(size.count()*sizeof(PT));
|
2013-12-30 00:21:53 +00:00
|
|
|
|
|
|
|
unsigned char *alpha = 0;
|
|
|
|
|
|
|
|
if (has_alpha)
|
2017-01-11 15:06:26 +00:00
|
|
|
alpha = (unsigned char *)_alloc.alloc(size.count());
|
2013-12-30 00:21:53 +00:00
|
|
|
|
2017-01-11 15:06:26 +00:00
|
|
|
return new (_alloc) Genode::Texture<PT>(pixel, alpha, size);
|
2013-12-30 00:21:53 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void free_texture(Texture_base *texture_base) override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
Texture<PT> *texture = static_cast<Texture<PT> *>(texture_base);
|
|
|
|
|
2016-09-15 12:40:37 +00:00
|
|
|
Genode::size_t const num_pixels = texture->size().count();
|
2013-12-30 00:21:53 +00:00
|
|
|
|
|
|
|
if (texture->alpha())
|
2017-01-11 15:06:26 +00:00
|
|
|
_alloc.free(texture->alpha(), num_pixels);
|
2013-12-30 00:21:53 +00:00
|
|
|
|
2017-01-11 15:06:26 +00:00
|
|
|
_alloc.free(texture->pixel(), sizeof(PT)*num_pixels);
|
2013-12-30 00:21:53 +00:00
|
|
|
|
2017-01-11 15:06:26 +00:00
|
|
|
destroy(_alloc, texture);
|
2013-12-30 00:21:53 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void set_rgba_texture(Texture_base *texture_base,
|
|
|
|
unsigned char const *rgba,
|
|
|
|
unsigned len, int y) override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
Texture<PT> *texture = static_cast<Texture<PT> *>(texture_base);
|
|
|
|
|
|
|
|
texture->rgba(rgba, len, y);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__SCOUT__CANVAS_H_ */
|