genode/repos/os/include/blit/painter.h
Norman Feske c629c54153 Make util/geometry.h C++20 friendly
- Move header to base/include to make it applicable for base types
  like 'Affinity' down the road.
- Represent 'Rect' as typle of point and area, which is the most
  common form of initialization, creates in valid 'Rect' by default.
- Turn Point, Area, and Rect into compound types, making x, y, w, h, at,
  area accessible without a method call
- 'Rect::Compound' function for constructing a 'Rect' from two points,
  replacing a former constructor
- Use result type 'Rect::Cut_remainder' instead of out parameters.

Fixes #5239
2024-06-20 12:54:30 +02:00

60 lines
1.6 KiB
C++

/*
* \brief Functor for blitting textures on a surface
* \author Norman Feske
* \date 2020-07-02
*/
/*
* 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__BLIT__PAINTER_H_
#define _INCLUDE__BLIT__PAINTER_H_
#include <blit/blit.h>
#include <os/texture.h>
struct Blit_painter
{
typedef Genode::Surface_base::Point Point;
typedef Genode::Surface_base::Rect Rect;
template <typename PT>
static inline void paint(Genode::Surface<PT> &surface,
Genode::Texture<PT> const &texture,
Point position)
{
Rect const clipped = Rect::intersect(Rect(position, texture.size()),
surface.clip());
if (!clipped.valid())
return;
int const src_w = texture.size().w;
int const dst_w = surface.size().w;
/* calculate offset of first texture pixel to copy */
unsigned long const tex_start_offset = (clipped.y1() - position.y)*src_w
+ clipped.x1() - position.x;
/* start address of source pixels */
PT const * const src = texture.pixel() + tex_start_offset;
/* start address of destination pixels */
PT * const dst = surface.addr() + clipped.y1()*dst_w + clipped.x1();
blit(src, (unsigned)(src_w*sizeof(PT)),
dst, (unsigned)(dst_w*sizeof(PT)),
(unsigned)(clipped.w()*sizeof(PT)), clipped.h());
surface.flush_pixels(clipped);
}
};
#endif /* _INCLUDE__BLIT__PAINTER_H_ */